packages feed

cardano-c-clib (empty) → 0.1.1.0

raw patch · 970 files changed

+423754/−0 lines, 970 filesdep +cardano-c-clib

Dependencies added: cardano-c-clib

This diff is very large; some files are shown as “too large to diff”. Download the raw patch for the complete diff.

Files

+ LICENSE view
@@ -0,0 +1,201 @@+                                 Apache License+                           Version 2.0, January 2004+                        http://www.apache.org/licenses/++   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION++   1. Definitions.++      "License" shall mean the terms and conditions for use, reproduction,+      and distribution as defined by Sections 1 through 9 of this document.++      "Licensor" shall mean the copyright owner or entity authorized by+      the copyright owner that is granting the License.++      "Legal Entity" shall mean the union of the acting entity and all+      other entities that control, are controlled by, or are under common+      control with that entity. For the purposes of this definition,+      "control" means (i) the power, direct or indirect, to cause the+      direction or management of such entity, whether by contract or+      otherwise, or (ii) ownership of fifty percent (50%) or more of the+      outstanding shares, or (iii) beneficial ownership of such entity.++      "You" (or "Your") shall mean an individual or Legal Entity+      exercising permissions granted by this License.++      "Source" form shall mean the preferred form for making modifications,+      including but not limited to software source code, documentation+      source, and configuration files.++      "Object" form shall mean any form resulting from mechanical+      transformation or translation of a Source form, including but+      not limited to compiled object code, generated documentation,+      and conversions to other media types.++      "Work" shall mean the work of authorship, whether in Source or+      Object form, made available under the License, as indicated by a+      copyright notice that is included in or attached to the work+      (an example is provided in the Appendix below).++      "Derivative Works" shall mean any work, whether in Source or Object+      form, that is based on (or derived from) the Work and for which the+      editorial revisions, annotations, elaborations, or other modifications+      represent, as a whole, an original work of authorship. For the purposes+      of this License, Derivative Works shall not include works that remain+      separable from, or merely link (or bind by name) to the interfaces of,+      the Work and Derivative Works thereof.++      "Contribution" shall mean any work of authorship, including+      the original version of the Work and any modifications or additions+      to that Work or Derivative Works thereof, that is intentionally+      submitted to Licensor for inclusion in the Work by the copyright owner+      or by an individual or Legal Entity authorized to submit on behalf of+      the copyright owner. For the purposes of this definition, "submitted"+      means any form of electronic, verbal, or written communication sent+      to the Licensor or its representatives, including but not limited to+      communication on electronic mailing lists, source code control systems,+      and issue tracking systems that are managed by, or on behalf of, the+      Licensor for the purpose of discussing and improving the Work, but+      excluding communication that is conspicuously marked or otherwise+      designated in writing by the copyright owner as "Not a Contribution."++      "Contributor" shall mean Licensor and any individual or Legal Entity+      on behalf of whom a Contribution has been received by Licensor and+      subsequently incorporated within the Work.++   2. Grant of Copyright License. Subject to the terms and conditions of+      this License, each Contributor hereby grants to You a perpetual,+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable+      copyright license to reproduce, prepare Derivative Works of,+      publicly display, publicly perform, sublicense, and distribute the+      Work and such Derivative Works in Source or Object form.++   3. Grant of Patent License. Subject to the terms and conditions of+      this License, each Contributor hereby grants to You a perpetual,+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable+      (except as stated in this section) patent license to make, have made,+      use, offer to sell, sell, import, and otherwise transfer the Work,+      where such license applies only to those patent claims licensable+      by such Contributor that are necessarily infringed by their+      Contribution(s) alone or by combination of their Contribution(s)+      with the Work to which such Contribution(s) was submitted. If You+      institute patent litigation against any entity (including a+      cross-claim or counterclaim in a lawsuit) alleging that the Work+      or a Contribution incorporated within the Work constitutes direct+      or contributory patent infringement, then any patent licenses+      granted to You under this License for that Work shall terminate+      as of the date such litigation is filed.++   4. Redistribution. You may reproduce and distribute copies of the+      Work or Derivative Works thereof in any medium, with or without+      modifications, and in Source or Object form, provided that You+      meet the following conditions:++      (a) You must give any other recipients of the Work or+          Derivative Works a copy of this License; and++      (b) You must cause any modified files to carry prominent notices+          stating that You changed the files; and++      (c) You must retain, in the Source form of any Derivative Works+          that You distribute, all copyright, patent, trademark, and+          attribution notices from the Source form of the Work,+          excluding those notices that do not pertain to any part of+          the Derivative Works; and++      (d) If the Work includes a "NOTICE" text file as part of its+          distribution, then any Derivative Works that You distribute must+          include a readable copy of the attribution notices contained+          within such NOTICE file, excluding those notices that do not+          pertain to any part of the Derivative Works, in at least one+          of the following places: within a NOTICE text file distributed+          as part of the Derivative Works; within the Source form or+          documentation, if provided along with the Derivative Works; or,+          within a display generated by the Derivative Works, if and+          wherever such third-party notices normally appear. The contents+          of the NOTICE file are for informational purposes only and+          do not modify the License. You may add Your own attribution+          notices within Derivative Works that You distribute, alongside+          or as an addendum to the NOTICE text from the Work, provided+          that such additional attribution notices cannot be construed+          as modifying the License.++      You may add Your own copyright statement to Your modifications and+      may provide additional or different license terms and conditions+      for use, reproduction, or distribution of Your modifications, or+      for any such Derivative Works as a whole, provided Your use,+      reproduction, and distribution of the Work otherwise complies with+      the conditions stated in this License.++   5. Submission of Contributions. Unless You explicitly state otherwise,+      any Contribution intentionally submitted for inclusion in the Work+      by You to the Licensor shall be under the terms and conditions of+      this License, without any additional terms or conditions.+      Notwithstanding the above, nothing herein shall supersede or modify+      the terms of any separate license agreement you may have executed+      with Licensor regarding such Contributions.++   6. Trademarks. This License does not grant permission to use the trade+      names, trademarks, service marks, or product names of the Licensor,+      except as required for reasonable and customary use in describing the+      origin of the Work and reproducing the content of the NOTICE file.++   7. Disclaimer of Warranty. Unless required by applicable law or+      agreed to in writing, Licensor provides the Work (and each+      Contributor provides its Contributions) on an "AS IS" BASIS,+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+      implied, including, without limitation, any warranties or conditions+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A+      PARTICULAR PURPOSE. You are solely responsible for determining the+      appropriateness of using or redistributing the Work and assume any+      risks associated with Your exercise of permissions under this License.++   8. Limitation of Liability. In no event and under no legal theory,+      whether in tort (including negligence), contract, or otherwise,+      unless required by applicable law (such as deliberate and grossly+      negligent acts) or agreed to in writing, shall any Contributor be+      liable to You for damages, including any direct, indirect, special,+      incidental, or consequential damages of any character arising as a+      result of this License or out of the use or inability to use the+      Work (including but not limited to damages for loss of goodwill,+      work stoppage, computer failure or malfunction, or any and all+      other commercial damages or losses), even if such Contributor+      has been advised of the possibility of such damages.++   9. Accepting Warranty or Additional Liability. While redistributing+      the Work or Derivative Works thereof, You may choose to offer,+      and charge a fee for, acceptance of support, warranty, indemnity,+      or other liability obligations and/or rights consistent with this+      License. However, in accepting such obligations, You may act only+      on Your own behalf and on Your sole responsibility, not on behalf+      of any other Contributor, and only if You agree to indemnify,+      defend, and hold each Contributor harmless for any liability+      incurred by, or claims asserted against, such Contributor by reason+      of your accepting any such warranty or additional liability.++   END OF TERMS AND CONDITIONS++   APPENDIX: How to apply the Apache License to your work.++      To apply the Apache License to your work, attach the following+      boilerplate notice, with the fields enclosed by brackets "[]"+      replaced with your own identifying information. (Don't include+      the brackets!)  The text should be enclosed in the appropriate+      comment syntax for the file format. We also recommend that a+      file or class name and description of purpose be included on the+      same "printed page" as the copyright notice for easier+      identification within third-party archives.++   Copyright 2024 Biglup Labs++   Licensed under the Apache License, Version 2.0 (the "License");+   you may not use this file except in compliance with the License.+   You may obtain a copy of the License at++       http://www.apache.org/licenses/LICENSE-2.0++   Unless required by applicable law or agreed to in writing, software+   distributed under the License is distributed on an "AS IS" BASIS,+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+   See the License for the specific language governing permissions and+   limitations under the License.
+ NATIVE_REVISION view
@@ -0,0 +1,1 @@+a6f659d780f17b60ebafa170af919cca8173df09
+ NOTICE view
@@ -0,0 +1,37 @@+Bundled cardano-c source package+===============================++cardano-c: Copyright Biglup Labs and contributors, Apache-2.0 (LICENSE).+The source revision is recorded in NATIVE_REVISION. Original source notices+are preserved. The Cabal description and config.h are generated by Cometa;+no upstream C implementation is modified by packaging.++This distribution contains multiple licenses. Its package license expression+lists the requirements of the combined source payload; it does not relicense+individual files. In particular, mini-gmp is not Apache-2.0 licensed.++vendor/external/libsodium: ISC (libsodium/LICENSE), with original public-domain+notices in individual files; SHA-256/SHA-512 by Colin Percival are BSD-2-Clause+(the full notice is reproduced in licenses/libsodium-sha-BSD-2-Clause.txt).+BLAKE2 reference files carry CC0 public-domain notices; CC0 is the selected+license where alternatives are offered (licenses/CC0-1.0.txt).++vendor/external/gmp: mini-gmp and mini-mpq by the Free Software Foundation and+contributors, LGPL-3.0-or-later OR GPL-2.0-or-later. See gmp/README and the source+headers, licenses/LGPL-3.0.txt, licenses/GPL-3.0.txt (incorporated by LGPL v3)+and licenses/GPL-2.0.txt. Consumers distributing linked applications must satisfy+the terms of their selected license, including its relinking/source provisions.++vendor/external/sha3: MIT (sha3/LICENSE).+vendor/external/secp256k1: MIT (secp256k1/COPYING).+vendor/external/blst: Apache-2.0 (blst/LICENSE).++vendor/external/ripemd160: public-domain dedication and fallback unrestricted+license with warranty disclaimer (ripemd160/LICENSE). This component imposes no+additional license conditions, so it adds no term to the package's SPDX license+expression. Hackage rejects custom LicenseRef identifiers. The original+dedication, fallback grant and disclaimer remain in the bundled LICENSE and+source headers; this metadata representation does not change those notices.++All paths above are relative to vendor/external unless given in full. Full+upstream provenance is retained in vendor/external/README and VERSION files.
+ README.md view
@@ -0,0 +1,25 @@+# cardano-c-clib++Unpublished native source companion to the Cometa Haskell binding. Package+version 0.1.1.0 bundles cardano-c 2.0.0-rc.7, revision `a6f659d780f17b60ebafa170af919cca8173df09`.++This is a generated Cabal `build-type: Simple` package. Cabal compiles bundled+C sources using its selected C toolchain and optimization settings. Consumers+need no separately installed cardano-c library, CMake, Git or network download+for the native build. Six private libraries isolate bundled dependencies;+public cardano-c headers are installed by the main library for downstream FFI.++The configuration uses upstream defaults (collection growth 1.5, JSON depth+256), portable C blst, and upstream secp256k1 verification defines. Unix builds+link math and pthread and enable libsodium's initialization mutex. Compiler and+architecture selection remain the consumer toolchain's responsibility.++Sources and original notices are in `vendor/`; the payload excludes native test+suites, development scripts and build outputs. `NOTICE` and `licenses/` describe+the mixed licensing, including mini-gmp's LGPL/GPL alternatives. The complete+source is provided for consumers to rebuild and satisfy applicable license terms.++Regenerate from the Cometa repository with+`python3 tools/package-native.py /path/to/pinned/cardano-c`.+The generator verifies the committed native pin and a clean tracked checkout;+`--check` compares the generated package byte for byte without modifying it.
+ VERSION view
@@ -0,0 +1,4 @@+VERSION_MAJOR=2+VERSION_MINOR=0+VERSION_PATCH=0+VERSION_PRERELEASE=rc.7
+ cardano-c-clib.cabal view
@@ -0,0 +1,1714 @@+cabal-version: 3.0+name: cardano-c-clib+version: 0.1.1.0+synopsis: Bundled cardano-c native sources for Cometa+description:+  Compiles pinned cardano-c and its six bundled C dependencies with Cabal.+  Installs the public native headers for Haskell FFI consumers. No CMake,+  Git checkout or installed cardano-c is required when building this package.+license: Apache-2.0 AND ISC AND BSD-2-Clause AND CC0-1.0 AND MIT AND (LGPL-3.0-or-later OR GPL-2.0-or-later)+author: Biglup Labs and bundled dependency authors+maintainer: angel.castillob@protonmail.com+category: Blockchain+homepage: https://github.com/Biglup/cometa.hs+bug-reports: https://github.com/Biglup/cometa.hs/issues+build-type: Simple+license-files:+  LICENSE+  NOTICE+  licenses/CC0-1.0.txt+  licenses/GPL-2.0.txt+  licenses/GPL-3.0.txt+  licenses/LGPL-3.0.txt+  licenses/libsodium-sha-BSD-2-Clause.txt+  vendor/external/blst/LICENSE+  vendor/external/libsodium/LICENSE+  vendor/external/ripemd160/LICENSE+  vendor/external/secp256k1/COPYING+  vendor/external/sha3/LICENSE+extra-source-files:+  LICENSE+  NATIVE_REVISION+  NOTICE+  README.md+  VERSION+  licenses/CC0-1.0.txt+  licenses/GPL-2.0.txt+  licenses/GPL-3.0.txt+  licenses/LGPL-3.0.txt+  licenses/libsodium-sha-BSD-2-Clause.txt+  vendor/external/README+  vendor/external/blst/LICENSE+  vendor/external/blst/VERSION.txt+  vendor/external/blst/bindings/blst.h+  vendor/external/blst/bindings/blst_aux.h+  vendor/external/blst/src/aggregate.c+  vendor/external/blst/src/bulk_addition.c+  vendor/external/blst/src/bytes.h+  vendor/external/blst/src/consts.c+  vendor/external/blst/src/consts.h+  vendor/external/blst/src/cpuid.c+  vendor/external/blst/src/e1.c+  vendor/external/blst/src/e2.c+  vendor/external/blst/src/ec_mult.h+  vendor/external/blst/src/ec_ops.h+  vendor/external/blst/src/errors.h+  vendor/external/blst/src/exp.c+  vendor/external/blst/src/exports.c+  vendor/external/blst/src/fields.h+  vendor/external/blst/src/fp12_tower.c+  vendor/external/blst/src/hash_to_field.c+  vendor/external/blst/src/keygen.c+  vendor/external/blst/src/map_to_g1.c+  vendor/external/blst/src/map_to_g2.c+  vendor/external/blst/src/multi_scalar.c+  vendor/external/blst/src/no_asm.h+  vendor/external/blst/src/pairing.c+  vendor/external/blst/src/pentaroot-addchain.h+  vendor/external/blst/src/pentaroot.c+  vendor/external/blst/src/point.h+  vendor/external/blst/src/rb_tree.c+  vendor/external/blst/src/recip-addchain.h+  vendor/external/blst/src/recip.c+  vendor/external/blst/src/server.c+  vendor/external/blst/src/sha256.h+  vendor/external/blst/src/sqrt-addchain.h+  vendor/external/blst/src/sqrt.c+  vendor/external/blst/src/vect.c+  vendor/external/blst/src/vect.h+  vendor/external/gmp/README+  vendor/external/gmp/mini-gmp.c+  vendor/external/gmp/mini-gmp.h+  vendor/external/libsodium/LICENSE+  vendor/external/libsodium/README.markdown+  vendor/external/libsodium/crypto_aead/chacha20poly1305/aead_chacha20poly1305.c+  vendor/external/libsodium/crypto_auth/crypto_auth.c+  vendor/external/libsodium/crypto_auth/hmacsha256/auth_hmacsha256.c+  vendor/external/libsodium/crypto_auth/hmacsha512/auth_hmacsha512.c+  vendor/external/libsodium/crypto_auth/hmacsha512256/auth_hmacsha512256.c+  vendor/external/libsodium/crypto_core/ed25519/core_ed25519.c+  vendor/external/libsodium/crypto_core/ed25519/core_ristretto255.c+  vendor/external/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c+  vendor/external/libsodium/crypto_core/ed25519/ref10/fe_25_5/base.h+  vendor/external/libsodium/crypto_core/ed25519/ref10/fe_25_5/base2.h+  vendor/external/libsodium/crypto_core/ed25519/ref10/fe_25_5/constants.h+  vendor/external/libsodium/crypto_core/ed25519/ref10/fe_25_5/fe.h+  vendor/external/libsodium/crypto_core/ed25519/ref10/fe_51/base.h+  vendor/external/libsodium/crypto_core/ed25519/ref10/fe_51/base2.h+  vendor/external/libsodium/crypto_core/ed25519/ref10/fe_51/constants.h+  vendor/external/libsodium/crypto_core/ed25519/ref10/fe_51/fe.h+  vendor/external/libsodium/crypto_core/hchacha20/core_hchacha20.c+  vendor/external/libsodium/crypto_core/hsalsa20/core_hsalsa20.c+  vendor/external/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20_ref2.c+  vendor/external/libsodium/crypto_core/salsa/ref/core_salsa_ref.c+  vendor/external/libsodium/crypto_generichash/blake2b/generichash_blake2.c+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2.h+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.c+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.h+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.c+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.h+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.h+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-load-avx2.h+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-load-sse2.h+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-load-sse41.h+  vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c+  vendor/external/libsodium/crypto_generichash/blake2b/ref/generichash_blake2b.c+  vendor/external/libsodium/crypto_generichash/crypto_generichash.c+  vendor/external/libsodium/crypto_hash/crypto_hash.c+  vendor/external/libsodium/crypto_hash/sha256/cp/hash_sha256_cp.c+  vendor/external/libsodium/crypto_hash/sha256/hash_sha256.c+  vendor/external/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c+  vendor/external/libsodium/crypto_hash/sha512/hash_sha512.c+  vendor/external/libsodium/crypto_onetimeauth/crypto_onetimeauth.c+  vendor/external/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c+  vendor/external/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h+  vendor/external/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h+  vendor/external/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h+  vendor/external/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c+  vendor/external/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.h+  vendor/external/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c+  vendor/external/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.h+  vendor/external/libsodium/crypto_scalarmult/crypto_scalarmult.c+  vendor/external/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c+  vendor/external/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.h+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/consts_namespace.h+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.h+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe.h+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51.h+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_namespace.h+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.h+  vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_namespace.h+  vendor/external/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c+  vendor/external/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.h+  vendor/external/libsodium/crypto_scalarmult/ed25519/ref10/scalarmult_ed25519_ref10.c+  vendor/external/libsodium/crypto_secretstream/xchacha20poly1305/secretstream_xchacha20poly1305.c+  vendor/external/libsodium/crypto_sign/crypto_sign.c+  vendor/external/libsodium/crypto_sign/ed25519/ref10/keypair.c+  vendor/external/libsodium/crypto_sign/ed25519/ref10/obsolete.c+  vendor/external/libsodium/crypto_sign/ed25519/ref10/open.c+  vendor/external/libsodium/crypto_sign/ed25519/ref10/sign.c+  vendor/external/libsodium/crypto_sign/ed25519/ref10/sign_ed25519_ref10.h+  vendor/external/libsodium/crypto_sign/ed25519/sign_ed25519.c+  vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c+  vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.h+  vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c+  vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.h+  vendor/external/libsodium/crypto_stream/chacha20/dolbeau/u0.h+  vendor/external/libsodium/crypto_stream/chacha20/dolbeau/u1.h+  vendor/external/libsodium/crypto_stream/chacha20/dolbeau/u4.h+  vendor/external/libsodium/crypto_stream/chacha20/dolbeau/u8.h+  vendor/external/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c+  vendor/external/libsodium/crypto_stream/chacha20/ref/chacha20_ref.h+  vendor/external/libsodium/crypto_stream/chacha20/stream_chacha20.c+  vendor/external/libsodium/crypto_stream/chacha20/stream_chacha20.h+  vendor/external/libsodium/crypto_stream/crypto_stream.c+  vendor/external/libsodium/crypto_stream/salsa20/ref/salsa20_ref.c+  vendor/external/libsodium/crypto_stream/salsa20/ref/salsa20_ref.h+  vendor/external/libsodium/crypto_stream/salsa20/stream_salsa20.c+  vendor/external/libsodium/crypto_stream/salsa20/stream_salsa20.h+  vendor/external/libsodium/crypto_stream/salsa20/xmm6/salsa20_xmm6.c+  vendor/external/libsodium/crypto_stream/salsa20/xmm6/salsa20_xmm6.h+  vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c+  vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.h+  vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c+  vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.h+  vendor/external/libsodium/crypto_stream/salsa20/xmm6int/u0.h+  vendor/external/libsodium/crypto_stream/salsa20/xmm6int/u1.h+  vendor/external/libsodium/crypto_stream/salsa20/xmm6int/u4.h+  vendor/external/libsodium/crypto_stream/salsa20/xmm6int/u8.h+  vendor/external/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012_ref.c+  vendor/external/libsodium/crypto_stream/salsa2012/stream_salsa2012.c+  vendor/external/libsodium/crypto_stream/salsa208/ref/stream_salsa208_ref.c+  vendor/external/libsodium/crypto_stream/salsa208/stream_salsa208.c+  vendor/external/libsodium/crypto_stream/xchacha20/stream_xchacha20.c+  vendor/external/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c+  vendor/external/libsodium/crypto_verify/verify.c+  vendor/external/libsodium/include/sodium.h+  vendor/external/libsodium/include/sodium/core.h+  vendor/external/libsodium/include/sodium/crypto_aead_aegis128l.h+  vendor/external/libsodium/include/sodium/crypto_aead_aegis256.h+  vendor/external/libsodium/include/sodium/crypto_aead_aes256gcm.h+  vendor/external/libsodium/include/sodium/crypto_aead_chacha20poly1305.h+  vendor/external/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h+  vendor/external/libsodium/include/sodium/crypto_auth.h+  vendor/external/libsodium/include/sodium/crypto_auth_hmacsha256.h+  vendor/external/libsodium/include/sodium/crypto_auth_hmacsha512.h+  vendor/external/libsodium/include/sodium/crypto_auth_hmacsha512256.h+  vendor/external/libsodium/include/sodium/crypto_box.h+  vendor/external/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h+  vendor/external/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h+  vendor/external/libsodium/include/sodium/crypto_core_ed25519.h+  vendor/external/libsodium/include/sodium/crypto_core_hchacha20.h+  vendor/external/libsodium/include/sodium/crypto_core_hsalsa20.h+  vendor/external/libsodium/include/sodium/crypto_core_ristretto255.h+  vendor/external/libsodium/include/sodium/crypto_core_salsa20.h+  vendor/external/libsodium/include/sodium/crypto_core_salsa2012.h+  vendor/external/libsodium/include/sodium/crypto_core_salsa208.h+  vendor/external/libsodium/include/sodium/crypto_generichash.h+  vendor/external/libsodium/include/sodium/crypto_generichash_blake2b.h+  vendor/external/libsodium/include/sodium/crypto_hash.h+  vendor/external/libsodium/include/sodium/crypto_hash_sha256.h+  vendor/external/libsodium/include/sodium/crypto_hash_sha512.h+  vendor/external/libsodium/include/sodium/crypto_kdf.h+  vendor/external/libsodium/include/sodium/crypto_kdf_blake2b.h+  vendor/external/libsodium/include/sodium/crypto_kdf_hkdf_sha256.h+  vendor/external/libsodium/include/sodium/crypto_kdf_hkdf_sha512.h+  vendor/external/libsodium/include/sodium/crypto_kx.h+  vendor/external/libsodium/include/sodium/crypto_onetimeauth.h+  vendor/external/libsodium/include/sodium/crypto_onetimeauth_poly1305.h+  vendor/external/libsodium/include/sodium/crypto_pwhash.h+  vendor/external/libsodium/include/sodium/crypto_pwhash_argon2i.h+  vendor/external/libsodium/include/sodium/crypto_pwhash_argon2id.h+  vendor/external/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h+  vendor/external/libsodium/include/sodium/crypto_scalarmult.h+  vendor/external/libsodium/include/sodium/crypto_scalarmult_curve25519.h+  vendor/external/libsodium/include/sodium/crypto_scalarmult_ed25519.h+  vendor/external/libsodium/include/sodium/crypto_scalarmult_ristretto255.h+  vendor/external/libsodium/include/sodium/crypto_secretbox.h+  vendor/external/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h+  vendor/external/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h+  vendor/external/libsodium/include/sodium/crypto_secretstream_xchacha20poly1305.h+  vendor/external/libsodium/include/sodium/crypto_shorthash.h+  vendor/external/libsodium/include/sodium/crypto_shorthash_siphash24.h+  vendor/external/libsodium/include/sodium/crypto_sign.h+  vendor/external/libsodium/include/sodium/crypto_sign_ed25519.h+  vendor/external/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h+  vendor/external/libsodium/include/sodium/crypto_stream.h+  vendor/external/libsodium/include/sodium/crypto_stream_chacha20.h+  vendor/external/libsodium/include/sodium/crypto_stream_salsa20.h+  vendor/external/libsodium/include/sodium/crypto_stream_salsa2012.h+  vendor/external/libsodium/include/sodium/crypto_stream_salsa208.h+  vendor/external/libsodium/include/sodium/crypto_stream_xchacha20.h+  vendor/external/libsodium/include/sodium/crypto_stream_xsalsa20.h+  vendor/external/libsodium/include/sodium/crypto_verify_16.h+  vendor/external/libsodium/include/sodium/crypto_verify_32.h+  vendor/external/libsodium/include/sodium/crypto_verify_64.h+  vendor/external/libsodium/include/sodium/export.h+  vendor/external/libsodium/include/sodium/private/asm_cet.h+  vendor/external/libsodium/include/sodium/private/chacha20_ietf_ext.h+  vendor/external/libsodium/include/sodium/private/common.h+  vendor/external/libsodium/include/sodium/private/ed25519_ref10.h+  vendor/external/libsodium/include/sodium/private/ed25519_ref10_fe_25_5.h+  vendor/external/libsodium/include/sodium/private/ed25519_ref10_fe_51.h+  vendor/external/libsodium/include/sodium/private/implementations.h+  vendor/external/libsodium/include/sodium/private/mutex.h+  vendor/external/libsodium/include/sodium/private/softaes.h+  vendor/external/libsodium/include/sodium/private/sse2_64_32.h+  vendor/external/libsodium/include/sodium/randombytes.h+  vendor/external/libsodium/include/sodium/randombytes_internal_random.h+  vendor/external/libsodium/include/sodium/randombytes_sysrandom.h+  vendor/external/libsodium/include/sodium/runtime.h+  vendor/external/libsodium/include/sodium/utils.h+  vendor/external/libsodium/include/sodium/version.h+  vendor/external/libsodium/randombytes/internal/randombytes_internal_random.c+  vendor/external/libsodium/randombytes/randombytes.c+  vendor/external/libsodium/randombytes/sysrandom/randombytes_sysrandom.c+  vendor/external/libsodium/sodium/codecs.c+  vendor/external/libsodium/sodium/core.c+  vendor/external/libsodium/sodium/runtime.c+  vendor/external/libsodium/sodium/utils.c+  vendor/external/libsodium/sodium/version.c+  vendor/external/ripemd160/LICENSE+  vendor/external/ripemd160/VERSION.txt+  vendor/external/ripemd160/ripemd160.c+  vendor/external/ripemd160/ripemd160.h+  vendor/external/secp256k1/COPYING+  vendor/external/secp256k1/VERSION.txt+  vendor/external/secp256k1/include/secp256k1.h+  vendor/external/secp256k1/include/secp256k1_extrakeys.h+  vendor/external/secp256k1/include/secp256k1_preallocated.h+  vendor/external/secp256k1/include/secp256k1_schnorrsig.h+  vendor/external/secp256k1/src/assumptions.h+  vendor/external/secp256k1/src/checkmem.h+  vendor/external/secp256k1/src/ecdsa.h+  vendor/external/secp256k1/src/ecdsa_impl.h+  vendor/external/secp256k1/src/eckey.h+  vendor/external/secp256k1/src/eckey_impl.h+  vendor/external/secp256k1/src/ecmult.h+  vendor/external/secp256k1/src/ecmult_compute_table.h+  vendor/external/secp256k1/src/ecmult_compute_table_impl.h+  vendor/external/secp256k1/src/ecmult_const.h+  vendor/external/secp256k1/src/ecmult_const_impl.h+  vendor/external/secp256k1/src/ecmult_gen.h+  vendor/external/secp256k1/src/ecmult_gen_compute_table.h+  vendor/external/secp256k1/src/ecmult_gen_compute_table_impl.h+  vendor/external/secp256k1/src/ecmult_gen_impl.h+  vendor/external/secp256k1/src/ecmult_impl.h+  vendor/external/secp256k1/src/field.h+  vendor/external/secp256k1/src/field_10x26.h+  vendor/external/secp256k1/src/field_10x26_impl.h+  vendor/external/secp256k1/src/field_5x52.h+  vendor/external/secp256k1/src/field_5x52_impl.h+  vendor/external/secp256k1/src/field_5x52_int128_impl.h+  vendor/external/secp256k1/src/field_impl.h+  vendor/external/secp256k1/src/group.h+  vendor/external/secp256k1/src/group_impl.h+  vendor/external/secp256k1/src/hash.h+  vendor/external/secp256k1/src/hash_impl.h+  vendor/external/secp256k1/src/hsort.h+  vendor/external/secp256k1/src/hsort_impl.h+  vendor/external/secp256k1/src/int128.h+  vendor/external/secp256k1/src/int128_impl.h+  vendor/external/secp256k1/src/int128_native.h+  vendor/external/secp256k1/src/int128_native_impl.h+  vendor/external/secp256k1/src/int128_struct.h+  vendor/external/secp256k1/src/int128_struct_impl.h+  vendor/external/secp256k1/src/modinv32.h+  vendor/external/secp256k1/src/modinv32_impl.h+  vendor/external/secp256k1/src/modinv64.h+  vendor/external/secp256k1/src/modinv64_impl.h+  vendor/external/secp256k1/src/modules/extrakeys/main_impl.h+  vendor/external/secp256k1/src/modules/schnorrsig/main_impl.h+  vendor/external/secp256k1/src/precomputed_ecmult.c+  vendor/external/secp256k1/src/precomputed_ecmult.h+  vendor/external/secp256k1/src/precomputed_ecmult_gen.c+  vendor/external/secp256k1/src/precomputed_ecmult_gen.h+  vendor/external/secp256k1/src/scalar.h+  vendor/external/secp256k1/src/scalar_4x64.h+  vendor/external/secp256k1/src/scalar_4x64_impl.h+  vendor/external/secp256k1/src/scalar_8x32.h+  vendor/external/secp256k1/src/scalar_8x32_impl.h+  vendor/external/secp256k1/src/scalar_impl.h+  vendor/external/secp256k1/src/scratch.h+  vendor/external/secp256k1/src/scratch_impl.h+  vendor/external/secp256k1/src/secp256k1.c+  vendor/external/secp256k1/src/selftest.h+  vendor/external/secp256k1/src/util.h+  vendor/external/sha3/LICENSE+  vendor/external/sha3/VERSION.txt+  vendor/external/sha3/sha3.c+  vendor/external/sha3/sha3.h+  vendor/include/cardano/address/address.h+  vendor/include/cardano/address/address_type.h+  vendor/include/cardano/address/base_address.h+  vendor/include/cardano/address/byron_address.h+  vendor/include/cardano/address/byron_address_attributes.h+  vendor/include/cardano/address/byron_address_type.h+  vendor/include/cardano/address/enterprise_address.h+  vendor/include/cardano/address/pointer_address.h+  vendor/include/cardano/address/reward_address.h+  vendor/include/cardano/address/stake_pointer.h+  vendor/include/cardano/assets/asset_id.h+  vendor/include/cardano/assets/asset_id_list.h+  vendor/include/cardano/assets/asset_id_map.h+  vendor/include/cardano/assets/asset_name.h+  vendor/include/cardano/assets/asset_name_list.h+  vendor/include/cardano/assets/asset_name_map.h+  vendor/include/cardano/assets/multi_asset.h+  vendor/include/cardano/assets/policy_id_list.h+  vendor/include/cardano/auxiliary_data/auxiliary_data.h+  vendor/include/cardano/auxiliary_data/metadatum.h+  vendor/include/cardano/auxiliary_data/metadatum_kind.h+  vendor/include/cardano/auxiliary_data/metadatum_label_list.h+  vendor/include/cardano/auxiliary_data/metadatum_list.h+  vendor/include/cardano/auxiliary_data/metadatum_map.h+  vendor/include/cardano/auxiliary_data/plutus_v1_script_list.h+  vendor/include/cardano/auxiliary_data/plutus_v2_script_list.h+  vendor/include/cardano/auxiliary_data/plutus_v3_script_list.h+  vendor/include/cardano/auxiliary_data/plutus_v4_script_list.h+  vendor/include/cardano/auxiliary_data/transaction_metadata.h+  vendor/include/cardano/bip39.h+  vendor/include/cardano/buffer.h+  vendor/include/cardano/cardano.h+  vendor/include/cardano/cbor/cbor_major_type.h+  vendor/include/cardano/cbor/cbor_reader.h+  vendor/include/cardano/cbor/cbor_reader_state.h+  vendor/include/cardano/cbor/cbor_simple_value.h+  vendor/include/cardano/cbor/cbor_tag.h+  vendor/include/cardano/cbor/cbor_writer.h+  vendor/include/cardano/certs/auth_committee_hot_cert.h+  vendor/include/cardano/certs/cert_type.h+  vendor/include/cardano/certs/certificate.h+  vendor/include/cardano/certs/certificate_set.h+  vendor/include/cardano/certs/genesis_key_delegation_cert.h+  vendor/include/cardano/certs/mir_cert.h+  vendor/include/cardano/certs/mir_cert_pot_type.h+  vendor/include/cardano/certs/mir_cert_type.h+  vendor/include/cardano/certs/mir_to_pot_cert.h+  vendor/include/cardano/certs/mir_to_stake_creds_cert.h+  vendor/include/cardano/certs/pool_registration_cert.h+  vendor/include/cardano/certs/pool_retirement_cert.h+  vendor/include/cardano/certs/register_drep_cert.h+  vendor/include/cardano/certs/registration_cert.h+  vendor/include/cardano/certs/resign_committee_cold_cert.h+  vendor/include/cardano/certs/stake_delegation_cert.h+  vendor/include/cardano/certs/stake_deregistration_cert.h+  vendor/include/cardano/certs/stake_registration_cert.h+  vendor/include/cardano/certs/stake_registration_delegation_cert.h+  vendor/include/cardano/certs/stake_vote_delegation_cert.h+  vendor/include/cardano/certs/stake_vote_registration_delegation_cert.h+  vendor/include/cardano/certs/unregister_drep_cert.h+  vendor/include/cardano/certs/unregistration_cert.h+  vendor/include/cardano/certs/update_drep_cert.h+  vendor/include/cardano/certs/vote_delegation_cert.h+  vendor/include/cardano/certs/vote_registration_delegation_cert.h+  vendor/include/cardano/common/anchor.h+  vendor/include/cardano/common/bigint.h+  vendor/include/cardano/common/byte_order.h+  vendor/include/cardano/common/credential.h+  vendor/include/cardano/common/credential_type.h+  vendor/include/cardano/common/datum.h+  vendor/include/cardano/common/datum_type.h+  vendor/include/cardano/common/drep.h+  vendor/include/cardano/common/drep_type.h+  vendor/include/cardano/common/ex_units.h+  vendor/include/cardano/common/governance_action_id.h+  vendor/include/cardano/common/governance_key_type.h+  vendor/include/cardano/common/guard_set.h+  vendor/include/cardano/common/network_id.h+  vendor/include/cardano/common/network_magic.h+  vendor/include/cardano/common/protocol_version.h+  vendor/include/cardano/common/reward_address_list.h+  vendor/include/cardano/common/unit_interval.h+  vendor/include/cardano/common/utxo.h+  vendor/include/cardano/common/utxo_list.h+  vendor/include/cardano/common/withdrawal_map.h+  vendor/include/cardano/crypto/bip32_private_key.h+  vendor/include/cardano/crypto/bip32_public_key.h+  vendor/include/cardano/crypto/blake2b_hash.h+  vendor/include/cardano/crypto/blake2b_hash_set.h+  vendor/include/cardano/crypto/blake2b_hash_size.h+  vendor/include/cardano/crypto/crc32.h+  vendor/include/cardano/crypto/ed25519_private_key.h+  vendor/include/cardano/crypto/ed25519_public_key.h+  vendor/include/cardano/crypto/ed25519_signature.h+  vendor/include/cardano/crypto/emip3.h+  vendor/include/cardano/crypto/pbkdf2.h+  vendor/include/cardano/encoding/base58.h+  vendor/include/cardano/encoding/bech32.h+  vendor/include/cardano/error.h+  vendor/include/cardano/export.h+  vendor/include/cardano/json/json_context.h+  vendor/include/cardano/json/json_format.h+  vendor/include/cardano/json/json_object.h+  vendor/include/cardano/json/json_object_type.h+  vendor/include/cardano/json/json_writer.h+  vendor/include/cardano/key_handlers/account_derivation_path.h+  vendor/include/cardano/key_handlers/cip_1852_constants.h+  vendor/include/cardano/key_handlers/derivation_path.h+  vendor/include/cardano/key_handlers/secure_key_handler.h+  vendor/include/cardano/key_handlers/secure_key_handler_impl.h+  vendor/include/cardano/key_handlers/secure_key_handler_type.h+  vendor/include/cardano/key_handlers/software_secure_key_handler.h+  vendor/include/cardano/message_signing/cip8.h+  vendor/include/cardano/object.h+  vendor/include/cardano/plutus_data/constr_plutus_data.h+  vendor/include/cardano/plutus_data/plutus_data.h+  vendor/include/cardano/plutus_data/plutus_data_kind.h+  vendor/include/cardano/plutus_data/plutus_list.h+  vendor/include/cardano/plutus_data/plutus_map.h+  vendor/include/cardano/pool_params/bls_key.h+  vendor/include/cardano/pool_params/ipv4.h+  vendor/include/cardano/pool_params/ipv6.h+  vendor/include/cardano/pool_params/multi_host_name_relay.h+  vendor/include/cardano/pool_params/pool_metadata.h+  vendor/include/cardano/pool_params/pool_owners.h+  vendor/include/cardano/pool_params/pool_params.h+  vendor/include/cardano/pool_params/relay.h+  vendor/include/cardano/pool_params/relay_type.h+  vendor/include/cardano/pool_params/relays.h+  vendor/include/cardano/pool_params/single_host_addr_relay.h+  vendor/include/cardano/pool_params/single_host_name_relay.h+  vendor/include/cardano/proposal_procedures/committee.h+  vendor/include/cardano/proposal_procedures/committee_members_map.h+  vendor/include/cardano/proposal_procedures/constitution.h+  vendor/include/cardano/proposal_procedures/credential_set.h+  vendor/include/cardano/proposal_procedures/governance_action_type.h+  vendor/include/cardano/proposal_procedures/hard_fork_initiation_action.h+  vendor/include/cardano/proposal_procedures/info_action.h+  vendor/include/cardano/proposal_procedures/new_constitution_action.h+  vendor/include/cardano/proposal_procedures/no_confidence_action.h+  vendor/include/cardano/proposal_procedures/parameter_change_action.h+  vendor/include/cardano/proposal_procedures/proposal_procedure.h+  vendor/include/cardano/proposal_procedures/proposal_procedure_set.h+  vendor/include/cardano/proposal_procedures/treasury_withdrawals_action.h+  vendor/include/cardano/proposal_procedures/update_committee_action.h+  vendor/include/cardano/protocol_params/cost_model.h+  vendor/include/cardano/protocol_params/costmdls.h+  vendor/include/cardano/protocol_params/drep_voting_thresholds.h+  vendor/include/cardano/protocol_params/ex_unit_prices.h+  vendor/include/cardano/protocol_params/pool_voting_thresholds.h+  vendor/include/cardano/protocol_params/proposed_param_updates.h+  vendor/include/cardano/protocol_params/protocol_param_update.h+  vendor/include/cardano/protocol_params/protocol_parameters.h+  vendor/include/cardano/protocol_params/update.h+  vendor/include/cardano/providers/provider.h+  vendor/include/cardano/providers/provider_impl.h+  vendor/include/cardano/scripts/native_scripts/native_script.h+  vendor/include/cardano/scripts/native_scripts/native_script_list.h+  vendor/include/cardano/scripts/native_scripts/native_script_type.h+  vendor/include/cardano/scripts/native_scripts/script_all.h+  vendor/include/cardano/scripts/native_scripts/script_any.h+  vendor/include/cardano/scripts/native_scripts/script_invalid_after.h+  vendor/include/cardano/scripts/native_scripts/script_invalid_before.h+  vendor/include/cardano/scripts/native_scripts/script_n_of_k.h+  vendor/include/cardano/scripts/native_scripts/script_pubkey.h+  vendor/include/cardano/scripts/native_scripts/script_require_guard.h+  vendor/include/cardano/scripts/plutus_scripts/plutus_language_version.h+  vendor/include/cardano/scripts/plutus_scripts/plutus_v1_script.h+  vendor/include/cardano/scripts/plutus_scripts/plutus_v2_script.h+  vendor/include/cardano/scripts/plutus_scripts/plutus_v3_script.h+  vendor/include/cardano/scripts/plutus_scripts/plutus_v4_script.h+  vendor/include/cardano/scripts/script.h+  vendor/include/cardano/scripts/script_language.h+  vendor/include/cardano/slot_config.h+  vendor/include/cardano/time.h+  vendor/include/cardano/transaction/sub_transaction.h+  vendor/include/cardano/transaction/transaction.h+  vendor/include/cardano/transaction_body/account_balance_interval.h+  vendor/include/cardano/transaction_body/account_balance_intervals_map.h+  vendor/include/cardano/transaction_body/direct_deposit_map.h+  vendor/include/cardano/transaction_body/required_guards_map.h+  vendor/include/cardano/transaction_body/sub_transaction_body.h+  vendor/include/cardano/transaction_body/sub_transaction_set.h+  vendor/include/cardano/transaction_body/transaction_body.h+  vendor/include/cardano/transaction_body/transaction_input.h+  vendor/include/cardano/transaction_body/transaction_input_set.h+  vendor/include/cardano/transaction_body/transaction_output.h+  vendor/include/cardano/transaction_body/transaction_output_list.h+  vendor/include/cardano/transaction_body/value.h+  vendor/include/cardano/transaction_builder/balancing/deferred_redeemer_list.h+  vendor/include/cardano/transaction_builder/balancing/implicit_coin.h+  vendor/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h+  vendor/include/cardano/transaction_builder/balancing/transaction_balancing.h+  vendor/include/cardano/transaction_builder/coin_selection/coin_selection_request.h+  vendor/include/cardano/transaction_builder/coin_selection/coin_selection_strategy.h+  vendor/include/cardano/transaction_builder/coin_selection/coin_selector.h+  vendor/include/cardano/transaction_builder/coin_selection/coin_selector_impl.h+  vendor/include/cardano/transaction_builder/coin_selection/large_first_coin_selector.h+  vendor/include/cardano/transaction_builder/coin_selection/random_improve_coin_selector.h+  vendor/include/cardano/transaction_builder/evaluation/native_tx_evaluator.h+  vendor/include/cardano/transaction_builder/evaluation/provider_tx_evaluator.h+  vendor/include/cardano/transaction_builder/evaluation/tx_evaluator.h+  vendor/include/cardano/transaction_builder/evaluation/tx_evaluator_impl.h+  vendor/include/cardano/transaction_builder/fee.h+  vendor/include/cardano/transaction_builder/script_data_hash.h+  vendor/include/cardano/transaction_builder/sub_transaction_builder.h+  vendor/include/cardano/transaction_builder/transaction_builder.h+  vendor/include/cardano/typedefs.h+  vendor/include/cardano/uplc/uplc_apply_params.h+  vendor/include/cardano/voting_procedures/governance_action_id_list.h+  vendor/include/cardano/voting_procedures/vote.h+  vendor/include/cardano/voting_procedures/voter.h+  vendor/include/cardano/voting_procedures/voter_list.h+  vendor/include/cardano/voting_procedures/voter_type.h+  vendor/include/cardano/voting_procedures/voting_procedure.h+  vendor/include/cardano/voting_procedures/voting_procedure_list.h+  vendor/include/cardano/voting_procedures/voting_procedures.h+  vendor/include/cardano/witness_set/bootstrap_witness.h+  vendor/include/cardano/witness_set/bootstrap_witness_set.h+  vendor/include/cardano/witness_set/native_script_set.h+  vendor/include/cardano/witness_set/plutus_data_set.h+  vendor/include/cardano/witness_set/plutus_v1_script_set.h+  vendor/include/cardano/witness_set/plutus_v2_script_set.h+  vendor/include/cardano/witness_set/plutus_v3_script_set.h+  vendor/include/cardano/witness_set/plutus_v4_script_set.h+  vendor/include/cardano/witness_set/redeemer.h+  vendor/include/cardano/witness_set/redeemer_list.h+  vendor/include/cardano/witness_set/redeemer_tag.h+  vendor/include/cardano/witness_set/vkey_witness.h+  vendor/include/cardano/witness_set/vkey_witness_set.h+  vendor/include/cardano/witness_set/witness_set.h+  vendor/src/address/address.c+  vendor/src/address/base_address.c+  vendor/src/address/byron_address.c+  vendor/src/address/enterprise_address.c+  vendor/src/address/internals/addr_common.c+  vendor/src/address/internals/addr_common.h+  vendor/src/address/internals/base_addr_pack.c+  vendor/src/address/internals/base_addr_pack.h+  vendor/src/address/internals/byron_addr_pack.c+  vendor/src/address/internals/byron_addr_pack.h+  vendor/src/address/internals/byron_address_content.h+  vendor/src/address/internals/enterprise_addr_pack.c+  vendor/src/address/internals/enterprise_addr_pack.h+  vendor/src/address/internals/pointer_addr_pack.c+  vendor/src/address/internals/pointer_addr_pack.h+  vendor/src/address/internals/reward_addr_pack.c+  vendor/src/address/internals/reward_addr_pack.h+  vendor/src/address/pointer_address.c+  vendor/src/address/reward_address.c+  vendor/src/allocators.c+  vendor/src/allocators.h+  vendor/src/assets/asset_id.c+  vendor/src/assets/asset_id_list.c+  vendor/src/assets/asset_id_map.c+  vendor/src/assets/asset_name.c+  vendor/src/assets/asset_name_list.c+  vendor/src/assets/asset_name_map.c+  vendor/src/assets/multi_asset.c+  vendor/src/assets/policy_id_list.c+  vendor/src/auxiliary_data/auxiliary_data.c+  vendor/src/auxiliary_data/metadatum.c+  vendor/src/auxiliary_data/metadatum_label_list.c+  vendor/src/auxiliary_data/metadatum_list.c+  vendor/src/auxiliary_data/metadatum_map.c+  vendor/src/auxiliary_data/plutus_v1_script_list.c+  vendor/src/auxiliary_data/plutus_v2_script_list.c+  vendor/src/auxiliary_data/plutus_v3_script_list.c+  vendor/src/auxiliary_data/plutus_v4_script_list.c+  vendor/src/auxiliary_data/transaction_metadata.c+  vendor/src/bip39/bip39.c+  vendor/src/bip39/bip39_wordlist_en.h+  vendor/src/buffer/buffer.c+  vendor/src/cardano.c+  vendor/src/cbor/cbor_additional_info.h+  vendor/src/cbor/cbor_initial_byte.c+  vendor/src/cbor/cbor_initial_byte.h+  vendor/src/cbor/cbor_major_type.c+  vendor/src/cbor/cbor_reader/cbor_reader.c+  vendor/src/cbor/cbor_reader/cbor_reader_collections.c+  vendor/src/cbor/cbor_reader/cbor_reader_collections.h+  vendor/src/cbor/cbor_reader/cbor_reader_core.c+  vendor/src/cbor/cbor_reader/cbor_reader_core.h+  vendor/src/cbor/cbor_reader/cbor_reader_numeric.c+  vendor/src/cbor/cbor_reader/cbor_reader_numeric.h+  vendor/src/cbor/cbor_reader/cbor_reader_simple_values.c+  vendor/src/cbor/cbor_reader/cbor_reader_simple_values.h+  vendor/src/cbor/cbor_reader/cbor_reader_tags.c+  vendor/src/cbor/cbor_reader/cbor_reader_tags.h+  vendor/src/cbor/cbor_reader_state.c+  vendor/src/cbor/cbor_simple_value.c+  vendor/src/cbor/cbor_tag.c+  vendor/src/cbor/cbor_validation.c+  vendor/src/cbor/cbor_validation.h+  vendor/src/cbor/cbor_writer.c+  vendor/src/certs/auth_committee_hot_cert.c+  vendor/src/certs/cert_type.c+  vendor/src/certs/certificate.c+  vendor/src/certs/certificate_set.c+  vendor/src/certs/genesis_key_delegation_cert.c+  vendor/src/certs/mir_cert.c+  vendor/src/certs/mir_to_pot_cert.c+  vendor/src/certs/mir_to_stake_creds_cert.c+  vendor/src/certs/pool_registration_cert.c+  vendor/src/certs/pool_retirement_cert.c+  vendor/src/certs/register_drep_cert.c+  vendor/src/certs/registration_cert.c+  vendor/src/certs/resign_committee_cold_cert.c+  vendor/src/certs/stake_delegation_cert.c+  vendor/src/certs/stake_deregistration_cert.c+  vendor/src/certs/stake_registration_cert.c+  vendor/src/certs/stake_registration_delegation_cert.c+  vendor/src/certs/stake_vote_delegation_cert.c+  vendor/src/certs/stake_vote_registration_delegation_cert.c+  vendor/src/certs/unregister_drep_cert.c+  vendor/src/certs/unregistration_cert.c+  vendor/src/certs/update_drep_cert.c+  vendor/src/certs/vote_delegation_cert.c+  vendor/src/certs/vote_registration_delegation_cert.c+  vendor/src/collections/array.c+  vendor/src/collections/array.h+  vendor/src/collections/set.c+  vendor/src/collections/set.h+  vendor/src/common/anchor.c+  vendor/src/common/bigint.c+  vendor/src/common/credential.c+  vendor/src/common/datum.c+  vendor/src/common/drep.c+  vendor/src/common/ex_units.c+  vendor/src/common/governance_action_id.c+  vendor/src/common/guard_set.c+  vendor/src/common/ledger_order.c+  vendor/src/common/ledger_order.h+  vendor/src/common/network_magic.c+  vendor/src/common/protocol_version.c+  vendor/src/common/reward_address_list.c+  vendor/src/common/unit_interval.c+  vendor/src/common/utxo.c+  vendor/src/common/utxo_list.c+  vendor/src/common/withdrawal_map.c+  vendor/src/config.h+  vendor/src/crypto/arithmetic.c+  vendor/src/crypto/arithmetic.h+  vendor/src/crypto/bip32_key_derivation.c+  vendor/src/crypto/bip32_key_derivation.h+  vendor/src/crypto/bip32_private_key.c+  vendor/src/crypto/bip32_public_key.c+  vendor/src/crypto/blake2b_hash.c+  vendor/src/crypto/blake2b_hash_internal.h+  vendor/src/crypto/blake2b_hash_set.c+  vendor/src/crypto/crc32.c+  vendor/src/crypto/ed25519_private_key.c+  vendor/src/crypto/ed25519_public_key.c+  vendor/src/crypto/ed25519_signature.c+  vendor/src/crypto/emip3.c+  vendor/src/crypto/pbkdf2.c+  vendor/src/encoding/base58.c+  vendor/src/encoding/bech32.c+  vendor/src/endian.c+  vendor/src/endian.h+  vendor/src/error.c+  vendor/src/json/internals/json_object_common.c+  vendor/src/json/internals/json_object_common.h+  vendor/src/json/internals/json_object_serialization.c+  vendor/src/json/internals/json_object_serialization.h+  vendor/src/json/internals/json_parser.c+  vendor/src/json/internals/json_parser.h+  vendor/src/json/internals/json_writer_common.c+  vendor/src/json/internals/json_writer_common.h+  vendor/src/json/internals/utf8.c+  vendor/src/json/internals/utf8.h+  vendor/src/json/json_object.c+  vendor/src/json/json_writer.c+  vendor/src/key_handlers/secure_key_handler.c+  vendor/src/key_handlers/software_secure_key_handler.c+  vendor/src/message_signing/cip8.c+  vendor/src/object.c+  vendor/src/plutus_data/constr_plutus_data.c+  vendor/src/plutus_data/plutus_data.c+  vendor/src/plutus_data/plutus_list.c+  vendor/src/plutus_data/plutus_map.c+  vendor/src/pool_params/bls_key.c+  vendor/src/pool_params/ipv4.c+  vendor/src/pool_params/ipv6.c+  vendor/src/pool_params/multi_host_name_relay.c+  vendor/src/pool_params/pool_metadata.c+  vendor/src/pool_params/pool_owners.c+  vendor/src/pool_params/pool_params.c+  vendor/src/pool_params/relay.c+  vendor/src/pool_params/relay_type.c+  vendor/src/pool_params/relays.c+  vendor/src/pool_params/single_host_addr_relay.c+  vendor/src/pool_params/single_host_name_relay.c+  vendor/src/proposal_procedures/committee.c+  vendor/src/proposal_procedures/committee_members_map.c+  vendor/src/proposal_procedures/constitution.c+  vendor/src/proposal_procedures/credential_set.c+  vendor/src/proposal_procedures/governance_action_type.c+  vendor/src/proposal_procedures/hard_fork_initiation_action.c+  vendor/src/proposal_procedures/info_action.c+  vendor/src/proposal_procedures/new_constitution_action.c+  vendor/src/proposal_procedures/no_confidence_action.c+  vendor/src/proposal_procedures/parameter_change_action.c+  vendor/src/proposal_procedures/proposal_procedure.c+  vendor/src/proposal_procedures/proposal_procedure_set.c+  vendor/src/proposal_procedures/treasury_withdrawals_action.c+  vendor/src/proposal_procedures/update_committee_action.c+  vendor/src/protocol_params/cost_model.c+  vendor/src/protocol_params/costmdls.c+  vendor/src/protocol_params/drep_voting_thresholds.c+  vendor/src/protocol_params/ex_unit_prices.c+  vendor/src/protocol_params/pool_voting_thresholds.c+  vendor/src/protocol_params/proposed_param_updates.c+  vendor/src/protocol_params/protocol_param_update.c+  vendor/src/protocol_params/protocol_parameters.c+  vendor/src/protocol_params/update.c+  vendor/src/providers/emscripten/emscripten_provider.c+  vendor/src/providers/provider.c+  vendor/src/scripts/native_scripts/native_script.c+  vendor/src/scripts/native_scripts/native_script_list.c+  vendor/src/scripts/native_scripts/native_script_type.c+  vendor/src/scripts/native_scripts/script_all.c+  vendor/src/scripts/native_scripts/script_any.c+  vendor/src/scripts/native_scripts/script_invalid_after.c+  vendor/src/scripts/native_scripts/script_invalid_before.c+  vendor/src/scripts/native_scripts/script_n_of_k.c+  vendor/src/scripts/native_scripts/script_pubkey.c+  vendor/src/scripts/native_scripts/script_require_guard.c+  vendor/src/scripts/plutus_scripts/plutus_v1_script.c+  vendor/src/scripts/plutus_scripts/plutus_v2_script.c+  vendor/src/scripts/plutus_scripts/plutus_v3_script.c+  vendor/src/scripts/plutus_scripts/plutus_v4_script.c+  vendor/src/scripts/script.c+  vendor/src/string_safe.c+  vendor/src/string_safe.h+  vendor/src/time.c+  vendor/src/transaction/sub_transaction.c+  vendor/src/transaction/transaction.c+  vendor/src/transaction_body/account_balance_interval.c+  vendor/src/transaction_body/account_balance_intervals_map.c+  vendor/src/transaction_body/direct_deposit_map.c+  vendor/src/transaction_body/internals/body_fields.c+  vendor/src/transaction_body/internals/body_fields.h+  vendor/src/transaction_body/required_guards_map.c+  vendor/src/transaction_body/sub_transaction_body.c+  vendor/src/transaction_body/sub_transaction_set.c+  vendor/src/transaction_body/transaction_body.c+  vendor/src/transaction_body/transaction_input.c+  vendor/src/transaction_body/transaction_input_set.c+  vendor/src/transaction_body/transaction_output.c+  vendor/src/transaction_body/transaction_output_list.c+  vendor/src/transaction_body/value.c+  vendor/src/transaction_builder/balancing/deferred_redeemer_list.c+  vendor/src/transaction_builder/balancing/implicit_coin.c+  vendor/src/transaction_builder/balancing/input_to_redeemer_map.c+  vendor/src/transaction_builder/balancing/internals/collateral.c+  vendor/src/transaction_builder/balancing/internals/collateral.h+  vendor/src/transaction_builder/balancing/internals/pool_deposits.c+  vendor/src/transaction_builder/balancing/internals/pool_deposits.h+  vendor/src/transaction_builder/balancing/internals/scripts_needed.c+  vendor/src/transaction_builder/balancing/internals/scripts_needed.h+  vendor/src/transaction_builder/balancing/internals/unique_signers.c+  vendor/src/transaction_builder/balancing/internals/unique_signers.h+  vendor/src/transaction_builder/balancing/transaction_balancing.c+  vendor/src/transaction_builder/coin_selection/coin_selector.c+  vendor/src/transaction_builder/coin_selection/internals/change_builder.c+  vendor/src/transaction_builder/coin_selection/internals/change_builder.h+  vendor/src/transaction_builder/coin_selection/internals/emscripten_coin_selector.c+  vendor/src/transaction_builder/coin_selection/internals/large_first_coin_selector.c+  vendor/src/transaction_builder/coin_selection/internals/large_first_helpers.c+  vendor/src/transaction_builder/coin_selection/internals/large_first_helpers.h+  vendor/src/transaction_builder/coin_selection/internals/random_improve_change_state.c+  vendor/src/transaction_builder/coin_selection/internals/random_improve_change_state.h+  vendor/src/transaction_builder/coin_selection/internals/random_improve_coin_selector.c+  vendor/src/transaction_builder/coin_selection/internals/random_improve_helpers.c+  vendor/src/transaction_builder/coin_selection/internals/random_improve_helpers.h+  vendor/src/transaction_builder/coin_selection/internals/random_improve_selection_index.c+  vendor/src/transaction_builder/coin_selection/internals/random_improve_selection_index.h+  vendor/src/transaction_builder/coin_selection/internals/random_improve_utxo_utils.c+  vendor/src/transaction_builder/coin_selection/internals/random_improve_utxo_utils.h+  vendor/src/transaction_builder/coin_selection/internals/value_splitting.c+  vendor/src/transaction_builder/coin_selection/internals/value_splitting.h+  vendor/src/transaction_builder/evaluation/emscripten_tx_evaluator.c+  vendor/src/transaction_builder/evaluation/native_tx_evaluator.c+  vendor/src/transaction_builder/evaluation/provider_tx_evaluator.c+  vendor/src/transaction_builder/evaluation/tx_evaluator.c+  vendor/src/transaction_builder/fee.c+  vendor/src/transaction_builder/internals/blake2b_hash_to_redeemer_map.c+  vendor/src/transaction_builder/internals/blake2b_hash_to_redeemer_map.h+  vendor/src/transaction_builder/internals/builder_build.c+  vendor/src/transaction_builder/internals/builder_build.h+  vendor/src/transaction_builder/internals/builder_certs.c+  vendor/src/transaction_builder/internals/builder_certs.h+  vendor/src/transaction_builder/internals/builder_config.c+  vendor/src/transaction_builder/internals/builder_config.h+  vendor/src/transaction_builder/internals/builder_entities.c+  vendor/src/transaction_builder/internals/builder_entities.h+  vendor/src/transaction_builder/internals/builder_inputs.c+  vendor/src/transaction_builder/internals/builder_inputs.h+  vendor/src/transaction_builder/internals/builder_mint.c+  vendor/src/transaction_builder/internals/builder_mint.h+  vendor/src/transaction_builder/internals/builder_outputs.c+  vendor/src/transaction_builder/internals/builder_outputs.h+  vendor/src/transaction_builder/internals/builder_proposals.c+  vendor/src/transaction_builder/internals/builder_proposals.h+  vendor/src/transaction_builder/internals/builder_redeemers.c+  vendor/src/transaction_builder/internals/builder_redeemers.h+  vendor/src/transaction_builder/internals/builder_state.c+  vendor/src/transaction_builder/internals/builder_state.h+  vendor/src/transaction_builder/internals/builder_sub_build.c+  vendor/src/transaction_builder/internals/builder_sub_build.h+  vendor/src/transaction_builder/internals/builder_sub_transactions.c+  vendor/src/transaction_builder/internals/builder_sub_transactions.h+  vendor/src/transaction_builder/internals/builder_votes.c+  vendor/src/transaction_builder/internals/builder_votes.h+  vendor/src/transaction_builder/internals/builder_withdrawals.c+  vendor/src/transaction_builder/internals/builder_withdrawals.h+  vendor/src/transaction_builder/internals/builder_witnesses.c+  vendor/src/transaction_builder/internals/builder_witnesses.h+  vendor/src/transaction_builder/internals/created_output_scripts.c+  vendor/src/transaction_builder/internals/created_output_scripts.h+  vendor/src/transaction_builder/script_data_hash.c+  vendor/src/transaction_builder/sub_transaction_builder.c+  vendor/src/transaction_builder/transaction_builder.c+  vendor/src/uplc/arena/uplc_arena.c+  vendor/src/uplc/arena/uplc_arena.h+  vendor/src/uplc/ast/uplc_constant.c+  vendor/src/uplc/ast/uplc_constant.h+  vendor/src/uplc/ast/uplc_int.c+  vendor/src/uplc/ast/uplc_int.h+  vendor/src/uplc/ast/uplc_int_math.c+  vendor/src/uplc/ast/uplc_int_math.h+  vendor/src/uplc/ast/uplc_lang_version.c+  vendor/src/uplc/ast/uplc_lang_version.h+  vendor/src/uplc/ast/uplc_program.c+  vendor/src/uplc/ast/uplc_program.h+  vendor/src/uplc/ast/uplc_scope_check_mode.h+  vendor/src/uplc/ast/uplc_term.c+  vendor/src/uplc/ast/uplc_term.h+  vendor/src/uplc/ast/uplc_term_kind.h+  vendor/src/uplc/ast/uplc_type.c+  vendor/src/uplc/ast/uplc_type.h+  vendor/src/uplc/ast/uplc_type_kind.h+  vendor/src/uplc/builtins/bls.c+  vendor/src/uplc/builtins/bls.h+  vendor/src/uplc/builtins/builtins.c+  vendor/src/uplc/builtins/builtins.h+  vendor/src/uplc/builtins/uplc_builtin.c+  vendor/src/uplc/builtins/uplc_builtin.h+  vendor/src/uplc/builtins/uplc_builtin_outcome.h+  vendor/src/uplc/builtins/uplc_builtin_semantics.c+  vendor/src/uplc/builtins/uplc_builtin_semantics.h+  vendor/src/uplc/builtins/uplc_byte_view.h+  vendor/src/uplc/cost/uplc_builtin_cost.h+  vendor/src/uplc/cost/uplc_builtin_cost_arity.h+  vendor/src/uplc/cost/uplc_builtin_costs.c+  vendor/src/uplc/cost/uplc_builtin_costs.h+  vendor/src/uplc/cost/uplc_const_or_linear_cost.h+  vendor/src/uplc/cost/uplc_const_or_two_arg_cost.h+  vendor/src/uplc/cost/uplc_cost_model.c+  vendor/src/uplc/cost/uplc_cost_model.h+  vendor/src/uplc/cost/uplc_cost_model_version.h+  vendor/src/uplc/cost/uplc_cost_sat.c+  vendor/src/uplc/cost/uplc_cost_sat.h+  vendor/src/uplc/cost/uplc_diag_model_kind.h+  vendor/src/uplc/cost/uplc_ex_mem.c+  vendor/src/uplc/cost/uplc_ex_mem.h+  vendor/src/uplc/cost/uplc_exp_mod_cost.h+  vendor/src/uplc/cost/uplc_four_arg_cost.c+  vendor/src/uplc/cost/uplc_four_arg_cost.h+  vendor/src/uplc/cost/uplc_four_arg_kind.h+  vendor/src/uplc/cost/uplc_linear_cost.h+  vendor/src/uplc/cost/uplc_machine_costs.c+  vendor/src/uplc/cost/uplc_machine_costs.h+  vendor/src/uplc/cost/uplc_one_arg_cost.c+  vendor/src/uplc/cost/uplc_one_arg_cost.h+  vendor/src/uplc/cost/uplc_one_arg_kind.h+  vendor/src/uplc/cost/uplc_quadratic_cost.h+  vendor/src/uplc/cost/uplc_selected_cost_model.c+  vendor/src/uplc/cost/uplc_selected_cost_model.h+  vendor/src/uplc/cost/uplc_six_arg_cost.c+  vendor/src/uplc/cost/uplc_six_arg_cost.h+  vendor/src/uplc/cost/uplc_six_arg_kind.h+  vendor/src/uplc/cost/uplc_step_accumulator.c+  vendor/src/uplc/cost/uplc_step_accumulator.h+  vendor/src/uplc/cost/uplc_step_kind.h+  vendor/src/uplc/cost/uplc_subtracted_sizes_cost.h+  vendor/src/uplc/cost/uplc_three_arg_cost.c+  vendor/src/uplc/cost/uplc_three_arg_cost.h+  vendor/src/uplc/cost/uplc_three_arg_kind.h+  vendor/src/uplc/cost/uplc_two_arg_cost.c+  vendor/src/uplc/cost/uplc_two_arg_cost.h+  vendor/src/uplc/cost/uplc_two_arg_kind.h+  vendor/src/uplc/cost/uplc_two_var_linear_cost.h+  vendor/src/uplc/cost/uplc_two_var_quadratic_cost.h+  vendor/src/uplc/cost/uplc_with_interaction_cost.h+  vendor/src/uplc/data/uplc_data.c+  vendor/src/uplc/data/uplc_data.h+  vendor/src/uplc/data/uplc_data_kind.h+  vendor/src/uplc/data/uplc_data_pair.h+  vendor/src/uplc/flat/flat_decode.c+  vendor/src/uplc/flat/flat_decode.h+  vendor/src/uplc/flat/flat_encode.c+  vendor/src/uplc/flat/flat_encode.h+  vendor/src/uplc/flat/flat_reader.c+  vendor/src/uplc/flat/flat_reader.h+  vendor/src/uplc/flat/flat_writer.c+  vendor/src/uplc/flat/flat_writer.h+  vendor/src/uplc/machine/uplc_budget.h+  vendor/src/uplc/machine/uplc_env.c+  vendor/src/uplc/machine/uplc_env.h+  vendor/src/uplc/machine/uplc_eval_result.h+  vendor/src/uplc/machine/uplc_eval_status.h+  vendor/src/uplc/machine/uplc_frame.c+  vendor/src/uplc/machine/uplc_frame.h+  vendor/src/uplc/machine/uplc_frame_kind.h+  vendor/src/uplc/machine/uplc_machine.c+  vendor/src/uplc/machine/uplc_machine.h+  vendor/src/uplc/machine/uplc_machine_version.h+  vendor/src/uplc/machine/uplc_state_kind.h+  vendor/src/uplc/machine/uplc_value.c+  vendor/src/uplc/machine/uplc_value.h+  vendor/src/uplc/machine/uplc_value_kind.h+  vendor/src/uplc/syntax/pretty.c+  vendor/src/uplc/syntax/pretty.h+  vendor/src/uplc/syntax/text_parser.c+  vendor/src/uplc/syntax/text_parser.h+  vendor/src/uplc/tx/script_context.c+  vendor/src/uplc/tx/script_context.h+  vendor/src/uplc/tx/uplc_apply_params.c+  vendor/src/voting_procedures/governance_action_id_list.c+  vendor/src/voting_procedures/vote.c+  vendor/src/voting_procedures/voter.c+  vendor/src/voting_procedures/voter_list.c+  vendor/src/voting_procedures/voter_type.c+  vendor/src/voting_procedures/voting_procedure.c+  vendor/src/voting_procedures/voting_procedure_list.c+  vendor/src/voting_procedures/voting_procedure_map.c+  vendor/src/voting_procedures/voting_procedure_map.h+  vendor/src/voting_procedures/voting_procedures.c+  vendor/src/witness_set/bootstrap_witness.c+  vendor/src/witness_set/bootstrap_witness_set.c+  vendor/src/witness_set/native_script_set.c+  vendor/src/witness_set/plutus_data_set.c+  vendor/src/witness_set/plutus_v1_script_set.c+  vendor/src/witness_set/plutus_v2_script_set.c+  vendor/src/witness_set/plutus_v3_script_set.c+  vendor/src/witness_set/plutus_v4_script_set.c+  vendor/src/witness_set/redeemer.c+  vendor/src/witness_set/redeemer_list.c+  vendor/src/witness_set/vkey_witness.c+  vendor/src/witness_set/vkey_witness_set.c+  vendor/src/witness_set/witness_set.c++library sodium+  visibility: private+  default-language: Haskell2010+  c-sources:+    vendor/external/libsodium/crypto_aead/chacha20poly1305/aead_chacha20poly1305.c+    vendor/external/libsodium/crypto_auth/crypto_auth.c+    vendor/external/libsodium/crypto_auth/hmacsha256/auth_hmacsha256.c+    vendor/external/libsodium/crypto_auth/hmacsha512/auth_hmacsha512.c+    vendor/external/libsodium/crypto_auth/hmacsha512256/auth_hmacsha512256.c+    vendor/external/libsodium/crypto_core/ed25519/core_ed25519.c+    vendor/external/libsodium/crypto_core/ed25519/core_ristretto255.c+    vendor/external/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c+    vendor/external/libsodium/crypto_core/hchacha20/core_hchacha20.c+    vendor/external/libsodium/crypto_core/hsalsa20/core_hsalsa20.c+    vendor/external/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20_ref2.c+    vendor/external/libsodium/crypto_core/salsa/ref/core_salsa_ref.c+    vendor/external/libsodium/crypto_generichash/blake2b/generichash_blake2.c+    vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.c+    vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c+    vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.c+    vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c+    vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c+    vendor/external/libsodium/crypto_generichash/blake2b/ref/generichash_blake2b.c+    vendor/external/libsodium/crypto_generichash/crypto_generichash.c+    vendor/external/libsodium/crypto_hash/crypto_hash.c+    vendor/external/libsodium/crypto_hash/sha256/cp/hash_sha256_cp.c+    vendor/external/libsodium/crypto_hash/sha256/hash_sha256.c+    vendor/external/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c+    vendor/external/libsodium/crypto_hash/sha512/hash_sha512.c+    vendor/external/libsodium/crypto_onetimeauth/crypto_onetimeauth.c+    vendor/external/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c+    vendor/external/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c+    vendor/external/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c+    vendor/external/libsodium/crypto_scalarmult/crypto_scalarmult.c+    vendor/external/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c+    vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c+    vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c+    vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c+    vendor/external/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c+    vendor/external/libsodium/crypto_scalarmult/ed25519/ref10/scalarmult_ed25519_ref10.c+    vendor/external/libsodium/crypto_secretstream/xchacha20poly1305/secretstream_xchacha20poly1305.c+    vendor/external/libsodium/crypto_sign/crypto_sign.c+    vendor/external/libsodium/crypto_sign/ed25519/ref10/keypair.c+    vendor/external/libsodium/crypto_sign/ed25519/ref10/obsolete.c+    vendor/external/libsodium/crypto_sign/ed25519/ref10/open.c+    vendor/external/libsodium/crypto_sign/ed25519/ref10/sign.c+    vendor/external/libsodium/crypto_sign/ed25519/sign_ed25519.c+    vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c+    vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c+    vendor/external/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c+    vendor/external/libsodium/crypto_stream/chacha20/stream_chacha20.c+    vendor/external/libsodium/crypto_stream/crypto_stream.c+    vendor/external/libsodium/crypto_stream/salsa20/ref/salsa20_ref.c+    vendor/external/libsodium/crypto_stream/salsa20/stream_salsa20.c+    vendor/external/libsodium/crypto_stream/salsa20/xmm6/salsa20_xmm6.c+    vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c+    vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c+    vendor/external/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012_ref.c+    vendor/external/libsodium/crypto_stream/salsa2012/stream_salsa2012.c+    vendor/external/libsodium/crypto_stream/salsa208/ref/stream_salsa208_ref.c+    vendor/external/libsodium/crypto_stream/salsa208/stream_salsa208.c+    vendor/external/libsodium/crypto_stream/xchacha20/stream_xchacha20.c+    vendor/external/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c+    vendor/external/libsodium/crypto_verify/verify.c+    vendor/external/libsodium/randombytes/internal/randombytes_internal_random.c+    vendor/external/libsodium/randombytes/randombytes.c+    vendor/external/libsodium/randombytes/sysrandom/randombytes_sysrandom.c+    vendor/external/libsodium/sodium/codecs.c+    vendor/external/libsodium/sodium/core.c+    vendor/external/libsodium/sodium/runtime.c+    vendor/external/libsodium/sodium/utils.c+    vendor/external/libsodium/sodium/version.c+  include-dirs:+    vendor+    vendor/include+    vendor/external/libsodium/include+    vendor/external/libsodium/include/sodium+    vendor/external/gmp+    vendor/external/sha3+    vendor/external/ripemd160+    vendor/external/secp256k1/include+    vendor/external/blst/bindings+  cc-options: -std=c99 -DSODIUM_STATIC -DJSONC_STATIC -w+  if !os(windows)+    cc-options: -DHAVE_PTHREAD=1+    extra-libraries: pthread++library gmp+  visibility: private+  default-language: Haskell2010+  c-sources:+    vendor/external/gmp/mini-gmp.c+  include-dirs:+    vendor+    vendor/include+    vendor/external/libsodium/include+    vendor/external/libsodium/include/sodium+    vendor/external/gmp+    vendor/external/sha3+    vendor/external/ripemd160+    vendor/external/secp256k1/include+    vendor/external/blst/bindings+  cc-options: -std=c99 -DSODIUM_STATIC -DJSONC_STATIC -w++library sha3+  visibility: private+  default-language: Haskell2010+  c-sources:+    vendor/external/sha3/sha3.c+  include-dirs:+    vendor+    vendor/include+    vendor/external/libsodium/include+    vendor/external/libsodium/include/sodium+    vendor/external/gmp+    vendor/external/sha3+    vendor/external/ripemd160+    vendor/external/secp256k1/include+    vendor/external/blst/bindings+  cc-options: -std=c99 -DSODIUM_STATIC -DJSONC_STATIC -w++library ripemd160+  visibility: private+  default-language: Haskell2010+  c-sources:+    vendor/external/ripemd160/ripemd160.c+  include-dirs:+    vendor+    vendor/include+    vendor/external/libsodium/include+    vendor/external/libsodium/include/sodium+    vendor/external/gmp+    vendor/external/sha3+    vendor/external/ripemd160+    vendor/external/secp256k1/include+    vendor/external/blst/bindings+  cc-options: -std=c99 -DSODIUM_STATIC -DJSONC_STATIC -w++library secp256k1+  visibility: private+  default-language: Haskell2010+  c-sources:+    vendor/external/secp256k1/src/precomputed_ecmult.c+    vendor/external/secp256k1/src/precomputed_ecmult_gen.c+    vendor/external/secp256k1/src/secp256k1.c+  include-dirs:+    vendor+    vendor/include+    vendor/external/libsodium/include+    vendor/external/libsodium/include/sodium+    vendor/external/gmp+    vendor/external/sha3+    vendor/external/ripemd160+    vendor/external/secp256k1/include+    vendor/external/blst/bindings+  cc-options: -std=c99 -DSODIUM_STATIC -DJSONC_STATIC -w -DENABLE_MODULE_EXTRAKEYS=1 -DENABLE_MODULE_SCHNORRSIG=1 -DECMULT_WINDOW_SIZE=8 -DSECP256K1_STATIC++library blst+  visibility: private+  default-language: Haskell2010+  c-sources:+    vendor/external/blst/src/server.c+  include-dirs:+    vendor+    vendor/include+    vendor/external/libsodium/include+    vendor/external/libsodium/include/sodium+    vendor/external/gmp+    vendor/external/sha3+    vendor/external/ripemd160+    vendor/external/secp256k1/include+    vendor/external/blst/bindings+  cc-options: -std=c99 -DSODIUM_STATIC -DJSONC_STATIC -w -D__BLST_NO_ASM__ -D__BLST_PORTABLE__++library+  default-language: Haskell2010+  build-depends: sodium, gmp, sha3, ripemd160, secp256k1, blst+  c-sources:+    vendor/src/address/address.c+    vendor/src/address/base_address.c+    vendor/src/address/byron_address.c+    vendor/src/address/enterprise_address.c+    vendor/src/address/internals/addr_common.c+    vendor/src/address/internals/base_addr_pack.c+    vendor/src/address/internals/byron_addr_pack.c+    vendor/src/address/internals/enterprise_addr_pack.c+    vendor/src/address/internals/pointer_addr_pack.c+    vendor/src/address/internals/reward_addr_pack.c+    vendor/src/address/pointer_address.c+    vendor/src/address/reward_address.c+    vendor/src/allocators.c+    vendor/src/assets/asset_id.c+    vendor/src/assets/asset_id_list.c+    vendor/src/assets/asset_id_map.c+    vendor/src/assets/asset_name.c+    vendor/src/assets/asset_name_list.c+    vendor/src/assets/asset_name_map.c+    vendor/src/assets/multi_asset.c+    vendor/src/assets/policy_id_list.c+    vendor/src/auxiliary_data/auxiliary_data.c+    vendor/src/auxiliary_data/metadatum.c+    vendor/src/auxiliary_data/metadatum_label_list.c+    vendor/src/auxiliary_data/metadatum_list.c+    vendor/src/auxiliary_data/metadatum_map.c+    vendor/src/auxiliary_data/plutus_v1_script_list.c+    vendor/src/auxiliary_data/plutus_v2_script_list.c+    vendor/src/auxiliary_data/plutus_v3_script_list.c+    vendor/src/auxiliary_data/plutus_v4_script_list.c+    vendor/src/auxiliary_data/transaction_metadata.c+    vendor/src/bip39/bip39.c+    vendor/src/buffer/buffer.c+    vendor/src/cardano.c+    vendor/src/cbor/cbor_initial_byte.c+    vendor/src/cbor/cbor_major_type.c+    vendor/src/cbor/cbor_reader/cbor_reader.c+    vendor/src/cbor/cbor_reader/cbor_reader_collections.c+    vendor/src/cbor/cbor_reader/cbor_reader_core.c+    vendor/src/cbor/cbor_reader/cbor_reader_numeric.c+    vendor/src/cbor/cbor_reader/cbor_reader_simple_values.c+    vendor/src/cbor/cbor_reader/cbor_reader_tags.c+    vendor/src/cbor/cbor_reader_state.c+    vendor/src/cbor/cbor_simple_value.c+    vendor/src/cbor/cbor_tag.c+    vendor/src/cbor/cbor_validation.c+    vendor/src/cbor/cbor_writer.c+    vendor/src/certs/auth_committee_hot_cert.c+    vendor/src/certs/cert_type.c+    vendor/src/certs/certificate.c+    vendor/src/certs/certificate_set.c+    vendor/src/certs/genesis_key_delegation_cert.c+    vendor/src/certs/mir_cert.c+    vendor/src/certs/mir_to_pot_cert.c+    vendor/src/certs/mir_to_stake_creds_cert.c+    vendor/src/certs/pool_registration_cert.c+    vendor/src/certs/pool_retirement_cert.c+    vendor/src/certs/register_drep_cert.c+    vendor/src/certs/registration_cert.c+    vendor/src/certs/resign_committee_cold_cert.c+    vendor/src/certs/stake_delegation_cert.c+    vendor/src/certs/stake_deregistration_cert.c+    vendor/src/certs/stake_registration_cert.c+    vendor/src/certs/stake_registration_delegation_cert.c+    vendor/src/certs/stake_vote_delegation_cert.c+    vendor/src/certs/stake_vote_registration_delegation_cert.c+    vendor/src/certs/unregister_drep_cert.c+    vendor/src/certs/unregistration_cert.c+    vendor/src/certs/update_drep_cert.c+    vendor/src/certs/vote_delegation_cert.c+    vendor/src/certs/vote_registration_delegation_cert.c+    vendor/src/collections/array.c+    vendor/src/collections/set.c+    vendor/src/common/anchor.c+    vendor/src/common/bigint.c+    vendor/src/common/credential.c+    vendor/src/common/datum.c+    vendor/src/common/drep.c+    vendor/src/common/ex_units.c+    vendor/src/common/governance_action_id.c+    vendor/src/common/guard_set.c+    vendor/src/common/ledger_order.c+    vendor/src/common/network_magic.c+    vendor/src/common/protocol_version.c+    vendor/src/common/reward_address_list.c+    vendor/src/common/unit_interval.c+    vendor/src/common/utxo.c+    vendor/src/common/utxo_list.c+    vendor/src/common/withdrawal_map.c+    vendor/src/crypto/arithmetic.c+    vendor/src/crypto/bip32_key_derivation.c+    vendor/src/crypto/bip32_private_key.c+    vendor/src/crypto/bip32_public_key.c+    vendor/src/crypto/blake2b_hash.c+    vendor/src/crypto/blake2b_hash_set.c+    vendor/src/crypto/crc32.c+    vendor/src/crypto/ed25519_private_key.c+    vendor/src/crypto/ed25519_public_key.c+    vendor/src/crypto/ed25519_signature.c+    vendor/src/crypto/emip3.c+    vendor/src/crypto/pbkdf2.c+    vendor/src/encoding/base58.c+    vendor/src/encoding/bech32.c+    vendor/src/endian.c+    vendor/src/error.c+    vendor/src/json/internals/json_object_common.c+    vendor/src/json/internals/json_object_serialization.c+    vendor/src/json/internals/json_parser.c+    vendor/src/json/internals/json_writer_common.c+    vendor/src/json/internals/utf8.c+    vendor/src/json/json_object.c+    vendor/src/json/json_writer.c+    vendor/src/key_handlers/secure_key_handler.c+    vendor/src/key_handlers/software_secure_key_handler.c+    vendor/src/message_signing/cip8.c+    vendor/src/object.c+    vendor/src/plutus_data/constr_plutus_data.c+    vendor/src/plutus_data/plutus_data.c+    vendor/src/plutus_data/plutus_list.c+    vendor/src/plutus_data/plutus_map.c+    vendor/src/pool_params/bls_key.c+    vendor/src/pool_params/ipv4.c+    vendor/src/pool_params/ipv6.c+    vendor/src/pool_params/multi_host_name_relay.c+    vendor/src/pool_params/pool_metadata.c+    vendor/src/pool_params/pool_owners.c+    vendor/src/pool_params/pool_params.c+    vendor/src/pool_params/relay.c+    vendor/src/pool_params/relay_type.c+    vendor/src/pool_params/relays.c+    vendor/src/pool_params/single_host_addr_relay.c+    vendor/src/pool_params/single_host_name_relay.c+    vendor/src/proposal_procedures/committee.c+    vendor/src/proposal_procedures/committee_members_map.c+    vendor/src/proposal_procedures/constitution.c+    vendor/src/proposal_procedures/credential_set.c+    vendor/src/proposal_procedures/governance_action_type.c+    vendor/src/proposal_procedures/hard_fork_initiation_action.c+    vendor/src/proposal_procedures/info_action.c+    vendor/src/proposal_procedures/new_constitution_action.c+    vendor/src/proposal_procedures/no_confidence_action.c+    vendor/src/proposal_procedures/parameter_change_action.c+    vendor/src/proposal_procedures/proposal_procedure.c+    vendor/src/proposal_procedures/proposal_procedure_set.c+    vendor/src/proposal_procedures/treasury_withdrawals_action.c+    vendor/src/proposal_procedures/update_committee_action.c+    vendor/src/protocol_params/cost_model.c+    vendor/src/protocol_params/costmdls.c+    vendor/src/protocol_params/drep_voting_thresholds.c+    vendor/src/protocol_params/ex_unit_prices.c+    vendor/src/protocol_params/pool_voting_thresholds.c+    vendor/src/protocol_params/proposed_param_updates.c+    vendor/src/protocol_params/protocol_param_update.c+    vendor/src/protocol_params/protocol_parameters.c+    vendor/src/protocol_params/update.c+    vendor/src/providers/emscripten/emscripten_provider.c+    vendor/src/providers/provider.c+    vendor/src/scripts/native_scripts/native_script.c+    vendor/src/scripts/native_scripts/native_script_list.c+    vendor/src/scripts/native_scripts/native_script_type.c+    vendor/src/scripts/native_scripts/script_all.c+    vendor/src/scripts/native_scripts/script_any.c+    vendor/src/scripts/native_scripts/script_invalid_after.c+    vendor/src/scripts/native_scripts/script_invalid_before.c+    vendor/src/scripts/native_scripts/script_n_of_k.c+    vendor/src/scripts/native_scripts/script_pubkey.c+    vendor/src/scripts/native_scripts/script_require_guard.c+    vendor/src/scripts/plutus_scripts/plutus_v1_script.c+    vendor/src/scripts/plutus_scripts/plutus_v2_script.c+    vendor/src/scripts/plutus_scripts/plutus_v3_script.c+    vendor/src/scripts/plutus_scripts/plutus_v4_script.c+    vendor/src/scripts/script.c+    vendor/src/string_safe.c+    vendor/src/time.c+    vendor/src/transaction/sub_transaction.c+    vendor/src/transaction/transaction.c+    vendor/src/transaction_body/account_balance_interval.c+    vendor/src/transaction_body/account_balance_intervals_map.c+    vendor/src/transaction_body/direct_deposit_map.c+    vendor/src/transaction_body/internals/body_fields.c+    vendor/src/transaction_body/required_guards_map.c+    vendor/src/transaction_body/sub_transaction_body.c+    vendor/src/transaction_body/sub_transaction_set.c+    vendor/src/transaction_body/transaction_body.c+    vendor/src/transaction_body/transaction_input.c+    vendor/src/transaction_body/transaction_input_set.c+    vendor/src/transaction_body/transaction_output.c+    vendor/src/transaction_body/transaction_output_list.c+    vendor/src/transaction_body/value.c+    vendor/src/transaction_builder/balancing/deferred_redeemer_list.c+    vendor/src/transaction_builder/balancing/implicit_coin.c+    vendor/src/transaction_builder/balancing/input_to_redeemer_map.c+    vendor/src/transaction_builder/balancing/internals/collateral.c+    vendor/src/transaction_builder/balancing/internals/pool_deposits.c+    vendor/src/transaction_builder/balancing/internals/scripts_needed.c+    vendor/src/transaction_builder/balancing/internals/unique_signers.c+    vendor/src/transaction_builder/balancing/transaction_balancing.c+    vendor/src/transaction_builder/coin_selection/coin_selector.c+    vendor/src/transaction_builder/coin_selection/internals/change_builder.c+    vendor/src/transaction_builder/coin_selection/internals/emscripten_coin_selector.c+    vendor/src/transaction_builder/coin_selection/internals/large_first_coin_selector.c+    vendor/src/transaction_builder/coin_selection/internals/large_first_helpers.c+    vendor/src/transaction_builder/coin_selection/internals/random_improve_change_state.c+    vendor/src/transaction_builder/coin_selection/internals/random_improve_coin_selector.c+    vendor/src/transaction_builder/coin_selection/internals/random_improve_helpers.c+    vendor/src/transaction_builder/coin_selection/internals/random_improve_selection_index.c+    vendor/src/transaction_builder/coin_selection/internals/random_improve_utxo_utils.c+    vendor/src/transaction_builder/coin_selection/internals/value_splitting.c+    vendor/src/transaction_builder/evaluation/emscripten_tx_evaluator.c+    vendor/src/transaction_builder/evaluation/native_tx_evaluator.c+    vendor/src/transaction_builder/evaluation/provider_tx_evaluator.c+    vendor/src/transaction_builder/evaluation/tx_evaluator.c+    vendor/src/transaction_builder/fee.c+    vendor/src/transaction_builder/internals/blake2b_hash_to_redeemer_map.c+    vendor/src/transaction_builder/internals/builder_build.c+    vendor/src/transaction_builder/internals/builder_certs.c+    vendor/src/transaction_builder/internals/builder_config.c+    vendor/src/transaction_builder/internals/builder_entities.c+    vendor/src/transaction_builder/internals/builder_inputs.c+    vendor/src/transaction_builder/internals/builder_mint.c+    vendor/src/transaction_builder/internals/builder_outputs.c+    vendor/src/transaction_builder/internals/builder_proposals.c+    vendor/src/transaction_builder/internals/builder_redeemers.c+    vendor/src/transaction_builder/internals/builder_state.c+    vendor/src/transaction_builder/internals/builder_sub_build.c+    vendor/src/transaction_builder/internals/builder_sub_transactions.c+    vendor/src/transaction_builder/internals/builder_votes.c+    vendor/src/transaction_builder/internals/builder_withdrawals.c+    vendor/src/transaction_builder/internals/builder_witnesses.c+    vendor/src/transaction_builder/internals/created_output_scripts.c+    vendor/src/transaction_builder/script_data_hash.c+    vendor/src/transaction_builder/sub_transaction_builder.c+    vendor/src/transaction_builder/transaction_builder.c+    vendor/src/uplc/arena/uplc_arena.c+    vendor/src/uplc/ast/uplc_constant.c+    vendor/src/uplc/ast/uplc_int.c+    vendor/src/uplc/ast/uplc_int_math.c+    vendor/src/uplc/ast/uplc_lang_version.c+    vendor/src/uplc/ast/uplc_program.c+    vendor/src/uplc/ast/uplc_term.c+    vendor/src/uplc/ast/uplc_type.c+    vendor/src/uplc/builtins/bls.c+    vendor/src/uplc/builtins/builtins.c+    vendor/src/uplc/builtins/uplc_builtin.c+    vendor/src/uplc/builtins/uplc_builtin_semantics.c+    vendor/src/uplc/cost/uplc_builtin_costs.c+    vendor/src/uplc/cost/uplc_cost_model.c+    vendor/src/uplc/cost/uplc_cost_sat.c+    vendor/src/uplc/cost/uplc_ex_mem.c+    vendor/src/uplc/cost/uplc_four_arg_cost.c+    vendor/src/uplc/cost/uplc_machine_costs.c+    vendor/src/uplc/cost/uplc_one_arg_cost.c+    vendor/src/uplc/cost/uplc_selected_cost_model.c+    vendor/src/uplc/cost/uplc_six_arg_cost.c+    vendor/src/uplc/cost/uplc_step_accumulator.c+    vendor/src/uplc/cost/uplc_three_arg_cost.c+    vendor/src/uplc/cost/uplc_two_arg_cost.c+    vendor/src/uplc/data/uplc_data.c+    vendor/src/uplc/flat/flat_decode.c+    vendor/src/uplc/flat/flat_encode.c+    vendor/src/uplc/flat/flat_reader.c+    vendor/src/uplc/flat/flat_writer.c+    vendor/src/uplc/machine/uplc_env.c+    vendor/src/uplc/machine/uplc_frame.c+    vendor/src/uplc/machine/uplc_machine.c+    vendor/src/uplc/machine/uplc_value.c+    vendor/src/uplc/syntax/pretty.c+    vendor/src/uplc/syntax/text_parser.c+    vendor/src/uplc/tx/script_context.c+    vendor/src/uplc/tx/uplc_apply_params.c+    vendor/src/voting_procedures/governance_action_id_list.c+    vendor/src/voting_procedures/vote.c+    vendor/src/voting_procedures/voter.c+    vendor/src/voting_procedures/voter_list.c+    vendor/src/voting_procedures/voter_type.c+    vendor/src/voting_procedures/voting_procedure.c+    vendor/src/voting_procedures/voting_procedure_list.c+    vendor/src/voting_procedures/voting_procedure_map.c+    vendor/src/voting_procedures/voting_procedures.c+    vendor/src/witness_set/bootstrap_witness.c+    vendor/src/witness_set/bootstrap_witness_set.c+    vendor/src/witness_set/native_script_set.c+    vendor/src/witness_set/plutus_data_set.c+    vendor/src/witness_set/plutus_v1_script_set.c+    vendor/src/witness_set/plutus_v2_script_set.c+    vendor/src/witness_set/plutus_v3_script_set.c+    vendor/src/witness_set/plutus_v4_script_set.c+    vendor/src/witness_set/redeemer.c+    vendor/src/witness_set/redeemer_list.c+    vendor/src/witness_set/vkey_witness.c+    vendor/src/witness_set/vkey_witness_set.c+    vendor/src/witness_set/witness_set.c+  include-dirs:+    vendor+    vendor/include+    vendor/external/libsodium/include+    vendor/external/libsodium/include/sodium+    vendor/external/gmp+    vendor/external/sha3+    vendor/external/ripemd160+    vendor/external/secp256k1/include+    vendor/external/blst/bindings+  install-includes:+    cardano/address/address.h+    cardano/address/address_type.h+    cardano/address/base_address.h+    cardano/address/byron_address.h+    cardano/address/byron_address_attributes.h+    cardano/address/byron_address_type.h+    cardano/address/enterprise_address.h+    cardano/address/pointer_address.h+    cardano/address/reward_address.h+    cardano/address/stake_pointer.h+    cardano/assets/asset_id.h+    cardano/assets/asset_id_list.h+    cardano/assets/asset_id_map.h+    cardano/assets/asset_name.h+    cardano/assets/asset_name_list.h+    cardano/assets/asset_name_map.h+    cardano/assets/multi_asset.h+    cardano/assets/policy_id_list.h+    cardano/auxiliary_data/auxiliary_data.h+    cardano/auxiliary_data/metadatum.h+    cardano/auxiliary_data/metadatum_kind.h+    cardano/auxiliary_data/metadatum_label_list.h+    cardano/auxiliary_data/metadatum_list.h+    cardano/auxiliary_data/metadatum_map.h+    cardano/auxiliary_data/plutus_v1_script_list.h+    cardano/auxiliary_data/plutus_v2_script_list.h+    cardano/auxiliary_data/plutus_v3_script_list.h+    cardano/auxiliary_data/plutus_v4_script_list.h+    cardano/auxiliary_data/transaction_metadata.h+    cardano/bip39.h+    cardano/buffer.h+    cardano/cardano.h+    cardano/cbor/cbor_major_type.h+    cardano/cbor/cbor_reader.h+    cardano/cbor/cbor_reader_state.h+    cardano/cbor/cbor_simple_value.h+    cardano/cbor/cbor_tag.h+    cardano/cbor/cbor_writer.h+    cardano/certs/auth_committee_hot_cert.h+    cardano/certs/cert_type.h+    cardano/certs/certificate.h+    cardano/certs/certificate_set.h+    cardano/certs/genesis_key_delegation_cert.h+    cardano/certs/mir_cert.h+    cardano/certs/mir_cert_pot_type.h+    cardano/certs/mir_cert_type.h+    cardano/certs/mir_to_pot_cert.h+    cardano/certs/mir_to_stake_creds_cert.h+    cardano/certs/pool_registration_cert.h+    cardano/certs/pool_retirement_cert.h+    cardano/certs/register_drep_cert.h+    cardano/certs/registration_cert.h+    cardano/certs/resign_committee_cold_cert.h+    cardano/certs/stake_delegation_cert.h+    cardano/certs/stake_deregistration_cert.h+    cardano/certs/stake_registration_cert.h+    cardano/certs/stake_registration_delegation_cert.h+    cardano/certs/stake_vote_delegation_cert.h+    cardano/certs/stake_vote_registration_delegation_cert.h+    cardano/certs/unregister_drep_cert.h+    cardano/certs/unregistration_cert.h+    cardano/certs/update_drep_cert.h+    cardano/certs/vote_delegation_cert.h+    cardano/certs/vote_registration_delegation_cert.h+    cardano/common/anchor.h+    cardano/common/bigint.h+    cardano/common/byte_order.h+    cardano/common/credential.h+    cardano/common/credential_type.h+    cardano/common/datum.h+    cardano/common/datum_type.h+    cardano/common/drep.h+    cardano/common/drep_type.h+    cardano/common/ex_units.h+    cardano/common/governance_action_id.h+    cardano/common/governance_key_type.h+    cardano/common/guard_set.h+    cardano/common/network_id.h+    cardano/common/network_magic.h+    cardano/common/protocol_version.h+    cardano/common/reward_address_list.h+    cardano/common/unit_interval.h+    cardano/common/utxo.h+    cardano/common/utxo_list.h+    cardano/common/withdrawal_map.h+    cardano/crypto/bip32_private_key.h+    cardano/crypto/bip32_public_key.h+    cardano/crypto/blake2b_hash.h+    cardano/crypto/blake2b_hash_set.h+    cardano/crypto/blake2b_hash_size.h+    cardano/crypto/crc32.h+    cardano/crypto/ed25519_private_key.h+    cardano/crypto/ed25519_public_key.h+    cardano/crypto/ed25519_signature.h+    cardano/crypto/emip3.h+    cardano/crypto/pbkdf2.h+    cardano/encoding/base58.h+    cardano/encoding/bech32.h+    cardano/error.h+    cardano/export.h+    cardano/json/json_context.h+    cardano/json/json_format.h+    cardano/json/json_object.h+    cardano/json/json_object_type.h+    cardano/json/json_writer.h+    cardano/key_handlers/account_derivation_path.h+    cardano/key_handlers/cip_1852_constants.h+    cardano/key_handlers/derivation_path.h+    cardano/key_handlers/secure_key_handler.h+    cardano/key_handlers/secure_key_handler_impl.h+    cardano/key_handlers/secure_key_handler_type.h+    cardano/key_handlers/software_secure_key_handler.h+    cardano/message_signing/cip8.h+    cardano/object.h+    cardano/plutus_data/constr_plutus_data.h+    cardano/plutus_data/plutus_data.h+    cardano/plutus_data/plutus_data_kind.h+    cardano/plutus_data/plutus_list.h+    cardano/plutus_data/plutus_map.h+    cardano/pool_params/bls_key.h+    cardano/pool_params/ipv4.h+    cardano/pool_params/ipv6.h+    cardano/pool_params/multi_host_name_relay.h+    cardano/pool_params/pool_metadata.h+    cardano/pool_params/pool_owners.h+    cardano/pool_params/pool_params.h+    cardano/pool_params/relay.h+    cardano/pool_params/relay_type.h+    cardano/pool_params/relays.h+    cardano/pool_params/single_host_addr_relay.h+    cardano/pool_params/single_host_name_relay.h+    cardano/proposal_procedures/committee.h+    cardano/proposal_procedures/committee_members_map.h+    cardano/proposal_procedures/constitution.h+    cardano/proposal_procedures/credential_set.h+    cardano/proposal_procedures/governance_action_type.h+    cardano/proposal_procedures/hard_fork_initiation_action.h+    cardano/proposal_procedures/info_action.h+    cardano/proposal_procedures/new_constitution_action.h+    cardano/proposal_procedures/no_confidence_action.h+    cardano/proposal_procedures/parameter_change_action.h+    cardano/proposal_procedures/proposal_procedure.h+    cardano/proposal_procedures/proposal_procedure_set.h+    cardano/proposal_procedures/treasury_withdrawals_action.h+    cardano/proposal_procedures/update_committee_action.h+    cardano/protocol_params/cost_model.h+    cardano/protocol_params/costmdls.h+    cardano/protocol_params/drep_voting_thresholds.h+    cardano/protocol_params/ex_unit_prices.h+    cardano/protocol_params/pool_voting_thresholds.h+    cardano/protocol_params/proposed_param_updates.h+    cardano/protocol_params/protocol_param_update.h+    cardano/protocol_params/protocol_parameters.h+    cardano/protocol_params/update.h+    cardano/providers/provider.h+    cardano/providers/provider_impl.h+    cardano/scripts/native_scripts/native_script.h+    cardano/scripts/native_scripts/native_script_list.h+    cardano/scripts/native_scripts/native_script_type.h+    cardano/scripts/native_scripts/script_all.h+    cardano/scripts/native_scripts/script_any.h+    cardano/scripts/native_scripts/script_invalid_after.h+    cardano/scripts/native_scripts/script_invalid_before.h+    cardano/scripts/native_scripts/script_n_of_k.h+    cardano/scripts/native_scripts/script_pubkey.h+    cardano/scripts/native_scripts/script_require_guard.h+    cardano/scripts/plutus_scripts/plutus_language_version.h+    cardano/scripts/plutus_scripts/plutus_v1_script.h+    cardano/scripts/plutus_scripts/plutus_v2_script.h+    cardano/scripts/plutus_scripts/plutus_v3_script.h+    cardano/scripts/plutus_scripts/plutus_v4_script.h+    cardano/scripts/script.h+    cardano/scripts/script_language.h+    cardano/slot_config.h+    cardano/time.h+    cardano/transaction/sub_transaction.h+    cardano/transaction/transaction.h+    cardano/transaction_body/account_balance_interval.h+    cardano/transaction_body/account_balance_intervals_map.h+    cardano/transaction_body/direct_deposit_map.h+    cardano/transaction_body/required_guards_map.h+    cardano/transaction_body/sub_transaction_body.h+    cardano/transaction_body/sub_transaction_set.h+    cardano/transaction_body/transaction_body.h+    cardano/transaction_body/transaction_input.h+    cardano/transaction_body/transaction_input_set.h+    cardano/transaction_body/transaction_output.h+    cardano/transaction_body/transaction_output_list.h+    cardano/transaction_body/value.h+    cardano/transaction_builder/balancing/deferred_redeemer_list.h+    cardano/transaction_builder/balancing/implicit_coin.h+    cardano/transaction_builder/balancing/input_to_redeemer_map.h+    cardano/transaction_builder/balancing/transaction_balancing.h+    cardano/transaction_builder/coin_selection/coin_selection_request.h+    cardano/transaction_builder/coin_selection/coin_selection_strategy.h+    cardano/transaction_builder/coin_selection/coin_selector.h+    cardano/transaction_builder/coin_selection/coin_selector_impl.h+    cardano/transaction_builder/coin_selection/large_first_coin_selector.h+    cardano/transaction_builder/coin_selection/random_improve_coin_selector.h+    cardano/transaction_builder/evaluation/native_tx_evaluator.h+    cardano/transaction_builder/evaluation/provider_tx_evaluator.h+    cardano/transaction_builder/evaluation/tx_evaluator.h+    cardano/transaction_builder/evaluation/tx_evaluator_impl.h+    cardano/transaction_builder/fee.h+    cardano/transaction_builder/script_data_hash.h+    cardano/transaction_builder/sub_transaction_builder.h+    cardano/transaction_builder/transaction_builder.h+    cardano/typedefs.h+    cardano/uplc/uplc_apply_params.h+    cardano/voting_procedures/governance_action_id_list.h+    cardano/voting_procedures/vote.h+    cardano/voting_procedures/voter.h+    cardano/voting_procedures/voter_list.h+    cardano/voting_procedures/voter_type.h+    cardano/voting_procedures/voting_procedure.h+    cardano/voting_procedures/voting_procedure_list.h+    cardano/voting_procedures/voting_procedures.h+    cardano/witness_set/bootstrap_witness.h+    cardano/witness_set/bootstrap_witness_set.h+    cardano/witness_set/native_script_set.h+    cardano/witness_set/plutus_data_set.h+    cardano/witness_set/plutus_v1_script_set.h+    cardano/witness_set/plutus_v2_script_set.h+    cardano/witness_set/plutus_v3_script_set.h+    cardano/witness_set/plutus_v4_script_set.h+    cardano/witness_set/redeemer.h+    cardano/witness_set/redeemer_list.h+    cardano/witness_set/redeemer_tag.h+    cardano/witness_set/vkey_witness.h+    cardano/witness_set/vkey_witness_set.h+    cardano/witness_set/witness_set.h+  cc-options: -std=c99 -DSODIUM_STATIC -DJSONC_STATIC+  if !os(windows)+    extra-libraries: m, pthread
+ licenses/CC0-1.0.txt view
@@ -0,0 +1,121 @@+Creative Commons Legal Code++CC0 1.0 Universal++    CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE+    LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN+    ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS+    INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES+    REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS+    PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM+    THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED+    HEREUNDER.++Statement of Purpose++The laws of most jurisdictions throughout the world automatically confer+exclusive Copyright and Related Rights (defined below) upon the creator+and subsequent owner(s) (each and all, an "owner") of an original work of+authorship and/or a database (each, a "Work").++Certain owners wish to permanently relinquish those rights to a Work for+the purpose of contributing to a commons of creative, cultural and+scientific works ("Commons") that the public can reliably and without fear+of later claims of infringement build upon, modify, incorporate in other+works, reuse and redistribute as freely as possible in any form whatsoever+and for any purposes, including without limitation commercial purposes.+These owners may contribute to the Commons to promote the ideal of a free+culture and the further production of creative, cultural and scientific+works, or to gain reputation or greater distribution for their Work in+part through the use and efforts of others.++For these and/or other purposes and motivations, and without any+expectation of additional consideration or compensation, the person+associating CC0 with a Work (the "Affirmer"), to the extent that he or she+is an owner of Copyright and Related Rights in the Work, voluntarily+elects to apply CC0 to the Work and publicly distribute the Work under its+terms, with knowledge of his or her Copyright and Related Rights in the+Work and the meaning and intended legal effect of CC0 on those rights.++1. Copyright and Related Rights. A Work made available under CC0 may be+protected by copyright and related or neighboring rights ("Copyright and+Related Rights"). Copyright and Related Rights include, but are not+limited to, the following:++  i. the right to reproduce, adapt, distribute, perform, display,+     communicate, and translate a Work;+ ii. moral rights retained by the original author(s) and/or performer(s);+iii. publicity and privacy rights pertaining to a person's image or+     likeness depicted in a Work;+ iv. rights protecting against unfair competition in regards to a Work,+     subject to the limitations in paragraph 4(a), below;+  v. rights protecting the extraction, dissemination, use and reuse of data+     in a Work;+ vi. database rights (such as those arising under Directive 96/9/EC of the+     European Parliament and of the Council of 11 March 1996 on the legal+     protection of databases, and under any national implementation+     thereof, including any amended or successor version of such+     directive); and+vii. other similar, equivalent or corresponding rights throughout the+     world based on applicable law or treaty, and any national+     implementations thereof.++2. Waiver. To the greatest extent permitted by, but not in contravention+of, applicable law, Affirmer hereby overtly, fully, permanently,+irrevocably and unconditionally waives, abandons, and surrenders all of+Affirmer's Copyright and Related Rights and associated claims and causes+of action, whether now known or unknown (including existing as well as+future claims and causes of action), in the Work (i) in all territories+worldwide, (ii) for the maximum duration provided by applicable law or+treaty (including future time extensions), (iii) in any current or future+medium and for any number of copies, and (iv) for any purpose whatsoever,+including without limitation commercial, advertising or promotional+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each+member of the public at large and to the detriment of Affirmer's heirs and+successors, fully intending that such Waiver shall not be subject to+revocation, rescission, cancellation, termination, or any other legal or+equitable action to disrupt the quiet enjoyment of the Work by the public+as contemplated by Affirmer's express Statement of Purpose.++3. Public License Fallback. Should any part of the Waiver for any reason+be judged legally invalid or ineffective under applicable law, then the+Waiver shall be preserved to the maximum extent permitted taking into+account Affirmer's express Statement of Purpose. In addition, to the+extent the Waiver is so judged Affirmer hereby grants to each affected+person a royalty-free, non transferable, non sublicensable, non exclusive,+irrevocable and unconditional license to exercise Affirmer's Copyright and+Related Rights in the Work (i) in all territories worldwide, (ii) for the+maximum duration provided by applicable law or treaty (including future+time extensions), (iii) in any current or future medium and for any number+of copies, and (iv) for any purpose whatsoever, including without+limitation commercial, advertising or promotional purposes (the+"License"). The License shall be deemed effective as of the date CC0 was+applied by Affirmer to the Work. Should any part of the License for any+reason be judged legally invalid or ineffective under applicable law, such+partial invalidity or ineffectiveness shall not invalidate the remainder+of the License, and in such case Affirmer hereby affirms that he or she+will not (i) exercise any of his or her remaining Copyright and Related+Rights in the Work or (ii) assert any associated claims and causes of+action with respect to the Work, in either case contrary to Affirmer's+express Statement of Purpose.++4. Limitations and Disclaimers.++ a. No trademark or patent rights held by Affirmer are waived, abandoned,+    surrendered, licensed or otherwise affected by this document.+ b. Affirmer offers the Work as-is and makes no representations or+    warranties of any kind concerning the Work, express, implied,+    statutory or otherwise, including without limitation warranties of+    title, merchantability, fitness for a particular purpose, non+    infringement, or the absence of latent or other defects, accuracy, or+    the present or absence of errors, whether or not discoverable, all to+    the greatest extent permissible under applicable law.+ c. Affirmer disclaims responsibility for clearing rights of other persons+    that may apply to the Work or any use thereof, including without+    limitation any person's Copyright and Related Rights in the Work.+    Further, Affirmer disclaims responsibility for obtaining any necessary+    consents, permissions or other rights required for any use of the+    Work.+ d. Affirmer understands and acknowledges that Creative Commons is not a+    party to this document and has no duty or obligation with respect to+    this CC0 or use of the Work.
+ licenses/GPL-2.0.txt view
@@ -0,0 +1,339 @@+                    GNU GENERAL PUBLIC LICENSE+                       Version 2, June 1991++ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++                            Preamble++  The licenses for most software are designed to take away your+freedom to share and change it.  By contrast, the GNU General Public+License is intended to guarantee your freedom to share and change free+software--to make sure the software is free for all its users.  This+General Public License applies to most of the Free Software+Foundation's software and to any other program whose authors commit to+using it.  (Some other Free Software Foundation software is covered by+the GNU Lesser General Public License instead.)  You can apply it to+your programs, too.++  When we speak of free software, we are referring to freedom, not+price.  Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+this service if you wish), that you receive source code or can get it+if you want it, that you can change the software or use pieces of it+in new free programs; and that you know you can do these things.++  To protect your rights, we need to make restrictions that forbid+anyone to deny you these rights or to ask you to surrender the rights.+These restrictions translate to certain responsibilities for you if you+distribute copies of the software, or if you modify it.++  For example, if you distribute copies of such a program, whether+gratis or for a fee, you must give the recipients all the rights that+you have.  You must make sure that they, too, receive or can get the+source code.  And you must show them these terms so they know their+rights.++  We protect your rights with two steps: (1) copyright the software, and+(2) offer you this license which gives you legal permission to copy,+distribute and/or modify the software.++  Also, for each author's protection and ours, we want to make certain+that everyone understands that there is no warranty for this free+software.  If the software is modified by someone else and passed on, we+want its recipients to know that what they have is not the original, so+that any problems introduced by others will not reflect on the original+authors' reputations.++  Finally, any free program is threatened constantly by software+patents.  We wish to avoid the danger that redistributors of a free+program will individually obtain patent licenses, in effect making the+program proprietary.  To prevent this, we have made it clear that any+patent must be licensed for everyone's free use or not licensed at all.++  The precise terms and conditions for copying, distribution and+modification follow.++                    GNU GENERAL PUBLIC LICENSE+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION++  0. This License applies to any program or other work which contains+a notice placed by the copyright holder saying it may be distributed+under the terms of this General Public License.  The "Program", below,+refers to any such program or work, and a "work based on the Program"+means either the Program or any derivative work under copyright law:+that is to say, a work containing the Program or a portion of it,+either verbatim or with modifications and/or translated into another+language.  (Hereinafter, translation is included without limitation in+the term "modification".)  Each licensee is addressed as "you".++Activities other than copying, distribution and modification are not+covered by this License; they are outside its scope.  The act of+running the Program is not restricted, and the output from the Program+is covered only if its contents constitute a work based on the+Program (independent of having been made by running the Program).+Whether that is true depends on what the Program does.++  1. You may copy and distribute verbatim copies of the Program's+source code as you receive it, in any medium, provided that you+conspicuously and appropriately publish on each copy an appropriate+copyright notice and disclaimer of warranty; keep intact all the+notices that refer to this License and to the absence of any warranty;+and give any other recipients of the Program a copy of this License+along with the Program.++You may charge a fee for the physical act of transferring a copy, and+you may at your option offer warranty protection in exchange for a fee.++  2. You may modify your copy or copies of the Program or any portion+of it, thus forming a work based on the Program, and copy and+distribute such modifications or work under the terms of Section 1+above, provided that you also meet all of these conditions:++    a) You must cause the modified files to carry prominent notices+    stating that you changed the files and the date of any change.++    b) You must cause any work that you distribute or publish, that in+    whole or in part contains or is derived from the Program or any+    part thereof, to be licensed as a whole at no charge to all third+    parties under the terms of this License.++    c) If the modified program normally reads commands interactively+    when run, you must cause it, when started running for such+    interactive use in the most ordinary way, to print or display an+    announcement including an appropriate copyright notice and a+    notice that there is no warranty (or else, saying that you provide+    a warranty) and that users may redistribute the program under+    these conditions, and telling the user how to view a copy of this+    License.  (Exception: if the Program itself is interactive but+    does not normally print such an announcement, your work based on+    the Program is not required to print an announcement.)++These requirements apply to the modified work as a whole.  If+identifiable sections of that work are not derived from the Program,+and can be reasonably considered independent and separate works in+themselves, then this License, and its terms, do not apply to those+sections when you distribute them as separate works.  But when you+distribute the same sections as part of a whole which is a work based+on the Program, the distribution of the whole must be on the terms of+this License, whose permissions for other licensees extend to the+entire whole, and thus to each and every part regardless of who wrote it.++Thus, it is not the intent of this section to claim rights or contest+your rights to work written entirely by you; rather, the intent is to+exercise the right to control the distribution of derivative or+collective works based on the Program.++In addition, mere aggregation of another work not based on the Program+with the Program (or with a work based on the Program) on a volume of+a storage or distribution medium does not bring the other work under+the scope of this License.++  3. You may copy and distribute the Program (or a work based on it,+under Section 2) in object code or executable form under the terms of+Sections 1 and 2 above provided that you also do one of the following:++    a) Accompany it with the complete corresponding machine-readable+    source code, which must be distributed under the terms of Sections+    1 and 2 above on a medium customarily used for software interchange; or,++    b) Accompany it with a written offer, valid for at least three+    years, to give any third party, for a charge no more than your+    cost of physically performing source distribution, a complete+    machine-readable copy of the corresponding source code, to be+    distributed under the terms of Sections 1 and 2 above on a medium+    customarily used for software interchange; or,++    c) Accompany it with the information you received as to the offer+    to distribute corresponding source code.  (This alternative is+    allowed only for noncommercial distribution and only if you+    received the program in object code or executable form with such+    an offer, in accord with Subsection b above.)++The source code for a work means the preferred form of the work for+making modifications to it.  For an executable work, complete source+code means all the source code for all modules it contains, plus any+associated interface definition files, plus the scripts used to+control compilation and installation of the executable.  However, as a+special exception, the source code distributed need not include+anything that is normally distributed (in either source or binary+form) with the major components (compiler, kernel, and so on) of the+operating system on which the executable runs, unless that component+itself accompanies the executable.++If distribution of executable or object code is made by offering+access to copy from a designated place, then offering equivalent+access to copy the source code from the same place counts as+distribution of the source code, even though third parties are not+compelled to copy the source along with the object code.++  4. You may not copy, modify, sublicense, or distribute the Program+except as expressly provided under this License.  Any attempt+otherwise to copy, modify, sublicense or distribute the Program is+void, and will automatically terminate your rights under this License.+However, parties who have received copies, or rights, from you under+this License will not have their licenses terminated so long as such+parties remain in full compliance.++  5. You are not required to accept this License, since you have not+signed it.  However, nothing else grants you permission to modify or+distribute the Program or its derivative works.  These actions are+prohibited by law if you do not accept this License.  Therefore, by+modifying or distributing the Program (or any work based on the+Program), you indicate your acceptance of this License to do so, and+all its terms and conditions for copying, distributing or modifying+the Program or works based on it.++  6. Each time you redistribute the Program (or any work based on the+Program), the recipient automatically receives a license from the+original licensor to copy, distribute or modify the Program subject to+these terms and conditions.  You may not impose any further+restrictions on the recipients' exercise of the rights granted herein.+You are not responsible for enforcing compliance by third parties to+this License.++  7. If, as a consequence of a court judgment or allegation of patent+infringement or for any other reason (not limited to patent issues),+conditions are imposed on you (whether by court order, agreement or+otherwise) that contradict the conditions of this License, they do not+excuse you from the conditions of this License.  If you cannot+distribute so as to satisfy simultaneously your obligations under this+License and any other pertinent obligations, then as a consequence you+may not distribute the Program at all.  For example, if a patent+license would not permit royalty-free redistribution of the Program by+all those who receive copies directly or indirectly through you, then+the only way you could satisfy both it and this License would be to+refrain entirely from distribution of the Program.++If any portion of this section is held invalid or unenforceable under+any particular circumstance, the balance of the section is intended to+apply and the section as a whole is intended to apply in other+circumstances.++It is not the purpose of this section to induce you to infringe any+patents or other property right claims or to contest validity of any+such claims; this section has the sole purpose of protecting the+integrity of the free software distribution system, which is+implemented by public license practices.  Many people have made+generous contributions to the wide range of software distributed+through that system in reliance on consistent application of that+system; it is up to the author/donor to decide if he or she is willing+to distribute software through any other system and a licensee cannot+impose that choice.++This section is intended to make thoroughly clear what is believed to+be a consequence of the rest of this License.++  8. If the distribution and/or use of the Program is restricted in+certain countries either by patents or by copyrighted interfaces, the+original copyright holder who places the Program under this License+may add an explicit geographical distribution limitation excluding+those countries, so that distribution is permitted only in or among+countries not thus excluded.  In such case, this License incorporates+the limitation as if written in the body of this License.++  9. The Free Software Foundation may publish revised and/or new versions+of the General Public License from time to time.  Such new versions will+be similar in spirit to the present version, but may differ in detail to+address new problems or concerns.++Each version is given a distinguishing version number.  If the Program+specifies a version number of this License which applies to it and "any+later version", you have the option of following the terms and conditions+either of that version or of any later version published by the Free+Software Foundation.  If the Program does not specify a version number of+this License, you may choose any version ever published by the Free Software+Foundation.++  10. If you wish to incorporate parts of the Program into other free+programs whose distribution conditions are different, write to the author+to ask for permission.  For software which is copyrighted by the Free+Software Foundation, write to the Free Software Foundation; we sometimes+make exceptions for this.  Our decision will be guided by the two goals+of preserving the free status of all derivatives of our free software and+of promoting the sharing and reuse of software generally.++                            NO WARRANTY++  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,+REPAIR OR CORRECTION.++  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE+POSSIBILITY OF SUCH DAMAGES.++                     END OF TERMS AND CONDITIONS++            How to Apply These Terms to Your New Programs++  If you develop a new program, and you want it to be of the greatest+possible use to the public, the best way to achieve this is to make it+free software which everyone can redistribute and change under these terms.++  To do so, attach the following notices to the program.  It is safest+to attach them to the start of each source file to most effectively+convey the exclusion of warranty; and each file should have at least+the "copyright" line and a pointer to where the full notice is found.++    <one line to give the program's name and a brief idea of what it does.>+    Copyright (C) <year>  <name of author>++    This program is free software; you can redistribute it and/or modify+    it under the terms of the GNU General Public License as published by+    the Free Software Foundation; either version 2 of the License, or+    (at your option) any later version.++    This program is distributed in the hope that it will be useful,+    but WITHOUT ANY WARRANTY; without even the implied warranty of+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the+    GNU General Public License for more details.++    You should have received a copy of the GNU General Public License along+    with this program; if not, write to the Free Software Foundation, Inc.,+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.++Also add information on how to contact you by electronic and paper mail.++If the program is interactive, make it output a short notice like this+when it starts in an interactive mode:++    Gnomovision version 69, Copyright (C) year name of author+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.+    This is free software, and you are welcome to redistribute it+    under certain conditions; type `show c' for details.++The hypothetical commands `show w' and `show c' should show the appropriate+parts of the General Public License.  Of course, the commands you use may+be called something other than `show w' and `show c'; they could even be+mouse-clicks or menu items--whatever suits your program.++You should also get your employer (if you work as a programmer) or your+school, if any, to sign a "copyright disclaimer" for the program, if+necessary.  Here is a sample; alter the names:++  Yoyodyne, Inc., hereby disclaims all copyright interest in the program+  `Gnomovision' (which makes passes at compilers) written by James Hacker.++  <signature of Ty Coon>, 1 April 1989+  Ty Coon, President of Vice++This General Public License does not permit incorporating your program into+proprietary programs.  If your program is a subroutine library, you may+consider it more useful to permit linking proprietary applications with the+library.  If this is what you want to do, use the GNU Lesser General+Public License instead of this License.
+ licenses/GPL-3.0.txt view
@@ -0,0 +1,674 @@+                    GNU GENERAL PUBLIC LICENSE+                       Version 3, 29 June 2007++ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++                            Preamble++  The GNU General Public License is a free, copyleft license for+software and other kinds of works.++  The licenses for most software and other practical works are designed+to take away your freedom to share and change the works.  By contrast,+the GNU General Public License is intended to guarantee your freedom to+share and change all versions of a program--to make sure it remains free+software for all its users.  We, the Free Software Foundation, use the+GNU General Public License for most of our software; it applies also to+any other work released this way by its authors.  You can apply it to+your programs, too.++  When we speak of free software, we are referring to freedom, not+price.  Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+them if you wish), that you receive source code or can get it if you+want it, that you can change the software or use pieces of it in new+free programs, and that you know you can do these things.++  To protect your rights, we need to prevent others from denying you+these rights or asking you to surrender the rights.  Therefore, you have+certain responsibilities if you distribute copies of the software, or if+you modify it: responsibilities to respect the freedom of others.++  For example, if you distribute copies of such a program, whether+gratis or for a fee, you must pass on to the recipients the same+freedoms that you received.  You must make sure that they, too, receive+or can get the source code.  And you must show them these terms so they+know their rights.++  Developers that use the GNU GPL protect your rights with two steps:+(1) assert copyright on the software, and (2) offer you this License+giving you legal permission to copy, distribute and/or modify it.++  For the developers' and authors' protection, the GPL clearly explains+that there is no warranty for this free software.  For both users' and+authors' sake, the GPL requires that modified versions be marked as+changed, so that their problems will not be attributed erroneously to+authors of previous versions.++  Some devices are designed to deny users access to install or run+modified versions of the software inside them, although the manufacturer+can do so.  This is fundamentally incompatible with the aim of+protecting users' freedom to change the software.  The systematic+pattern of such abuse occurs in the area of products for individuals to+use, which is precisely where it is most unacceptable.  Therefore, we+have designed this version of the GPL to prohibit the practice for those+products.  If such problems arise substantially in other domains, we+stand ready to extend this provision to those domains in future versions+of the GPL, as needed to protect the freedom of users.++  Finally, every program is threatened constantly by software patents.+States should not allow patents to restrict development and use of+software on general-purpose computers, but in those that do, we wish to+avoid the special danger that patents applied to a free program could+make it effectively proprietary.  To prevent this, the GPL assures that+patents cannot be used to render the program non-free.++  The precise terms and conditions for copying, distribution and+modification follow.++                       TERMS AND CONDITIONS++  0. Definitions.++  "This License" refers to version 3 of the GNU General Public License.++  "Copyright" also means copyright-like laws that apply to other kinds of+works, such as semiconductor masks.++  "The Program" refers to any copyrightable work licensed under this+License.  Each licensee is addressed as "you".  "Licensees" and+"recipients" may be individuals or organizations.++  To "modify" a work means to copy from or adapt all or part of the work+in a fashion requiring copyright permission, other than the making of an+exact copy.  The resulting work is called a "modified version" of the+earlier work or a work "based on" the earlier work.++  A "covered work" means either the unmodified Program or a work based+on the Program.++  To "propagate" a work means to do anything with it that, without+permission, would make you directly or secondarily liable for+infringement under applicable copyright law, except executing it on a+computer or modifying a private copy.  Propagation includes copying,+distribution (with or without modification), making available to the+public, and in some countries other activities as well.++  To "convey" a work means any kind of propagation that enables other+parties to make or receive copies.  Mere interaction with a user through+a computer network, with no transfer of a copy, is not conveying.++  An interactive user interface displays "Appropriate Legal Notices"+to the extent that it includes a convenient and prominently visible+feature that (1) displays an appropriate copyright notice, and (2)+tells the user that there is no warranty for the work (except to the+extent that warranties are provided), that licensees may convey the+work under this License, and how to view a copy of this License.  If+the interface presents a list of user commands or options, such as a+menu, a prominent item in the list meets this criterion.++  1. Source Code.++  The "source code" for a work means the preferred form of the work+for making modifications to it.  "Object code" means any non-source+form of a work.++  A "Standard Interface" means an interface that either is an official+standard defined by a recognized standards body, or, in the case of+interfaces specified for a particular programming language, one that+is widely used among developers working in that language.++  The "System Libraries" of an executable work include anything, other+than the work as a whole, that (a) is included in the normal form of+packaging a Major Component, but which is not part of that Major+Component, and (b) serves only to enable use of the work with that+Major Component, or to implement a Standard Interface for which an+implementation is available to the public in source code form.  A+"Major Component", in this context, means a major essential component+(kernel, window system, and so on) of the specific operating system+(if any) on which the executable work runs, or a compiler used to+produce the work, or an object code interpreter used to run it.++  The "Corresponding Source" for a work in object code form means all+the source code needed to generate, install, and (for an executable+work) run the object code and to modify the work, including scripts to+control those activities.  However, it does not include the work's+System Libraries, or general-purpose tools or generally available free+programs which are used unmodified in performing those activities but+which are not part of the work.  For example, Corresponding Source+includes interface definition files associated with source files for+the work, and the source code for shared libraries and dynamically+linked subprograms that the work is specifically designed to require,+such as by intimate data communication or control flow between those+subprograms and other parts of the work.++  The Corresponding Source need not include anything that users+can regenerate automatically from other parts of the Corresponding+Source.++  The Corresponding Source for a work in source code form is that+same work.++  2. Basic Permissions.++  All rights granted under this License are granted for the term of+copyright on the Program, and are irrevocable provided the stated+conditions are met.  This License explicitly affirms your unlimited+permission to run the unmodified Program.  The output from running a+covered work is covered by this License only if the output, given its+content, constitutes a covered work.  This License acknowledges your+rights of fair use or other equivalent, as provided by copyright law.++  You may make, run and propagate covered works that you do not+convey, without conditions so long as your license otherwise remains+in force.  You may convey covered works to others for the sole purpose+of having them make modifications exclusively for you, or provide you+with facilities for running those works, provided that you comply with+the terms of this License in conveying all material for which you do+not control copyright.  Those thus making or running the covered works+for you must do so exclusively on your behalf, under your direction+and control, on terms that prohibit them from making any copies of+your copyrighted material outside their relationship with you.++  Conveying under any other circumstances is permitted solely under+the conditions stated below.  Sublicensing is not allowed; section 10+makes it unnecessary.++  3. Protecting Users' Legal Rights From Anti-Circumvention Law.++  No covered work shall be deemed part of an effective technological+measure under any applicable law fulfilling obligations under article+11 of the WIPO copyright treaty adopted on 20 December 1996, or+similar laws prohibiting or restricting circumvention of such+measures.++  When you convey a covered work, you waive any legal power to forbid+circumvention of technological measures to the extent such circumvention+is effected by exercising rights under this License with respect to+the covered work, and you disclaim any intention to limit operation or+modification of the work as a means of enforcing, against the work's+users, your or third parties' legal rights to forbid circumvention of+technological measures.++  4. Conveying Verbatim Copies.++  You may convey verbatim copies of the Program's source code as you+receive it, in any medium, provided that you conspicuously and+appropriately publish on each copy an appropriate copyright notice;+keep intact all notices stating that this License and any+non-permissive terms added in accord with section 7 apply to the code;+keep intact all notices of the absence of any warranty; and give all+recipients a copy of this License along with the Program.++  You may charge any price or no price for each copy that you convey,+and you may offer support or warranty protection for a fee.++  5. Conveying Modified Source Versions.++  You may convey a work based on the Program, or the modifications to+produce it from the Program, in the form of source code under the+terms of section 4, provided that you also meet all of these conditions:++    a) The work must carry prominent notices stating that you modified+    it, and giving a relevant date.++    b) The work must carry prominent notices stating that it is+    released under this License and any conditions added under section+    7.  This requirement modifies the requirement in section 4 to+    "keep intact all notices".++    c) You must license the entire work, as a whole, under this+    License to anyone who comes into possession of a copy.  This+    License will therefore apply, along with any applicable section 7+    additional terms, to the whole of the work, and all its parts,+    regardless of how they are packaged.  This License gives no+    permission to license the work in any other way, but it does not+    invalidate such permission if you have separately received it.++    d) If the work has interactive user interfaces, each must display+    Appropriate Legal Notices; however, if the Program has interactive+    interfaces that do not display Appropriate Legal Notices, your+    work need not make them do so.++  A compilation of a covered work with other separate and independent+works, which are not by their nature extensions of the covered work,+and which are not combined with it such as to form a larger program,+in or on a volume of a storage or distribution medium, is called an+"aggregate" if the compilation and its resulting copyright are not+used to limit the access or legal rights of the compilation's users+beyond what the individual works permit.  Inclusion of a covered work+in an aggregate does not cause this License to apply to the other+parts of the aggregate.++  6. Conveying Non-Source Forms.++  You may convey a covered work in object code form under the terms+of sections 4 and 5, provided that you also convey the+machine-readable Corresponding Source under the terms of this License,+in one of these ways:++    a) Convey the object code in, or embodied in, a physical product+    (including a physical distribution medium), accompanied by the+    Corresponding Source fixed on a durable physical medium+    customarily used for software interchange.++    b) Convey the object code in, or embodied in, a physical product+    (including a physical distribution medium), accompanied by a+    written offer, valid for at least three years and valid for as+    long as you offer spare parts or customer support for that product+    model, to give anyone who possesses the object code either (1) a+    copy of the Corresponding Source for all the software in the+    product that is covered by this License, on a durable physical+    medium customarily used for software interchange, for a price no+    more than your reasonable cost of physically performing this+    conveying of source, or (2) access to copy the+    Corresponding Source from a network server at no charge.++    c) Convey individual copies of the object code with a copy of the+    written offer to provide the Corresponding Source.  This+    alternative is allowed only occasionally and noncommercially, and+    only if you received the object code with such an offer, in accord+    with subsection 6b.++    d) Convey the object code by offering access from a designated+    place (gratis or for a charge), and offer equivalent access to the+    Corresponding Source in the same way through the same place at no+    further charge.  You need not require recipients to copy the+    Corresponding Source along with the object code.  If the place to+    copy the object code is a network server, the Corresponding Source+    may be on a different server (operated by you or a third party)+    that supports equivalent copying facilities, provided you maintain+    clear directions next to the object code saying where to find the+    Corresponding Source.  Regardless of what server hosts the+    Corresponding Source, you remain obligated to ensure that it is+    available for as long as needed to satisfy these requirements.++    e) Convey the object code using peer-to-peer transmission, provided+    you inform other peers where the object code and Corresponding+    Source of the work are being offered to the general public at no+    charge under subsection 6d.++  A separable portion of the object code, whose source code is excluded+from the Corresponding Source as a System Library, need not be+included in conveying the object code work.++  A "User Product" is either (1) a "consumer product", which means any+tangible personal property which is normally used for personal, family,+or household purposes, or (2) anything designed or sold for incorporation+into a dwelling.  In determining whether a product is a consumer product,+doubtful cases shall be resolved in favor of coverage.  For a particular+product received by a particular user, "normally used" refers to a+typical or common use of that class of product, regardless of the status+of the particular user or of the way in which the particular user+actually uses, or expects or is expected to use, the product.  A product+is a consumer product regardless of whether the product has substantial+commercial, industrial or non-consumer uses, unless such uses represent+the only significant mode of use of the product.++  "Installation Information" for a User Product means any methods,+procedures, authorization keys, or other information required to install+and execute modified versions of a covered work in that User Product from+a modified version of its Corresponding Source.  The information must+suffice to ensure that the continued functioning of the modified object+code is in no case prevented or interfered with solely because+modification has been made.++  If you convey an object code work under this section in, or with, or+specifically for use in, a User Product, and the conveying occurs as+part of a transaction in which the right of possession and use of the+User Product is transferred to the recipient in perpetuity or for a+fixed term (regardless of how the transaction is characterized), the+Corresponding Source conveyed under this section must be accompanied+by the Installation Information.  But this requirement does not apply+if neither you nor any third party retains the ability to install+modified object code on the User Product (for example, the work has+been installed in ROM).++  The requirement to provide Installation Information does not include a+requirement to continue to provide support service, warranty, or updates+for a work that has been modified or installed by the recipient, or for+the User Product in which it has been modified or installed.  Access to a+network may be denied when the modification itself materially and+adversely affects the operation of the network or violates the rules and+protocols for communication across the network.++  Corresponding Source conveyed, and Installation Information provided,+in accord with this section must be in a format that is publicly+documented (and with an implementation available to the public in+source code form), and must require no special password or key for+unpacking, reading or copying.++  7. Additional Terms.++  "Additional permissions" are terms that supplement the terms of this+License by making exceptions from one or more of its conditions.+Additional permissions that are applicable to the entire Program shall+be treated as though they were included in this License, to the extent+that they are valid under applicable law.  If additional permissions+apply only to part of the Program, that part may be used separately+under those permissions, but the entire Program remains governed by+this License without regard to the additional permissions.++  When you convey a copy of a covered work, you may at your option+remove any additional permissions from that copy, or from any part of+it.  (Additional permissions may be written to require their own+removal in certain cases when you modify the work.)  You may place+additional permissions on material, added by you to a covered work,+for which you have or can give appropriate copyright permission.++  Notwithstanding any other provision of this License, for material you+add to a covered work, you may (if authorized by the copyright holders of+that material) supplement the terms of this License with terms:++    a) Disclaiming warranty or limiting liability differently from the+    terms of sections 15 and 16 of this License; or++    b) Requiring preservation of specified reasonable legal notices or+    author attributions in that material or in the Appropriate Legal+    Notices displayed by works containing it; or++    c) Prohibiting misrepresentation of the origin of that material, or+    requiring that modified versions of such material be marked in+    reasonable ways as different from the original version; or++    d) Limiting the use for publicity purposes of names of licensors or+    authors of the material; or++    e) Declining to grant rights under trademark law for use of some+    trade names, trademarks, or service marks; or++    f) Requiring indemnification of licensors and authors of that+    material by anyone who conveys the material (or modified versions of+    it) with contractual assumptions of liability to the recipient, for+    any liability that these contractual assumptions directly impose on+    those licensors and authors.++  All other non-permissive additional terms are considered "further+restrictions" within the meaning of section 10.  If the Program as you+received it, or any part of it, contains a notice stating that it is+governed by this License along with a term that is a further+restriction, you may remove that term.  If a license document contains+a further restriction but permits relicensing or conveying under this+License, you may add to a covered work material governed by the terms+of that license document, provided that the further restriction does+not survive such relicensing or conveying.++  If you add terms to a covered work in accord with this section, you+must place, in the relevant source files, a statement of the+additional terms that apply to those files, or a notice indicating+where to find the applicable terms.++  Additional terms, permissive or non-permissive, may be stated in the+form of a separately written license, or stated as exceptions;+the above requirements apply either way.++  8. Termination.++  You may not propagate or modify a covered work except as expressly+provided under this License.  Any attempt otherwise to propagate or+modify it is void, and will automatically terminate your rights under+this License (including any patent licenses granted under the third+paragraph of section 11).++  However, if you cease all violation of this License, then your+license from a particular copyright holder is reinstated (a)+provisionally, unless and until the copyright holder explicitly and+finally terminates your license, and (b) permanently, if the copyright+holder fails to notify you of the violation by some reasonable means+prior to 60 days after the cessation.++  Moreover, your license from a particular copyright holder is+reinstated permanently if the copyright holder notifies you of the+violation by some reasonable means, this is the first time you have+received notice of violation of this License (for any work) from that+copyright holder, and you cure the violation prior to 30 days after+your receipt of the notice.++  Termination of your rights under this section does not terminate the+licenses of parties who have received copies or rights from you under+this License.  If your rights have been terminated and not permanently+reinstated, you do not qualify to receive new licenses for the same+material under section 10.++  9. Acceptance Not Required for Having Copies.++  You are not required to accept this License in order to receive or+run a copy of the Program.  Ancillary propagation of a covered work+occurring solely as a consequence of using peer-to-peer transmission+to receive a copy likewise does not require acceptance.  However,+nothing other than this License grants you permission to propagate or+modify any covered work.  These actions infringe copyright if you do+not accept this License.  Therefore, by modifying or propagating a+covered work, you indicate your acceptance of this License to do so.++  10. Automatic Licensing of Downstream Recipients.++  Each time you convey a covered work, the recipient automatically+receives a license from the original licensors, to run, modify and+propagate that work, subject to this License.  You are not responsible+for enforcing compliance by third parties with this License.++  An "entity transaction" is a transaction transferring control of an+organization, or substantially all assets of one, or subdividing an+organization, or merging organizations.  If propagation of a covered+work results from an entity transaction, each party to that+transaction who receives a copy of the work also receives whatever+licenses to the work the party's predecessor in interest had or could+give under the previous paragraph, plus a right to possession of the+Corresponding Source of the work from the predecessor in interest, if+the predecessor has it or can get it with reasonable efforts.++  You may not impose any further restrictions on the exercise of the+rights granted or affirmed under this License.  For example, you may+not impose a license fee, royalty, or other charge for exercise of+rights granted under this License, and you may not initiate litigation+(including a cross-claim or counterclaim in a lawsuit) alleging that+any patent claim is infringed by making, using, selling, offering for+sale, or importing the Program or any portion of it.++  11. Patents.++  A "contributor" is a copyright holder who authorizes use under this+License of the Program or a work on which the Program is based.  The+work thus licensed is called the contributor's "contributor version".++  A contributor's "essential patent claims" are all patent claims+owned or controlled by the contributor, whether already acquired or+hereafter acquired, that would be infringed by some manner, permitted+by this License, of making, using, or selling its contributor version,+but do not include claims that would be infringed only as a+consequence of further modification of the contributor version.  For+purposes of this definition, "control" includes the right to grant+patent sublicenses in a manner consistent with the requirements of+this License.++  Each contributor grants you a non-exclusive, worldwide, royalty-free+patent license under the contributor's essential patent claims, to+make, use, sell, offer for sale, import and otherwise run, modify and+propagate the contents of its contributor version.++  In the following three paragraphs, a "patent license" is any express+agreement or commitment, however denominated, not to enforce a patent+(such as an express permission to practice a patent or covenant not to+sue for patent infringement).  To "grant" such a patent license to a+party means to make such an agreement or commitment not to enforce a+patent against the party.++  If you convey a covered work, knowingly relying on a patent license,+and the Corresponding Source of the work is not available for anyone+to copy, free of charge and under the terms of this License, through a+publicly available network server or other readily accessible means,+then you must either (1) cause the Corresponding Source to be so+available, or (2) arrange to deprive yourself of the benefit of the+patent license for this particular work, or (3) arrange, in a manner+consistent with the requirements of this License, to extend the patent+license to downstream recipients.  "Knowingly relying" means you have+actual knowledge that, but for the patent license, your conveying the+covered work in a country, or your recipient's use of the covered work+in a country, would infringe one or more identifiable patents in that+country that you have reason to believe are valid.++  If, pursuant to or in connection with a single transaction or+arrangement, you convey, or propagate by procuring conveyance of, a+covered work, and grant a patent license to some of the parties+receiving the covered work authorizing them to use, propagate, modify+or convey a specific copy of the covered work, then the patent license+you grant is automatically extended to all recipients of the covered+work and works based on it.++  A patent license is "discriminatory" if it does not include within+the scope of its coverage, prohibits the exercise of, or is+conditioned on the non-exercise of one or more of the rights that are+specifically granted under this License.  You may not convey a covered+work if you are a party to an arrangement with a third party that is+in the business of distributing software, under which you make payment+to the third party based on the extent of your activity of conveying+the work, and under which the third party grants, to any of the+parties who would receive the covered work from you, a discriminatory+patent license (a) in connection with copies of the covered work+conveyed by you (or copies made from those copies), or (b) primarily+for and in connection with specific products or compilations that+contain the covered work, unless you entered into that arrangement,+or that patent license was granted, prior to 28 March 2007.++  Nothing in this License shall be construed as excluding or limiting+any implied license or other defenses to infringement that may+otherwise be available to you under applicable patent law.++  12. No Surrender of Others' Freedom.++  If conditions are imposed on you (whether by court order, agreement or+otherwise) that contradict the conditions of this License, they do not+excuse you from the conditions of this License.  If you cannot convey a+covered work so as to satisfy simultaneously your obligations under this+License and any other pertinent obligations, then as a consequence you may+not convey it at all.  For example, if you agree to terms that obligate you+to collect a royalty for further conveying from those to whom you convey+the Program, the only way you could satisfy both those terms and this+License would be to refrain entirely from conveying the Program.++  13. Use with the GNU Affero General Public License.++  Notwithstanding any other provision of this License, you have+permission to link or combine any covered work with a work licensed+under version 3 of the GNU Affero General Public License into a single+combined work, and to convey the resulting work.  The terms of this+License will continue to apply to the part which is the covered work,+but the special requirements of the GNU Affero General Public License,+section 13, concerning interaction through a network will apply to the+combination as such.++  14. Revised Versions of this License.++  The Free Software Foundation may publish revised and/or new versions of+the GNU General Public License from time to time.  Such new versions will+be similar in spirit to the present version, but may differ in detail to+address new problems or concerns.++  Each version is given a distinguishing version number.  If the+Program specifies that a certain numbered version of the GNU General+Public License "or any later version" applies to it, you have the+option of following the terms and conditions either of that numbered+version or of any later version published by the Free Software+Foundation.  If the Program does not specify a version number of the+GNU General Public License, you may choose any version ever published+by the Free Software Foundation.++  If the Program specifies that a proxy can decide which future+versions of the GNU General Public License can be used, that proxy's+public statement of acceptance of a version permanently authorizes you+to choose that version for the Program.++  Later license versions may give you additional or different+permissions.  However, no additional obligations are imposed on any+author or copyright holder as a result of your choosing to follow a+later version.++  15. Disclaimer of Warranty.++  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.++  16. Limitation of Liability.++  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF+SUCH DAMAGES.++  17. Interpretation of Sections 15 and 16.++  If the disclaimer of warranty and limitation of liability provided+above cannot be given local legal effect according to their terms,+reviewing courts shall apply local law that most closely approximates+an absolute waiver of all civil liability in connection with the+Program, unless a warranty or assumption of liability accompanies a+copy of the Program in return for a fee.++                     END OF TERMS AND CONDITIONS++            How to Apply These Terms to Your New Programs++  If you develop a new program, and you want it to be of the greatest+possible use to the public, the best way to achieve this is to make it+free software which everyone can redistribute and change under these terms.++  To do so, attach the following notices to the program.  It is safest+to attach them to the start of each source file to most effectively+state the exclusion of warranty; and each file should have at least+the "copyright" line and a pointer to where the full notice is found.++    <one line to give the program's name and a brief idea of what it does.>+    Copyright (C) <year>  <name of author>++    This program is free software: you can redistribute it and/or modify+    it under the terms of the GNU General Public License as published by+    the Free Software Foundation, either version 3 of the License, or+    (at your option) any later version.++    This program is distributed in the hope that it will be useful,+    but WITHOUT ANY WARRANTY; without even the implied warranty of+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the+    GNU General Public License for more details.++    You should have received a copy of the GNU General Public License+    along with this program.  If not, see <http://www.gnu.org/licenses/>.++Also add information on how to contact you by electronic and paper mail.++  If the program does terminal interaction, make it output a short+notice like this when it starts in an interactive mode:++    <program>  Copyright (C) <year>  <name of author>+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.+    This is free software, and you are welcome to redistribute it+    under certain conditions; type `show c' for details.++The hypothetical commands `show w' and `show c' should show the appropriate+parts of the General Public License.  Of course, your program's commands+might be different; for a GUI interface, you would use an "about box".++  You should also get your employer (if you work as a programmer) or school,+if any, to sign a "copyright disclaimer" for the program, if necessary.+For more information on this, and how to apply and follow the GNU GPL, see+<http://www.gnu.org/licenses/>.++  The GNU General Public License does not permit incorporating your program+into proprietary programs.  If your program is a subroutine library, you+may consider it more useful to permit linking proprietary applications with+the library.  If this is what you want to do, use the GNU Lesser General+Public License instead of this License.  But first, please read+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+ licenses/LGPL-3.0.txt view
@@ -0,0 +1,165 @@+                   GNU LESSER GENERAL PUBLIC LICENSE+                       Version 3, 29 June 2007++ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.+++  This version of the GNU Lesser General Public License incorporates+the terms and conditions of version 3 of the GNU General Public+License, supplemented by the additional permissions listed below.++  0. Additional Definitions.++  As used herein, "this License" refers to version 3 of the GNU Lesser+General Public License, and the "GNU GPL" refers to version 3 of the GNU+General Public License.++  "The Library" refers to a covered work governed by this License,+other than an Application or a Combined Work as defined below.++  An "Application" is any work that makes use of an interface provided+by the Library, but which is not otherwise based on the Library.+Defining a subclass of a class defined by the Library is deemed a mode+of using an interface provided by the Library.++  A "Combined Work" is a work produced by combining or linking an+Application with the Library.  The particular version of the Library+with which the Combined Work was made is also called the "Linked+Version".++  The "Minimal Corresponding Source" for a Combined Work means the+Corresponding Source for the Combined Work, excluding any source code+for portions of the Combined Work that, considered in isolation, are+based on the Application, and not on the Linked Version.++  The "Corresponding Application Code" for a Combined Work means the+object code and/or source code for the Application, including any data+and utility programs needed for reproducing the Combined Work from the+Application, but excluding the System Libraries of the Combined Work.++  1. Exception to Section 3 of the GNU GPL.++  You may convey a covered work under sections 3 and 4 of this License+without being bound by section 3 of the GNU GPL.++  2. Conveying Modified Versions.++  If you modify a copy of the Library, and, in your modifications, a+facility refers to a function or data to be supplied by an Application+that uses the facility (other than as an argument passed when the+facility is invoked), then you may convey a copy of the modified+version:++   a) under this License, provided that you make a good faith effort to+   ensure that, in the event an Application does not supply the+   function or data, the facility still operates, and performs+   whatever part of its purpose remains meaningful, or++   b) under the GNU GPL, with none of the additional permissions of+   this License applicable to that copy.++  3. Object Code Incorporating Material from Library Header Files.++  The object code form of an Application may incorporate material from+a header file that is part of the Library.  You may convey such object+code under terms of your choice, provided that, if the incorporated+material is not limited to numerical parameters, data structure+layouts and accessors, or small macros, inline functions and templates+(ten or fewer lines in length), you do both of the following:++   a) Give prominent notice with each copy of the object code that the+   Library is used in it and that the Library and its use are+   covered by this License.++   b) Accompany the object code with a copy of the GNU GPL and this license+   document.++  4. Combined Works.++  You may convey a Combined Work under terms of your choice that,+taken together, effectively do not restrict modification of the+portions of the Library contained in the Combined Work and reverse+engineering for debugging such modifications, if you also do each of+the following:++   a) Give prominent notice with each copy of the Combined Work that+   the Library is used in it and that the Library and its use are+   covered by this License.++   b) Accompany the Combined Work with a copy of the GNU GPL and this license+   document.++   c) For a Combined Work that displays copyright notices during+   execution, include the copyright notice for the Library among+   these notices, as well as a reference directing the user to the+   copies of the GNU GPL and this license document.++   d) Do one of the following:++       0) Convey the Minimal Corresponding Source under the terms of this+       License, and the Corresponding Application Code in a form+       suitable for, and under terms that permit, the user to+       recombine or relink the Application with a modified version of+       the Linked Version to produce a modified Combined Work, in the+       manner specified by section 6 of the GNU GPL for conveying+       Corresponding Source.++       1) Use a suitable shared library mechanism for linking with the+       Library.  A suitable mechanism is one that (a) uses at run time+       a copy of the Library already present on the user's computer+       system, and (b) will operate properly with a modified version+       of the Library that is interface-compatible with the Linked+       Version.++   e) Provide Installation Information, but only if you would otherwise+   be required to provide such information under section 6 of the+   GNU GPL, and only to the extent that such information is+   necessary to install and execute a modified version of the+   Combined Work produced by recombining or relinking the+   Application with a modified version of the Linked Version. (If+   you use option 4d0, the Installation Information must accompany+   the Minimal Corresponding Source and Corresponding Application+   Code. If you use option 4d1, you must provide the Installation+   Information in the manner specified by section 6 of the GNU GPL+   for conveying Corresponding Source.)++  5. Combined Libraries.++  You may place library facilities that are a work based on the+Library side by side in a single library together with other library+facilities that are not Applications and are not covered by this+License, and convey such a combined library under terms of your+choice, if you do both of the following:++   a) Accompany the combined library with a copy of the same work based+   on the Library, uncombined with any other library facilities,+   conveyed under the terms of this License.++   b) Give prominent notice with the combined library that part of it+   is a work based on the Library, and explaining where to find the+   accompanying uncombined form of the same work.++  6. Revised Versions of the GNU Lesser General Public License.++  The Free Software Foundation may publish revised and/or new versions+of the GNU Lesser General Public License from time to time. Such new+versions will be similar in spirit to the present version, but may+differ in detail to address new problems or concerns.++  Each version is given a distinguishing version number. If the+Library as you received it specifies that a certain numbered version+of the GNU Lesser General Public License "or any later version"+applies to it, you have the option of following the terms and+conditions either of that published version or of any later version+published by the Free Software Foundation. If the Library as you+received it does not specify a version number of the GNU Lesser+General Public License, you may choose any version of the GNU Lesser+General Public License ever published by the Free Software Foundation.++  If the Library as you received it specifies that a proxy can decide+whether future versions of the GNU Lesser General Public License shall+apply, that proxy's public statement of acceptance of any version is+permanent authorization for you to choose that version for the+Library.
+ licenses/libsodium-sha-BSD-2-Clause.txt view
@@ -0,0 +1,27 @@+/*-+ * Copyright 2005,2007,2009 Colin Percival+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or without+ * modification, are permitted provided that the following conditions+ * are met:+ * 1. Redistributions of source code must retain the above copyright+ *    notice, this list of conditions and the following disclaimer.+ * 2. Redistributions in binary form must reproduce the above copyright+ *    notice, this list of conditions and the following disclaimer in the+ *    documentation and/or other materials provided with the distribution.+ *+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+ * SUCH DAMAGE.+ *+ */+
+ vendor/external/README view
@@ -0,0 +1,71 @@+Third-party libraries vendored into cardano-c+=============================================++Each dependency below is vendored under lib/external/<name>/, compiled as an+isolated CMake OBJECT library with warnings and clang-tidy disabled for that+target only, and folded into libcardano-c. The upstream license text is kept+verbatim in each directory; copyright notices are never altered. All listed+licenses are compatible with the project's Apache-2.0 license.++libsodium+  Use:      SHA-256, SHA-512, Blake2b, Ed25519, HMAC, constant-time compare.+  License:  ISC (see libsodium/LICENSE).+  Origin:   https://github.com/jedisct1/libsodium++gmp (mini-gmp)+  Use:      arbitrary-precision integers backing cardano_bigint_t.+  License:  LGPL/GPL dual (see gmp/README and the headers).+  Origin:   https://gmplib.org (mini-gmp subset)++sha3+  Use:      SHA3-256 and Keccak-256 (shared Keccak-f permutation, differing+            domain pad byte).+  Version:  tiny_sha3 @ dcbb3192047c2a721f5f851db591871d428036a9+  License:  MIT (see sha3/LICENSE).+  Origin:   https://github.com/mjosaarinen/tiny_sha3+  Details:  sha3/VERSION.txt++ripemd160+  Use:      RIPEMD-160 (20-byte digest).+  Version:  trezor-firmware crypto/ripemd160.c @+            fb471a96f226737ec1c22bbf88078f5b36a572bc+            (Litzenberger 2008, public-domain changes by Wuille 2012)+  License:  Public domain (see ripemd160/LICENSE).+  Origin:   https://github.com/trezor/trezor-firmware+  Details:  ripemd160/VERSION.txt++secp256k1+  Use:      secp256k1 ECDSA-verify and Schnorr (BIP340) verify backing the+            verifyEcdsaSecp256k1Signature and verifySchnorrSecp256k1Signature+            builtins. Only the verify path plus the extrakeys and schnorrsig+            modules are compiled; recovery, ECDH, ellswift and musig are+            dropped.+  Version:  bitcoin-core/secp256k1 v0.6.0 @+            0cdc758a56360bf58a851fe91085a327ec97685a+  License:  MIT (see secp256k1/COPYING).+  Origin:   https://github.com/bitcoin-core/secp256k1+  Details:  secp256k1/VERSION.txt+  Build:    No autotools and no codegen. Configured by compile defines on the+            OBJECT target (ENABLE_MODULE_EXTRAKEYS, ENABLE_MODULE_SCHNORRSIG,+            ECMULT_WINDOW_SIZE=8, SECP256K1_STATIC); the checked-in precomputed+            tables are compiled as-is. The small window keeps the verify table+            at 8 KiB instead of 1 MiB, since secp verify is a cold path.++blst+  Use:      BLS12-381 G1/G2 arithmetic, pairings, hash-to-curve and+            serialization backing the bls12_381_* Plutus builtins.+  Version:  supranational/blst v0.3.14 @+            8c7db7fe8d2ce6e76dc398ebd4d475c0ec564355+  License:  Apache-2.0 (see blst/LICENSE).+  Origin:   https://github.com/supranational/blst+  Details:  blst/VERSION.txt+  Build:    Portable no-assembly build. Only src/server.c is a compilation+            unit; it includes the implementation .c files it needs. The+            OBJECT target sets __BLST_NO_ASM__ (reference C field arithmetic+            in no_asm.h) and __BLST_PORTABLE__ (pure-C SHA-256, no runtime+            asm dispatch), so there is no assembly and the target builds on+            WASM and the armv6/armv7 cross builds. src/vect.h was reordered so+            the no-asm 32-bit-limb path is also taken on x86_64/aarch64; no+            copyright text was altered. The asm/ and build/ trees, the C++ and+            language bindings, and the alternative client_min_* amalgamation+            units are dropped.
+ vendor/external/blst/LICENSE view
@@ -0,0 +1,201 @@+                                 Apache License+                           Version 2.0, January 2004+                        http://www.apache.org/licenses/++   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION++   1. Definitions.++      "License" shall mean the terms and conditions for use, reproduction,+      and distribution as defined by Sections 1 through 9 of this document.++      "Licensor" shall mean the copyright owner or entity authorized by+      the copyright owner that is granting the License.++      "Legal Entity" shall mean the union of the acting entity and all+      other entities that control, are controlled by, or are under common+      control with that entity. For the purposes of this definition,+      "control" means (i) the power, direct or indirect, to cause the+      direction or management of such entity, whether by contract or+      otherwise, or (ii) ownership of fifty percent (50%) or more of the+      outstanding shares, or (iii) beneficial ownership of such entity.++      "You" (or "Your") shall mean an individual or Legal Entity+      exercising permissions granted by this License.++      "Source" form shall mean the preferred form for making modifications,+      including but not limited to software source code, documentation+      source, and configuration files.++      "Object" form shall mean any form resulting from mechanical+      transformation or translation of a Source form, including but+      not limited to compiled object code, generated documentation,+      and conversions to other media types.++      "Work" shall mean the work of authorship, whether in Source or+      Object form, made available under the License, as indicated by a+      copyright notice that is included in or attached to the work+      (an example is provided in the Appendix below).++      "Derivative Works" shall mean any work, whether in Source or Object+      form, that is based on (or derived from) the Work and for which the+      editorial revisions, annotations, elaborations, or other modifications+      represent, as a whole, an original work of authorship. For the purposes+      of this License, Derivative Works shall not include works that remain+      separable from, or merely link (or bind by name) to the interfaces of,+      the Work and Derivative Works thereof.++      "Contribution" shall mean any work of authorship, including+      the original version of the Work and any modifications or additions+      to that Work or Derivative Works thereof, that is intentionally+      submitted to Licensor for inclusion in the Work by the copyright owner+      or by an individual or Legal Entity authorized to submit on behalf of+      the copyright owner. For the purposes of this definition, "submitted"+      means any form of electronic, verbal, or written communication sent+      to the Licensor or its representatives, including but not limited to+      communication on electronic mailing lists, source code control systems,+      and issue tracking systems that are managed by, or on behalf of, the+      Licensor for the purpose of discussing and improving the Work, but+      excluding communication that is conspicuously marked or otherwise+      designated in writing by the copyright owner as "Not a Contribution."++      "Contributor" shall mean Licensor and any individual or Legal Entity+      on behalf of whom a Contribution has been received by Licensor and+      subsequently incorporated within the Work.++   2. Grant of Copyright License. Subject to the terms and conditions of+      this License, each Contributor hereby grants to You a perpetual,+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable+      copyright license to reproduce, prepare Derivative Works of,+      publicly display, publicly perform, sublicense, and distribute the+      Work and such Derivative Works in Source or Object form.++   3. Grant of Patent License. Subject to the terms and conditions of+      this License, each Contributor hereby grants to You a perpetual,+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable+      (except as stated in this section) patent license to make, have made,+      use, offer to sell, sell, import, and otherwise transfer the Work,+      where such license applies only to those patent claims licensable+      by such Contributor that are necessarily infringed by their+      Contribution(s) alone or by combination of their Contribution(s)+      with the Work to which such Contribution(s) was submitted. If You+      institute patent litigation against any entity (including a+      cross-claim or counterclaim in a lawsuit) alleging that the Work+      or a Contribution incorporated within the Work constitutes direct+      or contributory patent infringement, then any patent licenses+      granted to You under this License for that Work shall terminate+      as of the date such litigation is filed.++   4. Redistribution. You may reproduce and distribute copies of the+      Work or Derivative Works thereof in any medium, with or without+      modifications, and in Source or Object form, provided that You+      meet the following conditions:++      (a) You must give any other recipients of the Work or+          Derivative Works a copy of this License; and++      (b) You must cause any modified files to carry prominent notices+          stating that You changed the files; and++      (c) You must retain, in the Source form of any Derivative Works+          that You distribute, all copyright, patent, trademark, and+          attribution notices from the Source form of the Work,+          excluding those notices that do not pertain to any part of+          the Derivative Works; and++      (d) If the Work includes a "NOTICE" text file as part of its+          distribution, then any Derivative Works that You distribute must+          include a readable copy of the attribution notices contained+          within such NOTICE file, excluding those notices that do not+          pertain to any part of the Derivative Works, in at least one+          of the following places: within a NOTICE text file distributed+          as part of the Derivative Works; within the Source form or+          documentation, if provided along with the Derivative Works; or,+          within a display generated by the Derivative Works, if and+          wherever such third-party notices normally appear. The contents+          of the NOTICE file are for informational purposes only and+          do not modify the License. You may add Your own attribution+          notices within Derivative Works that You distribute, alongside+          or as an addendum to the NOTICE text from the Work, provided+          that such additional attribution notices cannot be construed+          as modifying the License.++      You may add Your own copyright statement to Your modifications and+      may provide additional or different license terms and conditions+      for use, reproduction, or distribution of Your modifications, or+      for any such Derivative Works as a whole, provided Your use,+      reproduction, and distribution of the Work otherwise complies with+      the conditions stated in this License.++   5. Submission of Contributions. Unless You explicitly state otherwise,+      any Contribution intentionally submitted for inclusion in the Work+      by You to the Licensor shall be under the terms and conditions of+      this License, without any additional terms or conditions.+      Notwithstanding the above, nothing herein shall supersede or modify+      the terms of any separate license agreement you may have executed+      with Licensor regarding such Contributions.++   6. Trademarks. This License does not grant permission to use the trade+      names, trademarks, service marks, or product names of the Licensor,+      except as required for reasonable and customary use in describing the+      origin of the Work and reproducing the content of the NOTICE file.++   7. Disclaimer of Warranty. Unless required by applicable law or+      agreed to in writing, Licensor provides the Work (and each+      Contributor provides its Contributions) on an "AS IS" BASIS,+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+      implied, including, without limitation, any warranties or conditions+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A+      PARTICULAR PURPOSE. You are solely responsible for determining the+      appropriateness of using or redistributing the Work and assume any+      risks associated with Your exercise of permissions under this License.++   8. Limitation of Liability. In no event and under no legal theory,+      whether in tort (including negligence), contract, or otherwise,+      unless required by applicable law (such as deliberate and grossly+      negligent acts) or agreed to in writing, shall any Contributor be+      liable to You for damages, including any direct, indirect, special,+      incidental, or consequential damages of any character arising as a+      result of this License or out of the use or inability to use the+      Work (including but not limited to damages for loss of goodwill,+      work stoppage, computer failure or malfunction, or any and all+      other commercial damages or losses), even if such Contributor+      has been advised of the possibility of such damages.++   9. Accepting Warranty or Additional Liability. While redistributing+      the Work or Derivative Works thereof, You may choose to offer,+      and charge a fee for, acceptance of support, warranty, indemnity,+      or other liability obligations and/or rights consistent with this+      License. However, in accepting such obligations, You may act only+      on Your own behalf and on Your sole responsibility, not on behalf+      of any other Contributor, and only if You agree to indemnify,+      defend, and hold each Contributor harmless for any liability+      incurred by, or claims asserted against, such Contributor by reason+      of your accepting any such warranty or additional liability.++   END OF TERMS AND CONDITIONS++   APPENDIX: How to apply the Apache License to your work.++      To apply the Apache License to your work, attach the following+      boilerplate notice, with the fields enclosed by brackets "[]"+      replaced with your own identifying information. (Don't include+      the brackets!)  The text should be enclosed in the appropriate+      comment syntax for the file format. We also recommend that a+      file or class name and description of purpose be included on the+      same "printed page" as the copyright notice for easier+      identification within third-party archives.++   Copyright [yyyy] [name of copyright owner]++   Licensed under the Apache License, Version 2.0 (the "License");+   you may not use this file except in compliance with the License.+   You may obtain a copy of the License at++       http://www.apache.org/licenses/LICENSE-2.0++   Unless required by applicable law or agreed to in writing, software+   distributed under the License is distributed on an "AS IS" BASIS,+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+   See the License for the specific language governing permissions and+   limitations under the License.
+ vendor/external/blst/VERSION.txt view
@@ -0,0 +1,72 @@+Upstream:  supranational/blst+Origin:    https://github.com/supranational/blst+Tag:       v0.3.14+Commit:    8c7db7fe8d2ce6e76dc398ebd4d475c0ec564355+License:   Apache-2.0 (see LICENSE in this directory)++Provides BLS12-381 G1/G2 group arithmetic, pairings, hash-to-curve and+serialization for the Plutus bls12_381_* builtins (added in a later task).+This task only vendors and wires the library plus a smoke test; the builtin+bodies are implemented separately.++Build configuration: portable, no-assembly build+  The library is compiled as a single translation unit, src/server.c, which+  #includes the implementation .c files it needs:+    keygen.c hash_to_field.c e1.c map_to_g1.c e2.c map_to_g2.c fp12_tower.c+    pairing.c aggregate.c exp.c sqrt.c recip.c bulk_addition.c multi_scalar.c+    consts.c vect.c exports.c rb_tree.c cpuid.c+  (pentaroot.c is included only under BLST_FR_PENTAROOT, which is never+  defined here.)++  Two compile defines are set on the isolated CMake OBJECT target+  (see lib/CMakeLists.txt):+    __BLST_NO_ASM__   - select the portable reference C field arithmetic in+                        src/no_asm.h instead of any assembly. With this define+                        there is no assembly anywhere, so the library builds on+                        WASM/Emscripten and the armv6/armv7 cross builds.+    __BLST_PORTABLE__ - also disable the runtime-dispatched SHA-256 assembly+                        kernels (blst_sha256_block_data_order_shaext /+                        blst_sha256_block_armv8 in src/sha256.h), falling back+                        to the pure-C blst_sha256_block_data_order. Without this+                        define, on an x86_64 host built with -msha or on Apple+                        Silicon (which defines __ARM_FEATURE_CRYPTO) the header+                        would reference an assembly SHA-256 symbol that the+                        no-asm build does not provide, and the link would fail.++Local changes to the vendored source (recorded per the vendoring rules):+  src/no_asm.h - replace variable-length scratch arrays with fixed capacity+    for the largest supported field (384 bits), plus a carry limb or doubled+    capacity where required. smul_2n receives up to 768 bits. The public+    wrappers fix n to the field width; loop bounds and copy/zero lengths+    remain based on n. Remove the VLA compiler restriction so MSVC can use+    the same portable C implementation. No arithmetic operations changed.+  src/vect.h - the limb-size selection block is reordered so that the+    __BLST_NO_ASM__/__wasm64__ branch (32-bit limbs, the path no_asm.h is+    written for) is tested before the __x86_64__/__aarch64__ branch (64-bit+    limbs). Upstream only ships the no-assembly path for architectures other+    than x86_64/aarch64, so on those two it would otherwise pick 64-bit limbs+    and fail to compile no_asm.h (which defines its 64-bit double-limb llimb_t+    only for the 32-bit-limb case). Reordering lets the portable build compile+    on x86_64 and aarch64 too. No copyright or license text was altered.++Removed from the upstream tree to keep this lean (no copyright text altered):+  - src/asm/        - all .pl assembly generators (not used in the no-asm build).+  - build/          - assembly.S and per-platform assembly tooling (unused).+  - bindings/blst_t.hpp, bindings/blst.hpp, bindings/blst.swg - C++/SWIG glue.+  - All language bindings: bindings/{go,rust,python,node.js,java,c#,emscripten}+    and bindings/vectors.+  - src/client_min_pk.c, src/client_min_sig.c - alternative amalgamation units+    (server.c is the unit we compile; these are not #included by it).+  - build.sh, build.bat, go.mod, README.md, SECURITY.md, the logo image.++Vendored files:+  LICENSE                 - upstream Apache-2.0 license, copied verbatim.+  bindings/blst.h         - public C API.+  bindings/blst_aux.h     - auxiliary public C API.+  src/server.c            - the single translation unit compiled; it #includes+                            the implementation .c files listed above.+  src/*.c                 - the implementation units server.c #includes.+  src/*.h                 - the internal headers they need (vect.h, no_asm.h,+                            consts.h, point.h, fields.h, ec_ops.h, ec_mult.h,+                            errors.h, bytes.h, sha256.h and the *-addchain.h+                            tables).
+ vendor/external/blst/bindings/blst.h view
@@ -0,0 +1,490 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLST_H__+#define __BLST_H__++#ifdef __SIZE_TYPE__+typedef __SIZE_TYPE__ size_t;+#else+#include <stddef.h>+#endif++#if defined(__UINT8_TYPE__) && defined(__UINT32_TYPE__) \+                            && defined(__UINT64_TYPE__)+typedef __UINT8_TYPE__  uint8_t;+typedef __UINT32_TYPE__ uint32_t;+typedef __UINT64_TYPE__ uint64_t;+#else+#include <stdint.h>+#endif++#ifdef __cplusplus+extern "C" {+#elif !defined(__STDC_VERSION__) || __STDC_VERSION__<202311+# if defined(__BLST_CGO__)+typedef _Bool bool; /* it's assumed that cgo calls modern enough compiler */+# elif !defined(bool)+#  if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901+#   define bool _Bool+#  else+#   define bool int+#  endif+#  define __blst_h_bool__+# endif+#endif++#ifdef SWIG+# define DEFNULL =NULL+#elif defined __cplusplus+# define DEFNULL =0+#else+# define DEFNULL+#endif++typedef enum {+    BLST_SUCCESS = 0,+    BLST_BAD_ENCODING,+    BLST_POINT_NOT_ON_CURVE,+    BLST_POINT_NOT_IN_GROUP,+    BLST_AGGR_TYPE_MISMATCH,+    BLST_VERIFY_FAIL,+    BLST_PK_IS_INFINITY,+    BLST_BAD_SCALAR,+} BLST_ERROR;++typedef uint8_t byte;+typedef uint64_t limb_t;++typedef struct { byte b[256/8]; } blst_scalar;+typedef struct { limb_t l[256/8/sizeof(limb_t)]; } blst_fr;+typedef struct { limb_t l[384/8/sizeof(limb_t)]; } blst_fp;+/* 0 is "real" part, 1 is "imaginary" */+typedef struct { blst_fp fp[2]; } blst_fp2;+typedef struct { blst_fp2 fp2[3]; } blst_fp6;+typedef struct { blst_fp6 fp6[2]; } blst_fp12;++void blst_scalar_from_uint32(blst_scalar *out, const uint32_t a[8]);+void blst_uint32_from_scalar(uint32_t out[8], const blst_scalar *a);+void blst_scalar_from_uint64(blst_scalar *out, const uint64_t a[4]);+void blst_uint64_from_scalar(uint64_t out[4], const blst_scalar *a);+void blst_scalar_from_bendian(blst_scalar *out, const byte a[32]);+void blst_bendian_from_scalar(byte out[32], const blst_scalar *a);+void blst_scalar_from_lendian(blst_scalar *out, const byte a[32]);+void blst_lendian_from_scalar(byte out[32], const blst_scalar *a);+bool blst_scalar_fr_check(const blst_scalar *a);+bool blst_sk_check(const blst_scalar *a);+bool blst_sk_add_n_check(blst_scalar *out, const blst_scalar *a,+                                           const blst_scalar *b);+bool blst_sk_sub_n_check(blst_scalar *out, const blst_scalar *a,+                                           const blst_scalar *b);+bool blst_sk_mul_n_check(blst_scalar *out, const blst_scalar *a,+                                           const blst_scalar *b);+void blst_sk_inverse(blst_scalar *out, const blst_scalar *a);+bool blst_scalar_from_le_bytes(blst_scalar *out, const byte *in, size_t len);+bool blst_scalar_from_be_bytes(blst_scalar *out, const byte *in, size_t len);++#ifndef SWIG+/*+ * BLS12-381-specific Fr operations.+ */+void blst_fr_add(blst_fr *ret, const blst_fr *a, const blst_fr *b);+void blst_fr_sub(blst_fr *ret, const blst_fr *a, const blst_fr *b);+void blst_fr_mul_by_3(blst_fr *ret, const blst_fr *a);+void blst_fr_lshift(blst_fr *ret, const blst_fr *a, size_t count);+void blst_fr_rshift(blst_fr *ret, const blst_fr *a, size_t count);+void blst_fr_mul(blst_fr *ret, const blst_fr *a, const blst_fr *b);+void blst_fr_sqr(blst_fr *ret, const blst_fr *a);+void blst_fr_cneg(blst_fr *ret, const blst_fr *a, bool flag);+void blst_fr_eucl_inverse(blst_fr *ret, const blst_fr *a);+void blst_fr_inverse(blst_fr *ret, const blst_fr *a);++void blst_fr_from_uint64(blst_fr *ret, const uint64_t a[4]);+void blst_uint64_from_fr(uint64_t ret[4], const blst_fr *a);+void blst_fr_from_scalar(blst_fr *ret, const blst_scalar *a);+void blst_scalar_from_fr(blst_scalar *ret, const blst_fr *a);++/*+ * BLS12-381-specific Fp operations.+ */+void blst_fp_add(blst_fp *ret, const blst_fp *a, const blst_fp *b);+void blst_fp_sub(blst_fp *ret, const blst_fp *a, const blst_fp *b);+void blst_fp_mul_by_3(blst_fp *ret, const blst_fp *a);+void blst_fp_mul_by_8(blst_fp *ret, const blst_fp *a);+void blst_fp_lshift(blst_fp *ret, const blst_fp *a, size_t count);+void blst_fp_mul(blst_fp *ret, const blst_fp *a, const blst_fp *b);+void blst_fp_sqr(blst_fp *ret, const blst_fp *a);+void blst_fp_cneg(blst_fp *ret, const blst_fp *a, bool flag);+void blst_fp_eucl_inverse(blst_fp *ret, const blst_fp *a);+void blst_fp_inverse(blst_fp *ret, const blst_fp *a);+bool blst_fp_sqrt(blst_fp *ret, const blst_fp *a);++void blst_fp_from_uint32(blst_fp *ret, const uint32_t a[12]);+void blst_uint32_from_fp(uint32_t ret[12], const blst_fp *a);+void blst_fp_from_uint64(blst_fp *ret, const uint64_t a[6]);+void blst_uint64_from_fp(uint64_t ret[6], const blst_fp *a);+void blst_fp_from_bendian(blst_fp *ret, const byte a[48]);+void blst_bendian_from_fp(byte ret[48], const blst_fp *a);+void blst_fp_from_lendian(blst_fp *ret, const byte a[48]);+void blst_lendian_from_fp(byte ret[48], const blst_fp *a);++/*+ * BLS12-381-specific Fp2 operations.+ */+void blst_fp2_add(blst_fp2 *ret, const blst_fp2 *a, const blst_fp2 *b);+void blst_fp2_sub(blst_fp2 *ret, const blst_fp2 *a, const blst_fp2 *b);+void blst_fp2_mul_by_3(blst_fp2 *ret, const blst_fp2 *a);+void blst_fp2_mul_by_8(blst_fp2 *ret, const blst_fp2 *a);+void blst_fp2_lshift(blst_fp2 *ret, const blst_fp2 *a, size_t count);+void blst_fp2_mul(blst_fp2 *ret, const blst_fp2 *a, const blst_fp2 *b);+void blst_fp2_sqr(blst_fp2 *ret, const blst_fp2 *a);+void blst_fp2_cneg(blst_fp2 *ret, const blst_fp2 *a, bool flag);+void blst_fp2_eucl_inverse(blst_fp2 *ret, const blst_fp2 *a);+void blst_fp2_inverse(blst_fp2 *ret, const blst_fp2 *a);+bool blst_fp2_sqrt(blst_fp2 *ret, const blst_fp2 *a);++/*+ * BLS12-381-specific Fp12 operations.+ */+void blst_fp12_sqr(blst_fp12 *ret, const blst_fp12 *a);+void blst_fp12_cyclotomic_sqr(blst_fp12 *ret, const blst_fp12 *a);+void blst_fp12_mul(blst_fp12 *ret, const blst_fp12 *a, const blst_fp12 *b);+void blst_fp12_mul_by_xy00z0(blst_fp12 *ret, const blst_fp12 *a,+                                             const blst_fp6 *xy00z0);+void blst_fp12_conjugate(blst_fp12 *a);+void blst_fp12_inverse(blst_fp12 *ret, const blst_fp12 *a);+/* caveat lector! |n| has to be non-zero and not more than 3! */+void blst_fp12_frobenius_map(blst_fp12 *ret, const blst_fp12 *a, size_t n);+bool blst_fp12_is_equal(const blst_fp12 *a, const blst_fp12 *b);+bool blst_fp12_is_one(const blst_fp12 *a);+bool blst_fp12_in_group(const blst_fp12 *a);+const blst_fp12 *blst_fp12_one(void);+#endif  // SWIG++/*+ * BLS12-381-specific point operations.+ */+typedef struct { blst_fp x, y, z; } blst_p1;+typedef struct { blst_fp x, y; } blst_p1_affine;++void blst_p1_add(blst_p1 *out, const blst_p1 *a, const blst_p1 *b);+void blst_p1_add_or_double(blst_p1 *out, const blst_p1 *a, const blst_p1 *b);+void blst_p1_add_affine(blst_p1 *out, const blst_p1 *a,+                                      const blst_p1_affine *b);+void blst_p1_add_or_double_affine(blst_p1 *out, const blst_p1 *a,+                                                const blst_p1_affine *b);+void blst_p1_double(blst_p1 *out, const blst_p1 *a);+void blst_p1_mult(blst_p1 *out, const blst_p1 *p, const byte *scalar,+                                                  size_t nbits);+void blst_p1_cneg(blst_p1 *p, bool cbit);+void blst_p1_to_affine(blst_p1_affine *out, const blst_p1 *in);+void blst_p1_from_affine(blst_p1 *out, const blst_p1_affine *in);+bool blst_p1_on_curve(const blst_p1 *p);+bool blst_p1_in_g1(const blst_p1 *p);+bool blst_p1_is_equal(const blst_p1 *a, const blst_p1 *b);+bool blst_p1_is_inf(const blst_p1 *a);+const blst_p1 *blst_p1_generator(void);++bool blst_p1_affine_on_curve(const blst_p1_affine *p);+bool blst_p1_affine_in_g1(const blst_p1_affine *p);+bool blst_p1_affine_is_equal(const blst_p1_affine *a, const blst_p1_affine *b);+bool blst_p1_affine_is_inf(const blst_p1_affine *a);+const blst_p1_affine *blst_p1_affine_generator(void);++typedef struct { blst_fp2 x, y, z; } blst_p2;+typedef struct { blst_fp2 x, y; } blst_p2_affine;++void blst_p2_add(blst_p2 *out, const blst_p2 *a, const blst_p2 *b);+void blst_p2_add_or_double(blst_p2 *out, const blst_p2 *a, const blst_p2 *b);+void blst_p2_add_affine(blst_p2 *out, const blst_p2 *a,+                                      const blst_p2_affine *b);+void blst_p2_add_or_double_affine(blst_p2 *out, const blst_p2 *a,+                                                const blst_p2_affine *b);+void blst_p2_double(blst_p2 *out, const blst_p2 *a);+void blst_p2_mult(blst_p2 *out, const blst_p2 *p, const byte *scalar,+                                                  size_t nbits);+void blst_p2_cneg(blst_p2 *p, bool cbit);+void blst_p2_to_affine(blst_p2_affine *out, const blst_p2 *in);+void blst_p2_from_affine(blst_p2 *out, const blst_p2_affine *in);+bool blst_p2_on_curve(const blst_p2 *p);+bool blst_p2_in_g2(const blst_p2 *p);+bool blst_p2_is_equal(const blst_p2 *a, const blst_p2 *b);+bool blst_p2_is_inf(const blst_p2 *a);+const blst_p2 *blst_p2_generator(void);++bool blst_p2_affine_on_curve(const blst_p2_affine *p);+bool blst_p2_affine_in_g2(const blst_p2_affine *p);+bool blst_p2_affine_is_equal(const blst_p2_affine *a, const blst_p2_affine *b);+bool blst_p2_affine_is_inf(const blst_p2_affine *a);+const blst_p2_affine *blst_p2_affine_generator(void);++/*+ * Multi-scalar multiplications and other multi-point operations.+ */++void blst_p1s_to_affine(blst_p1_affine dst[], const blst_p1 *const points[],+                        size_t npoints);+void blst_p1s_add(blst_p1 *ret, const blst_p1_affine *const points[],+                                size_t npoints);++size_t blst_p1s_mult_wbits_precompute_sizeof(size_t wbits, size_t npoints);+void blst_p1s_mult_wbits_precompute(blst_p1_affine table[], size_t wbits,+                                    const blst_p1_affine *const points[],+                                    size_t npoints);+size_t blst_p1s_mult_wbits_scratch_sizeof(size_t npoints);+void blst_p1s_mult_wbits(blst_p1 *ret, const blst_p1_affine table[],+                         size_t wbits, size_t npoints,+                         const byte *const scalars[], size_t nbits,+                         limb_t *scratch);++size_t blst_p1s_mult_pippenger_scratch_sizeof(size_t npoints);+void blst_p1s_mult_pippenger(blst_p1 *ret, const blst_p1_affine *const points[],+                             size_t npoints, const byte *const scalars[],+                             size_t nbits, limb_t *scratch);+void blst_p1s_tile_pippenger(blst_p1 *ret, const blst_p1_affine *const points[],+                             size_t npoints, const byte *const scalars[],+                             size_t nbits, limb_t *scratch,+                             size_t bit0, size_t window);++void blst_p2s_to_affine(blst_p2_affine dst[], const blst_p2 *const points[],+                        size_t npoints);+void blst_p2s_add(blst_p2 *ret, const blst_p2_affine *const points[],+                                size_t npoints);++size_t blst_p2s_mult_wbits_precompute_sizeof(size_t wbits, size_t npoints);+void blst_p2s_mult_wbits_precompute(blst_p2_affine table[], size_t wbits,+                                    const blst_p2_affine *const points[],+                                    size_t npoints);+size_t blst_p2s_mult_wbits_scratch_sizeof(size_t npoints);+void blst_p2s_mult_wbits(blst_p2 *ret, const blst_p2_affine table[],+                         size_t wbits, size_t npoints,+                         const byte *const scalars[], size_t nbits,+                         limb_t *scratch);++size_t blst_p2s_mult_pippenger_scratch_sizeof(size_t npoints);+void blst_p2s_mult_pippenger(blst_p2 *ret, const blst_p2_affine *const points[],+                             size_t npoints, const byte *const scalars[],+                             size_t nbits, limb_t *scratch);+void blst_p2s_tile_pippenger(blst_p2 *ret, const blst_p2_affine *const points[],+                             size_t npoints, const byte *const scalars[],+                             size_t nbits, limb_t *scratch,+                             size_t bit0, size_t window);++/*+ * Hash-to-curve operations.+ */+#ifndef SWIG+void blst_map_to_g1(blst_p1 *out, const blst_fp *u, const blst_fp *v DEFNULL);+void blst_map_to_g2(blst_p2 *out, const blst_fp2 *u, const blst_fp2 *v DEFNULL);+#endif++void blst_encode_to_g1(blst_p1 *out,+                       const byte *msg, size_t msg_len,+                       const byte *DST DEFNULL, size_t DST_len DEFNULL,+                       const byte *aug DEFNULL, size_t aug_len DEFNULL);+void blst_hash_to_g1(blst_p1 *out,+                     const byte *msg, size_t msg_len,+                     const byte *DST DEFNULL, size_t DST_len DEFNULL,+                     const byte *aug DEFNULL, size_t aug_len DEFNULL);++void blst_encode_to_g2(blst_p2 *out,+                       const byte *msg, size_t msg_len,+                       const byte *DST DEFNULL, size_t DST_len DEFNULL,+                       const byte *aug DEFNULL, size_t aug_len DEFNULL);+void blst_hash_to_g2(blst_p2 *out,+                     const byte *msg, size_t msg_len,+                     const byte *DST DEFNULL, size_t DST_len DEFNULL,+                     const byte *aug DEFNULL, size_t aug_len DEFNULL);++/*+ * Zcash-compatible serialization/deserialization.+ */+void blst_p1_serialize(byte out[96], const blst_p1 *in);+void blst_p1_compress(byte out[48], const blst_p1 *in);+void blst_p1_affine_serialize(byte out[96], const blst_p1_affine *in);+void blst_p1_affine_compress(byte out[48], const blst_p1_affine *in);+BLST_ERROR blst_p1_uncompress(blst_p1_affine *out, const byte in[48]);+BLST_ERROR blst_p1_deserialize(blst_p1_affine *out, const byte in[96]);++void blst_p2_serialize(byte out[192], const blst_p2 *in);+void blst_p2_compress(byte out[96], const blst_p2 *in);+void blst_p2_affine_serialize(byte out[192], const blst_p2_affine *in);+void blst_p2_affine_compress(byte out[96], const blst_p2_affine *in);+BLST_ERROR blst_p2_uncompress(blst_p2_affine *out, const byte in[96]);+BLST_ERROR blst_p2_deserialize(blst_p2_affine *out, const byte in[192]);++/*+ * Specification defines two variants, 'minimal-signature-size' and+ * 'minimal-pubkey-size'. To unify appearance we choose to distinguish+ * them by suffix referring to the public key type, more specifically+ * _pk_in_g1 corresponds to 'minimal-pubkey-size' and _pk_in_g2 - to+ * 'minimal-signature-size'. It might appear a bit counterintuitive+ * in sign call, but no matter how you twist it, something is bound to+ * turn a little odd.+ */+/*+ * Secret-key operations.+ */+void blst_keygen(blst_scalar *out_SK, const byte *IKM, size_t IKM_len,+                 const byte *info DEFNULL, size_t info_len DEFNULL);+void blst_sk_to_pk_in_g1(blst_p1 *out_pk, const blst_scalar *SK);+void blst_sign_pk_in_g1(blst_p2 *out_sig, const blst_p2 *hash,+                                          const blst_scalar *SK);+void blst_sk_to_pk_in_g2(blst_p2 *out_pk, const blst_scalar *SK);+void blst_sign_pk_in_g2(blst_p1 *out_sig, const blst_p1 *hash,+                                          const blst_scalar *SK);++/*+ * Pairing interface.+ */+#ifndef SWIG+void blst_miller_loop(blst_fp12 *ret, const blst_p2_affine *Q,+                                      const blst_p1_affine *P);+void blst_miller_loop_n(blst_fp12 *ret, const blst_p2_affine *const Qs[],+                                        const blst_p1_affine *const Ps[],+                                        size_t n);+void blst_final_exp(blst_fp12 *ret, const blst_fp12 *f);+void blst_precompute_lines(blst_fp6 Qlines[68], const blst_p2_affine *Q);+void blst_miller_loop_lines(blst_fp12 *ret, const blst_fp6 Qlines[68],+                                            const blst_p1_affine *P);+bool blst_fp12_finalverify(const blst_fp12 *gt1, const blst_fp12 *gt2);+#endif++#ifdef __BLST_CGO__+typedef limb_t blst_pairing;+#elif defined(__BLST_RUST_BINDGEN__)+typedef struct {} blst_pairing;+#else+typedef struct blst_opaque blst_pairing;+#endif++size_t blst_pairing_sizeof(void);+void blst_pairing_init(blst_pairing *new_ctx, bool hash_or_encode,+                       const byte *DST DEFNULL, size_t DST_len DEFNULL);+const byte *blst_pairing_get_dst(const blst_pairing *ctx);+void blst_pairing_commit(blst_pairing *ctx);+BLST_ERROR blst_pairing_aggregate_pk_in_g2(blst_pairing *ctx,+                                           const blst_p2_affine *PK,+                                           const blst_p1_affine *signature,+                                           const byte *msg, size_t msg_len,+                                           const byte *aug DEFNULL,+                                           size_t aug_len DEFNULL);+BLST_ERROR blst_pairing_chk_n_aggr_pk_in_g2(blst_pairing *ctx,+                                            const blst_p2_affine *PK,+                                            bool pk_grpchk,+                                            const blst_p1_affine *signature,+                                            bool sig_grpchk,+                                            const byte *msg, size_t msg_len,+                                            const byte *aug DEFNULL,+                                            size_t aug_len DEFNULL);+BLST_ERROR blst_pairing_mul_n_aggregate_pk_in_g2(blst_pairing *ctx,+                                                 const blst_p2_affine *PK,+                                                 const blst_p1_affine *sig,+                                                 const byte *scalar,+                                                 size_t nbits,+                                                 const byte *msg,+                                                 size_t msg_len,+                                                 const byte *aug DEFNULL,+                                                 size_t aug_len DEFNULL);+BLST_ERROR blst_pairing_chk_n_mul_n_aggr_pk_in_g2(blst_pairing *ctx,+                                                  const blst_p2_affine *PK,+                                                  bool pk_grpchk,+                                                  const blst_p1_affine *sig,+                                                  bool sig_grpchk,+                                                  const byte *scalar,+                                                  size_t nbits,+                                                  const byte *msg,+                                                  size_t msg_len,+                                                  const byte *aug DEFNULL,+                                                  size_t aug_len DEFNULL);+BLST_ERROR blst_pairing_aggregate_pk_in_g1(blst_pairing *ctx,+                                           const blst_p1_affine *PK,+                                           const blst_p2_affine *signature,+                                           const byte *msg, size_t msg_len,+                                           const byte *aug DEFNULL,+                                           size_t aug_len DEFNULL);+BLST_ERROR blst_pairing_chk_n_aggr_pk_in_g1(blst_pairing *ctx,+                                            const blst_p1_affine *PK,+                                            bool pk_grpchk,+                                            const blst_p2_affine *signature,+                                            bool sig_grpchk,+                                            const byte *msg, size_t msg_len,+                                            const byte *aug DEFNULL,+                                            size_t aug_len DEFNULL);+BLST_ERROR blst_pairing_mul_n_aggregate_pk_in_g1(blst_pairing *ctx,+                                                 const blst_p1_affine *PK,+                                                 const blst_p2_affine *sig,+                                                 const byte *scalar,+                                                 size_t nbits,+                                                 const byte *msg,+                                                 size_t msg_len,+                                                 const byte *aug DEFNULL,+                                                 size_t aug_len DEFNULL);+BLST_ERROR blst_pairing_chk_n_mul_n_aggr_pk_in_g1(blst_pairing *ctx,+                                                  const blst_p1_affine *PK,+                                                  bool pk_grpchk,+                                                  const blst_p2_affine *sig,+                                                  bool sig_grpchk,+                                                  const byte *scalar,+                                                  size_t nbits,+                                                  const byte *msg,+                                                  size_t msg_len,+                                                  const byte *aug DEFNULL,+                                                  size_t aug_len DEFNULL);+BLST_ERROR blst_pairing_merge(blst_pairing *ctx, const blst_pairing *ctx1);+bool blst_pairing_finalverify(const blst_pairing *ctx,+                              const blst_fp12 *gtsig DEFNULL);+++/*+ * Customarily applications aggregate signatures separately.+ * In which case application would have to pass NULLs for |signature|+ * to blst_pairing_aggregate calls and pass aggregated signature+ * collected with these calls to blst_pairing_finalverify. Inputs are+ * Zcash-compatible "straight-from-wire" byte vectors, compressed or+ * not.+ */+BLST_ERROR blst_aggregate_in_g1(blst_p1 *out, const blst_p1 *in,+                                              const byte *zwire);+BLST_ERROR blst_aggregate_in_g2(blst_p2 *out, const blst_p2 *in,+                                              const byte *zwire);++void blst_aggregated_in_g1(blst_fp12 *out, const blst_p1_affine *signature);+void blst_aggregated_in_g2(blst_fp12 *out, const blst_p2_affine *signature);++/*+ * "One-shot" CoreVerify entry points.+ */+BLST_ERROR blst_core_verify_pk_in_g1(const blst_p1_affine *pk,+                                     const blst_p2_affine *signature,+                                     bool hash_or_encode,+                                     const byte *msg, size_t msg_len,+                                     const byte *DST DEFNULL,+                                     size_t DST_len DEFNULL,+                                     const byte *aug DEFNULL,+                                     size_t aug_len DEFNULL);+BLST_ERROR blst_core_verify_pk_in_g2(const blst_p2_affine *pk,+                                     const blst_p1_affine *signature,+                                     bool hash_or_encode,+                                     const byte *msg, size_t msg_len,+                                     const byte *DST DEFNULL,+                                     size_t DST_len DEFNULL,+                                     const byte *aug DEFNULL,+                                     size_t aug_len DEFNULL);++extern const blst_p1_affine BLS12_381_G1;+extern const blst_p1_affine BLS12_381_NEG_G1;+extern const blst_p2_affine BLS12_381_G2;+extern const blst_p2_affine BLS12_381_NEG_G2;++#include "blst_aux.h"++#ifdef __cplusplus+}+#elif defined(__blst_h_bool__)+# undef __blst_h_bool__+# undef bool+#endif+#endif
+ vendor/external/blst/bindings/blst_aux.h view
@@ -0,0 +1,117 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLST_AUX_H__+#define __BLST_AUX_H__+/*+ * This file lists interfaces that might be promoted to blst.h or removed,+ * depending on their proven/unproven worthiness.+ */++void blst_fr_ct_bfly(blst_fr *x0, blst_fr *x1, const blst_fr *twiddle);+void blst_fr_gs_bfly(blst_fr *x0, blst_fr *x1, const blst_fr *twiddle);+void blst_fr_to(blst_fr *ret, const blst_fr *a);+void blst_fr_from(blst_fr *ret, const blst_fr *a);+#ifdef BLST_FR_PENTAROOT+void blst_fr_pentaroot(blst_fr *ret, const blst_fr *a);+void blst_fr_pentapow(blst_fr *ret, const blst_fr *a);+#endif++void blst_fp_to(blst_fp *ret, const blst_fp *a);+void blst_fp_from(blst_fp *ret, const blst_fp *a);++bool blst_fp_is_square(const blst_fp *a);+bool blst_fp2_is_square(const blst_fp2 *a);++void blst_p1_from_jacobian(blst_p1 *out, const blst_p1 *in);+void blst_p2_from_jacobian(blst_p2 *out, const blst_p2 *in);++/*+ * Below functions produce both point and deserialized outcome of+ * SkToPk and Sign. However, deserialized outputs are pre-decorated+ * with sign and infinity bits. This means that you have to bring the+ * output into compliance prior returning to application. If you want+ * compressed point value, then do [equivalent of]+ *+ *  byte temp[96];+ *  blst_sk_to_pk2_in_g1(temp, out_pk, SK);+ *  temp[0] |= 0x80;+ *  memcpy(out, temp, 48);+ *+ * Otherwise do+ *+ *  blst_sk_to_pk2_in_g1(out, out_pk, SK);+ *  out[0] &= ~0x20;+ *+ * Either |out| or |out_<point>| can be NULL.+ */+void blst_sk_to_pk2_in_g1(byte out[96], blst_p1_affine *out_pk,+                          const blst_scalar *SK);+void blst_sign_pk2_in_g1(byte out[192], blst_p2_affine *out_sig,+                         const blst_p2 *hash, const blst_scalar *SK);+void blst_sk_to_pk2_in_g2(byte out[192], blst_p2_affine *out_pk,+                          const blst_scalar *SK);+void blst_sign_pk2_in_g2(byte out[96], blst_p1_affine *out_sig,+                         const blst_p1 *hash, const blst_scalar *SK);++#ifdef __BLST_RUST_BINDGEN__+typedef struct {} blst_uniq;+#else+typedef struct blst_opaque blst_uniq;+#endif++size_t blst_uniq_sizeof(size_t n_nodes);+void blst_uniq_init(blst_uniq *tree);+bool blst_uniq_test(blst_uniq *tree, const byte *msg, size_t len);++#ifdef expand_message_xmd+void expand_message_xmd(unsigned char *bytes, size_t len_in_bytes,+                        const unsigned char *aug, size_t aug_len,+                        const unsigned char *msg, size_t msg_len,+                        const unsigned char *DST, size_t DST_len);+#else+void blst_expand_message_xmd(byte *out, size_t out_len,+                             const byte *msg, size_t msg_len,+                             const byte *DST, size_t DST_len);+#endif++void blst_p1_unchecked_mult(blst_p1 *out, const blst_p1 *p, const byte *scalar,+                                                            size_t nbits);+void blst_p2_unchecked_mult(blst_p2 *out, const blst_p2 *p, const byte *scalar,+                                                            size_t nbits);++void blst_pairing_raw_aggregate(blst_pairing *ctx, const blst_p2_affine *q,+                                                   const blst_p1_affine *p);+blst_fp12 *blst_pairing_as_fp12(blst_pairing *ctx);+void blst_bendian_from_fp12(byte out[48*12], const blst_fp12 *a);++void blst_keygen_v3(blst_scalar *out_SK, const byte *IKM, size_t IKM_len,+                    const byte *info DEFNULL, size_t info_len DEFNULL);+void blst_keygen_v4_5(blst_scalar *out_SK, const byte *IKM, size_t IKM_len,+                      const byte *salt, size_t salt_len,+                      const byte *info DEFNULL, size_t info_len DEFNULL);+void blst_keygen_v5(blst_scalar *out_SK, const byte *IKM, size_t IKM_len,+                    const byte *salt, size_t salt_len,+                    const byte *info DEFNULL, size_t info_len DEFNULL);+void blst_derive_master_eip2333(blst_scalar *out_SK,+                                const byte *IKM, size_t IKM_len);+void blst_derive_child_eip2333(blst_scalar *out_SK, const blst_scalar *SK,+                               uint32_t child_index);++void blst_scalar_from_hexascii(blst_scalar *out, const byte *hex);+void blst_fr_from_hexascii(blst_fr *ret, const byte *hex);+void blst_fp_from_hexascii(blst_fp *ret, const byte *hex);++size_t blst_p1_sizeof(void);+size_t blst_p1_affine_sizeof(void);+size_t blst_p2_sizeof(void);+size_t blst_p2_affine_sizeof(void);+size_t blst_fp12_sizeof(void);++/*+ * Single-shot SHA-256 hash function.+ */+void blst_sha256(byte out[32], const byte *msg, size_t msg_len);+#endif
+ vendor/external/blst/src/aggregate.c view
@@ -0,0 +1,673 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++/*+ * Usage pattern on single-processor system is+ *+ * blst_pairing_init(ctx, hash_or_encode, DST);+ * blst_pairing_aggregate_pk_in_g1(ctx, PK[0], aggregated_signature, msg[0]);+ * blst_pairing_aggregate_pk_in_g1(ctx, PK[1], NULL, msg[1]);+ * ...+ * blst_pairing_commit(ctx);+ * blst_pairing_finalverify(ctx, NULL);+ *+ ***********************************************************************+ * Usage pattern on multi-processor system is+ *+ *   blst_pairing_init(pk[0], hash_or_encode, DST);+ *   blst_pairing_init(pk[1], hash_or_encode, DST);+ *   ...+ * start threads each processing an N/nthreads slice of PKs and messages:+ *     blst_pairing_aggregate_pk_in_g1(pk[i], PK[i*n+0], NULL, msg[i*n+0]);+ *     blst_pairing_aggregate_pk_in_g1(pk[i], PK[i*n+1], NULL, msg[i*n+1]);+ *     ...+ *     blst_pairing_commit(pkx);+ *   ...+ * meanwhile in main thread+ *   blst_fp12 gtsig;+ *   blst_aggregated_in_g2(&gtsig, aggregated_signature);+ * join threads and merge their contexts:+ *   blst_pairing_merge(pk[0], pk[1]);+ *   blst_pairing_merge(pk[0], pk[2]);+ *   ...+ *   blst_pairing_finalverify(pk[0], gtsig);+ */++#ifndef N_MAX+# define N_MAX 8+#endif++typedef union { POINTonE1 e1; POINTonE2 e2; } AggregatedSignature;+typedef struct {+    unsigned int ctrl;+    unsigned int nelems;+    const void *DST;+    size_t DST_len;+    vec384fp12 GT;+    AggregatedSignature AggrSign;+    POINTonE2_affine Q[N_MAX];+    POINTonE1_affine P[N_MAX];+} PAIRING;++enum { AGGR_UNDEFINED      = 0,+       AGGR_MIN_SIG        = 1,+       AGGR_MIN_PK         = 2,+       AGGR_SIGN_SET       = 0x10,+       AGGR_GT_SET         = 0x20,+       AGGR_HASH_OR_ENCODE = 0x40 };+#define MIN_SIG_OR_PK (AGGR_MIN_SIG | AGGR_MIN_PK)++static const size_t sizeof_pairing = (sizeof(PAIRING) + 7) & ~(size_t)7;++size_t blst_pairing_sizeof(void)+{   return sizeof_pairing;   }++void blst_pairing_init(PAIRING *ctx, int hash_or_encode,+                       const void *DST, size_t DST_len)+{+    ctx->ctrl = AGGR_UNDEFINED | (hash_or_encode ? AGGR_HASH_OR_ENCODE : 0);+    ctx->nelems = 0;+    ctx->DST = (uptr_t)DST==(uptr_t)((byte *)ctx+sizeof_pairing) ? (void *)42+                                                                 : DST;+    ctx->DST_len = DST_len;+}++static const void *pairing_get_dst(const PAIRING *ctx)+{   return (uptr_t)ctx->DST==(uptr_t)42 ? (const byte *)ctx+sizeof_pairing+                                        : ctx->DST;+}++const void *blst_pairing_get_dst(const PAIRING *ctx)+{   return pairing_get_dst(ctx);   }++#define FROM_AFFINE(out,in) do { \+    vec_copy((out)->X, in->X, 2*sizeof(in->X)), \+    vec_select((out)->Z, in->X, BLS12_381_Rx.p, sizeof(in->X), \+                         vec_is_zero(in->X, 2*sizeof(in->X))); } while(0)++/*+ * Optional |nbits|-wide |scalar| is used to facilitate multiple aggregated+ * signature verification as discussed at+ * https://ethresear.ch/t/fast-verification-of-multiple-bls-signatures/5407.+ * Usage pattern is not finalized yet, because (sig != NULL) is better and+ * will be handled separately...+ */+static BLST_ERROR PAIRING_Aggregate_PK_in_G2(PAIRING *ctx,+                                             const POINTonE2_affine *PK,+                                             size_t pk_groupcheck,+                                             const POINTonE1_affine *sig,+                                             size_t sig_groupcheck,+                                             const byte *scalar, size_t nbits,+                                             const void *msg, size_t msg_len,+                                             const void *aug, size_t aug_len)+{+    if (ctx->ctrl & AGGR_MIN_PK)+        return BLST_AGGR_TYPE_MISMATCH;++    ctx->ctrl |= AGGR_MIN_SIG;++    /*+     * Since we don't know if the signature is individual or aggregated,+     * the only sensible thing to do is to skip over infinite one and+     * count on the corresponding infinite public key to be rejected,+     * in case the signature is non-aggregated that is.+     */+    if (sig != NULL && !vec_is_zero(sig, sizeof(*sig))) {+        POINTonE1 *S = &ctx->AggrSign.e1;+        POINTonE1 P[1];++        FROM_AFFINE(P, sig);++        if (sig_groupcheck && !POINTonE1_in_G1(P))+            return BLST_POINT_NOT_IN_GROUP;++        if (ctx->ctrl & AGGR_SIGN_SET) {+            if (nbits != 0 && scalar != NULL) {+                POINTonE1_mult_w5(P, P, scalar, nbits);+                POINTonE1_dadd(S, S, P, NULL);+            } else {+                POINTonE1_dadd_affine(S, S, sig);+            }+        } else {+            ctx->ctrl |= AGGR_SIGN_SET;+            if (nbits != 0 && scalar != NULL)+                POINTonE1_mult_w5(S, P, scalar, nbits);+            else+                vec_copy(S, P, sizeof(P));+        }+    }++    if (PK != NULL) {+        unsigned int n;+        POINTonE1 H[1];+        const void *DST = pairing_get_dst(ctx);++        /*+         * Reject infinite public keys.+         */+        if (vec_is_zero(PK, sizeof(*PK)))+            return BLST_PK_IS_INFINITY;++        if (pk_groupcheck) {+            POINTonE2 P[1];++            FROM_AFFINE(P, PK);+            if (!POINTonE2_in_G2(P))+                return BLST_POINT_NOT_IN_GROUP;+        }++        if (ctx->ctrl & AGGR_HASH_OR_ENCODE)+            Hash_to_G1(H, msg, msg_len, DST, ctx->DST_len, aug, aug_len);+        else+            Encode_to_G1(H, msg, msg_len, DST, ctx->DST_len, aug, aug_len);++        if (nbits != 0 && scalar != NULL)+            POINTonE1_mult_w5(H, H, scalar, nbits);++        POINTonE1_from_Jacobian(H, H);++        n = ctx->nelems;+        vec_copy(ctx->Q + n, PK, sizeof(POINTonE2_affine));+        vec_copy(ctx->P + n, H, sizeof(POINTonE1_affine));+        if (++n == N_MAX) {+            if (ctx->ctrl & AGGR_GT_SET) {+                vec384fp12 GT;+                miller_loop_n(GT, ctx->Q, ctx->P, n);+                mul_fp12(ctx->GT, ctx->GT, GT);+            } else {+                miller_loop_n(ctx->GT, ctx->Q, ctx->P, n);+                ctx->ctrl |= AGGR_GT_SET;+            }+            n = 0;+        }+        ctx->nelems = n;+    }++    return BLST_SUCCESS;+}++BLST_ERROR blst_pairing_aggregate_pk_in_g2(PAIRING *ctx,+                                           const POINTonE2_affine *PK,+                                           const POINTonE1_affine *signature,+                                           const void *msg, size_t msg_len,+                                           const void *aug, size_t aug_len)+{   return PAIRING_Aggregate_PK_in_G2(ctx, PK, 0, signature, 1, NULL, 0,+                                      msg, msg_len, aug, aug_len);+}++BLST_ERROR blst_pairing_mul_n_aggregate_pk_in_g2(PAIRING *ctx,+                                                 const POINTonE2_affine *PK,+                                                 const POINTonE1_affine *sig,+                                                 const byte *scalar,+                                                 size_t nbits,+                                                 const void *msg,+                                                 size_t msg_len,+                                                 const void *aug,+                                                 size_t aug_len)+{   return PAIRING_Aggregate_PK_in_G2(ctx, PK, 0, sig, 1, scalar, nbits,+                                      msg, msg_len, aug, aug_len);+}++BLST_ERROR blst_pairing_chk_n_aggr_pk_in_g2(PAIRING *ctx,+                                            const POINTonE2_affine *PK,+                                            size_t pk_grpchk,+                                            const POINTonE1_affine *signature,+                                            size_t sig_grpchk,+                                            const void *msg, size_t msg_len,+                                            const void *aug, size_t aug_len)+{   return PAIRING_Aggregate_PK_in_G2(ctx, PK, pk_grpchk, signature, sig_grpchk,+                                      NULL, 0, msg, msg_len, aug, aug_len);+}++BLST_ERROR blst_pairing_chk_n_mul_n_aggr_pk_in_g2(PAIRING *ctx,+                                                  const POINTonE2_affine *PK,+                                                  size_t pk_grpchk,+                                                  const POINTonE1_affine *sig,+                                                  size_t sig_grpchk,+                                                  const byte *scalar,+                                                  size_t nbits,+                                                  const void *msg,+                                                  size_t msg_len,+                                                  const void *aug,+                                                  size_t aug_len)+{   return PAIRING_Aggregate_PK_in_G2(ctx, PK, pk_grpchk, sig, sig_grpchk,+                                      scalar, nbits,+                                      msg, msg_len, aug, aug_len);+}++static BLST_ERROR PAIRING_Aggregate_PK_in_G1(PAIRING *ctx,+                                             const POINTonE1_affine *PK,+                                             size_t pk_groupcheck,+                                             const POINTonE2_affine *sig,+                                             size_t sig_groupcheck,+                                             const byte *scalar, size_t nbits,+                                             const void *msg, size_t msg_len,+                                             const void *aug, size_t aug_len)+{+    if (ctx->ctrl & AGGR_MIN_SIG)+        return BLST_AGGR_TYPE_MISMATCH;++    ctx->ctrl |= AGGR_MIN_PK;++    /*+     * Since we don't know if the signature is individual or aggregated,+     * the only sensible thing to do is to skip over infinite one and+     * count on the corresponding infinite public key to be rejected,+     * in case the signature is non-aggregated that is.+     */+    if (sig != NULL && !vec_is_zero(sig, sizeof(*sig))) {+        POINTonE2 *S = &ctx->AggrSign.e2;+        POINTonE2 P[1];++        FROM_AFFINE(P, sig);++        if (sig_groupcheck && !POINTonE2_in_G2(P))+            return BLST_POINT_NOT_IN_GROUP;++        if (ctx->ctrl & AGGR_SIGN_SET) {+            if (nbits != 0 && scalar != NULL) {++                POINTonE2_mult_w5(P, P, scalar, nbits);+                POINTonE2_dadd(S, S, P, NULL);+            } else {+                POINTonE2_dadd_affine(S, S, sig);+            }+        } else {+            ctx->ctrl |= AGGR_SIGN_SET;+            if (nbits != 0 && scalar != NULL)+                POINTonE2_mult_w5(S, P, scalar, nbits);+            else+                vec_copy(S, P, sizeof(P));+        }+    }++    if (PK != NULL) {+        unsigned int n;+        POINTonE2 H[1];+        POINTonE1 pk[1];+        const void *DST = pairing_get_dst(ctx);++        /*+         * Reject infinite public keys.+         */+        if (vec_is_zero(PK, sizeof(*PK)))+            return BLST_PK_IS_INFINITY;++        if (pk_groupcheck) {+            POINTonE1 P[1];++            FROM_AFFINE(P, PK);+            if (!POINTonE1_in_G1(P))+                return BLST_POINT_NOT_IN_GROUP;+        }++        if (ctx->ctrl & AGGR_HASH_OR_ENCODE)+            Hash_to_G2(H, msg, msg_len, DST, ctx->DST_len, aug, aug_len);+        else+            Encode_to_G2(H, msg, msg_len, DST, ctx->DST_len, aug, aug_len);++        POINTonE2_from_Jacobian(H, H);++        if (nbits != 0 && scalar != NULL) {+            FROM_AFFINE(pk, PK);+            POINTonE1_mult_w5(pk, pk, scalar, nbits);+            POINTonE1_from_Jacobian(pk, pk);+            PK = (const POINTonE1_affine *)pk;+        }++        n = ctx->nelems;+        vec_copy(ctx->Q + n, H, sizeof(POINTonE2_affine));+        vec_copy(ctx->P + n, PK, sizeof(POINTonE1_affine));+        if (++n == N_MAX) {+            if (ctx->ctrl & AGGR_GT_SET) {+                vec384fp12 GT;+                miller_loop_n(GT, ctx->Q, ctx->P, n);+                mul_fp12(ctx->GT, ctx->GT, GT);+            } else {+                miller_loop_n(ctx->GT, ctx->Q, ctx->P, n);+                ctx->ctrl |= AGGR_GT_SET;+            }+            n = 0;+        }+        ctx->nelems = n;+    }++    return BLST_SUCCESS;+}++BLST_ERROR blst_pairing_aggregate_pk_in_g1(PAIRING *ctx,+                                           const POINTonE1_affine *PK,+                                           const POINTonE2_affine *signature,+                                           const void *msg, size_t msg_len,+                                           const void *aug, size_t aug_len)+{   return PAIRING_Aggregate_PK_in_G1(ctx, PK, 0, signature, 1, NULL, 0,+                                      msg, msg_len, aug, aug_len);+}++BLST_ERROR blst_pairing_mul_n_aggregate_pk_in_g1(PAIRING *ctx,+                                                 const POINTonE1_affine *PK,+                                                 const POINTonE2_affine *sig,+                                                 const byte *scalar,+                                                 size_t nbits,+                                                 const void *msg,+                                                 size_t msg_len,+                                                 const void *aug,+                                                 size_t aug_len)+{   return PAIRING_Aggregate_PK_in_G1(ctx, PK, 0, sig, 1, scalar, nbits,+                                      msg, msg_len, aug, aug_len);+}++BLST_ERROR blst_pairing_chk_n_aggr_pk_in_g1(PAIRING *ctx,+                                            const POINTonE1_affine *PK,+                                            size_t pk_grpchk,+                                            const POINTonE2_affine *signature,+                                            size_t sig_grpchk,+                                            const void *msg, size_t msg_len,+                                            const void *aug, size_t aug_len)+{   return PAIRING_Aggregate_PK_in_G1(ctx, PK, pk_grpchk, signature, sig_grpchk,+                                      NULL, 0, msg, msg_len, aug, aug_len);+}++BLST_ERROR blst_pairing_chk_n_mul_n_aggr_pk_in_g1(PAIRING *ctx,+                                                  const POINTonE1_affine *PK,+                                                  size_t pk_grpchk,+                                                  const POINTonE2_affine *sig,+                                                  size_t sig_grpchk,+                                                  const byte *scalar,+                                                  size_t nbits,+                                                  const void *msg,+                                                  size_t msg_len,+                                                  const void *aug,+                                                  size_t aug_len)+{   return PAIRING_Aggregate_PK_in_G1(ctx, PK, pk_grpchk, sig, sig_grpchk,+                                      scalar, nbits,+                                      msg, msg_len, aug, aug_len);+}++static void PAIRING_Commit(PAIRING *ctx)+{+    unsigned int n;++    if ((n = ctx->nelems) != 0) {+        if (ctx->ctrl & AGGR_GT_SET) {+            vec384fp12 GT;+            miller_loop_n(GT, ctx->Q, ctx->P, n);+            mul_fp12(ctx->GT, ctx->GT, GT);+        } else {+            miller_loop_n(ctx->GT, ctx->Q, ctx->P, n);+            ctx->ctrl |= AGGR_GT_SET;+        }+        ctx->nelems = 0;+    }+}++void blst_pairing_commit(PAIRING *ctx)+{   PAIRING_Commit(ctx);   }++BLST_ERROR blst_pairing_merge(PAIRING *ctx, const PAIRING *ctx1)+{+    if ((ctx->ctrl & MIN_SIG_OR_PK) != AGGR_UNDEFINED+        && (ctx1->ctrl & MIN_SIG_OR_PK) != AGGR_UNDEFINED+        && (ctx->ctrl & ctx1->ctrl & MIN_SIG_OR_PK) == 0)+        return BLST_AGGR_TYPE_MISMATCH;++    /* context producers are expected to have called blst_pairing_commit */+    if (ctx->nelems || ctx1->nelems)+        return BLST_AGGR_TYPE_MISMATCH;++    ctx->ctrl |= ctx1->ctrl & MIN_SIG_OR_PK;++    switch (ctx->ctrl & MIN_SIG_OR_PK) {+        case AGGR_MIN_SIG:+            if (ctx->ctrl & ctx1->ctrl & AGGR_SIGN_SET) {+                POINTonE1_dadd(&ctx->AggrSign.e1, &ctx->AggrSign.e1,+                                                  &ctx1->AggrSign.e1, NULL);+            } else if (ctx1->ctrl & AGGR_SIGN_SET) {+                ctx->ctrl |= AGGR_SIGN_SET;+                vec_copy(&ctx->AggrSign.e1, &ctx1->AggrSign.e1,+                         sizeof(ctx->AggrSign.e1));+            }+            break;+        case AGGR_MIN_PK:+            if (ctx->ctrl & ctx1->ctrl & AGGR_SIGN_SET) {+                POINTonE2_dadd(&ctx->AggrSign.e2, &ctx->AggrSign.e2,+                                                  &ctx1->AggrSign.e2, NULL);+            } else if (ctx1->ctrl & AGGR_SIGN_SET) {+                ctx->ctrl |= AGGR_SIGN_SET;+                vec_copy(&ctx->AggrSign.e2, &ctx1->AggrSign.e2,+                         sizeof(ctx->AggrSign.e2));+            }+            break;+        case AGGR_UNDEFINED:+            break;+        default:+            return BLST_AGGR_TYPE_MISMATCH;+    }++    if (ctx->ctrl & ctx1->ctrl & AGGR_GT_SET) {+        mul_fp12(ctx->GT, ctx->GT, ctx1->GT);+    } else if (ctx1->ctrl & AGGR_GT_SET) {+        ctx->ctrl |= AGGR_GT_SET;+        vec_copy(ctx->GT, ctx1->GT, sizeof(ctx->GT));+    }++    return BLST_SUCCESS;+}++static bool_t PAIRING_FinalVerify(const PAIRING *ctx, const vec384fp12 GTsig)+{+    vec384fp12 GT;++    if (!(ctx->ctrl & AGGR_GT_SET))+        return 0;++    if (GTsig != NULL) {+        vec_copy(GT, GTsig, sizeof(GT));+    } else if (ctx->ctrl & AGGR_SIGN_SET) {+        AggregatedSignature AggrSign;++        switch (ctx->ctrl & MIN_SIG_OR_PK) {+            case AGGR_MIN_SIG:+                POINTonE1_from_Jacobian(&AggrSign.e1, &ctx->AggrSign.e1);+                miller_loop_n(GT, (const POINTonE2_affine *)&BLS12_381_G2,+                                  (const POINTonE1_affine *)&AggrSign.e1, 1);+                break;+            case AGGR_MIN_PK:+                POINTonE2_from_Jacobian(&AggrSign.e2, &ctx->AggrSign.e2);+                miller_loop_n(GT, (const POINTonE2_affine *)&AggrSign.e2,+                                  (const POINTonE1_affine *)&BLS12_381_G1, 1);+                break;+            default:+                return 0;+        }+    } else {+        /*+         * The aggregated signature was infinite, relation between the+         * hashes and the public keys has to be VERY special...+         */+        vec_copy(GT, BLS12_381_Rx.p12, sizeof(GT));+    }++    conjugate_fp12(GT);+    mul_fp12(GT, GT, ctx->GT);+    final_exp(GT, GT);++    /* return GT==1 */+    return vec_is_equal(GT[0][0], BLS12_381_Rx.p2, sizeof(GT[0][0])) &+           vec_is_zero(GT[0][1], sizeof(GT) - sizeof(GT[0][0]));+}++int blst_pairing_finalverify(const PAIRING *ctx, const vec384fp12 GTsig)+{   return (int)PAIRING_FinalVerify(ctx, GTsig);   }++int blst_fp12_finalverify(const vec384fp12 GT1, const vec384fp12 GT2)+{+    vec384fp12 GT;++    vec_copy(GT, GT1, sizeof(GT));+    conjugate_fp12(GT);+    mul_fp12(GT, GT, GT2);+    final_exp(GT, GT);++    /* return GT==1 */+    return (int)(vec_is_equal(GT[0][0], BLS12_381_Rx.p2, sizeof(GT[0][0])) &+                 vec_is_zero(GT[0][1], sizeof(GT) - sizeof(GT[0][0])));+}++void blst_pairing_raw_aggregate(PAIRING *ctx, const POINTonE2_affine *q,+                                              const POINTonE1_affine *p)+{+    unsigned int n;++    if (vec_is_zero(q, sizeof(*q)) & vec_is_zero(p, sizeof(*p)))+        return;++    n = ctx->nelems;+    vec_copy(ctx->Q + n, q, sizeof(*q));+    vec_copy(ctx->P + n, p, sizeof(*p));+    if (++n == N_MAX) {+        if (ctx->ctrl & AGGR_GT_SET) {+            vec384fp12 GT;+            miller_loop_n(GT, ctx->Q, ctx->P, n);+            mul_fp12(ctx->GT, ctx->GT, GT);+        } else {+            miller_loop_n(ctx->GT, ctx->Q, ctx->P, n);+            ctx->ctrl |= AGGR_GT_SET;+        }+        n = 0;+    }+    ctx->nelems = n;+}++vec384fp12 *blst_pairing_as_fp12(PAIRING *ctx)+{+    PAIRING_Commit(ctx);+    return (vec384fp12 *)ctx->GT;+}++/*+ * PAIRING context-free entry points.+ *+ * To perform FastAggregateVerify, aggregate all public keys and+ * signatures with corresponding blst_aggregate_in_g{12}, convert+ * result to affine and call suitable blst_core_verify_pk_in_g{12}+ * or blst_aggregated_in_g{12}...+ */+BLST_ERROR blst_aggregate_in_g1(POINTonE1 *out, const POINTonE1 *in,+                                                const unsigned char *zwire)+{+    POINTonE1 P[1];+    BLST_ERROR ret;++    ret = POINTonE1_Deserialize_Z((POINTonE1_affine *)P, zwire);++    if (ret != BLST_SUCCESS)+        return ret;++    if (vec_is_zero(P, sizeof(POINTonE1_affine))) {+        if (in == NULL)+            vec_zero(out, sizeof(*out));+        return BLST_SUCCESS;+    }++    vec_copy(P->Z, BLS12_381_Rx.p, sizeof(P->Z));++    if (!POINTonE1_in_G1(P))+        return BLST_POINT_NOT_IN_GROUP;++    if (in == NULL)+        vec_copy(out, P, sizeof(P));+    else+        POINTonE1_dadd_affine(out, in, (POINTonE1_affine *)P);++    return BLST_SUCCESS;+}++BLST_ERROR blst_aggregate_in_g2(POINTonE2 *out, const POINTonE2 *in,+                                                const unsigned char *zwire)+{+    POINTonE2 P[1];+    BLST_ERROR ret;++    ret = POINTonE2_Deserialize_Z((POINTonE2_affine *)P, zwire);++    if (ret != BLST_SUCCESS)+        return ret;++    if (vec_is_zero(P, sizeof(POINTonE2_affine))) {+        if (in == NULL)+            vec_zero(out, sizeof(*out));+        return BLST_SUCCESS;+    }++    vec_copy(P->Z, BLS12_381_Rx.p, sizeof(P->Z));++    if (!POINTonE2_in_G2(P))+        return BLST_POINT_NOT_IN_GROUP;++    if (in == NULL) {+        vec_copy(out, P, sizeof(P));+    } else {+        POINTonE2_dadd_affine(out, in, (POINTonE2_affine *)P);+    }+    return BLST_SUCCESS;+}++void blst_aggregated_in_g1(vec384fp12 ret, const POINTonE1_affine *sig)+{   miller_loop_n(ret, (const POINTonE2_affine *)&BLS12_381_G2, sig, 1);   }++void blst_aggregated_in_g2(vec384fp12 ret, const POINTonE2_affine *sig)+{   miller_loop_n(ret, sig, (const POINTonE1_affine *)&BLS12_381_G1, 1);   }++BLST_ERROR blst_core_verify_pk_in_g1(const POINTonE1_affine *pk,+                                     const POINTonE2_affine *signature,+                                     int hash_or_encode,+                                     const void *msg, size_t msg_len,+                                     const void *DST, size_t DST_len,+                                     const void *aug, size_t aug_len)+{+    PAIRING ctx;+    BLST_ERROR ret;++    ctx.ctrl = AGGR_UNDEFINED | (hash_or_encode ? AGGR_HASH_OR_ENCODE : 0);+    ctx.nelems = 0;+    ctx.DST = DST;+    ctx.DST_len = DST_len;++    ret = PAIRING_Aggregate_PK_in_G1(&ctx, pk, 1, signature, 1, NULL, 0,+                                     msg, msg_len, aug, aug_len);+    if (ret != BLST_SUCCESS)+        return ret;++    PAIRING_Commit(&ctx);++    return PAIRING_FinalVerify(&ctx, NULL) ? BLST_SUCCESS : BLST_VERIFY_FAIL;+}++BLST_ERROR blst_core_verify_pk_in_g2(const POINTonE2_affine *pk,+                                     const POINTonE1_affine *signature,+                                     int hash_or_encode,+                                     const void *msg, size_t msg_len,+                                     const void *DST, size_t DST_len,+                                     const void *aug, size_t aug_len)+{+    PAIRING ctx;+    BLST_ERROR ret;++    ctx.ctrl = AGGR_UNDEFINED | (hash_or_encode ? AGGR_HASH_OR_ENCODE : 0);+    ctx.nelems = 0;+    ctx.DST = DST;+    ctx.DST_len = DST_len;++    ret = PAIRING_Aggregate_PK_in_G2(&ctx, pk, 1, signature, 1, NULL, 0,+                                     msg, msg_len, aug, aug_len);+    if (ret != BLST_SUCCESS)+        return ret;++    PAIRING_Commit(&ctx);++    return PAIRING_FinalVerify(&ctx, NULL) ? BLST_SUCCESS : BLST_VERIFY_FAIL;+}
+ vendor/external/blst/src/bulk_addition.c view
@@ -0,0 +1,176 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "fields.h"+#include "point.h"++/*+ * This implementation uses explicit addition formula:+ *+ * λ = (Y₂-Y₁)/(X₂-X₁)+ * X₃ = λ²-(X₁+X₂)+ * Y₃ = λ⋅(X₁-X₃)-Y₁+ *+ * But since we don't know if we'll have to add point to itself, we need+ * to eventually resort to corresponding doubling formula:+ *+ * λ = 3X₁²/2Y₁+ * X₃ = λ²-2X₁+ * Y₃ = λ⋅(X₁-X₃)-Y₁+ *+ * The formulae use prohibitively expensive inversion, but whenever we+ * have a lot of affine points to accumulate, we can amortize the cost+ * by applying Montgomery's batch inversion approach. As a result,+ * asymptotic[!] per-point cost for addition is as small as 5M+1S. For+ * comparison, ptype##_dadd_affine takes 8M+5S. In practice, all things+ * considered, the improvement coefficient varies from 60% to 85%+ * depending on platform and curve.+ *+ * THIS IMPLEMENTATION IS *NOT* CONSTANT-TIME. [But if there is an+ * application that requires constant time-ness, speak up!]+ */++/*+ * Calculate λ's numerator and denominator.+ *+ * input:	A	x1	y1	-+ *		B	x2	y2	-+ * output:+ * if A!=B:	A	x1	y1	(x2-x1)*mul_acc+ *		B	x2+x1	y2-y1	(x2-x1)+ *+ * if A==B:	A	x	y	2y*mul_acc+ *		B	2x	3*x^2	2y+ *+ * if A==-B:	A	0	0	1*mul_acc+ *		B	0	3*x^2	0+ */+#define HEAD(ptype, bits, field, one) \+static void ptype##_head(ptype AB[2], const vec##bits mul_acc) \+{ \+    ptype *A = AB, *B = AB+1; \+    limb_t inf = vec_is_zero(A, sizeof(ptype##_affine)) | \+                 vec_is_zero(B, sizeof(ptype##_affine));  \+    static const vec##bits zero = { 0 }; \+\+    sub_##field(B->Z, B->X, A->X);		/* X2-X1  */ \+    add_##field(B->X, B->X, A->X);		/* X2+X1  */ \+    add_##field(A->Z, B->Y, A->Y);		/* Y2+Y1  */ \+    sub_##field(B->Y, B->Y, A->Y);		/* Y2-Y1  */ \+    if (vec_is_zero(B->Z, sizeof(B->Z))) {	/* X2==X1 */ \+        inf = vec_is_zero(A->Z, sizeof(A->Z));	\+        vec_select(B->X, A->Z, B->X, sizeof(B->X), inf); \+        sqr_##field(B->Y, A->X);		\+        mul_by_3_##field(B->Y, B->Y);		/* 3*X1^2 */ \+        vec_copy(B->Z, A->Z, sizeof(B->Z));	/* 2*Y1   */ \+    }						/* B->Y is numenator    */ \+						/* B->Z is denominator  */ \+    vec_select(A->X, B->X, A->X, sizeof(A->X), inf); \+    vec_select(A->Y, A->Z, A->Y, sizeof(A->Y), inf); \+    vec_select(A->Z, one,  B->Z, sizeof(A->Z), inf); \+    vec_select(B->Z, zero, B->Z, sizeof(B->Z), inf); \+    if (mul_acc != NULL) \+        mul_##field(A->Z, A->Z, mul_acc);	/* chain multiplication */\+}++/*+ * Calculate λ and resulting coordinates.+ *+ * input:	A		x1			y1		-+ *		B		x2+x1			nominator	-+ * 		lambda		1/denominator+ * output:	D		x3=(nom/den)^2-(x2+x1)	y3=(nom/den)(x1-x3)-y1+ */+#define TAIL(ptype, bits, field, one) \+static void ptype##_tail(ptype *D, ptype AB[2], vec##bits lambda) \+{ \+    ptype *A = AB, *B = AB+1; \+    vec##bits llambda; \+    limb_t inf = vec_is_zero(B->Z, sizeof(B->Z)); \+\+    mul_##field(lambda, lambda, B->Y);		/* λ = (Y2-Y1)/(X2-X1)  */ \+						/* alt. 3*X1^2/2*Y1     */ \+    sqr_##field(llambda, lambda); \+    sub_##field(D->X, llambda, B->X);		/* X3 = λ^2-X1-X2       */ \+\+    sub_##field(D->Y, A->X, D->X);   \+    mul_##field(D->Y, D->Y, lambda); \+    sub_##field(D->Y, D->Y, A->Y);		/* Y3 = λ*(X1-X3)-Y1    */ \+\+    vec_select(D->X, A->X, D->X, 2*sizeof(D->X), inf); \+    vec_select(B->Z, one, B->Z, sizeof(B->Z), inf); \+}++/*+ * |points[]| is volatile buffer with |X|s and |Y|s initially holding+ * input affine coordinates, and with |Z|s being used as additional+ * temporary storage [unrelated to Jacobian coordinates]. |sum| is+ * in-/output, initialize to infinity accordingly.+ */+#define ADDITION_BTREE(prefix, ptype, bits, field, one) \+HEAD(ptype, bits, field, one) \+TAIL(ptype, bits, field, one) \+static void ptype##s_accumulate(ptype *sum, ptype points[], size_t n) \+{ \+    ptype *dst; \+    void *mul_acc; \+    size_t i; \+\+    while (n >= 16) { \+        if (n & 1) \+            ptype##_dadd_affine(sum, sum, (const ptype##_affine *)points++); \+        n /= 2; \+        for (mul_acc = NULL, i = n; i--; mul_acc = points->Z, points += 2) \+            ptype##_head(points, mul_acc); \+\+        reciprocal_##field(points[-2].Z, points[-2].Z); /* 1/∏ Zi */ \+\+        for (dst = points, i = n; --i;) { \+            dst--; points -= 2; \+            mul_##field(points[-2].Z, points[0].Z, points[-2].Z); \+            ptype##_tail(dst, points, points[-2].Z); \+            mul_##field(points[-2].Z, points[0].Z, points[1].Z); \+        } \+        dst--; points -= 2; \+        ptype##_tail(dst, points, points[0].Z); \+        points = dst; \+    } \+    while (n--) \+        ptype##_dadd_affine(sum, sum, (const ptype##_affine *)points++); \+} \+\+void prefix##s_add(ptype *sum, const ptype##_affine *const points[], \+                               size_t npoints) \+{ \+    const size_t stride = SCRATCH_LIMIT / sizeof(ptype); \+    ptype *scratch = alloca((npoints > stride ? stride : npoints) * \+                            sizeof(ptype)); \+    const ptype##_affine *point = NULL; \+\+    vec_zero(sum, sizeof(*sum)); \+    while (npoints) { \+        size_t i, j = npoints > stride ? stride : npoints; \+        for (i=0; i<j; i++) { \+            point = *points ? *points++ : point+1; \+            vec_copy(&scratch[i], point, sizeof(*point)); \+        } \+        ptype##s_accumulate(sum, scratch, j); \+        npoints -= j; \+    } \+}++#ifndef SCRATCH_LIMIT+# ifdef __wasm__+#  define SCRATCH_LIMIT (45 * 1024)+# else+   /* Performance with 144K scratch is within 1-2-3% from optimal */+#  define SCRATCH_LIMIT (144 * 1024)+# endif+#endif++ADDITION_BTREE(blst_p1, POINTonE1, 384, fp, BLS12_381_Rx.p2)++ADDITION_BTREE(blst_p2, POINTonE2, 384x, fp2, BLS12_381_Rx.p2)
+ vendor/external/blst/src/bytes.h view
@@ -0,0 +1,152 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLS12_381_ASM_BYTES_H__+#define __BLS12_381_ASM_BYTES_H__++static inline void bytes_zero(unsigned char *a, size_t num)+{+    size_t i;++    for (i = 0; i < num; i++)+        a[i] = 0;+}++static inline void limbs_from_be_bytes(limb_t *restrict ret,+                                       const unsigned char *in, size_t n)+{+    limb_t limb = 0;++    while(n--) {+        limb <<= 8;+        limb |= *in++;+        /*+         * 'if (n % sizeof(limb_t) == 0)' is omitted because it's cheaper+         * to perform redundant stores than to pay penalty for+         * mispredicted branch. Besides, some compilers unroll the+         * loop and remove redundant stores to 'restrict'-ed storage...+         */+        ret[n / sizeof(limb_t)] = limb;+    }+}++static inline void be_bytes_from_limbs(unsigned char *out, const limb_t *in,+                                       size_t n)+{+    limb_t limb;++    while(n--) {+        limb = in[n / sizeof(limb_t)];+        *out++ = (unsigned char)(limb >> (8 * (n % sizeof(limb_t))));+    }+}++static inline void limbs_from_le_bytes(limb_t *restrict ret,+                                       const unsigned char *in, size_t n)+{+    limb_t limb = 0;++    while(n--) {+        limb <<= 8;+        limb |= in[n];+        /*+         * 'if (n % sizeof(limb_t) == 0)' is omitted because it's cheaper+         * to perform redundant stores than to pay penalty for+         * mispredicted branch. Besides, some compilers unroll the+         * loop and remove redundant stores to 'restrict'-ed storage...+         */+        ret[n / sizeof(limb_t)] = limb;+    }+}++static inline void le_bytes_from_limbs(unsigned char *out, const limb_t *in,+                                       size_t n)+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };+    limb_t limb;+    size_t i, j, r;++    if ((uptr_t)out == (uptr_t)in && is_endian.little)+        return;++    r = n % sizeof(limb_t);+    n /= sizeof(limb_t);++    for(i = 0; i < n; i++) {+        for (limb = in[i], j = 0; j < sizeof(limb_t); j++, limb >>= 8)+            *out++ = (unsigned char)limb;+    }+    if (r) {+        for (limb = in[i], j = 0; j < r; j++, limb >>= 8)+            *out++ = (unsigned char)limb;+    }+}++static inline char hex_from_nibble(unsigned char nibble)+{+    int mask = (9 - (nibble &= 0xf)) >> 31;+    return (char)(nibble + ((('a'-10) & mask) | ('0' & ~mask)));+}++static unsigned char nibble_from_hex(char c)+{+    int mask, ret;++    mask = (('a'-c-1) & (c-1-'f')) >> 31;+    ret  = (10 + c - 'a') & mask;+    mask = (('A'-c-1) & (c-1-'F')) >> 31;+    ret |= (10 + c - 'A') & mask;+    mask = (('0'-c-1) & (c-1-'9')) >> 31;+    ret |= (c - '0') & mask;+    mask = ((ret-1) & ~mask) >> 31;+    ret |= 16 & mask;++    return (unsigned char)ret;+}++static void bytes_from_hexascii(unsigned char *ret, size_t sz, const char *hex)+{+    size_t len;+    unsigned char b = 0;++    if (hex[0]=='0' && (hex[1]=='x' || hex[1]=='X'))+        hex += 2;++    for (len = 0; len<2*sz && nibble_from_hex(hex[len])<16; len++) ;++    bytes_zero(ret, sz);++    while(len--) {+        b <<= 4;+        b |= nibble_from_hex(*hex++);+        if (len % 2 == 0)+            ret[len / 2] = b;+    }+}++static void limbs_from_hexascii(limb_t *ret, size_t sz, const char *hex)+{+    size_t len;+    limb_t limb = 0;++    if (hex[0]=='0' && (hex[1]=='x' || hex[1]=='X'))+        hex += 2;++    for (len = 0; len<2*sz && nibble_from_hex(hex[len])<16; len++) ;++    vec_zero(ret, sz);++    while(len--) {+        limb <<= 4;+        limb |= nibble_from_hex(*hex++);+        if (len % (2*sizeof(limb_t)) == 0)+            ret[len / (2*sizeof(limb_t))] = limb;+    }+}++#endif
+ vendor/external/blst/src/consts.c view
@@ -0,0 +1,36 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "consts.h"++/* z = -0xd201000000010000 */+const vec384 BLS12_381_P = {    /* (z-1)^2 * (z^4 - z^2 + 1)/3 + z */+    TO_LIMB_T(0xb9feffffffffaaab), TO_LIMB_T(0x1eabfffeb153ffff),+    TO_LIMB_T(0x6730d2a0f6b0f624), TO_LIMB_T(0x64774b84f38512bf),+    TO_LIMB_T(0x4b1ba7b6434bacd7), TO_LIMB_T(0x1a0111ea397fe69a)+};+const limb_t BLS12_381_p0 = (limb_t)0x89f3fffcfffcfffd;  /* -1/P */++const radix384 BLS12_381_Rx = { /* (1<<384)%P, "radix", one-in-Montgomery */+  { { ONE_MONT_P },+    { 0 } }+};++const vec384 BLS12_381_RR = {   /* (1<<768)%P, "radix"^2, to-Montgomery */+    TO_LIMB_T(0xf4df1f341c341746), TO_LIMB_T(0x0a76e6a609d104f1),+    TO_LIMB_T(0x8de5476c4c95b6d5), TO_LIMB_T(0x67eb88a9939d83c0),+    TO_LIMB_T(0x9a793e85b519952d), TO_LIMB_T(0x11988fe592cae3aa)+};++const vec256 BLS12_381_r = {    /* z^4 - z^2 + 1, group order */+    TO_LIMB_T(0xffffffff00000001), TO_LIMB_T(0x53bda402fffe5bfe),+    TO_LIMB_T(0x3339d80809a1d805), TO_LIMB_T(0x73eda753299d7d48)+};++const vec256 BLS12_381_rRR = {  /* (1<<512)%r, "radix"^2, to-Montgomery */+    TO_LIMB_T(0xc999e990f3f29c6d), TO_LIMB_T(0x2b6cedcb87925c23),+    TO_LIMB_T(0x05d314967254398f), TO_LIMB_T(0x0748d9d99f59ff11)+};
+ vendor/external/blst/src/consts.h view
@@ -0,0 +1,30 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLS12_381_ASM_CONST_H__+#define __BLS12_381_ASM_CONST_H__+#include "vect.h"++extern const vec384 BLS12_381_P;+extern const limb_t BLS12_381_p0;+static const limb_t p0 = (limb_t)0x89f3fffcfffcfffd;  /* -1/P */+typedef union { vec384 p12[12]; vec384x p2; vec384 p; } radix384;+extern const radix384 BLS12_381_Rx; /* (1<<384)%P, "radix", one-in-Montgomery */+extern const vec384 BLS12_381_RR;   /* (1<<768)%P, "radix"^2, to-Montgomery   */++#define ONE_MONT_P TO_LIMB_T(0x760900000002fffd), \+                   TO_LIMB_T(0xebf4000bc40c0002), \+                   TO_LIMB_T(0x5f48985753c758ba), \+                   TO_LIMB_T(0x77ce585370525745), \+                   TO_LIMB_T(0x5c071a97a256ec6d), \+                   TO_LIMB_T(0x15f65ec3fa80e493)++#define ZERO_384 (BLS12_381_Rx.p2[1])++extern const vec256 BLS12_381_r;    /* order */+static const limb_t r0 = (limb_t)0xfffffffeffffffff;  /* -1/r */+extern const vec256 BLS12_381_rRR;  /* (1<<512)%r, "radix"^2, to-Montgomery   */++#endif
+ vendor/external/blst/src/cpuid.c view
@@ -0,0 +1,114 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#if (defined(__GNUC__) || defined(__clang__) || defined(__SUNPRO_C)) && !defined(_WIN32)+__attribute__((visibility("hidden")))+#endif+int __blst_platform_cap = 0;++#if defined(__x86_64__) || defined(__x86_64) || (defined(_M_X64) && !defined(_M_ARM64EC))++# if defined(__GNUC__) || defined(__clang__) || defined(__SUNPRO_C)+static void __cpuidex(int info[4], int func, int sub)+{+    int eax, ebx, ecx, edx;++    __asm__("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)+                    : "a"(func), "c"(sub));++    info[0] = eax;+    info[1] = ebx;+    info[2] = ecx;+    info[3] = edx;+}+# else+#  include <intrin.h>+# endif++# if defined(__GNUC__) || defined(__clang__)+__attribute__((constructor))+# endif+static int __blst_cpuid(void)+{+    int info[4], cap = 0;++    __cpuidex(info, 0, 0);+    if (info[0] > 6) {+        __cpuidex(info, 7, 0);+        cap |= (info[1]>>19) & 1; /* ADX */+        cap |= (info[1]>>28) & 2; /* SHA */+    }++    __blst_platform_cap = cap;++    return 0;+}++# if defined(_MSC_VER) && !defined(__clang__)+#  pragma section(".CRT$XCU",read)+__declspec(allocate(".CRT$XCU")) static int (*p)(void) = __blst_cpuid;+# elif defined(__SUNPRO_C)+#  pragma init(__blst_cpuid)+# endif++#elif defined(__aarch64__) || defined(__aarch64) || defined(_M_ARM64)++# if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))+extern unsigned long getauxval(unsigned long type) __attribute__ ((weak));++__attribute__((constructor))+static int __blst_cpuid(void)+{+    int cap = 0;++    if (getauxval) {+        unsigned long hwcap_ce = getauxval(16);+        cap = (hwcap_ce>>6) & 1; /* SHA256 */+    }++    __blst_platform_cap = cap;++    return 0;+}+# elif defined(__APPLE__) && (defined(__GNUC__) || defined(__clang__))+__attribute__((constructor))+static int __blst_cpuid()+{+    __blst_platform_cap = 1; /* SHA256 */+    return 0;+}+# elif defined(__FreeBSD__) && __FreeBSD__ >= 12+#  include <sys/auxv.h>+__attribute__((constructor))+static int __blst_cpuid()+{+    unsigned long cap;++    if (elf_aux_info(AT_HWCAP, &cap, sizeof(cap)) == 0)+        __blst_platform_cap = (cap & HWCAP_SHA2) != 0;++    return 0;+}+# elif defined(_WIN64)+int IsProcessorFeaturePresent(int);++#  if defined(__GNUC__) || defined(__clang__)+__attribute__((constructor))+#  endif+static int __blst_cpuid(void)+{+    __blst_platform_cap = IsProcessorFeaturePresent(30); /* AES, SHA1, SHA2 */++    return 0;+}++#  if defined(_MSC_VER) && !defined(__clang__)+#   pragma section(".CRT$XCU",read)+__declspec(allocate(".CRT$XCU")) static int (*p)(void) = __blst_cpuid;+#  endif+# endif++#endif
+ vendor/external/blst/src/e1.c view
@@ -0,0 +1,564 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "point.h"+#include "fields.h"+#include "errors.h"++/*+ * y^2 = x^3 + B+ */+static const vec384 B_E1 = {        /* (4 << 384) % P */+    TO_LIMB_T(0xaa270000000cfff3), TO_LIMB_T(0x53cc0032fc34000a),+    TO_LIMB_T(0x478fe97a6b0a807f), TO_LIMB_T(0xb1d37ebee6ba24d7),+    TO_LIMB_T(0x8ec9733bbf78ab2f), TO_LIMB_T(0x09d645513d83de7e)+};++const POINTonE1 BLS12_381_G1 = {    /* generator point [in Montgomery] */+  /* (0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905+   *    a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb << 384) % P */+  { TO_LIMB_T(0x5cb38790fd530c16), TO_LIMB_T(0x7817fc679976fff5),+    TO_LIMB_T(0x154f95c7143ba1c1), TO_LIMB_T(0xf0ae6acdf3d0e747),+    TO_LIMB_T(0xedce6ecc21dbf440), TO_LIMB_T(0x120177419e0bfb75) },+  /* (0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af6+   *    00db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1 << 384) % P */+  { TO_LIMB_T(0xbaac93d50ce72271), TO_LIMB_T(0x8c22631a7918fd8e),+    TO_LIMB_T(0xdd595f13570725ce), TO_LIMB_T(0x51ac582950405194),+    TO_LIMB_T(0x0e1c8c3fad0059c0), TO_LIMB_T(0x0bbc3efc5008a26a) },+  { ONE_MONT_P }+};++const POINTonE1 BLS12_381_NEG_G1 = { /* negative generator [in Montgomery] */+  /* (0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905+   *    a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb << 384) % P */+  { TO_LIMB_T(0x5cb38790fd530c16), TO_LIMB_T(0x7817fc679976fff5),+    TO_LIMB_T(0x154f95c7143ba1c1), TO_LIMB_T(0xf0ae6acdf3d0e747),+    TO_LIMB_T(0xedce6ecc21dbf440), TO_LIMB_T(0x120177419e0bfb75) },+  /* (0x114d1d6855d545a8aa7d76c8cf2e21f267816aef1db507c9+   *    6655b9d5caac42364e6f38ba0ecb751bad54dcd6b939c2ca << 384) % P */+  { TO_LIMB_T(0xff526c2af318883a), TO_LIMB_T(0x92899ce4383b0270),+    TO_LIMB_T(0x89d7738d9fa9d055), TO_LIMB_T(0x12caf35ba344c12a),+    TO_LIMB_T(0x3cff1b76964b5317), TO_LIMB_T(0x0e44d2ede9774430) },+  { ONE_MONT_P }+};++static inline void mul_by_b_onE1(vec384 out, const vec384 in)+{   lshift_fp(out, in, 2);   }++static inline void mul_by_4b_onE1(vec384 out, const vec384 in)+{   lshift_fp(out, in, 4);   }++static void POINTonE1_cneg(POINTonE1 *p, bool_t cbit)+{   cneg_fp(p->Y, p->Y, cbit);   }++void blst_p1_cneg(POINTonE1 *a, int cbit)+{   POINTonE1_cneg(a, is_zero(cbit) ^ 1);   }++static void POINTonE1_from_Jacobian(POINTonE1 *out, const POINTonE1 *in)+{+    vec384 Z, ZZ;+    limb_t inf = vec_is_zero(in->Z, sizeof(in->Z));++    reciprocal_fp(Z, in->Z);                            /* 1/Z   */++    sqr_fp(ZZ, Z);+    mul_fp(out->X, in->X, ZZ);                          /* X = X/Z^2 */++    mul_fp(ZZ, ZZ, Z);+    mul_fp(out->Y, in->Y, ZZ);                          /* Y = Y/Z^3 */++    vec_select(out->Z, in->Z, BLS12_381_G1.Z,+                       sizeof(BLS12_381_G1.Z), inf);    /* Z = inf ? 0 : 1 */+}++void blst_p1_from_jacobian(POINTonE1 *out, const POINTonE1 *a)+{   POINTonE1_from_Jacobian(out, a);   }++static void POINTonE1_to_affine(POINTonE1_affine *out, const POINTonE1 *in)+{+    POINTonE1 p;++    if (!vec_is_equal(in->Z, BLS12_381_Rx.p, sizeof(in->Z))) {+        POINTonE1_from_Jacobian(&p, in);+        in = &p;+    }+    vec_copy(out, in, sizeof(*out));+}++void blst_p1_to_affine(POINTonE1_affine *out, const POINTonE1 *a)+{   POINTonE1_to_affine(out, a);   }++void blst_p1_from_affine(POINTonE1 *out, const POINTonE1_affine *a)+{+    vec_copy(out, a, sizeof(*a));+    vec_select(out->Z, a->X, BLS12_381_Rx.p, sizeof(out->Z),+                       vec_is_zero(a, sizeof(*a)));+}++static bool_t POINTonE1_affine_on_curve(const POINTonE1_affine *p)+{+    vec384 XXX, YY;++    sqr_fp(XXX, p->X);+    mul_fp(XXX, XXX, p->X);                             /* X^3 */+    add_fp(XXX, XXX, B_E1);                             /* X^3 + B */++    sqr_fp(YY, p->Y);                                   /* Y^2 */++    return vec_is_equal(XXX, YY, sizeof(XXX));+}++int blst_p1_affine_on_curve(const POINTonE1_affine *p)+{   return (int)(POINTonE1_affine_on_curve(p) | vec_is_zero(p, sizeof(*p)));   }++static bool_t POINTonE1_on_curve(const POINTonE1 *p)+{+    vec384 XXX, YY, BZ6;+    limb_t inf = vec_is_zero(p->Z, sizeof(p->Z));++    sqr_fp(BZ6, p->Z);+    mul_fp(BZ6, BZ6, p->Z);+    sqr_fp(BZ6, BZ6);                                   /* Z^6 */+    mul_by_b_onE1(BZ6, BZ6);                            /* B*Z^6 */++    sqr_fp(XXX, p->X);+    mul_fp(XXX, XXX, p->X);                             /* X^3 */+    add_fp(XXX, XXX, BZ6);                              /* X^3 + B*Z^6 */++    sqr_fp(YY, p->Y);                                   /* Y^2 */++    return vec_is_equal(XXX, YY, sizeof(XXX)) | inf;+}++int blst_p1_on_curve(const POINTonE1 *p)+{   return (int)POINTonE1_on_curve(p);   }++static limb_t POINTonE1_affine_Serialize_BE(unsigned char out[96],+                                            const POINTonE1_affine *in)+{+    vec384 temp;++    from_fp(temp, in->X);+    be_bytes_from_limbs(out, temp, sizeof(temp));++    from_fp(temp, in->Y);+    be_bytes_from_limbs(out + 48, temp, sizeof(temp));++    return sgn0_pty_mod_384(temp, BLS12_381_P);+}++void blst_p1_affine_serialize(unsigned char out[96],+                              const POINTonE1_affine *in)+{+    if (vec_is_zero(in->X, 2*sizeof(in->X))) {+        bytes_zero(out, 96);+        out[0] = 0x40;    /* infinity bit */+    } else {+        (void)POINTonE1_affine_Serialize_BE(out, in);+    }+}++static limb_t POINTonE1_Serialize_BE(unsigned char out[96],+                                     const POINTonE1 *in)+{+    POINTonE1 p;++    if (!vec_is_equal(in->Z, BLS12_381_Rx.p, sizeof(in->Z))) {+        POINTonE1_from_Jacobian(&p, in);+        in = &p;+    }++    return POINTonE1_affine_Serialize_BE(out, (const POINTonE1_affine *)in);+}++static void POINTonE1_Serialize(unsigned char out[96], const POINTonE1 *in)+{+    if (vec_is_zero(in->Z, sizeof(in->Z))) {+        bytes_zero(out, 96);+        out[0] = 0x40;    /* infinity bit */+    } else {+        (void)POINTonE1_Serialize_BE(out, in);+    }+}++void blst_p1_serialize(unsigned char out[96], const POINTonE1 *in)+{   POINTonE1_Serialize(out, in);   }++static limb_t POINTonE1_affine_Compress_BE(unsigned char out[48],+                                           const POINTonE1_affine *in)+{+    vec384 temp;++    from_fp(temp, in->X);+    be_bytes_from_limbs(out, temp, sizeof(temp));++    return sgn0_pty_mont_384(in->Y, BLS12_381_P, p0);+}++void blst_p1_affine_compress(unsigned char out[48], const POINTonE1_affine *in)+{+    if (vec_is_zero(in->X, 2*sizeof(in->X))) {+        bytes_zero(out, 48);+        out[0] = 0xc0;    /* compressed and infinity bits */+    } else {+        limb_t sign = POINTonE1_affine_Compress_BE(out, in);+        out[0] |= (unsigned char)(0x80 | ((sign & 2) << 4));+    }+}++static limb_t POINTonE1_Compress_BE(unsigned char out[48],+                                    const POINTonE1 *in)+{+    POINTonE1 p;++    if (!vec_is_equal(in->Z, BLS12_381_Rx.p, sizeof(in->Z))) {+        POINTonE1_from_Jacobian(&p, in);+        in = &p;+    }++    return POINTonE1_affine_Compress_BE(out, (const POINTonE1_affine *)in);+}++void blst_p1_compress(unsigned char out[48], const POINTonE1 *in)+{+    if (vec_is_zero(in->Z, sizeof(in->Z))) {+        bytes_zero(out, 48);+        out[0] = 0xc0;    /* compressed and infinity bits */+    } else {+        limb_t sign = POINTonE1_Compress_BE(out, in);+        out[0] |= (unsigned char)(0x80 | ((sign & 2) << 4));+    }+}++static limb_t POINTonE1_Uncompress_BE(POINTonE1_affine *out,+                                      const unsigned char in[48])+{+    POINTonE1_affine ret;+    vec384 temp;++    limbs_from_be_bytes(ret.X, in, sizeof(ret.X));+    /* clear top 3 bits in case caller was conveying some information there */+    ret.X[sizeof(ret.X)/sizeof(limb_t)-1] &= ((limb_t)0-1) >> 3;+    add_fp(temp, ret.X, ZERO_384);  /* less than modulus? */+    if (!vec_is_equal(temp, ret.X, sizeof(temp)))+        return (limb_t)0 - BLST_BAD_ENCODING;+    mul_fp(ret.X, ret.X, BLS12_381_RR);++    sqr_fp(ret.Y, ret.X);+    mul_fp(ret.Y, ret.Y, ret.X);+    add_fp(ret.Y, ret.Y, B_E1);                         /* X^3 + B */+    if (!sqrt_fp(ret.Y, ret.Y))+        return (limb_t)0 - BLST_POINT_NOT_ON_CURVE;++    vec_copy(out, &ret, sizeof(ret));++    return sgn0_pty_mont_384(out->Y, BLS12_381_P, p0);+}++static BLST_ERROR POINTonE1_Uncompress_Z(POINTonE1_affine *out,+                                         const unsigned char in[48])+{+    unsigned char in0 = in[0];+    limb_t sgn0_pty;++    if ((in0 & 0x80) == 0)      /* compressed bit */+        return BLST_BAD_ENCODING;++    if (in0 & 0x40) {           /* infinity bit */+        if (byte_is_zero(in0 & 0x3f) & bytes_are_zero(in+1, 47)) {+            vec_zero(out, sizeof(*out));+            return BLST_SUCCESS;+        } else {+            return BLST_BAD_ENCODING;+        }+    }++    sgn0_pty = POINTonE1_Uncompress_BE(out, in);++    if (sgn0_pty > 3)+        return (BLST_ERROR)(0 - sgn0_pty); /* POINT_NOT_ON_CURVE */++    sgn0_pty >>= 1; /* skip over parity bit */+    sgn0_pty ^= (in0 & 0x20) >> 5;+    cneg_fp(out->Y, out->Y, sgn0_pty);++    /* (0,±2) is not in group, but application might want to ignore? */+    return vec_is_zero(out->X, sizeof(out->X)) ? BLST_POINT_NOT_IN_GROUP+                                               : BLST_SUCCESS;+}++BLST_ERROR blst_p1_uncompress(POINTonE1_affine *out, const unsigned char in[48])+{   return POINTonE1_Uncompress_Z(out, in);   }++static BLST_ERROR POINTonE1_Deserialize_BE(POINTonE1_affine *out,+                                           const unsigned char in[96])+{+    POINTonE1_affine ret;+    vec384 temp;++    limbs_from_be_bytes(ret.X, in, sizeof(ret.X));+    limbs_from_be_bytes(ret.Y, in + 48, sizeof(ret.Y));++    /* clear top 3 bits in case caller was conveying some information there */+    ret.X[sizeof(ret.X)/sizeof(limb_t)-1] &= ((limb_t)0-1) >> 3;+    add_fp(temp, ret.X, ZERO_384);  /* less than modulus? */+    if (!vec_is_equal(temp, ret.X, sizeof(temp)))+        return BLST_BAD_ENCODING;++    add_fp(temp, ret.Y, ZERO_384);  /* less than modulus? */+    if (!vec_is_equal(temp, ret.Y, sizeof(temp)))+        return BLST_BAD_ENCODING;++    mul_fp(ret.X, ret.X, BLS12_381_RR);+    mul_fp(ret.Y, ret.Y, BLS12_381_RR);++    if (!POINTonE1_affine_on_curve(&ret))+        return BLST_POINT_NOT_ON_CURVE;++    vec_copy(out, &ret, sizeof(ret));++    /* (0,±2) is not in group, but application might want to ignore? */+    return vec_is_zero(out->X, sizeof(out->X)) ? BLST_POINT_NOT_IN_GROUP+                                               : BLST_SUCCESS;+}++static BLST_ERROR POINTonE1_Deserialize_Z(POINTonE1_affine *out,+                                          const unsigned char in[96])+{+    unsigned char in0 = in[0];++    if ((in0 & 0xe0) == 0)+        return POINTonE1_Deserialize_BE(out, in);++    if (in0 & 0x80)             /* compressed bit */+        return POINTonE1_Uncompress_Z(out, in);++    if (in0 & 0x40) {           /* infinity bit */+        if (byte_is_zero(in0 & 0x3f) & bytes_are_zero(in+1, 95)) {+            vec_zero(out, sizeof(*out));+            return BLST_SUCCESS;+        }+    }++    return BLST_BAD_ENCODING;+}++BLST_ERROR blst_p1_deserialize(POINTonE1_affine *out,+                               const unsigned char in[96])+{   return POINTonE1_Deserialize_Z(out, in);   }++#include "ec_ops.h"+POINT_DADD_IMPL(POINTonE1, 384, fp)+POINT_DADD_AFFINE_IMPL_A0(POINTonE1, 384, fp, BLS12_381_Rx.p)+POINT_ADD_IMPL(POINTonE1, 384, fp)+POINT_ADD_AFFINE_IMPL(POINTonE1, 384, fp, BLS12_381_Rx.p)+POINT_DOUBLE_IMPL_A0(POINTonE1, 384, fp)+POINT_IS_EQUAL_IMPL(POINTonE1, 384, fp)++void blst_p1_add(POINTonE1 *out, const POINTonE1 *a, const POINTonE1 *b)+{   POINTonE1_add(out, a, b);   }++void blst_p1_add_or_double(POINTonE1 *out, const POINTonE1 *a,+                                           const POINTonE1 *b)+{   POINTonE1_dadd(out, a, b, NULL);   }++void blst_p1_add_affine(POINTonE1 *out, const POINTonE1 *a,+                                        const POINTonE1_affine *b)+{   POINTonE1_add_affine(out, a, b);   }++void blst_p1_add_or_double_affine(POINTonE1 *out, const POINTonE1 *a,+                                                  const POINTonE1_affine *b)+{   POINTonE1_dadd_affine(out, a, b);   }++void blst_p1_double(POINTonE1 *out, const POINTonE1 *a)+{   POINTonE1_double(out, a);   }++int blst_p1_is_equal(const POINTonE1 *a, const POINTonE1 *b)+{   return (int)POINTonE1_is_equal(a, b);   }++#include "ec_mult.h"+POINT_MULT_SCALAR_WX_IMPL(POINTonE1, 4)+POINT_MULT_SCALAR_WX_IMPL(POINTonE1, 5)++#ifdef __BLST_PRIVATE_TESTMODE__+POINT_AFFINE_MULT_SCALAR_IMPL(POINTonE1)++DECLARE_PRIVATE_POINTXZ(POINTonE1, 384)+POINT_LADDER_PRE_IMPL(POINTonE1, 384, fp)+POINT_LADDER_STEP_IMPL_A0(POINTonE1, 384, fp, onE1)+POINT_LADDER_POST_IMPL_A0(POINTonE1, 384, fp, onE1)+POINT_MULT_SCALAR_LADDER_IMPL(POINTonE1)+#endif++static const vec384 beta = {            /* such that beta^3 - 1 = 0  */+    /* -1/2 * (1 + sqrt(-3)) = ((P-2)^(P-2)) * (1 + (P-3)^((P+1)/4)) */+    /* (0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4+          897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac << 384) % P */+    TO_LIMB_T(0xcd03c9e48671f071), TO_LIMB_T(0x5dab22461fcda5d2),+    TO_LIMB_T(0x587042afd3851b95), TO_LIMB_T(0x8eb60ebe01bacb9e),+    TO_LIMB_T(0x03f97d6e83d050d2), TO_LIMB_T(0x18f0206554638741)+};++static void sigma(POINTonE1 *out, const POINTonE1 *in)+{+    vec_copy(out->X, in->X, 2*sizeof(out->X));+    mul_fp(out->Z, in->Z, beta);+}++/* Gallant-Lambert-Vanstone, ~45% faster than POINTonE1_mult_w5 */+static void POINTonE1_mult_glv(POINTonE1 *out, const POINTonE1 *in,+                               const pow256 SK)+{+    union { vec256 l; pow256 s; } val;++    /* SK/z^2 [in constant time] */++    limbs_from_le_bytes(val.l, SK, 32);+    div_by_zz(val.l);+    le_bytes_from_limbs(val.s, val.l, 32);++    {+        const byte *scalars[2] = { val.s+16, val.s };+        POINTonE1 table[2][1<<(5-1)];   /* 4.5KB */+        size_t i;++        POINTonE1_precompute_w5(table[0], in);+        for (i = 0; i < 1<<(5-1); i++) {+            mul_fp(table[1][i].X, table[0][i].X, beta);+            cneg_fp(table[1][i].Y, table[0][i].Y, 1);+            vec_copy(table[1][i].Z, table[0][i].Z, sizeof(table[1][i].Z));+        }++        POINTonE1s_mult_w5(out, NULL, 2, scalars, 128, table);+        POINTonE1_cneg(out, 1);+        mul_fp(out->Z, out->Z, beta);+        mul_fp(out->Z, out->Z, beta);+    }++    vec_zero(val.l, sizeof(val));   /* scrub the copy of SK */+}++static void POINTonE1_sign(POINTonE1 *out, const POINTonE1 *in, const pow256 SK)+{+    vec384 Z, ZZ;+    limb_t inf;++    POINTonE1_mult_glv(out, in, SK);++    /* convert to affine to remove possible bias in out->Z */+    inf = vec_is_zero(out->Z, sizeof(out->Z));+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION+    flt_reciprocal_fp(Z, out->Z);                       /* 1/Z   */+#else+    reciprocal_fp(Z, out->Z);                           /* 1/Z   */+#endif++    sqr_fp(ZZ, Z);+    mul_fp(out->X, out->X, ZZ);                         /* X = X/Z^2 */++    mul_fp(ZZ, ZZ, Z);+    mul_fp(out->Y, out->Y, ZZ);                         /* Y = Y/Z^3 */++    vec_select(out->Z, out->Z, BLS12_381_G1.Z, sizeof(BLS12_381_G1.Z),+                       inf);                            /* Z = inf ? 0 : 1 */+}++void blst_sk_to_pk_in_g1(POINTonE1 *out, const pow256 SK)+{   POINTonE1_sign(out, &BLS12_381_G1, SK);   }++void blst_sign_pk_in_g2(POINTonE1 *out, const POINTonE1 *msg, const pow256 SK)+{   POINTonE1_sign(out, msg, SK);   }++void blst_sk_to_pk2_in_g1(unsigned char out[96], POINTonE1_affine *PK,+                          const pow256 SK)+{+    POINTonE1 P[1];++    POINTonE1_sign(P, &BLS12_381_G1, SK);+    if (PK != NULL)+        vec_copy(PK, P, sizeof(*PK));+    if (out != NULL) {+        limb_t sgn0_pty = POINTonE1_Serialize_BE(out, P);+        out[0] |= (sgn0_pty & 2) << 4;      /* pre-decorate */+        out[0] |= vec_is_zero(P->Z, sizeof(P->Z)) << 6;+    }+}++void blst_sign_pk2_in_g2(unsigned char out[96], POINTonE1_affine *sig,+                         const POINTonE1 *hash, const pow256 SK)+{+    POINTonE1 P[1];++    POINTonE1_sign(P, hash, SK);+    if (sig != NULL)+        vec_copy(sig, P, sizeof(*sig));+    if (out != NULL) {+        limb_t sgn0_pty = POINTonE1_Serialize_BE(out, P);+        out[0] |= (sgn0_pty & 2) << 4;      /* pre-decorate */+        out[0] |= vec_is_zero(P->Z, sizeof(P->Z)) << 6;+    }+}++void blst_p1_mult(POINTonE1 *out, const POINTonE1 *a,+                                  const byte *scalar, size_t nbits)+{+    if (nbits < 176) {+        if (nbits)+            POINTonE1_mult_w4(out, a, scalar, nbits);+        else+            vec_zero(out, sizeof(*out));+    } else if (nbits <= 256) {+        union { vec256 l; pow256 s; } val;+        size_t i, j, top, mask = (size_t)0 - 1;++        /* this is not about constant-time-ness, but branch optimization */+        for (top = (nbits + 7)/8, i=0, j=0; i<sizeof(val.s);) {+            val.s[i++] = scalar[j] & mask;+            mask = 0 - ((i - top) >> (8*sizeof(top)-1));+            j += 1 & mask;+        }++        if (check_mod_256(val.s, BLS12_381_r))  /* z^4 is the formal limit */+            POINTonE1_mult_glv(out, a, val.s);+        else    /* should never be the case, added for formal completeness */+            POINTonE1_mult_w5(out, a, scalar, nbits);++        vec_zero(val.l, sizeof(val));+    } else {    /* should never be the case, added for formal completeness */+        POINTonE1_mult_w5(out, a, scalar, nbits);+    }+}++void blst_p1_unchecked_mult(POINTonE1 *out, const POINTonE1 *a,+                                            const byte *scalar, size_t nbits)+{+    if (nbits)+        POINTonE1_mult_w4(out, a, scalar, nbits);+    else+        vec_zero(out, sizeof(*out));+}++int blst_p1_affine_is_equal(const POINTonE1_affine *a,+                            const POINTonE1_affine *b)+{   return (int)vec_is_equal(a, b, sizeof(*a));   }++int blst_p1_is_inf(const POINTonE1 *p)+{   return (int)vec_is_zero(p->Z, sizeof(p->Z));   }++const POINTonE1 *blst_p1_generator(void)+{   return &BLS12_381_G1;   }++int blst_p1_affine_is_inf(const POINTonE1_affine *p)+{   return (int)vec_is_zero(p, sizeof(*p));   }++const POINTonE1_affine *blst_p1_affine_generator(void)+{   return (const POINTonE1_affine *)&BLS12_381_G1;   }++size_t blst_p1_sizeof(void)+{   return sizeof(POINTonE1);   }++size_t blst_p1_affine_sizeof(void)+{   return sizeof(POINTonE1_affine);   }
+ vendor/external/blst/src/e2.c view
@@ -0,0 +1,638 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "point.h"+#include "fields.h"+#include "errors.h"++/*+ * y^2 = x^3 + B+ */+static const vec384x B_E2 = {       /* 4 + 4*i */+  { TO_LIMB_T(0xaa270000000cfff3), TO_LIMB_T(0x53cc0032fc34000a),+    TO_LIMB_T(0x478fe97a6b0a807f), TO_LIMB_T(0xb1d37ebee6ba24d7),+    TO_LIMB_T(0x8ec9733bbf78ab2f), TO_LIMB_T(0x09d645513d83de7e) },+  { TO_LIMB_T(0xaa270000000cfff3), TO_LIMB_T(0x53cc0032fc34000a),+    TO_LIMB_T(0x478fe97a6b0a807f), TO_LIMB_T(0xb1d37ebee6ba24d7),+    TO_LIMB_T(0x8ec9733bbf78ab2f), TO_LIMB_T(0x09d645513d83de7e) }+};++const POINTonE2 BLS12_381_G2 = {    /* generator point [in Montgomery] */+{ /* (0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02+        b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8 << 384) % P */+  { TO_LIMB_T(0xf5f28fa202940a10), TO_LIMB_T(0xb3f5fb2687b4961a),+    TO_LIMB_T(0xa1a893b53e2ae580), TO_LIMB_T(0x9894999d1a3caee9),+    TO_LIMB_T(0x6f67b7631863366b), TO_LIMB_T(0x058191924350bcd7) },+  /* (0x13e02b6052719f607dacd3a088274f65596bd0d09920b61a+        b5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e << 384) % P */+  { TO_LIMB_T(0xa5a9c0759e23f606), TO_LIMB_T(0xaaa0c59dbccd60c3),+    TO_LIMB_T(0x3bb17e18e2867806), TO_LIMB_T(0x1b1ab6cc8541b367),+    TO_LIMB_T(0xc2b6ed0ef2158547), TO_LIMB_T(0x11922a097360edf3) }+},+{ /* (0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a7+        6d429a695160d12c923ac9cc3baca289e193548608b82801 << 384) % P */+  { TO_LIMB_T(0x4c730af860494c4a), TO_LIMB_T(0x597cfa1f5e369c5a),+    TO_LIMB_T(0xe7e6856caa0a635a), TO_LIMB_T(0xbbefb5e96e0d495f),+    TO_LIMB_T(0x07d3a975f0ef25a2), TO_LIMB_T(0x0083fd8e7e80dae5) },+  /* (0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af+        267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be << 384) % P */+  { TO_LIMB_T(0xadc0fc92df64b05d), TO_LIMB_T(0x18aa270a2b1461dc),+    TO_LIMB_T(0x86adac6a3be4eba0), TO_LIMB_T(0x79495c4ec93da33a),+    TO_LIMB_T(0xe7175850a43ccaed), TO_LIMB_T(0x0b2bc2a163de1bf2) },+},+{ { ONE_MONT_P }, { 0 } }+};++const POINTonE2 BLS12_381_NEG_G2 = { /* negative generator [in Montgomery] */+{ /* (0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02+        b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8 << 384) % P */+  { TO_LIMB_T(0xf5f28fa202940a10), TO_LIMB_T(0xb3f5fb2687b4961a),+    TO_LIMB_T(0xa1a893b53e2ae580), TO_LIMB_T(0x9894999d1a3caee9),+    TO_LIMB_T(0x6f67b7631863366b), TO_LIMB_T(0x058191924350bcd7) },+  /* (0x13e02b6052719f607dacd3a088274f65596bd0d09920b61a+        b5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e << 384) % P */+  { TO_LIMB_T(0xa5a9c0759e23f606), TO_LIMB_T(0xaaa0c59dbccd60c3),+    TO_LIMB_T(0x3bb17e18e2867806), TO_LIMB_T(0x1b1ab6cc8541b367),+    TO_LIMB_T(0xc2b6ed0ef2158547), TO_LIMB_T(0x11922a097360edf3) }+},+{ /* (0x0d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17+        f9ee3837a55024f78c71363275a75d75d86bab79f74782aa << 384) % P */+  { TO_LIMB_T(0x6d8bf5079fb65e61), TO_LIMB_T(0xc52f05df531d63a5),+    TO_LIMB_T(0x7f4a4d344ca692c9), TO_LIMB_T(0xa887959b8577c95f),+    TO_LIMB_T(0x4347fe40525c8734), TO_LIMB_T(0x197d145bbaff0bb5) },+  /* (0x13fa4d4a0ad8b1ce186ed5061789213d993923066dddaf10+        40bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed << 384) % P */+  { TO_LIMB_T(0x0c3e036d209afa4e), TO_LIMB_T(0x0601d8f4863f9e23),+    TO_LIMB_T(0xe0832636bacc0a84), TO_LIMB_T(0xeb2def362a476f84),+    TO_LIMB_T(0x64044f659f0ee1e9), TO_LIMB_T(0x0ed54f48d5a1caa7) }+},+{ { ONE_MONT_P }, { 0 } }+};++static void mul_by_b_onE2(vec384x out, const vec384x in)+{+    sub_fp(out[0], in[0], in[1]);+    add_fp(out[1], in[0], in[1]);+    lshift_fp(out[0], out[0], 2);+    lshift_fp(out[1], out[1], 2);+}++static void mul_by_4b_onE2(vec384x out, const vec384x in)+{+    sub_fp(out[0], in[0], in[1]);+    add_fp(out[1], in[0], in[1]);+    lshift_fp(out[0], out[0], 4);+    lshift_fp(out[1], out[1], 4);+}++static void POINTonE2_cneg(POINTonE2 *p, bool_t cbit)+{   cneg_fp2(p->Y, p->Y, cbit);   }++void blst_p2_cneg(POINTonE2 *a, int cbit)+{   POINTonE2_cneg(a, is_zero(cbit) ^ 1);   }++static void POINTonE2_from_Jacobian(POINTonE2 *out, const POINTonE2 *in)+{+    vec384x Z, ZZ;+    limb_t inf = vec_is_zero(in->Z, sizeof(in->Z));++    reciprocal_fp2(Z, in->Z);                           /* 1/Z */++    sqr_fp2(ZZ, Z);+    mul_fp2(out->X, in->X, ZZ);                         /* X = X/Z^2 */++    mul_fp2(ZZ, ZZ, Z);+    mul_fp2(out->Y, in->Y, ZZ);                         /* Y = Y/Z^3 */++    vec_select(out->Z, in->Z, BLS12_381_G2.Z,+                       sizeof(BLS12_381_G2.Z), inf);    /* Z = inf ? 0 : 1 */+}++void blst_p2_from_jacobian(POINTonE2 *out, const POINTonE2 *a)+{   POINTonE2_from_Jacobian(out, a);   }++static void POINTonE2_to_affine(POINTonE2_affine *out, const POINTonE2 *in)+{+    POINTonE2 p;++    if (!vec_is_equal(in->Z, BLS12_381_Rx.p2, sizeof(in->Z))) {+        POINTonE2_from_Jacobian(&p, in);+        in = &p;+    }+    vec_copy(out, in, sizeof(*out));+}++void blst_p2_to_affine(POINTonE2_affine *out, const POINTonE2 *a)+{   POINTonE2_to_affine(out, a);   }++void blst_p2_from_affine(POINTonE2 *out, const POINTonE2_affine *a)+{+    vec_copy(out, a, sizeof(*a));+    vec_select(out->Z, a->X, BLS12_381_Rx.p2, sizeof(out->Z),+                       vec_is_zero(a, sizeof(*a)));+}++static bool_t POINTonE2_affine_on_curve(const POINTonE2_affine *p)+{+    vec384x XXX, YY;++    sqr_fp2(XXX, p->X);+    mul_fp2(XXX, XXX, p->X);                            /* X^3 */+    add_fp2(XXX, XXX, B_E2);                            /* X^3 + B */++    sqr_fp2(YY, p->Y);                                  /* Y^2 */++    return vec_is_equal(XXX, YY, sizeof(XXX));+}++int blst_p2_affine_on_curve(const POINTonE2_affine *p)+{   return (int)(POINTonE2_affine_on_curve(p) | vec_is_zero(p, sizeof(*p)));   }++static bool_t POINTonE2_on_curve(const POINTonE2 *p)+{+    vec384x XXX, YY, BZ6;+    limb_t inf = vec_is_zero(p->Z, sizeof(p->Z));++    sqr_fp2(BZ6, p->Z);+    mul_fp2(BZ6, BZ6, p->Z);+    sqr_fp2(XXX, BZ6);                                  /* Z^6 */+    mul_by_b_onE2(BZ6, XXX);                            /* B*Z^6 */++    sqr_fp2(XXX, p->X);+    mul_fp2(XXX, XXX, p->X);                            /* X^3 */+    add_fp2(XXX, XXX, BZ6);                             /* X^3 + B*Z^6 */++    sqr_fp2(YY, p->Y);                                  /* Y^2 */++    return vec_is_equal(XXX, YY, sizeof(XXX)) | inf;+}++int blst_p2_on_curve(const POINTonE2 *p)+{   return (int)POINTonE2_on_curve(p);   }++static limb_t POINTonE2_affine_Serialize_BE(unsigned char out[192],+                                            const POINTonE2_affine *in)+{+    vec384x temp;++    from_fp(temp[1], in->X[1]);+    be_bytes_from_limbs(out, temp[1], sizeof(temp[1]));+    from_fp(temp[0], in->X[0]);+    be_bytes_from_limbs(out + 48, temp[0], sizeof(temp[0]));++    from_fp(temp[1], in->Y[1]);+    be_bytes_from_limbs(out + 96, temp[1], sizeof(temp[1]));+    from_fp(temp[0], in->Y[0]);+    be_bytes_from_limbs(out + 144, temp[0], sizeof(temp[0]));++    return sgn0_pty_mod_384x(temp, BLS12_381_P);+}++void blst_p2_affine_serialize(unsigned char out[192],+                              const POINTonE2_affine *in)+{+    if (vec_is_zero(in->X, 2*sizeof(in->X))) {+        bytes_zero(out, 192);+        out[0] = 0x40;    /* infinity bit */+    } else {+        (void)POINTonE2_affine_Serialize_BE(out, in);+    }+}++static limb_t POINTonE2_Serialize_BE(unsigned char out[192],+                                     const POINTonE2 *in)+{+    POINTonE2 p;++    if (!vec_is_equal(in->Z, BLS12_381_Rx.p2, sizeof(in->Z))) {+        POINTonE2_from_Jacobian(&p, in);+        in = &p;+    }++    return POINTonE2_affine_Serialize_BE(out, (const POINTonE2_affine *)in);+}++static void POINTonE2_Serialize(unsigned char out[192], const POINTonE2 *in)+{+    if (vec_is_zero(in->Z, sizeof(in->Z))) {+        bytes_zero(out, 192);+        out[0] = 0x40;    /* infinity bit */+    } else {+        (void)POINTonE2_Serialize_BE(out, in);+    }+}++void blst_p2_serialize(unsigned char out[192], const POINTonE2 *in)+{   POINTonE2_Serialize(out, in);   }++static limb_t POINTonE2_affine_Compress_BE(unsigned char out[96],+                                           const POINTonE2_affine *in)+{+    vec384 temp;++    from_fp(temp, in->X[1]);+    be_bytes_from_limbs(out, temp, sizeof(temp));+    from_fp(temp, in->X[0]);+    be_bytes_from_limbs(out + 48, temp, sizeof(temp));++    return sgn0_pty_mont_384x(in->Y, BLS12_381_P, p0);+}++void blst_p2_affine_compress(unsigned char out[96], const POINTonE2_affine *in)+{+    if (vec_is_zero(in->X, 2*sizeof(in->X))) {+        bytes_zero(out, 96);+        out[0] = 0xc0;    /* compressed and infinity bits */+    } else {+        limb_t sign = POINTonE2_affine_Compress_BE(out, in);+        out[0] |= (unsigned char)(0x80 | ((sign & 2) << 4));+    }+}++static limb_t POINTonE2_Compress_BE(unsigned char out[96],+                                    const POINTonE2 *in)+{+    POINTonE2 p;++    if (!vec_is_equal(in->Z, BLS12_381_Rx.p, sizeof(in->Z))) {+        POINTonE2_from_Jacobian(&p, in);+        in = &p;+    }++    return POINTonE2_affine_Compress_BE(out, (const POINTonE2_affine *)in);+}++void blst_p2_compress(unsigned char out[96], const POINTonE2 *in)+{+    if (vec_is_zero(in->Z, sizeof(in->Z))) {+        bytes_zero(out, 96);+        out[0] = 0xc0;    /* compressed and infinity bits */+    } else {+        limb_t sign = POINTonE2_Compress_BE(out, in);+        out[0] |= (unsigned char)(0x80 | ((sign & 2) << 4));+    }+}++static limb_t POINTonE2_Uncompress_BE(POINTonE2_affine *out,+                                      const unsigned char in[96])+{+    POINTonE2_affine ret;+    vec384 temp;++    limbs_from_be_bytes(ret.X[1], in, sizeof(ret.X[1]));+    limbs_from_be_bytes(ret.X[0], in + 48, sizeof(ret.X[0]));++    /* clear top 3 bits in case caller was conveying some information there */+    ret.X[1][sizeof(ret.X[1])/sizeof(limb_t)-1] &= ((limb_t)0-1) >> 3;+    add_fp(temp, ret.X[1], ZERO_384);  /* less than modulus? */+    if (!vec_is_equal(temp, ret.X[1], sizeof(temp)))+        return (limb_t)0 - BLST_BAD_ENCODING;++    add_fp(temp, ret.X[0], ZERO_384);  /* less than modulus? */+    if (!vec_is_equal(temp, ret.X[0], sizeof(temp)))+        return (limb_t)0 - BLST_BAD_ENCODING;++    mul_fp(ret.X[0], ret.X[0], BLS12_381_RR);+    mul_fp(ret.X[1], ret.X[1], BLS12_381_RR);++    sqr_fp2(ret.Y, ret.X);+    mul_fp2(ret.Y, ret.Y, ret.X);+    add_fp2(ret.Y, ret.Y, B_E2);                        /* X^3 + B */+    if (!sqrt_fp2(ret.Y, ret.Y))+        return (limb_t)0 - BLST_POINT_NOT_ON_CURVE;++    vec_copy(out, &ret, sizeof(ret));++    return sgn0_pty_mont_384x(out->Y, BLS12_381_P, p0);+}++static BLST_ERROR POINTonE2_Uncompress_Z(POINTonE2_affine *out,+                                         const unsigned char in[96])+{+    unsigned char in0 = in[0];+    limb_t sgn0_pty;++    if ((in0 & 0x80) == 0)      /* compressed bit */+        return BLST_BAD_ENCODING;++    if (in0 & 0x40) {           /* infinity bit */+        if (byte_is_zero(in0 & 0x3f) & bytes_are_zero(in+1, 95)) {+            vec_zero(out, sizeof(*out));+            return BLST_SUCCESS;+        } else {+            return BLST_BAD_ENCODING;+        }+    }++    sgn0_pty = POINTonE2_Uncompress_BE(out, in);++    if (sgn0_pty > 3)+        return (BLST_ERROR)(0 - sgn0_pty); /* POINT_NOT_ON_CURVE */++    sgn0_pty >>= 1; /* skip over parity bit */+    sgn0_pty ^= (in0 & 0x20) >> 5;+    cneg_fp2(out->Y, out->Y, sgn0_pty);++    return BLST_SUCCESS;+}++BLST_ERROR blst_p2_uncompress(POINTonE2_affine *out, const unsigned char in[96])+{   return POINTonE2_Uncompress_Z(out, in);   }++static BLST_ERROR POINTonE2_Deserialize_BE(POINTonE2_affine *out,+                                           const unsigned char in[192])+{+    POINTonE2_affine ret;+    vec384 temp;++    limbs_from_be_bytes(ret.X[1], in, sizeof(ret.X[1]));+    limbs_from_be_bytes(ret.X[0], in + 48, sizeof(ret.X[0]));+    limbs_from_be_bytes(ret.Y[1], in + 96, sizeof(ret.Y[1]));+    limbs_from_be_bytes(ret.Y[0], in + 144, sizeof(ret.Y[0]));++    /* clear top 3 bits in case caller was conveying some information there */+    ret.X[1][sizeof(ret.X[1])/sizeof(limb_t)-1] &= ((limb_t)0-1) >> 3;+    add_fp(temp, ret.X[1], ZERO_384);  /* less than modulus? */+    if (!vec_is_equal(temp, ret.X[1], sizeof(temp)))+        return BLST_BAD_ENCODING;++    add_fp(temp, ret.X[0], ZERO_384);  /* less than modulus? */+    if (!vec_is_equal(temp, ret.X[0], sizeof(temp)))+        return BLST_BAD_ENCODING;++    add_fp(temp, ret.Y[1], ZERO_384);  /* less than modulus? */+    if (!vec_is_equal(temp, ret.Y[1], sizeof(temp)))+        return BLST_BAD_ENCODING;++    add_fp(temp, ret.Y[0], ZERO_384);  /* less than modulus? */+    if (!vec_is_equal(temp, ret.Y[0], sizeof(temp)))+        return BLST_BAD_ENCODING;++    mul_fp(ret.X[0], ret.X[0], BLS12_381_RR);+    mul_fp(ret.X[1], ret.X[1], BLS12_381_RR);+    mul_fp(ret.Y[0], ret.Y[0], BLS12_381_RR);+    mul_fp(ret.Y[1], ret.Y[1], BLS12_381_RR);++    if (!POINTonE2_affine_on_curve(&ret))+        return BLST_POINT_NOT_ON_CURVE;++    vec_copy(out, &ret, sizeof(ret));++    return BLST_SUCCESS;+}++static BLST_ERROR POINTonE2_Deserialize_Z(POINTonE2_affine *out,+                                          const unsigned char in[192])+{+    unsigned char in0 = in[0];++    if ((in0 & 0xe0) == 0)+        return POINTonE2_Deserialize_BE(out, in);++    if (in0 & 0x80)             /* compressed bit */+        return POINTonE2_Uncompress_Z(out, in);++    if (in0 & 0x40) {           /* infinity bit */+        if (byte_is_zero(in0 & 0x3f) & bytes_are_zero(in+1, 191)) {+            vec_zero(out, sizeof(*out));+            return BLST_SUCCESS;+        }+    }++    return BLST_BAD_ENCODING;+}++BLST_ERROR blst_p2_deserialize(POINTonE2_affine *out,+                               const unsigned char in[192])+{   return POINTonE2_Deserialize_Z(out, in);   }++#include "ec_ops.h"+POINT_DADD_IMPL(POINTonE2, 384x, fp2)+POINT_DADD_AFFINE_IMPL_A0(POINTonE2, 384x, fp2, BLS12_381_Rx.p2)+POINT_ADD_IMPL(POINTonE2, 384x, fp2)+POINT_ADD_AFFINE_IMPL(POINTonE2, 384x, fp2, BLS12_381_Rx.p2)+POINT_DOUBLE_IMPL_A0(POINTonE2, 384x, fp2)+POINT_IS_EQUAL_IMPL(POINTonE2, 384x, fp2)++void blst_p2_add(POINTonE2 *out, const POINTonE2 *a, const POINTonE2 *b)+{   POINTonE2_add(out, a, b);   }++void blst_p2_add_or_double(POINTonE2 *out, const POINTonE2 *a,+                                           const POINTonE2 *b)+{   POINTonE2_dadd(out, a, b, NULL);   }++void blst_p2_add_affine(POINTonE2 *out, const POINTonE2 *a,+                                        const POINTonE2_affine *b)+{   POINTonE2_add_affine(out, a, b);   }++void blst_p2_add_or_double_affine(POINTonE2 *out, const POINTonE2 *a,+                                                  const POINTonE2_affine *b)+{   POINTonE2_dadd_affine(out, a, b);   }++void blst_p2_double(POINTonE2 *out, const POINTonE2 *a)+{   POINTonE2_double(out, a);   }++int blst_p2_is_equal(const POINTonE2 *a, const POINTonE2 *b)+{   return (int)POINTonE2_is_equal(a, b);   }++#include "ec_mult.h"+POINT_MULT_SCALAR_WX_IMPL(POINTonE2, 4)+POINT_MULT_SCALAR_WX_IMPL(POINTonE2, 5)++#ifdef __BLST_PRIVATE_TESTMODE__+POINT_AFFINE_MULT_SCALAR_IMPL(POINTonE2)++DECLARE_PRIVATE_POINTXZ(POINTonE2, 384x)+POINT_LADDER_PRE_IMPL(POINTonE2, 384x, fp2)+POINT_LADDER_STEP_IMPL_A0(POINTonE2, 384x, fp2, onE2)+POINT_LADDER_POST_IMPL_A0(POINTonE2, 384x, fp2, onE2)+POINT_MULT_SCALAR_LADDER_IMPL(POINTonE2)+#endif++static void psi(POINTonE2 *out, const POINTonE2 *in)+{+    static const vec384x frobenius_x = { /* 1/(1 + i)^((P-1)/3) */+      { 0 },+      { /* (0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4+              897d29650fb85f9b409427eb4f49fffd8bfd00000000aaad << 384) % P */+        TO_LIMB_T(0x890dc9e4867545c3), TO_LIMB_T(0x2af322533285a5d5),+        TO_LIMB_T(0x50880866309b7e2c), TO_LIMB_T(0xa20d1b8c7e881024),+        TO_LIMB_T(0x14e4f04fe2db9068), TO_LIMB_T(0x14e56d3f1564853a) }+    };+    static const vec384x frobenius_y = { /* 1/(1 + i)^((P-1)/2) */+      { /* (0x135203e60180a68ee2e9c448d77a2cd91c3dedd930b1cf60+              ef396489f61eb45e304466cf3e67fa0af1ee7b04121bdea2 << 384) % P */+        TO_LIMB_T(0x3e2f585da55c9ad1), TO_LIMB_T(0x4294213d86c18183),+        TO_LIMB_T(0x382844c88b623732), TO_LIMB_T(0x92ad2afd19103e18),+        TO_LIMB_T(0x1d794e4fac7cf0b9), TO_LIMB_T(0x0bd592fc7d825ec8) },+      { /* (0x06af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e+              77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09 << 384) % P */+        TO_LIMB_T(0x7bcfa7a25aa30fda), TO_LIMB_T(0xdc17dec12a927e7c),+        TO_LIMB_T(0x2f088dd86b4ebef1), TO_LIMB_T(0xd1ca2087da74d4a7),+        TO_LIMB_T(0x2da2596696cebc1d), TO_LIMB_T(0x0e2b7eedbbfd87d2) },+    };++    vec_copy(out, in, sizeof(*out));+    cneg_fp(out->X[1], out->X[1], 1);   mul_fp2(out->X, out->X, frobenius_x);+    cneg_fp(out->Y[1], out->Y[1], 1);   mul_fp2(out->Y, out->Y, frobenius_y);+    cneg_fp(out->Z[1], out->Z[1], 1);+}++/* Galbraith-Lin-Scott, ~67% faster than POINTonE2_mul_w5 */+static void POINTonE2_mult_gls(POINTonE2 *out, const POINTonE2 *in,+                               const pow256 SK)+{+    union { vec256 l; pow256 s; } val;++    /* break down SK to "digits" with |z| as radix [in constant time] */++    limbs_from_le_bytes(val.l, SK, 32);+    div_by_zz(val.l);+    div_by_z(val.l);+    div_by_z(val.l + NLIMBS(256)/2);+    le_bytes_from_limbs(val.s, val.l, 32);++    {+        const byte *scalars[2] = { val.s, NULL };+        POINTonE2 table[4][1<<(5-1)];   /* 18KB */+        size_t i;++        POINTonE2_precompute_w5(table[0], in);+        for (i = 0; i < 1<<(5-1); i++) {+            psi(&table[1][i], &table[0][i]);+            psi(&table[2][i], &table[1][i]);+            psi(&table[3][i], &table[2][i]);+            POINTonE2_cneg(&table[1][i], 1); /* account for z being negative */+            POINTonE2_cneg(&table[3][i], 1);+        }++        POINTonE2s_mult_w5(out, NULL, 4, scalars, 64, table);+    }++    vec_zero(val.l, sizeof(val));   /* scrub the copy of SK */+}++static void POINTonE2_sign(POINTonE2 *out, const POINTonE2 *in, const pow256 SK)+{+    vec384x Z, ZZ;+    limb_t inf;++    POINTonE2_mult_gls(out, in, SK);++    /* convert to affine to remove possible bias in out->Z */+    inf = vec_is_zero(out->Z, sizeof(out->Z));+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION+    flt_reciprocal_fp2(Z, out->Z);                      /* 1/Z   */+#else+    reciprocal_fp2(Z, out->Z);                          /* 1/Z   */+#endif++    sqr_fp2(ZZ, Z);+    mul_fp2(out->X, out->X, ZZ);                        /* X = X/Z^2 */++    mul_fp2(ZZ, ZZ, Z);+    mul_fp2(out->Y, out->Y, ZZ);                        /* Y = Y/Z^3 */++    vec_select(out->Z, out->Z, BLS12_381_G2.Z, sizeof(BLS12_381_G2.Z),+                       inf);                            /* Z = inf ? 0 : 1 */+}++void blst_sk_to_pk_in_g2(POINTonE2 *out, const pow256 SK)+{   POINTonE2_sign(out, &BLS12_381_G2, SK);   }++void blst_sign_pk_in_g1(POINTonE2 *out, const POINTonE2 *msg, const pow256 SK)+{   POINTonE2_sign(out, msg, SK);   }++void blst_sk_to_pk2_in_g2(unsigned char out[192], POINTonE2_affine *PK,+                          const pow256 SK)+{+    POINTonE2 P[1];++    POINTonE2_sign(P, &BLS12_381_G2, SK);+    if (PK != NULL)+        vec_copy(PK, P, sizeof(*PK));+    if (out != NULL) {+        limb_t sgn0_pty = POINTonE2_Serialize_BE(out, P);+        out[0] |= (sgn0_pty & 2) << 4;      /* pre-decorate */+        out[0] |= vec_is_zero(P->Z, sizeof(P->Z)) << 6;+    }+}++void blst_sign_pk2_in_g1(unsigned char out[192], POINTonE2_affine *sig,+                         const POINTonE2 *hash, const pow256 SK)+{+    POINTonE2 P[1];++    POINTonE2_sign(P, hash, SK);+    if (sig != NULL)+        vec_copy(sig, P, sizeof(*sig));+    if (out != NULL) {+        limb_t sgn0_pty = POINTonE2_Serialize_BE(out, P);+        out[0] |= (sgn0_pty & 2) << 4;      /* pre-decorate */+        out[0] |= vec_is_zero(P->Z, sizeof(P->Z)) << 6;+    }+}++void blst_p2_mult(POINTonE2 *out, const POINTonE2 *a,+                                  const byte *scalar, size_t nbits)+{+    if (nbits < 144) {+        if (nbits)+            POINTonE2_mult_w4(out, a, scalar, nbits);+        else+            vec_zero(out, sizeof(*out));+    } else if (nbits <= 256) {+        union { vec256 l; pow256 s; } val;+        size_t i, j, top, mask = (size_t)0 - 1;++        /* this is not about constant-time-ness, but branch optimization */+        for (top = (nbits + 7)/8, i=0, j=0; i<sizeof(val.s);) {+            val.s[i++] = scalar[j] & mask;+            mask = 0 - ((i - top) >> (8*sizeof(top)-1));+            j += 1 & mask;+        }++        if (check_mod_256(val.s, BLS12_381_r))  /* z^4 is the formal limit */+            POINTonE2_mult_gls(out, a, val.s);+        else    /* should never be the case, added for formal completeness */+            POINTonE2_mult_w5(out, a, scalar, nbits);++        vec_zero(val.l, sizeof(val));+    } else {    /* should never be the case, added for formal completeness */+        POINTonE2_mult_w5(out, a, scalar, nbits);+    }+}++void blst_p2_unchecked_mult(POINTonE2 *out, const POINTonE2 *a,+                                            const byte *scalar, size_t nbits)+{+    if (nbits)+        POINTonE2_mult_w4(out, a, scalar, nbits);+    else+        vec_zero(out, sizeof(*out));+}++int blst_p2_affine_is_equal(const POINTonE2_affine *a,+                            const POINTonE2_affine *b)+{   return (int)vec_is_equal(a, b, sizeof(*a));   }++int blst_p2_is_inf(const POINTonE2 *p)+{   return (int)vec_is_zero(p->Z, sizeof(p->Z));   }++const POINTonE2 *blst_p2_generator(void)+{   return &BLS12_381_G2;   }++int blst_p2_affine_is_inf(const POINTonE2_affine *p)+{   return (int)vec_is_zero(p, sizeof(*p));   }++const POINTonE2_affine *blst_p2_affine_generator(void)+{   return (const POINTonE2_affine *)&BLS12_381_G2;   }++size_t blst_p2_sizeof(void)+{   return sizeof(POINTonE2);   }++size_t blst_p2_affine_sizeof(void)+{   return sizeof(POINTonE2_affine);   }
+ vendor/external/blst/src/ec_mult.h view
@@ -0,0 +1,316 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLS12_381_ASM_EC_MULT_H__+#define __BLS12_381_ASM_EC_MULT_H__++#include "point.h"++/* Works up to 9 bits */+static limb_t get_wval(const byte *d, size_t off, size_t bits)+{+    size_t top = off + bits - 1;+    limb_t ret;++    ret = ((limb_t)d[top / 8] << 8) | d[off / 8];++    return ret >> (off%8);+}++/* Works up to 25 bits. */+static limb_t get_wval_limb(const byte *d, size_t off, size_t bits)+{+    size_t i, top = (off + bits - 1)/8;+    limb_t ret, mask = (limb_t)0 - 1;++    d   += off/8;+    top -= off/8-1;++    /* this is not about constant-time-ness, but branch optimization */+    for (ret=0, i=0; i<4;) {+        ret |= (*d & mask) << (8*i);+        mask = (limb_t)0 - ((++i - top) >> (8*sizeof(top)-1));+        d += 1 & mask;+    }++    return ret >> (off%8);+}++/*+ * Window value encoding that utilizes the fact that -P is trivially+ * calculated, which allows to halve the size of pre-computed table,+ * is attributed to A. D. Booth, hence the name of the subroutines...+ */+static limb_t booth_encode(limb_t wval, size_t sz)+{+    limb_t mask = 0 - (wval >> sz);     /* "sign" bit -> mask */+    launder(mask);++    wval = (wval + 1) >> 1;+    wval = (wval ^ mask) - mask;++    /* &0x1f, but <=0x10, is index in table, rest is extended "sign" bit */+    return wval;+}++/*+ * Key feature of these constant-time subroutines is that they tolerate+ * zeros in most significant bit positions of the scalar[s], or in other+ * words, zero-padded scalar values. This means that one can and should+ * pass order's bit-length, which is customarily publicly known, instead+ * of the factual scalars' bit-lengths. This is facilitated by point+ * addition subroutines implemented to handle points at infinity, which+ * are encoded as Z==0. [Doubling algorithms handle such points at+ * infinity "naturally," since resulting Z is product of original Z.]+ */+#define POINT_MULT_SCALAR_WX_IMPL(ptype, SZ) \+static bool_t ptype##_gather_booth_w##SZ(ptype *restrict p, \+                                         const ptype table[1<<(SZ-1)], \+                                         limb_t booth_idx) \+{ \+    size_t i; \+    bool_t booth_sign = (booth_idx >> SZ) & 1; \+\+    booth_idx &= (1<<SZ) - 1; \+    vec_copy(p, table, sizeof(ptype)); \+    /* ~6% with -Os, ~2% with -O3 ... */\+    for (i = 2; i <= 1<<(SZ-1); i++) \+        ptype##_ccopy(p, table + i - 1, byte_is_zero((byte)(i ^ booth_idx))); \+\+    ptype##_cneg(p, booth_sign); \+\+    return byte_is_zero((byte)booth_idx); \+} \+\+static void ptype##_precompute_w##SZ(ptype row[], const ptype *point) \+{ \+    size_t i, j; \+                                      /* row[-1] is implicit infinity */\+    vec_copy(&row[0], point, sizeof(ptype));        /* row[0]=p*1     */\+    ptype##_double(&row[1],  point);                /* row[1]=p*(1+1) */\+    for (i = 2, j = 1; i < 1<<(SZ-1); i += 2, j++) \+        ptype##_add(&row[i], &row[j], &row[j-1]),   /* row[2]=p*(2+1) */\+        ptype##_double(&row[i+1], &row[j]);         /* row[3]=p*(2+2) */\+}                                                   /* row[4] ...     */\+\+static void ptype##s_mult_w##SZ(ptype *ret, \+                                const ptype *points[], size_t npoints, \+                                const byte *scalars[], size_t bits, \+                                ptype table[][1<<(SZ-1)]) \+{ \+    limb_t wmask, wval; \+    size_t i, j, window, nbytes; \+    const byte *scalar, **scalar_s = scalars; \+    ptype sum[1], row[1]; \+    bool_t sum_is_inf, row_is_inf, ret_is_inf; \+\+    if (table == NULL) \+        table = (ptype (*)[1<<(SZ-1)])alloca((1<<(SZ-1)) * sizeof(ptype) * \+                                             npoints); \+\+    if (points != NULL) { \+        const ptype *point = NULL; \+        for (i = 0; i < npoints; i++) \+            point = *points ? *points++ : point+1, \+            ptype##_precompute_w##SZ(table[i], point); \+    } \+\+    nbytes = (bits + 7)/8; /* convert |bits| to bytes */ \+    scalar = *scalar_s++; \+\+    /* top excess bits modulo target window size */ \+    window = bits % SZ; /* yes, it may be zero */ \+    wmask = ((limb_t)1 << (window + 1)) - 1; \+\+    bits -= window; \+    if (bits > 0) \+        wval = get_wval(scalar, bits - 1, window + 1) & wmask; \+    else \+        wval = (scalar[0] << 1) & wmask; \+\+    wval = booth_encode(wval, SZ); \+    ret_is_inf = ptype##_gather_booth_w##SZ(ret, table[0], wval); \+\+    i = 1; \+    while (bits > 0) { \+        for (; i < npoints; i++) { \+            scalar = *scalar_s ? *scalar_s++ : scalar+nbytes; \+            wval = get_wval(scalar, bits - 1, window + 1) & wmask; \+            wval = booth_encode(wval, SZ); \+            row_is_inf = ptype##_gather_booth_w##SZ(row, table[i], wval); \+            ptype##_dadd(sum, ret, row, NULL); \+            ptype##_ccopy(ret, sum, (ret_is_inf | row_is_inf) ^ 1); \+            sum_is_inf = vec_is_zero(ret->Z, sizeof(ret->Z)); \+            ret_is_inf |= sum_is_inf; \+            row_is_inf |= sum_is_inf; \+            ptype##_ccopy(ret, row, ret_is_inf); \+            ret_is_inf &= row_is_inf; \+        } \+\+        for (j = 0; j < SZ; j++) \+            ptype##_double(ret, ret); \+\+        window = SZ; \+        wmask = ((limb_t)1 << (window + 1)) - 1; \+        bits -= window; \+        i = 0; scalar_s = scalars; \+    } \+\+    for (; i < npoints; i++) { \+        scalar = *scalar_s ? *scalar_s++ : scalar+nbytes; \+        wval = (scalar[0] << 1) & wmask; \+        wval = booth_encode(wval, SZ); \+        row_is_inf = ptype##_gather_booth_w##SZ(row, table[i], wval); \+        ptype##_dadd(sum, ret, row, NULL); \+        ptype##_ccopy(ret, sum, (ret_is_inf | row_is_inf) ^ 1); \+        sum_is_inf = vec_is_zero(ret->Z, sizeof(ret->Z)); \+        ret_is_inf |= sum_is_inf; \+        row_is_inf |= sum_is_inf; \+        ptype##_ccopy(ret, row, ret_is_inf); \+        ret_is_inf &= row_is_inf; \+    } \+\+    vec_czero(ret->Z, sizeof(ret->Z), ret_is_inf); \+} \+\+static void ptype##_mult_w##SZ(ptype *ret, const ptype *point, \+                               const byte *scalar, size_t bits) \+{ \+    limb_t wmask, wval; \+    size_t j, window; \+    ptype sum[1], row[1]; \+    bool_t sum_is_inf, row_is_inf, ret_is_inf; \+    ptype table[1<<(SZ-1)]; \+\+    ptype##_precompute_w##SZ(table, point); \+\+    /* top excess bits modulo target window size */ \+    window = bits % SZ;  /* yes, it may be zero */ \+    wmask = ((limb_t)1 << (window + 1)) - 1; \+\+    bits -= window; \+    wval = bits ? get_wval(scalar, bits - 1, window + 1) \+                : (limb_t)scalar[0] << 1; \+    wval &= wmask; \+    wval = booth_encode(wval, SZ); \+    ret_is_inf = ptype##_gather_booth_w##SZ(ret, table, wval); \+\+    while (bits > 0) { \+        for (j = 0; j < SZ; j++) \+            ptype##_double(ret, ret); \+\+        window = SZ; \+        wmask = ((limb_t)1 << (window + 1)) - 1; \+        bits -= window; \+\+        wval = bits ? get_wval(scalar, bits - 1, window + 1) \+                    : (limb_t)scalar[0] << 1; \+        wval &= wmask; \+        wval = booth_encode(wval, SZ); \+        row_is_inf = ptype##_gather_booth_w##SZ(row, table, wval); \+        if (bits > 0) ptype##_add(sum, ret, row); \+        else          ptype##_dadd(sum, ret, row, NULL); \+        ptype##_ccopy(ret, sum, (ret_is_inf | row_is_inf) ^ 1); \+        sum_is_inf = vec_is_zero(ret->Z, sizeof(ret->Z)); \+        ret_is_inf |= sum_is_inf; \+        row_is_inf |= sum_is_inf; \+        ptype##_ccopy(ret, row, ret_is_inf); \+        ret_is_inf &= row_is_inf; \+    } \+\+    vec_czero(ret->Z, sizeof(ret->Z), ret_is_inf); \+}++#if 0+/* ~50%, or ~2x[!] slower than w5... */+#define POINT_MULT_SCALAR_LADDER_IMPL(ptype) \+static void ptype##_mult_ladder(ptype *ret, const ptype *p, \+                                const byte *scalar, size_t bits) \+{ \+    ptype sum[1]; \+    bool_t bit, pbit = 0; \+\+    vec_copy(sum, p, sizeof(ptype)); \+    vec_zero(ret, sizeof(ptype));   /* infinity */ \+\+    while (bits--) { \+        bit = is_bit_set(scalar, bits); \+        bit ^= pbit; \+        ptype##_cswap(ret, sum, bit); \+        ptype##_add(sum, sum, ret); \+        ptype##_double(ret, ret); \+        pbit ^= bit; \+    } \+    ptype##_cswap(ret, sum, pbit); \+}+#else+/* >40% better performance than above, [and ~30% slower than w5]... */+#define POINT_MULT_SCALAR_LADDER_IMPL(ptype) \+static void ptype##_mult_ladder(ptype *out, const ptype *p, \+                                const byte *scalar, size_t bits) \+{ \+    ptype##xz sum[1]; \+    ptype##xz pxz[1]; \+    ptype##xz ret[1]; \+    bool_t bit, pbit = 0; \+\+    ptype##xz_ladder_pre(pxz, p); \+    vec_copy(sum, pxz, sizeof(ptype##xz)); \+    vec_zero(ret, sizeof(ptype##xz));   /* infinity */ \+\+    while (bits--) { \+        bit = is_bit_set(scalar, bits); \+        bit ^= pbit; \+        ptype##xz_cswap(ret, sum, bit); \+        ptype##xz_ladder_step(ret, sum, pxz); \+        pbit ^= bit; \+    } \+    ptype##xz_cswap(ret, sum, pbit); \+    ptype##xz_ladder_post(out, ret, sum, pxz, p->Y); \+}+#endif++/*+ * Sole reason for existence of this implementation is that addition+ * with affine point renders a share of multiplications redundant by+ * virtue of Z==1. And since pre-defined generator point can be and+ * customarily is instantiated affine, it would be hardly appropriate+ * to pass on this opportunity. Though while it's faster than the+ * generic ladder implementation, by ~25%, it's not faster than XZ one+ * above, <15% slower. Just in case, it's faster than generic ladder+ * even if one accounts for prior conversion to affine coordinates,+ * so that choice [for resource-constrained case] is actually between+ * this plus said conversion and XZ ladder...+ *+ * To summarize, if ptype##_mult_w5 executed in one unit of time, then+ * - naive ptype##_mult_ladder would execute in ~2;+ * - XZ version above - in ~1.4;+ * - ptype##_affine_mult_ladder below - in ~1.65;+ * - [small-footprint ptype##_to_affine would run in ~0.18].+ *+ * Caveat lector, |p_affine|*(order+2) produces wrong result, because+ * addition doesn't handle doubling. Indeed, P*(order+1) is P and it+ * fails to add with itself producing infinity in last addition. But+ * as long as |scalar| is reduced modulo order, as it should be, it's+ * not a problem...+ */+#define POINT_AFFINE_MULT_SCALAR_IMPL(ptype) \+static void ptype##_affine_mult_ladder(ptype *ret, \+                                       const ptype##_affine *p_affine, \+                                       const byte *scalar, size_t bits) \+{ \+    ptype sum[1]; \+    bool_t bit; \+\+    vec_zero(ret, sizeof(ptype));   /* infinity */ \+\+    while (bits--) { \+        ptype##_double(ret, ret); \+        ptype##_add_affine(sum, ret, p_affine); \+        bit = (scalar[bits / LIMB_T_BITS] >> (bits % LIMB_T_BITS)) & 1; \+        ptype##_ccopy(ret, sum, bit); \+    } \+}+#endif
+ vendor/external/blst/src/ec_ops.h view
@@ -0,0 +1,787 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLS12_384_ASM_EC_OPS_H__+#define __BLS12_384_ASM_EC_OPS_H__+/*+ * Addition that can handle doubling [as well as points at infinity,+ * which are encoded as Z==0] in constant time. It naturally comes at+ * cost, but this subroutine should be called only when independent+ * points are processed, which is considered reasonable compromise.+ * For example, ptype##s_mult_w5 calls it, but since *major* gain is+ * result of pure doublings being effectively divided by amount of+ * points, slightly slower addition can be tolerated. But what is the+ * additional cost more specifically? Best addition result is 11M+5S,+ * while this routine takes 13M+5S (+1M+1S if a4!=0), as per+ *+ * -------------+-------------+ * addition     | doubling+ * -------------+-------------+ * U1 = X1*Z2^2 | U1 = X1+ * U2 = X2*Z1^2 |+ * S1 = Y1*Z2^3 | S1 = Y1+ * S2 = Y2*Z1^3 |+ * zz = Z1*Z2   | zz = Z1+ * H = U2-U1    | H' = 2*Y1+ * R = S2-S1    | R' = 3*X1^2[+a*Z1^4]+ * sx = U1+U2   | sx = X1+X1+ * -------------+-------------+ * H!=0 || R!=0 | H==0 && R==0+ *+ *      X3 = R^2-H^2*sx+ *      Y3 = R*(H^2*U1-X3)-H^3*S1+ *      Z3 = H*zz+ *+ * As for R!=0 condition in context of H==0, a.k.a. P-P. The result is+ * infinity by virtue of Z3 = (U2-U1)*zz = H*zz = 0*zz == 0.+ */+#define POINT_DADD_IMPL(ptype, bits, field) \+static void ptype##_dadd(ptype *out, const ptype *p1, const ptype *p2, \+                         const vec##bits a4) \+{ \+    ptype p3; /* starts as (U1, S1, zz) from addition side */\+    struct { vec##bits H, R, sx; } add, dbl; \+    bool_t p1inf, p2inf, is_dbl; \+\+    add_##field(dbl.sx, p1->X, p1->X);  /* sx = X1+X1 */\+    sqr_##field(dbl.R, p1->X);          /* X1^2 */\+    mul_by_3_##field(dbl.R, dbl.R);     /* R = 3*X1^2 */\+    add_##field(dbl.H, p1->Y, p1->Y);   /* H = 2*Y1 */\+\+    p2inf = vec_is_zero(p2->Z, sizeof(p2->Z)); \+    sqr_##field(p3.X, p2->Z);           /* Z2^2 */\+    mul_##field(p3.Z, p1->Z, p2->Z);    /* Z1*Z2 */\+    p1inf = vec_is_zero(p1->Z, sizeof(p1->Z)); \+    sqr_##field(add.H, p1->Z);          /* Z1^2 */\+\+    if (a4 != NULL) { \+        sqr_##field(p3.Y, add.H);       /* Z1^4, [borrow p3.Y] */\+        mul_##field(p3.Y, p3.Y, a4);    \+        add_##field(dbl.R, dbl.R, p3.Y);/* R = 3*X1^2+a*Z1^4 */\+    } \+\+    mul_##field(p3.Y, p1->Y, p2->Z);    \+    mul_##field(p3.Y, p3.Y, p3.X);      /* S1 = Y1*Z2^3 */\+    mul_##field(add.R, p2->Y, p1->Z);   \+    mul_##field(add.R, add.R, add.H);   /* S2 = Y2*Z1^3 */\+    sub_##field(add.R, add.R, p3.Y);    /* R = S2-S1 */\+\+    mul_##field(p3.X, p3.X, p1->X);     /* U1 = X1*Z2^2 */\+    mul_##field(add.H, add.H, p2->X);   /* U2 = X2*Z1^2 */\+\+    add_##field(add.sx, add.H, p3.X);   /* sx = U1+U2 */\+    sub_##field(add.H, add.H, p3.X);    /* H = U2-U1 */\+\+    /* make the choice between addition and doubling */\+    is_dbl = vec_is_zero(add.H, 2*sizeof(add.H));      \+    vec_select(&p3, p1, &p3, sizeof(p3), is_dbl);      \+    vec_select(&add, &dbl, &add, sizeof(add), is_dbl); \+    /* |p3| and |add| hold all inputs now, |p3| will hold output */\+\+    mul_##field(p3.Z, p3.Z, add.H);     /* Z3 = H*Z1*Z2 */\+\+    sqr_##field(dbl.H, add.H);          /* H^2 */\+    mul_##field(dbl.R, dbl.H, add.H);   /* H^3 */\+    mul_##field(dbl.R, dbl.R, p3.Y);    /* H^3*S1 */\+    mul_##field(p3.Y, dbl.H, p3.X);     /* H^2*U1 */\+\+    mul_##field(dbl.H, dbl.H, add.sx);  /* H^2*sx */\+    sqr_##field(p3.X, add.R);           /* R^2 */\+    sub_##field(p3.X, p3.X, dbl.H);     /* X3 = R^2-H^2*sx */\+\+    sub_##field(p3.Y, p3.Y, p3.X);      /* H^2*U1-X3 */\+    mul_##field(p3.Y, p3.Y, add.R);     /* R*(H^2*U1-X3) */\+    sub_##field(p3.Y, p3.Y, dbl.R);     /* Y3 = R*(H^2*U1-X3)-H^3*S1 */\+\+    vec_select(&p3, p1, &p3, sizeof(ptype), p2inf); \+    vec_select(out, p2, &p3, sizeof(ptype), p1inf); \+}++/*+ * Addition with affine point that can handle doubling [as well as+ * points at infinity, with |p1| being encoded as Z==0 and |p2| as+ * X,Y==0] in constant time. But at what additional cost? Best+ * addition result is 7M+4S, while this routine takes 8M+5S, as per+ *+ * -------------+-------------+ * addition     | doubling+ * -------------+-------------+ * U1 = X1      | U1 = X2+ * U2 = X2*Z1^2 |+ * S1 = Y1      | S1 = Y2+ * S2 = Y2*Z1^3 |+ * H = U2-X1    | H' = 2*Y2+ * R = S2-Y1    | R' = 3*X2^2[+a]+ * sx = X1+U2   | sx = X2+X2+ * zz = H*Z1    | zz = H'+ * -------------+-------------+ * H!=0 || R!=0 | H==0 && R==0+ *+ *      X3 = R^2-H^2*sx+ *      Y3 = R*(H^2*U1-X3)-H^3*S1+ *      Z3 = zz+ *+ * As for R!=0 condition in context of H==0, a.k.a. P-P. The result is+ * infinity by virtue of Z3 = (U2-U1)*zz = H*zz = 0*zz == 0.+ */+#define POINT_DADD_AFFINE_IMPL_A0(ptype, bits, field, one) \+static void ptype##_dadd_affine(ptype *out, const ptype *p1, \+                                            const ptype##_affine *p2) \+{ \+    ptype p3; /* starts as (,, H*Z1) from addition side */\+    struct { vec##bits H, R, sx; } add, dbl; \+    bool_t p1inf, p2inf, is_dbl; \+\+    p2inf = vec_is_zero(p2->X, 2*sizeof(p2->X)); \+    add_##field(dbl.sx, p2->X, p2->X);  /* sx = X2+X2 */\+    sqr_##field(dbl.R, p2->X);          /* X2^2 */\+    mul_by_3_##field(dbl.R, dbl.R);     /* R = 3*X2^2 */\+    add_##field(dbl.H, p2->Y, p2->Y);   /* H = 2*Y2 */\+\+    p1inf = vec_is_zero(p1->Z, sizeof(p1->Z)); \+    sqr_##field(add.H, p1->Z);          /* Z1^2 */\+    mul_##field(add.R, add.H, p1->Z);   /* Z1^3 */\+    mul_##field(add.R, add.R, p2->Y);   /* S2 = Y2*Z1^3 */\+    sub_##field(add.R, add.R, p1->Y);   /* R = S2-Y1 */\+\+    mul_##field(add.H, add.H, p2->X);   /* U2 = X2*Z1^2 */\+\+    add_##field(add.sx, add.H, p1->X);  /* sx = X1+U2 */\+    sub_##field(add.H, add.H, p1->X);   /* H = U2-X1 */\+\+    mul_##field(p3.Z, add.H, p1->Z);    /* Z3 = H*Z1 */\+\+    /* make the choice between addition and doubling */ \+    is_dbl = vec_is_zero(add.H, 2*sizeof(add.H));       \+    vec_select(p3.X, p2, p1, 2*sizeof(p3.X), is_dbl);   \+    vec_select(p3.Z, dbl.H, p3.Z, sizeof(p3.Z), is_dbl);\+    vec_select(&add, &dbl, &add, sizeof(add), is_dbl);  \+    /* |p3| and |add| hold all inputs now, |p3| will hold output */\+\+    sqr_##field(dbl.H, add.H);          /* H^2 */\+    mul_##field(dbl.R, dbl.H, add.H);   /* H^3 */\+    mul_##field(dbl.R, dbl.R, p3.Y);    /* H^3*S1 */\+    mul_##field(p3.Y, dbl.H, p3.X);     /* H^2*U1 */\+\+    mul_##field(dbl.H, dbl.H, add.sx);  /* H^2*sx */\+    sqr_##field(p3.X, add.R);           /* R^2 */\+    sub_##field(p3.X, p3.X, dbl.H);     /* X3 = R^2-H^2*sx */\+\+    sub_##field(p3.Y, p3.Y, p3.X);      /* H^2*U1-X3 */\+    mul_##field(p3.Y, p3.Y, add.R);     /* R*(H^2*U1-X3) */\+    sub_##field(p3.Y, p3.Y, dbl.R);     /* Y3 = R*(H^2*U1-X3)-H^3*S1 */\+\+    vec_select(p3.X, p2,  p3.X, 2*sizeof(p3.X), p1inf); \+    vec_select(p3.Z, one, p3.Z, sizeof(p3.Z), p1inf); \+    vec_select(out, p1, &p3, sizeof(ptype), p2inf); \+}++/*+ * https://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-add-2007-bl+ * with twist to handle either input at infinity, which are encoded as Z==0.+ */+#define POINT_ADD_IMPL(ptype, bits, field) \+static void ptype##_add(ptype *out, const ptype *p1, const ptype *p2) \+{ \+    ptype p3; \+    vec##bits Z1Z1, Z2Z2, U1, S1, H, I, J; \+    bool_t p1inf, p2inf; \+\+    p1inf = vec_is_zero(p1->Z, sizeof(p1->Z)); \+    sqr_##field(Z1Z1, p1->Z);           /* Z1Z1 = Z1^2 */\+\+    mul_##field(p3.Z, Z1Z1, p1->Z);     /* Z1*Z1Z1 */\+    mul_##field(p3.Z, p3.Z, p2->Y);     /* S2 = Y2*Z1*Z1Z1 */\+\+    p2inf = vec_is_zero(p2->Z, sizeof(p2->Z)); \+    sqr_##field(Z2Z2, p2->Z);           /* Z2Z2 = Z2^2 */\+\+    mul_##field(S1, Z2Z2, p2->Z);       /* Z2*Z2Z2 */\+    mul_##field(S1, S1, p1->Y);         /* S1 = Y1*Z2*Z2Z2 */\+\+    sub_##field(p3.Z, p3.Z, S1);        /* S2-S1 */\+    add_##field(p3.Z, p3.Z, p3.Z);      /* r = 2*(S2-S1) */\+\+    mul_##field(U1, p1->X, Z2Z2);       /* U1 = X1*Z2Z2 */\+    mul_##field(H,  p2->X, Z1Z1);       /* U2 = X2*Z1Z1 */\+\+    sub_##field(H, H, U1);              /* H = U2-U1 */\+\+    add_##field(I, H, H);               /* 2*H */\+    sqr_##field(I, I);                  /* I = (2*H)^2 */\+\+    mul_##field(J, H, I);               /* J = H*I */\+    mul_##field(S1, S1, J);             /* S1*J */\+\+    mul_##field(p3.Y, U1, I);           /* V = U1*I */\+\+    sqr_##field(p3.X, p3.Z);            /* r^2 */\+    sub_##field(p3.X, p3.X, J);         /* r^2-J */\+    sub_##field(p3.X, p3.X, p3.Y);      \+    sub_##field(p3.X, p3.X, p3.Y);      /* X3 = r^2-J-2*V */\+\+    sub_##field(p3.Y, p3.Y, p3.X);      /* V-X3 */\+    mul_##field(p3.Y, p3.Y, p3.Z);      /* r*(V-X3) */\+    sub_##field(p3.Y, p3.Y, S1);        \+    sub_##field(p3.Y, p3.Y, S1);        /* Y3 = r*(V-X3)-2*S1*J */\+\+    add_##field(p3.Z, p1->Z, p2->Z);    /* Z1+Z2 */\+    sqr_##field(p3.Z, p3.Z);            /* (Z1+Z2)^2 */\+    sub_##field(p3.Z, p3.Z, Z1Z1);      /* (Z1+Z2)^2-Z1Z1 */\+    sub_##field(p3.Z, p3.Z, Z2Z2);      /* (Z1+Z2)^2-Z1Z1-Z2Z2 */\+    mul_##field(p3.Z, p3.Z, H);         /* Z3 = ((Z1+Z2)^2-Z1Z1-Z2Z2)*H */\+\+    vec_select(&p3, p1, &p3, sizeof(ptype), p2inf); \+    vec_select(out, p2, &p3, sizeof(ptype), p1inf); \+}++/*+ * https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-madd-2007-bl+ * with twist to handle either input at infinity, with |p1| encoded as Z==0,+ * and |p2| as X==Y==0.+ */+#define POINT_ADD_AFFINE_IMPL(ptype, bits, field, one) \+static void ptype##_add_affine(ptype *out, const ptype *p1, \+                                           const ptype##_affine *p2) \+{ \+    ptype p3; \+    vec##bits Z1Z1, H, HH, I, J; \+    bool_t p1inf, p2inf; \+\+    p1inf = vec_is_zero(p1->Z, sizeof(p1->Z)); \+\+    sqr_##field(Z1Z1, p1->Z);           /* Z1Z1 = Z1^2 */\+\+    mul_##field(p3.Z, Z1Z1, p1->Z);     /* Z1*Z1Z1 */\+    mul_##field(p3.Z, p3.Z, p2->Y);     /* S2 = Y2*Z1*Z1Z1 */\+\+    p2inf = vec_is_zero(p2->X, 2*sizeof(p2->X)); \+\+    mul_##field(H, p2->X, Z1Z1);        /* U2 = X2*Z1Z1 */\+    sub_##field(H, H, p1->X);           /* H = U2-X1 */\+\+    sqr_##field(HH, H);                 /* HH = H^2 */\+    add_##field(I, HH, HH);             \+    add_##field(I, I, I);               /* I = 4*HH */\+\+    mul_##field(p3.Y, p1->X, I);        /* V = X1*I */\+    mul_##field(J, H, I);               /* J = H*I */\+    mul_##field(I, J, p1->Y);           /* Y1*J */\+\+    sub_##field(p3.Z, p3.Z, p1->Y);     /* S2-Y1 */\+    add_##field(p3.Z, p3.Z, p3.Z);      /* r = 2*(S2-Y1) */\+\+    sqr_##field(p3.X, p3.Z);            /* r^2 */\+    sub_##field(p3.X, p3.X, J);         /* r^2-J */\+    sub_##field(p3.X, p3.X, p3.Y);      \+    sub_##field(p3.X, p3.X, p3.Y);      /* X3 = r^2-J-2*V */\+\+    sub_##field(p3.Y, p3.Y, p3.X);      /* V-X3 */\+    mul_##field(p3.Y, p3.Y, p3.Z);      /* r*(V-X3) */\+    sub_##field(p3.Y, p3.Y, I);         \+    sub_##field(p3.Y, p3.Y, I);         /* Y3 = r*(V-X3)-2*Y1*J */\+\+    add_##field(p3.Z, p1->Z, H);        /* Z1+H */\+    sqr_##field(p3.Z, p3.Z);            /* (Z1+H)^2 */\+    sub_##field(p3.Z, p3.Z, Z1Z1);      /* (Z1+H)^2-Z1Z1 */\+    sub_##field(p3.Z, p3.Z, HH);        /* Z3 = (Z1+H)^2-Z1Z1-HH */\+\+    vec_select(p3.Z, one, p3.Z, sizeof(p3.Z), p1inf); \+    vec_select(p3.X, p2,  p3.X, 2*sizeof(p3.X), p1inf); \+    vec_select(out, p1, &p3, sizeof(ptype), p2inf); \+}++/*+ * https://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l+ */+#define POINT_DOUBLE_IMPL_A0(ptype, bits, field) \+static void ptype##_double(ptype *p3, const ptype *p1) \+{ \+    vec##bits A, B, C; \+\+    sqr_##field(A, p1->X);              /* A = X1^2 */\+    sqr_##field(B, p1->Y);              /* B = Y1^2 */\+    sqr_##field(C, B);                  /* C = B^2 */\+\+    add_##field(B, B, p1->X);           /* X1+B */\+    sqr_##field(B, B);                  /* (X1+B)^2 */\+    sub_##field(B, B, A);               /* (X1+B)^2-A */\+    sub_##field(B, B, C);               /* (X1+B)^2-A-C */\+    add_##field(B, B, B);               /* D = 2*((X1+B)^2-A-C) */\+\+    mul_by_3_##field(A, A);             /* E = 3*A */\+\+    sqr_##field(p3->X, A);              /* F = E^2 */\+    sub_##field(p3->X, p3->X, B);       \+    sub_##field(p3->X, p3->X, B);       /* X3 = F-2*D */\+\+    add_##field(p3->Z, p1->Z, p1->Z);   /* 2*Z1 */\+    mul_##field(p3->Z, p3->Z, p1->Y);   /* Z3 = 2*Z1*Y1 */\+\+    mul_by_8_##field(C, C);             /* 8*C */\+    sub_##field(p3->Y, B, p3->X);       /* D-X3 */\+    mul_##field(p3->Y, p3->Y, A);       /* E*(D-X3) */\+    sub_##field(p3->Y, p3->Y, C);       /* Y3 = E*(D-X3)-8*C */\+}++#define POINT_LADDER_PRE_IMPL(ptype, bits, field) \+static void ptype##xz_ladder_pre(ptype##xz *pxz, const ptype *p) \+{ \+    mul_##field(pxz->X, p->X, p->Z);    /* X2 = X1*Z1 */\+    sqr_##field(pxz->Z, p->Z);          \+    mul_##field(pxz->Z, pxz->Z, p->Z);  /* Z2 = Z1^3 */\+}++/*+ * https://hyperelliptic.org/EFD/g1p/auto-shortw-xz.html#ladder-ladd-2002-it-3+ * with twist to handle either input at infinity, which are encoded as Z==0.+ * Just in case, order of doubling and addition is reverse in comparison to+ * hyperelliptic.org entry. This was done to minimize temporary storage.+ *+ * XZ1 is |p|, XZ2&XZ4 are in&out |r|, XZ3&XZ5 are in&out |s|.+ */+#define POINT_LADDER_STEP_IMPL_A0(ptype, bits, field, suffix4b) \+static void ptype##xz_ladder_step(ptype##xz *r, ptype##xz *s, \+                                  const ptype##xz *p) \+{ \+    ptype##xz p5; \+    vec##bits A, B, C, D, XX, ZZ; \+    bool_t r_inf, s_inf; \+                                        /* s += r */\+    mul_##field(A, r->X, s->X);         /* A = X2*X3 */\+    mul_##field(B, r->Z, s->Z);         /* B = Z2*Z3 */\+    mul_##field(C, r->X, s->Z);         /* C = X2*Z3 */\+    mul_##field(D, r->Z, s->X);         /* D = X3*Z2 */\+\+    sqr_##field(A, A);                  /* (A[-a*B])^2 */\+    add_##field(p5.X, C, D);            /* C+D */\+    mul_##field(p5.X, p5.X, B);         /* B*(C+D) */\+    mul_by_4b_##suffix4b(B, p5.X);      /* b4*B*(C+D) */\+    sub_##field(p5.X, A, B);            /* (A[-a*B])^2-b4*B*(C+D) */\+    mul_##field(p5.X, p5.X, p->Z);      /* X5 = Z1*((A[-a*B])^2-b4*B*(C+D)) */\+\+    sub_##field(p5.Z, C, D);            /* C-D */\+    sqr_##field(p5.Z, p5.Z);            /* (C-D)^2 */\+    mul_##field(p5.Z, p5.Z, p->X);      /* Z5 = X1*(C-D)^2 */\+\+    r_inf = vec_is_zero(r->Z, sizeof(r->Z)); \+    s_inf = vec_is_zero(s->Z, sizeof(s->Z)); \+\+    vec_select(&p5, r, &p5, sizeof(ptype##xz), s_inf); \+    vec_select(s,   s, &p5, sizeof(ptype##xz), r_inf); \+                                        /* r *= 2 */\+    sqr_##field(XX, r->X);              /* XX = X2^2 */\+    sqr_##field(ZZ, r->Z);              /* ZZ = Z2^2 */\+\+    add_##field(r->Z, r->X, r->Z);      /* X2+Z2 */\+    sqr_##field(r->Z, r->Z);            /* (X2+Z2)^2 */\+    sub_##field(r->Z, r->Z, XX);        /* (X2+Z2)^2-XX */\+    sub_##field(r->Z, r->Z, ZZ);        /* E = (X2+Z2)^2-XX-ZZ */\+\+    sqr_##field(A, XX);                 /* (XX[-a*ZZ])^2 */\+    mul_##field(B, r->Z, ZZ);           /* E*ZZ */\+    mul_by_4b_##suffix4b(C, B);         /* b4*E*ZZ */\+    sub_##field(r->X, A, C);            /* X4 = (XX[-a*ZZ])^2-b4*E*ZZ */\+\+    sqr_##field(ZZ, ZZ);                /* ZZ^2 */\+    mul_by_4b_##suffix4b(B, ZZ);        /* b4*ZZ^2 */\+    mul_##field(r->Z, r->Z, XX);        /* E*(XX[+a*ZZ]) */\+    add_##field(r->Z, r->Z, r->Z);      /* 2*E*(XX[+a*ZZ]) */\+    add_##field(r->Z, r->Z, B);         /* Z4 = 2*E*(XX[+a*ZZ])+b4*ZZ^2 */\+}++/*+ * Recover the |r|'s y-coordinate using Eq. (8) from Brier-Joye,+ * "Weierstraß Elliptic Curves and Side-Channel Attacks", with XZ twist+ * and conversion to Jacobian coordinates from <openssl>/.../ecp_smpl.c,+ * and with twist to recover from |s| at infinity [which occurs when+ * multiplying by (order-1)].+ *+ * X4 = 2*Y1*X2*Z3*Z1*Z2+ * Y4 = 2*b*Z3*(Z1*Z2)^2 + Z3*(a*Z1*Z2+X1*X2)*(X1*Z2+X2*Z1) - X3*(X1*Z2-X2*Z1)^2+ * Z4 = 2*Y1*Z3*Z2^2*Z1+ *+ * Z3x2 = 2*Z3+ * Y1Z3x2 = Y1*Z3x2+ * Z1Z2 = Z1*Z2+ * X1Z2 = X1*Z2+ * X2Z1 = X2*Z1+ * X4 = Y1Z3x2*X2*Z1Z2+ * A = b*Z3x2*(Z1Z2)^2+ * B = Z3*(a*Z1Z2+X1*X2)*(X1Z2+X2Z1)+ * C = X3*(X1Z2-X2Z1)^2+ * Y4 = A+B-C+ * Z4 = Y1Z3x2*Z1Z2*Z2+ *+ * XZ1 is |p|, XZ2 is |r|, XZ3 is |s|, 'a' is 0.+ */+#define POINT_LADDER_POST_IMPL_A0(ptype, bits, field, suffixb) \+static void ptype##xz_ladder_post(ptype *p4, \+                                  const ptype##xz *r, const ptype##xz *s, \+                                  const ptype##xz *p, const vec##bits Y1) \+{ \+    vec##bits Z3x2, Y1Z3x2, Z1Z2, X1Z2, X2Z1, A, B, C; \+    bool_t s_inf; \+\+    add_##field(Z3x2, s->Z, s->Z);      /* Z3x2 = 2*Z3 */\+    mul_##field(Y1Z3x2, Y1, Z3x2);      /* Y1Z3x2 = Y1*Z3x2 */\+    mul_##field(Z1Z2, p->Z, r->Z);      /* Z1Z2 = Z1*Z2 */\+    mul_##field(X1Z2, p->X, r->Z);      /* X1Z2 = X1*Z2 */\+    mul_##field(X2Z1, r->X, p->Z);      /* X2Z1 = X2*Z1 */\+\+    mul_##field(p4->X, Y1Z3x2, r->X);   /* Y1Z3x2*X2 */\+    mul_##field(p4->X, p4->X, Z1Z2);    /* X4 = Y1Z3x2*X2*Z1Z2 */\+\+    sqr_##field(A, Z1Z2);               /* (Z1Z2)^2 */\+    mul_##field(B, A, Z3x2);            /* Z3x2*(Z1Z2)^2 */\+    mul_by_b_##suffixb(A, B);           /* A = b*Z3x2*(Z1Z2)^2 */\+\+    mul_##field(B, p->X, r->X);         /* [a*Z1Z2+]X1*X2 */\+    mul_##field(B, B, s->Z);            /* Z3*([a*Z1Z2+]X1*X2) */\+    add_##field(C, X1Z2, X2Z1);         /* X1Z2+X2Z1 */\+    mul_##field(B, B, C);               /* B = Z3*([a*Z2Z1+]X1*X2)*(X1Z2+X2Z1) */\+\+    sub_##field(C, X1Z2, X2Z1);         /* X1Z2-X2Z1 */\+    sqr_##field(C, C);                  /* (X1Z2-X2Z1)^2 */\+    mul_##field(C, C, s->X);            /* C = X3*(X1Z2-X2Z1)^2 */\+\+    add_##field(A, A, B);               /* A+B */\+    sub_##field(A, A, C);               /* Y4 = A+B-C */\+\+    mul_##field(p4->Z, Z1Z2, r->Z);     /* Z1Z2*Z2 */\+    mul_##field(p4->Z, p4->Z, Y1Z3x2);  /* Y1Z3x2*Z1Z2*Z2 */\+\+    s_inf = vec_is_zero(s->Z, sizeof(s->Z)); \+    vec_select(p4->X, p->X, p4->X, sizeof(p4->X), s_inf); \+    vec_select(p4->Y, Y1,   A,     sizeof(p4->Y), s_inf); \+    vec_select(p4->Z, p->Z, p4->Z, sizeof(p4->Z), s_inf); \+    ptype##_cneg(p4, s_inf); \+                                        /* to Jacobian */\+    mul_##field(p4->X, p4->X, p4->Z);   /* X4 = X4*Z4 */\+    sqr_##field(B, p4->Z);              \+    mul_##field(p4->Y, p4->Y, B);       /* Y4 = Y4*Z4^2 */\+}++#define POINT_IS_EQUAL_IMPL(ptype, bits, field) \+static limb_t ptype##_is_equal(const ptype *p1, const ptype *p2) \+{ \+    vec##bits Z1Z1, Z2Z2; \+    ptype##_affine a1, a2; \+    bool_t is_inf1 = vec_is_zero(p1->Z, sizeof(p1->Z)); \+    bool_t is_inf2 = vec_is_zero(p2->Z, sizeof(p2->Z)); \+\+    sqr_##field(Z1Z1, p1->Z);           /* Z1Z1 = Z1^2 */\+    sqr_##field(Z2Z2, p2->Z);           /* Z2Z2 = Z2^2 */\+\+    mul_##field(a1.X, p1->X, Z2Z2);     /* U1 = X1*Z2Z2 */\+    mul_##field(a2.X, p2->X, Z1Z1);     /* U2 = X2*Z1Z1 */\+\+    mul_##field(a1.Y, p1->Y, p2->Z);    /* Y1*Z2 */\+    mul_##field(a2.Y, p2->Y, p1->Z);    /* Y2*Z1 */\+\+    mul_##field(a1.Y, a1.Y, Z2Z2);      /* S1 = Y1*Z2*Z2Z2 */\+    mul_##field(a2.Y, a2.Y, Z1Z1);      /* S2 = Y2*Z1*Z1Z1 */\+\+    return vec_is_equal(&a1, &a2, sizeof(a1)) & (is_inf1 ^ is_inf2 ^ 1); \+}++/*+ * https://eprint.iacr.org/2015/1060, algorithm 7 with a twist to handle+ * |p3| pointing at either |p1| or |p2|. This is resolved by adding |t5|+ * and replacing few first references to |X3| in the formula, up to step+ * 21, with it. 12M[+27A], doubling and infinity are handled by the+ * formula itself. Infinity is to be encoded as [0, !0, 0].+ */+#define POINT_PROJ_DADD_IMPL_A0(ptype, bits, field, suffixb) \+static void ptype##proj_dadd(ptype##proj *p3, const ptype##proj *p1, \+                                              const ptype##proj *p2) \+{ \+    vec##bits t0, t1, t2, t3, t4, t5; \+\+    mul_##field(t0, p1->X, p2->X);      /* 1.     t0 = X1*X2 */\+    mul_##field(t1, p1->Y, p2->Y);      /* 2.     t1 = Y1*Y2 */\+    mul_##field(t2, p1->Z, p2->Z);      /* 3.     t2 = Z1*Z2 */\+    add_##field(t3, p1->X, p1->Y);      /* 4.     t3 = X1+Y1 */\+    add_##field(t4, p2->X, p2->Y);      /* 5.     t4 = X2+Y2 */\+    mul_##field(t3, t3, t4);            /* 6.     t3 = t3*t4 */\+    add_##field(t4, t0, t1);            /* 7.     t4 = t0+t1 */\+    sub_##field(t3, t3, t4);            /* 8.     t3 = t3-t4 */\+    add_##field(t4, p1->Y, p1->Z);      /* 9.     t4 = Y1+Z1 */\+    add_##field(t5, p2->Y, p2->Z);      /* 10.    t5 = Y2+Z2 */\+    mul_##field(t4, t4, t5);            /* 11.    t4 = t4*t5 */\+    add_##field(t5, t1, t2);            /* 12.    t5 = t1+t2 */\+    sub_##field(t4, t4, t5);            /* 13.    t4 = t4-t5 */\+    add_##field(t5, p1->X, p1->Z);      /* 14.    t5 = X1+Z1 */\+    add_##field(p3->Y, p2->X, p2->Z);   /* 15.    Y3 = X2+Z2 */\+    mul_##field(t5, t5, p3->Y);         /* 16.    t5 = t5*Y3 */\+    add_##field(p3->Y, t0, t2);         /* 17.    Y3 = t0+t2 */\+    sub_##field(p3->Y, t5, p3->Y);      /* 18.    Y3 = t5-Y3 */\+    mul_by_3_##field(t0, t0);           /* 19-20. t0 = 3*t0  */\+    mul_by_3_##field(t5, t2);           /* 21.    t5 = 3*t2  */\+    mul_by_b_##suffixb(t2, t5);         /* 21.    t2 = b*t5  */\+    add_##field(p3->Z, t1, t2);         /* 22.    Z3 = t1+t2 */\+    sub_##field(t1, t1, t2);            /* 23.    t1 = t1-t2 */\+    mul_by_3_##field(t5, p3->Y);        /* 24.    t5 = 3*Y3  */\+    mul_by_b_##suffixb(p3->Y, t5);      /* 24.    Y3 = b*t5  */\+    mul_##field(p3->X, t4, p3->Y);      /* 25.    X3 = t4*Y3 */\+    mul_##field(t2, t3, t1);            /* 26.    t2 = t3*t1 */\+    sub_##field(p3->X, t2, p3->X);      /* 27.    X3 = t2-X3 */\+    mul_##field(p3->Y, p3->Y, t0);      /* 28.    Y3 = Y3*t0 */\+    mul_##field(t1, t1, p3->Z);         /* 29.    t1 = t1*Z3 */\+    add_##field(p3->Y, t1, p3->Y);      /* 30.    Y3 = t1+Y3 */\+    mul_##field(t0, t0, t3);            /* 31.    t0 = t0*t3 */\+    mul_##field(p3->Z, p3->Z, t4);      /* 32.    Z3 = Z3*t4 */\+    add_##field(p3->Z, p3->Z, t0);      /* 33.    Z3 = Z3+t0 */\+}++/*+ * https://eprint.iacr.org/2015/1060, algorithm 8 with a twist to handle+ * |p2| being infinity encoded as [0, 0]. 11M[+21A].+ */+#define POINT_PROJ_DADD_AFFINE_IMPL_A0(ptype, bits, field, suffixb) \+static void ptype##proj_dadd_affine(ptype##proj *out, const ptype##proj *p1, \+                                                      const ptype##_affine *p2) \+{ \+    ptype##proj p3[1]; \+    vec##bits t0, t1, t2, t3, t4; \+    limb_t p2inf = vec_is_zero(p2, sizeof(*p2)); \+\+    mul_##field(t0, p1->X, p2->X);      /* 1.     t0 = X1*X2 */\+    mul_##field(t1, p1->Y, p2->Y);      /* 2.     t1 = Y1*Y2 */\+    add_##field(t3, p1->X, p1->Y);      /* 3.     t3 = X1+Y1 */\+    add_##field(t4, p2->X, p2->Y);      /* 4.     t4 = X2+Y2 */\+    mul_##field(t3, t3, t4);            /* 5.     t3 = t3*t4 */\+    add_##field(t4, t0, t1);            /* 6.     t4 = t0+t1 */\+    sub_##field(t3, t3, t4);            /* 7.     t3 = t3-t4 */\+    mul_##field(t4, p2->Y, p1->Z);      /* 8.     t4 = Y2*Z1 */\+    add_##field(t4, t4, p1->Y);         /* 9.     t4 = t4+Y1 */\+    mul_##field(p3->Y, p2->X, p1->Z);   /* 10.    Y3 = X2*Z1 */\+    add_##field(p3->Y, p3->Y, p1->X);   /* 11.    Y3 = Y3+X1 */\+    mul_by_3_##field(t0, t0);           /* 12-13. t0 = 3*t0  */\+    mul_by_b_##suffixb(t2, p1->Z);      /* 14.    t2 = b*Z1  */\+    mul_by_3_##field(t2, t2);           /* 14.    t2 = 3*t2  */\+    add_##field(p3->Z, t1, t2);         /* 15.    Z3 = t1+t2 */\+    sub_##field(t1, t1, t2);            /* 16.    t1 = t1-t2 */\+    mul_by_b_##suffixb(t2, p3->Y);      /* 17.    t2 = b*Y3  */\+    mul_by_3_##field(p3->Y, t2);        /* 17.    Y3 = 3*t2  */\+    mul_##field(p3->X, t4, p3->Y);      /* 18.    X3 = t4*Y3 */\+    mul_##field(t2, t3, t1);            /* 19.    t2 = t3*t1 */\+    sub_##field(p3->X, t2, p3->X);      /* 20.    X3 = t2-X3 */\+    mul_##field(p3->Y, p3->Y, t0);      /* 21.    Y3 = Y3*t0 */\+    mul_##field(t1, t1, p3->Z);         /* 22.    t1 = t1*Z3 */\+    add_##field(p3->Y, t1, p3->Y);      /* 23.    Y3 = t1+Y3 */\+    mul_##field(t0, t0, t3);            /* 24.    t0 = t0*t3 */\+    mul_##field(p3->Z, p3->Z, t4);      /* 25.    Z3 = Z3*t4 */\+    add_##field(p3->Z, p3->Z, t0);      /* 26.    Z3 = Z3+t0 */\+\+    vec_select(out, p1, p3, sizeof(*out), p2inf); \+}++/*+ * https://eprint.iacr.org/2015/1060, algorithm 9 with a twist to handle+ * |p3| pointing at |p1|. This is resolved by adding |t3| to hold X*Y+ * and reordering operations to bring references to |p1| forward.+ * 6M+2S[+13A].+ */+#define POINT_PROJ_DOUBLE_IMPL_A0(ptype, bits, field, suffixb) \+static void ptype##proj_double(ptype##proj *p3, const ptype##proj *p1) \+{ \+    vec##bits t0, t1, t2, t3; \+\+    sqr_##field(t0, p1->Y);             /* 1.     t0 = Y*Y   */\+    mul_##field(t1, p1->Y, p1->Z);      /* 5.     t1 = Y*Z   */\+    sqr_##field(t2, p1->Z);             /* 6.     t2 = Z*Z   */\+    mul_##field(t3, p1->X, p1->Y);      /* 16.    t3 = X*Y   */\+    lshift_##field(p3->Z, t0, 3);       /* 2-4.   Z3 = 8*t0  */\+    mul_by_b_##suffixb(p3->X, t2);      /* 7.     t2 = b*t2  */\+    mul_by_3_##field(t2, p3->X);        /* 7.     t2 = 3*t2  */\+    mul_##field(p3->X, t2, p3->Z);      /* 8.     X3 = t2*Z3 */\+    add_##field(p3->Y, t0, t2);         /* 9.     Y3 = t0+t2 */\+    mul_##field(p3->Z, t1, p3->Z);      /* 10.    Z3 = t1*Z3 */\+    mul_by_3_##field(t2, t2);           /* 11-12. t2 = 3*t2  */\+    sub_##field(t0, t0, t2);            /* 13.    t0 = t0-t2 */\+    mul_##field(p3->Y, t0, p3->Y);      /* 14.    Y3 = t0*Y3 */\+    add_##field(p3->Y, p3->X, p3->Y);   /* 15.    Y3 = X3+Y3 */\+    mul_##field(p3->X, t0, t3);         /* 17.    X3 = t0*t3 */\+    add_##field(p3->X, p3->X, p3->X);   /* 18.    X3 = X3+X3 */\+}++#define POINT_PROJ_TO_JACOBIAN_IMPL(ptype, bits, field) \+static void ptype##proj_to_Jacobian(ptype *out, const ptype##proj *in) \+{ \+    vec##bits ZZ; \+\+    sqr_##field(ZZ, in->Z); \+    mul_##field(out->X, in->X, in->Z); \+    mul_##field(out->Y, in->Y, ZZ); \+    vec_copy(out->Z, in->Z, sizeof(out->Z)); \+}++#define POINT_TO_PROJECTIVE_IMPL(ptype, bits, field, one) \+static void ptype##_to_projective(ptype##proj *out, const ptype *in) \+{ \+    vec##bits ZZ; \+    limb_t is_inf = vec_is_zero(in->Z, sizeof(in->Z)); \+\+    sqr_##field(ZZ, in->Z); \+    mul_##field(out->X, in->X, in->Z); \+    vec_select(out->Y, one, in->Y, sizeof(out->Y), is_inf); \+    mul_##field(out->Z, ZZ, in->Z); \+}++/******************* !!!!! NOT CONSTANT TIME !!!!! *******************/++/*+ * http://hyperelliptic.org/EFD/g1p/auto-shortw-xyzz.html#addition-add-2008-s+ * http://hyperelliptic.org/EFD/g1p/auto-shortw-xyzz.html#doubling-dbl-2008-s-1+ * with twist to handle either input at infinity. Addition costs 12M+2S,+ * while conditional doubling - 4M+6M+3S.+ */+#define POINTXYZZ_DADD_IMPL(ptype, bits, field) \+static void ptype##xyzz_dadd(ptype##xyzz *p3, const ptype##xyzz *p1, \+                                              const ptype##xyzz *p2) \+{ \+    vec##bits U, S, P, R; \+\+    if (vec_is_zero(p2->ZZZ, 2*sizeof(p2->ZZZ))) { \+        vec_copy(p3, p1, sizeof(*p3));  \+        return; \+    } else if (vec_is_zero(p1->ZZZ, 2*sizeof(p1->ZZZ))) { \+        vec_copy(p3, p2, sizeof(*p3));  \+        return; \+    } \+\+    mul_##field(U, p1->X, p2->ZZ);              /* U1 = X1*ZZ2 */\+    mul_##field(S, p1->Y, p2->ZZZ);             /* S1 = Y1*ZZZ2 */\+    mul_##field(P, p2->X, p1->ZZ);              /* U2 = X2*ZZ1 */\+    mul_##field(R, p2->Y, p1->ZZZ);             /* S2 = Y2*ZZZ1 */\+    sub_##field(P, P, U);                       /* P = U2-U1 */\+    sub_##field(R, R, S);                       /* R = S2-S1 */\+\+    if (!vec_is_zero(P, sizeof(P))) {           /* X1!=X2 */\+        vec##bits PP, PPP, Q;                   /* add |p1| and |p2| */\+\+        sqr_##field(PP, P);                     /* PP = P^2 */\+        mul_##field(PPP, PP, P);                /* PPP = P*PP */\+        mul_##field(Q, U, PP);                  /* Q = U1*PP */\+        sqr_##field(p3->X, R);                  /* R^2 */\+        add_##field(P, Q, Q); \+        sub_##field(p3->X, p3->X, PPP);         /* R^2-PPP */\+        sub_##field(p3->X, p3->X, P);           /* X3 = R^2-PPP-2*Q */\+        sub_##field(Q, Q, p3->X); \+        mul_##field(Q, Q, R);                   /* R*(Q-X3) */\+        mul_##field(p3->Y, S, PPP);             /* S1*PPP */\+        sub_##field(p3->Y, Q, p3->Y);           /* Y3 = R*(Q-X3)-S1*PPP */\+        mul_##field(p3->ZZ, p1->ZZ, p2->ZZ);    /* ZZ1*ZZ2 */\+        mul_##field(p3->ZZZ, p1->ZZZ, p2->ZZZ); /* ZZZ1*ZZZ2 */\+        mul_##field(p3->ZZ, p3->ZZ, PP);        /* ZZ3 = ZZ1*ZZ2*PP */\+        mul_##field(p3->ZZZ, p3->ZZZ, PPP);     /* ZZZ3 = ZZZ1*ZZZ2*PPP */\+    } else if (vec_is_zero(R, sizeof(R))) {     /* X1==X2 && Y1==Y2 */\+        vec##bits V, W, M;                      /* double |p1| */\+\+        add_##field(U, p1->Y, p1->Y);           /* U = 2*Y1 */\+        sqr_##field(V, U);                      /* V = U^2 */\+        mul_##field(W, V, U);                   /* W = U*V */\+        mul_##field(S, p1->X, V);               /* S = X1*V */\+        sqr_##field(M, p1->X); \+        mul_by_3_##field(M, M);                 /* M = 3*X1^2[+a*ZZ1^2] */\+        sqr_##field(p3->X, M); \+        add_##field(U, S, S);                   /* 2*S */\+        sub_##field(p3->X, p3->X, U);           /* X3 = M^2-2*S */\+        mul_##field(p3->Y, W, p1->Y);           /* W*Y1 */\+        sub_##field(S, S, p3->X); \+        mul_##field(S, S, M);                   /* M*(S-X3) */\+        sub_##field(p3->Y, S, p3->Y);           /* Y3 = M*(S-X3)-W*Y1 */\+        mul_##field(p3->ZZ, p1->ZZ, V);         /* ZZ3 = V*ZZ1 */\+        mul_##field(p3->ZZZ, p1->ZZZ, W);       /* ZZ3 = W*ZZZ1 */\+    } else {                                    /* X1==X2 && Y1==-Y2 */\+        vec_zero(p3->ZZZ, 2*sizeof(p3->ZZZ));   /* set |p3| to infinity */\+    } \+}++/*+ * http://hyperelliptic.org/EFD/g1p/auto-shortw-xyzz.html#addition-madd-2008-s+ * http://hyperelliptic.org/EFD/g1p/auto-shortw-xyzz.html#doubling-mdbl-2008-s-1+ * with twists to handle even subtractions and either input at infinity.+ * Addition costs 8M+2S, while conditional doubling - 2M+4M+3S.+ */+#define POINTXYZZ_DADD_AFFINE_IMPL(ptype, bits, field, one) \+static void ptype##xyzz_dadd_affine(ptype##xyzz *p3, const ptype##xyzz *p1, \+                                                     const ptype##_affine *p2, \+                                                     bool_t subtract) \+{ \+    vec##bits P, R; \+\+    if (vec_is_zero(p2, sizeof(*p2))) { \+        vec_copy(p3, p1, sizeof(*p3));  \+        return; \+    } else if (vec_is_zero(p1->ZZZ, 2*sizeof(p1->ZZZ))) { \+        vec_copy(p3->X, p2->X, 2*sizeof(p3->X));\+        cneg_##field(p3->ZZZ, one, subtract);   \+        vec_copy(p3->ZZ, one, sizeof(p3->ZZ));  \+        return; \+    } \+\+    mul_##field(P, p2->X, p1->ZZ);              /* U2 = X2*ZZ1 */\+    mul_##field(R, p2->Y, p1->ZZZ);             /* S2 = Y2*ZZZ1 */\+    cneg_##field(R, R, subtract); \+    sub_##field(P, P, p1->X);                   /* P = U2-X1 */\+    sub_##field(R, R, p1->Y);                   /* R = S2-Y1 */\+\+    if (!vec_is_zero(P, sizeof(P))) {           /* X1!=X2 */\+        vec##bits PP, PPP, Q;                   /* add |p2| to |p1| */\+\+        sqr_##field(PP, P);                     /* PP = P^2 */\+        mul_##field(PPP, PP, P);                /* PPP = P*PP */\+        mul_##field(Q, p1->X, PP);              /* Q = X1*PP */\+        sqr_##field(p3->X, R);                  /* R^2 */\+        add_##field(P, Q, Q); \+        sub_##field(p3->X, p3->X, PPP);         /* R^2-PPP */\+        sub_##field(p3->X, p3->X, P);           /* X3 = R^2-PPP-2*Q */\+        sub_##field(Q, Q, p3->X); \+        mul_##field(Q, Q, R);                   /* R*(Q-X3) */\+        mul_##field(p3->Y, p1->Y, PPP);         /* Y1*PPP */\+        sub_##field(p3->Y, Q, p3->Y);           /* Y3 = R*(Q-X3)-Y1*PPP */\+        mul_##field(p3->ZZ, p1->ZZ, PP);        /* ZZ3 = ZZ1*PP */\+        mul_##field(p3->ZZZ, p1->ZZZ, PPP);     /* ZZZ3 = ZZZ1*PPP */\+    } else if (vec_is_zero(R, sizeof(R))) {     /* X1==X2 && Y1==Y2 */\+        vec##bits U, S, M;                      /* double |p2| */\+\+        add_##field(U, p2->Y, p2->Y);           /* U = 2*Y1 */\+        sqr_##field(p3->ZZ, U);                 /* [ZZ3 =] V = U^2 */\+        mul_##field(p3->ZZZ, p3->ZZ, U);        /* [ZZZ3 =] W = U*V */\+        mul_##field(S, p2->X, p3->ZZ);          /* S = X1*V */\+        sqr_##field(M, p2->X); \+        mul_by_3_##field(M, M);                 /* M = 3*X1^2[+a] */\+        sqr_##field(p3->X, M); \+        add_##field(U, S, S);                   /* 2*S */\+        sub_##field(p3->X, p3->X, U);           /* X3 = M^2-2*S */\+        mul_##field(p3->Y, p3->ZZZ, p2->Y);     /* W*Y1 */\+        sub_##field(S, S, p3->X); \+        mul_##field(S, S, M);                   /* M*(S-X3) */\+        sub_##field(p3->Y, S, p3->Y);           /* Y3 = M*(S-X3)-W*Y1 */\+        cneg_##field(p3->ZZZ, p3->ZZZ, subtract); \+    } else {                                    /* X1==X2 && Y1==-Y2 */\+        vec_zero(p3->ZZZ, 2*sizeof(p3->ZZZ));   /* set |p3| to infinity */\+    } \+}++#define POINTXYZZ_TO_JACOBIAN_IMPL(ptype, bits, field) \+static void ptype##xyzz_to_Jacobian(ptype *out, const ptype##xyzz *in) \+{ \+    mul_##field(out->X, in->X, in->ZZ); \+    mul_##field(out->Y, in->Y, in->ZZZ); \+    vec_copy(out->Z, in->ZZ, sizeof(out->Z)); \+}++#define POINT_TO_XYZZ_IMPL(ptype, bits, field) \+static void ptype##_to_xyzz(ptype##xyzz *out, const ptype *in) \+{ \+    vec_copy(out->X, in->X, 2*sizeof(out->X)); \+    sqr_##field(out->ZZ, in->Z); \+    mul_##field(out->ZZZ, out->ZZ, in->Z); \+}++#endif
+ vendor/external/blst/src/errors.h view
@@ -0,0 +1,19 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLS12_381_ASM_ERRORS_H__+#define __BLS12_381_ASM_ERRORS_H__++typedef enum {+    BLST_SUCCESS = 0,+    BLST_BAD_ENCODING,+    BLST_POINT_NOT_ON_CURVE,+    BLST_POINT_NOT_IN_GROUP,+    BLST_AGGR_TYPE_MISMATCH,+    BLST_VERIFY_FAIL,+    BLST_PK_IS_INFINITY,+} BLST_ERROR;++#endif
+ vendor/external/blst/src/exp.c view
@@ -0,0 +1,55 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "vect.h"++/*+ * |out| = |inp|^|pow|, small footprint, public exponent+ */+static void exp_mont_384(vec384 out, const vec384 inp, const byte *pow,+                         size_t pow_bits, const vec384 p, limb_t n0)+{+#if 1+    vec384 ret;++    vec_copy(ret, inp, sizeof(ret));  /* ret = inp^1 */+    --pow_bits; /* most significant bit is set, skip over */+    while (pow_bits--) {+        sqr_mont_384(ret, ret, p, n0);+        if (is_bit_set(pow, pow_bits))+            mul_mont_384(ret, ret, inp, p, n0);+    }+    vec_copy(out, ret, sizeof(ret));  /* out = ret */+#else+    unsigned int i;+    vec384 sqr;++    vec_copy(sqr, inp, sizeof(sqr));+    for (i = 0; !is_bit_set(pow, i++);)+        sqr_mont_384(sqr, sqr, sqr, p, n0);+    vec_copy(out, sqr, sizeof(sqr));+    for (; i < pow_bits; i++) {+        sqr_mont_384(sqr, sqr, sqr, p, n0);+        if (is_bit_set(pow, i))+            mul_mont_384(out, out, sqr, p, n0);+    }+#endif+}++static void exp_mont_384x(vec384x out, const vec384x inp, const byte *pow,+                          size_t pow_bits, const vec384 p, limb_t n0)+{+    vec384x ret;++    vec_copy(ret, inp, sizeof(ret));  /* |ret| = |inp|^1 */+    --pow_bits; /* most significant bit is accounted for, skip over */+    while (pow_bits--) {+        sqr_mont_384x(ret, ret, p, n0);+        if (is_bit_set(pow, pow_bits))+            mul_mont_384x(ret, ret, inp, p, n0);+    }+    vec_copy(out, ret, sizeof(ret));  /* |out| = |ret| */+}
+ vendor/external/blst/src/exports.c view
@@ -0,0 +1,583 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+/*+ * Why this file? Overall goal is to ensure that all internal calls+ * remain internal after linking application. This is to both+ *+ * a) minimize possibility of external name conflicts (since all+ *    non-blst-prefixed and [assembly subroutines] remain static);+ * b) preclude possibility of unintentional internal reference+ *    overload in shared library context (one can achieve same+ *    effect with -Bsymbolic, but we don't want to rely on end-user+ *    to remember to use it);+ */++#include "fields.h"+#include "bytes.h"++/*+ * BLS12-381-specific Fr shortcuts to assembly.+ */+void blst_fr_add(vec256 ret, const vec256 a, const vec256 b)+{   add_mod_256(ret, a, b, BLS12_381_r);   }++void blst_fr_sub(vec256 ret, const vec256 a, const vec256 b)+{   sub_mod_256(ret, a, b, BLS12_381_r);   }++void blst_fr_mul_by_3(vec256 ret, const vec256 a)+{   mul_by_3_mod_256(ret, a, BLS12_381_r);   }++void blst_fr_lshift(vec256 ret, const vec256 a, size_t count)+{   lshift_mod_256(ret, a, count, BLS12_381_r);   }++void blst_fr_rshift(vec256 ret, const vec256 a, size_t count)+{   rshift_mod_256(ret, a, count, BLS12_381_r);   }++void blst_fr_mul(vec256 ret, const vec256 a, const vec256 b)+{   mul_mont_sparse_256(ret, a, b, BLS12_381_r, r0);   }++void blst_fr_ct_bfly(vec256 x0, vec256 x1, const vec256 twiddle)+{+    vec256 x2;++    mul_mont_sparse_256(x2, x1, twiddle, BLS12_381_r, r0);+    sub_mod_256(x1, x0, x2, BLS12_381_r);+    add_mod_256(x0, x0, x2, BLS12_381_r);+}++void blst_fr_gs_bfly(vec256 x0, vec256 x1, const vec256 twiddle)+{+    vec256 x2;++    sub_mod_256(x2, x0, x1, BLS12_381_r);+    add_mod_256(x0, x0, x1, BLS12_381_r);+    mul_mont_sparse_256(x1, x2, twiddle, BLS12_381_r, r0);+}++void blst_fr_sqr(vec256 ret, const vec256 a)+{   sqr_mont_sparse_256(ret, a, BLS12_381_r, r0);   }++void blst_fr_cneg(vec256 ret, const vec256 a, int flag)+{   cneg_mod_256(ret, a, is_zero(flag) ^ 1, BLS12_381_r);   }++void blst_fr_to(vec256 ret, const vec256 a)+{   mul_mont_sparse_256(ret, a, BLS12_381_rRR, BLS12_381_r, r0);   }++void blst_fr_from(vec256 ret, const vec256 a)+{   from_mont_256(ret, a, BLS12_381_r, r0);   }++void blst_fr_from_scalar(vec256 ret, const pow256 a)+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };++    if ((uptr_t)ret == (uptr_t)a && is_endian.little) {+        mul_mont_sparse_256(ret, (const limb_t *)a, BLS12_381_rRR,+                                                    BLS12_381_r, r0);+    } else {+        vec256 out;+        limbs_from_le_bytes(out, a, 32);+        mul_mont_sparse_256(ret, out, BLS12_381_rRR, BLS12_381_r, r0);+        vec_zero(out, sizeof(out));+    }+}++void blst_scalar_from_fr(pow256 ret, const vec256 a)+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };++    if ((uptr_t)ret == (uptr_t)a && is_endian.little) {+        from_mont_256((limb_t *)ret, a, BLS12_381_r, r0);+    } else {+        vec256 out;+        from_mont_256(out, a, BLS12_381_r, r0);+        le_bytes_from_limbs(ret, out, 32);+        vec_zero(out, sizeof(out));+    }+}++int blst_scalar_fr_check(const pow256 a)+{   return (int)(check_mod_256(a, BLS12_381_r) |+                 bytes_are_zero(a, sizeof(pow256)));+}++int blst_sk_check(const pow256 a)+{   return (int)check_mod_256(a, BLS12_381_r);   }++int blst_sk_add_n_check(pow256 ret, const pow256 a, const pow256 b)+{   return (int)add_n_check_mod_256(ret, a, b, BLS12_381_r);   }++int blst_sk_sub_n_check(pow256 ret, const pow256 a, const pow256 b)+{   return (int)sub_n_check_mod_256(ret, a, b, BLS12_381_r);   }++int blst_sk_mul_n_check(pow256 ret, const pow256 a, const pow256 b)+{+    vec256 t[2];+    const union {+        long one;+        char little;+    } is_endian = { 1 };+    bool_t is_zero;++    if (((size_t)a|(size_t)b)%sizeof(limb_t) != 0 || !is_endian.little) {+        limbs_from_le_bytes(t[0], a, sizeof(pow256));+        limbs_from_le_bytes(t[1], b, sizeof(pow256));+        a = (const byte *)t[0];+        b = (const byte *)t[1];+    }+    mul_mont_sparse_256(t[0], BLS12_381_rRR, (const limb_t *)a, BLS12_381_r, r0);+    mul_mont_sparse_256(t[0], t[0], (const limb_t *)b, BLS12_381_r, r0);+    le_bytes_from_limbs(ret, t[0], sizeof(pow256));+    is_zero = vec_is_zero(t[0], sizeof(vec256));+    vec_zero(t, sizeof(t));++    return (int)(is_zero^1);+}++void blst_sk_inverse(pow256 ret, const pow256 a)+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };++    if (((size_t)a|(size_t)ret)%sizeof(limb_t) == 0 && is_endian.little) {+        limb_t *out = (limb_t *)ret;+        mul_mont_sparse_256(out, (const limb_t *)a, BLS12_381_rRR,+                                                    BLS12_381_r, r0);+        reciprocal_fr(out, out);+        from_mont_256(out, out, BLS12_381_r, r0);+    } else {+        vec256 out;+        limbs_from_le_bytes(out, a, 32);+        mul_mont_sparse_256(out, out, BLS12_381_rRR, BLS12_381_r, r0);+        reciprocal_fr(out, out);+        from_mont_256(out, out, BLS12_381_r, r0);+        le_bytes_from_limbs(ret, out, 32);+        vec_zero(out, sizeof(out));+    }+}++/*+ * BLS12-381-specific Fp shortcuts to assembly.+ */+void blst_fp_add(vec384 ret, const vec384 a, const vec384 b)+{   add_fp(ret, a, b);   }++void blst_fp_sub(vec384 ret, const vec384 a, const vec384 b)+{   sub_fp(ret, a, b);   }++void blst_fp_mul_by_3(vec384 ret, const vec384 a)+{   mul_by_3_fp(ret, a);   }++void blst_fp_mul_by_8(vec384 ret, const vec384 a)+{   mul_by_8_fp(ret, a);   }++void blst_fp_lshift(vec384 ret, const vec384 a, size_t count)+{   lshift_fp(ret, a, count);   }++void blst_fp_mul(vec384 ret, const vec384 a, const vec384 b)+{   mul_fp(ret, a, b);   }++void blst_fp_sqr(vec384 ret, const vec384 a)+{   sqr_fp(ret, a);   }++void blst_fp_cneg(vec384 ret, const vec384 a, int flag)+{   cneg_fp(ret, a, is_zero(flag) ^ 1);   }++void blst_fp_to(vec384 ret, const vec384 a)+{   mul_fp(ret, a, BLS12_381_RR);   }++void blst_fp_from(vec384 ret, const vec384 a)+{   from_fp(ret, a);   }++/*+ * Fp serialization/deserialization.+ */+void blst_fp_from_uint32(vec384 ret, const unsigned int a[12])+{+    if (sizeof(limb_t) == 8) {+        int i;+        for (i = 0; i < 6; i++)+            ret[i] = a[2*i] | ((limb_t)a[2*i+1] << (32 & (8*sizeof(limb_t)-1)));+        a = (const unsigned int *)ret;+    }+    mul_fp(ret, (const limb_t *)a, BLS12_381_RR);+}++void blst_uint32_from_fp(unsigned int ret[12], const vec384 a)+{+    if (sizeof(limb_t) == 4) {+        from_fp((limb_t *)ret, a);+    } else {+        vec384 out;+        int i;++        from_fp(out, a);+        for (i = 0; i < 6; i++) {+            limb_t limb = out[i];+            ret[2*i]   = (unsigned int)limb;+            ret[2*i+1] = (unsigned int)(limb >> (32 & (8*sizeof(limb_t)-1)));+        }+    }+}++void blst_fp_from_uint64(vec384 ret, const unsigned long long a[6])+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };++    if (sizeof(limb_t) == 4 && !is_endian.little) {+        int i;+        for (i = 0; i < 6; i++) {+            unsigned long long limb = a[i];+            ret[2*i]   = (limb_t)limb;+            ret[2*i+1] = (limb_t)(limb >> 32);+        }+        a = (const unsigned long long *)ret;+    }+    mul_fp(ret, (const limb_t *)a, BLS12_381_RR);+}++void blst_uint64_from_fp(unsigned long long ret[6], const vec384 a)+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };++    if (sizeof(limb_t) == 8 || is_endian.little) {+        from_fp((limb_t *)ret, a);+    } else {+        vec384 out;+        int i;++        from_fp(out, a);+        for (i = 0; i < 6; i++)+            ret[i] = out[2*i] | ((unsigned long long)out[2*i+1] << 32);+    }+}++void blst_fp_from_bendian(vec384 ret, const unsigned char a[48])+{+    vec384 out;++    limbs_from_be_bytes(out, a, sizeof(vec384));+    mul_fp(ret, out, BLS12_381_RR);+}++void blst_bendian_from_fp(unsigned char ret[48], const vec384 a)+{+    vec384 out;++    from_fp(out, a);+    be_bytes_from_limbs(ret, out, sizeof(vec384));+}++void blst_fp_from_lendian(vec384 ret, const unsigned char a[48])+{+    vec384 out;++    limbs_from_le_bytes(out, a, sizeof(vec384));+    mul_fp(ret, out, BLS12_381_RR);+}++void blst_lendian_from_fp(unsigned char ret[48], const vec384 a)+{+    vec384 out;++    from_fp(out, a);+    le_bytes_from_limbs(ret, out, sizeof(vec384));+}++/*+ * BLS12-381-specific Fp2 shortcuts to assembly.+ */+void blst_fp2_add(vec384x ret, const vec384x a, const vec384x b)+{   add_fp2(ret, a, b);   }++void blst_fp2_sub(vec384x ret, const vec384x a, const vec384x b)+{   sub_fp2(ret, a, b);   }++void blst_fp2_mul_by_3(vec384x ret, const vec384x a)+{   mul_by_3_fp2(ret, a);   }++void blst_fp2_mul_by_8(vec384x ret, const vec384x a)+{   mul_by_8_fp2(ret, a);   }++void blst_fp2_lshift(vec384x ret, const vec384x a, size_t count)+{   lshift_fp2(ret, a, count);    }++void blst_fp2_mul(vec384x ret, const vec384x a, const vec384x b)+{   mul_fp2(ret, a, b);   }++void blst_fp2_sqr(vec384x ret, const vec384x a)+{   sqr_fp2(ret, a);   }++void blst_fp2_cneg(vec384x ret, const vec384x a, int flag)+{   cneg_fp2(ret, a, is_zero(flag) ^ 1);   }++/*+ * Scalar serialization/deserialization.+ */+void blst_scalar_from_uint32(pow256 ret, const unsigned int a[8])+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };+    size_t i;++    if ((uptr_t)ret==(uptr_t)a && is_endian.little)+        return;++    for(i = 0; i < 8; i++) {+        unsigned int w = a[i];+        *ret++ = (byte)w;+        *ret++ = (byte)(w >> 8);+        *ret++ = (byte)(w >> 16);+        *ret++ = (byte)(w >> 24);+    }+}++void blst_uint32_from_scalar(unsigned int ret[8], const pow256 a)+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };+    size_t i;++    if ((uptr_t)ret==(uptr_t)a && is_endian.little)+        return;++    for(i = 0; i < 8; i++) {+        unsigned int w = (unsigned int)(*a++);+        w |= (unsigned int)(*a++) << 8;+        w |= (unsigned int)(*a++) << 16;+        w |= (unsigned int)(*a++) << 24;+        ret[i] = w;+    }+}++void blst_scalar_from_uint64(pow256 ret, const unsigned long long a[4])+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };+    size_t i;++    if ((uptr_t)ret==(uptr_t)a && is_endian.little)+        return;++    for(i = 0; i < 4; i++) {+        unsigned long long w = a[i];+        *ret++ = (byte)w;+        *ret++ = (byte)(w >> 8);+        *ret++ = (byte)(w >> 16);+        *ret++ = (byte)(w >> 24);+        *ret++ = (byte)(w >> 32);+        *ret++ = (byte)(w >> 40);+        *ret++ = (byte)(w >> 48);+        *ret++ = (byte)(w >> 56);+    }+}++void blst_uint64_from_scalar(unsigned long long ret[4], const pow256 a)+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };+    size_t i;++    if ((uptr_t)ret==(uptr_t)a && is_endian.little)+        return;++    for(i = 0; i < 4; i++) {+        unsigned long long w = (unsigned long long)(*a++);+        w |= (unsigned long long)(*a++) << 8;+        w |= (unsigned long long)(*a++) << 16;+        w |= (unsigned long long)(*a++) << 24;+        w |= (unsigned long long)(*a++) << 32;+        w |= (unsigned long long)(*a++) << 40;+        w |= (unsigned long long)(*a++) << 48;+        w |= (unsigned long long)(*a++) << 56;+        ret[i] = w;+    }+}++void blst_scalar_from_bendian(pow256 ret, const unsigned char a[32])+{+    vec256 out;+    limbs_from_be_bytes(out, a, sizeof(out));+    le_bytes_from_limbs(ret, out, sizeof(out));+    vec_zero(out, sizeof(out));+}++void blst_bendian_from_scalar(unsigned char ret[32], const pow256 a)+{+    vec256 out;+    limbs_from_le_bytes(out, a, sizeof(out));+    be_bytes_from_limbs(ret, out, sizeof(out));+    vec_zero(out, sizeof(out));+}++void blst_scalar_from_lendian(pow256 ret, const unsigned char a[32])+{+    size_t i;++    if ((uptr_t)ret==(uptr_t)a)+        return;++    for (i = 0; i < 32; i++)+        ret[i] = a[i];+}++void blst_lendian_from_scalar(unsigned char ret[32], const pow256 a)+{+    size_t i;++    if ((uptr_t)ret==(uptr_t)a)+        return;++    for (i = 0; i < 32; i++)+        ret[i] = a[i];+}++void blst_fr_from_uint64(vec256 ret, const unsigned long long a[4])+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };++    if (sizeof(limb_t) == 4 && !is_endian.little) {+        int i;+        for (i = 0; i < 4; i++) {+            unsigned long long limb = a[i];+            ret[2*i]   = (limb_t)limb;+            ret[2*i+1] = (limb_t)(limb >> 32);+        }+        a = (const unsigned long long *)ret;+    }+    mul_mont_sparse_256(ret, (const limb_t *)a, BLS12_381_rRR, BLS12_381_r, r0);+}++void blst_uint64_from_fr(unsigned long long ret[4], const vec256 a)+{+    const union {+        long one;+        char little;+    } is_endian = { 1 };++    if (sizeof(limb_t) == 8 || is_endian.little) {+        from_mont_256((limb_t *)ret, a, BLS12_381_r, r0);+    } else {+        vec256 out;+        int i;++        from_mont_256(out, a, BLS12_381_r, r0);+        for (i = 0; i < 4; i++)+            ret[i] = out[2*i] | ((unsigned long long)out[2*i+1] << 32);+        vec_zero(out, sizeof(out));+    }+}++int blst_scalar_from_le_bytes(pow256 out, const unsigned char *bytes, size_t n)+{+    size_t rem = (n - 1) % 32 + 1;+    struct { vec256 out, digit; } t;+    limb_t ret;++    vec_zero(t.out, sizeof(t.out));++    n -= rem;+    limbs_from_le_bytes(t.out, bytes += n, rem);+    mul_mont_sparse_256(t.out, BLS12_381_rRR, t.out, BLS12_381_r, r0);++    while (n) {+        limbs_from_le_bytes(t.digit, bytes -= 32, 32);+        add_mod_256(t.out, t.out, t.digit, BLS12_381_r);+        mul_mont_sparse_256(t.out, BLS12_381_rRR, t.out, BLS12_381_r, r0);+        n -= 32;+    }++    from_mont_256(t.out, t.out, BLS12_381_r, r0);++    ret = vec_is_zero(t.out, sizeof(t.out));+    le_bytes_from_limbs(out, t.out, 32);+    vec_zero(&t, sizeof(t));++    return (int)(ret^1);+}++int blst_scalar_from_be_bytes(pow256 out, const unsigned char *bytes, size_t n)+{+    size_t rem = (n - 1) % 32 + 1;+    struct { vec256 out, digit; } t;+    limb_t ret;++    vec_zero(t.out, sizeof(t.out));++    limbs_from_be_bytes(t.out, bytes, rem);+    mul_mont_sparse_256(t.out, BLS12_381_rRR, t.out, BLS12_381_r, r0);++    while (n -= rem) {+        limbs_from_be_bytes(t.digit, bytes += rem, 32);+        add_mod_256(t.out, t.out, t.digit, BLS12_381_r);+        mul_mont_sparse_256(t.out, BLS12_381_rRR, t.out, BLS12_381_r, r0);+        rem = 32;+    }++    from_mont_256(t.out, t.out, BLS12_381_r, r0);++    ret = vec_is_zero(t.out, sizeof(t.out));+    le_bytes_from_limbs(out, t.out, 32);+    vec_zero(&t, sizeof(t));++    return (int)(ret^1);+}++/*+ * Single-short SHA-256 hash function.+ */+#include "sha256.h"++void blst_sha256(unsigned char md[32], const void *msg, size_t len)+{+    SHA256_CTX ctx;++    sha256_init(&ctx);+    sha256_update(&ctx, msg, len);+    sha256_final(md, &ctx);+}++/*+ * Test facilitator.+ */+void blst_scalar_from_hexascii(pow256 ret, const char *hex)+{   bytes_from_hexascii(ret, sizeof(pow256), hex);   }++void blst_fr_from_hexascii(vec256 ret, const char *hex)+{+    limbs_from_hexascii(ret, sizeof(vec256), hex);+    mul_mont_sparse_256(ret, ret, BLS12_381_rRR, BLS12_381_r, r0);+}++void blst_fp_from_hexascii(vec384 ret, const char *hex)+{+    limbs_from_hexascii(ret, sizeof(vec384), hex);+    mul_fp(ret, ret, BLS12_381_RR);+}
+ vendor/external/blst/src/fields.h view
@@ -0,0 +1,116 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLS12_381_ASM_FIELDS_H__+#define __BLS12_381_ASM_FIELDS_H__++#include "vect.h"+#include "consts.h"++/*+ * BLS12-381-specific Fp shortcuts to assembly.+ */+static inline void add_fp(vec384 ret, const vec384 a, const vec384 b)+{   add_mod_384(ret, a, b, BLS12_381_P);   }++static inline void sub_fp(vec384 ret, const vec384 a, const vec384 b)+{   sub_mod_384(ret, a, b, BLS12_381_P);   }++static inline void mul_by_3_fp(vec384 ret, const vec384 a)+{   mul_by_3_mod_384(ret, a, BLS12_381_P);   }++static inline void mul_by_8_fp(vec384 ret, const vec384 a)+{   mul_by_8_mod_384(ret, a, BLS12_381_P);   }++static inline void lshift_fp(vec384 ret, const vec384 a, size_t count)+{   lshift_mod_384(ret, a, count, BLS12_381_P);   }++static inline void rshift_fp(vec384 ret, const vec384 a, size_t count)+{   rshift_mod_384(ret, a, count, BLS12_381_P);   }++static inline void div_by_2_fp(vec384 ret, const vec384 a)+{   div_by_2_mod_384(ret, a, BLS12_381_P);   }++static inline void mul_fp(vec384 ret, const vec384 a, const vec384 b)+{   mul_mont_384(ret, a, b, BLS12_381_P, p0);   }++static inline void sqr_fp(vec384 ret, const vec384 a)+{   sqr_mont_384(ret, a, BLS12_381_P, p0);   }++static inline void cneg_fp(vec384 ret, const vec384 a, bool_t flag)+{   cneg_mod_384(ret, a, flag, BLS12_381_P);   }++static inline void from_fp(vec384 ret, const vec384 a)+{   from_mont_384(ret, a, BLS12_381_P, p0);   }++static inline void redc_fp(vec384 ret, const vec768 a)+{   redc_mont_384(ret, a, BLS12_381_P, p0);   }++/*+ * BLS12-381-specific Fp2 shortcuts to assembly.+ */+static inline void add_fp2(vec384x ret, const vec384x a, const vec384x b)+{   add_mod_384x(ret, a, b, BLS12_381_P);   }++static inline void sub_fp2(vec384x ret, const vec384x a, const vec384x b)+{   sub_mod_384x(ret, a, b, BLS12_381_P);   }++static inline void mul_by_3_fp2(vec384x ret, const vec384x a)+{   mul_by_3_mod_384x(ret, a, BLS12_381_P);   }++static inline void mul_by_8_fp2(vec384x ret, const vec384x a)+{   mul_by_8_mod_384x(ret, a, BLS12_381_P);   }++static inline void lshift_fp2(vec384x ret, const vec384x a, size_t count)+{+    lshift_mod_384(ret[0], a[0], count, BLS12_381_P);+    lshift_mod_384(ret[1], a[1], count, BLS12_381_P);+}++static inline void mul_fp2(vec384x ret, const vec384x a, const vec384x b)+{   mul_mont_384x(ret, a, b, BLS12_381_P, p0);   }++static inline void sqr_fp2(vec384x ret, const vec384x a)+{   sqr_mont_384x(ret, a, BLS12_381_P, p0);   }++static inline void cneg_fp2(vec384x ret, const vec384x a, bool_t flag)+{+    cneg_mod_384(ret[0], a[0], flag, BLS12_381_P);+    cneg_mod_384(ret[1], a[1], flag, BLS12_381_P);+}++#define vec_load_global vec_copy++static void reciprocal_fp(vec384 out, const vec384 inp);+static void flt_reciprocal_fp(vec384 out, const vec384 inp);+static bool_t recip_sqrt_fp(vec384 out, const vec384 inp);+static bool_t sqrt_fp(vec384 out, const vec384 inp);++static void reciprocal_fp2(vec384x out, const vec384x inp);+static void flt_reciprocal_fp2(vec384x out, const vec384x inp);+static bool_t recip_sqrt_fp2(vec384x out, const vec384x inp,+                             const vec384x recip_ZZZ, const vec384x magic_ZZZ);+static bool_t sqrt_fp2(vec384x out, const vec384x inp);+static bool_t sqrt_align_fp2(vec384x out, const vec384x ret,+                             const vec384x sqrt, const vec384x inp);++typedef vec384x   vec384fp2;+typedef vec384fp2 vec384fp6[3];+typedef vec384fp6 vec384fp12[2];++static void sqr_fp12(vec384fp12 ret, const vec384fp12 a);+static void cyclotomic_sqr_fp12(vec384fp12 ret, const vec384fp12 a);+static void mul_fp12(vec384fp12 ret, const vec384fp12 a, const vec384fp12 b);+static void mul_by_xy00z0_fp12(vec384fp12 ret, const vec384fp12 a,+                                               const vec384fp6 xy00z0);+static void conjugate_fp12(vec384fp12 a);+static void inverse_fp12(vec384fp12 ret, const vec384fp12 a);+/* caveat lector! |n| has to be non-zero and not more than 3! */+static void frobenius_map_fp12(vec384fp12 ret, const vec384fp12 a, size_t n);++#define neg_fp(r,a) cneg_fp((r),(a),1)+#define neg_fp2(r,a) cneg_fp2((r),(a),1)++#endif /* __BLS12_381_ASM_FIELDS_H__ */
+ vendor/external/blst/src/fp12_tower.c view
@@ -0,0 +1,789 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "fields.h"++/*+ * Fp2  = Fp[u]  / (u^2 + 1)+ * Fp6  = Fp2[v] / (v^3 - u - 1)+ * Fp12 = Fp6[w] / (w^2 - v)+ */++static inline void mul_by_u_plus_1_fp2(vec384x ret, const vec384x a)+{   mul_by_1_plus_i_mod_384x(ret, a, BLS12_381_P);   }++#if 1 && !defined(__BLST_NO_ASM__)+#define __FP2x2__+/*+ * Fp2x2 is a "widened" version of Fp2, which allows to consolidate+ * reductions from several multiplications. In other words instead of+ * "mul_redc-mul_redc-add" we get "mul-mul-add-redc," where latter+ * addition is double-width... To be more specific this gives ~7-10%+ * faster pairing depending on platform...+ */+typedef vec768 vec768x[2];++static inline void add_fp2x2(vec768x ret, const vec768x a, const vec768x b)+{+    add_mod_384x384(ret[0], a[0], b[0], BLS12_381_P);+    add_mod_384x384(ret[1], a[1], b[1], BLS12_381_P);+}++static inline void sub_fp2x2(vec768x ret, const vec768x a, const vec768x b)+{+    sub_mod_384x384(ret[0], a[0], b[0], BLS12_381_P);+    sub_mod_384x384(ret[1], a[1], b[1], BLS12_381_P);+}++static inline void mul_by_u_plus_1_fp2x2(vec768x ret, const vec768x a)+{+    /* caveat lector! |ret| may not be same as |a| */+    sub_mod_384x384(ret[0], a[0], a[1], BLS12_381_P);+    add_mod_384x384(ret[1], a[0], a[1], BLS12_381_P);+}++static inline void redc_fp2x2(vec384x ret, const vec768x a)+{+    redc_mont_384(ret[0], a[0], BLS12_381_P, p0);+    redc_mont_384(ret[1], a[1], BLS12_381_P, p0);+}++static void mul_fp2x2(vec768x ret, const vec384x a, const vec384x b)+{+#if 1+    mul_382x(ret, a, b, BLS12_381_P);   /* +~6% in Miller loop */+#else+    union { vec384 x[2]; vec768 x2; } t;++    add_mod_384(t.x[0], a[0], a[1], BLS12_381_P);+    add_mod_384(t.x[1], b[0], b[1], BLS12_381_P);+    mul_384(ret[1], t.x[0], t.x[1]);++    mul_384(ret[0], a[0], b[0]);+    mul_384(t.x2,   a[1], b[1]);++    sub_mod_384x384(ret[1], ret[1], ret[0], BLS12_381_P);+    sub_mod_384x384(ret[1], ret[1], t.x2, BLS12_381_P);++    sub_mod_384x384(ret[0], ret[0], t.x2, BLS12_381_P);+#endif+}++static void sqr_fp2x2(vec768x ret, const vec384x a)+{+#if 1+    sqr_382x(ret, a, BLS12_381_P);      /* +~5% in final exponentiation */+#else+    vec384 t0, t1;++    add_mod_384(t0, a[0], a[1], BLS12_381_P);+    sub_mod_384(t1, a[0], a[1], BLS12_381_P);++    mul_384(ret[1], a[0], a[1]);+    add_mod_384x384(ret[1], ret[1], ret[1], BLS12_381_P);++    mul_384(ret[0], t0, t1);+#endif+}+#endif  /* __FP2x2__ */++/*+ * Fp6 extension+ */+#if defined(__FP2x2__)  /* ~10-13% improvement for mul_fp12 and sqr_fp12 */+typedef vec768x vec768fp6[3];++static inline void sub_fp6x2(vec768fp6 ret, const vec768fp6 a,+                                            const vec768fp6 b)+{+    sub_fp2x2(ret[0], a[0], b[0]);+    sub_fp2x2(ret[1], a[1], b[1]);+    sub_fp2x2(ret[2], a[2], b[2]);+}++static void mul_fp6x2(vec768fp6 ret, const vec384fp6 a, const vec384fp6 b)+{+    vec768x t0, t1, t2;+    vec384x aa, bb;++    mul_fp2x2(t0, a[0], b[0]);+    mul_fp2x2(t1, a[1], b[1]);+    mul_fp2x2(t2, a[2], b[2]);++    /* ret[0] = ((a1 + a2)*(b1 + b2) - a1*b1 - a2*b2)*(u+1) + a0*b0+              = (a1*b2 + a2*b1)*(u+1) + a0*b0 */+    add_fp2(aa, a[1], a[2]);+    add_fp2(bb, b[1], b[2]);+    mul_fp2x2(ret[0], aa, bb);+    sub_fp2x2(ret[0], ret[0], t1);+    sub_fp2x2(ret[0], ret[0], t2);+    mul_by_u_plus_1_fp2x2(ret[1], ret[0]);  /* borrow ret[1] for a moment */+    add_fp2x2(ret[0], ret[1], t0);++    /* ret[1] = (a0 + a1)*(b0 + b1) - a0*b0 - a1*b1 + a2*b2*(u+1)+              = a0*b1 + a1*b0 + a2*b2*(u+1) */+    add_fp2(aa, a[0], a[1]);+    add_fp2(bb, b[0], b[1]);+    mul_fp2x2(ret[1], aa, bb);+    sub_fp2x2(ret[1], ret[1], t0);+    sub_fp2x2(ret[1], ret[1], t1);+    mul_by_u_plus_1_fp2x2(ret[2], t2);      /* borrow ret[2] for a moment */+    add_fp2x2(ret[1], ret[1], ret[2]);++    /* ret[2] = (a0 + a2)*(b0 + b2) - a0*b0 - a2*b2 + a1*b1+              = a0*b2 + a2*b0 + a1*b1 */+    add_fp2(aa, a[0], a[2]);+    add_fp2(bb, b[0], b[2]);+    mul_fp2x2(ret[2], aa, bb);+    sub_fp2x2(ret[2], ret[2], t0);+    sub_fp2x2(ret[2], ret[2], t2);+    add_fp2x2(ret[2], ret[2], t1);+}++static inline void redc_fp6x2(vec384fp6 ret, const vec768fp6 a)+{+    redc_fp2x2(ret[0], a[0]);+    redc_fp2x2(ret[1], a[1]);+    redc_fp2x2(ret[2], a[2]);+}++static void mul_fp6(vec384fp6 ret, const vec384fp6 a, const vec384fp6 b)+{+    vec768fp6 r;++    mul_fp6x2(r, a, b);+    redc_fp6x2(ret, r); /* narrow to normal width */+}++static void sqr_fp6(vec384fp6 ret, const vec384fp6 a)+{+    vec768x s0, m01, m12, s2, rx;++    sqr_fp2x2(s0, a[0]);++    mul_fp2x2(m01, a[0], a[1]);+    add_fp2x2(m01, m01, m01);++    mul_fp2x2(m12, a[1], a[2]);+    add_fp2x2(m12, m12, m12);++    sqr_fp2x2(s2, a[2]);++    /* ret[2] = (a0 + a1 + a2)^2 - a0^2 - a2^2 - 2*(a0*a1) - 2*(a1*a2)+              = a1^2 + 2*(a0*a2) */+    add_fp2(ret[2], a[2], a[1]);+    add_fp2(ret[2], ret[2], a[0]);+    sqr_fp2x2(rx, ret[2]);+    sub_fp2x2(rx, rx, s0);+    sub_fp2x2(rx, rx, s2);+    sub_fp2x2(rx, rx, m01);+    sub_fp2x2(rx, rx, m12);+    redc_fp2x2(ret[2], rx);++    /* ret[0] = a0^2 + 2*(a1*a2)*(u+1) */+    mul_by_u_plus_1_fp2x2(rx, m12);+    add_fp2x2(rx, rx, s0);+    redc_fp2x2(ret[0], rx);++    /* ret[1] = a2^2*(u+1) + 2*(a0*a1) */+    mul_by_u_plus_1_fp2x2(rx, s2);+    add_fp2x2(rx, rx, m01);+    redc_fp2x2(ret[1], rx);+}+#else+static void mul_fp6(vec384fp6 ret, const vec384fp6 a, const vec384fp6 b)+{+    vec384x t0, t1, t2, t3, t4, t5;++    mul_fp2(t0, a[0], b[0]);+    mul_fp2(t1, a[1], b[1]);+    mul_fp2(t2, a[2], b[2]);++    /* ret[0] = ((a1 + a2)*(b1 + b2) - a1*b1 - a2*b2)*(u+1) + a0*b0+              = (a1*b2 + a2*b1)*(u+1) + a0*b0 */+    add_fp2(t4, a[1], a[2]);+    add_fp2(t5, b[1], b[2]);+    mul_fp2(t3, t4, t5);+    sub_fp2(t3, t3, t1);+    sub_fp2(t3, t3, t2);+    mul_by_u_plus_1_fp2(t3, t3);+    /* add_fp2(ret[0], t3, t0); considering possible aliasing... */++    /* ret[1] = (a0 + a1)*(b0 + b1) - a0*b0 - a1*b1 + a2*b2*(u+1)+              = a0*b1 + a1*b0 + a2*b2*(u+1) */+    add_fp2(t4, a[0], a[1]);+    add_fp2(t5, b[0], b[1]);+    mul_fp2(ret[1], t4, t5);+    sub_fp2(ret[1], ret[1], t0);+    sub_fp2(ret[1], ret[1], t1);+    mul_by_u_plus_1_fp2(t4, t2);+    add_fp2(ret[1], ret[1], t4);++    /* ret[2] = (a0 + a2)*(b0 + b2) - a0*b0 - a2*b2 + a1*b1+              = a0*b2 + a2*b0 + a1*b1 */+    add_fp2(t4, a[0], a[2]);+    add_fp2(t5, b[0], b[2]);+    mul_fp2(ret[2], t4, t5);+    sub_fp2(ret[2], ret[2], t0);+    sub_fp2(ret[2], ret[2], t2);+    add_fp2(ret[2], ret[2], t1);++    add_fp2(ret[0], t3, t0);    /* ... moved from above */+}++static void sqr_fp6(vec384fp6 ret, const vec384fp6 a)+{+    vec384x s0, m01, m12, s2;++    sqr_fp2(s0, a[0]);++    mul_fp2(m01, a[0], a[1]);+    add_fp2(m01, m01, m01);++    mul_fp2(m12, a[1], a[2]);+    add_fp2(m12, m12, m12);++    sqr_fp2(s2, a[2]);++    /* ret[2] = (a0 + a1 + a2)^2 - a0^2 - a2^2 - 2*(a0*a1) - 2*(a1*a2)+              = a1^2 + 2*(a0*a2) */+    add_fp2(ret[2], a[2], a[1]);+    add_fp2(ret[2], ret[2], a[0]);+    sqr_fp2(ret[2], ret[2]);+    sub_fp2(ret[2], ret[2], s0);+    sub_fp2(ret[2], ret[2], s2);+    sub_fp2(ret[2], ret[2], m01);+    sub_fp2(ret[2], ret[2], m12);++    /* ret[0] = a0^2 + 2*(a1*a2)*(u+1) */+    mul_by_u_plus_1_fp2(ret[0], m12);+    add_fp2(ret[0], ret[0], s0);++    /* ret[1] = a2^2*(u+1) + 2*(a0*a1) */+    mul_by_u_plus_1_fp2(ret[1], s2);+    add_fp2(ret[1], ret[1], m01);+}+#endif++static void add_fp6(vec384fp6 ret, const vec384fp6 a, const vec384fp6 b)+{+    add_fp2(ret[0], a[0], b[0]);+    add_fp2(ret[1], a[1], b[1]);+    add_fp2(ret[2], a[2], b[2]);+}++static void sub_fp6(vec384fp6 ret, const vec384fp6 a, const vec384fp6 b)+{+    sub_fp2(ret[0], a[0], b[0]);+    sub_fp2(ret[1], a[1], b[1]);+    sub_fp2(ret[2], a[2], b[2]);+}++static void neg_fp6(vec384fp6 ret, const vec384fp6 a)+{+    neg_fp2(ret[0], a[0]);+    neg_fp2(ret[1], a[1]);+    neg_fp2(ret[2], a[2]);+}++#if 0+#define mul_by_v_fp6 mul_by_v_fp6+static void mul_by_v_fp6(vec384fp6 ret, const vec384fp6 a)+{+    vec384x t;++    mul_by_u_plus_1_fp2(t, a[2]);+    vec_copy(ret[2], a[1], sizeof(a[1]));+    vec_copy(ret[1], a[0], sizeof(a[0]));+    vec_copy(ret[0], t, sizeof(t));+}+#endif++/*+ * Fp12 extension+ */+#if defined(__FP2x2__)+static void mul_fp12(vec384fp12 ret, const vec384fp12 a, const vec384fp12 b)+{+    vec768fp6 t0, t1, rx;+    vec384fp6 t2;++    mul_fp6x2(t0, a[0], b[0]);+    mul_fp6x2(t1, a[1], b[1]);++    /* ret[1] = (a0 + a1)*(b0 + b1) - a0*b0 - a1*b1+              = a0*b1 + a1*b0 */+    add_fp6(t2, a[0], a[1]);+    add_fp6(ret[1], b[0], b[1]);+    mul_fp6x2(rx, ret[1], t2);+    sub_fp6x2(rx, rx, t0);+    sub_fp6x2(rx, rx, t1);+    redc_fp6x2(ret[1], rx);++    /* ret[0] = a0*b0 + a1*b1*v */+    mul_by_u_plus_1_fp2x2(rx[0], t1[2]);+    add_fp2x2(rx[0], t0[0], rx[0]);+    add_fp2x2(rx[1], t0[1], t1[0]);+    add_fp2x2(rx[2], t0[2], t1[1]);+    redc_fp6x2(ret[0], rx);+}++static inline void mul_by_0y0_fp6x2(vec768fp6 ret, const vec384fp6 a,+                                                   const vec384fp2 b)+{+    mul_fp2x2(ret[1], a[2], b);     /* borrow ret[1] for a moment */+    mul_by_u_plus_1_fp2x2(ret[0], ret[1]);+    mul_fp2x2(ret[1], a[0], b);+    mul_fp2x2(ret[2], a[1], b);+}++static void mul_by_xy0_fp6x2(vec768fp6 ret, const vec384fp6 a,+                                            const vec384fp6 b)+{+    vec768x t0, t1;+    vec384x aa, bb;++    mul_fp2x2(t0, a[0], b[0]);+    mul_fp2x2(t1, a[1], b[1]);++    /* ret[0] = ((a1 + a2)*(b1 + 0) - a1*b1 - a2*0)*(u+1) + a0*b0+              = (a1*0 + a2*b1)*(u+1) + a0*b0 */+    mul_fp2x2(ret[1], a[2], b[1]);  /* borrow ret[1] for a moment */+    mul_by_u_plus_1_fp2x2(ret[0], ret[1]);+    add_fp2x2(ret[0], ret[0], t0);++    /* ret[1] = (a0 + a1)*(b0 + b1) - a0*b0 - a1*b1 + a2*0*(u+1)+              = a0*b1 + a1*b0 + a2*0*(u+1) */+    add_fp2(aa, a[0], a[1]);+    add_fp2(bb, b[0], b[1]);+    mul_fp2x2(ret[1], aa, bb);+    sub_fp2x2(ret[1], ret[1], t0);+    sub_fp2x2(ret[1], ret[1], t1);++    /* ret[2] = (a0 + a2)*(b0 + 0) - a0*b0 - a2*0 + a1*b1+              = a0*0 + a2*b0 + a1*b1 */+    mul_fp2x2(ret[2], a[2], b[0]);+    add_fp2x2(ret[2], ret[2], t1);+}++static void mul_by_xy00z0_fp12(vec384fp12 ret, const vec384fp12 a,+                                               const vec384fp6 xy00z0)+{+    vec768fp6 t0, t1, rr;+    vec384fp6 t2;++    mul_by_xy0_fp6x2(t0, a[0], xy00z0);+    mul_by_0y0_fp6x2(t1, a[1], xy00z0[2]);++    /* ret[1] = (a0 + a1)*(b0 + b1) - a0*b0 - a1*b1+              = a0*b1 + a1*b0 */+    vec_copy(t2[0], xy00z0[0], sizeof(t2[0]));+    add_fp2(t2[1], xy00z0[1], xy00z0[2]);+    add_fp6(ret[1], a[0], a[1]);+    mul_by_xy0_fp6x2(rr, ret[1], t2);+    sub_fp6x2(rr, rr, t0);+    sub_fp6x2(rr, rr, t1);+    redc_fp6x2(ret[1], rr);++    /* ret[0] = a0*b0 + a1*b1*v */+    mul_by_u_plus_1_fp2x2(rr[0], t1[2]);+    add_fp2x2(rr[0], t0[0], rr[0]);+    add_fp2x2(rr[1], t0[1], t1[0]);+    add_fp2x2(rr[2], t0[2], t1[1]);+    redc_fp6x2(ret[0], rr);+}+#else+static void mul_fp12(vec384fp12 ret, const vec384fp12 a, const vec384fp12 b)+{+    vec384fp6 t0, t1, t2;++    mul_fp6(t0, a[0], b[0]);+    mul_fp6(t1, a[1], b[1]);++    /* ret[1] = (a0 + a1)*(b0 + b1) - a0*b0 - a1*b1+              = a0*b1 + a1*b0 */+    add_fp6(t2, a[0], a[1]);+    add_fp6(ret[1], b[0], b[1]);+    mul_fp6(ret[1], ret[1], t2);+    sub_fp6(ret[1], ret[1], t0);+    sub_fp6(ret[1], ret[1], t1);++    /* ret[0] = a0*b0 + a1*b1*v */+#ifdef mul_by_v_fp6+    mul_by_v_fp6(t1, t1);+    add_fp6(ret[0], t0, t1);+#else+    mul_by_u_plus_1_fp2(t1[2], t1[2]);+    add_fp2(ret[0][0], t0[0], t1[2]);+    add_fp2(ret[0][1], t0[1], t1[0]);+    add_fp2(ret[0][2], t0[2], t1[1]);+#endif+}++static inline void mul_by_0y0_fp6(vec384fp6 ret, const vec384fp6 a,+                                                 const vec384fp2 b)+{+    vec384x t;++    mul_fp2(t,      a[2], b);+    mul_fp2(ret[2], a[1], b);+    mul_fp2(ret[1], a[0], b);+    mul_by_u_plus_1_fp2(ret[0], t);+}++static void mul_by_xy0_fp6(vec384fp6 ret, const vec384fp6 a, const vec384fp6 b)+{+    vec384x t0, t1, /*t2,*/ t3, t4, t5;++    mul_fp2(t0, a[0], b[0]);+    mul_fp2(t1, a[1], b[1]);++    /* ret[0] = ((a1 + a2)*(b1 + 0) - a1*b1 - a2*0)*(u+1) + a0*b0+              = (a1*0 + a2*b1)*(u+1) + a0*b0 */+    mul_fp2(t3, a[2], b[1]);+    mul_by_u_plus_1_fp2(t3, t3);+    /* add_fp2(ret[0], t3, t0); considering possible aliasing... */++    /* ret[1] = (a0 + a1)*(b0 + b1) - a0*b0 - a1*b1 + a2*0*(u+1)+              = a0*b1 + a1*b0 + a2*0*(u+1) */+    add_fp2(t4, a[0], a[1]);+    add_fp2(t5, b[0], b[1]);+    mul_fp2(ret[1], t4, t5);+    sub_fp2(ret[1], ret[1], t0);+    sub_fp2(ret[1], ret[1], t1);++    /* ret[2] = (a0 + a2)*(b0 + 0) - a0*b0 - a2*0 + a1*b1+              = a0*0 + a2*b0 + a1*b1 */+    mul_fp2(ret[2], a[2], b[0]);+    add_fp2(ret[2], ret[2], t1);++    add_fp2(ret[0], t3, t0);    /* ... moved from above */+}++static void mul_by_xy00z0_fp12(vec384fp12 ret, const vec384fp12 a,+                                               const vec384fp6 xy00z0)+{+    vec384fp6 t0, t1, t2;++    mul_by_xy0_fp6(t0, a[0], xy00z0);+    mul_by_0y0_fp6(t1, a[1], xy00z0[2]);++    /* ret[1] = (a0 + a1)*(b0 + b1) - a0*b0 - a1*b1+              = a0*b1 + a1*b0 */+    vec_copy(t2[0], xy00z0[0], sizeof(t2[0]));+    add_fp2(t2[1], xy00z0[1], xy00z0[2]);+    add_fp6(ret[1], a[0], a[1]);+    mul_by_xy0_fp6(ret[1], ret[1], t2);+    sub_fp6(ret[1], ret[1], t0);+    sub_fp6(ret[1], ret[1], t1);++    /* ret[0] = a0*b0 + a1*b1*v */+#ifdef mul_by_v_fp6+    mul_by_v_fp6(t1, t1);+    add_fp6(ret[0], t0, t1);+#else+    mul_by_u_plus_1_fp2(t1[2], t1[2]);+    add_fp2(ret[0][0], t0[0], t1[2]);+    add_fp2(ret[0][1], t0[1], t1[0]);+    add_fp2(ret[0][2], t0[2], t1[1]);+#endif+}+#endif++static void sqr_fp12(vec384fp12 ret, const vec384fp12 a)+{+    vec384fp6 t0, t1;++    add_fp6(t0, a[0], a[1]);+#ifdef mul_by_v_fp6+    mul_by_v_fp6(t1, a[1]);+    add_fp6(t1, a[0], t1);+#else+    mul_by_u_plus_1_fp2(t1[2], a[1][2]);+    add_fp2(t1[0], a[0][0], t1[2]);+    add_fp2(t1[1], a[0][1], a[1][0]);+    add_fp2(t1[2], a[0][2], a[1][1]);+#endif+    mul_fp6(t0, t0, t1);+    mul_fp6(t1, a[0], a[1]);++    /* ret[1] = 2*(a0*a1) */+    add_fp6(ret[1], t1, t1);++    /* ret[0] = (a0 + a1)*(a0 + a1*v) - a0*a1 - a0*a1*v+              = a0^2 + a1^2*v */+    sub_fp6(ret[0], t0, t1);+#ifdef mul_by_v_fp6+    mul_by_v_fp6(t1, t1);+    sub_fp6(ret[0], ret[0], t1);+#else+    mul_by_u_plus_1_fp2(t1[2], t1[2]);+    sub_fp2(ret[0][0], ret[0][0], t1[2]);+    sub_fp2(ret[0][1], ret[0][1], t1[0]);+    sub_fp2(ret[0][2], ret[0][2], t1[1]);+#endif+}++static void conjugate_fp12(vec384fp12 a)+{   neg_fp6(a[1], a[1]);   }++static void inverse_fp6(vec384fp6 ret, const vec384fp6 a)+{+    vec384x c0, c1, c2, t0, t1;++    /* c0 = a0^2 - (a1*a2)*(u+1) */+    sqr_fp2(c0, a[0]);+    mul_fp2(t0, a[1], a[2]);+    mul_by_u_plus_1_fp2(t0, t0);+    sub_fp2(c0, c0, t0);++    /* c1 = a2^2*(u+1) - (a0*a1) */+    sqr_fp2(c1, a[2]);+    mul_by_u_plus_1_fp2(c1, c1);+    mul_fp2(t0, a[0], a[1]);+    sub_fp2(c1, c1, t0);++    /* c2 = a1^2 - a0*a2 */+    sqr_fp2(c2, a[1]);+    mul_fp2(t0, a[0], a[2]);+    sub_fp2(c2, c2, t0);++    /* (a2*c1 + a1*c2)*(u+1) + a0*c0 */+    mul_fp2(t0, c1, a[2]);+    mul_fp2(t1, c2, a[1]);+    add_fp2(t0, t0, t1);+    mul_by_u_plus_1_fp2(t0, t0);+    mul_fp2(t1, c0, a[0]);+    add_fp2(t0, t0, t1);++    reciprocal_fp2(t1, t0);++    mul_fp2(ret[0], c0, t1);+    mul_fp2(ret[1], c1, t1);+    mul_fp2(ret[2], c2, t1);+}++static void inverse_fp12(vec384fp12 ret, const vec384fp12 a)+{+    vec384fp6 t0, t1;++    sqr_fp6(t0, a[0]);+    sqr_fp6(t1, a[1]);+#ifdef mul_by_v_fp6+    mul_by_v_fp6(t1, t1);+    sub_fp6(t0, t0, t1);+#else+    mul_by_u_plus_1_fp2(t1[2], t1[2]);+    sub_fp2(t0[0], t0[0], t1[2]);+    sub_fp2(t0[1], t0[1], t1[0]);+    sub_fp2(t0[2], t0[2], t1[1]);+#endif++    inverse_fp6(t1, t0);++    mul_fp6(ret[0], a[0], t1);+    mul_fp6(ret[1], a[1], t1);+    neg_fp6(ret[1], ret[1]);+}++typedef vec384x vec384fp4[2];++#if defined(__FP2x2__)+static void sqr_fp4(vec384fp4 ret, const vec384x a0, const vec384x a1)+{+    vec768x t0, t1, t2;++    sqr_fp2x2(t0, a0);+    sqr_fp2x2(t1, a1);+    add_fp2(ret[1], a0, a1);++    mul_by_u_plus_1_fp2x2(t2, t1);+    add_fp2x2(t2, t2, t0);+    redc_fp2x2(ret[0], t2);++    sqr_fp2x2(t2, ret[1]);+    sub_fp2x2(t2, t2, t0);+    sub_fp2x2(t2, t2, t1);+    redc_fp2x2(ret[1], t2);+}+#else+static void sqr_fp4(vec384fp4 ret, const vec384x a0, const vec384x a1)+{+    vec384x t0, t1;++    sqr_fp2(t0, a0);+    sqr_fp2(t1, a1);+    add_fp2(ret[1], a0, a1);++    mul_by_u_plus_1_fp2(ret[0], t1);+    add_fp2(ret[0], ret[0], t0);++    sqr_fp2(ret[1], ret[1]);+    sub_fp2(ret[1], ret[1], t0);+    sub_fp2(ret[1], ret[1], t1);+}+#endif++static void cyclotomic_sqr_fp12(vec384fp12 ret, const vec384fp12 a)+{+    vec384fp4 t0, t1, t2;++    sqr_fp4(t0, a[0][0], a[1][1]);+    sqr_fp4(t1, a[1][0], a[0][2]);+    sqr_fp4(t2, a[0][1], a[1][2]);++    sub_fp2(ret[0][0], t0[0],     a[0][0]);+    add_fp2(ret[0][0], ret[0][0], ret[0][0]);+    add_fp2(ret[0][0], ret[0][0], t0[0]);++    sub_fp2(ret[0][1], t1[0],     a[0][1]);+    add_fp2(ret[0][1], ret[0][1], ret[0][1]);+    add_fp2(ret[0][1], ret[0][1], t1[0]);++    sub_fp2(ret[0][2], t2[0],     a[0][2]);+    add_fp2(ret[0][2], ret[0][2], ret[0][2]);+    add_fp2(ret[0][2], ret[0][2], t2[0]);++    mul_by_u_plus_1_fp2(t2[1], t2[1]);+    add_fp2(ret[1][0], t2[1],     a[1][0]);+    add_fp2(ret[1][0], ret[1][0], ret[1][0]);+    add_fp2(ret[1][0], ret[1][0], t2[1]);++    add_fp2(ret[1][1], t0[1],     a[1][1]);+    add_fp2(ret[1][1], ret[1][1], ret[1][1]);+    add_fp2(ret[1][1], ret[1][1], t0[1]);++    add_fp2(ret[1][2], t1[1],     a[1][2]);+    add_fp2(ret[1][2], ret[1][2], ret[1][2]);+    add_fp2(ret[1][2], ret[1][2], t1[1]);+}++/*+ * caveat lector! |n| has to be non-zero and not more than 3!+ */+static inline void frobenius_map_fp2(vec384x ret, const vec384x a, size_t n)+{+    vec_copy(ret[0], a[0], sizeof(ret[0]));+    cneg_fp(ret[1], a[1], n & 1);+}++static void frobenius_map_fp6(vec384fp6 ret, const vec384fp6 a, size_t n)+{+    static const vec384x coeffs1[] = {  /* (u + 1)^((P^n - 1) / 3) */+      { { 0 },+        { TO_LIMB_T(0xcd03c9e48671f071), TO_LIMB_T(0x5dab22461fcda5d2),+          TO_LIMB_T(0x587042afd3851b95), TO_LIMB_T(0x8eb60ebe01bacb9e),+          TO_LIMB_T(0x03f97d6e83d050d2), TO_LIMB_T(0x18f0206554638741) } },+      { { TO_LIMB_T(0x30f1361b798a64e8), TO_LIMB_T(0xf3b8ddab7ece5a2a),+          TO_LIMB_T(0x16a8ca3ac61577f7), TO_LIMB_T(0xc26a2ff874fd029b),+          TO_LIMB_T(0x3636b76660701c6e), TO_LIMB_T(0x051ba4ab241b6160) } },+      { { 0 }, { ONE_MONT_P } }+    };+    static const vec384 coeffs2[] = {  /* (u + 1)^((2P^n - 2) / 3) */+      {   TO_LIMB_T(0x890dc9e4867545c3), TO_LIMB_T(0x2af322533285a5d5),+          TO_LIMB_T(0x50880866309b7e2c), TO_LIMB_T(0xa20d1b8c7e881024),+          TO_LIMB_T(0x14e4f04fe2db9068), TO_LIMB_T(0x14e56d3f1564853a)   },+      {   TO_LIMB_T(0xcd03c9e48671f071), TO_LIMB_T(0x5dab22461fcda5d2),+          TO_LIMB_T(0x587042afd3851b95), TO_LIMB_T(0x8eb60ebe01bacb9e),+          TO_LIMB_T(0x03f97d6e83d050d2), TO_LIMB_T(0x18f0206554638741)   },+      {   TO_LIMB_T(0x43f5fffffffcaaae), TO_LIMB_T(0x32b7fff2ed47fffd),+          TO_LIMB_T(0x07e83a49a2e99d69), TO_LIMB_T(0xeca8f3318332bb7a),+          TO_LIMB_T(0xef148d1ea0f4c069), TO_LIMB_T(0x040ab3263eff0206)   }+    };++    frobenius_map_fp2(ret[0], a[0], n);+    frobenius_map_fp2(ret[1], a[1], n);+    frobenius_map_fp2(ret[2], a[2], n);+    --n;    /* implied ONE_MONT_P at index 0 */+    mul_fp2(ret[1], ret[1], coeffs1[n]);+    mul_fp(ret[2][0], ret[2][0], coeffs2[n]);+    mul_fp(ret[2][1], ret[2][1], coeffs2[n]);+}++static void frobenius_map_fp12(vec384fp12 ret, const vec384fp12 a, size_t n)+{+    static const vec384x coeffs[] = {  /* (u + 1)^((P^n - 1) / 6) */+      { { TO_LIMB_T(0x07089552b319d465), TO_LIMB_T(0xc6695f92b50a8313),+          TO_LIMB_T(0x97e83cccd117228f), TO_LIMB_T(0xa35baecab2dc29ee),+          TO_LIMB_T(0x1ce393ea5daace4d), TO_LIMB_T(0x08f2220fb0fb66eb) },+	{ TO_LIMB_T(0xb2f66aad4ce5d646), TO_LIMB_T(0x5842a06bfc497cec),+          TO_LIMB_T(0xcf4895d42599d394), TO_LIMB_T(0xc11b9cba40a8e8d0),+          TO_LIMB_T(0x2e3813cbe5a0de89), TO_LIMB_T(0x110eefda88847faf) } },+      { { TO_LIMB_T(0xecfb361b798dba3a), TO_LIMB_T(0xc100ddb891865a2c),+          TO_LIMB_T(0x0ec08ff1232bda8e), TO_LIMB_T(0xd5c13cc6f1ca4721),+          TO_LIMB_T(0x47222a47bf7b5c04), TO_LIMB_T(0x0110f184e51c5f59) } },+      { { TO_LIMB_T(0x3e2f585da55c9ad1), TO_LIMB_T(0x4294213d86c18183),+          TO_LIMB_T(0x382844c88b623732), TO_LIMB_T(0x92ad2afd19103e18),+          TO_LIMB_T(0x1d794e4fac7cf0b9), TO_LIMB_T(0x0bd592fc7d825ec8) },+	{ TO_LIMB_T(0x7bcfa7a25aa30fda), TO_LIMB_T(0xdc17dec12a927e7c),+          TO_LIMB_T(0x2f088dd86b4ebef1), TO_LIMB_T(0xd1ca2087da74d4a7),+          TO_LIMB_T(0x2da2596696cebc1d), TO_LIMB_T(0x0e2b7eedbbfd87d2) } },+    };++    frobenius_map_fp6(ret[0], a[0], n);+    frobenius_map_fp6(ret[1], a[1], n);+    --n;    /* implied ONE_MONT_P at index 0 */+    mul_fp2(ret[1][0], ret[1][0], coeffs[n]);+    mul_fp2(ret[1][1], ret[1][1], coeffs[n]);+    mul_fp2(ret[1][2], ret[1][2], coeffs[n]);+}+++/*+ * BLS12-381-specific Fp12 shortcuts.+ */+void blst_fp12_sqr(vec384fp12 ret, const vec384fp12 a)+{   sqr_fp12(ret, a);   }++void blst_fp12_cyclotomic_sqr(vec384fp12 ret, const vec384fp12 a)+{   cyclotomic_sqr_fp12(ret, a);   }++void blst_fp12_mul(vec384fp12 ret, const vec384fp12 a, const vec384fp12 b)+{   mul_fp12(ret, a, b);   }++void blst_fp12_mul_by_xy00z0(vec384fp12 ret, const vec384fp12 a,+                                             const vec384fp6 xy00z0)+{   mul_by_xy00z0_fp12(ret, a, xy00z0);   }++void blst_fp12_conjugate(vec384fp12 a)+{   conjugate_fp12(a);   }++void blst_fp12_inverse(vec384fp12 ret, const vec384fp12 a)+{   inverse_fp12(ret, a);   }++/* caveat lector! |n| has to be non-zero and not more than 3! */+void blst_fp12_frobenius_map(vec384fp12 ret, const vec384fp12 a, size_t n)+{   frobenius_map_fp12(ret, a, n);   }++int blst_fp12_is_equal(const vec384fp12 a, const vec384fp12 b)+{   return (int)vec_is_equal(a, b, sizeof(vec384fp12));   }++int blst_fp12_is_one(const vec384fp12 a)+{+    return (int)(vec_is_equal(a[0][0], BLS12_381_Rx.p2, sizeof(a[0][0])) &+                 vec_is_zero(a[0][1], sizeof(vec384fp12) - sizeof(a[0][0])));+}++const vec384fp12 *blst_fp12_one(void)+{   return (const vec384fp12 *)BLS12_381_Rx.p12;   }++void blst_bendian_from_fp12(unsigned char ret[48*12], const vec384fp12 a)+{+    size_t i, j;+    vec384 out;++    for (i = 0; i < 3; i++) {+        for (j = 0; j < 2; j++) {+            from_fp(out, a[j][i][0]);+            be_bytes_from_limbs(ret, out, sizeof(vec384));  ret += 48;+            from_fp(out, a[j][i][1]);+            be_bytes_from_limbs(ret, out, sizeof(vec384));  ret += 48;+        }+    }+}++size_t blst_fp12_sizeof(void)+{   return sizeof(vec384fp12);   }
+ vendor/external/blst/src/hash_to_field.c view
@@ -0,0 +1,177 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "consts.h"+#include "sha256.h"++static const vec384 BLS12_381_RRRR = {  /* RR^2 */+    TO_LIMB_T(0xed48ac6bd94ca1e0), TO_LIMB_T(0x315f831e03a7adf8),+    TO_LIMB_T(0x9a53352a615e29dd), TO_LIMB_T(0x34c04e5e921e1761),+    TO_LIMB_T(0x2512d43565724728), TO_LIMB_T(0x0aa6346091755d4d)+};++#ifdef expand_message_xmd+void expand_message_xmd(unsigned char *bytes, size_t len_in_bytes,+                        const unsigned char *aug, size_t aug_len,+                        const unsigned char *msg, size_t msg_len,+                        const unsigned char *DST, size_t DST_len);+#else+static void sha256_init_Zpad(SHA256_CTX *ctx)+{+    ctx->h[0] = 0xda5698beU;+    ctx->h[1] = 0x17b9b469U;+    ctx->h[2] = 0x62335799U;+    ctx->h[3] = 0x779fbecaU;+    ctx->h[4] = 0x8ce5d491U;+    ctx->h[5] = 0xc0d26243U;+    ctx->h[6] = 0xbafef9eaU;+    ctx->h[7] = 0x1837a9d8U;+    ctx->N = 64;+    vec_zero(ctx->buf, sizeof(ctx->buf));+    ctx->off = 0;+}++static void vec_xor(void *restrict ret, const void *restrict a,+                                        const void *restrict b, size_t num)+{+    limb_t *rp = (limb_t *)ret;+    const limb_t *ap = (const limb_t *)a;+    const limb_t *bp = (const limb_t *)b;+    size_t i;++    num /= sizeof(limb_t);++    for (i = 0; i < num; i++)+        rp[i] = ap[i] ^ bp[i];+}++static void expand_message_xmd(unsigned char *bytes, size_t len_in_bytes,+                               const unsigned char *aug, size_t aug_len,+                               const unsigned char *msg, size_t msg_len,+                               const unsigned char *DST, size_t DST_len)+{+    union { limb_t align; unsigned char c[32]; } b_0;+    union { limb_t align; unsigned char c[33+256+31]; } b_i;+    unsigned char *p;+    size_t i, b_i_bits, b_i_blocks;+    SHA256_CTX ctx;++    /*+     * compose template for 'strxor(b_0, b_(i-1)) || I2OSP(i, 1) || DST_prime'+     */+    if (DST_len > 255) {+        sha256_init(&ctx);+        sha256_update(&ctx, "H2C-OVERSIZE-DST-", 17);+        sha256_update(&ctx, DST, DST_len);+        sha256_final(b_0.c, &ctx);+        DST = b_0.c, DST_len = 32;+    }+    b_i_blocks = ((33 + DST_len + 1 + 9) + 63) & -64;+    vec_zero(b_i.c + b_i_blocks - 64, 64);++    p = b_i.c + 33;+    for (i = 0; i < DST_len; i++)+        p[i] = DST[i];+    p[i++] = (unsigned char)DST_len;+    p[i++] = 0x80;+    p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = 0;+    b_i_bits = (33 + DST_len + 1) * 8;+    p = b_i.c + b_i_blocks;+    p[-2] = (unsigned char)(b_i_bits >> 8);+    p[-1] = (unsigned char)(b_i_bits);++    sha256_init_Zpad(&ctx);                         /* Z_pad | */+    sha256_update(&ctx, aug, aug_len);              /* | aug | */+    sha256_update(&ctx, msg, msg_len);              /* | msg | */+    /* | I2OSP(len_in_bytes, 2) || I2OSP(0, 1) || DST_prime    */+    b_i.c[30] = (unsigned char)(len_in_bytes >> 8);+    b_i.c[31] = (unsigned char)(len_in_bytes);+    b_i.c[32] = 0;+    sha256_update(&ctx, b_i.c + 30, 3 + DST_len + 1);+    sha256_final(b_0.c, &ctx);++    sha256_init_h(ctx.h);+    vec_copy(b_i.c, b_0.c, 32);+    ++b_i.c[32];+    sha256_block_data_order(ctx.h, b_i.c, b_i_blocks / 64);+    sha256_emit(bytes, ctx.h);++    len_in_bytes += 31; /* ell = ceil(len_in_bytes / b_in_bytes), with */+    len_in_bytes /= 32; /* caller being responsible for accordingly large+                         * buffer. hash_to_field passes one with length+                         * divisible by 64, remember? which works... */+    while (--len_in_bytes) {+        sha256_init_h(ctx.h);+        vec_xor(b_i.c, b_0.c, bytes, 32);+        bytes += 32;+        ++b_i.c[32];+        sha256_block_data_order(ctx.h, b_i.c, b_i_blocks / 64);+        sha256_emit(bytes, ctx.h);+    }+}+#endif++/*+ * |nelems| is 'count * m' from spec+ */+static void hash_to_field(vec384 elems[], size_t nelems,+                          const unsigned char *aug, size_t aug_len,+                          const unsigned char *msg, size_t msg_len,+                          const unsigned char *DST, size_t DST_len)+{+    size_t L = sizeof(vec384) + 128/8;  /* ceil((ceil(log2(p)) + k) / 8) */+    size_t len_in_bytes = L * nelems;   /* divisible by 64, hurray!      */+#if !defined(__STDC_VERSION__) || __STDC_VERSION__<199901 \+                               || defined(__STDC_NO_VLA__)+    limb_t *pseudo_random = alloca(len_in_bytes);+#else+    limb_t pseudo_random[len_in_bytes/sizeof(limb_t)];+#endif+    unsigned char *bytes;+    vec768 elem;++    aug_len = aug!=NULL ? aug_len : 0;+    DST_len = DST!=NULL ? DST_len : 0;++    expand_message_xmd((unsigned char *)pseudo_random, len_in_bytes,+                       aug, aug_len, msg, msg_len, DST, DST_len);++    vec_zero(elem, sizeof(elem));+    bytes = (unsigned char *)pseudo_random;+    while (nelems--) {+        limbs_from_be_bytes(elem, bytes, L);+        bytes += L;+        /*+         * L-bytes block % P, output is in Montgomery domain...+         */+        redc_mont_384(elems[0], elem, BLS12_381_P, p0);+        mul_mont_384(elems[0], elems[0], BLS12_381_RRRR, BLS12_381_P, p0);+        elems++;+    }+}++void blst_expand_message_xmd(unsigned char *bytes, size_t len_in_bytes,+                             const unsigned char *msg, size_t msg_len,+                             const unsigned char *DST, size_t DST_len)+{+    size_t buf_len = (len_in_bytes+31) & ((size_t)0-32);+    unsigned char *buf_ptr = bytes;++    if (buf_len > 255*32)+        return;++    if (buf_len != len_in_bytes)+        buf_ptr = alloca(buf_len);++    expand_message_xmd(buf_ptr, len_in_bytes, NULL, 0, msg, msg_len,+                                              DST, DST_len);+    if (buf_ptr != bytes) {+        unsigned char *ptr = buf_ptr;+        while (len_in_bytes--)+            *bytes++ = *ptr++;+        vec_zero(buf_ptr, buf_len);+    }+}
+ vendor/external/blst/src/keygen.c view
@@ -0,0 +1,319 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "consts.h"+#include "bytes.h"+#include "sha256.h"++typedef struct {+    SHA256_CTX ctx;+    unsigned int h_ipad[8];+    unsigned int h_opad[8];+    union { limb_t l[64/sizeof(limb_t)]; unsigned char c[64]; } tail;+} HMAC_SHA256_CTX;++static void HMAC_init(HMAC_SHA256_CTX *ctx, const void *K, size_t K_len)+{+    size_t i;++    if (K == NULL) {            /* reuse h_ipad and h_opad */+        sha256_hcopy(ctx->ctx.h, ctx->h_ipad);+        ctx->ctx.N = 64;+        vec_zero(ctx->ctx.buf, sizeof(ctx->ctx.buf));+        ctx->ctx.off = 0;++        return;+    }++    vec_zero(ctx->tail.c, sizeof(ctx->tail));+    if (K_len > 64) {+        sha256_init(&ctx->ctx);+        sha256_update(&ctx->ctx, K, K_len);+        sha256_final(ctx->tail.c, &ctx->ctx);+    } else {+        sha256_bcopy(ctx->tail.c, K, K_len);+    }++    for (i = 0; i < 64/sizeof(limb_t); i++)+        ctx->tail.l[i] ^= (limb_t)0x3636363636363636;++    sha256_init(&ctx->ctx);+    sha256_update(&ctx->ctx, ctx->tail.c, 64);+    sha256_hcopy(ctx->h_ipad, ctx->ctx.h);++    for (i = 0; i < 64/sizeof(limb_t); i++)+        ctx->tail.l[i] ^= (limb_t)(0x3636363636363636 ^ 0x5c5c5c5c5c5c5c5c);++    sha256_init_h(ctx->h_opad);+    sha256_block_data_order(ctx->h_opad, ctx->tail.c, 1);++    vec_zero(ctx->tail.c, sizeof(ctx->tail));+    ctx->tail.c[32] = 0x80;+    ctx->tail.c[62] = 3;        /* (64+32)*8 in big endian */+    ctx->tail.c[63] = 0;+}++static void HMAC_update(HMAC_SHA256_CTX *ctx, const unsigned char *inp,+                                              size_t len)+{   sha256_update(&ctx->ctx, inp, len);   }++static void HMAC_final(unsigned char md[32], HMAC_SHA256_CTX *ctx)+{+    sha256_final(ctx->tail.c, &ctx->ctx);+    sha256_hcopy(ctx->ctx.h, ctx->h_opad);+    sha256_block_data_order(ctx->ctx.h, ctx->tail.c, 1);+    sha256_emit(md, ctx->ctx.h);+}++static void HKDF_Extract(unsigned char PRK[32],+                         const void *salt, size_t salt_len,+                         const void *IKM,  size_t IKM_len,+#ifndef __BLST_HKDF_TESTMODE__+                         int IKM_fixup,+#endif+                         HMAC_SHA256_CTX *ctx)+{+    unsigned char zero[1] = { 0 };++    HMAC_init(ctx, salt != NULL ? salt : zero, salt_len);+    HMAC_update(ctx, IKM, IKM_len);+#ifndef __BLST_HKDF_TESTMODE__+    if (IKM_fixup) {+        /* Section 2.3 KeyGen in BLS-signature draft */+        HMAC_update(ctx, zero, 1);+    }+#endif+    HMAC_final(PRK, ctx);+}++static void HKDF_Expand(unsigned char *OKM, size_t L,+                        const unsigned char PRK[32],+                        const void *info, size_t info_len,+#ifndef __BLST_HKDF_TESTMODE__+                        int info_fixup,+#endif+                        HMAC_SHA256_CTX *ctx)+{+#if !defined(__STDC_VERSION__) || __STDC_VERSION__<199901 \+                               || defined(__STDC_NO_VLA__)+    unsigned char *info_prime = alloca(info_len + 2 + 1);+#else+    unsigned char info_prime[info_len + 2 + 1];+#endif++    HMAC_init(ctx, PRK, 32);++    if (info_len != 0)+        sha256_bcopy(info_prime, info, info_len);+#ifndef __BLST_HKDF_TESTMODE__+    if (info_fixup) {+        /* Section 2.3 KeyGen in BLS-signature draft */+        info_prime[info_len + 0] = (unsigned char)(L >> 8);+        info_prime[info_len + 1] = (unsigned char)(L);+        info_len += 2;+    }+#endif+    info_prime[info_len] = 1;   /* counter */+    HMAC_update(ctx, info_prime, info_len + 1);+    HMAC_final(ctx->tail.c, ctx);+    while (L > 32) {+        sha256_hcopy((unsigned int *)OKM, (const unsigned int *)ctx->tail.c);+        OKM += 32; L -= 32;+        ++info_prime[info_len]; /* counter */+        HMAC_init(ctx, NULL, 0);+        HMAC_update(ctx, ctx->tail.c, 32);+        HMAC_update(ctx, info_prime, info_len + 1);+        HMAC_final(ctx->tail.c, ctx);+    }+    sha256_bcopy(OKM, ctx->tail.c, L);+}++#ifndef __BLST_HKDF_TESTMODE__+static void keygen(pow256 SK, const void *IKM, size_t IKM_len,+                              const void *salt, size_t salt_len,+                              const void *info, size_t info_len,+                              int version)+{+    struct {+        HMAC_SHA256_CTX ctx;+        unsigned char PRK[32], OKM[48];+        vec512 key;+    } scratch;+    unsigned char salt_prime[32] = "BLS-SIG-KEYGEN-SALT-";++    if (IKM_len < 32 || (version > 4 && salt == NULL)) {+        vec_zero(SK, sizeof(pow256));+        return;+    }++    /*+     * Vet |info| since some callers were caught to be sloppy, e.g.+     * SWIG-4.0-generated Python wrapper...+     */+    info_len = info==NULL ? 0 : info_len;++    if (salt == NULL) {+        salt = salt_prime;+        salt_len = 20;+    }++    if (version == 4) {+        /* salt = H(salt) */+        sha256_init(&scratch.ctx.ctx);+        sha256_update(&scratch.ctx.ctx, salt, salt_len);+        sha256_final(salt_prime, &scratch.ctx.ctx);+        salt = salt_prime;+        salt_len = sizeof(salt_prime);+    }++    while (1) {+        /* PRK = HKDF-Extract(salt, IKM || I2OSP(0, 1)) */+        HKDF_Extract(scratch.PRK, salt, salt_len,+                                  IKM, IKM_len, 1, &scratch.ctx);++        /* OKM = HKDF-Expand(PRK, key_info || I2OSP(L, 2), L) */+        HKDF_Expand(scratch.OKM, sizeof(scratch.OKM), scratch.PRK,+                    info, info_len, 1, &scratch.ctx);++        /* SK = OS2IP(OKM) mod r */+        vec_zero(scratch.key, sizeof(scratch.key));+        limbs_from_be_bytes(scratch.key, scratch.OKM, sizeof(scratch.OKM));+        redc_mont_256(scratch.key, scratch.key, BLS12_381_r, r0);+        /*+         * Given that mul_mont_sparse_256 has special boundary conditions+         * it's appropriate to mention that redc_mont_256 output is fully+         * reduced at this point. Because we started with 384-bit input,+         * one with most significant half smaller than the modulus.+         */+        mul_mont_sparse_256(scratch.key, scratch.key, BLS12_381_rRR,+                            BLS12_381_r, r0);++        if (version < 4 || !vec_is_zero(scratch.key, sizeof(vec256)))+            break;++        /* salt = H(salt) */+        sha256_init(&scratch.ctx.ctx);+        sha256_update(&scratch.ctx.ctx, salt, salt_len);+        sha256_final(salt_prime, &scratch.ctx.ctx);+        salt = salt_prime;+        salt_len = sizeof(salt_prime);+    }++    le_bytes_from_limbs(SK, scratch.key, sizeof(pow256));++    /*+     * scrub the stack just in case next callee inadvertently flashes+     * a fragment across application boundary...+     */+    vec_zero(&scratch, sizeof(scratch));+}++void blst_keygen(pow256 SK, const void *IKM, size_t IKM_len,+                            const void *info, size_t info_len)+{   keygen(SK, IKM, IKM_len, NULL, 0, info, info_len, 4);   }++void blst_keygen_v3(pow256 SK, const void *IKM, size_t IKM_len,+                               const void *info, size_t info_len)+{   keygen(SK, IKM, IKM_len, NULL, 0, info, info_len, 3);   }++void blst_keygen_v4_5(pow256 SK, const void *IKM, size_t IKM_len,+                                 const void *salt, size_t salt_len,+                                 const void *info, size_t info_len)+{   keygen(SK, IKM, IKM_len, salt, salt_len, info, info_len, 4);   }++void blst_keygen_v5(pow256 SK, const void *IKM, size_t IKM_len,+                               const void *salt, size_t salt_len,+                               const void *info, size_t info_len)+{   keygen(SK, IKM, IKM_len, salt, salt_len, info, info_len, 5);   }++/*+ * https://eips.ethereum.org/EIPS/eip-2333+ */+void blst_derive_master_eip2333(pow256 SK, const void *seed, size_t seed_len)+{   keygen(SK, seed, seed_len, NULL, 0, NULL, 0, 4);   }++static void parent_SK_to_lamport_PK(pow256 PK, const pow256 parent_SK,+                                    unsigned int index)+{+    size_t i;+    struct {+        HMAC_SHA256_CTX ctx;+        SHA256_CTX ret;+        unsigned char PRK[32], IKM[32];+        unsigned char lamport[255][32];+    } scratch;++    /* salt = I2OSP(index, 4) */+    unsigned char salt[4] = { (unsigned char)(index>>24),+                              (unsigned char)(index>>16),+                              (unsigned char)(index>>8),+                              (unsigned char)(index) };++    /* IKM = I2OSP(parent_SK, 32) */+    for (i = 0; i < 32; i++)+        scratch.IKM[i] = parent_SK[31-i];++    /* lamport_0 = IKM_to_lamport_SK(IKM, salt) */+    HKDF_Extract(scratch.PRK, salt, sizeof(salt), scratch.IKM, 32, 0,+                 &scratch.ctx);+    HKDF_Expand(scratch.lamport[0], sizeof(scratch.lamport),+                scratch.PRK, NULL, 0, 0, &scratch.ctx);++    vec_zero(scratch.ctx.ctx.buf, sizeof(scratch.ctx.ctx.buf));+    scratch.ctx.ctx.buf[32] = 0x80;+    scratch.ctx.ctx.buf[62] = 1;    /* 32*8 in big endian */+    scratch.ctx.ctx.buf[63] = 0;+    for (i = 0; i < 255; i++) {+        /* lamport_PK = lamport_PK | SHA256(lamport_0[i]) */+        sha256_init_h(scratch.ctx.ctx.h);+        sha256_bcopy(scratch.ctx.ctx.buf, scratch.lamport[i], 32);+        sha256_block_data_order(scratch.ctx.ctx.h, scratch.ctx.ctx.buf, 1);+        sha256_emit(scratch.lamport[i], scratch.ctx.ctx.h);+    }++    /* compressed_lamport_PK = SHA256(lamport_PK) */+    sha256_init(&scratch.ret);+    sha256_update(&scratch.ret, scratch.lamport, sizeof(scratch.lamport));++    /* not_IKM = flip_bits(IKM) */+    for (i = 0; i< 32; i++)+        scratch.IKM[i] = ~scratch.IKM[i];++    /* lamport_1 = IKM_to_lamport_SK(not_IKM, salt) */+    HKDF_Extract(scratch.PRK, salt, sizeof(salt), scratch.IKM, 32, 0,+                 &scratch.ctx);+    HKDF_Expand(scratch.lamport[0], sizeof(scratch.lamport),+                scratch.PRK, NULL, 0, 0, &scratch.ctx);++    vec_zero(scratch.ctx.ctx.buf, sizeof(scratch.ctx.ctx.buf));+    scratch.ctx.ctx.buf[32] = 0x80;+    scratch.ctx.ctx.buf[62] = 1;+    for (i = 0; i < 255; i++) {+        /* lamport_PK = lamport_PK | SHA256(lamport_1[i]) */+        sha256_init_h(scratch.ctx.ctx.h);+        sha256_bcopy(scratch.ctx.ctx.buf, scratch.lamport[i], 32);+        sha256_block_data_order(scratch.ctx.ctx.h, scratch.ctx.ctx.buf, 1);+        sha256_emit(scratch.lamport[i], scratch.ctx.ctx.h);+    }++    /* compressed_lamport_PK = SHA256(lamport_PK) */+    sha256_update(&scratch.ret, scratch.lamport, sizeof(scratch.lamport));+    sha256_final(PK, &scratch.ret);++    /*+     * scrub the stack just in case next callee inadvertently flashes+     * a fragment across application boundary...+     */+    vec_zero(&scratch, sizeof(scratch));+}++void blst_derive_child_eip2333(pow256 SK, const pow256 parent_SK,+                               unsigned int child_index)+{+    parent_SK_to_lamport_PK(SK, parent_SK, child_index);+    keygen(SK, SK, sizeof(pow256), NULL, 0, NULL, 0, 4);+}+#endif
+ vendor/external/blst/src/map_to_g1.c view
@@ -0,0 +1,559 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "point.h"+#include "fields.h"++/*+ * y^2 = x^3 + A'*x + B', isogenous one+ */+static const vec384 Aprime_E1 = {+    /* (0x00144698a3b8e9433d693a02c96d4982b0ea985383ee66a8+          d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d << 384) % P */+    TO_LIMB_T(0x2f65aa0e9af5aa51), TO_LIMB_T(0x86464c2d1e8416c3),+    TO_LIMB_T(0xb85ce591b7bd31e2), TO_LIMB_T(0x27e11c91b5f24e7c),+    TO_LIMB_T(0x28376eda6bfc1835), TO_LIMB_T(0x155455c3e5071d85)+};+static const vec384 Bprime_E1 = {+    /* (0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070+          a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0 << 384) % P */+    TO_LIMB_T(0xfb996971fe22a1e0), TO_LIMB_T(0x9aa93eb35b742d6f),+    TO_LIMB_T(0x8c476013de99c5c4), TO_LIMB_T(0x873e27c3a221e571),+    TO_LIMB_T(0xca72b5e45a52d888), TO_LIMB_T(0x06824061418a386b)+};++static void map_fp_times_Zz(vec384 map[], const vec384 isogeny_map[],+                            const vec384 Zz_powers[], size_t n)+{+    while (n--)+        mul_fp(map[n], isogeny_map[n], Zz_powers[n]);+}++static void map_fp(vec384 acc, const vec384 x, const vec384 map[], size_t n)+{+    while (n--) {+        mul_fp(acc, acc, x);+        add_fp(acc, acc, map[n]);+    }+}++static void isogeny_map_to_E1(POINTonE1 *out, const POINTonE1 *p)+{+    /*+     * x = x_num / x_den, where+     * x_num = k_(1,11) * x'^11 + k_(1,10) * x'^10 + k_(1,9) * x'^9 ++     *         ... + k_(1,0)+     * ...+     */+    static const vec384 isogeny_map_x_num[] = { /*  (k_(1,*)<<384) % P  */+      { TO_LIMB_T(0x4d18b6f3af00131c), TO_LIMB_T(0x19fa219793fee28c),+        TO_LIMB_T(0x3f2885f1467f19ae), TO_LIMB_T(0x23dcea34f2ffb304),+        TO_LIMB_T(0xd15b58d2ffc00054), TO_LIMB_T(0x0913be200a20bef4)  },+      { TO_LIMB_T(0x898985385cdbbd8b), TO_LIMB_T(0x3c79e43cc7d966aa),+        TO_LIMB_T(0x1597e193f4cd233a), TO_LIMB_T(0x8637ef1e4d6623ad),+        TO_LIMB_T(0x11b22deed20d827b), TO_LIMB_T(0x07097bc5998784ad)  },+      { TO_LIMB_T(0xa542583a480b664b), TO_LIMB_T(0xfc7169c026e568c6),+        TO_LIMB_T(0x5ba2ef314ed8b5a6), TO_LIMB_T(0x5b5491c05102f0e7),+        TO_LIMB_T(0xdf6e99707d2a0079), TO_LIMB_T(0x0784151ed7605524)  },+      { TO_LIMB_T(0x494e212870f72741), TO_LIMB_T(0xab9be52fbda43021),+        TO_LIMB_T(0x26f5577994e34c3d), TO_LIMB_T(0x049dfee82aefbd60),+        TO_LIMB_T(0x65dadd7828505289), TO_LIMB_T(0x0e93d431ea011aeb)  },+      { TO_LIMB_T(0x90ee774bd6a74d45), TO_LIMB_T(0x7ada1c8a41bfb185),+        TO_LIMB_T(0x0f1a8953b325f464), TO_LIMB_T(0x104c24211be4805c),+        TO_LIMB_T(0x169139d319ea7a8f), TO_LIMB_T(0x09f20ead8e532bf6)  },+      { TO_LIMB_T(0x6ddd93e2f43626b7), TO_LIMB_T(0xa5482c9aa1ccd7bd),+        TO_LIMB_T(0x143245631883f4bd), TO_LIMB_T(0x2e0a94ccf77ec0db),+        TO_LIMB_T(0xb0282d480e56489f), TO_LIMB_T(0x18f4bfcbb4368929)  },+      { TO_LIMB_T(0x23c5f0c953402dfd), TO_LIMB_T(0x7a43ff6958ce4fe9),+        TO_LIMB_T(0x2c390d3d2da5df63), TO_LIMB_T(0xd0df5c98e1f9d70f),+        TO_LIMB_T(0xffd89869a572b297), TO_LIMB_T(0x1277ffc72f25e8fe)  },+      { TO_LIMB_T(0x79f4f0490f06a8a6), TO_LIMB_T(0x85f894a88030fd81),+        TO_LIMB_T(0x12da3054b18b6410), TO_LIMB_T(0xe2a57f6505880d65),+        TO_LIMB_T(0xbba074f260e400f1), TO_LIMB_T(0x08b76279f621d028)  },+      { TO_LIMB_T(0xe67245ba78d5b00b), TO_LIMB_T(0x8456ba9a1f186475),+        TO_LIMB_T(0x7888bff6e6b33bb4), TO_LIMB_T(0xe21585b9a30f86cb),+        TO_LIMB_T(0x05a69cdcef55feee), TO_LIMB_T(0x09e699dd9adfa5ac)  },+      { TO_LIMB_T(0x0de5c357bff57107), TO_LIMB_T(0x0a0db4ae6b1a10b2),+        TO_LIMB_T(0xe256bb67b3b3cd8d), TO_LIMB_T(0x8ad456574e9db24f),+        TO_LIMB_T(0x0443915f50fd4179), TO_LIMB_T(0x098c4bf7de8b6375)  },+      { TO_LIMB_T(0xe6b0617e7dd929c7), TO_LIMB_T(0xfe6e37d442537375),+        TO_LIMB_T(0x1dafdeda137a489e), TO_LIMB_T(0xe4efd1ad3f767ceb),+        TO_LIMB_T(0x4a51d8667f0fe1cf), TO_LIMB_T(0x054fdf4bbf1d821c)  },+      { TO_LIMB_T(0x72db2a50658d767b), TO_LIMB_T(0x8abf91faa257b3d5),+        TO_LIMB_T(0xe969d6833764ab47), TO_LIMB_T(0x464170142a1009eb),+        TO_LIMB_T(0xb14f01aadb30be2f), TO_LIMB_T(0x18ae6a856f40715d)  }+    };+    /* ...+     * x_den = x'^10 + k_(2,9) * x'^9 + k_(2,8) * x'^8 + ... + k_(2,0)+     */+    static const vec384 isogeny_map_x_den[] = { /*  (k_(2,*)<<384) % P  */+      { TO_LIMB_T(0xb962a077fdb0f945), TO_LIMB_T(0xa6a9740fefda13a0),+        TO_LIMB_T(0xc14d568c3ed6c544), TO_LIMB_T(0xb43fc37b908b133e),+        TO_LIMB_T(0x9c0b3ac929599016), TO_LIMB_T(0x0165aa6c93ad115f)  },+      { TO_LIMB_T(0x23279a3ba506c1d9), TO_LIMB_T(0x92cfca0a9465176a),+        TO_LIMB_T(0x3b294ab13755f0ff), TO_LIMB_T(0x116dda1c5070ae93),+        TO_LIMB_T(0xed4530924cec2045), TO_LIMB_T(0x083383d6ed81f1ce)  },+      { TO_LIMB_T(0x9885c2a6449fecfc), TO_LIMB_T(0x4a2b54ccd37733f0),+        TO_LIMB_T(0x17da9ffd8738c142), TO_LIMB_T(0xa0fba72732b3fafd),+        TO_LIMB_T(0xff364f36e54b6812), TO_LIMB_T(0x0f29c13c660523e2)  },+      { TO_LIMB_T(0xe349cc118278f041), TO_LIMB_T(0xd487228f2f3204fb),+        TO_LIMB_T(0xc9d325849ade5150), TO_LIMB_T(0x43a92bd69c15c2df),+        TO_LIMB_T(0x1c2c7844bc417be4), TO_LIMB_T(0x12025184f407440c)  },+      { TO_LIMB_T(0x587f65ae6acb057b), TO_LIMB_T(0x1444ef325140201f),+        TO_LIMB_T(0xfbf995e71270da49), TO_LIMB_T(0xccda066072436a42),+        TO_LIMB_T(0x7408904f0f186bb2), TO_LIMB_T(0x13b93c63edf6c015)  },+      { TO_LIMB_T(0xfb918622cd141920), TO_LIMB_T(0x4a4c64423ecaddb4),+        TO_LIMB_T(0x0beb232927f7fb26), TO_LIMB_T(0x30f94df6f83a3dc2),+        TO_LIMB_T(0xaeedd424d780f388), TO_LIMB_T(0x06cc402dd594bbeb)  },+      { TO_LIMB_T(0xd41f761151b23f8f), TO_LIMB_T(0x32a92465435719b3),+        TO_LIMB_T(0x64f436e888c62cb9), TO_LIMB_T(0xdf70a9a1f757c6e4),+        TO_LIMB_T(0x6933a38d5b594c81), TO_LIMB_T(0x0c6f7f7237b46606)  },+      { TO_LIMB_T(0x693c08747876c8f7), TO_LIMB_T(0x22c9850bf9cf80f0),+        TO_LIMB_T(0x8e9071dab950c124), TO_LIMB_T(0x89bc62d61c7baf23),+        TO_LIMB_T(0xbc6be2d8dad57c23), TO_LIMB_T(0x17916987aa14a122)  },+      { TO_LIMB_T(0x1be3ff439c1316fd), TO_LIMB_T(0x9965243a7571dfa7),+        TO_LIMB_T(0xc7f7f62962f5cd81), TO_LIMB_T(0x32c6aa9af394361c),+        TO_LIMB_T(0xbbc2ee18e1c227f4), TO_LIMB_T(0x0c102cbac531bb34)  },+      { TO_LIMB_T(0x997614c97bacbf07), TO_LIMB_T(0x61f86372b99192c0),+        TO_LIMB_T(0x5b8c95fc14353fc3), TO_LIMB_T(0xca2b066c2a87492f),+        TO_LIMB_T(0x16178f5bbf698711), TO_LIMB_T(0x12a6dcd7f0f4e0e8)  }+    };+    /*+     * y = y' * y_num / y_den, where+     * y_num = k_(3,15) * x'^15 + k_(3,14) * x'^14 + k_(3,13) * x'^13 ++     *         ... + k_(3,0)+     * ...+     */+    static const vec384 isogeny_map_y_num[] = { /*  (k_(3,*)<<384) % P  */+      { TO_LIMB_T(0x2b567ff3e2837267), TO_LIMB_T(0x1d4d9e57b958a767),+        TO_LIMB_T(0xce028fea04bd7373), TO_LIMB_T(0xcc31a30a0b6cd3df),+        TO_LIMB_T(0x7d7b18a682692693), TO_LIMB_T(0x0d300744d42a0310)  },+      { TO_LIMB_T(0x99c2555fa542493f), TO_LIMB_T(0xfe7f53cc4874f878),+        TO_LIMB_T(0x5df0608b8f97608a), TO_LIMB_T(0x14e03832052b49c8),+        TO_LIMB_T(0x706326a6957dd5a4), TO_LIMB_T(0x0a8dadd9c2414555)  },+      { TO_LIMB_T(0x13d942922a5cf63a), TO_LIMB_T(0x357e33e36e261e7d),+        TO_LIMB_T(0xcf05a27c8456088d), TO_LIMB_T(0x0000bd1de7ba50f0),+        TO_LIMB_T(0x83d0c7532f8c1fde), TO_LIMB_T(0x13f70bf38bbf2905)  },+      { TO_LIMB_T(0x5c57fd95bfafbdbb), TO_LIMB_T(0x28a359a65e541707),+        TO_LIMB_T(0x3983ceb4f6360b6d), TO_LIMB_T(0xafe19ff6f97e6d53),+        TO_LIMB_T(0xb3468f4550192bf7), TO_LIMB_T(0x0bb6cde49d8ba257)  },+      { TO_LIMB_T(0x590b62c7ff8a513f), TO_LIMB_T(0x314b4ce372cacefd),+        TO_LIMB_T(0x6bef32ce94b8a800), TO_LIMB_T(0x6ddf84a095713d5f),+        TO_LIMB_T(0x64eace4cb0982191), TO_LIMB_T(0x0386213c651b888d)  },+      { TO_LIMB_T(0xa5310a31111bbcdd), TO_LIMB_T(0xa14ac0f5da148982),+        TO_LIMB_T(0xf9ad9cc95423d2e9), TO_LIMB_T(0xaa6ec095283ee4a7),+        TO_LIMB_T(0xcf5b1f022e1c9107), TO_LIMB_T(0x01fddf5aed881793)  },+      { TO_LIMB_T(0x65a572b0d7a7d950), TO_LIMB_T(0xe25c2d8183473a19),+        TO_LIMB_T(0xc2fcebe7cb877dbd), TO_LIMB_T(0x05b2d36c769a89b0),+        TO_LIMB_T(0xba12961be86e9efb), TO_LIMB_T(0x07eb1b29c1dfde1f)  },+      { TO_LIMB_T(0x93e09572f7c4cd24), TO_LIMB_T(0x364e929076795091),+        TO_LIMB_T(0x8569467e68af51b5), TO_LIMB_T(0xa47da89439f5340f),+        TO_LIMB_T(0xf4fa918082e44d64), TO_LIMB_T(0x0ad52ba3e6695a79)  },+      { TO_LIMB_T(0x911429844e0d5f54), TO_LIMB_T(0xd03f51a3516bb233),+        TO_LIMB_T(0x3d587e5640536e66), TO_LIMB_T(0xfa86d2a3a9a73482),+        TO_LIMB_T(0xa90ed5adf1ed5537), TO_LIMB_T(0x149c9c326a5e7393)  },+      { TO_LIMB_T(0x462bbeb03c12921a), TO_LIMB_T(0xdc9af5fa0a274a17),+        TO_LIMB_T(0x9a558ebde836ebed), TO_LIMB_T(0x649ef8f11a4fae46),+        TO_LIMB_T(0x8100e1652b3cdc62), TO_LIMB_T(0x1862bd62c291dacb)  },+      { TO_LIMB_T(0x05c9b8ca89f12c26), TO_LIMB_T(0x0194160fa9b9ac4f),+        TO_LIMB_T(0x6a643d5a6879fa2c), TO_LIMB_T(0x14665bdd8846e19d),+        TO_LIMB_T(0xbb1d0d53af3ff6bf), TO_LIMB_T(0x12c7e1c3b28962e5)  },+      { TO_LIMB_T(0xb55ebf900b8a3e17), TO_LIMB_T(0xfedc77ec1a9201c4),+        TO_LIMB_T(0x1f07db10ea1a4df4), TO_LIMB_T(0x0dfbd15dc41a594d),+        TO_LIMB_T(0x389547f2334a5391), TO_LIMB_T(0x02419f98165871a4)  },+      { TO_LIMB_T(0xb416af000745fc20), TO_LIMB_T(0x8e563e9d1ea6d0f5),+        TO_LIMB_T(0x7c763e17763a0652), TO_LIMB_T(0x01458ef0159ebbef),+        TO_LIMB_T(0x8346fe421f96bb13), TO_LIMB_T(0x0d2d7b829ce324d2)  },+      { TO_LIMB_T(0x93096bb538d64615), TO_LIMB_T(0x6f2a2619951d823a),+        TO_LIMB_T(0x8f66b3ea59514fa4), TO_LIMB_T(0xf563e63704f7092f),+        TO_LIMB_T(0x724b136c4cf2d9fa), TO_LIMB_T(0x046959cfcfd0bf49)  },+      { TO_LIMB_T(0xea748d4b6e405346), TO_LIMB_T(0x91e9079c2c02d58f),+        TO_LIMB_T(0x41064965946d9b59), TO_LIMB_T(0xa06731f1d2bbe1ee),+        TO_LIMB_T(0x07f897e267a33f1b), TO_LIMB_T(0x1017290919210e5f)  },+      { TO_LIMB_T(0x872aa6c17d985097), TO_LIMB_T(0xeecc53161264562a),+        TO_LIMB_T(0x07afe37afff55002), TO_LIMB_T(0x54759078e5be6838),+        TO_LIMB_T(0xc4b92d15db8acca8), TO_LIMB_T(0x106d87d1b51d13b9)  }+    };+    /* ...+     * y_den = x'^15 + k_(4,14) * x'^14 + k_(4,13) * x'^13 + ... + k_(4,0)+     */+    static const vec384 isogeny_map_y_den[] = { /*  (k_(4,*)<<384) % P  */+      { TO_LIMB_T(0xeb6c359d47e52b1c), TO_LIMB_T(0x18ef5f8a10634d60),+        TO_LIMB_T(0xddfa71a0889d5b7e), TO_LIMB_T(0x723e71dcc5fc1323),+        TO_LIMB_T(0x52f45700b70d5c69), TO_LIMB_T(0x0a8b981ee47691f1)  },+      { TO_LIMB_T(0x616a3c4f5535b9fb), TO_LIMB_T(0x6f5f037395dbd911),+        TO_LIMB_T(0xf25f4cc5e35c65da), TO_LIMB_T(0x3e50dffea3c62658),+        TO_LIMB_T(0x6a33dca523560776), TO_LIMB_T(0x0fadeff77b6bfe3e)  },+      { TO_LIMB_T(0x2be9b66df470059c), TO_LIMB_T(0x24a2c159a3d36742),+        TO_LIMB_T(0x115dbe7ad10c2a37), TO_LIMB_T(0xb6634a652ee5884d),+        TO_LIMB_T(0x04fe8bb2b8d81af4), TO_LIMB_T(0x01c2a7a256fe9c41)  },+      { TO_LIMB_T(0xf27bf8ef3b75a386), TO_LIMB_T(0x898b367476c9073f),+        TO_LIMB_T(0x24482e6b8c2f4e5f), TO_LIMB_T(0xc8e0bbd6fe110806),+        TO_LIMB_T(0x59b0c17f7631448a), TO_LIMB_T(0x11037cd58b3dbfbd)  },+      { TO_LIMB_T(0x31c7912ea267eec6), TO_LIMB_T(0x1dbf6f1c5fcdb700),+        TO_LIMB_T(0xd30d4fe3ba86fdb1), TO_LIMB_T(0x3cae528fbee9a2a4),+        TO_LIMB_T(0xb1cce69b6aa9ad9a), TO_LIMB_T(0x044393bb632d94fb)  },+      { TO_LIMB_T(0xc66ef6efeeb5c7e8), TO_LIMB_T(0x9824c289dd72bb55),+        TO_LIMB_T(0x71b1a4d2f119981d), TO_LIMB_T(0x104fc1aafb0919cc),+        TO_LIMB_T(0x0e49df01d942a628), TO_LIMB_T(0x096c3a09773272d4)  },+      { TO_LIMB_T(0x9abc11eb5fadeff4), TO_LIMB_T(0x32dca50a885728f0),+        TO_LIMB_T(0xfb1fa3721569734c), TO_LIMB_T(0xc4b76271ea6506b3),+        TO_LIMB_T(0xd466a75599ce728e), TO_LIMB_T(0x0c81d4645f4cb6ed)  },+      { TO_LIMB_T(0x4199f10e5b8be45b), TO_LIMB_T(0xda64e495b1e87930),+        TO_LIMB_T(0xcb353efe9b33e4ff), TO_LIMB_T(0x9e9efb24aa6424c6),+        TO_LIMB_T(0xf08d33680a237465), TO_LIMB_T(0x0d3378023e4c7406)  },+      { TO_LIMB_T(0x7eb4ae92ec74d3a5), TO_LIMB_T(0xc341b4aa9fac3497),+        TO_LIMB_T(0x5be603899e907687), TO_LIMB_T(0x03bfd9cca75cbdeb),+        TO_LIMB_T(0x564c2935a96bfa93), TO_LIMB_T(0x0ef3c33371e2fdb5)  },+      { TO_LIMB_T(0x7ee91fd449f6ac2e), TO_LIMB_T(0xe5d5bd5cb9357a30),+        TO_LIMB_T(0x773a8ca5196b1380), TO_LIMB_T(0xd0fda172174ed023),+        TO_LIMB_T(0x6cb95e0fa776aead), TO_LIMB_T(0x0d22d5a40cec7cff)  },+      { TO_LIMB_T(0xf727e09285fd8519), TO_LIMB_T(0xdc9d55a83017897b),+        TO_LIMB_T(0x7549d8bd057894ae), TO_LIMB_T(0x178419613d90d8f8),+        TO_LIMB_T(0xfce95ebdeb5b490a), TO_LIMB_T(0x0467ffaef23fc49e)  },+      { TO_LIMB_T(0xc1769e6a7c385f1b), TO_LIMB_T(0x79bc930deac01c03),+        TO_LIMB_T(0x5461c75a23ede3b5), TO_LIMB_T(0x6e20829e5c230c45),+        TO_LIMB_T(0x828e0f1e772a53cd), TO_LIMB_T(0x116aefa749127bff)  },+      { TO_LIMB_T(0x101c10bf2744c10a), TO_LIMB_T(0xbbf18d053a6a3154),+        TO_LIMB_T(0xa0ecf39ef026f602), TO_LIMB_T(0xfc009d4996dc5153),+        TO_LIMB_T(0xb9000209d5bd08d3), TO_LIMB_T(0x189e5fe4470cd73c)  },+      { TO_LIMB_T(0x7ebd546ca1575ed2), TO_LIMB_T(0xe47d5a981d081b55),+        TO_LIMB_T(0x57b2b625b6d4ca21), TO_LIMB_T(0xb0a1ba04228520cc),+        TO_LIMB_T(0x98738983c2107ff3), TO_LIMB_T(0x13dddbc4799d81d6)  },+      { TO_LIMB_T(0x09319f2e39834935), TO_LIMB_T(0x039e952cbdb05c21),+        TO_LIMB_T(0x55ba77a9a2f76493), TO_LIMB_T(0xfd04e3dfc6086467),+        TO_LIMB_T(0xfb95832e7d78742e), TO_LIMB_T(0x0ef9c24eccaf5e0e)  }+    };+    vec384 Zz_powers[15], map[15], xn, xd, yn, yd;++    /* lay down Z^2 powers in descending order                          */+    sqr_fp(Zz_powers[14], p->Z);                        /* ZZ^1         */+#ifdef __OPTIMIZE_SIZE__+    for (size_t i = 14; i > 0; i--)+        mul_fp(Zz_powers[i-1], Zz_powers[i], Zz_powers[14]);+#else+    sqr_fp(Zz_powers[13], Zz_powers[14]);               /* ZZ^2  1+1    */+    mul_fp(Zz_powers[12], Zz_powers[14], Zz_powers[13]);/* ZZ^3  2+1    */+    sqr_fp(Zz_powers[11], Zz_powers[13]);               /* ZZ^4  2+2    */+    mul_fp(Zz_powers[10], Zz_powers[13], Zz_powers[12]);/* ZZ^5  2+3    */+    sqr_fp(Zz_powers[9],  Zz_powers[12]);               /* ZZ^6  3+3    */+    mul_fp(Zz_powers[8],  Zz_powers[12], Zz_powers[11]);/* ZZ^7  3+4    */+    sqr_fp(Zz_powers[7],  Zz_powers[11]);               /* ZZ^8  4+4    */+    mul_fp(Zz_powers[6],  Zz_powers[11], Zz_powers[10]);/* ZZ^9  4+5    */+    sqr_fp(Zz_powers[5],  Zz_powers[10]);               /* ZZ^10 5+5    */+    mul_fp(Zz_powers[4],  Zz_powers[10], Zz_powers[9]); /* ZZ^11 5+6    */+    sqr_fp(Zz_powers[3],  Zz_powers[9]);                /* ZZ^12 6+6    */+    mul_fp(Zz_powers[2],  Zz_powers[9],  Zz_powers[8]); /* ZZ^13 6+7    */+    sqr_fp(Zz_powers[1],  Zz_powers[8]);                /* ZZ^14 7+7    */+    mul_fp(Zz_powers[0],  Zz_powers[8],  Zz_powers[7]); /* ZZ^15 7+8    */+#endif++    map_fp_times_Zz(map, isogeny_map_x_num, Zz_powers + 4, 11);+    mul_fp(xn, p->X, isogeny_map_x_num[11]);+    add_fp(xn, xn, map[10]);+    map_fp(xn, p->X, map, 10);++    map_fp_times_Zz(map, isogeny_map_x_den, Zz_powers + 5, 10);+    add_fp(xd, p->X, map[9]);+    map_fp(xd, p->X, map, 9);+    mul_fp(xd, xd, Zz_powers[14]);      /* xd *= Z^2                    */++    map_fp_times_Zz(map, isogeny_map_y_num, Zz_powers, 15);+    mul_fp(yn, p->X, isogeny_map_y_num[15]);+    add_fp(yn, yn, map[14]);+    map_fp(yn, p->X, map, 14);+    mul_fp(yn, yn, p->Y);               /* yn *= Y                      */++    map_fp_times_Zz(map, isogeny_map_y_den, Zz_powers, 15);+    add_fp(yd, p->X, map[14]);+    map_fp(yd, p->X, map, 14);+    mul_fp(Zz_powers[14], Zz_powers[14], p->Z);+    mul_fp(yd, yd, Zz_powers[14]);      /* yd *= Z^3                    */++    /* convert (xn, xd, yn, yd) to Jacobian coordinates                 */+    mul_fp(out->Z, xd, yd);             /* Z = xd * yd                  */+    mul_fp(out->X, xn, yd);+    mul_fp(out->X, out->X, out->Z);     /* X = xn * xd * yd^2           */+    sqr_fp(out->Y, out->Z);+    mul_fp(out->Y, out->Y, xd);+    mul_fp(out->Y, out->Y, yn);         /* Y = yn * xd^3 * yd^2         */+}++static void map_to_isogenous_E1(POINTonE1 *p, const vec384 u)+{+    static const vec384 minus_A = { /* P - A */+        TO_LIMB_T(0x8a9955f1650a005a), TO_LIMB_T(0x9865b3d192cfe93c),+        TO_LIMB_T(0xaed3ed0f3ef3c441), TO_LIMB_T(0x3c962ef33d92c442),+        TO_LIMB_T(0x22e438dbd74f94a2), TO_LIMB_T(0x04acbc265478c915)+    };+    static const vec384 Z = {       /* (11<<384) % P */+        TO_LIMB_T(0x886c00000023ffdc), TO_LIMB_T(0x0f70008d3090001d),+        TO_LIMB_T(0x77672417ed5828c3), TO_LIMB_T(0x9dac23e943dc1740),+        TO_LIMB_T(0x50553f1b9c131521), TO_LIMB_T(0x078c712fbe0ab6e8)+    };+    static const vec384 sqrt_minus_ZZZ = {+        TO_LIMB_T(0x43b571cad3215f1f), TO_LIMB_T(0xccb460ef1c702dc2),+        TO_LIMB_T(0x742d884f4f97100b), TO_LIMB_T(0xdb2c3e3238a3382b),+        TO_LIMB_T(0xe40f3fa13fce8f88), TO_LIMB_T(0x0073a2af9892a2ff)+    };+    static const vec384 ZxA = {+        TO_LIMB_T(0x7f674ea0a8915178), TO_LIMB_T(0xb0f945fc13b8fa65),+        TO_LIMB_T(0x4b46759a38e87d76), TO_LIMB_T(0x2e7a929641bbb6a1),+        TO_LIMB_T(0x1668ddfa462bf6b6), TO_LIMB_T(0x00960e2ed1cf294c)+    };+    vec384 uu, tv2, x2n, gx1, gxd, y2;+#if 0+    vec384 xn, x1n, xd, y, y1, Zuu, tv4;+#else+# define xn     p->X+# define y      p->Y+# define xd     p->Z+# define x1n    xn+# define y1     y+# define Zuu    x2n+# define tv4    y1+#endif+#define sgn0_fp(a) (sgn0_pty_mont_384((a), BLS12_381_P, p0) & 1)+    bool_t e1, e2;++    /*+     * as per map_to_curve() from poc/sswu_opt.sage at+     * https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve+     */+    /* x numerator variants                                             */+    sqr_fp(uu, u);                      /* uu = u^2                     */+    mul_fp(Zuu, Z, uu);                 /* Zuu = Z * uu                 */+    sqr_fp(tv2, Zuu);                   /* tv2 = Zuu^2                  */+    add_fp(tv2, tv2, Zuu);              /* tv2 = tv2 + Zuu              */+    add_fp(x1n, tv2, BLS12_381_Rx.p);   /* x1n = tv2 + 1                */+    mul_fp(x1n, x1n, Bprime_E1);        /* x1n = x1n * B                */+    mul_fp(x2n, Zuu, x1n);              /* x2n = Zuu * x1n              */++    /* x denumenator                                                    */+    mul_fp(xd, minus_A, tv2);           /* xd = -A * tv2                */+    e1 = vec_is_zero(xd, sizeof(xd));   /* e1 = xd == 0                 */+    vec_select(xd, ZxA, xd, sizeof(xd), e1);    /*              # If xd == 0, set xd = Z*A */++    /* y numerators variants                                            */+    sqr_fp(tv2, xd);                    /* tv2 = xd^2                   */+    mul_fp(gxd, xd, tv2);               /* gxd = xd^3                   */+    mul_fp(tv2, Aprime_E1, tv2);        /* tv2 = A * tv2                */+    sqr_fp(gx1, x1n);                   /* gx1 = x1n^2                  */+    add_fp(gx1, gx1, tv2);              /* gx1 = gx1 + tv2      # x1n^2 + A*xd^2 */+    mul_fp(gx1, gx1, x1n);              /* gx1 = gx1 * x1n      # x1n^3 + A*x1n*xd^2 */+    mul_fp(tv2, Bprime_E1, gxd);        /* tv2 = B * gxd                */+    add_fp(gx1, gx1, tv2);              /* gx1 = gx1 + tv2      # x1^3 + A*x1*xd^2 + B*xd^3 */+    sqr_fp(tv4, gxd);                   /* tv4 = gxd^2                  */+    mul_fp(tv2, gx1, gxd);              /* tv2 = gx1 * gxd              */+    mul_fp(tv4, tv4, tv2);              /* tv4 = tv4 * tv2      # gx1*gxd^3 */+    e2 = recip_sqrt_fp(y1, tv4);        /* y1 = tv4^c1          # (gx1*gxd^3)^((p-3)/4) */+    mul_fp(y1, y1, tv2);                /* y1 = y1 * tv2        # gx1*gxd*y1 */+    mul_fp(y2, y1, sqrt_minus_ZZZ);     /* y2 = y1 * c2         # y2 = y1*sqrt(-Z^3) */+    mul_fp(y2, y2, uu);                 /* y2 = y2 * uu                 */+    mul_fp(y2, y2, u);                  /* y2 = y2 * u                  */++    /* choose numerators                                                */+    vec_select(xn, x1n, x2n, sizeof(xn), e2);   /* xn = e2 ? x1n : x2n  */+    vec_select(y, y1, y2, sizeof(y), e2);       /* y  = e2 ? y1 : y2    */++    e1 = sgn0_fp(u);+    e2 = sgn0_fp(y);+    cneg_fp(y, y, e1^e2);               /* fix sign of y                */+                                        /* return (xn, xd, y, 1)        */++    /* convert (xn, xd, y, 1) to Jacobian projective coordinates        */+    mul_fp(p->X, xn, xd);               /* X = xn * xd                  */+    mul_fp(p->Y, y, gxd);               /* Y = y * xd^3                 */+#ifndef xd+    vec_copy(p->Z, xd, sizeof(xd));     /* Z = xd                       */+#else+# undef xn+# undef y+# undef xd+# undef x1n+# undef y1+# undef Zuu+# undef tv4+#endif+#undef sgn0_fp+}++static void POINTonE1_add_n_dbl(POINTonE1 *out, const POINTonE1 *p, size_t n)+{+    POINTonE1_dadd(out, out, p, NULL);+    while(n--)+        POINTonE1_double(out, out);+}++static void POINTonE1_times_minus_z(POINTonE1 *out, const POINTonE1 *in)+{+    POINTonE1_double(out, in);          /*      1: 0x2                  */+    POINTonE1_add_n_dbl(out, in, 2);    /*   2..4: 0x3..0xc             */+    POINTonE1_add_n_dbl(out, in, 3);    /*   5..8: 0xd..0x68            */+    POINTonE1_add_n_dbl(out, in, 9);    /*  9..18: 0x69..0xd200         */+    POINTonE1_add_n_dbl(out, in, 32);   /* 19..51: ..0xd20100000000     */+    POINTonE1_add_n_dbl(out, in, 16);   /* 52..68: ..0xd201000000010000 */+}++/*+ * |u|, |v| are expected to be in Montgomery representation+ */+static void map_to_g1(POINTonE1 *out, const vec384 u, const vec384 v)+{+    POINTonE1 p;++    map_to_isogenous_E1(&p, u);++    if (v != NULL) {+        map_to_isogenous_E1(out, v);    /* borrow |out|                 */+        POINTonE1_dadd(&p, &p, out, Aprime_E1);+    }++    isogeny_map_to_E1(&p, &p);          /* sprinkle isogenous powder    */++    /* clear the cofactor by multiplying |p| by 1-z, 0xd201000000010001 */+    POINTonE1_times_minus_z(out, &p);+    POINTonE1_dadd(out, out, &p, NULL);+}++void blst_map_to_g1(POINTonE1 *out, const vec384 u, const vec384 v)+{   map_to_g1(out, u, v);   }++static void Encode_to_G1(POINTonE1 *p, const unsigned char *msg, size_t msg_len,+                                       const unsigned char *DST, size_t DST_len,+                                       const unsigned char *aug, size_t aug_len)+{+    vec384 u[1];++    hash_to_field(u, 1, aug, aug_len, msg, msg_len, DST, DST_len);+    map_to_g1(p, u[0], NULL);+}++void blst_encode_to_g1(POINTonE1 *p, const unsigned char *msg, size_t msg_len,+                                     const unsigned char *DST, size_t DST_len,+                                     const unsigned char *aug, size_t aug_len)+{   Encode_to_G1(p, msg, msg_len, DST, DST_len, aug, aug_len);   }++static void Hash_to_G1(POINTonE1 *p, const unsigned char *msg, size_t msg_len,+                                     const unsigned char *DST, size_t DST_len,+                                     const unsigned char *aug, size_t aug_len)+{+    vec384 u[2];++    hash_to_field(u, 2, aug, aug_len, msg, msg_len, DST, DST_len);+    map_to_g1(p, u[0], u[1]);+}++void blst_hash_to_g1(POINTonE1 *p, const unsigned char *msg, size_t msg_len,+                                   const unsigned char *DST, size_t DST_len,+                                   const unsigned char *aug, size_t aug_len)+{   Hash_to_G1(p, msg, msg_len, DST, DST_len, aug, aug_len);   }++static void sigma(POINTonE1 *out, const POINTonE1 *in);++#if 0+#ifdef __OPTIMIZE_SIZE__+static void POINTonE1_times_zz_minus_1_div_by_3(POINTonE1 *out,+                                                const POINTonE1 *in)+{+    static const byte zz_minus_1_div_by_3[] = {+        TO_BYTES(0x0000000055555555ULL), TO_BYTES(0x396c8c005555e156)+    };+    size_t n = 126-1;+    const POINTonE1 *dblin = in;++    while(n--) {+        POINTonE1_double(out, dblin);   dblin = out;+        if (is_bit_set(zz_minus_1_div_by_3, n))+            POINTonE1_dadd(out, out, in, NULL);+    }+}+#else+static void POINTonE1_dbl_n_add(POINTonE1 *out, size_t n, const POINTonE1 *p)+{+    while(n--)+        POINTonE1_double(out, out);+    POINTonE1_dadd(out, out, p, NULL);+}++static void POINTonE1_times_zz_minus_1_div_by_3(POINTonE1 *out,+                                                const POINTonE1 *in)+{+    POINTonE1 t3, t5, t7, t11, t85;++    POINTonE1_double(&t7, in);              /* 2P */+    POINTonE1_dadd(&t3, &t7, in, NULL);     /* 3P */+    POINTonE1_dadd(&t5, &t3, &t7, NULL);    /* 5P */+    POINTonE1_dadd(&t7, &t5, &t7, NULL);    /* 7P */+    POINTonE1_double(&t85, &t5);            /* 10P */+    POINTonE1_dadd(&t11, &t85, in, NULL);   /* 11P */+    POINTonE1_dbl_n_add(&t85, 3, &t5);      /* 0x55P */+                                            /* (-0xd201000000010000^2 - 1) / 3 */+    POINTonE1_double(out, &t7);             /* 0xe */+    POINTonE1_dbl_n_add(out, 5,  &t11);     /* 0x1cb */+    POINTonE1_dbl_n_add(out, 3,  &t3);      /* 0xe5b */+    POINTonE1_dbl_n_add(out, 3,  in);       /* 0x72d9 */+    POINTonE1_dbl_n_add(out, 5,  &t3);      /* 0xe5b23 */+    POINTonE1_dbl_n_add(out, 18, &t85);     /* 0x396c8c0055 */+    POINTonE1_dbl_n_add(out, 8,  &t85);     /* 0x396c8c005555 */+    POINTonE1_dbl_n_add(out, 3,  &t7);      /* 0x1cb646002aaaf */+    POINTonE1_dbl_n_add(out, 7,  &t5);      /* 0xe5b23001555785 */+    POINTonE1_dbl_n_add(out, 5,  &t11);     /* 0x1cb646002aaaf0ab */+    POINTonE1_dbl_n_add(out, 41, &t85);     /* 0x396c8c005555e1560000000055 */+    POINTonE1_dbl_n_add(out, 8,  &t85);     /* 0x396c8c005555e156000000005555 */+    POINTonE1_dbl_n_add(out, 8,  &t85);     /* 0x396c8c005555e15600000000555555 */+    POINTonE1_dbl_n_add(out, 8,  &t85);     /* 0x396c8c005555e1560000000055555555 */+}+#endif++static bool_t POINTonE1_in_G1(const POINTonE1 *P)+{+    POINTonE1 t0, t1, t2;++    /* Bowe, S., "Faster subgroup checks for BLS12-381"                   */+    sigma(&t0, P);                        /* σ(P)                         */+    sigma(&t1, &t0);                      /* σ²(P)                        */++    POINTonE1_double(&t0, &t0);           /* 2σ(P)                        */+    POINTonE1_dadd(&t2, &t1, P, NULL);    /* P +  σ²(P)                   */+    POINTonE1_cneg(&t2, 1);               /* - P - σ²(P)                  */+    POINTonE1_dadd(&t2, &t2, &t0, NULL);  /* 2σ(P) - P - σ²(P)            */+    POINTonE1_times_zz_minus_1_div_by_3(  &t0, &t2);+    POINTonE1_cneg(&t1, 1);+    POINTonE1_dadd(&t0, &t0, &t1, NULL);  /* [(z²-1)/3](2σ(P) - P - σ²(P)) */+                                          /* - σ²(P) */+    return vec_is_zero(t0.Z, sizeof(t0.Z));+}+#else+static bool_t POINTonE1_in_G1(const POINTonE1 *P)+{+    POINTonE1 t0, t1;++    /* Scott, M., https://eprint.iacr.org/2021/1130 */+    POINTonE1_times_minus_z(&t0, P);+    POINTonE1_times_minus_z(&t1, &t0);+    POINTonE1_cneg(&t1, 1);             /* [-z²]P   */++    sigma(&t0, P);                      /* σ(P)     */+    sigma(&t0, &t0);                    /* σ²(P)    */++    return POINTonE1_is_equal(&t0, &t1);+}+#endif++int blst_p1_in_g1(const POINTonE1 *p)+{   return (int)POINTonE1_in_G1(p);   }++int blst_p1_affine_in_g1(const POINTonE1_affine *p)+{+    POINTonE1 P;++    vec_copy(P.X, p->X, 2*sizeof(P.X));+    vec_select(P.Z, p->X, BLS12_381_Rx.p, sizeof(P.Z),+                     vec_is_zero(p, sizeof(*p)));++    return (int)POINTonE1_in_G1(&P);+}
+ vendor/external/blst/src/map_to_g2.c view
@@ -0,0 +1,444 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "point.h"+#include "fields.h"++/*+ * y^2 = x^3 + A'*x + B', isogenous one+ */+static const vec384x Aprime_E2 = {      /* 240*i */+  { 0 },+  { TO_LIMB_T(0xe53a000003135242), TO_LIMB_T(0x01080c0fdef80285),+    TO_LIMB_T(0xe7889edbe340f6bd), TO_LIMB_T(0x0b51375126310601),+    TO_LIMB_T(0x02d6985717c744ab), TO_LIMB_T(0x1220b4e979ea5467) }+};+static const vec384x Bprime_E2 = {      /* 1012 + 1012*i */+  { TO_LIMB_T(0x22ea00000cf89db2), TO_LIMB_T(0x6ec832df71380aa4),+    TO_LIMB_T(0x6e1b94403db5a66e), TO_LIMB_T(0x75bf3c53a79473ba),+    TO_LIMB_T(0x3dd3a569412c0a34), TO_LIMB_T(0x125cdb5e74dc4fd1) },+  { TO_LIMB_T(0x22ea00000cf89db2), TO_LIMB_T(0x6ec832df71380aa4),+    TO_LIMB_T(0x6e1b94403db5a66e), TO_LIMB_T(0x75bf3c53a79473ba),+    TO_LIMB_T(0x3dd3a569412c0a34), TO_LIMB_T(0x125cdb5e74dc4fd1) }+};++static void map_fp2_times_Zz(vec384x map[], const vec384x isogeny_map[],+                             const vec384x Zz_powers[], size_t n)+{+    while (n--)+        mul_fp2(map[n], isogeny_map[n], Zz_powers[n]);+}++static void map_fp2(vec384x acc, const vec384x x, const vec384x map[], size_t n)+{+    while (n--) {+        mul_fp2(acc, acc, x);+        add_fp2(acc, acc, map[n]);+    }+}++static void isogeny_map_to_E2(POINTonE2 *out, const POINTonE2 *p)+{+    /*+     * x = x_num / x_den, where+     * x_num = k_(1,3) * x'^3 + k_(1,2) * x'^2 + k_(1,1) * x' + k_(1,0)+     * ...+     */+    static const vec384x isogeny_map_x_num[] = {    /* (k_(1,*)<<384) % P   */+     {{ TO_LIMB_T(0x47f671c71ce05e62), TO_LIMB_T(0x06dd57071206393e),+        TO_LIMB_T(0x7c80cd2af3fd71a2), TO_LIMB_T(0x048103ea9e6cd062),+        TO_LIMB_T(0xc54516acc8d037f6), TO_LIMB_T(0x13808f550920ea41) },+      { TO_LIMB_T(0x47f671c71ce05e62), TO_LIMB_T(0x06dd57071206393e),+        TO_LIMB_T(0x7c80cd2af3fd71a2), TO_LIMB_T(0x048103ea9e6cd062),+        TO_LIMB_T(0xc54516acc8d037f6), TO_LIMB_T(0x13808f550920ea41) }},+     {{ 0 },+      { TO_LIMB_T(0x5fe55555554c71d0), TO_LIMB_T(0x873fffdd236aaaa3),+        TO_LIMB_T(0x6a6b4619b26ef918), TO_LIMB_T(0x21c2888408874945),+        TO_LIMB_T(0x2836cda7028cabc5), TO_LIMB_T(0x0ac73310a7fd5abd) }},+     {{ TO_LIMB_T(0x0a0c5555555971c3), TO_LIMB_T(0xdb0c00101f9eaaae),+        TO_LIMB_T(0xb1fb2f941d797997), TO_LIMB_T(0xd3960742ef416e1c),+        TO_LIMB_T(0xb70040e2c20556f4), TO_LIMB_T(0x149d7861e581393b) },+      { TO_LIMB_T(0xaff2aaaaaaa638e8), TO_LIMB_T(0x439fffee91b55551),+        TO_LIMB_T(0xb535a30cd9377c8c), TO_LIMB_T(0x90e144420443a4a2),+        TO_LIMB_T(0x941b66d3814655e2), TO_LIMB_T(0x0563998853fead5e) }},+     {{ TO_LIMB_T(0x40aac71c71c725ed), TO_LIMB_T(0x190955557a84e38e),+        TO_LIMB_T(0xd817050a8f41abc3), TO_LIMB_T(0xd86485d4c87f6fb1),+        TO_LIMB_T(0x696eb479f885d059), TO_LIMB_T(0x198e1a74328002d2) },+      { 0 }}+    };+    /* ...+     * x_den = x'^2 + k_(2,1) * x' + k_(2,0)+     */+    static const vec384x isogeny_map_x_den[] = {    /* (k_(2,*)<<384) % P   */+     {{ 0 },+      { TO_LIMB_T(0x1f3affffff13ab97), TO_LIMB_T(0xf25bfc611da3ff3e),+        TO_LIMB_T(0xca3757cb3819b208), TO_LIMB_T(0x3e6427366f8cec18),+        TO_LIMB_T(0x03977bc86095b089), TO_LIMB_T(0x04f69db13f39a952) }},+     {{ TO_LIMB_T(0x447600000027552e), TO_LIMB_T(0xdcb8009a43480020),+        TO_LIMB_T(0x6f7ee9ce4a6e8b59), TO_LIMB_T(0xb10330b7c0a95bc6),+        TO_LIMB_T(0x6140b1fcfb1e54b7), TO_LIMB_T(0x0381be097f0bb4e1) },+      { TO_LIMB_T(0x7588ffffffd8557d), TO_LIMB_T(0x41f3ff646e0bffdf),+        TO_LIMB_T(0xf7b1e8d2ac426aca), TO_LIMB_T(0xb3741acd32dbb6f8),+        TO_LIMB_T(0xe9daf5b9482d581f), TO_LIMB_T(0x167f53e0ba7431b8) }}+    };+    /*+     * y = y' * y_num / y_den, where+     * y_num = k_(3,3) * x'^3 + k_(3,2) * x'^2 + k_(3,1) * x' + k_(3,0)+     * ...+     */+    static const vec384x isogeny_map_y_num[] = {    /* (k_(3,*)<<384) % P   */+     {{ TO_LIMB_T(0x96d8f684bdfc77be), TO_LIMB_T(0xb530e4f43b66d0e2),+        TO_LIMB_T(0x184a88ff379652fd), TO_LIMB_T(0x57cb23ecfae804e1),+        TO_LIMB_T(0x0fd2e39eada3eba9), TO_LIMB_T(0x08c8055e31c5d5c3) },+      { TO_LIMB_T(0x96d8f684bdfc77be), TO_LIMB_T(0xb530e4f43b66d0e2),+        TO_LIMB_T(0x184a88ff379652fd), TO_LIMB_T(0x57cb23ecfae804e1),+        TO_LIMB_T(0x0fd2e39eada3eba9), TO_LIMB_T(0x08c8055e31c5d5c3) }},+     {{ 0 },+      { TO_LIMB_T(0xbf0a71c71c91b406), TO_LIMB_T(0x4d6d55d28b7638fd),+        TO_LIMB_T(0x9d82f98e5f205aee), TO_LIMB_T(0xa27aa27b1d1a18d5),+        TO_LIMB_T(0x02c3b2b2d2938e86), TO_LIMB_T(0x0c7d13420b09807f) }},+     {{ TO_LIMB_T(0xd7f9555555531c74), TO_LIMB_T(0x21cffff748daaaa8),+        TO_LIMB_T(0x5a9ad1866c9bbe46), TO_LIMB_T(0x4870a2210221d251),+        TO_LIMB_T(0x4a0db369c0a32af1), TO_LIMB_T(0x02b1ccc429ff56af) },+      { TO_LIMB_T(0xe205aaaaaaac8e37), TO_LIMB_T(0xfcdc000768795556),+        TO_LIMB_T(0x0c96011a8a1537dd), TO_LIMB_T(0x1c06a963f163406e),+        TO_LIMB_T(0x010df44c82a881e6), TO_LIMB_T(0x174f45260f808feb) }},+     {{ TO_LIMB_T(0xa470bda12f67f35c), TO_LIMB_T(0xc0fe38e23327b425),+        TO_LIMB_T(0xc9d3d0f2c6f0678d), TO_LIMB_T(0x1c55c9935b5a982e),+        TO_LIMB_T(0x27f6c0e2f0746764), TO_LIMB_T(0x117c5e6e28aa9054) },+      { 0 }}+    };+    /* ...+     * y_den = x'^3 + k_(4,2) * x'^2 + k_(4,1) * x' + k_(4,0)+     */+    static const vec384x isogeny_map_y_den[] = {    /* (k_(4,*)<<384) % P   */+     {{ TO_LIMB_T(0x0162fffffa765adf), TO_LIMB_T(0x8f7bea480083fb75),+        TO_LIMB_T(0x561b3c2259e93611), TO_LIMB_T(0x11e19fc1a9c875d5),+        TO_LIMB_T(0xca713efc00367660), TO_LIMB_T(0x03c6a03d41da1151) },+      { TO_LIMB_T(0x0162fffffa765adf), TO_LIMB_T(0x8f7bea480083fb75),+        TO_LIMB_T(0x561b3c2259e93611), TO_LIMB_T(0x11e19fc1a9c875d5),+        TO_LIMB_T(0xca713efc00367660), TO_LIMB_T(0x03c6a03d41da1151) }},+     {{ 0 },+      { TO_LIMB_T(0x5db0fffffd3b02c5), TO_LIMB_T(0xd713f52358ebfdba),+        TO_LIMB_T(0x5ea60761a84d161a), TO_LIMB_T(0xbb2c75a34ea6c44a),+        TO_LIMB_T(0x0ac6735921c1119b), TO_LIMB_T(0x0ee3d913bdacfbf6) }},+     {{ TO_LIMB_T(0x66b10000003affc5), TO_LIMB_T(0xcb1400e764ec0030),+        TO_LIMB_T(0xa73e5eb56fa5d106), TO_LIMB_T(0x8984c913a0fe09a9),+        TO_LIMB_T(0x11e10afb78ad7f13), TO_LIMB_T(0x05429d0e3e918f52) },+      { TO_LIMB_T(0x534dffffffc4aae6), TO_LIMB_T(0x5397ff174c67ffcf),+        TO_LIMB_T(0xbff273eb870b251d), TO_LIMB_T(0xdaf2827152870915),+        TO_LIMB_T(0x393a9cbaca9e2dc3), TO_LIMB_T(0x14be74dbfaee5748) }}+    };+    vec384x Zz_powers[3], map[3], xn, xd, yn, yd;++    /* lay down Z^2 powers in descending order                          */+    sqr_fp2(Zz_powers[2], p->Z);                       /* ZZ^1          */+    sqr_fp2(Zz_powers[1], Zz_powers[2]);               /* ZZ^2  1+1     */+    mul_fp2(Zz_powers[0], Zz_powers[2], Zz_powers[1]); /* ZZ^3  2+1     */++    map_fp2_times_Zz(map, isogeny_map_x_num, Zz_powers, 3);+    mul_fp2(xn, p->X, isogeny_map_x_num[3]);+    add_fp2(xn, xn, map[2]);+    map_fp2(xn, p->X, map, 2);++    map_fp2_times_Zz(map, isogeny_map_x_den, Zz_powers + 1, 2);+    add_fp2(xd, p->X, map[1]);+    map_fp2(xd, p->X, map, 1);+    mul_fp2(xd, xd, Zz_powers[2]);      /* xd *= Z^2                    */++    map_fp2_times_Zz(map, isogeny_map_y_num, Zz_powers, 3);+    mul_fp2(yn, p->X, isogeny_map_y_num[3]);+    add_fp2(yn, yn, map[2]);+    map_fp2(yn, p->X, map, 2);+    mul_fp2(yn, yn, p->Y);              /* yn *= Y                      */++    map_fp2_times_Zz(map, isogeny_map_y_den, Zz_powers, 3);+    add_fp2(yd, p->X, map[2]);+    map_fp2(yd, p->X, map, 2);+    mul_fp2(Zz_powers[2], Zz_powers[2], p->Z);+    mul_fp2(yd, yd, Zz_powers[2]);      /* yd *= Z^3                    */++    /* convert (xn, xd, yn, yd) to Jacobian coordinates                 */+    mul_fp2(out->Z, xd, yd);            /* Z = xd * yd                  */+    mul_fp2(out->X, xn, yd);+    mul_fp2(out->X, out->X, out->Z);    /* X = xn * xd * yd^2           */+    sqr_fp2(out->Y, out->Z);+    mul_fp2(out->Y, out->Y, xd);+    mul_fp2(out->Y, out->Y, yn);        /* Y = yn * xd^3 * yd^2         */+}++static void map_to_isogenous_E2(POINTonE2 *p, const vec384x u)+{+    static const vec384x minus_A = {+      { 0 },+      { TO_LIMB_T(0xd4c4fffffcec5869), TO_LIMB_T(0x1da3f3eed25bfd79),+        TO_LIMB_T(0x7fa833c5136fff67), TO_LIMB_T(0x59261433cd540cbd),+        TO_LIMB_T(0x48450f5f2b84682c), TO_LIMB_T(0x07e05d00bf959233) }+    };+    static const vec384x Z = {              /* -2 - i */+      { TO_LIMB_T(0x87ebfffffff9555c), TO_LIMB_T(0x656fffe5da8ffffa),+        TO_LIMB_T(0x0fd0749345d33ad2), TO_LIMB_T(0xd951e663066576f4),+        TO_LIMB_T(0xde291a3d41e980d3), TO_LIMB_T(0x0815664c7dfe040d) },+      { TO_LIMB_T(0x43f5fffffffcaaae), TO_LIMB_T(0x32b7fff2ed47fffd),+        TO_LIMB_T(0x07e83a49a2e99d69), TO_LIMB_T(0xeca8f3318332bb7a),+        TO_LIMB_T(0xef148d1ea0f4c069), TO_LIMB_T(0x040ab3263eff0206) }+    };+    static const vec384x recip_ZZZ = {      /* 1/(Z^3) */+      { TO_LIMB_T(0x65018f5c28f598eb), TO_LIMB_T(0xe6020417f022d916),+        TO_LIMB_T(0xd6327313288369c7), TO_LIMB_T(0x622ded8eb447156f),+        TO_LIMB_T(0xe52a2aee72c2a01f), TO_LIMB_T(0x089812fb8481ffe4) },+      { TO_LIMB_T(0x2574eb851eb8619f), TO_LIMB_T(0xdba2e97912925604),+        TO_LIMB_T(0x67e495a909e7a18e), TO_LIMB_T(0xdf2da23b8145b8f7),+        TO_LIMB_T(0xcf5d3728310ebf6d), TO_LIMB_T(0x11be446236f4c116) }+    };+    static const vec384x magic_ZZZ = {      /* 1/Z^3 = a + b*i */+                                            /* a^2 + b^2 */+      { TO_LIMB_T(0xaa7eb851eb8508e0), TO_LIMB_T(0x1c54fdf360989374),+        TO_LIMB_T(0xc87f2fc6e716c62e), TO_LIMB_T(0x0124aefb1f9efea7),+        TO_LIMB_T(0xb2f8be63e844865c), TO_LIMB_T(0x08b47f775a7ef35a) },+                                            /* (a^2 + b^2)^((P-3)/4) */+      { TO_LIMB_T(0xe4132bbd838cf70a), TO_LIMB_T(0x01d769ac83772c19),+        TO_LIMB_T(0xa83dd6e974c22e45), TO_LIMB_T(0xbc8ec3e777b08dff),+        TO_LIMB_T(0xc035c2042ecf5da3), TO_LIMB_T(0x073929e97f0850bf) }+    };+    static const vec384x ZxA = {            /* 240 - 480*i */+      { TO_LIMB_T(0xe53a000003135242), TO_LIMB_T(0x01080c0fdef80285),+        TO_LIMB_T(0xe7889edbe340f6bd), TO_LIMB_T(0x0b51375126310601),+        TO_LIMB_T(0x02d6985717c744ab), TO_LIMB_T(0x1220b4e979ea5467) },+      { TO_LIMB_T(0xa989fffff9d8b0d2), TO_LIMB_T(0x3b47e7dda4b7faf3),+        TO_LIMB_T(0xff50678a26dffece), TO_LIMB_T(0xb24c28679aa8197a),+        TO_LIMB_T(0x908a1ebe5708d058), TO_LIMB_T(0x0fc0ba017f2b2466) }+    };+    vec384x uu, tv2, tv4, x2n, gx1, gxd, y2;+#if 0+    vec384x xn, x1n, xd, y, y1, Zuu;+#else+# define xn     p->X+# define y      p->Y+# define xd     p->Z+# define x1n    xn+# define y1     y+# define Zuu    x2n+#endif+#define sgn0_fp2(a) (sgn0_pty_mont_384x((a), BLS12_381_P, p0) & 1)+    bool_t e1, e2;++    /*+     * as per map_to_curve() from poc/sswu_opt.sage at+     * https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve+     * with 9mod16 twists...+     */+    /* x numerator variants                                             */+    sqr_fp2(uu, u);                     /* uu = u^2                     */+    mul_fp2(Zuu, Z, uu);                /* Zuu = Z * uu                 */+    sqr_fp2(tv2, Zuu);                  /* tv2 = Zuu^2                  */+    add_fp2(tv2, tv2, Zuu);             /* tv2 = tv2 + Zuu              */+    add_fp2(x1n, tv2, BLS12_381_Rx.p2); /* x1n = tv2 + 1                */+    mul_fp2(x1n, x1n, Bprime_E2);       /* x1n = x1n * B                */+    mul_fp2(x2n, Zuu, x1n);             /* x2n = Zuu * x1n              */++    /* x denumenator                                                    */+    mul_fp2(xd, minus_A, tv2);          /* xd = -A * tv2                */+    e1 = vec_is_zero(xd, sizeof(xd));   /* e1 = xd == 0                 */+    vec_select(xd, ZxA, xd, sizeof(xd), e1);    /*              # If xd == 0, set xd = Z*A */++    /* y numerators variants                                            */+    sqr_fp2(tv2, xd);                   /* tv2 = xd^2                   */+    mul_fp2(gxd, xd, tv2);              /* gxd = xd^3                   */+    mul_fp2(tv2, Aprime_E2, tv2);       /* tv2 = A * tv2                */+    sqr_fp2(gx1, x1n);                  /* gx1 = x1n^2                  */+    add_fp2(gx1, gx1, tv2);             /* gx1 = gx1 + tv2      # x1n^2 + A*xd^2 */+    mul_fp2(gx1, gx1, x1n);             /* gx1 = gx1 * x1n      # x1n^3 + A*x1n*xd^2 */+    mul_fp2(tv2, Bprime_E2, gxd);       /* tv2 = B * gxd                */+    add_fp2(gx1, gx1, tv2);             /* gx1 = gx1 + tv2      # x1^3 + A*x1*xd^2 + B*xd^3 */+    sqr_fp2(tv4, gxd);                  /* tv4 = gxd^2                  */+    mul_fp2(tv2, gx1, gxd);             /* tv2 = gx1 * gxd              */+    mul_fp2(tv4, tv4, tv2);             /* tv4 = tv4 * tv2      # gx1*gxd^3 */+    e2 = recip_sqrt_fp2(y1, tv4,        /* y1 = tv4^c1          # (gx1*gxd^3)^((p^2-9)/16) */+                        recip_ZZZ, magic_ZZZ);+    mul_fp2(y1, y1, tv2);               /* y1 = y1 * tv2        # gx1*gxd*y1 */+    mul_fp2(y2, y1, uu);                /* y2 = y1 * uu                 */+    mul_fp2(y2, y2, u);                 /* y2 = y2 * u                  */++    /* choose numerators                                                */+    vec_select(xn, x1n, x2n, sizeof(xn), e2);   /* xn = e2 ? x1n : x2n  */+    vec_select(y, y1, y2, sizeof(y), e2);       /* y  = e2 ? y1 : y2    */++    e1 = sgn0_fp2(u);+    e2 = sgn0_fp2(y);+    cneg_fp2(y, y, e1^e2);              /* fix sign of y                */+                                        /* return (xn, xd, y, 1)        */++    /* convert (xn, xd, y, 1) to Jacobian projective coordinates        */+    mul_fp2(p->X, xn, xd);              /* X = xn * xd                  */+    mul_fp2(p->Y, y, gxd);              /* Y = y * xd^3                 */+#ifndef xd+    vec_copy(p->Z, xd, sizeof(xd));     /* Z = xd                       */+#else+# undef xn+# undef y+# undef xd+# undef x1n+# undef y1+# undef Zuu+# undef tv4+#endif+#undef sgn0_fp2+}++#if 0+static const byte h_eff[] = {+    TO_BYTES(0xe8020005aaa95551), TO_BYTES(0x59894c0adebbf6b4),+    TO_BYTES(0xe954cbc06689f6a3), TO_BYTES(0x2ec0ec69d7477c1a),+    TO_BYTES(0x6d82bf015d1212b0), TO_BYTES(0x329c2f178731db95),+    TO_BYTES(0x9986ff031508ffe1), TO_BYTES(0x88e2a8e9145ad768),+    TO_BYTES(0x584c6a0ea91b3528), TO_BYTES(0x0bc69f08f2ee75b3)+};++static void clear_cofactor(POINTonE2 *out, const POINTonE2 *p)+{    POINTonE2_mult_w5(out, p, h_eff, 636);   }+#else+/*+ * As per suggestions in "7. Clearing the cofactor" at+ * https://tools.ietf.org/html/draft-irtf-cfrg-hash-to-curve-06+ */+static void POINTonE2_add_n_dbl(POINTonE2 *out, const POINTonE2 *p, size_t n)+{+    POINTonE2_dadd(out, out, p, NULL);+    while(n--)+        POINTonE2_double(out, out);+}++static void POINTonE2_times_minus_z(POINTonE2 *out, const POINTonE2 *in)+{+    POINTonE2_double(out, in);          /*      1: 0x2                  */+    POINTonE2_add_n_dbl(out, in, 2);    /*   2..4: 0x3..0xc             */+    POINTonE2_add_n_dbl(out, in, 3);    /*   5..8: 0xd..0x68            */+    POINTonE2_add_n_dbl(out, in, 9);    /*  9..18: 0x69..0xd200         */+    POINTonE2_add_n_dbl(out, in, 32);   /* 19..51: ..0xd20100000000     */+    POINTonE2_add_n_dbl(out, in, 16);   /* 52..68: ..0xd201000000010000 */+}++static void psi(POINTonE2 *out, const POINTonE2 *in);++static void clear_cofactor(POINTonE2 *out, const POINTonE2 *p)+{+    POINTonE2 t0, t1;++    /* A.Budroni, F.Pintore, "Efficient hash maps to G2 on BLS curves"  */+    POINTonE2_double(out, p);           /* out = 2P                     */+    psi(out, out);                      /* out = Ψ(2P)                  */+    psi(out, out);                      /* out = Ψ²(2P)                 */++    vec_copy(&t0, p, sizeof(t0));+    POINTonE2_cneg(&t0, 1);             /* t0 = -P                      */+    psi(&t1, &t0);                      /* t1 = -Ψ(P)                   */+    POINTonE2_dadd(out, out, &t0, NULL);/* out = Ψ²(2P) - P             */+    POINTonE2_dadd(out, out, &t1, NULL);/* out = Ψ²(2P) - P - Ψ(P)      */++    POINTonE2_times_minus_z(&t0, p);    /* t0 = [-z]P                   */+    POINTonE2_dadd(&t0, &t0, p, NULL);  /* t0 = [-z + 1]P               */+    POINTonE2_dadd(&t0, &t0, &t1, NULL);/* t0 = [-z + 1]P - Ψ(P)        */+    POINTonE2_times_minus_z(&t1, &t0);  /* t1 = [z² - z]P + [z]Ψ(P)     */+    POINTonE2_dadd(out, out, &t1, NULL);/* out = [z² - z - 1]P          */+                                        /*     + [z - 1]Ψ(P)            */+                                        /*     + Ψ²(2P)                 */+}+#endif++/*+ * |u|, |v| are expected to be in Montgomery representation+ */+static void map_to_g2(POINTonE2 *out, const vec384x u, const vec384x v)+{+    POINTonE2 p;++    map_to_isogenous_E2(&p, u);++    if (v != NULL) {+        map_to_isogenous_E2(out, v);    /* borrow |out|                 */+        POINTonE2_dadd(&p, &p, out, Aprime_E2);+    }++    isogeny_map_to_E2(&p, &p);          /* sprinkle isogenous powder    */+    clear_cofactor(out, &p);+}++void blst_map_to_g2(POINTonE2 *out, const vec384x u, const vec384x v)+{   map_to_g2(out, u, v);   }++static void Encode_to_G2(POINTonE2 *p, const unsigned char *msg, size_t msg_len,+                                       const unsigned char *DST, size_t DST_len,+                                       const unsigned char *aug, size_t aug_len)+{+    vec384x u[1];++    hash_to_field(u[0], 2, aug, aug_len, msg, msg_len, DST, DST_len);+    map_to_g2(p, u[0], NULL);+}++void blst_encode_to_g2(POINTonE2 *p, const unsigned char *msg, size_t msg_len,+                                     const unsigned char *DST, size_t DST_len,+                                     const unsigned char *aug, size_t aug_len)+{   Encode_to_G2(p, msg, msg_len, DST, DST_len, aug, aug_len);   }++static void Hash_to_G2(POINTonE2 *p, const unsigned char *msg, size_t msg_len,+                                     const unsigned char *DST, size_t DST_len,+                                     const unsigned char *aug, size_t aug_len)+{+    vec384x u[2];++    hash_to_field(u[0], 4, aug, aug_len, msg, msg_len, DST, DST_len);+    map_to_g2(p, u[0], u[1]);+}++void blst_hash_to_g2(POINTonE2 *p, const unsigned char *msg, size_t msg_len,+                                   const unsigned char *DST, size_t DST_len,+                                   const unsigned char *aug, size_t aug_len)+{   Hash_to_G2(p, msg, msg_len, DST, DST_len, aug, aug_len);   }++static bool_t POINTonE2_in_G2(const POINTonE2 *P)+{+#if 0+    POINTonE2 t0, t1, t2;++    /* Bowe, S., "Faster subgroup checks for BLS12-381"                 */+    psi(&t0, P);                        /* Ψ(P)                         */+    psi(&t0, &t0);                      /* Ψ²(P)                        */+    psi(&t1, &t0);                      /* Ψ³(P)                        */++    POINTonE2_times_minus_z(&t2, &t1);+    POINTonE2_dadd(&t0, &t0, &t2, NULL);+    POINTonE2_cneg(&t0, 1);+    POINTonE2_dadd(&t0, &t0, P, NULL);  /* [z]Ψ³(P) - Ψ²(P) + P         */++    return vec_is_zero(t0.Z, sizeof(t0.Z));+#else+    POINTonE2 t0, t1;++    /* Scott, M., https://eprint.iacr.org/2021/1130 */+    psi(&t0, P);                            /* Ψ(P) */++    POINTonE2_times_minus_z(&t1, P);+    POINTonE2_cneg(&t1, 1);                 /* [z]P */++    return POINTonE2_is_equal(&t0, &t1);+#endif+}++int blst_p2_in_g2(const POINTonE2 *p)+{   return (int)POINTonE2_in_G2(p);   }++int blst_p2_affine_in_g2(const POINTonE2_affine *p)+{+    POINTonE2 P;++    vec_copy(P.X, p->X, 2*sizeof(P.X));+    vec_select(P.Z, p->X, BLS12_381_Rx.p, sizeof(P.Z),+                     vec_is_zero(p, sizeof(*p)));++    return (int)POINTonE2_in_G2(&P);+}
+ vendor/external/blst/src/multi_scalar.c view
@@ -0,0 +1,427 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "fields.h"+#include "point.h"++/*+ * Infinite point among inputs would be devastating. Shall we change it?+ */+#define POINTS_TO_AFFINE_IMPL(prefix, ptype, bits, field) \+static void ptype##s_to_affine(ptype##_affine dst[], \+                               const ptype *const points[], size_t npoints) \+{ \+    size_t i; \+    vec##bits *acc, ZZ, ZZZ; \+    const ptype *point = NULL; \+    const size_t stride = sizeof(ptype)==sizeof(POINTonE1) ? 1536 : 768; \+\+    while (npoints) { \+        const ptype *p, *const *walkback; \+        size_t delta = stride<npoints ? stride : npoints; \+\+        point = *points ? *points++ : point+1; \+        acc = (vec##bits *)dst; \+        vec_copy(acc++, point->Z, sizeof(vec##bits)); \+        for (i = 1; i < delta; i++, acc++) \+            point = *points ? *points++ : point+1, \+            mul_##field(acc[0], acc[-1], point->Z); \+\+        --acc; reciprocal_##field(acc[0], acc[0]); \+\+        walkback = points-1, p = point, --delta, dst += delta; \+        for (i = 0; i < delta; i++, acc--, dst--) { \+            mul_##field(acc[-1], acc[-1], acc[0]);  /* 1/Z        */\+            sqr_##field(ZZ, acc[-1]);               /* 1/Z^2      */\+            mul_##field(ZZZ, ZZ, acc[-1]);          /* 1/Z^3      */\+            mul_##field(acc[-1], p->Z, acc[0]);     \+            mul_##field(dst->X,  p->X, ZZ);         /* X = X'/Z^2 */\+            mul_##field(dst->Y,  p->Y, ZZZ);        /* Y = Y'/Z^3 */\+            p = (p == *walkback) ? *--walkback : p-1; \+        } \+        sqr_##field(ZZ, acc[0]);                    /* 1/Z^2      */\+        mul_##field(ZZZ, ZZ, acc[0]);               /* 1/Z^3      */\+        mul_##field(dst->X, p->X, ZZ);              /* X = X'/Z^2 */\+        mul_##field(dst->Y, p->Y, ZZZ);             /* Y = Y'/Z^3 */\+        ++delta, dst += delta, npoints -= delta; \+    } \+} \+\+void prefix##s_to_affine(ptype##_affine dst[], const ptype *const points[], \+                         size_t npoints) \+{   ptype##s_to_affine(dst, points, npoints);   }++POINTS_TO_AFFINE_IMPL(blst_p1, POINTonE1, 384, fp)+POINTS_TO_AFFINE_IMPL(blst_p2, POINTonE2, 384x, fp2)++/*+ * This is two-step multi-scalar multiplication procedure. First, given+ * a set of points you pre-compute a table for chosen windowing factor+ * [expressed in bits with value between 2 and 14], and then you pass+ * this table to the actual multiplication procedure along with scalars.+ * Idea is that the pre-computed table will be reused multiple times. In+ * which case multiplication runs faster than below Pippenger algorithm+ * implementation for up to ~16K points for wbits=8, naturally at the+ * expense of multi-megabyte table. One can trade even more memory for+ * performance, but each wbits increment doubles the memory requirement,+ * so at some point it gets prohibively large... For reference, without+ * reusing the table it's faster than Pippenger algorithm for up ~32+ * points [with wbits=5]...+ */++#define SCRATCH_SZ(ptype) (sizeof(ptype)==sizeof(POINTonE1) ? 8192 : 4096)++#define PRECOMPUTE_WBITS_IMPL(prefix, ptype, bits, field, one) \+static void ptype##_precompute_row_wbits(ptype row[], size_t wbits, \+                                         const ptype##_affine *point) \+{ \+    size_t i, j, n = (size_t)1 << (wbits-1); \+                                          /* row[-1] is implicit infinity */\+    vec_copy(&row[0], point, sizeof(*point));           /* row[0]=p*1     */\+    vec_copy(&row[0].Z, one, sizeof(row[0].Z));                             \+    ptype##_double(&row[1],  &row[0]);                  /* row[1]=p*(1+1) */\+    for (i = 2, j = 1; i < n; i += 2, j++) \+        ptype##_add_affine(&row[i], &row[i-1], point),  /* row[2]=p*(2+1) */\+        ptype##_double(&row[i+1], &row[j]);             /* row[3]=p*(2+2) */\+}                                                       /* row[4] ...     */\+\+static void ptype##s_to_affine_row_wbits(ptype##_affine dst[], ptype src[], \+                                         size_t wbits, size_t npoints) \+{ \+    size_t total = npoints << (wbits-1); \+    size_t nwin = (size_t)1 << (wbits-1); \+    size_t i, j; \+    vec##bits *acc, ZZ, ZZZ; \+\+    src += total; \+    acc = (vec##bits *)src; \+    vec_copy(acc++, one, sizeof(vec##bits)); \+    for (i = 0; i < npoints; i++) \+        for (j = nwin; --src, --j; acc++)    \+            mul_##field(acc[0], acc[-1], src->Z); \+\+    --acc; reciprocal_##field(acc[0], acc[0]); \+\+    for (i = 0; i < npoints; i++) { \+        vec_copy(dst++, src++, sizeof(ptype##_affine)); \+        for (j = 1; j < nwin; j++, acc--, src++, dst++) { \+            mul_##field(acc[-1], acc[-1], acc[0]);  /* 1/Z        */\+            sqr_##field(ZZ, acc[-1]);               /* 1/Z^2      */\+            mul_##field(ZZZ, ZZ, acc[-1]);          /* 1/Z^3      */\+            mul_##field(acc[-1], src->Z, acc[0]);                   \+            mul_##field(dst->X, src->X, ZZ);        /* X = X'/Z^2 */\+            mul_##field(dst->Y, src->Y, ZZZ);       /* Y = Y'/Z^3 */\+        } \+    } \+} \+\+/* flat |points[n]| can be placed at the end of |table[n<<(wbits-1)]| */\+static void ptype##s_precompute_wbits(ptype##_affine table[], size_t wbits, \+                                      const ptype##_affine *const points[], \+                                      size_t npoints) \+{ \+    size_t total = npoints << (wbits-1); \+    size_t nwin = (size_t)1 << (wbits-1); \+    size_t nmin = wbits>9 ? (size_t)1: (size_t)1 << (9-wbits); \+    size_t i, top = 0; \+    ptype *rows, *row; \+    const ptype##_affine *point = NULL; \+    size_t stride = ((512*1024)/sizeof(ptype##_affine)) >> wbits; \+    if (stride == 0) stride = 1; \+\+    while (npoints >= nmin) { \+        size_t limit = total - npoints; \+\+        if (top + (stride << wbits) > limit) { \+            stride = (limit - top) >> wbits;   \+            if (stride == 0) break;            \+        } \+        rows = row = (ptype *)(&table[top]); \+        for (i = 0; i < stride; i++, row += nwin) \+            point = *points ? *points++ : point+1, \+            ptype##_precompute_row_wbits(row, wbits, point); \+        ptype##s_to_affine_row_wbits(&table[top], rows, wbits, stride); \+        top += stride << (wbits-1); \+        npoints -= stride; \+    } \+    rows = row = alloca(2*sizeof(ptype##_affine) * npoints * nwin); \+    for (i = 0; i < npoints; i++, row += nwin) \+        point = *points ? *points++ : point+1, \+        ptype##_precompute_row_wbits(row, wbits, point); \+    ptype##s_to_affine_row_wbits(&table[top], rows, wbits, npoints); \+} \+\+size_t prefix##s_mult_wbits_precompute_sizeof(size_t wbits, size_t npoints) \+{ return (sizeof(ptype##_affine)*npoints) << (wbits-1); } \+void prefix##s_mult_wbits_precompute(ptype##_affine table[], size_t wbits, \+                                     const ptype##_affine *const points[], \+                                     size_t npoints) \+{ ptype##s_precompute_wbits(table, wbits, points, npoints); }++#define POINTS_MULT_WBITS_IMPL(prefix, ptype, bits, field, one) \+static void ptype##_gather_booth_wbits(ptype *p, const ptype##_affine row[], \+                                       size_t wbits, limb_t booth_idx) \+{ \+    bool_t booth_sign = (booth_idx >> wbits) & 1; \+    bool_t idx_is_zero; \+    static const ptype##_affine infinity = { 0 }; \+\+    booth_idx &= ((limb_t)1 << wbits) - 1; \+    idx_is_zero = is_zero(booth_idx); \+    booth_idx -= 1 ^ idx_is_zero; \+    vec_select(p, &infinity, &row[booth_idx], sizeof(row[0]), idx_is_zero); \+    ptype##_cneg(p, booth_sign); \+} \+\+static void ptype##s_mult_wbits(ptype *ret, const ptype##_affine table[], \+                                size_t wbits, size_t npoints, \+                                const byte *const scalars[], size_t nbits, \+                                ptype scratch[]) \+{ \+    limb_t wmask, wval; \+    size_t i, j, z, nbytes, window, nwin = (size_t)1 << (wbits-1); \+    const byte *scalar, *const *scalar_s = scalars; \+    const ptype##_affine *row = table; \+\+    size_t scratch_sz = SCRATCH_SZ(ptype); \+    if (scratch == NULL) { \+        scratch_sz /= 4; /* limit to 288K */ \+        scratch_sz = scratch_sz < npoints ? scratch_sz : npoints; \+        scratch = alloca(sizeof(ptype) * scratch_sz); \+    } \+\+    nbytes = (nbits + 7)/8; /* convert |nbits| to bytes */ \+    scalar = *scalar_s++; \+\+    /* top excess bits modulo target window size */ \+    window = nbits % wbits; /* yes, it may be zero */ \+    wmask = ((limb_t)1 << (window + 1)) - 1; \+\+    nbits -= window; \+    z = is_zero(nbits); \+    wval = (get_wval_limb(scalar, nbits - (z^1), wbits + (z^1)) << z) & wmask; \+    wval = booth_encode(wval, wbits); \+    ptype##_gather_booth_wbits(&scratch[0], row, wbits, wval); \+    row += nwin; \+\+    i = 1; vec_zero(ret, sizeof(*ret)); \+    while (nbits > 0) { \+        for (j = i; i < npoints; i++, j++, row += nwin) { \+            if (j == scratch_sz) \+                ptype##s_accumulate(ret, scratch, j), j = 0; \+            scalar = *scalar_s ? *scalar_s++ : scalar+nbytes; \+            wval = get_wval_limb(scalar, nbits - 1, window + 1) & wmask; \+            wval = booth_encode(wval, wbits); \+            ptype##_gather_booth_wbits(&scratch[j], row, wbits, wval); \+        } \+        ptype##s_accumulate(ret, scratch, j); \+\+        for (j = 0; j < wbits; j++) \+            ptype##_double(ret, ret); \+\+        window = wbits; \+        wmask = ((limb_t)1 << (window + 1)) - 1; \+        nbits -= window; \+        i = 0; row = table; scalar_s = scalars; \+    } \+\+    for (j = i; i < npoints; i++, j++, row += nwin) { \+        if (j == scratch_sz) \+            ptype##s_accumulate(ret, scratch, j), j = 0; \+        scalar = *scalar_s ? *scalar_s++ : scalar+nbytes; \+        wval = (get_wval_limb(scalar, 0, wbits) << 1) & wmask; \+        wval = booth_encode(wval, wbits); \+        ptype##_gather_booth_wbits(&scratch[j], row, wbits, wval); \+    } \+    ptype##s_accumulate(ret, scratch, j); \+} \+\+size_t prefix##s_mult_wbits_scratch_sizeof(size_t npoints) \+{ \+    const size_t scratch_sz = SCRATCH_SZ(ptype); \+    return sizeof(ptype) * (npoints < scratch_sz ? npoints : scratch_sz); \+} \+void prefix##s_mult_wbits(ptype *ret, const ptype##_affine table[], \+                          size_t wbits, size_t npoints, \+                          const byte *const scalars[], size_t nbits, \+                          ptype scratch[]) \+{ ptype##s_mult_wbits(ret, table, wbits, npoints, scalars, nbits, scratch); }++PRECOMPUTE_WBITS_IMPL(blst_p1, POINTonE1, 384, fp, BLS12_381_Rx.p)+POINTS_MULT_WBITS_IMPL(blst_p1, POINTonE1, 384, fp, BLS12_381_Rx.p)++PRECOMPUTE_WBITS_IMPL(blst_p2, POINTonE2, 384x, fp2, BLS12_381_Rx.p2)+POINTS_MULT_WBITS_IMPL(blst_p2, POINTonE2, 384x, fp2, BLS12_381_Rx.p2)++/*+ * Pippenger algorithm implementation, fastest option for larger amount+ * of points...+ */++static size_t pippenger_window_size(size_t npoints)+{+    size_t wbits;++    for (wbits=0; npoints>>=1; wbits++) ;++    return wbits>12 ? wbits-3 : (wbits>4 ? wbits-2 : (wbits ? 2 : 1));+}++#define DECLARE_PRIVATE_POINTXYZZ(ptype, bits) \+typedef struct { vec##bits X,Y,ZZZ,ZZ; } ptype##xyzz;++#define POINTS_MULT_PIPPENGER_IMPL(prefix, ptype) \+static void ptype##_integrate_buckets(ptype *out, ptype##xyzz buckets[], \+                                                  size_t wbits) \+{ \+    ptype##xyzz ret[1], acc[1]; \+    size_t n = (size_t)1 << wbits; \+\+    /* Calculate sum of x[i-1]*i for i=1 through 1<<|wbits|. */\+    vec_copy(acc, &buckets[--n], sizeof(acc)); \+    vec_copy(ret, &buckets[n], sizeof(ret)); \+    vec_zero(&buckets[n], sizeof(buckets[n])); \+    while (n--) { \+        ptype##xyzz_dadd(acc, acc, &buckets[n]); \+        ptype##xyzz_dadd(ret, ret, acc); \+        vec_zero(&buckets[n], sizeof(buckets[n])); \+    } \+    ptype##xyzz_to_Jacobian(out, ret); \+} \+\+static void ptype##_bucket(ptype##xyzz buckets[], limb_t booth_idx, \+                           size_t wbits, const ptype##_affine *p) \+{ \+    bool_t booth_sign = (booth_idx >> wbits) & 1; \+\+    booth_idx &= (1<<wbits) - 1; \+    if (booth_idx--) \+        ptype##xyzz_dadd_affine(&buckets[booth_idx], &buckets[booth_idx], \+                                                     p, booth_sign); \+} \+\+static void ptype##_prefetch(const ptype##xyzz buckets[], limb_t booth_idx, \+                             size_t wbits) \+{ \+    booth_idx &= (1<<wbits) - 1; \+    if (booth_idx--) \+        vec_prefetch(&buckets[booth_idx], sizeof(buckets[booth_idx])); \+} \+\+static void ptype##s_tile_pippenger(ptype *ret, \+                                    const ptype##_affine *const points[], \+                                    size_t npoints, \+                                    const byte *const scalars[], size_t nbits, \+                                    ptype##xyzz buckets[], \+                                    size_t bit0, size_t wbits, size_t cbits) \+{ \+    limb_t wmask, wval, wnxt; \+    size_t i, z, nbytes; \+    const byte *scalar = *scalars++; \+    const ptype##_affine *point = *points++; \+\+    nbytes = (nbits + 7)/8; /* convert |nbits| to bytes */ \+    wmask = ((limb_t)1 << (wbits+1)) - 1; \+    z = is_zero(bit0); \+    bit0 -= z^1; wbits += z^1; \+    wval = (get_wval_limb(scalar, bit0, wbits) << z) & wmask; \+    wval = booth_encode(wval, cbits); \+    scalar = *scalars ? *scalars++ : scalar+nbytes; \+    wnxt = (get_wval_limb(scalar, bit0, wbits) << z) & wmask; \+    wnxt = booth_encode(wnxt, cbits); \+    npoints--;  /* account for prefetch */ \+\+    ptype##_bucket(buckets, wval, cbits, point); \+    for (i = 1; i < npoints; i++) { \+        wval = wnxt; \+        scalar = *scalars ? *scalars++ : scalar+nbytes; \+        wnxt = (get_wval_limb(scalar, bit0, wbits) << z) & wmask; \+        wnxt = booth_encode(wnxt, cbits); \+        ptype##_prefetch(buckets, wnxt, cbits); \+        point = *points ? *points++ : point+1; \+        ptype##_bucket(buckets, wval, cbits, point); \+    } \+    point = *points ? *points++ : point+1; \+    ptype##_bucket(buckets, wnxt, cbits, point); \+    ptype##_integrate_buckets(ret, buckets, cbits - 1); \+} \+\+static void ptype##s_mult_pippenger(ptype *ret, \+                                    const ptype##_affine *const points[], \+                                    size_t npoints, \+                                    const byte *const scalars[], size_t nbits, \+                                    ptype##xyzz buckets[], size_t window) \+{ \+    size_t i, wbits, cbits, bit0 = nbits; \+    ptype tile[1]; \+\+    window = window ? window : pippenger_window_size(npoints); \+    vec_zero(buckets, sizeof(buckets[0]) << (window-1)); \+    vec_zero(ret, sizeof(*ret)); \+\+    /* top excess bits modulo target window size */ \+    wbits = nbits % window; /* yes, it may be zero */ \+    cbits = wbits + 1; \+    while (bit0 -= wbits) { \+        ptype##s_tile_pippenger(tile, points, npoints, scalars, nbits, \+                                      buckets, bit0, wbits, cbits); \+        ptype##_dadd(ret, ret, tile, NULL); \+        for (i = 0; i < window; i++) \+            ptype##_double(ret, ret); \+        cbits = wbits = window; \+    } \+    ptype##s_tile_pippenger(tile, points, npoints, scalars, nbits, \+                                  buckets, 0, wbits, cbits); \+    ptype##_dadd(ret, ret, tile, NULL); \+} \+\+size_t prefix##s_mult_pippenger_scratch_sizeof(size_t npoints) \+{   return sizeof(ptype##xyzz) << (pippenger_window_size(npoints)-1);   } \+void prefix##s_tile_pippenger(ptype *ret, \+                              const ptype##_affine *const points[], \+                              size_t npoints, \+                              const byte *const scalars[], size_t nbits, \+                              ptype##xyzz scratch[], \+                              size_t bit0, size_t window) \+{ \+    size_t wbits, cbits; \+\+    if (bit0 + window > nbits)  wbits = nbits - bit0, cbits = wbits + 1; \+    else                        wbits = cbits = window; \+    ptype##s_tile_pippenger(ret, points, npoints, scalars, nbits, scratch, \+                                 bit0, wbits, cbits); \+} \+void prefix##s_mult_pippenger(ptype *ret, \+                              const ptype##_affine *const points[], \+                              size_t npoints, \+                              const byte *const scalars[], size_t nbits, \+                              ptype##xyzz scratch[]) \+{ \+    if (npoints == 1) { \+        prefix##_from_affine(ret, points[0]); \+        prefix##_mult(ret, ret, scalars[0], nbits); \+        return; \+    } \+    if ((npoints * sizeof(ptype##_affine) * 8 * 3) <= SCRATCH_LIMIT) { \+        ptype##_affine *table = alloca(npoints * sizeof(ptype##_affine) * 8); \+        ptype##s_precompute_wbits(table, 4, points, npoints); \+        ptype##s_mult_wbits(ret, table, 4, npoints, scalars, nbits, NULL); \+        return; \+    } \+    ptype##s_mult_pippenger(ret, points, npoints, scalars, nbits, scratch, 0); \+}++DECLARE_PRIVATE_POINTXYZZ(POINTonE1, 384)+POINTXYZZ_TO_JACOBIAN_IMPL(POINTonE1, 384, fp)+POINTXYZZ_DADD_IMPL(POINTonE1, 384, fp)+POINTXYZZ_DADD_AFFINE_IMPL(POINTonE1, 384, fp, BLS12_381_Rx.p)+POINTS_MULT_PIPPENGER_IMPL(blst_p1, POINTonE1)++DECLARE_PRIVATE_POINTXYZZ(POINTonE2, 384x)+POINTXYZZ_TO_JACOBIAN_IMPL(POINTonE2, 384x, fp2)+POINTXYZZ_DADD_IMPL(POINTonE2, 384x, fp2)+POINTXYZZ_DADD_AFFINE_IMPL(POINTonE2, 384x, fp2, BLS12_381_Rx.p2)+POINTS_MULT_PIPPENGER_IMPL(blst_p2, POINTonE2)
+ vendor/external/blst/src/no_asm.h view
@@ -0,0 +1,1347 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#if LIMB_T_BITS==32+typedef unsigned long long llimb_t;+#endif++/* cardano-c: all callers use at most 384-bit fields. Fixed-capacity+ * scratch buffers keep this C implementation usable with MSVC, which does+ * not support VLAs. smul_2n uses double-width (768-bit) scratch space.+ * Copy lengths below remain based on n, not on the buffer capacity. */+#define BLST_MAX_LIMBS NLIMBS(384)++#if defined(__clang__)+# pragma GCC diagnostic ignored "-Wstatic-in-inline"+#endif++#if !defined(__clang__) && !defined(__builtin_assume)+# if defined(__GNUC__) && __GNUC__>=5+#  define __builtin_assume(condition) if (!(condition)) __builtin_unreachable()+# elif defined(_MSC_VER)+#  define __builtin_assume(condition) __assume(condition)+# else+#  define __builtin_assume(condition) (void)(condition)+# endif+#endif++static void mul_mont_n(limb_t ret[], const limb_t a[], const limb_t b[],+                       const limb_t p[], limb_t n0, size_t n)+{+    __builtin_assume(n != 0 && n%2 == 0);+    llimb_t limbx;+    limb_t mask, borrow, mx, hi, tmp[BLST_MAX_LIMBS+1], carry;+    size_t i, j;++    for (mx=b[0], hi=0, i=0; i<n; i++) {+        limbx = (mx * (llimb_t)a[i]) + hi;+        tmp[i] = (limb_t)limbx;+        hi = (limb_t)(limbx >> LIMB_T_BITS);+    }+    mx = n0*tmp[0];+    tmp[i] = hi;++    for (carry=0, j=0; ; ) {+        limbx = (mx * (llimb_t)p[0]) + tmp[0];+        hi = (limb_t)(limbx >> LIMB_T_BITS);+        for (i=1; i<n; i++) {+            limbx = (mx * (llimb_t)p[i] + hi) + tmp[i];+            tmp[i-1] = (limb_t)limbx;+            hi = (limb_t)(limbx >> LIMB_T_BITS);+        }+        limbx = tmp[i] + (hi + (llimb_t)carry);+        tmp[i-1] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);++        if (++j==n)+            break;++        for (mx=b[j], hi=0, i=0; i<n; i++) {+            limbx = (mx * (llimb_t)a[i] + hi) + tmp[i];+            tmp[i] = (limb_t)limbx;+            hi = (limb_t)(limbx >> LIMB_T_BITS);+        }+        mx = n0*tmp[0];+        limbx = hi + (llimb_t)carry;+        tmp[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }++    for (borrow=0, i=0; i<n; i++) {+        limbx = tmp[i] - (p[i] + (llimb_t)borrow);+        ret[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    mask = carry - borrow;+    launder(mask);++    for(i=0; i<n; i++)+        ret[i] = (ret[i] & ~mask) | (tmp[i] & mask);+}++#define MUL_MONT_IMPL(bits) \+inline void mul_mont_##bits(vec##bits ret, const vec##bits a, \+                            const vec##bits b, const vec##bits p, limb_t n0) \+{   mul_mont_n(ret, a, b, p, n0, NLIMBS(bits));   } \+\+inline void sqr_mont_##bits(vec##bits ret, const vec##bits a, \+                            const vec##bits p, limb_t n0) \+{   mul_mont_n(ret, a, a, p, n0, NLIMBS(bits));   }++/*+ * 256-bit subroutines can handle arbitrary modulus, even non-"sparse",+ * but we have to harmonize the naming with assembly.+ */+#define mul_mont_256 mul_mont_sparse_256+#define sqr_mont_256 sqr_mont_sparse_256+MUL_MONT_IMPL(256)+#undef mul_mont_256+#undef sqr_mont_256+MUL_MONT_IMPL(384)++static void add_mod_n(limb_t ret[], const limb_t a[], const limb_t b[],+                      const limb_t p[], size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t mask, carry, borrow, tmp[BLST_MAX_LIMBS];+    size_t i;++    for (carry=0, i=0; i<n; i++) {+        limbx = a[i] + (b[i] + (llimb_t)carry);+        tmp[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }++    for (borrow=0, i=0; i<n; i++) {+        limbx = tmp[i] - (p[i] + (llimb_t)borrow);+        ret[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    mask = carry - borrow;+    launder(mask);++    for(i=0; i<n; i++)+        ret[i] = (ret[i] & ~mask) | (tmp[i] & mask);+}++#define ADD_MOD_IMPL(bits) \+inline void add_mod_##bits(vec##bits ret, const vec##bits a, \+                           const vec##bits b, const vec##bits p) \+{   add_mod_n(ret, a, b, p, NLIMBS(bits));   }++ADD_MOD_IMPL(256)+ADD_MOD_IMPL(384)++static void sub_mod_n(limb_t ret[], const limb_t a[], const limb_t b[],+                      const limb_t p[], size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t mask, carry, borrow;+    size_t i;++    for (borrow=0, i=0; i<n; i++) {+        limbx = a[i] - (b[i] + (llimb_t)borrow);+        ret[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    mask = 0 - borrow;+    launder(mask);++    for (carry=0, i=0; i<n; i++) {+        limbx = ret[i] + ((p[i] & mask) + (llimb_t)carry);+        ret[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }+}++#define SUB_MOD_IMPL(bits) \+inline void sub_mod_##bits(vec##bits ret, const vec##bits a, \+                           const vec##bits b, const vec##bits p) \+{   sub_mod_n(ret, a, b, p, NLIMBS(bits));   }++SUB_MOD_IMPL(256)+SUB_MOD_IMPL(384)++static void mul_by_3_mod_n(limb_t ret[], const limb_t a[], const limb_t p[],+                           size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t mask, carry, borrow, tmp[BLST_MAX_LIMBS], two_a[BLST_MAX_LIMBS];+    size_t i;++    for (carry=0, i=0; i<n; i++) {+        limb_t a_i = a[i];+        tmp[i] = a_i<<1 | carry;+        carry = a_i>>(LIMB_T_BITS-1);+    }++    for (borrow=0, i=0; i<n; i++) {+        limbx = tmp[i] - (p[i] + (llimb_t)borrow);+        two_a[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    mask = carry - borrow;+    launder(mask);++    for(i=0; i<n; i++)+        two_a[i] = (two_a[i] & ~mask) | (tmp[i] & mask);++    for (carry=0, i=0; i<n; i++) {+        limbx = a[i] + (two_a[i] + (llimb_t)carry);+        tmp[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }++    for (borrow=0, i=0; i<n; i++) {+        limbx = tmp[i] - (p[i] + (llimb_t)borrow);+        ret[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    mask = carry - borrow;+    launder(mask);++    for(i=0; i<n; i++)+        ret[i] = (ret[i] & ~mask) | (tmp[i] & mask);+}++#define MUL_BY_3_MOD_IMPL(bits) \+inline void mul_by_3_mod_##bits(vec##bits ret, const vec##bits a, \+                                const vec##bits p) \+{   mul_by_3_mod_n(ret, a, p, NLIMBS(bits));   }++MUL_BY_3_MOD_IMPL(256)+MUL_BY_3_MOD_IMPL(384)++static void lshift_mod_n(limb_t ret[], const limb_t a[], size_t count,+                         const limb_t p[], size_t n)+{+    __builtin_assume(count != 0);+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t mask, carry, borrow, tmp[BLST_MAX_LIMBS];+    size_t i;++    while (count--) {+        for (carry=0, i=0; i<n; i++) {+            limb_t a_i = a[i];+            tmp[i] = a_i<<1 | carry;+            carry = a_i>>(LIMB_T_BITS-1);+        }++        for (borrow=0, i=0; i<n; i++) {+            limbx = tmp[i] - (p[i] + (llimb_t)borrow);+            ret[i] = (limb_t)limbx;+            borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+        }++        mask = carry - borrow;+        launder(mask);++        for(i=0; i<n; i++)+            ret[i] = (ret[i] & ~mask) | (tmp[i] & mask);++        a = ret;+    }+}++#define LSHIFT_MOD_IMPL(bits) \+inline void lshift_mod_##bits(vec##bits ret, const vec##bits a, size_t count, \+                              const vec##bits p) \+{   lshift_mod_n(ret, a, count, p, NLIMBS(bits));   }++LSHIFT_MOD_IMPL(256)+LSHIFT_MOD_IMPL(384)++static void cneg_mod_n(limb_t ret[], const limb_t a[], bool_t flag,+                       const limb_t p[], size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t borrow, mask, tmp[BLST_MAX_LIMBS];+    size_t i;++    for (borrow=0, i=0; i<n; i++) {+        limbx = p[i] - (a[i] + (llimb_t)borrow);+        tmp[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    flag &= vec_is_zero(a, n*sizeof(limb_t)) ^ 1;+    mask = (limb_t)0 - flag;++    for(i=0; i<n; i++)+        ret[i] = (a[i] & ~mask) | (tmp[i] & mask);+}++#define CNEG_MOD_IMPL(bits) \+inline void cneg_mod_##bits(vec##bits ret, const vec##bits a, bool_t flag, \+                            const vec##bits p) \+{   cneg_mod_n(ret, a, flag, p, NLIMBS(bits));   }++CNEG_MOD_IMPL(256)+CNEG_MOD_IMPL(384)++static limb_t check_mod_n(const byte a[], const limb_t p[], size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t borrow, ai, acc;+    size_t i, j;++    for (acc=borrow=0, i=0; i<n; i++) {+        for (ai=0, j=0; j<8*sizeof(limb_t); j+=8)+            ai |= (limb_t)(*a++) << j;+        acc |= ai;+        limbx = ai - (p[i] + (llimb_t)borrow);+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    return borrow & (is_zero(acc) ^ 1);+}++#define CHECK_MOD_IMPL(bits) \+inline limb_t check_mod_##bits(const pow##bits a, const vec##bits p) \+{   return check_mod_n(a, p, NLIMBS(bits));   }++CHECK_MOD_IMPL(256)++static limb_t add_n_check_mod_n(byte ret[], const byte a[], const byte b[],+                                            const limb_t p[], size_t n)+{+    __builtin_assume(n != 0);+    limb_t ret_[BLST_MAX_LIMBS], a_[BLST_MAX_LIMBS], b_[BLST_MAX_LIMBS], zero;++    limbs_from_le_bytes(a_, a, n*sizeof(limb_t));+    limbs_from_le_bytes(b_, b, n*sizeof(limb_t));++    add_mod_n(ret_, a_, b_, p, n);+    zero = vec_is_zero(ret_, n*sizeof(limb_t));++    le_bytes_from_limbs(ret, ret_, n*sizeof(limb_t));++    return zero^1;+}++#define ADD_N_CHECK_MOD_IMPL(bits) \+inline limb_t add_n_check_mod_##bits(pow##bits ret, const pow##bits a, \+                                     const pow##bits b, const vec##bits p) \+{   return add_n_check_mod_n(ret, a, b, p, NLIMBS(bits));   }++ADD_N_CHECK_MOD_IMPL(256)++static limb_t sub_n_check_mod_n(byte ret[], const byte a[], const byte b[],+                                            const limb_t p[], size_t n)+{+    __builtin_assume(n != 0);+    limb_t ret_[BLST_MAX_LIMBS], a_[BLST_MAX_LIMBS], b_[BLST_MAX_LIMBS], zero;++    limbs_from_le_bytes(a_, a, n*sizeof(limb_t));+    limbs_from_le_bytes(b_, b, n*sizeof(limb_t));++    sub_mod_n(ret_, a_, b_, p, n);+    zero = vec_is_zero(ret_, n*sizeof(limb_t));++    le_bytes_from_limbs(ret, ret_, n*sizeof(limb_t));++    return zero^1;+}++#define SUB_N_CHECK_MOD_IMPL(bits) \+inline limb_t sub_n_check_mod_##bits(pow##bits ret, const pow##bits a, \+                                     const pow##bits b, const vec##bits p) \+{   return sub_n_check_mod_n(ret, a, b, p, NLIMBS(bits));   }++SUB_N_CHECK_MOD_IMPL(256)++static void from_mont_n(limb_t ret[], const limb_t a[],+                        const limb_t p[], limb_t n0, size_t n)+{+    __builtin_assume(n != 0 && n%2 == 0);+    llimb_t limbx;+    limb_t mask, borrow, mx, hi, tmp[BLST_MAX_LIMBS];+    size_t i, j;++    for (j=0; j<n; j++) {+        mx = n0*a[0];+        limbx = (mx * (llimb_t)p[0]) + a[0];+        hi = (limb_t)(limbx >> LIMB_T_BITS);+        for (i=1; i<n; i++) {+            limbx = (mx * (llimb_t)p[i] + hi) + a[i];+            tmp[i-1] = (limb_t)limbx;+            hi = (limb_t)(limbx >> LIMB_T_BITS);+        }+        tmp[i-1] = hi;+        a = tmp;+    }++    /* this is needed only if input can be non-fully-reduced */+    for (borrow=0, i=0; i<n; i++) {+        limbx = tmp[i] - (p[i] + (llimb_t)borrow);+        ret[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    mask = 0 - borrow;+    launder(mask);++    for(i=0; i<n; i++)+        ret[i] = (ret[i] & ~mask) | (tmp[i] & mask);+}++#define FROM_MONT_IMPL(bits) \+inline void from_mont_##bits(vec##bits ret, const vec##bits a, \+                             const vec##bits p, limb_t n0) \+{   from_mont_n(ret, a, p, n0, NLIMBS(bits));   }++FROM_MONT_IMPL(256)+FROM_MONT_IMPL(384)++static void redc_mont_n(limb_t ret[], const limb_t a[],+                        const limb_t p[], limb_t n0, size_t n)+{+    __builtin_assume(n != 0 && n%2 == 0);+    llimb_t limbx;+    limb_t mask, carry, borrow, mx, hi, tmp[BLST_MAX_LIMBS];+    const limb_t *b = a;+    size_t i, j;++    for (j=0; j<n; j++) {+        mx = n0*b[0];+        limbx = (mx * (llimb_t)p[0]) + b[0];+        hi = (limb_t)(limbx >> LIMB_T_BITS);+        for (i=1; i<n; i++) {+            limbx = (mx * (llimb_t)p[i] + hi) + b[i];+            tmp[i-1] = (limb_t)limbx;+            hi = (limb_t)(limbx >> LIMB_T_BITS);+        }+        tmp[i-1] = hi;+        b = tmp;+    }++    for (carry=0, i=0; i<n; i++) {+        limbx = a[n+i] + (tmp[i] + (llimb_t)carry);+        tmp[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }++    for (borrow=0, i=0; i<n; i++) {+        limbx = tmp[i] - (p[i] + (llimb_t)borrow);+        ret[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    mask = carry - borrow;+    launder(mask);++    for(i=0; i<n; i++)+        ret[i] = (ret[i] & ~mask) | (tmp[i] & mask);+}++#define REDC_MONT_IMPL(bits, bits2) \+inline void redc_mont_##bits(vec##bits ret, const vec##bits2 a, \+                             const vec##bits p, limb_t n0) \+{   redc_mont_n(ret, a, p, n0, NLIMBS(bits));   }++REDC_MONT_IMPL(256, 512)+REDC_MONT_IMPL(384, 768)++static void rshift_mod_n(limb_t ret[], const limb_t a[], size_t count,+                         const limb_t p[], size_t n)+{+    __builtin_assume(count != 0);+    __builtin_assume(n != 0 && n%2 == 0);+    llimb_t limbx;+    limb_t mask, carry, limb, next;+    size_t i;++    while (count--) {+        mask = 0 - (a[0] & 1);+        launder(mask);+        for (carry=0, i=0; i<n; i++) {+            limbx = a[i] + ((p[i]&mask) + (llimb_t)carry);+            ret[i] = (limb_t)limbx;+            carry = (limb_t)(limbx >> LIMB_T_BITS);+        }++        for (next=ret[0], i=0; i<n-1; i++) {+            limb = next >> 1;+            next = ret[i+1];+            ret[i] = limb | next << (LIMB_T_BITS-1);+        }+        ret[i] = next >> 1 | carry << (LIMB_T_BITS-1);++        a = ret;+    }+}++#define RSHIFT_MOD_IMPL(bits) \+inline void rshift_mod_##bits(vec##bits ret, const vec##bits a, size_t count, \+                              const vec##bits p) \+{   rshift_mod_n(ret, a, count, p, NLIMBS(bits));   }++RSHIFT_MOD_IMPL(256)+RSHIFT_MOD_IMPL(384)++#define DIV_BY_2_MOD_IMPL(bits) \+inline void div_by_2_mod_##bits(vec##bits ret, const vec##bits a, \+                                const vec##bits p) \+{   rshift_mod_n(ret, a, 1, p, NLIMBS(bits));   }++DIV_BY_2_MOD_IMPL(384)++static limb_t sgn0_pty_mod_n(const limb_t a[], const limb_t p[], size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t carry, borrow, ret, tmp[BLST_MAX_LIMBS];+    size_t i;++    ret = a[0] & 1; /* parity */++    for (carry=0, i=0; i<n; i++) {+        limb_t a_i = a[i];+        tmp[i] = a_i<<1 | carry;+        carry = a_i>>(LIMB_T_BITS-1);+    }++    for (borrow=0, i=0; i<n; i++) {+        limbx = tmp[i] - (p[i] + (llimb_t)borrow);+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    ret |= ((carry - borrow) & 2) ^ 2;++    return ret;+}++inline limb_t sgn0_pty_mod_384(const vec384 a, const vec384 p)+{   return sgn0_pty_mod_n(a, p, NLIMBS(384));   }++inline limb_t sgn0_pty_mont_384(const vec384 a, const vec384 p, limb_t n0)+{+    vec384 tmp;++    from_mont_n(tmp, a, p, n0, NLIMBS(384));++    return sgn0_pty_mod_n(tmp, p, NLIMBS(384));+}++inline limb_t sgn0_pty_mod_384x(const vec384x a, const vec384 p)+{+    limb_t re, im, sign, prty;++    re = sgn0_pty_mod_n(a[0], p, NLIMBS(384));+    im = sgn0_pty_mod_n(a[1], p, NLIMBS(384));++    /* a->im!=0 ? sgn0(a->im) : sgn0(a->re) */+    sign = (limb_t)0 - vec_is_zero(a[1], sizeof(vec384));+    sign = (re & sign) | (im & ~sign);++    /* a->re==0 ? prty(a->im) : prty(a->re) */+    prty = (limb_t)0 - vec_is_zero(a[0], sizeof(vec384));+    prty = (im & prty) | (re & ~prty);++    return (sign & 2) | (prty & 1);+}++inline limb_t sgn0_pty_mont_384x(const vec384x a, const vec384 p, limb_t n0)+{+    vec384x tmp;++    from_mont_n(tmp[0], a[0], p, n0, NLIMBS(384));+    from_mont_n(tmp[1], a[1], p, n0, NLIMBS(384));++    return sgn0_pty_mod_384x(tmp, p);+}++void mul_mont_384x(vec384x ret, const vec384x a, const vec384x b,+                          const vec384 p, limb_t n0)+{+    vec384 aa, bb, cc;++    add_mod_n(aa, a[0], a[1], p, NLIMBS(384));+    add_mod_n(bb, b[0], b[1], p, NLIMBS(384));+    mul_mont_n(bb, bb, aa, p, n0, NLIMBS(384));+    mul_mont_n(aa, a[0], b[0], p, n0, NLIMBS(384));+    mul_mont_n(cc, a[1], b[1], p, n0, NLIMBS(384));+    sub_mod_n(ret[0], aa, cc, p, NLIMBS(384));+    sub_mod_n(ret[1], bb, aa, p, NLIMBS(384));+    sub_mod_n(ret[1], ret[1], cc, p, NLIMBS(384));+}++/*+ * mul_mont_n without final conditional subtraction, which implies+ * that modulus is one bit short, which in turn means that there are+ * no carries to handle between iterations...+ */+static void mul_mont_nonred_n(limb_t ret[], const limb_t a[], const limb_t b[],+                              const limb_t p[], limb_t n0, size_t n)+{+    __builtin_assume(n != 0 && n%2 == 0);+    llimb_t limbx;+    limb_t mx, hi, tmp[BLST_MAX_LIMBS+1];+    size_t i, j;++    for (mx=b[0], hi=0, i=0; i<n; i++) {+        limbx = (mx * (llimb_t)a[i]) + hi;+        tmp[i] = (limb_t)limbx;+        hi = (limb_t)(limbx >> LIMB_T_BITS);+    }+    mx = n0*tmp[0];+    tmp[i] = hi;++    for (j=0; ; ) {+        limbx = (mx * (llimb_t)p[0]) + tmp[0];+        hi = (limb_t)(limbx >> LIMB_T_BITS);+        for (i=1; i<n; i++) {+            limbx = (mx * (llimb_t)p[i] + hi) + tmp[i];+            tmp[i-1] = (limb_t)limbx;+            hi = (limb_t)(limbx >> LIMB_T_BITS);+        }+        tmp[i-1] = tmp[i] + hi;++        if (++j==n)+            break;++        for (mx=b[j], hi=0, i=0; i<n; i++) {+            limbx = (mx * (llimb_t)a[i] + hi) + tmp[i];+            tmp[i] = (limb_t)limbx;+            hi = (limb_t)(limbx >> LIMB_T_BITS);+        }+        mx = n0*tmp[0];+        tmp[i] = hi;+    }++    vec_copy(ret, tmp, n*sizeof(limb_t));+}++void sqr_n_mul_mont_383(vec384 ret, const vec384 a, size_t count,+                        const vec384 p, limb_t n0, const vec384 b)+{+    __builtin_assume(count != 0);+    while(count--) {+        mul_mont_nonred_n(ret, a, a, p, n0, NLIMBS(384));+        a = ret;+    }+    mul_mont_n(ret, ret, b, p, n0, NLIMBS(384));+}++void sqr_mont_382x(vec384x ret, const vec384x a,+                          const vec384 p, limb_t n0)+{+    llimb_t limbx;+    limb_t mask, carry, borrow;+    size_t i;+    vec384 t0, t1;++    /* "add_mod_n(t0, a[0], a[1], p, NLIMBS(384));" */+    for (carry=0, i=0; i<NLIMBS(384); i++) {+        limbx = a[0][i] + (a[1][i] + (llimb_t)carry);+        t0[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }++    /* "sub_mod_n(t1, a[0], a[1], p, NLIMBS(384));" */+    for (borrow=0, i=0; i<NLIMBS(384); i++) {+        limbx = a[0][i] - (a[1][i] + (llimb_t)borrow);+        t1[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }+    mask = 0 - borrow;+    launder(mask);++    /* "mul_mont_n(ret[1], a[0], a[1], p, n0, NLIMBS(384));" */+    mul_mont_nonred_n(ret[1], a[0], a[1], p, n0, NLIMBS(384));++    /* "add_mod_n(ret[1], ret[1], ret[1], p, NLIMBS(384));" */+    for (carry=0, i=0; i<NLIMBS(384); i++) {+        limb_t a_i = ret[1][i];+        ret[1][i] = a_i<<1 | carry;+        carry = a_i>>(LIMB_T_BITS-1);+    }++    /* "mul_mont_n(ret[0], t0, t1, p, n0, NLIMBS(384));" */+    mul_mont_nonred_n(ret[0], t0, t1, p, n0, NLIMBS(384));++    /* account for t1's sign... */+    for (borrow=0, i=0; i<NLIMBS(384); i++) {+        limbx = ret[0][i] - ((t0[i] & mask) + (llimb_t)borrow);+        ret[0][i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }+    mask = 0 - borrow;+    launder(mask);+    for (carry=0, i=0; i<NLIMBS(384); i++) {+        limbx = ret[0][i] + ((p[i] & mask) + (llimb_t)carry);+        ret[0][i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }+}++#if defined(__GNUC__) || defined(__clang__)+# define MSB(x) ({ limb_t ret = (x) >> (LIMB_T_BITS-1); launder(ret); ret; })+#else+# define MSB(x) ((x) >> (LIMB_T_BITS-1))+#endif++static size_t num_bits(limb_t l)+{+    limb_t x, mask;+    size_t bits = is_zero(l) ^ 1;++    if (sizeof(limb_t) == 8) {+        x = l >> (32 & (8*sizeof(limb_t)-1));+        mask = 0 - MSB(0 - x);+        bits += 32 & mask;+        l ^= (x ^ l) & mask;+    }++    x = l >> 16;+    mask = 0 - MSB(0 - x);+    bits += 16 & mask;+    l ^= (x ^ l) & mask;++    x = l >> 8;+    mask = 0 - MSB(0 - x);+    bits += 8 & mask;+    l ^= (x ^ l) & mask;++    x = l >> 4;+    mask = 0 - MSB(0 - x);+    bits += 4 & mask;+    l ^= (x ^ l) & mask;++    x = l >> 2;+    mask = 0 - MSB(0 - x);+    bits += 2 & mask;+    l ^= (x ^ l) & mask;++    bits += l >> 1;++    return bits;+}++#if defined(__clang_major__) && __clang_major__>7+__attribute__((optnone))+#endif+static limb_t lshift_2(limb_t hi, limb_t lo, size_t l)+{+    size_t r = LIMB_T_BITS - l;+    limb_t mask = 0 - (is_zero(l)^1);+    return (hi << (l&(LIMB_T_BITS-1))) | ((lo & mask) >> (r&(LIMB_T_BITS-1)));+}++/*+ * https://eprint.iacr.org/2020/972 with 'k' being LIMB_T_BITS-1.+ */+static void ab_approximation_n(limb_t a_[2], const limb_t a[],+                               limb_t b_[2], const limb_t b[], size_t n)+{+    __builtin_assume(n != 0 && n%2 == 0);+    limb_t a_hi, a_lo, b_hi, b_lo, mask;+    size_t i;++    i = n-1;+    a_hi = a[i],    a_lo = a[i-1];+    b_hi = b[i],    b_lo = b[i-1];+    for (i--; --i;) {+        mask = 0 - is_zero(a_hi | b_hi);+        a_hi = ((a_lo ^ a_hi) & mask) ^ a_hi;+        b_hi = ((b_lo ^ b_hi) & mask) ^ b_hi;+        a_lo = ((a[i] ^ a_lo) & mask) ^ a_lo;+        b_lo = ((b[i] ^ b_lo) & mask) ^ b_lo;+    }+    i = LIMB_T_BITS - num_bits(a_hi | b_hi);+    /* |i| can be LIMB_T_BITS if all a[2..]|b[2..] were zeros */++    a_[0] = a[0], a_[1] = lshift_2(a_hi, a_lo, i);+    b_[0] = b[0], b_[1] = lshift_2(b_hi, b_lo, i);+}++typedef struct { limb_t f0, g0, f1, g1; } factors;++static void inner_loop_n(factors *fg, const limb_t a_[2], const limb_t b_[2],+                         size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t f0 = 1, g0 = 0, f1 = 0, g1 = 1;+    limb_t a_lo, a_hi, b_lo, b_hi, t_lo, t_hi, odd, borrow, xorm;++    a_lo = a_[0], a_hi = a_[1];+    b_lo = b_[0], b_hi = b_[1];++    while(n--) {+        odd = 0 - (a_lo&1);++        /* a_ -= b_ if a_ is odd */+        t_lo = a_lo, t_hi = a_hi;+        limbx = a_lo - (llimb_t)(b_lo & odd);+        a_lo = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+        limbx = a_hi - ((llimb_t)(b_hi & odd) + borrow);+        a_hi = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS);++        /* negate a_-b_ if it borrowed */+        a_lo ^= borrow;+        a_hi ^= borrow;+        limbx = a_lo + (llimb_t)(borrow & 1);+        a_lo = (limb_t)limbx;+        a_hi += (limb_t)(limbx >> LIMB_T_BITS) & 1;++        /* b_=a_ if a_-b_ borrowed */+        b_lo = ((t_lo ^ b_lo) & borrow) ^ b_lo;+        b_hi = ((t_hi ^ b_hi) & borrow) ^ b_hi;++        /* exchange f0 and f1 if a_-b_ borrowed */+        xorm = (f0 ^ f1) & borrow;+        f0 ^= xorm;+        f1 ^= xorm;++        /* exchange g0 and g1 if a_-b_ borrowed */+        xorm = (g0 ^ g1) & borrow;+        g0 ^= xorm;+        g1 ^= xorm;++        /* subtract if a_ was odd */+        f0 -= f1 & odd;+        g0 -= g1 & odd;++        f1 <<= 1;+        g1 <<= 1;+        a_lo >>= 1; a_lo |= a_hi << (LIMB_T_BITS-1);+        a_hi >>= 1;+    }++    fg->f0 = f0, fg->g0 = g0, fg->f1 = f1, fg->g1= g1;+}++static limb_t cneg_n(limb_t ret[], const limb_t a[], limb_t neg, size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx = 0;+    limb_t carry;+    size_t i;++    for (carry=neg&1, i=0; i<n; i++) {+        limbx = (llimb_t)(a[i] ^ neg) + carry;+        ret[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }++    return 0 - MSB((limb_t)limbx);+}++static limb_t add_n(limb_t ret[], const limb_t a[], limb_t b[], size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t carry;+    size_t i;++    for (carry=0, i=0; i<n; i++) {+        limbx = a[i] + (b[i] + (llimb_t)carry);+        ret[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }++    return carry;+}++static limb_t umul_n(limb_t ret[], const limb_t a[], limb_t b, size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t hi;+    size_t i;++    for (hi=0, i=0; i<n; i++) {+        limbx = (b * (llimb_t)a[i]) + hi;+        ret[i] = (limb_t)limbx;+        hi = (limb_t)(limbx >> LIMB_T_BITS);+    }++    return hi;+}++static limb_t smul_n_shift_n(limb_t ret[], const limb_t a[], limb_t *f_,+                                           const limb_t b[], limb_t *g_,+                                           size_t n)+{+    __builtin_assume(n != 0);+    limb_t a_[BLST_MAX_LIMBS+1], b_[BLST_MAX_LIMBS+1], f, g, neg, carry, hi;+    size_t i;++    /* |a|*|f_| */+    f = *f_;+    neg = 0 - MSB(f);+    f = (f ^ neg) - neg;            /* ensure |f| is positive */+    (void)cneg_n(a_, a, neg, n);+    hi = umul_n(a_, a_, f, n);+    a_[n] = hi - (f & neg);++    /* |b|*|g_| */+    g = *g_;+    neg = 0 - MSB(g);+    g = (g ^ neg) - neg;            /* ensure |g| is positive */+    (void)cneg_n(b_, b, neg, n);+    hi = umul_n(b_, b_, g, n);+    b_[n] = hi - (g & neg);++    /* |a|*|f_| + |b|*|g_| */+    (void)add_n(a_, a_, b_, n+1);++    /* (|a|*|f_| + |b|*|g_|) >> k */+    for (carry=a_[0], i=0; i<n; i++) {+        hi = carry >> (LIMB_T_BITS-2);+        carry = a_[i+1];+        ret[i] = hi | (carry << 2);+    }++    /* ensure result is non-negative, fix up |f_| and |g_| accordingly */+    neg = 0 - MSB(carry);+    *f_ = (*f_ ^ neg) - neg;+    *g_ = (*g_ ^ neg) - neg;+    (void)cneg_n(ret, ret, neg, n);++    return neg;+}++static limb_t smul_2n(limb_t ret[], const limb_t u[], limb_t f,+                                    const limb_t v[], limb_t g, size_t n)+{+    __builtin_assume(n != 0);+    limb_t u_[2*BLST_MAX_LIMBS], v_[2*BLST_MAX_LIMBS], neg, hi;++    /* |u|*|f_| */+    neg = 0 - MSB(f);+    f = (f ^ neg) - neg;            /* ensure |f| is positive */+    neg = cneg_n(u_, u, neg, n);+    hi = umul_n(u_, u_, f, n) - (f&neg);++    /* |v|*|g_| */+    neg = 0 - MSB(g);+    g = (g ^ neg) - neg;            /* ensure |g| is positive */+    neg = cneg_n(v_, v, neg, n);+    hi += umul_n(v_, v_, g, n) - (g&neg);++    /* |u|*|f_| + |v|*|g_| */+    hi += add_n(ret, u_, v_, n);++    return hi;+}++static void ct_inverse_mod_n(limb_t ret[], const limb_t inp[],+                             const limb_t mod[], const limb_t modx[], size_t n)+{+    __builtin_assume(n != 0 && n%2 == 0);+    llimb_t limbx;+    limb_t a[BLST_MAX_LIMBS], b[BLST_MAX_LIMBS], u[2*BLST_MAX_LIMBS], v[2*BLST_MAX_LIMBS], t[2*BLST_MAX_LIMBS];+    limb_t a_[2], b_[2], sign, carry, top;+    factors fg;+    size_t i;++    vec_copy(a, inp, n*sizeof(limb_t));+    vec_copy(b, mod, n*sizeof(limb_t));+    vec_zero(u, 2*n*sizeof(limb_t)); u[0] = 1;+    vec_zero(v, 2*n*sizeof(limb_t));++    for (i=0; i<(2*n*LIMB_T_BITS)/(LIMB_T_BITS-2); i++) {+        ab_approximation_n(a_, a, b_, b, n);+        inner_loop_n(&fg, a_, b_, LIMB_T_BITS-2);+        (void)smul_n_shift_n(t, a, &fg.f0, b, &fg.g0, n);+        (void)smul_n_shift_n(b, a, &fg.f1, b, &fg.g1, n);+        vec_copy(a, t, n*sizeof(limb_t));+        smul_2n(t, u, fg.f0, v, fg.g0, 2*n);+        smul_2n(v, u, fg.f1, v, fg.g1, 2*n);+        vec_copy(u, t, 2*n*sizeof(limb_t));+    }++    inner_loop_n(&fg, a, b, (2*n*LIMB_T_BITS)%(LIMB_T_BITS-2));+    top = smul_2n(ret, u, fg.f1, v, fg.g1, 2*n);++    sign = 0 - MSB(top);    /* top is 1, 0 or -1 */+    for (carry=0, i=0; i<n; i++) {+        limbx = ret[n+i] + ((modx[i] & sign) + (llimb_t)carry);+        ret[n+i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }+    top += carry;+    sign = 0 - top;         /* top is 1, 0 or -1 */+    top |= sign;+    for (i=0; i<n; i++)+        a[i] = modx[i] & top;+    (void)cneg_n(a, a, 0 - MSB(sign), n);+    add_n(ret+n, ret+n, a, n);+}++#define CT_INVERSE_MOD_IMPL(bits, bits2) \+inline void ct_inverse_mod_##bits(vec##bits2 ret, const vec##bits inp, \+                                  const vec##bits mod, const vec##bits modx) \+{   ct_inverse_mod_n(ret, inp, mod, modx, NLIMBS(bits));   }++CT_INVERSE_MOD_IMPL(256, 512)+CT_INVERSE_MOD_IMPL(384, 768)++/*+ * Copy of inner_loop_n above, but with |L| updates.+ */+static limb_t legendre_loop_n(limb_t L, factors *fg, const limb_t a_[2],+                              const limb_t b_[2], size_t n)+{+    __builtin_assume(n != 0);+    llimb_t limbx;+    limb_t f0 = 1, g0 = 0, f1 = 0, g1 = 1;+    limb_t a_lo, a_hi, b_lo, b_hi, t_lo, t_hi, odd, borrow, xorm;++    a_lo = a_[0], a_hi = a_[1];+    b_lo = b_[0], b_hi = b_[1];++    while(n--) {+        odd = 0 - (a_lo&1);++        /* a_ -= b_ if a_ is odd */+        t_lo = a_lo, t_hi = a_hi;+        limbx = a_lo - (llimb_t)(b_lo & odd);+        a_lo = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+        limbx = a_hi - ((llimb_t)(b_hi & odd) + borrow);+        a_hi = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS);++        L += ((t_lo & b_lo) >> 1) & borrow;++        /* negate a_-b_ if it borrowed */+        a_lo ^= borrow;+        a_hi ^= borrow;+        limbx = a_lo + (llimb_t)(borrow & 1);+        a_lo = (limb_t)limbx;+        a_hi += (limb_t)(limbx >> LIMB_T_BITS) & 1;++        /* b_=a_ if a_-b_ borrowed */+        b_lo = ((t_lo ^ b_lo) & borrow) ^ b_lo;+        b_hi = ((t_hi ^ b_hi) & borrow) ^ b_hi;++        /* exchange f0 and f1 if a_-b_ borrowed */+        xorm = (f0 ^ f1) & borrow;+        f0 ^= xorm;+        f1 ^= xorm;++        /* exchange g0 and g1 if a_-b_ borrowed */+        xorm = (g0 ^ g1) & borrow;+        g0 ^= xorm;+        g1 ^= xorm;++        /* subtract if a_ was odd */+        f0 -= f1 & odd;+        g0 -= g1 & odd;++        f1 <<= 1;+        g1 <<= 1;+        a_lo >>= 1; a_lo |= a_hi << (LIMB_T_BITS-1);+        a_hi >>= 1;++        L += (b_lo + 2) >> 2;+    }++    fg->f0 = f0, fg->g0 = g0, fg->f1 = f1, fg->g1 = g1;++    return L;+}++static bool_t ct_is_sqr_mod_n(const limb_t inp[], const limb_t mod[], size_t n)+{+    __builtin_assume(n != 0 && n%2 == 0);+    limb_t a[BLST_MAX_LIMBS], b[BLST_MAX_LIMBS], t[BLST_MAX_LIMBS];+    limb_t a_[2], b_[2], neg, L = 0;+    factors fg;+    size_t i;++    vec_copy(a, inp, n*sizeof(limb_t));+    vec_copy(b, mod, n*sizeof(limb_t));++    for (i=0; i<(2*n*LIMB_T_BITS)/(LIMB_T_BITS-2); i++) {+        ab_approximation_n(a_, a, b_, b, n);+        L = legendre_loop_n(L, &fg, a_, b_, LIMB_T_BITS-2);+        neg = smul_n_shift_n(t, a, &fg.f0, b, &fg.g0, n);+        (void)smul_n_shift_n(b, a, &fg.f1, b, &fg.g1, n);+        vec_copy(a, t, n*sizeof(limb_t));+        L += (b[0] >> 1) & neg;+    }++    L = legendre_loop_n(L, &fg, a, b, (2*n*LIMB_T_BITS)%(LIMB_T_BITS-2));++    return (L & 1) ^ 1;+}++#define CT_IS_SQR_MOD_IMPL(bits) \+inline bool_t ct_is_square_mod_##bits(const vec##bits inp, \+                                      const vec##bits mod) \+{   return ct_is_sqr_mod_n(inp, mod, NLIMBS(bits));   }++CT_IS_SQR_MOD_IMPL(384)++/*+ * |div_top| points at two most significant limbs of the dividend, |d_hi|+ * and |d_lo| are two most significant limbs of the divisor. If divisor+ * is only one limb, it is to be passed in |d_hi| with zero in |d_lo|.+ * The divisor is required to be "bitwise left-aligned," and dividend's+ * top limbs to be not larger than the divisor's. The latter limitation+ * can be problematic in the first iteration of multi-precision division,+ * where in most general case the condition would have to be "smaller."+ * The subroutine considers four limbs, two of which are "overlapping,"+ * hence the name... Another way to look at it is to think of the pair+ * of the dividend's limbs being suffixed with a zero:+ *   +-------+-------+-------++ * R |       |       |   0   |+ *   +-------+-------+-------++ *           +-------+-------++ * D         |       |       |+ *           +-------+-------++ */+limb_t div_3_limbs(const limb_t div_top[2], limb_t d_lo, limb_t d_hi)+{+    llimb_t Rx;+    limb_t r_lo = div_top[0], r_hi = div_top[1];+    limb_t Q = 0, mask, borrow, rx;+    size_t i;++    for (i = 0; i < LIMB_T_BITS; i++) {+        /* "borrow, Rx = R - D" */+        Rx = (llimb_t)r_lo - d_lo;+        rx = (limb_t)Rx;+        borrow = (limb_t)(Rx >> LIMB_T_BITS) & 1;+        Rx = r_hi - (d_hi + (llimb_t)borrow);+        borrow = (limb_t)(Rx >> LIMB_T_BITS);++        /* "if (R >= D) R -= D" */+        r_lo = ((r_lo ^ rx) & borrow) ^ rx;+        rx = (limb_t)Rx;+        r_hi = ((r_hi ^ rx) & borrow) ^ rx;++        Q <<= 1;+        Q |= ~borrow & 1;++        /* "D >>= 1" */+        d_lo >>= 1; d_lo |= d_hi << (LIMB_T_BITS - 1);+        d_hi >>= 1;+    }++    mask = 0 - MSB(Q);  /* does it overflow? */++    /* "borrow, Rx = R - D" */+    Rx = (llimb_t)r_lo - d_lo;+    rx = (limb_t)Rx;+    borrow = (limb_t)(Rx >> LIMB_T_BITS) & 1;+    Rx = r_hi - (d_hi + (llimb_t)borrow);+    borrow = (limb_t)(Rx >> LIMB_T_BITS) & 1;++    Q <<= 1;+    Q |= borrow ^ 1;++    return (Q | mask);+}++static limb_t quot_rem_n(limb_t *div_rem, const limb_t *divisor,+                                          limb_t quotient, size_t n)+{+    __builtin_assume(n != 0 && n%2 == 0);+    llimb_t limbx;+    limb_t tmp[BLST_MAX_LIMBS+1], carry, mask, borrow;+    size_t i;++    /* divisor*quotient */+    for (carry=0, i=0; i<n; i++) {+        limbx = (quotient * (llimb_t)divisor[i]) + carry;+        tmp[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS);+    }+    tmp[i] = carry;++    /* remainder = dividend - divisor*quotient */+    for (borrow=0, i=0; i<=n; i++) {+        limbx = div_rem[i] - (tmp[i] + (llimb_t)borrow);+        tmp[i] = (limb_t)limbx;+        borrow = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    mask = 0 - borrow;+    launder(mask);++    /* if quotient was off by one, add divisor to the remainder */+    for (carry=0, i=0; i<n; i++) {+        limbx = tmp[i] + ((divisor[i] & mask) + (llimb_t)carry);+        div_rem[i] = (limb_t)limbx;+        carry = (limb_t)(limbx >> LIMB_T_BITS) & 1;+    }++    return (div_rem[i] = quotient + mask);+}++inline limb_t quot_rem_128(limb_t *div_rem, const limb_t *divisor,+                                            limb_t quotient)+{   return quot_rem_n(div_rem, divisor, quotient, NLIMBS(128));   }++inline limb_t quot_rem_64(limb_t *div_rem, const limb_t *divisor,+                                           limb_t quotient)+{   return quot_rem_n(div_rem, divisor, quotient, NLIMBS(64));   }++/*+ * Unlock reference implementations in vect.c+ */+#define mul_by_8_mod_384 mul_by_8_mod_384+#define mul_by_8_mod_384x mul_by_8_mod_384x+#define mul_by_3_mod_384x mul_by_3_mod_384x+#define mul_by_1_plus_i_mod_384x mul_by_1_plus_i_mod_384x+#define add_mod_384x add_mod_384x+#define sub_mod_384x sub_mod_384x+#define lshift_mod_384x lshift_mod_384x+#define sqr_mont_384x sqr_mont_384x++inline void vec_prefetch(const void *ptr, size_t len)+{   (void)ptr; (void)len;   }++/*+ * SHA-256+ */+#define ROTR(x,n)	((x)>>n | (x)<<(32-n))+#define Sigma0(x)	(ROTR((x),2) ^ ROTR((x),13) ^ ROTR((x),22))+#define Sigma1(x)	(ROTR((x),6) ^ ROTR((x),11) ^ ROTR((x),25))+#define sigma0(x)	(ROTR((x),7) ^ ROTR((x),18) ^ ((x)>>3))+#define sigma1(x)	(ROTR((x),17) ^ ROTR((x),19) ^ ((x)>>10))+#define Ch(x,y,z)	(((x) & (y)) ^ ((~(x)) & (z)))+#define Maj(x,y,z)	(((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))++void blst_sha256_block_data_order(unsigned int *v, const void *inp,+                                                   size_t blocks)+{+    static const unsigned int K256[64] = {+        0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,+        0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,+        0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,+        0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,+        0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,+        0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,+        0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,+        0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,+        0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,+        0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,+        0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,+        0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,+        0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,+        0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,+        0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,+        0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2+    };+    unsigned int X[16], l, a, b, c, d, e, f, g, h, s0, s1, T1, T2;+    const unsigned char *data = inp;+    size_t round;++    a = v[0];+    b = v[1];+    c = v[2];+    d = v[3];+    e = v[4];+    f = v[5];+    g = v[6];+    h = v[7];++    while (blocks--) {+        for (round = 0; round < 16; round++) {+            l  = (unsigned int)data[0] << 24;+            l |= (unsigned int)data[1] << 16;+            l |= (unsigned int)data[2] << 8;+            l |= (unsigned int)data[3];+            data += 4;+            T1 = X[round] = l;+            T1 += h + Sigma1(e) + Ch(e, f, g) + K256[round];+            T2 = Sigma0(a) + Maj(a, b, c);+            h = g;+            g = f;+            f = e;+            e = d + T1;+            d = c;+            c = b;+            b = a;+            a = T1 + T2;+        }++        for (; round < 64; round++) {+            s0 = X[(round + 1) & 0x0f];+            s0 = sigma0(s0);+            s1 = X[(round + 14) & 0x0f];+            s1 = sigma1(s1);++            T1 = X[round & 0xf] += s0 + s1 + X[(round + 9) & 0xf];+            T1 += h + Sigma1(e) + Ch(e, f, g) + K256[round];+            T2 = Sigma0(a) + Maj(a, b, c);+            h = g;+            g = f;+            f = e;+            e = d + T1;+            d = c;+            c = b;+            b = a;+            a = T1 + T2;+        }++        a += v[0]; v[0] = a;+        b += v[1]; v[1] = b;+        c += v[2]; v[2] = c;+        d += v[3]; v[3] = d;+        e += v[4]; v[4] = e;+        f += v[5]; v[5] = f;+        g += v[6]; v[6] = g;+        h += v[7]; v[7] = h;+    }+}+#undef ROTR+#undef Sigma0+#undef Sigma1+#undef sigma0+#undef sigma1+#undef Ch+#undef Maj++void blst_sha256_hcopy(unsigned int dst[8], const unsigned int src[8])+{+    size_t i;++    for (i=0; i<8; i++)+        dst[i] = src[i];+}++void blst_sha256_emit(unsigned char md[32], const unsigned int h[8])+{+    size_t i;++    for (i=0; i<8; i++, md+=4) {+        unsigned int h_i = h[i];+        md[0] = (unsigned char)(h_i >> 24);+        md[1] = (unsigned char)(h_i >> 16);+        md[2] = (unsigned char)(h_i >> 8);+        md[3] = (unsigned char)h_i;+    }+}++void blst_sha256_bcopy(void *dst_, const void *src_, size_t len)+{+    unsigned char *dst = dst_;+    const unsigned char *src = src_;+    size_t i;++    for (i=0; i<len; i++)+        dst[i] = src[i];+}
+ vendor/external/blst/src/pairing.c view
@@ -0,0 +1,493 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "point.h"+#include "fields.h"++/*+ * Line evaluations from  https://eprint.iacr.org/2010/354.pdf+ * with a twist moving common expression to line_by_Px2.+ */+static void line_add(vec384fp6 line, POINTonE2 *T, const POINTonE2 *R,+                                                   const POINTonE2_affine *Q)+{+    vec384x Z1Z1, U2, S2, H, HH, I, J, V;+#if 1+# define r line[1]+#else+    vec384x r;+#endif++    /*+     * https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-madd-2007-bl+     * with XYZ3 being |T|, XYZ1 - |R|, XY2 - |Q|, i.e. Q is affine+     */+    sqr_fp2(Z1Z1, R->Z);                /* Z1Z1 = Z1^2 */+    mul_fp2(U2, Q->X, Z1Z1);            /* U2 = X2*Z1Z1 */++    mul_fp2(S2, Q->Y, R->Z);+    mul_fp2(S2, S2, Z1Z1);              /* S2 = Y2*Z1*Z1Z1 */++    sub_fp2(H, U2, R->X);               /* H = U2-X1 */++    sqr_fp2(HH, H);                     /* HH = H^2 */+    add_fp2(I, HH, HH);+    add_fp2(I, I, I);                   /* I = 4*HH */++    mul_fp2(J, H, I);                   /* J = H*I */++    sub_fp2(r, S2, R->Y);+    add_fp2(r, r, r);                   /* r = 2*(S2-Y1) */++    mul_fp2(V, R->X, I);                /* V = X1*I */++    sqr_fp2(T->X, r);+    sub_fp2(T->X, T->X, J);+    sub_fp2(T->X, T->X, V);+    sub_fp2(T->X, T->X, V);             /* X3 = r^2-J-2*V */++    mul_fp2(J, J, R->Y);+    sub_fp2(T->Y, V, T->X);+    mul_fp2(T->Y, T->Y, r);+    sub_fp2(T->Y, T->Y, J);+    sub_fp2(T->Y, T->Y, J);             /* Y3 = r*(V-X3)-2*Y1*J */++    add_fp2(T->Z, R->Z, H);+    sqr_fp2(T->Z, T->Z);+    sub_fp2(T->Z, T->Z, Z1Z1);+    sub_fp2(T->Z, T->Z, HH);            /* Z3 = (Z1+H)^2-Z1Z1-HH */++    /*+     * line evaluation+     */+    mul_fp2(I, r, Q->X);+    mul_fp2(J, Q->Y, T->Z);+    sub_fp2(I, I, J);+    add_fp2(line[0], I, I);          /* 2*(r*X2 - Y2*Z3) */+#ifdef r+# undef r+#else+    vec_copy(line[1], r, sizeof(r));+#endif+    vec_copy(line[2], T->Z, sizeof(T->Z));+}++static void line_dbl(vec384fp6 line, POINTonE2 *T, const POINTonE2 *Q)+{+    vec384x ZZ, A, B, C, D, E, F;++    /*+     * https://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-alnr+     */+    sqr_fp2(A, Q->X);                   /* A = X1^2 */+    sqr_fp2(B, Q->Y);                   /* B = Y1^2 */+    sqr_fp2(ZZ, Q->Z);                  /* ZZ = Z1^2 */+    sqr_fp2(C, B);                      /* C = B^2 */++    add_fp2(D, Q->X, B);                /* X1+B */+    sqr_fp2(D, D);                      /* (X1+B)^2 */+    sub_fp2(D, D, A);                   /* (X1+B)^2-A */+    sub_fp2(D, D, C);                   /* (X1+B)^2-A-C */+    add_fp2(D, D, D);                   /* D = 2*((X1+B)^2-A-C) */++    mul_by_3_fp2(E, A);                 /* E = 3*A */+    sqr_fp2(F, E);                      /* F = E^2 */++    add_fp2(line[0], E, Q->X);          /* 3*A+X1 for line evaluation */++    sub_fp2(T->X, F, D);+    sub_fp2(T->X, T->X, D);             /* X3 = F-2*D */++    add_fp2(T->Z, Q->Y, Q->Z);+    sqr_fp2(T->Z, T->Z);+    sub_fp2(T->Z, T->Z, B);+    sub_fp2(T->Z, T->Z, ZZ);            /* Z3 = (Y1+Z1)^2-B-ZZ */++    mul_by_8_fp2(C, C);                 /* 8*C */+    sub_fp2(T->Y, D, T->X);             /* D-X3 */+    mul_fp2(T->Y, T->Y, E);             /* E*(D-X3) */+    sub_fp2(T->Y, T->Y, C);             /* Y3 = E*(D-X3)-8*C */++    /*+     * line evaluation+     */+    sqr_fp2(line[0], line[0]);+    sub_fp2(line[0], line[0], A);+    sub_fp2(line[0], line[0], F);       /* (3*A+X1)^2 - X1^2 - 9*A^2 */+    lshift_fp2(B, B, 2);+    sub_fp2(line[0], line[0], B);       /* 6*X1^3 - 4*Y1^2 */++    mul_fp2(line[1], E, ZZ);            /* 3*X1^2 * Z1^2 */++    mul_fp2(line[2], T->Z, ZZ);         /* Z3 * Z1^2 */+}++static void line_by_Px2(vec384fp6 line, const POINTonE1_affine *Px2)+{+    mul_fp(line[1][0], line[1][0], Px2->X);   /* "b01" *= -2*P->X */+    mul_fp(line[1][1], line[1][1], Px2->X);++    mul_fp(line[2][0], line[2][0], Px2->Y);   /* "b11" *= 2*P->Y */+    mul_fp(line[2][1], line[2][1], Px2->Y);+}++#if 0+static void add_n_dbl(vec384fp12 ret, POINTonE2 *T, const POINTonE2_affine *Q,+                      const POINTonE1_affine *Px2, vec384fp6 line, size_t n)+{+    line_add(line, T, T, Q);    line_by_Px2(line, Px2);+    mul_by_xy00z0_fp12(ret, ret, line);+    while (n--) {+        sqr_fp12(ret, ret);+        line_dbl(line, T, T);   line_by_Px2(line, Px2);+        mul_by_xy00z0_fp12(ret, ret, line);+    }+}++static void miller_loop(vec384fp12 ret, const POINTonE2 *Q, const POINTonE1 *P)+{+#define Q ((const POINTonE2_affine *)Q)+    POINTonE2 T[1];+    POINTonE1_affine Px2[1];+    vec384fp6 line; /* it's not actual fp6, but 3 packed fp2, "xy00z0"  */++    /* Move common expression from line evaluation to line_by_Px2. */+    add_fp(Px2->X, P->X, P->X);+    neg_fp(Px2->X, Px2->X);+    add_fp(Px2->Y, P->Y, P->Y);++    vec_copy(T->X, Q->X, 2*sizeof(T->X));+    vec_copy(T->Z, BLS12_381_Rx.p2, sizeof(T->Z));++    /* first step is ret = 1^2*line, which is replaced with ret = line  */+    line_dbl(line, T, T);                       /* 0x2                  */+    line_by_Px2(line, Px2);+    vec_zero(ret, sizeof(vec384fp12));+    vec_copy(ret[0][0], line[0], 2*sizeof(vec384fp2));+    vec_copy(ret[1][1], line[2], sizeof(vec384fp2));+    add_n_dbl(ret, T, Q, Px2, line, 2);         /* ..0xc                */+    add_n_dbl(ret, T, Q, Px2, line, 3);         /* ..0x68               */+    add_n_dbl(ret, T, Q, Px2, line, 9);         /* ..0xd200             */+    add_n_dbl(ret, T, Q, Px2, line, 32);        /* ..0xd20100000000     */+    add_n_dbl(ret, T, Q, Px2, line, 16);        /* ..0xd201000000010000 */+    conjugate_fp12(ret);                /* account for z being negative */+#undef Q+}+#endif++static void start_dbl_n(vec384fp12 ret, POINTonE2 T[],+                                        const POINTonE1_affine Px2[], size_t n)+{+    size_t i;+    vec384fp6 line; /* it's not actual fp6, but 3 packed fp2, "xy00z0"  */++    /* first step is ret = 1^2*line, which is replaced with ret = line  */+    line_dbl(line, T+0, T+0);           line_by_Px2(line, Px2+0);+    vec_zero(ret, sizeof(vec384fp12));+    vec_copy(ret[0][0], line[0], 2*sizeof(vec384fp2));+    vec_copy(ret[1][1], line[2], sizeof(vec384fp2));++    for (i = 1; i < n; i++) {+        line_dbl(line, T+i, T+i);       line_by_Px2(line, Px2+i);+        mul_by_xy00z0_fp12(ret, ret, line);+    }+}++static void add_n_dbl_n(vec384fp12 ret, POINTonE2 T[],+                                        const POINTonE2_affine Q[],+                                        const POINTonE1_affine Px2[],+                                        size_t n, size_t k)+{+    size_t i;+    vec384fp6 line; /* it's not actual fp6, but 3 packed fp2, "xy00z0"  */++    for (i = 0; i < n; i++) {+        line_add(line, T+i, T+i, Q+i);  line_by_Px2(line, Px2+i);+        mul_by_xy00z0_fp12(ret, ret, line);+    }+    while (k--) {+        sqr_fp12(ret, ret);+        for (i = 0; i < n; i++) {+            line_dbl(line, T+i, T+i);   line_by_Px2(line, Px2+i);+            mul_by_xy00z0_fp12(ret, ret, line);+        }+    }+}++static void miller_loop_n(vec384fp12 ret, const POINTonE2_affine Q[],+                                          const POINTonE1_affine P[], size_t n)+{+#if !defined(__STDC_VERSION__) || __STDC_VERSION__<199901 \+                               || defined(__STDC_NO_VLA__)+    POINTonE2 *T = alloca(n*sizeof(POINTonE2));+    POINTonE1_affine *Px2 = alloca(n*sizeof(POINTonE1_affine));+#else+    POINTonE2 T[n];+    POINTonE1_affine Px2[n];+#endif+    size_t i;++    if ((n == 1) && (vec_is_zero(&Q[0], sizeof(Q[0])) |+                     vec_is_zero(&P[0], sizeof(P[0]))) ) {+        /*+         * Special case of infinite aggregated signature, pair the additive+         * group's identity with the multiplicative group's identity.+         */+        vec_copy(ret, BLS12_381_Rx.p12, sizeof(vec384fp12));+        return;+    }++    for (i = 0; i < n; i++) {+        /* Move common expression from line evaluation to line_by_Px2.  */+        add_fp(Px2[i].X, P[i].X, P[i].X);+        neg_fp(Px2[i].X, Px2[i].X);+        add_fp(Px2[i].Y, P[i].Y, P[i].Y);++        vec_copy(T[i].X, Q[i].X, 2*sizeof(T[i].X));+        vec_copy(T[i].Z, BLS12_381_Rx.p2, sizeof(T[i].Z));+    }++    /* first step is ret = 1^2*line, which is replaced with ret = line  */+    start_dbl_n(ret, T, Px2, n);                /* 0x2                  */+    add_n_dbl_n(ret, T, Q, Px2, n, 2);          /* ..0xc                */+    add_n_dbl_n(ret, T, Q, Px2, n, 3);          /* ..0x68               */+    add_n_dbl_n(ret, T, Q, Px2, n, 9);          /* ..0xd200             */+    add_n_dbl_n(ret, T, Q, Px2, n, 32);         /* ..0xd20100000000     */+    add_n_dbl_n(ret, T, Q, Px2, n, 16);         /* ..0xd201000000010000 */+    conjugate_fp12(ret);                /* account for z being negative */+}++static void pre_add_n_dbl(vec384fp6 lines[], POINTonE2 *T,+                                             const POINTonE2_affine *Q,+                                             size_t n)+{+    line_add(lines++[0], T, T, Q);+    while (n--)+        line_dbl(lines++[0], T, T);+}++static void precompute_lines(vec384fp6 Qlines[68], const POINTonE2_affine *Q)+{+    POINTonE2 T[1];++    vec_copy(T->X, Q->X, 2*sizeof(T->X));+    vec_copy(T->Z, BLS12_381_Rx.p2, sizeof(T->Z));++    line_dbl(Qlines[0], T, T);                  /* 0x2                  */+    pre_add_n_dbl(&Qlines[1],  T, Q, 2);        /* ..0xc                */+    pre_add_n_dbl(&Qlines[4],  T, Q, 3);        /* ..0x68               */+    pre_add_n_dbl(&Qlines[8],  T, Q, 9);        /* ..0xd200             */+    pre_add_n_dbl(&Qlines[18], T, Q, 32);       /* ..0xd20100000000     */+    pre_add_n_dbl(&Qlines[51], T, Q, 16);       /* ..0xd201000000010000 */+}++static void post_line_by_Px2(vec384fp6 out, const vec384fp6 in,+                                            const POINTonE1_affine *Px2)+{+    vec_copy(out[0], in[0], sizeof(out[0]));++    mul_fp(out[1][0], in[1][0], Px2->X);        /* "b01" *= -2*P->X */+    mul_fp(out[1][1], in[1][1], Px2->X);++    mul_fp(out[2][0], in[2][0], Px2->Y);        /* "b11" *= 2*P->Y */+    mul_fp(out[2][1], in[2][1], Px2->Y);+}++static void post_add_n_dbl(vec384fp12 ret, const vec384fp6 lines[],+                           const POINTonE1_affine *Px2, size_t n)+{+    vec384fp6 line;++    post_line_by_Px2(line, lines++[0], Px2);+    mul_by_xy00z0_fp12(ret, ret, line);+    while (n--) {+        sqr_fp12(ret, ret);+        post_line_by_Px2(line, lines++[0], Px2);+        mul_by_xy00z0_fp12(ret, ret, line);+    }+}++static void miller_loop_lines(vec384fp12 ret, const vec384fp6 Qlines[68],+                                              const POINTonE1_affine *P)+{+    POINTonE1_affine Px2[1];+    vec384fp6 line; /* it's not actual fp6, but 3 packed fp2, "xy00z0"  */++    /* Move common expression from line evaluation to line_by_Px2. */+    add_fp(Px2->X, P->X, P->X);+    neg_fp(Px2->X, Px2->X);+    add_fp(Px2->Y, P->Y, P->Y);++    /* first step is ret = 1^2*line, which is replaced with ret = line  */+    post_line_by_Px2(line, Qlines[0], Px2);     /* 0x2                  */+    vec_zero(ret, sizeof(vec384fp12));+    vec_copy(ret[0][0], line[0], 2*sizeof(vec384fp2));+    vec_copy(ret[1][1], line[2], sizeof(vec384fp2));+    post_add_n_dbl(ret, &Qlines[1],  Px2, 2);   /* ..0xc                */+    post_add_n_dbl(ret, &Qlines[4],  Px2, 3);   /* ..0x68               */+    post_add_n_dbl(ret, &Qlines[8],  Px2, 9);   /* ..0xd200             */+    post_add_n_dbl(ret, &Qlines[18], Px2, 32);  /* ..0xd20100000000     */+    post_add_n_dbl(ret, &Qlines[51], Px2, 16);  /* ..0xd201000000010000 */+    conjugate_fp12(ret);                /* account for z being negative */+}++#ifdef INTERNAL_TESTMODE+static void miller_loop_alt(vec384fp12 ret, const POINTonE2_affine *Q,+                                            const POINTonE1_affine *P)+{+    vec384fp6 lines[68];++    precompute_lines(lines, Q);+    miller_loop_lines(ret, lines, P);+}+#endif++static void mul_n_sqr(vec384fp12 ret, const vec384fp12 a, size_t n)+{+    mul_fp12(ret, ret, a);+    while (n--)+        cyclotomic_sqr_fp12(ret, ret);+}++static void raise_to_z_div_by_2(vec384fp12 ret, const vec384fp12 a)+{+    cyclotomic_sqr_fp12(ret, a);                /* 0x2                  */+    mul_n_sqr(ret, a, 2);                       /* ..0xc                */+    mul_n_sqr(ret, a, 3);                       /* ..0x68               */+    mul_n_sqr(ret, a, 9);                       /* ..0xd200             */+    mul_n_sqr(ret, a, 32);                      /* ..0xd20100000000     */+    mul_n_sqr(ret, a, 16-1);                    /* ..0x6900800000008000 */+    conjugate_fp12(ret);                /* account for z being negative */+}++#define raise_to_z(a, b) (raise_to_z_div_by_2(a, b), cyclotomic_sqr_fp12(a, a))++/*+ * Adaptation from <zkcrypto>/pairing/src/bls12_381/mod.rs+ */+static void final_exp(vec384fp12 ret, const vec384fp12 f)+{+    vec384fp12 y0, y1, y2, y3;++    vec_copy(y1, f, sizeof(y1));+    conjugate_fp12(y1);+    inverse_fp12(y2, f);+    mul_fp12(ret, y1, y2);+    frobenius_map_fp12(y2, ret, 2);+    mul_fp12(ret, ret, y2);++    cyclotomic_sqr_fp12(y0, ret);+    raise_to_z(y1, y0);+    raise_to_z_div_by_2(y2, y1);+    vec_copy(y3, ret, sizeof(y3));+    conjugate_fp12(y3);+    mul_fp12(y1, y1, y3);+    conjugate_fp12(y1);+    mul_fp12(y1, y1, y2);+    raise_to_z(y2, y1);+    raise_to_z(y3, y2);+    conjugate_fp12(y1);+    mul_fp12(y3, y3, y1);+    conjugate_fp12(y1);+    frobenius_map_fp12(y1, y1, 3);+    frobenius_map_fp12(y2, y2, 2);+    mul_fp12(y1, y1, y2);+    raise_to_z(y2, y3);+    mul_fp12(y2, y2, y0);+    mul_fp12(y2, y2, ret);+    mul_fp12(y1, y1, y2);+    frobenius_map_fp12(y2, y3, 1);+    mul_fp12(ret, y1, y2);+}++void blst_miller_loop(vec384fp12 ret, const POINTonE2_affine *Q,+                                      const POINTonE1_affine *P)+{   miller_loop_n(ret, Q ? Q : (const POINTonE2_affine *)&BLS12_381_G2,+                       P ? P : (const POINTonE1_affine *)&BLS12_381_G1, 1);+}++#ifndef MILLER_LOOP_N_MAX+# define MILLER_LOOP_N_MAX 16+#endif++void blst_miller_loop_n(vec384fp12 out, const POINTonE2_affine *const Qs[],+                                        const POINTonE1_affine *const Ps[],+                                        size_t n)+{   /* ~10KB of stack storage */+    POINTonE2 T[MILLER_LOOP_N_MAX];+    POINTonE2_affine Q[MILLER_LOOP_N_MAX];+    POINTonE1_affine Px2[MILLER_LOOP_N_MAX];+    const POINTonE2_affine *Qptr = NULL;+    const POINTonE1_affine *Pptr = NULL;+    size_t i, j;++    for (i = 0, j = 0; j < n; j++) {+        Qptr = *Qs ? *Qs++ : Qptr+1;+        Pptr = *Ps ? *Ps++ : Pptr+1;++        /* Move common expression from line evaluation to line_by_Px2.  */+        add_fp(Px2[i].X, Pptr->X, Pptr->X);+        neg_fp(Px2[i].X, Px2[i].X);+        add_fp(Px2[i].Y, Pptr->Y, Pptr->Y);++        vec_copy(Q[i].X, Qptr->X, 2*sizeof(Q[i].X));+        vec_copy(T[i].X, Qptr->X, 2*sizeof(T[i].X));+        vec_copy(T[i].Z, BLS12_381_Rx.p2, sizeof(T[i].Z));++        if (++i == MILLER_LOOP_N_MAX || j == n-1) {+            vec384fp12 tmp;+            vec384fp6 *ret = j < MILLER_LOOP_N_MAX ? out : tmp;++            /* first step is ret = 1^2*line, which is just ret = line       */+            start_dbl_n(ret, T, Px2, i);            /* 0x2                  */+            add_n_dbl_n(ret, T, Q, Px2, i, 2);      /* ..0xc                */+            add_n_dbl_n(ret, T, Q, Px2, i, 3);      /* ..0x68               */+            add_n_dbl_n(ret, T, Q, Px2, i, 9);      /* ..0xd200             */+            add_n_dbl_n(ret, T, Q, Px2, i, 32);     /* ..0xd20100000000     */+            add_n_dbl_n(ret, T, Q, Px2, i, 16);     /* ..0xd201000000010000 */+            conjugate_fp12(ret);            /* account for z being negative */++            if (j >= MILLER_LOOP_N_MAX)+                mul_fp12(out, out, ret);++            i = 0;+        }+    }+}++void blst_final_exp(vec384fp12 ret, const vec384fp12 f)+{   final_exp(ret, f);   }++void blst_precompute_lines(vec384fp6 Qlines[68], const POINTonE2_affine *Q)+{   precompute_lines(Qlines, Q);   }++void blst_miller_loop_lines(vec384fp12 ret, const vec384fp6 Qlines[68],+                                            const POINTonE1_affine *P)+{   miller_loop_lines(ret, Qlines, P);   }++static bool_t is_cyclotomic(const vec384fp12 f)+{+    vec384fp12 a, b;++    frobenius_map_fp12(a, f, 2);+    frobenius_map_fp12(b, a, 2);+    mul_fp12(b, b, f);++    return vec_is_equal(a, b, sizeof(a));+}++int blst_fp12_in_group(const vec384fp12 f)+{+    vec384fp12 a, b;++    if (vec_is_zero(f, sizeof(vec384fp12)) || !is_cyclotomic(f))+        return 0;++    frobenius_map_fp12(a, f, 1);+    raise_to_z(b, f);++    return (int)vec_is_equal(a, b, sizeof(a));+}
+ vendor/external/blst/src/pentaroot-addchain.h view
@@ -0,0 +1,333 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+/*+ * The "magic" number is 1/5 modulo BLS12_381_r-1. Exponentiation to which+ * yields 5th root of the base.+ *+ * Generated with 'addchain 20974350070050476191779096203274386335076221000211055129041463479975432473805'+ * https://github.com/kwantam/addchain+ * # Bos-Coster (win=4)           :  307 (15)+ * # Bos-Coster (win=10)          :  307 (18)+ * # Yacobi                       :  319 (16)+ * # Bos-Coster (win=2)           :  319 ( 5)+ * # Bos-Coster (win=5)           :  306 (19) <<<+ * # Bos-Coster (win=7)           :  311 (22)+ * # Bos-Coster (win=9)           :  313 (20)+ * # Bos-Coster (win=3)           :  314 ( 9)+ * # Bos-Coster (win=6)           :  309 (21)+ * # Bos-Coster (win=8)           :  309 (23)+ * # Bergeron-Berstel-Brlek-Duboc :  334 ( 5)+ */++#define PENTAROOT_MOD_BLS12_381_r(out, inp, ptype) do { \+ptype t[19]; \+vec_copy(t[1], inp, sizeof(ptype)); /*    0: 1 */\+sqr(t[7], t[1]);                    /*    1: 2 */\+sqr(t[0], t[7]);                    /*    2: 4 */\+sqr(t[2], t[0]);                    /*    3: 8 */\+mul(t[10], t[2], t[1]);             /*    4: 9 */\+mul(t[3], t[10], t[7]);             /*    5: b */\+mul(t[1], t[10], t[0]);             /*    6: d */\+mul(t[5], t[3], t[0]);              /*    7: f */\+mul(t[9], t[10], t[2]);             /*    8: 11 */\+mul(t[4], t[3], t[2]);              /*    9: 13 */\+mul(t[15], t[5], t[2]);             /*   10: 17 */\+mul(t[8], t[15], t[2]);             /*   11: 1f */\+mul(t[13], t[8], t[7]);             /*   12: 21 */\+mul(t[14], t[8], t[0]);             /*   13: 23 */\+mul(t[12], t[13], t[0]);            /*   14: 25 */\+mul(t[6], t[8], t[2]);              /*   15: 27 */\+mul(t[11], t[14], t[2]);            /*   16: 2b */\+sqr(t[0], t[15]);                   /*   17: 2e */\+mul(t[18], t[6], t[2]);             /*   18: 2f */\+mul(t[2], t[11], t[2]);             /*   19: 33 */\+mul(t[16], t[2], t[7]);             /*   20: 35 */\+mul(t[7], t[0], t[3]);              /*   21: 39 */\+mul(t[17], t[0], t[5]);             /*   22: 3d */\+/* sqr(t[0], t[0]); */              /*   23: 5c */\+/* sqr(t[0], t[0]); */              /*   24: b8 */\+/* sqr(t[0], t[0]); */              /*   25: 170 */\+/* sqr(t[0], t[0]); */              /*   26: 2e0 */\+/* sqr(t[0], t[0]); */              /*   27: 5c0 */\+/* sqr(t[0], t[0]); */              /*   28: b80 */\+/* sqr(t[0], t[0]); */              /*   29: 1700 */\+sqr_n_mul(t[0], t[0], 7, t[18]);    /*   30: 172f */\+/* sqr(t[0], t[0]); */              /*   31: 2e5e */\+/* sqr(t[0], t[0]); */              /*   32: 5cbc */\+/* sqr(t[0], t[0]); */              /*   33: b978 */\+/* sqr(t[0], t[0]); */              /*   34: 172f0 */\+/* sqr(t[0], t[0]); */              /*   35: 2e5e0 */\+/* sqr(t[0], t[0]); */              /*   36: 5cbc0 */\+sqr_n_mul(t[0], t[0], 6, t[13]);    /*   37: 5cbe1 */\+/* sqr(t[0], t[0]); */              /*   38: b97c2 */\+/* sqr(t[0], t[0]); */              /*   39: 172f84 */\+/* sqr(t[0], t[0]); */              /*   40: 2e5f08 */\+/* sqr(t[0], t[0]); */              /*   41: 5cbe10 */\+/* sqr(t[0], t[0]); */              /*   42: b97c20 */\+/* sqr(t[0], t[0]); */              /*   43: 172f840 */\+sqr_n_mul(t[0], t[0], 6, t[17]);    /*   44: 172f87d */\+/* sqr(t[0], t[0]); */              /*   45: 2e5f0fa */\+/* sqr(t[0], t[0]); */              /*   46: 5cbe1f4 */\+/* sqr(t[0], t[0]); */              /*   47: b97c3e8 */\+/* sqr(t[0], t[0]); */              /*   48: 172f87d0 */\+/* sqr(t[0], t[0]); */              /*   49: 2e5f0fa0 */\+/* sqr(t[0], t[0]); */              /*   50: 5cbe1f40 */\+sqr_n_mul(t[0], t[0], 6, t[16]);    /*   51: 5cbe1f75 */\+/* sqr(t[0], t[0]); */              /*   52: b97c3eea */\+/* sqr(t[0], t[0]); */              /*   53: 172f87dd4 */\+/* sqr(t[0], t[0]); */              /*   54: 2e5f0fba8 */\+/* sqr(t[0], t[0]); */              /*   55: 5cbe1f750 */\+/* sqr(t[0], t[0]); */              /*   56: b97c3eea0 */\+sqr_n_mul(t[0], t[0], 5, t[15]);    /*   57: b97c3eeb7 */\+/* sqr(t[0], t[0]); */              /*   58: 172f87dd6e */\+/* sqr(t[0], t[0]); */              /*   59: 2e5f0fbadc */\+/* sqr(t[0], t[0]); */              /*   60: 5cbe1f75b8 */\+/* sqr(t[0], t[0]); */              /*   61: b97c3eeb70 */\+/* sqr(t[0], t[0]); */              /*   62: 172f87dd6e0 */\+/* sqr(t[0], t[0]); */              /*   63: 2e5f0fbadc0 */\+sqr_n_mul(t[0], t[0], 6, t[15]);    /*   64: 2e5f0fbadd7 */\+/* sqr(t[0], t[0]); */              /*   65: 5cbe1f75bae */\+/* sqr(t[0], t[0]); */              /*   66: b97c3eeb75c */\+/* sqr(t[0], t[0]); */              /*   67: 172f87dd6eb8 */\+/* sqr(t[0], t[0]); */              /*   68: 2e5f0fbadd70 */\+/* sqr(t[0], t[0]); */              /*   69: 5cbe1f75bae0 */\+/* sqr(t[0], t[0]); */              /*   70: b97c3eeb75c0 */\+/* sqr(t[0], t[0]); */              /*   71: 172f87dd6eb80 */\+/* sqr(t[0], t[0]); */              /*   72: 2e5f0fbadd700 */\+sqr_n_mul(t[0], t[0], 8, t[14]);    /*   73: 2e5f0fbadd723 */\+/* sqr(t[0], t[0]); */              /*   74: 5cbe1f75bae46 */\+/* sqr(t[0], t[0]); */              /*   75: b97c3eeb75c8c */\+/* sqr(t[0], t[0]); */              /*   76: 172f87dd6eb918 */\+/* sqr(t[0], t[0]); */              /*   77: 2e5f0fbadd7230 */\+/* sqr(t[0], t[0]); */              /*   78: 5cbe1f75bae460 */\+/* sqr(t[0], t[0]); */              /*   79: b97c3eeb75c8c0 */\+/* sqr(t[0], t[0]); */              /*   80: 172f87dd6eb9180 */\+/* sqr(t[0], t[0]); */              /*   81: 2e5f0fbadd72300 */\+sqr_n_mul(t[0], t[0], 8, t[13]);    /*   82: 2e5f0fbadd72321 */\+/* sqr(t[0], t[0]); */              /*   83: 5cbe1f75bae4642 */\+/* sqr(t[0], t[0]); */              /*   84: b97c3eeb75c8c84 */\+/* sqr(t[0], t[0]); */              /*   85: 172f87dd6eb91908 */\+/* sqr(t[0], t[0]); */              /*   86: 2e5f0fbadd723210 */\+/* sqr(t[0], t[0]); */              /*   87: 5cbe1f75bae46420 */\+/* sqr(t[0], t[0]); */              /*   88: b97c3eeb75c8c840 */\+sqr_n_mul(t[0], t[0], 6, t[2]);     /*   89: b97c3eeb75c8c873 */\+/* sqr(t[0], t[0]); */              /*   90: 172f87dd6eb9190e6 */\+/* sqr(t[0], t[0]); */              /*   91: 2e5f0fbadd72321cc */\+/* sqr(t[0], t[0]); */              /*   92: 5cbe1f75bae464398 */\+/* sqr(t[0], t[0]); */              /*   93: b97c3eeb75c8c8730 */\+/* sqr(t[0], t[0]); */              /*   94: 172f87dd6eb9190e60 */\+/* sqr(t[0], t[0]); */              /*   95: 2e5f0fbadd72321cc0 */\+sqr_n_mul(t[0], t[0], 6, t[13]);    /*   96: 2e5f0fbadd72321ce1 */\+/* sqr(t[0], t[0]); */              /*   97: 5cbe1f75bae46439c2 */\+/* sqr(t[0], t[0]); */              /*   98: b97c3eeb75c8c87384 */\+/* sqr(t[0], t[0]); */              /*   99: 172f87dd6eb9190e708 */\+/* sqr(t[0], t[0]); */              /*  100: 2e5f0fbadd72321ce10 */\+/* sqr(t[0], t[0]); */              /*  101: 5cbe1f75bae46439c20 */\+/* sqr(t[0], t[0]); */              /*  102: b97c3eeb75c8c873840 */\+/* sqr(t[0], t[0]); */              /*  103: 172f87dd6eb9190e7080 */\+sqr_n_mul(t[0], t[0], 7, t[12]);    /*  104: 172f87dd6eb9190e70a5 */\+/* sqr(t[0], t[0]); */              /*  105: 2e5f0fbadd72321ce14a */\+/* sqr(t[0], t[0]); */              /*  106: 5cbe1f75bae46439c294 */\+/* sqr(t[0], t[0]); */              /*  107: b97c3eeb75c8c8738528 */\+/* sqr(t[0], t[0]); */              /*  108: 172f87dd6eb9190e70a50 */\+/* sqr(t[0], t[0]); */              /*  109: 2e5f0fbadd72321ce14a0 */\+/* sqr(t[0], t[0]); */              /*  110: 5cbe1f75bae46439c2940 */\+/* sqr(t[0], t[0]); */              /*  111: b97c3eeb75c8c87385280 */\+/* sqr(t[0], t[0]); */              /*  112: 172f87dd6eb9190e70a500 */\+sqr_n_mul(t[0], t[0], 8, t[11]);    /*  113: 172f87dd6eb9190e70a52b */\+/* sqr(t[0], t[0]); */              /*  114: 2e5f0fbadd72321ce14a56 */\+/* sqr(t[0], t[0]); */              /*  115: 5cbe1f75bae46439c294ac */\+/* sqr(t[0], t[0]); */              /*  116: b97c3eeb75c8c873852958 */\+/* sqr(t[0], t[0]); */              /*  117: 172f87dd6eb9190e70a52b0 */\+/* sqr(t[0], t[0]); */              /*  118: 2e5f0fbadd72321ce14a560 */\+/* sqr(t[0], t[0]); */              /*  119: 5cbe1f75bae46439c294ac0 */\+sqr_n_mul(t[0], t[0], 6, t[1]);     /*  120: 5cbe1f75bae46439c294acd */\+/* sqr(t[0], t[0]); */              /*  121: b97c3eeb75c8c873852959a */\+/* sqr(t[0], t[0]); */              /*  122: 172f87dd6eb9190e70a52b34 */\+/* sqr(t[0], t[0]); */              /*  123: 2e5f0fbadd72321ce14a5668 */\+/* sqr(t[0], t[0]); */              /*  124: 5cbe1f75bae46439c294acd0 */\+/* sqr(t[0], t[0]); */              /*  125: b97c3eeb75c8c873852959a0 */\+/* sqr(t[0], t[0]); */              /*  126: 172f87dd6eb9190e70a52b340 */\+/* sqr(t[0], t[0]); */              /*  127: 2e5f0fbadd72321ce14a56680 */\+/* sqr(t[0], t[0]); */              /*  128: 5cbe1f75bae46439c294acd00 */\+sqr_n_mul(t[0], t[0], 8, t[2]);     /*  129: 5cbe1f75bae46439c294acd33 */\+/* sqr(t[0], t[0]); */              /*  130: b97c3eeb75c8c873852959a66 */\+/* sqr(t[0], t[0]); */              /*  131: 172f87dd6eb9190e70a52b34cc */\+/* sqr(t[0], t[0]); */              /*  132: 2e5f0fbadd72321ce14a566998 */\+/* sqr(t[0], t[0]); */              /*  133: 5cbe1f75bae46439c294acd330 */\+/* sqr(t[0], t[0]); */              /*  134: b97c3eeb75c8c873852959a660 */\+/* sqr(t[0], t[0]); */              /*  135: 172f87dd6eb9190e70a52b34cc0 */\+sqr_n_mul(t[0], t[0], 6, t[11]);    /*  136: 172f87dd6eb9190e70a52b34ceb */\+/* sqr(t[0], t[0]); */              /*  137: 2e5f0fbadd72321ce14a56699d6 */\+/* sqr(t[0], t[0]); */              /*  138: 5cbe1f75bae46439c294acd33ac */\+/* sqr(t[0], t[0]); */              /*  139: b97c3eeb75c8c873852959a6758 */\+/* sqr(t[0], t[0]); */              /*  140: 172f87dd6eb9190e70a52b34ceb0 */\+sqr_n_mul(t[0], t[0], 4, t[10]);    /*  141: 172f87dd6eb9190e70a52b34ceb9 */\+/* sqr(t[0], t[0]); */              /*  142: 2e5f0fbadd72321ce14a56699d72 */\+/* sqr(t[0], t[0]); */              /*  143: 5cbe1f75bae46439c294acd33ae4 */\+/* sqr(t[0], t[0]); */              /*  144: b97c3eeb75c8c873852959a675c8 */\+/* sqr(t[0], t[0]); */              /*  145: 172f87dd6eb9190e70a52b34ceb90 */\+/* sqr(t[0], t[0]); */              /*  146: 2e5f0fbadd72321ce14a56699d720 */\+sqr_n_mul(t[0], t[0], 5, t[8]);     /*  147: 2e5f0fbadd72321ce14a56699d73f */\+/* sqr(t[0], t[0]); */              /*  148: 5cbe1f75bae46439c294acd33ae7e */\+/* sqr(t[0], t[0]); */              /*  149: b97c3eeb75c8c873852959a675cfc */\+/* sqr(t[0], t[0]); */              /*  150: 172f87dd6eb9190e70a52b34ceb9f8 */\+/* sqr(t[0], t[0]); */              /*  151: 2e5f0fbadd72321ce14a56699d73f0 */\+/* sqr(t[0], t[0]); */              /*  152: 5cbe1f75bae46439c294acd33ae7e0 */\+/* sqr(t[0], t[0]); */              /*  153: b97c3eeb75c8c873852959a675cfc0 */\+/* sqr(t[0], t[0]); */              /*  154: 172f87dd6eb9190e70a52b34ceb9f80 */\+/* sqr(t[0], t[0]); */              /*  155: 2e5f0fbadd72321ce14a56699d73f00 */\+/* sqr(t[0], t[0]); */              /*  156: 5cbe1f75bae46439c294acd33ae7e00 */\+/* sqr(t[0], t[0]); */              /*  157: b97c3eeb75c8c873852959a675cfc00 */\+/* sqr(t[0], t[0]); */              /*  158: 172f87dd6eb9190e70a52b34ceb9f800 */\+/* sqr(t[0], t[0]); */              /*  159: 2e5f0fbadd72321ce14a56699d73f000 */\+/* sqr(t[0], t[0]); */              /*  160: 5cbe1f75bae46439c294acd33ae7e000 */\+/* sqr(t[0], t[0]); */              /*  161: b97c3eeb75c8c873852959a675cfc000 */\+/* sqr(t[0], t[0]); */              /*  162: 172f87dd6eb9190e70a52b34ceb9f8000 */\+sqr_n_mul(t[0], t[0], 15, t[9]);    /*  163: 172f87dd6eb9190e70a52b34ceb9f8011 */\+/* sqr(t[0], t[0]); */              /*  164: 2e5f0fbadd72321ce14a56699d73f0022 */\+/* sqr(t[0], t[0]); */              /*  165: 5cbe1f75bae46439c294acd33ae7e0044 */\+/* sqr(t[0], t[0]); */              /*  166: b97c3eeb75c8c873852959a675cfc0088 */\+/* sqr(t[0], t[0]); */              /*  167: 172f87dd6eb9190e70a52b34ceb9f80110 */\+/* sqr(t[0], t[0]); */              /*  168: 2e5f0fbadd72321ce14a56699d73f00220 */\+/* sqr(t[0], t[0]); */              /*  169: 5cbe1f75bae46439c294acd33ae7e00440 */\+/* sqr(t[0], t[0]); */              /*  170: b97c3eeb75c8c873852959a675cfc00880 */\+/* sqr(t[0], t[0]); */              /*  171: 172f87dd6eb9190e70a52b34ceb9f801100 */\+sqr_n_mul(t[0], t[0], 8, t[3]);     /*  172: 172f87dd6eb9190e70a52b34ceb9f80110b */\+/* sqr(t[0], t[0]); */              /*  173: 2e5f0fbadd72321ce14a56699d73f002216 */\+/* sqr(t[0], t[0]); */              /*  174: 5cbe1f75bae46439c294acd33ae7e00442c */\+/* sqr(t[0], t[0]); */              /*  175: b97c3eeb75c8c873852959a675cfc008858 */\+/* sqr(t[0], t[0]); */              /*  176: 172f87dd6eb9190e70a52b34ceb9f80110b0 */\+/* sqr(t[0], t[0]); */              /*  177: 2e5f0fbadd72321ce14a56699d73f0022160 */\+sqr_n_mul(t[0], t[0], 5, t[8]);     /*  178: 2e5f0fbadd72321ce14a56699d73f002217f */\+/* sqr(t[0], t[0]); */              /*  179: 5cbe1f75bae46439c294acd33ae7e00442fe */\+/* sqr(t[0], t[0]); */              /*  180: b97c3eeb75c8c873852959a675cfc00885fc */\+/* sqr(t[0], t[0]); */              /*  181: 172f87dd6eb9190e70a52b34ceb9f80110bf8 */\+/* sqr(t[0], t[0]); */              /*  182: 2e5f0fbadd72321ce14a56699d73f002217f0 */\+/* sqr(t[0], t[0]); */              /*  183: 5cbe1f75bae46439c294acd33ae7e00442fe0 */\+/* sqr(t[0], t[0]); */              /*  184: b97c3eeb75c8c873852959a675cfc00885fc0 */\+/* sqr(t[0], t[0]); */              /*  185: 172f87dd6eb9190e70a52b34ceb9f80110bf80 */\+/* sqr(t[0], t[0]); */              /*  186: 2e5f0fbadd72321ce14a56699d73f002217f00 */\+/* sqr(t[0], t[0]); */              /*  187: 5cbe1f75bae46439c294acd33ae7e00442fe00 */\+/* sqr(t[0], t[0]); */              /*  188: b97c3eeb75c8c873852959a675cfc00885fc00 */\+sqr_n_mul(t[0], t[0], 10, t[7]);    /*  189: b97c3eeb75c8c873852959a675cfc00885fc39 */\+/* sqr(t[0], t[0]); */              /*  190: 172f87dd6eb9190e70a52b34ceb9f80110bf872 */\+/* sqr(t[0], t[0]); */              /*  191: 2e5f0fbadd72321ce14a56699d73f002217f0e4 */\+/* sqr(t[0], t[0]); */              /*  192: 5cbe1f75bae46439c294acd33ae7e00442fe1c8 */\+/* sqr(t[0], t[0]); */              /*  193: b97c3eeb75c8c873852959a675cfc00885fc390 */\+/* sqr(t[0], t[0]); */              /*  194: 172f87dd6eb9190e70a52b34ceb9f80110bf8720 */\+/* sqr(t[0], t[0]); */              /*  195: 2e5f0fbadd72321ce14a56699d73f002217f0e40 */\+sqr_n_mul(t[0], t[0], 6, t[6]);     /*  196: 2e5f0fbadd72321ce14a56699d73f002217f0e67 */\+/* sqr(t[0], t[0]); */              /*  197: 5cbe1f75bae46439c294acd33ae7e00442fe1cce */\+/* sqr(t[0], t[0]); */              /*  198: b97c3eeb75c8c873852959a675cfc00885fc399c */\+/* sqr(t[0], t[0]); */              /*  199: 172f87dd6eb9190e70a52b34ceb9f80110bf87338 */\+/* sqr(t[0], t[0]); */              /*  200: 2e5f0fbadd72321ce14a56699d73f002217f0e670 */\+/* sqr(t[0], t[0]); */              /*  201: 5cbe1f75bae46439c294acd33ae7e00442fe1cce0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  202: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3 */\+/* sqr(t[0], t[0]); */              /*  203: b97c3eeb75c8c873852959a675cfc00885fc399e6 */\+/* sqr(t[0], t[0]); */              /*  204: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cc */\+/* sqr(t[0], t[0]); */              /*  205: 2e5f0fbadd72321ce14a56699d73f002217f0e6798 */\+/* sqr(t[0], t[0]); */              /*  206: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf30 */\+/* sqr(t[0], t[0]); */              /*  207: b97c3eeb75c8c873852959a675cfc00885fc399e60 */\+/* sqr(t[0], t[0]); */              /*  208: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cc0 */\+/* sqr(t[0], t[0]); */              /*  209: 2e5f0fbadd72321ce14a56699d73f002217f0e67980 */\+/* sqr(t[0], t[0]); */              /*  210: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf300 */\+sqr_n_mul(t[0], t[0], 8, t[2]);     /*  211: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf333 */\+/* sqr(t[0], t[0]); */              /*  212: b97c3eeb75c8c873852959a675cfc00885fc399e666 */\+/* sqr(t[0], t[0]); */              /*  213: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc */\+/* sqr(t[0], t[0]); */              /*  214: 2e5f0fbadd72321ce14a56699d73f002217f0e679998 */\+/* sqr(t[0], t[0]); */              /*  215: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3330 */\+/* sqr(t[0], t[0]); */              /*  216: b97c3eeb75c8c873852959a675cfc00885fc399e6660 */\+/* sqr(t[0], t[0]); */              /*  217: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc0 */\+/* sqr(t[0], t[0]); */              /*  218: 2e5f0fbadd72321ce14a56699d73f002217f0e6799980 */\+sqr_n_mul(t[0], t[0], 7, t[5]);     /*  219: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f */\+/* sqr(t[0], t[0]); */              /*  220: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e */\+/* sqr(t[0], t[0]); */              /*  221: b97c3eeb75c8c873852959a675cfc00885fc399e6663c */\+/* sqr(t[0], t[0]); */              /*  222: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78 */\+/* sqr(t[0], t[0]); */              /*  223: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f0 */\+/* sqr(t[0], t[0]); */              /*  224: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e0 */\+/* sqr(t[0], t[0]); */              /*  225: b97c3eeb75c8c873852959a675cfc00885fc399e6663c0 */\+/* sqr(t[0], t[0]); */              /*  226: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc780 */\+/* sqr(t[0], t[0]); */              /*  227: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f00 */\+/* sqr(t[0], t[0]); */              /*  228: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e00 */\+sqr_n_mul(t[0], t[0], 9, t[2]);     /*  229: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e33 */\+/* sqr(t[0], t[0]); */              /*  230: b97c3eeb75c8c873852959a675cfc00885fc399e6663c66 */\+/* sqr(t[0], t[0]); */              /*  231: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc */\+/* sqr(t[0], t[0]); */              /*  232: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f198 */\+/* sqr(t[0], t[0]); */              /*  233: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e330 */\+/* sqr(t[0], t[0]); */              /*  234: b97c3eeb75c8c873852959a675cfc00885fc399e6663c660 */\+/* sqr(t[0], t[0]); */              /*  235: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc0 */\+/* sqr(t[0], t[0]); */              /*  236: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f1980 */\+sqr_n_mul(t[0], t[0], 7, t[4]);     /*  237: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f1993 */\+/* sqr(t[0], t[0]); */              /*  238: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e3326 */\+/* sqr(t[0], t[0]); */              /*  239: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664c */\+/* sqr(t[0], t[0]); */              /*  240: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc98 */\+/* sqr(t[0], t[0]); */              /*  241: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19930 */\+/* sqr(t[0], t[0]); */              /*  242: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e33260 */\+/* sqr(t[0], t[0]); */              /*  243: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664c0 */\+/* sqr(t[0], t[0]); */              /*  244: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc980 */\+/* sqr(t[0], t[0]); */              /*  245: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f199300 */\+sqr_n_mul(t[0], t[0], 8, t[2]);     /*  246: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f199333 */\+/* sqr(t[0], t[0]); */              /*  247: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e332666 */\+/* sqr(t[0], t[0]); */              /*  248: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664ccc */\+/* sqr(t[0], t[0]); */              /*  249: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc9998 */\+/* sqr(t[0], t[0]); */              /*  250: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f1993330 */\+/* sqr(t[0], t[0]); */              /*  251: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e3326660 */\+/* sqr(t[0], t[0]); */              /*  252: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664ccc0 */\+/* sqr(t[0], t[0]); */              /*  253: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc99980 */\+/* sqr(t[0], t[0]); */              /*  254: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933300 */\+sqr_n_mul(t[0], t[0], 8, t[2]);     /*  255: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333 */\+/* sqr(t[0], t[0]); */              /*  256: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e33266666 */\+/* sqr(t[0], t[0]); */              /*  257: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664ccccc */\+/* sqr(t[0], t[0]); */              /*  258: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc999998 */\+/* sqr(t[0], t[0]); */              /*  259: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f199333330 */\+/* sqr(t[0], t[0]); */              /*  260: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e332666660 */\+/* sqr(t[0], t[0]); */              /*  261: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664ccccc0 */\+/* sqr(t[0], t[0]); */              /*  262: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc9999980 */\+/* sqr(t[0], t[0]); */              /*  263: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f1993333300 */\+sqr_n_mul(t[0], t[0], 8, t[2]);     /*  264: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f1993333333 */\+/* sqr(t[0], t[0]); */              /*  265: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e3326666666 */\+/* sqr(t[0], t[0]); */              /*  266: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664ccccccc */\+/* sqr(t[0], t[0]); */              /*  267: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc99999998 */\+/* sqr(t[0], t[0]); */              /*  268: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333330 */\+/* sqr(t[0], t[0]); */              /*  269: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e33266666660 */\+/* sqr(t[0], t[0]); */              /*  270: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664ccccccc0 */\+sqr_n_mul(t[0], t[0], 6, t[3]);     /*  271: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb */\+/* sqr(t[0], t[0]); */              /*  272: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc999999996 */\+/* sqr(t[0], t[0]); */              /*  273: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333332c */\+/* sqr(t[0], t[0]); */              /*  274: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e332666666658 */\+/* sqr(t[0], t[0]); */              /*  275: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb0 */\+/* sqr(t[0], t[0]); */              /*  276: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc9999999960 */\+/* sqr(t[0], t[0]); */              /*  277: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333332c0 */\+/* sqr(t[0], t[0]); */              /*  278: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e3326666666580 */\+/* sqr(t[0], t[0]); */              /*  279: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb00 */\+sqr_n_mul(t[0], t[0], 8, t[2]);     /*  280: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb33 */\+/* sqr(t[0], t[0]); */              /*  281: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc99999999666 */\+/* sqr(t[0], t[0]); */              /*  282: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333332ccc */\+/* sqr(t[0], t[0]); */              /*  283: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e33266666665998 */\+/* sqr(t[0], t[0]); */              /*  284: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb330 */\+/* sqr(t[0], t[0]); */              /*  285: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc999999996660 */\+/* sqr(t[0], t[0]); */              /*  286: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333332ccc0 */\+/* sqr(t[0], t[0]); */              /*  287: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e332666666659980 */\+/* sqr(t[0], t[0]); */              /*  288: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb3300 */\+sqr_n_mul(t[0], t[0], 8, t[2]);     /*  289: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb3333 */\+/* sqr(t[0], t[0]); */              /*  290: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc9999999966666 */\+/* sqr(t[0], t[0]); */              /*  291: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333332ccccc */\+/* sqr(t[0], t[0]); */              /*  292: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e3326666666599998 */\+/* sqr(t[0], t[0]); */              /*  293: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb33330 */\+/* sqr(t[0], t[0]); */              /*  294: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc99999999666660 */\+/* sqr(t[0], t[0]); */              /*  295: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333332ccccc0 */\+/* sqr(t[0], t[0]); */              /*  296: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e33266666665999980 */\+/* sqr(t[0], t[0]); */              /*  297: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb333300 */\+sqr_n_mul(t[0], t[0], 8, t[2]);     /*  298: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb333333 */\+/* sqr(t[0], t[0]); */              /*  299: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc999999996666666 */\+/* sqr(t[0], t[0]); */              /*  300: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333332ccccccc */\+/* sqr(t[0], t[0]); */              /*  301: 5cbe1f75bae46439c294acd33ae7e00442fe1ccf3331e332666666659999998 */\+/* sqr(t[0], t[0]); */              /*  302: b97c3eeb75c8c873852959a675cfc00885fc399e6663c664cccccccb3333330 */\+/* sqr(t[0], t[0]); */              /*  303: 172f87dd6eb9190e70a52b34ceb9f80110bf8733cccc78cc9999999966666660 */\+/* sqr(t[0], t[0]); */              /*  304: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333332ccccccc0 */\+sqr_n_mul(out, t[0], 6, t[1]);      /*  305: 2e5f0fbadd72321ce14a56699d73f002217f0e679998f19933333332cccccccd */\+} while(0)
+ vendor/external/blst/src/pentaroot.c view
@@ -0,0 +1,76 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "fields.h"++static inline void mul_fr(vec256 ret, const vec256 a, const vec256 b)+{   mul_mont_sparse_256(ret, a, b, BLS12_381_r, r0);   }++static inline void sqr_fr(vec256 ret, const vec256 a)+{   sqr_mont_sparse_256(ret, a, BLS12_381_r, r0);   }++#ifdef __OPTIMIZE_SIZE__+void blst_fr_pentaroot(vec256 out, const vec256 inp)+{+    static const byte pow[] = {+        TO_BYTES(0x33333332cccccccd), TO_BYTES(0x217f0e679998f199),+        TO_BYTES(0xe14a56699d73f002), TO_BYTES(0x2e5f0fbadd72321c)+    };+    size_t pow_bits = 254;+    vec256 ret;++    vec_copy(ret, inp, sizeof(ret));  /* ret = inp^1 */+    --pow_bits; /* most significant bit is set, skip over */+    while (pow_bits--) {+        sqr_fr(ret, ret);+        if (is_bit_set(pow, pow_bits))+            mul_fr(ret, ret, inp);+    }+    vec_copy(out, ret, sizeof(ret));  /* out = ret */+}+#else+# if 0+/*+ * "255"-bit variant omits full reductions at the ends of squarings,+ * not implemented yet[?].+ */+static inline void sqr_n_mul_fr(vec256 out, const vec256 a, size_t count,+                                const vec256 b)+{   sqr_n_mul_mont_255(out, a, count, BLS12_381_r, r0, b);   }+# else+static void sqr_n_mul_fr(vec256 out, const vec256 a, size_t count,+                         const vec256 b)+{+    do {+        sqr_fr(out, a);+        a = out;+    } while (--count);+    mul_fr(out, out, b);+}+# endif++# define sqr(ret,a)		sqr_fr(ret,a)+# define mul(ret,a,b)		mul_fr(ret,a,b)+# define sqr_n_mul(ret,a,n,b)	sqr_n_mul_fr(ret,a,n,b)++# include "pentaroot-addchain.h"+void blst_fr_pentaroot(vec256 out, const vec256 inp)+{   PENTAROOT_MOD_BLS12_381_r(out, inp, vec256);   }+# undef PENTAROOT_MOD_BLS12_381_r++# undef sqr_n_mul+# undef sqr+# undef mul+#endif++void blst_fr_pentapow(vec256 out, const vec256 inp)+{+    vec256 tmp;++    sqr_fr(tmp, inp);+    sqr_fr(tmp, tmp);+    mul_fr(out, tmp, inp);+}
+ vendor/external/blst/src/point.h view
@@ -0,0 +1,62 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLS12_381_ASM_POINT_H__+#define __BLS12_381_ASM_POINT_H__++#include "vect.h"+#include "bytes.h"++#define DECLARE_POINT(ptype, bits) \+typedef struct { vec##bits X,Y,Z; } ptype; \+typedef struct { vec##bits X,Y; } ptype##_affine; \+\+static void ptype##_dadd(ptype *out, const ptype *p1, const ptype *p2,	\+                         const vec##bits a4);				\+static void ptype##_dadd_affine(ptype *out, const ptype *p1,		\+                                            const ptype##_affine *p2);	\+static void ptype##_add(ptype *out, const ptype *p1, const ptype *p2);	\+static void ptype##_add_affine(ptype *out, const ptype *p1,		\+                                           const ptype##_affine *p2);	\+static void ptype##_double(ptype *out, const ptype *p1);		\+static void ptype##_mult_w5(ptype *out, const ptype *point,		\+                            const byte *scalar, size_t nbits);		\+static void ptype##_cneg(ptype *p, limb_t cbit);			\+static void ptype##_to_affine(ptype##_affine *out, const ptype *in);	\+static void ptype##_from_Jacobian(ptype *out, const ptype *in);		\+\+static inline void ptype##_cswap(ptype *restrict a,			\+                                 ptype *restrict b, bool_t cbit) {	\+    vec_cswap(a, b, sizeof(ptype), cbit);				\+} \+static inline void ptype##_ccopy(ptype *restrict a,			\+                                 const ptype *restrict b, bool_t cbit) {\+    vec_select(a, b, a, sizeof(ptype), cbit);				\+}++#define DECLARE_PRIVATE_POINTXZ(ptype, bits) \+typedef struct { vec##bits X,Z; } ptype##xz; \+\+static void ptype##xz_ladder_pre(ptype##xz *out, const ptype *in);	\+static void ptype##xz_ladder_step(ptype##xz *r, ptype##xz *s,		\+                                  const ptype##xz *p);			\+static void ptype##xz_ladder_post(ptype *ret,				\+                                  const ptype##xz *r, const ptype##xz *s, \+                                  const ptype##xz *p, const vec##bits Y1);\+\+static inline void ptype##xz_cswap(ptype##xz *restrict a,		\+                                   ptype##xz *restrict b, bool_t cbit) {\+    vec_cswap(a, b, sizeof(ptype##xz), cbit);				\+}++DECLARE_POINT(POINTonE1, 384)++DECLARE_POINT(POINTonE2, 384x)++#ifdef __GNUC__+# pragma GCC diagnostic ignored "-Wunused-function"+#endif++#endif
+ vendor/external/blst/src/rb_tree.c view
@@ -0,0 +1,145 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include <stddef.h>++/*+ * Red-black tree tailored for uniqueness test. Amount of messages to be+ * checked is known prior context initialization, implementation is+ * insert-only, failure is returned if message is already in the tree.+ */++struct node {+    struct node *leafs[2];+    const void *data;+    size_t len_n_colour;    /* len<<1 | colour */+};++struct rb_tree {+    struct node *root;+    size_t n_nodes;+    struct node nodes[1];+};++static long bytes_compare(const unsigned char *ptr0, size_t len0,+                          const unsigned char *ptr1, size_t len1)+{+    size_t i, len = len0<len1 ? len0 : len1;+    long a, b;++    for (i=0; i<len; i++) {+        if ((a = ptr0[i]) != (b = ptr1[i]))+            return a - b;+    }++    return (long)len0 - (long)len1;+}++#define PAINT_BLACK(p)  ((p)->len_n_colour &= ~(size_t)1)+#define PAINT_RED(p)    ((p)->len_n_colour |= 1)+#define IS_RED(p)       ((p)->len_n_colour & 1)++static int rb_tree_insert(struct rb_tree *tree, const void *data, size_t len)+{+    struct node *nodes[8*sizeof(void *)];   /* visited nodes    */+    unsigned char dirs[8*sizeof(void *)];   /* taken directions */+    size_t k = 0;                           /* walked distance  */+    struct node *p, *y, *z;++    for (p = tree->root; p != NULL; k++) {+        long cmp = bytes_compare(data, len, p->data, p->len_n_colour>>1);++        if (cmp == 0)+            return 0;   /* already in tree, no insertion */++        /* record the step */+        nodes[k] = p;+        p = p->leafs[(dirs[k] = cmp>0)];+    }++    /* allocate new node */+    z = &tree->nodes[tree->n_nodes++];+    z->leafs[0] = z->leafs[1] = NULL;+    z->data = data;+    z->len_n_colour = len<<1;+    PAINT_RED(z);++    /* graft |z| */+    if (k > 0)+        nodes[k-1]->leafs[dirs[k-1]] = z;+    else+        tree->root = z;++    /* re-balance |tree| */+    while (k >= 2 && IS_RED(y = nodes[k-1])) {+        size_t ydir = dirs[k-2];+        struct node *x = nodes[k-2],        /* |z|'s grandparent    */+                    *s = x->leafs[ydir^1];  /* |z|'s uncle          */++        if (s != NULL && IS_RED(s)) {+            PAINT_RED(x);+            PAINT_BLACK(y);+            PAINT_BLACK(s);+            k -= 2;+        } else {+            if (dirs[k-1] != ydir) {+                /*    |        |+                 *    x        x+                 *   / \        \+                 *  y   s -> z   s+                 *   \      /+                 *    z    y+                 *   /      \+                 *  ?        ?+                 */+                struct node *t = y;+                y = y->leafs[ydir^1];+                t->leafs[ydir^1] = y->leafs[ydir];+                y->leafs[ydir] = t;+            }++            /*      |        |+             *      x        y+             *       \      / \+             *    y   s -> z   x+             *   / \          / \+             *  z   ?        ?   s+             */+            x->leafs[ydir] = y->leafs[ydir^1];+            y->leafs[ydir^1] = x;++            PAINT_RED(x);+            PAINT_BLACK(y);++            if (k > 2)+                nodes[k-3]->leafs[dirs[k-3]] = y;+            else+                tree->root = y;++            break;+        }+    }++    PAINT_BLACK(tree->root);++    return 1;+}++#undef IS_RED+#undef PAINT_RED+#undef PAINT_BLACK++size_t blst_uniq_sizeof(size_t n_nodes)+{   return sizeof(struct rb_tree) + sizeof(struct node)*(n_nodes-1);   }++void blst_uniq_init(struct rb_tree *tree)+{+    tree->root = NULL;+    tree->n_nodes = 0;+}++int blst_uniq_test(struct rb_tree *tree, const void *data, size_t len)+{   return (int)rb_tree_insert(tree, data, len);   }
+ vendor/external/blst/src/recip-addchain.h view
@@ -0,0 +1,489 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+/*+ * The "magic" number is BLS12_381_P-2. Exponentiation to which yields+ * reciprocal to input base.+ *+ * Generated with 'addchain 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559785'+ * https://github.com/kwantam/addchain+ *+ * # Bos-Coster (win=4)           :  461 (16) <<<+ * # Bos-Coster (win=3)           :  464 ( 9)+ * # Bos-Coster (win=8)           :  469 (35)+ * # Bos-Coster (win=5)           :  463 (28)+ * # Bos-Coster (win=9)           :  467 (32)+ * # Bos-Coster (win=7)           :  462 (27)+ * # Yacobi                       :  481 (31)+ * # Bos-Coster (win=10)          :  475 (30)+ * # Bos-Coster (win=6)           :  463 (32)+ * # Bos-Coster (win=2)           :  489 ( 5)+ * # Bergeron-Berstel-Brlek-Duboc :  498 ( 5)+ */++#define RECIPROCAL_MOD_BLS12_381_P(out, inp, ptype) do { \+ptype t[16]; \+vec_copy(t[1], inp, sizeof(ptype)); /*    0: 1 */\+sqr(t[0], t[1]);                    /*    1: 2 */\+mul(t[9], t[0], t[1]);              /*    2: 3 */\+sqr(t[5], t[0]);                    /*    3: 4 */\+mul(t[2], t[9], t[0]);              /*    4: 5 */\+mul(t[7], t[5], t[9]);              /*    5: 7 */\+mul(t[10], t[2], t[5]);             /*    6: 9 */\+mul(t[13], t[7], t[5]);             /*    7: b */\+mul(t[4], t[10], t[5]);             /*    8: d */\+mul(t[8], t[13], t[5]);             /*    9: f */\+mul(t[15], t[4], t[5]);             /*   10: 11 */\+mul(t[11], t[8], t[5]);             /*   11: 13 */\+mul(t[3], t[15], t[5]);             /*   12: 15 */\+mul(t[12], t[11], t[5]);            /*   13: 17 */\+sqr(t[0], t[4]);                    /*   14: 1a */\+mul(t[14], t[12], t[5]);            /*   15: 1b */\+mul(t[6], t[0], t[9]);              /*   16: 1d */\+mul(t[5], t[0], t[2]);              /*   17: 1f */\+/* sqr(t[0], t[0]); */              /*   18: 34 */\+/* sqr(t[0], t[0]); */              /*   19: 68 */\+/* sqr(t[0], t[0]); */              /*   20: d0 */\+/* sqr(t[0], t[0]); */              /*   21: 1a0 */\+/* sqr(t[0], t[0]); */              /*   22: 340 */\+/* sqr(t[0], t[0]); */              /*   23: 680 */\+/* sqr(t[0], t[0]); */              /*   24: d00 */\+/* sqr(t[0], t[0]); */              /*   25: 1a00 */\+/* sqr(t[0], t[0]); */              /*   26: 3400 */\+/* sqr(t[0], t[0]); */              /*   27: 6800 */\+/* sqr(t[0], t[0]); */              /*   28: d000 */\+/* sqr(t[0], t[0]); */              /*   29: 1a000 */\+sqr_n_mul(t[0], t[0], 12, t[15]);   /*   30: 1a011 */\+/* sqr(t[0], t[0]); */              /*   31: 34022 */\+/* sqr(t[0], t[0]); */              /*   32: 68044 */\+/* sqr(t[0], t[0]); */              /*   33: d0088 */\+/* sqr(t[0], t[0]); */              /*   34: 1a0110 */\+/* sqr(t[0], t[0]); */              /*   35: 340220 */\+/* sqr(t[0], t[0]); */              /*   36: 680440 */\+/* sqr(t[0], t[0]); */              /*   37: d00880 */\+sqr_n_mul(t[0], t[0], 7, t[8]);     /*   38: d0088f */\+/* sqr(t[0], t[0]); */              /*   39: 1a0111e */\+/* sqr(t[0], t[0]); */              /*   40: 340223c */\+/* sqr(t[0], t[0]); */              /*   41: 6804478 */\+/* sqr(t[0], t[0]); */              /*   42: d0088f0 */\+sqr_n_mul(t[0], t[0], 4, t[2]);     /*   43: d0088f5 */\+/* sqr(t[0], t[0]); */              /*   44: 1a0111ea */\+/* sqr(t[0], t[0]); */              /*   45: 340223d4 */\+/* sqr(t[0], t[0]); */              /*   46: 680447a8 */\+/* sqr(t[0], t[0]); */              /*   47: d0088f50 */\+/* sqr(t[0], t[0]); */              /*   48: 1a0111ea0 */\+/* sqr(t[0], t[0]); */              /*   49: 340223d40 */\+sqr_n_mul(t[0], t[0], 6, t[7]);     /*   50: 340223d47 */\+/* sqr(t[0], t[0]); */              /*   51: 680447a8e */\+/* sqr(t[0], t[0]); */              /*   52: d0088f51c */\+/* sqr(t[0], t[0]); */              /*   53: 1a0111ea38 */\+/* sqr(t[0], t[0]); */              /*   54: 340223d470 */\+/* sqr(t[0], t[0]); */              /*   55: 680447a8e0 */\+/* sqr(t[0], t[0]); */              /*   56: d0088f51c0 */\+/* sqr(t[0], t[0]); */              /*   57: 1a0111ea380 */\+sqr_n_mul(t[0], t[0], 7, t[12]);    /*   58: 1a0111ea397 */\+/* sqr(t[0], t[0]); */              /*   59: 340223d472e */\+/* sqr(t[0], t[0]); */              /*   60: 680447a8e5c */\+/* sqr(t[0], t[0]); */              /*   61: d0088f51cb8 */\+/* sqr(t[0], t[0]); */              /*   62: 1a0111ea3970 */\+/* sqr(t[0], t[0]); */              /*   63: 340223d472e0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*   64: 340223d472ff */\+/* sqr(t[0], t[0]); */              /*   65: 680447a8e5fe */\+/* sqr(t[0], t[0]); */              /*   66: d0088f51cbfc */\+sqr_n_mul(t[0], t[0], 2, t[9]);     /*   67: d0088f51cbff */\+/* sqr(t[0], t[0]); */              /*   68: 1a0111ea397fe */\+/* sqr(t[0], t[0]); */              /*   69: 340223d472ffc */\+/* sqr(t[0], t[0]); */              /*   70: 680447a8e5ff8 */\+/* sqr(t[0], t[0]); */              /*   71: d0088f51cbff0 */\+/* sqr(t[0], t[0]); */              /*   72: 1a0111ea397fe0 */\+/* sqr(t[0], t[0]); */              /*   73: 340223d472ffc0 */\+sqr_n_mul(t[0], t[0], 6, t[4]);     /*   74: 340223d472ffcd */\+/* sqr(t[0], t[0]); */              /*   75: 680447a8e5ff9a */\+/* sqr(t[0], t[0]); */              /*   76: d0088f51cbff34 */\+/* sqr(t[0], t[0]); */              /*   77: 1a0111ea397fe68 */\+/* sqr(t[0], t[0]); */              /*   78: 340223d472ffcd0 */\+/* sqr(t[0], t[0]); */              /*   79: 680447a8e5ff9a0 */\+/* sqr(t[0], t[0]); */              /*   80: d0088f51cbff340 */\+sqr_n_mul(t[0], t[0], 6, t[4]);     /*   81: d0088f51cbff34d */\+/* sqr(t[0], t[0]); */              /*   82: 1a0111ea397fe69a */\+/* sqr(t[0], t[0]); */              /*   83: 340223d472ffcd34 */\+/* sqr(t[0], t[0]); */              /*   84: 680447a8e5ff9a68 */\+/* sqr(t[0], t[0]); */              /*   85: d0088f51cbff34d0 */\+/* sqr(t[0], t[0]); */              /*   86: 1a0111ea397fe69a0 */\+/* sqr(t[0], t[0]); */              /*   87: 340223d472ffcd340 */\+sqr_n_mul(t[0], t[0], 6, t[10]);    /*   88: 340223d472ffcd349 */\+/* sqr(t[0], t[0]); */              /*   89: 680447a8e5ff9a692 */\+/* sqr(t[0], t[0]); */              /*   90: d0088f51cbff34d24 */\+/* sqr(t[0], t[0]); */              /*   91: 1a0111ea397fe69a48 */\+sqr_n_mul(t[0], t[0], 3, t[9]);     /*   92: 1a0111ea397fe69a4b */\+/* sqr(t[0], t[0]); */              /*   93: 340223d472ffcd3496 */\+/* sqr(t[0], t[0]); */              /*   94: 680447a8e5ff9a692c */\+/* sqr(t[0], t[0]); */              /*   95: d0088f51cbff34d258 */\+/* sqr(t[0], t[0]); */              /*   96: 1a0111ea397fe69a4b0 */\+/* sqr(t[0], t[0]); */              /*   97: 340223d472ffcd34960 */\+/* sqr(t[0], t[0]); */              /*   98: 680447a8e5ff9a692c0 */\+/* sqr(t[0], t[0]); */              /*   99: d0088f51cbff34d2580 */\+sqr_n_mul(t[0], t[0], 7, t[4]);     /*  100: d0088f51cbff34d258d */\+/* sqr(t[0], t[0]); */              /*  101: 1a0111ea397fe69a4b1a */\+/* sqr(t[0], t[0]); */              /*  102: 340223d472ffcd349634 */\+/* sqr(t[0], t[0]); */              /*  103: 680447a8e5ff9a692c68 */\+/* sqr(t[0], t[0]); */              /*  104: d0088f51cbff34d258d0 */\+sqr_n_mul(t[0], t[0], 4, t[4]);     /*  105: d0088f51cbff34d258dd */\+/* sqr(t[0], t[0]); */              /*  106: 1a0111ea397fe69a4b1ba */\+/* sqr(t[0], t[0]); */              /*  107: 340223d472ffcd3496374 */\+/* sqr(t[0], t[0]); */              /*  108: 680447a8e5ff9a692c6e8 */\+/* sqr(t[0], t[0]); */              /*  109: d0088f51cbff34d258dd0 */\+/* sqr(t[0], t[0]); */              /*  110: 1a0111ea397fe69a4b1ba0 */\+/* sqr(t[0], t[0]); */              /*  111: 340223d472ffcd34963740 */\+sqr_n_mul(t[0], t[0], 6, t[8]);     /*  112: 340223d472ffcd3496374f */\+/* sqr(t[0], t[0]); */              /*  113: 680447a8e5ff9a692c6e9e */\+/* sqr(t[0], t[0]); */              /*  114: d0088f51cbff34d258dd3c */\+/* sqr(t[0], t[0]); */              /*  115: 1a0111ea397fe69a4b1ba78 */\+/* sqr(t[0], t[0]); */              /*  116: 340223d472ffcd3496374f0 */\+/* sqr(t[0], t[0]); */              /*  117: 680447a8e5ff9a692c6e9e0 */\+/* sqr(t[0], t[0]); */              /*  118: d0088f51cbff34d258dd3c0 */\+sqr_n_mul(t[0], t[0], 6, t[14]);    /*  119: d0088f51cbff34d258dd3db */\+/* sqr(t[0], t[0]); */              /*  120: 1a0111ea397fe69a4b1ba7b6 */\+/* sqr(t[0], t[0]); */              /*  121: 340223d472ffcd3496374f6c */\+/* sqr(t[0], t[0]); */              /*  122: 680447a8e5ff9a692c6e9ed8 */\+sqr_n_mul(t[0], t[0], 3, t[1]);     /*  123: 680447a8e5ff9a692c6e9ed9 */\+/* sqr(t[0], t[0]); */              /*  124: d0088f51cbff34d258dd3db2 */\+/* sqr(t[0], t[0]); */              /*  125: 1a0111ea397fe69a4b1ba7b64 */\+/* sqr(t[0], t[0]); */              /*  126: 340223d472ffcd3496374f6c8 */\+/* sqr(t[0], t[0]); */              /*  127: 680447a8e5ff9a692c6e9ed90 */\+/* sqr(t[0], t[0]); */              /*  128: d0088f51cbff34d258dd3db20 */\+/* sqr(t[0], t[0]); */              /*  129: 1a0111ea397fe69a4b1ba7b640 */\+/* sqr(t[0], t[0]); */              /*  130: 340223d472ffcd3496374f6c80 */\+/* sqr(t[0], t[0]); */              /*  131: 680447a8e5ff9a692c6e9ed900 */\+sqr_n_mul(t[0], t[0], 8, t[4]);     /*  132: 680447a8e5ff9a692c6e9ed90d */\+/* sqr(t[0], t[0]); */              /*  133: d0088f51cbff34d258dd3db21a */\+/* sqr(t[0], t[0]); */              /*  134: 1a0111ea397fe69a4b1ba7b6434 */\+/* sqr(t[0], t[0]); */              /*  135: 340223d472ffcd3496374f6c868 */\+/* sqr(t[0], t[0]); */              /*  136: 680447a8e5ff9a692c6e9ed90d0 */\+/* sqr(t[0], t[0]); */              /*  137: d0088f51cbff34d258dd3db21a0 */\+/* sqr(t[0], t[0]); */              /*  138: 1a0111ea397fe69a4b1ba7b64340 */\+/* sqr(t[0], t[0]); */              /*  139: 340223d472ffcd3496374f6c8680 */\+sqr_n_mul(t[0], t[0], 7, t[12]);    /*  140: 340223d472ffcd3496374f6c8697 */\+/* sqr(t[0], t[0]); */              /*  141: 680447a8e5ff9a692c6e9ed90d2e */\+/* sqr(t[0], t[0]); */              /*  142: d0088f51cbff34d258dd3db21a5c */\+/* sqr(t[0], t[0]); */              /*  143: 1a0111ea397fe69a4b1ba7b6434b8 */\+/* sqr(t[0], t[0]); */              /*  144: 340223d472ffcd3496374f6c86970 */\+/* sqr(t[0], t[0]); */              /*  145: 680447a8e5ff9a692c6e9ed90d2e0 */\+sqr_n_mul(t[0], t[0], 5, t[13]);    /*  146: 680447a8e5ff9a692c6e9ed90d2eb */\+/* sqr(t[0], t[0]); */              /*  147: d0088f51cbff34d258dd3db21a5d6 */\+/* sqr(t[0], t[0]); */              /*  148: 1a0111ea397fe69a4b1ba7b6434bac */\+/* sqr(t[0], t[0]); */              /*  149: 340223d472ffcd3496374f6c869758 */\+/* sqr(t[0], t[0]); */              /*  150: 680447a8e5ff9a692c6e9ed90d2eb0 */\+/* sqr(t[0], t[0]); */              /*  151: d0088f51cbff34d258dd3db21a5d60 */\+/* sqr(t[0], t[0]); */              /*  152: 1a0111ea397fe69a4b1ba7b6434bac0 */\+sqr_n_mul(t[0], t[0], 6, t[4]);     /*  153: 1a0111ea397fe69a4b1ba7b6434bacd */\+/* sqr(t[0], t[0]); */              /*  154: 340223d472ffcd3496374f6c869759a */\+/* sqr(t[0], t[0]); */              /*  155: 680447a8e5ff9a692c6e9ed90d2eb34 */\+/* sqr(t[0], t[0]); */              /*  156: d0088f51cbff34d258dd3db21a5d668 */\+/* sqr(t[0], t[0]); */              /*  157: 1a0111ea397fe69a4b1ba7b6434bacd0 */\+/* sqr(t[0], t[0]); */              /*  158: 340223d472ffcd3496374f6c869759a0 */\+/* sqr(t[0], t[0]); */              /*  159: 680447a8e5ff9a692c6e9ed90d2eb340 */\+sqr_n_mul(t[0], t[0], 6, t[6]);     /*  160: 680447a8e5ff9a692c6e9ed90d2eb35d */\+/* sqr(t[0], t[0]); */              /*  161: d0088f51cbff34d258dd3db21a5d66ba */\+/* sqr(t[0], t[0]); */              /*  162: 1a0111ea397fe69a4b1ba7b6434bacd74 */\+/* sqr(t[0], t[0]); */              /*  163: 340223d472ffcd3496374f6c869759ae8 */\+/* sqr(t[0], t[0]); */              /*  164: 680447a8e5ff9a692c6e9ed90d2eb35d0 */\+sqr_n_mul(t[0], t[0], 4, t[10]);    /*  165: 680447a8e5ff9a692c6e9ed90d2eb35d9 */\+/* sqr(t[0], t[0]); */              /*  166: d0088f51cbff34d258dd3db21a5d66bb2 */\+/* sqr(t[0], t[0]); */              /*  167: 1a0111ea397fe69a4b1ba7b6434bacd764 */\+/* sqr(t[0], t[0]); */              /*  168: 340223d472ffcd3496374f6c869759aec8 */\+/* sqr(t[0], t[0]); */              /*  169: 680447a8e5ff9a692c6e9ed90d2eb35d90 */\+/* sqr(t[0], t[0]); */              /*  170: d0088f51cbff34d258dd3db21a5d66bb20 */\+/* sqr(t[0], t[0]); */              /*  171: 1a0111ea397fe69a4b1ba7b6434bacd7640 */\+/* sqr(t[0], t[0]); */              /*  172: 340223d472ffcd3496374f6c869759aec80 */\+/* sqr(t[0], t[0]); */              /*  173: 680447a8e5ff9a692c6e9ed90d2eb35d900 */\+sqr_n_mul(t[0], t[0], 8, t[6]);     /*  174: 680447a8e5ff9a692c6e9ed90d2eb35d91d */\+/* sqr(t[0], t[0]); */              /*  175: d0088f51cbff34d258dd3db21a5d66bb23a */\+/* sqr(t[0], t[0]); */              /*  176: 1a0111ea397fe69a4b1ba7b6434bacd76474 */\+/* sqr(t[0], t[0]); */              /*  177: 340223d472ffcd3496374f6c869759aec8e8 */\+/* sqr(t[0], t[0]); */              /*  178: 680447a8e5ff9a692c6e9ed90d2eb35d91d0 */\+sqr_n_mul(t[0], t[0], 4, t[4]);     /*  179: 680447a8e5ff9a692c6e9ed90d2eb35d91dd */\+/* sqr(t[0], t[0]); */              /*  180: d0088f51cbff34d258dd3db21a5d66bb23ba */\+/* sqr(t[0], t[0]); */              /*  181: 1a0111ea397fe69a4b1ba7b6434bacd764774 */\+/* sqr(t[0], t[0]); */              /*  182: 340223d472ffcd3496374f6c869759aec8ee8 */\+/* sqr(t[0], t[0]); */              /*  183: 680447a8e5ff9a692c6e9ed90d2eb35d91dd0 */\+/* sqr(t[0], t[0]); */              /*  184: d0088f51cbff34d258dd3db21a5d66bb23ba0 */\+/* sqr(t[0], t[0]); */              /*  185: 1a0111ea397fe69a4b1ba7b6434bacd7647740 */\+/* sqr(t[0], t[0]); */              /*  186: 340223d472ffcd3496374f6c869759aec8ee80 */\+sqr_n_mul(t[0], t[0], 7, t[12]);    /*  187: 340223d472ffcd3496374f6c869759aec8ee97 */\+/* sqr(t[0], t[0]); */              /*  188: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e */\+/* sqr(t[0], t[0]); */              /*  189: d0088f51cbff34d258dd3db21a5d66bb23ba5c */\+/* sqr(t[0], t[0]); */              /*  190: 1a0111ea397fe69a4b1ba7b6434bacd764774b8 */\+/* sqr(t[0], t[0]); */              /*  191: 340223d472ffcd3496374f6c869759aec8ee970 */\+/* sqr(t[0], t[0]); */              /*  192: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e0 */\+/* sqr(t[0], t[0]); */              /*  193: d0088f51cbff34d258dd3db21a5d66bb23ba5c0 */\+/* sqr(t[0], t[0]); */              /*  194: 1a0111ea397fe69a4b1ba7b6434bacd764774b80 */\+/* sqr(t[0], t[0]); */              /*  195: 340223d472ffcd3496374f6c869759aec8ee9700 */\+/* sqr(t[0], t[0]); */              /*  196: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e00 */\+sqr_n_mul(t[0], t[0], 9, t[11]);    /*  197: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13 */\+/* sqr(t[0], t[0]); */              /*  198: d0088f51cbff34d258dd3db21a5d66bb23ba5c26 */\+/* sqr(t[0], t[0]); */              /*  199: 1a0111ea397fe69a4b1ba7b6434bacd764774b84c */\+sqr_n_mul(t[0], t[0], 2, t[9]);     /*  200: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f */\+/* sqr(t[0], t[0]); */              /*  201: 340223d472ffcd3496374f6c869759aec8ee9709e */\+/* sqr(t[0], t[0]); */              /*  202: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13c */\+/* sqr(t[0], t[0]); */              /*  203: d0088f51cbff34d258dd3db21a5d66bb23ba5c278 */\+/* sqr(t[0], t[0]); */              /*  204: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f0 */\+/* sqr(t[0], t[0]); */              /*  205: 340223d472ffcd3496374f6c869759aec8ee9709e0 */\+sqr_n_mul(t[0], t[0], 5, t[7]);     /*  206: 340223d472ffcd3496374f6c869759aec8ee9709e7 */\+/* sqr(t[0], t[0]); */              /*  207: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce */\+/* sqr(t[0], t[0]); */              /*  208: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c */\+/* sqr(t[0], t[0]); */              /*  209: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38 */\+/* sqr(t[0], t[0]); */              /*  210: 340223d472ffcd3496374f6c869759aec8ee9709e70 */\+/* sqr(t[0], t[0]); */              /*  211: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce0 */\+/* sqr(t[0], t[0]); */              /*  212: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c0 */\+/* sqr(t[0], t[0]); */              /*  213: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f380 */\+sqr_n_mul(t[0], t[0], 7, t[2]);     /*  214: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f385 */\+/* sqr(t[0], t[0]); */              /*  215: 340223d472ffcd3496374f6c869759aec8ee9709e70a */\+/* sqr(t[0], t[0]); */              /*  216: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce14 */\+/* sqr(t[0], t[0]); */              /*  217: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c28 */\+/* sqr(t[0], t[0]); */              /*  218: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f3850 */\+/* sqr(t[0], t[0]); */              /*  219: 340223d472ffcd3496374f6c869759aec8ee9709e70a0 */\+/* sqr(t[0], t[0]); */              /*  220: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce140 */\+/* sqr(t[0], t[0]); */              /*  221: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c280 */\+sqr_n_mul(t[0], t[0], 7, t[10]);    /*  222: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c289 */\+/* sqr(t[0], t[0]); */              /*  223: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512 */\+/* sqr(t[0], t[0]); */              /*  224: 340223d472ffcd3496374f6c869759aec8ee9709e70a24 */\+/* sqr(t[0], t[0]); */              /*  225: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce1448 */\+/* sqr(t[0], t[0]); */              /*  226: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2890 */\+/* sqr(t[0], t[0]); */              /*  227: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f385120 */\+/* sqr(t[0], t[0]); */              /*  228: 340223d472ffcd3496374f6c869759aec8ee9709e70a240 */\+sqr_n_mul(t[0], t[0], 6, t[12]);    /*  229: 340223d472ffcd3496374f6c869759aec8ee9709e70a257 */\+/* sqr(t[0], t[0]); */              /*  230: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144ae */\+/* sqr(t[0], t[0]); */              /*  231: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895c */\+/* sqr(t[0], t[0]); */              /*  232: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512b8 */\+/* sqr(t[0], t[0]); */              /*  233: 340223d472ffcd3496374f6c869759aec8ee9709e70a2570 */\+/* sqr(t[0], t[0]); */              /*  234: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144ae0 */\+sqr_n_mul(t[0], t[0], 5, t[6]);     /*  235: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd */\+/* sqr(t[0], t[0]); */              /*  236: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fa */\+/* sqr(t[0], t[0]); */              /*  237: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf4 */\+/* sqr(t[0], t[0]); */              /*  238: 340223d472ffcd3496374f6c869759aec8ee9709e70a257e8 */\+/* sqr(t[0], t[0]); */              /*  239: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd0 */\+/* sqr(t[0], t[0]); */              /*  240: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fa0 */\+sqr_n_mul(t[0], t[0], 5, t[11]);    /*  241: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb3 */\+/* sqr(t[0], t[0]); */              /*  242: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf66 */\+/* sqr(t[0], t[0]); */              /*  243: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ecc */\+/* sqr(t[0], t[0]); */              /*  244: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd98 */\+/* sqr(t[0], t[0]); */              /*  245: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb30 */\+/* sqr(t[0], t[0]); */              /*  246: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf660 */\+sqr_n_mul(t[0], t[0], 5, t[11]);    /*  247: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf673 */\+/* sqr(t[0], t[0]); */              /*  248: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece6 */\+/* sqr(t[0], t[0]); */              /*  249: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc */\+/* sqr(t[0], t[0]); */              /*  250: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb398 */\+/* sqr(t[0], t[0]); */              /*  251: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730 */\+/* sqr(t[0], t[0]); */              /*  252: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece60 */\+/* sqr(t[0], t[0]); */              /*  253: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc0 */\+/* sqr(t[0], t[0]); */              /*  254: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb3980 */\+/* sqr(t[0], t[0]); */              /*  255: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf67300 */\+sqr_n_mul(t[0], t[0], 8, t[4]);     /*  256: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d */\+/* sqr(t[0], t[0]); */              /*  257: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a */\+/* sqr(t[0], t[0]); */              /*  258: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34 */\+/* sqr(t[0], t[0]); */              /*  259: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39868 */\+/* sqr(t[0], t[0]); */              /*  260: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d0 */\+/* sqr(t[0], t[0]); */              /*  261: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a0 */\+/* sqr(t[0], t[0]); */              /*  262: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc340 */\+/* sqr(t[0], t[0]); */              /*  263: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb398680 */\+sqr_n_mul(t[0], t[0], 7, t[3]);     /*  264: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb398695 */\+/* sqr(t[0], t[0]); */              /*  265: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a */\+/* sqr(t[0], t[0]); */              /*  266: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a54 */\+/* sqr(t[0], t[0]); */              /*  267: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a8 */\+/* sqr(t[0], t[0]); */              /*  268: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb3986950 */\+/* sqr(t[0], t[0]); */              /*  269: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0 */\+/* sqr(t[0], t[0]); */              /*  270: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a540 */\+/* sqr(t[0], t[0]); */              /*  271: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a80 */\+/* sqr(t[0], t[0]); */              /*  272: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869500 */\+/* sqr(t[0], t[0]); */              /*  273: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a00 */\+sqr_n_mul(t[0], t[0], 9, t[8]);     /*  274: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f */\+/* sqr(t[0], t[0]); */              /*  275: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541e */\+/* sqr(t[0], t[0]); */              /*  276: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83c */\+/* sqr(t[0], t[0]); */              /*  277: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb398695078 */\+/* sqr(t[0], t[0]); */              /*  278: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f0 */\+/* sqr(t[0], t[0]); */              /*  279: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541e0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  280: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed */\+/* sqr(t[0], t[0]); */              /*  281: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83da */\+/* sqr(t[0], t[0]); */              /*  282: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b4 */\+/* sqr(t[0], t[0]); */              /*  283: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f68 */\+sqr_n_mul(t[0], t[0], 3, t[9]);     /*  284: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b */\+/* sqr(t[0], t[0]); */              /*  285: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed6 */\+/* sqr(t[0], t[0]); */              /*  286: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac */\+/* sqr(t[0], t[0]); */              /*  287: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b58 */\+/* sqr(t[0], t[0]); */              /*  288: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0 */\+/* sqr(t[0], t[0]); */              /*  289: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed60 */\+/* sqr(t[0], t[0]); */              /*  290: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac0 */\+/* sqr(t[0], t[0]); */              /*  291: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b580 */\+/* sqr(t[0], t[0]); */              /*  292: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b00 */\+sqr_n_mul(t[0], t[0], 8, t[8]);     /*  293: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f */\+/* sqr(t[0], t[0]); */              /*  294: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61e */\+/* sqr(t[0], t[0]); */              /*  295: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3c */\+/* sqr(t[0], t[0]); */              /*  296: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b5878 */\+sqr_n_mul(t[0], t[0], 3, t[9]);     /*  297: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b */\+/* sqr(t[0], t[0]); */              /*  298: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6 */\+/* sqr(t[0], t[0]); */              /*  299: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec */\+/* sqr(t[0], t[0]); */              /*  300: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8 */\+/* sqr(t[0], t[0]); */              /*  301: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b0 */\+/* sqr(t[0], t[0]); */              /*  302: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f60 */\+/* sqr(t[0], t[0]); */              /*  303: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec0 */\+/* sqr(t[0], t[0]); */              /*  304: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d80 */\+sqr_n_mul(t[0], t[0], 7, t[10]);    /*  305: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d89 */\+/* sqr(t[0], t[0]); */              /*  306: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b12 */\+/* sqr(t[0], t[0]); */              /*  307: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f624 */\+/* sqr(t[0], t[0]); */              /*  308: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec48 */\+/* sqr(t[0], t[0]); */              /*  309: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d890 */\+/* sqr(t[0], t[0]); */              /*  310: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120 */\+/* sqr(t[0], t[0]); */              /*  311: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6240 */\+/* sqr(t[0], t[0]); */              /*  312: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec480 */\+/* sqr(t[0], t[0]); */              /*  313: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8900 */\+/* sqr(t[0], t[0]); */              /*  314: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b1200 */\+sqr_n_mul(t[0], t[0], 9, t[8]);     /*  315: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f */\+/* sqr(t[0], t[0]); */              /*  316: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241e */\+/* sqr(t[0], t[0]); */              /*  317: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483c */\+/* sqr(t[0], t[0]); */              /*  318: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d89078 */\+/* sqr(t[0], t[0]); */              /*  319: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f0 */\+/* sqr(t[0], t[0]); */              /*  320: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241e0 */\+/* sqr(t[0], t[0]); */              /*  321: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483c0 */\+sqr_n_mul(t[0], t[0], 6, t[3]);     /*  322: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d5 */\+/* sqr(t[0], t[0]); */              /*  323: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aa */\+/* sqr(t[0], t[0]); */              /*  324: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f54 */\+/* sqr(t[0], t[0]); */              /*  325: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241ea8 */\+/* sqr(t[0], t[0]); */              /*  326: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d50 */\+/* sqr(t[0], t[0]); */              /*  327: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aa0 */\+/* sqr(t[0], t[0]); */              /*  328: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f540 */\+sqr_n_mul(t[0], t[0], 6, t[5]);     /*  329: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55f */\+/* sqr(t[0], t[0]); */              /*  330: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabe */\+/* sqr(t[0], t[0]); */              /*  331: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57c */\+/* sqr(t[0], t[0]); */              /*  332: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaf8 */\+/* sqr(t[0], t[0]); */              /*  333: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55f0 */\+/* sqr(t[0], t[0]); */              /*  334: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabe0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  335: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabff */\+/* sqr(t[0], t[0]); */              /*  336: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fe */\+/* sqr(t[0], t[0]); */              /*  337: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffc */\+/* sqr(t[0], t[0]); */              /*  338: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ff8 */\+/* sqr(t[0], t[0]); */              /*  339: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabff0 */\+/* sqr(t[0], t[0]); */              /*  340: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fe0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  341: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fff */\+/* sqr(t[0], t[0]); */              /*  342: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aafffe */\+/* sqr(t[0], t[0]); */              /*  343: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55fffc */\+/* sqr(t[0], t[0]); */              /*  344: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfff8 */\+/* sqr(t[0], t[0]); */              /*  345: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fff0 */\+sqr_n_mul(t[0], t[0], 4, t[4]);     /*  346: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd */\+/* sqr(t[0], t[0]); */              /*  347: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffa */\+/* sqr(t[0], t[0]); */              /*  348: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff4 */\+/* sqr(t[0], t[0]); */              /*  349: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffe8 */\+sqr_n_mul(t[0], t[0], 3, t[9]);     /*  350: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb */\+/* sqr(t[0], t[0]); */              /*  351: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd6 */\+/* sqr(t[0], t[0]); */              /*  352: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac */\+/* sqr(t[0], t[0]); */              /*  353: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58 */\+/* sqr(t[0], t[0]); */              /*  354: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb0 */\+/* sqr(t[0], t[0]); */              /*  355: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd60 */\+/* sqr(t[0], t[0]); */              /*  356: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac0 */\+/* sqr(t[0], t[0]); */              /*  357: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff580 */\+/* sqr(t[0], t[0]); */              /*  358: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb00 */\+sqr_n_mul(t[0], t[0], 8, t[3]);     /*  359: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb15 */\+/* sqr(t[0], t[0]); */              /*  360: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a */\+/* sqr(t[0], t[0]); */              /*  361: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54 */\+/* sqr(t[0], t[0]); */              /*  362: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a8 */\+/* sqr(t[0], t[0]); */              /*  363: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb150 */\+/* sqr(t[0], t[0]); */              /*  364: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a0 */\+/* sqr(t[0], t[0]); */              /*  365: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac540 */\+/* sqr(t[0], t[0]); */              /*  366: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a80 */\+sqr_n_mul(t[0], t[0], 7, t[5]);     /*  367: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9f */\+/* sqr(t[0], t[0]); */              /*  368: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153e */\+/* sqr(t[0], t[0]); */              /*  369: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7c */\+/* sqr(t[0], t[0]); */              /*  370: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54f8 */\+/* sqr(t[0], t[0]); */              /*  371: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9f0 */\+/* sqr(t[0], t[0]); */              /*  372: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153e0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  373: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ff */\+/* sqr(t[0], t[0]); */              /*  374: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7fe */\+/* sqr(t[0], t[0]); */              /*  375: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffc */\+/* sqr(t[0], t[0]); */              /*  376: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ff8 */\+/* sqr(t[0], t[0]); */              /*  377: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ff0 */\+/* sqr(t[0], t[0]); */              /*  378: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7fe0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  379: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7fff */\+/* sqr(t[0], t[0]); */              /*  380: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54fffe */\+/* sqr(t[0], t[0]); */              /*  381: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9fffc */\+/* sqr(t[0], t[0]); */              /*  382: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153fff8 */\+/* sqr(t[0], t[0]); */              /*  383: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7fff0 */\+sqr_n_mul(t[0], t[0], 4, t[8]);     /*  384: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff */\+/* sqr(t[0], t[0]); */              /*  385: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffe */\+/* sqr(t[0], t[0]); */              /*  386: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffc */\+/* sqr(t[0], t[0]); */              /*  387: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffff8 */\+/* sqr(t[0], t[0]); */              /*  388: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff0 */\+sqr_n_mul(t[0], t[0], 4, t[7]);     /*  389: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff7 */\+/* sqr(t[0], t[0]); */              /*  390: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee */\+/* sqr(t[0], t[0]); */              /*  391: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdc */\+/* sqr(t[0], t[0]); */              /*  392: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb8 */\+/* sqr(t[0], t[0]); */              /*  393: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff70 */\+/* sqr(t[0], t[0]); */              /*  394: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee0 */\+/* sqr(t[0], t[0]); */              /*  395: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdc0 */\+/* sqr(t[0], t[0]); */              /*  396: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb80 */\+sqr_n_mul(t[0], t[0], 7, t[5]);     /*  397: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9f */\+/* sqr(t[0], t[0]); */              /*  398: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73e */\+/* sqr(t[0], t[0]); */              /*  399: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7c */\+/* sqr(t[0], t[0]); */              /*  400: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcf8 */\+/* sqr(t[0], t[0]); */              /*  401: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9f0 */\+/* sqr(t[0], t[0]); */              /*  402: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73e0 */\+sqr_n_mul(t[0], t[0], 5, t[6]);     /*  403: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fd */\+/* sqr(t[0], t[0]); */              /*  404: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fa */\+/* sqr(t[0], t[0]); */              /*  405: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff4 */\+/* sqr(t[0], t[0]); */              /*  406: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9fe8 */\+/* sqr(t[0], t[0]); */              /*  407: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fd0 */\+/* sqr(t[0], t[0]); */              /*  408: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fa0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  409: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbf */\+/* sqr(t[0], t[0]); */              /*  410: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7e */\+/* sqr(t[0], t[0]); */              /*  411: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9fefc */\+/* sqr(t[0], t[0]); */              /*  412: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdf8 */\+/* sqr(t[0], t[0]); */              /*  413: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbf0 */\+/* sqr(t[0], t[0]); */              /*  414: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7e0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  415: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7ff */\+/* sqr(t[0], t[0]); */              /*  416: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffe */\+/* sqr(t[0], t[0]); */              /*  417: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffc */\+/* sqr(t[0], t[0]); */              /*  418: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbff8 */\+/* sqr(t[0], t[0]); */              /*  419: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7ff0 */\+/* sqr(t[0], t[0]); */              /*  420: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffe0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  421: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffff */\+/* sqr(t[0], t[0]); */              /*  422: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffe */\+/* sqr(t[0], t[0]); */              /*  423: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffc */\+/* sqr(t[0], t[0]); */              /*  424: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fff8 */\+/* sqr(t[0], t[0]); */              /*  425: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffff0 */\+/* sqr(t[0], t[0]); */              /*  426: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffe0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  427: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffff */\+/* sqr(t[0], t[0]); */              /*  428: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbffffe */\+/* sqr(t[0], t[0]); */              /*  429: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7ffffc */\+/* sqr(t[0], t[0]); */              /*  430: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9fefffff8 */\+/* sqr(t[0], t[0]); */              /*  431: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffff0 */\+/* sqr(t[0], t[0]); */              /*  432: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbffffe0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  433: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbffffff */\+/* sqr(t[0], t[0]); */              /*  434: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffe */\+/* sqr(t[0], t[0]); */              /*  435: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffc */\+/* sqr(t[0], t[0]); */              /*  436: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffff8 */\+/* sqr(t[0], t[0]); */              /*  437: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbffffff0 */\+/* sqr(t[0], t[0]); */              /*  438: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffe0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  439: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffff */\+/* sqr(t[0], t[0]); */              /*  440: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9fefffffffe */\+/* sqr(t[0], t[0]); */              /*  441: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffffffc */\+/* sqr(t[0], t[0]); */              /*  442: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffffff8 */\+/* sqr(t[0], t[0]); */              /*  443: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffff0 */\+sqr_n_mul(t[0], t[0], 4, t[4]);     /*  444: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffffd */\+/* sqr(t[0], t[0]); */              /*  445: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa */\+/* sqr(t[0], t[0]); */              /*  446: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff4 */\+/* sqr(t[0], t[0]); */              /*  447: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffffffe8 */\+/* sqr(t[0], t[0]); */              /*  448: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffffd0 */\+/* sqr(t[0], t[0]); */              /*  449: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa0 */\+/* sqr(t[0], t[0]); */              /*  450: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff40 */\+sqr_n_mul(t[0], t[0], 6, t[3]);     /*  451: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff55 */\+/* sqr(t[0], t[0]); */              /*  452: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffffffeaa */\+/* sqr(t[0], t[0]); */              /*  453: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffffd54 */\+/* sqr(t[0], t[0]); */              /*  454: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa8 */\+/* sqr(t[0], t[0]); */              /*  455: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff550 */\+sqr_n_mul(t[0], t[0], 4, t[2]);     /*  456: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff555 */\+/* sqr(t[0], t[0]); */              /*  457: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffffffeaaa */\+/* sqr(t[0], t[0]); */              /*  458: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffffd554 */\+/* sqr(t[0], t[0]); */              /*  459: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaa8 */\+sqr_n_mul(out, t[0], 3, t[1]);      /*  460: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaa9 */\+} while(0)
+ vendor/external/blst/src/recip.c view
@@ -0,0 +1,139 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "fields.h"++#ifdef __OPTIMIZE_SIZE__+/*+ * 608 multiplications for scalar inversion modulo BLS12-381 prime, 32%+ * more than corresponding optimal addition-chain, plus mispredicted+ * branch penalties on top of that... The addition chain below was+ * measured to be >50% faster.+ */+static void flt_reciprocal_fp(vec384 out, const vec384 inp)+{+    static const byte BLS12_381_P_minus_2[] = {+        TO_BYTES(0xb9feffffffffaaa9), TO_BYTES(0x1eabfffeb153ffff),+        TO_BYTES(0x6730d2a0f6b0f624), TO_BYTES(0x64774b84f38512bf),+        TO_BYTES(0x4b1ba7b6434bacd7), TO_BYTES(0x1a0111ea397fe69a)+    };++    exp_mont_384(out, inp, BLS12_381_P_minus_2, 381, BLS12_381_P, p0);+}+#else+# define sqr(ret,a)		sqr_fp(ret,a)+# define mul(ret,a,b)		mul_fp(ret,a,b)+# define sqr_n_mul(ret,a,n,b)	sqr_n_mul_fp(ret,a,n,b)++# include "recip-addchain.h"+static void flt_reciprocal_fp(vec384 out, const vec384 inp)+{+    RECIPROCAL_MOD_BLS12_381_P(out, inp, vec384);+}+# undef RECIPROCAL_MOD_BLS12_381_P+# undef sqr_n_mul+# undef mul+# undef sqr+#endif++static void flt_reciprocal_fp2(vec384x out, const vec384x inp)+{+    vec384 t0, t1;++    /*+     * |out| = 1/(a + b*i) = a/(a^2+b^2) - b/(a^2+b^2)*i+     */+    sqr_fp(t0, inp[0]);+    sqr_fp(t1, inp[1]);+    add_fp(t0, t0, t1);+    flt_reciprocal_fp(t1, t0);+    mul_fp(out[0], inp[0], t1);+    mul_fp(out[1], inp[1], t1);+    neg_fp(out[1], out[1]);+}++static void reciprocal_fp(vec384 out, const vec384 inp)+{+    static const vec384 Px8 = {    /* left-aligned value of the modulus */+        TO_LIMB_T(0xcff7fffffffd5558), TO_LIMB_T(0xf55ffff58a9ffffd),+        TO_LIMB_T(0x39869507b587b120), TO_LIMB_T(0x23ba5c279c2895fb),+        TO_LIMB_T(0x58dd3db21a5d66bb), TO_LIMB_T(0xd0088f51cbff34d2)+    };+#ifdef __BLST_NO_ASM__+# define RRx4 BLS12_381_RR+#else+    static const vec384 RRx4 = {   /* (4<<768)%P */+        TO_LIMB_T(0x5f7e7cd070d107c2), TO_LIMB_T(0xec839a9ac49c13c8),+        TO_LIMB_T(0x6933786f44f4ef0b), TO_LIMB_T(0xd6bf8b9c676be983),+        TO_LIMB_T(0xd3adaaaa4dcefb06), TO_LIMB_T(0x12601bc1d82bc175)+    };+#endif+    union { vec768 x; vec384 r[2]; } temp;++    ct_inverse_mod_383(temp.x, inp, BLS12_381_P, Px8);+    redc_mont_384(temp.r[0], temp.x, BLS12_381_P, p0);+    mul_mont_384(temp.r[0], temp.r[0], RRx4, BLS12_381_P, p0);++#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION+    /* sign goes straight to flt_reciprocal */+    mul_mont_384(temp.r[1], temp.r[0], inp, BLS12_381_P, p0);+    if (vec_is_equal(temp.r[1],  BLS12_381_Rx.p, sizeof(vec384)) |+        vec_is_zero(temp.r[1], sizeof(vec384)))+        vec_copy(out, temp.r[0], sizeof(vec384));+    else+        flt_reciprocal_fp(out, inp);+#else+    vec_copy(out, temp.r[0], sizeof(vec384));+#endif+#undef RRx4+}++void blst_fp_inverse(vec384 out, const vec384 inp)+{   reciprocal_fp(out, inp);   }++void blst_fp_eucl_inverse(vec384 ret, const vec384 a)+{   reciprocal_fp(ret, a);   }++static void reciprocal_fp2(vec384x out, const vec384x inp)+{+    vec384 t0, t1;++    /*+     * |out| = 1/(a + b*i) = a/(a^2+b^2) - b/(a^2+b^2)*i+     */+    sqr_fp(t0, inp[0]);+    sqr_fp(t1, inp[1]);+    add_fp(t0, t0, t1);+    reciprocal_fp(t1, t0);+    mul_fp(out[0], inp[0], t1);+    mul_fp(out[1], inp[1], t1);+    neg_fp(out[1], out[1]);+}++void blst_fp2_inverse(vec384x out, const vec384x inp)+{   reciprocal_fp2(out, inp);   }++void blst_fp2_eucl_inverse(vec384x out, const vec384x inp)+{   reciprocal_fp2(out, inp);   }++static void reciprocal_fr(vec256 out, const vec256 inp)+{+    static const vec256 rx2 = { /* left-aligned value of the modulus */+        TO_LIMB_T(0xfffffffe00000002), TO_LIMB_T(0xa77b4805fffcb7fd),+        TO_LIMB_T(0x6673b0101343b00a), TO_LIMB_T(0xe7db4ea6533afa90),+    };+    vec512 temp;++    ct_inverse_mod_256(temp, inp, BLS12_381_r, rx2);+    redc_mont_256(out, temp, BLS12_381_r, r0);+    mul_mont_sparse_256(out, out, BLS12_381_rRR, BLS12_381_r, r0);+}++void blst_fr_inverse(vec256 out, const vec256 inp)+{   reciprocal_fr(out, inp);   }++void blst_fr_eucl_inverse(vec256 out, const vec256 inp)+{   reciprocal_fr(out, inp);   }
+ vendor/external/blst/src/server.c view
@@ -0,0 +1,32 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "keygen.c"+#include "hash_to_field.c"+#include "e1.c"+#include "map_to_g1.c"+#include "e2.c"+#include "map_to_g2.c"+#include "fp12_tower.c"+#include "pairing.c"+#include "aggregate.c"+#include "exp.c"+#include "sqrt.c"+#include "recip.c"+#include "bulk_addition.c"+#include "multi_scalar.c"+#include "consts.c"+#include "vect.c"+#include "exports.c"+#ifndef __BLST_CGO__+# include "rb_tree.c"+#endif+#ifdef BLST_FR_PENTAROOT+# include "pentaroot.c"+#endif+#ifndef __BLST_NO_CPUID__+# include "cpuid.c"+#endif
+ vendor/external/blst/src/sha256.h view
@@ -0,0 +1,140 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLS12_381_ASM_SHA256_H__+#define __BLS12_381_ASM_SHA256_H__++#include "vect.h"++#if (defined(__x86_64__) || defined(__x86_64) || defined(_M_X64)) && \+     defined(__SHA__) /* -msha */ && !defined(__BLST_PORTABLE__)+# define sha256_block_data_order blst_sha256_block_data_order_shaext+#elif defined(__aarch64__) && \+      defined(__ARM_FEATURE_CRYPTO) && !defined(__BLST_PORTABLE__)+# define sha256_block_data_order blst_sha256_block_armv8+#else+# define sha256_block_data_order blst_sha256_block_data_order+#endif+#define sha256_hcopy blst_sha256_hcopy+#define sha256_bcopy blst_sha256_bcopy+#define sha256_emit  blst_sha256_emit++void sha256_block_data_order(unsigned int *h, const void *inp, size_t blocks);+void sha256_hcopy(unsigned int dst[8], const unsigned int src[8]);+void sha256_bcopy(void *dst, const void *src, size_t len);++/*+ * If SHA256_CTX conflicts with something, just redefine it to alternative+ * custom name prior including this header.+ */+typedef struct {+    unsigned int h[8];+    unsigned long long N;+    unsigned char buf[64];+    size_t off;+} SHA256_CTX;+++static void sha256_init_h(unsigned int h[8])+{+    h[0] = 0x6a09e667U;+    h[1] = 0xbb67ae85U;+    h[2] = 0x3c6ef372U;+    h[3] = 0xa54ff53aU;+    h[4] = 0x510e527fU;+    h[5] = 0x9b05688cU;+    h[6] = 0x1f83d9abU;+    h[7] = 0x5be0cd19U;+}++static void sha256_init(SHA256_CTX *ctx)+{+    sha256_init_h(ctx->h);+    ctx->N = 0;+    vec_zero(ctx->buf, sizeof(ctx->buf));+    ctx->off = 0;+}++static void sha256_update(SHA256_CTX *ctx, const void *_inp, size_t len)+{+    size_t n;+    const unsigned char *inp = _inp;++    ctx->N += len;++    if ((len != 0) & ((n = ctx->off) != 0)) {+        size_t rem = sizeof(ctx->buf) - n;++        if (rem > len) {+            sha256_bcopy(ctx->buf + n, inp, len);+            ctx->off += len;+            return;+        } else {+            sha256_bcopy(ctx->buf + n, inp, rem);+            inp += rem;+            len -= rem;+            sha256_block_data_order(ctx->h, ctx->buf, 1);+            vec_zero(ctx->buf, sizeof(ctx->buf));+            ctx->off = 0;+        }+    }++    n = len / sizeof(ctx->buf);+    if (n > 0) {+        sha256_block_data_order(ctx->h, inp, n);+        n *= sizeof(ctx->buf);+        inp += n;+        len -= n;+    }++    if (len)+        sha256_bcopy(ctx->buf, inp, ctx->off = len);+}++#define __TOBE32(ptr, val) ((ptr)[0] = (unsigned char)((val)>>24), \+                            (ptr)[1] = (unsigned char)((val)>>16), \+                            (ptr)[2] = (unsigned char)((val)>>8),  \+                            (ptr)[3] = (unsigned char)(val))++#if 1+void sha256_emit(unsigned char md[32], const unsigned int h[8]);+#else+static void sha256_emit(unsigned char md[32], const unsigned int h[8])+{+    unsigned int h_i;++    h_i = h[0]; __TOBE32(md + 0, h_i);+    h_i = h[1]; __TOBE32(md + 4, h_i);+    h_i = h[2]; __TOBE32(md + 8, h_i);+    h_i = h[3]; __TOBE32(md + 12, h_i);+    h_i = h[4]; __TOBE32(md + 16, h_i);+    h_i = h[5]; __TOBE32(md + 20, h_i);+    h_i = h[6]; __TOBE32(md + 24, h_i);+    h_i = h[7]; __TOBE32(md + 28, h_i);+}+#endif++static void sha256_final(unsigned char md[32], SHA256_CTX *ctx)+{+    unsigned long long bits = ctx->N * 8;+    size_t n = ctx->off;+    unsigned char *tail;++    ctx->buf[n++] = 0x80;++    if (n > (sizeof(ctx->buf) - 8)) {+        sha256_block_data_order(ctx->h, ctx->buf, 1);+        vec_zero(ctx->buf, sizeof(ctx->buf));+    }++    tail = ctx->buf + sizeof(ctx->buf) - 8;+    __TOBE32(tail, (unsigned int)(bits >> 32));+    __TOBE32(tail + 4, (unsigned int)bits);+    sha256_block_data_order(ctx->h, ctx->buf, 1);+    sha256_emit(md, ctx->h);+}++#undef __TOBE32+#endif
+ vendor/external/blst/src/sqrt-addchain.h view
@@ -0,0 +1,489 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+/*+ * The "magic" number is (BLS12_381_P-3)/4. Exponentiation to which+ * yields reciprocal of sqrt(x), which is used in simplified Shallue-+ * van de Woestijne-Ulas map-to-curve method, but it's trivial to adapt+ * it for more "traditional" sqrt(x) as 'x*ret' (or for is_square(x)+ * as 'x*ret^2==1').+ *+ * Generated with 'addchain 1000602388805416848354447456433976039139220704984751971333014534031007912622709466110671907282253916009473568139946'+ * https://github.com/kwantam/addchain+ *+ * # Bos-Coster (win=4)           :  458 (16) <<<+ * # Bos-Coster (win=5)           :  460 (28)+ * # Bos-Coster (win=6)           :  461 (33)+ * # Bos-Coster (win=7)           :  460 (28)+ * # Bos-Coster (win=3)           :  462 ( 9)+ * # Bos-Coster (win=8)           :  466 (34)+ * # Bos-Coster (win=9)           :  464 (31)+ * # Yacobi                       :  478 (31)+ * # Bos-Coster (win=10)          :  473 (30)+ * # Bos-Coster (win=2)           :  486 ( 5)+ * # Bergeron-Berstel-Brlek-Duboc :  489 ( 5)+ */++#define RECIP_SQRT_MOD_BLS12_381_P(out, inp, ptype) do { \+ptype t[16]; \+vec_copy(t[13], inp, sizeof(ptype));/*    0: 1 */\+sqr(t[0], t[13]);                   /*    1: 2 */\+mul(t[8], t[0], t[13]);             /*    2: 3 */\+sqr(t[4], t[0]);                    /*    3: 4 */\+mul(t[1], t[8], t[0]);              /*    4: 5 */\+mul(t[6], t[4], t[8]);              /*    5: 7 */\+mul(t[9], t[1], t[4]);              /*    6: 9 */\+mul(t[12], t[6], t[4]);             /*    7: b */\+mul(t[3], t[9], t[4]);              /*    8: d */\+mul(t[7], t[12], t[4]);             /*    9: f */\+mul(t[15], t[3], t[4]);             /*   10: 11 */\+mul(t[10], t[7], t[4]);             /*   11: 13 */\+mul(t[2], t[15], t[4]);             /*   12: 15 */\+mul(t[11], t[10], t[4]);            /*   13: 17 */\+sqr(t[0], t[3]);                    /*   14: 1a */\+mul(t[14], t[11], t[4]);            /*   15: 1b */\+mul(t[5], t[0], t[8]);              /*   16: 1d */\+mul(t[4], t[0], t[1]);              /*   17: 1f */\+/* sqr(t[0], t[0]); */              /*   18: 34 */\+/* sqr(t[0], t[0]); */              /*   19: 68 */\+/* sqr(t[0], t[0]); */              /*   20: d0 */\+/* sqr(t[0], t[0]); */              /*   21: 1a0 */\+/* sqr(t[0], t[0]); */              /*   22: 340 */\+/* sqr(t[0], t[0]); */              /*   23: 680 */\+/* sqr(t[0], t[0]); */              /*   24: d00 */\+/* sqr(t[0], t[0]); */              /*   25: 1a00 */\+/* sqr(t[0], t[0]); */              /*   26: 3400 */\+/* sqr(t[0], t[0]); */              /*   27: 6800 */\+/* sqr(t[0], t[0]); */              /*   28: d000 */\+/* sqr(t[0], t[0]); */              /*   29: 1a000 */\+sqr_n_mul(t[0], t[0], 12, t[15]);   /*   30: 1a011 */\+/* sqr(t[0], t[0]); */              /*   31: 34022 */\+/* sqr(t[0], t[0]); */              /*   32: 68044 */\+/* sqr(t[0], t[0]); */              /*   33: d0088 */\+/* sqr(t[0], t[0]); */              /*   34: 1a0110 */\+/* sqr(t[0], t[0]); */              /*   35: 340220 */\+/* sqr(t[0], t[0]); */              /*   36: 680440 */\+/* sqr(t[0], t[0]); */              /*   37: d00880 */\+sqr_n_mul(t[0], t[0], 7, t[7]);     /*   38: d0088f */\+/* sqr(t[0], t[0]); */              /*   39: 1a0111e */\+/* sqr(t[0], t[0]); */              /*   40: 340223c */\+/* sqr(t[0], t[0]); */              /*   41: 6804478 */\+/* sqr(t[0], t[0]); */              /*   42: d0088f0 */\+sqr_n_mul(t[0], t[0], 4, t[1]);     /*   43: d0088f5 */\+/* sqr(t[0], t[0]); */              /*   44: 1a0111ea */\+/* sqr(t[0], t[0]); */              /*   45: 340223d4 */\+/* sqr(t[0], t[0]); */              /*   46: 680447a8 */\+/* sqr(t[0], t[0]); */              /*   47: d0088f50 */\+/* sqr(t[0], t[0]); */              /*   48: 1a0111ea0 */\+/* sqr(t[0], t[0]); */              /*   49: 340223d40 */\+sqr_n_mul(t[0], t[0], 6, t[6]);     /*   50: 340223d47 */\+/* sqr(t[0], t[0]); */              /*   51: 680447a8e */\+/* sqr(t[0], t[0]); */              /*   52: d0088f51c */\+/* sqr(t[0], t[0]); */              /*   53: 1a0111ea38 */\+/* sqr(t[0], t[0]); */              /*   54: 340223d470 */\+/* sqr(t[0], t[0]); */              /*   55: 680447a8e0 */\+/* sqr(t[0], t[0]); */              /*   56: d0088f51c0 */\+/* sqr(t[0], t[0]); */              /*   57: 1a0111ea380 */\+sqr_n_mul(t[0], t[0], 7, t[11]);    /*   58: 1a0111ea397 */\+/* sqr(t[0], t[0]); */              /*   59: 340223d472e */\+/* sqr(t[0], t[0]); */              /*   60: 680447a8e5c */\+/* sqr(t[0], t[0]); */              /*   61: d0088f51cb8 */\+/* sqr(t[0], t[0]); */              /*   62: 1a0111ea3970 */\+/* sqr(t[0], t[0]); */              /*   63: 340223d472e0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*   64: 340223d472ff */\+/* sqr(t[0], t[0]); */              /*   65: 680447a8e5fe */\+/* sqr(t[0], t[0]); */              /*   66: d0088f51cbfc */\+sqr_n_mul(t[0], t[0], 2, t[8]);     /*   67: d0088f51cbff */\+/* sqr(t[0], t[0]); */              /*   68: 1a0111ea397fe */\+/* sqr(t[0], t[0]); */              /*   69: 340223d472ffc */\+/* sqr(t[0], t[0]); */              /*   70: 680447a8e5ff8 */\+/* sqr(t[0], t[0]); */              /*   71: d0088f51cbff0 */\+/* sqr(t[0], t[0]); */              /*   72: 1a0111ea397fe0 */\+/* sqr(t[0], t[0]); */              /*   73: 340223d472ffc0 */\+sqr_n_mul(t[0], t[0], 6, t[3]);     /*   74: 340223d472ffcd */\+/* sqr(t[0], t[0]); */              /*   75: 680447a8e5ff9a */\+/* sqr(t[0], t[0]); */              /*   76: d0088f51cbff34 */\+/* sqr(t[0], t[0]); */              /*   77: 1a0111ea397fe68 */\+/* sqr(t[0], t[0]); */              /*   78: 340223d472ffcd0 */\+/* sqr(t[0], t[0]); */              /*   79: 680447a8e5ff9a0 */\+/* sqr(t[0], t[0]); */              /*   80: d0088f51cbff340 */\+sqr_n_mul(t[0], t[0], 6, t[3]);     /*   81: d0088f51cbff34d */\+/* sqr(t[0], t[0]); */              /*   82: 1a0111ea397fe69a */\+/* sqr(t[0], t[0]); */              /*   83: 340223d472ffcd34 */\+/* sqr(t[0], t[0]); */              /*   84: 680447a8e5ff9a68 */\+/* sqr(t[0], t[0]); */              /*   85: d0088f51cbff34d0 */\+/* sqr(t[0], t[0]); */              /*   86: 1a0111ea397fe69a0 */\+/* sqr(t[0], t[0]); */              /*   87: 340223d472ffcd340 */\+sqr_n_mul(t[0], t[0], 6, t[9]);     /*   88: 340223d472ffcd349 */\+/* sqr(t[0], t[0]); */              /*   89: 680447a8e5ff9a692 */\+/* sqr(t[0], t[0]); */              /*   90: d0088f51cbff34d24 */\+/* sqr(t[0], t[0]); */              /*   91: 1a0111ea397fe69a48 */\+sqr_n_mul(t[0], t[0], 3, t[8]);     /*   92: 1a0111ea397fe69a4b */\+/* sqr(t[0], t[0]); */              /*   93: 340223d472ffcd3496 */\+/* sqr(t[0], t[0]); */              /*   94: 680447a8e5ff9a692c */\+/* sqr(t[0], t[0]); */              /*   95: d0088f51cbff34d258 */\+/* sqr(t[0], t[0]); */              /*   96: 1a0111ea397fe69a4b0 */\+/* sqr(t[0], t[0]); */              /*   97: 340223d472ffcd34960 */\+/* sqr(t[0], t[0]); */              /*   98: 680447a8e5ff9a692c0 */\+/* sqr(t[0], t[0]); */              /*   99: d0088f51cbff34d2580 */\+sqr_n_mul(t[0], t[0], 7, t[3]);     /*  100: d0088f51cbff34d258d */\+/* sqr(t[0], t[0]); */              /*  101: 1a0111ea397fe69a4b1a */\+/* sqr(t[0], t[0]); */              /*  102: 340223d472ffcd349634 */\+/* sqr(t[0], t[0]); */              /*  103: 680447a8e5ff9a692c68 */\+/* sqr(t[0], t[0]); */              /*  104: d0088f51cbff34d258d0 */\+sqr_n_mul(t[0], t[0], 4, t[3]);     /*  105: d0088f51cbff34d258dd */\+/* sqr(t[0], t[0]); */              /*  106: 1a0111ea397fe69a4b1ba */\+/* sqr(t[0], t[0]); */              /*  107: 340223d472ffcd3496374 */\+/* sqr(t[0], t[0]); */              /*  108: 680447a8e5ff9a692c6e8 */\+/* sqr(t[0], t[0]); */              /*  109: d0088f51cbff34d258dd0 */\+/* sqr(t[0], t[0]); */              /*  110: 1a0111ea397fe69a4b1ba0 */\+/* sqr(t[0], t[0]); */              /*  111: 340223d472ffcd34963740 */\+sqr_n_mul(t[0], t[0], 6, t[7]);     /*  112: 340223d472ffcd3496374f */\+/* sqr(t[0], t[0]); */              /*  113: 680447a8e5ff9a692c6e9e */\+/* sqr(t[0], t[0]); */              /*  114: d0088f51cbff34d258dd3c */\+/* sqr(t[0], t[0]); */              /*  115: 1a0111ea397fe69a4b1ba78 */\+/* sqr(t[0], t[0]); */              /*  116: 340223d472ffcd3496374f0 */\+/* sqr(t[0], t[0]); */              /*  117: 680447a8e5ff9a692c6e9e0 */\+/* sqr(t[0], t[0]); */              /*  118: d0088f51cbff34d258dd3c0 */\+sqr_n_mul(t[0], t[0], 6, t[14]);    /*  119: d0088f51cbff34d258dd3db */\+/* sqr(t[0], t[0]); */              /*  120: 1a0111ea397fe69a4b1ba7b6 */\+/* sqr(t[0], t[0]); */              /*  121: 340223d472ffcd3496374f6c */\+/* sqr(t[0], t[0]); */              /*  122: 680447a8e5ff9a692c6e9ed8 */\+sqr_n_mul(t[0], t[0], 3, t[13]);    /*  123: 680447a8e5ff9a692c6e9ed9 */\+/* sqr(t[0], t[0]); */              /*  124: d0088f51cbff34d258dd3db2 */\+/* sqr(t[0], t[0]); */              /*  125: 1a0111ea397fe69a4b1ba7b64 */\+/* sqr(t[0], t[0]); */              /*  126: 340223d472ffcd3496374f6c8 */\+/* sqr(t[0], t[0]); */              /*  127: 680447a8e5ff9a692c6e9ed90 */\+/* sqr(t[0], t[0]); */              /*  128: d0088f51cbff34d258dd3db20 */\+/* sqr(t[0], t[0]); */              /*  129: 1a0111ea397fe69a4b1ba7b640 */\+/* sqr(t[0], t[0]); */              /*  130: 340223d472ffcd3496374f6c80 */\+/* sqr(t[0], t[0]); */              /*  131: 680447a8e5ff9a692c6e9ed900 */\+sqr_n_mul(t[0], t[0], 8, t[3]);     /*  132: 680447a8e5ff9a692c6e9ed90d */\+/* sqr(t[0], t[0]); */              /*  133: d0088f51cbff34d258dd3db21a */\+/* sqr(t[0], t[0]); */              /*  134: 1a0111ea397fe69a4b1ba7b6434 */\+/* sqr(t[0], t[0]); */              /*  135: 340223d472ffcd3496374f6c868 */\+/* sqr(t[0], t[0]); */              /*  136: 680447a8e5ff9a692c6e9ed90d0 */\+/* sqr(t[0], t[0]); */              /*  137: d0088f51cbff34d258dd3db21a0 */\+/* sqr(t[0], t[0]); */              /*  138: 1a0111ea397fe69a4b1ba7b64340 */\+/* sqr(t[0], t[0]); */              /*  139: 340223d472ffcd3496374f6c8680 */\+sqr_n_mul(t[0], t[0], 7, t[11]);    /*  140: 340223d472ffcd3496374f6c8697 */\+/* sqr(t[0], t[0]); */              /*  141: 680447a8e5ff9a692c6e9ed90d2e */\+/* sqr(t[0], t[0]); */              /*  142: d0088f51cbff34d258dd3db21a5c */\+/* sqr(t[0], t[0]); */              /*  143: 1a0111ea397fe69a4b1ba7b6434b8 */\+/* sqr(t[0], t[0]); */              /*  144: 340223d472ffcd3496374f6c86970 */\+/* sqr(t[0], t[0]); */              /*  145: 680447a8e5ff9a692c6e9ed90d2e0 */\+sqr_n_mul(t[0], t[0], 5, t[12]);    /*  146: 680447a8e5ff9a692c6e9ed90d2eb */\+/* sqr(t[0], t[0]); */              /*  147: d0088f51cbff34d258dd3db21a5d6 */\+/* sqr(t[0], t[0]); */              /*  148: 1a0111ea397fe69a4b1ba7b6434bac */\+/* sqr(t[0], t[0]); */              /*  149: 340223d472ffcd3496374f6c869758 */\+/* sqr(t[0], t[0]); */              /*  150: 680447a8e5ff9a692c6e9ed90d2eb0 */\+/* sqr(t[0], t[0]); */              /*  151: d0088f51cbff34d258dd3db21a5d60 */\+/* sqr(t[0], t[0]); */              /*  152: 1a0111ea397fe69a4b1ba7b6434bac0 */\+sqr_n_mul(t[0], t[0], 6, t[3]);     /*  153: 1a0111ea397fe69a4b1ba7b6434bacd */\+/* sqr(t[0], t[0]); */              /*  154: 340223d472ffcd3496374f6c869759a */\+/* sqr(t[0], t[0]); */              /*  155: 680447a8e5ff9a692c6e9ed90d2eb34 */\+/* sqr(t[0], t[0]); */              /*  156: d0088f51cbff34d258dd3db21a5d668 */\+/* sqr(t[0], t[0]); */              /*  157: 1a0111ea397fe69a4b1ba7b6434bacd0 */\+/* sqr(t[0], t[0]); */              /*  158: 340223d472ffcd3496374f6c869759a0 */\+/* sqr(t[0], t[0]); */              /*  159: 680447a8e5ff9a692c6e9ed90d2eb340 */\+sqr_n_mul(t[0], t[0], 6, t[5]);     /*  160: 680447a8e5ff9a692c6e9ed90d2eb35d */\+/* sqr(t[0], t[0]); */              /*  161: d0088f51cbff34d258dd3db21a5d66ba */\+/* sqr(t[0], t[0]); */              /*  162: 1a0111ea397fe69a4b1ba7b6434bacd74 */\+/* sqr(t[0], t[0]); */              /*  163: 340223d472ffcd3496374f6c869759ae8 */\+/* sqr(t[0], t[0]); */              /*  164: 680447a8e5ff9a692c6e9ed90d2eb35d0 */\+sqr_n_mul(t[0], t[0], 4, t[9]);     /*  165: 680447a8e5ff9a692c6e9ed90d2eb35d9 */\+/* sqr(t[0], t[0]); */              /*  166: d0088f51cbff34d258dd3db21a5d66bb2 */\+/* sqr(t[0], t[0]); */              /*  167: 1a0111ea397fe69a4b1ba7b6434bacd764 */\+/* sqr(t[0], t[0]); */              /*  168: 340223d472ffcd3496374f6c869759aec8 */\+/* sqr(t[0], t[0]); */              /*  169: 680447a8e5ff9a692c6e9ed90d2eb35d90 */\+/* sqr(t[0], t[0]); */              /*  170: d0088f51cbff34d258dd3db21a5d66bb20 */\+/* sqr(t[0], t[0]); */              /*  171: 1a0111ea397fe69a4b1ba7b6434bacd7640 */\+/* sqr(t[0], t[0]); */              /*  172: 340223d472ffcd3496374f6c869759aec80 */\+/* sqr(t[0], t[0]); */              /*  173: 680447a8e5ff9a692c6e9ed90d2eb35d900 */\+sqr_n_mul(t[0], t[0], 8, t[5]);     /*  174: 680447a8e5ff9a692c6e9ed90d2eb35d91d */\+/* sqr(t[0], t[0]); */              /*  175: d0088f51cbff34d258dd3db21a5d66bb23a */\+/* sqr(t[0], t[0]); */              /*  176: 1a0111ea397fe69a4b1ba7b6434bacd76474 */\+/* sqr(t[0], t[0]); */              /*  177: 340223d472ffcd3496374f6c869759aec8e8 */\+/* sqr(t[0], t[0]); */              /*  178: 680447a8e5ff9a692c6e9ed90d2eb35d91d0 */\+sqr_n_mul(t[0], t[0], 4, t[3]);     /*  179: 680447a8e5ff9a692c6e9ed90d2eb35d91dd */\+/* sqr(t[0], t[0]); */              /*  180: d0088f51cbff34d258dd3db21a5d66bb23ba */\+/* sqr(t[0], t[0]); */              /*  181: 1a0111ea397fe69a4b1ba7b6434bacd764774 */\+/* sqr(t[0], t[0]); */              /*  182: 340223d472ffcd3496374f6c869759aec8ee8 */\+/* sqr(t[0], t[0]); */              /*  183: 680447a8e5ff9a692c6e9ed90d2eb35d91dd0 */\+/* sqr(t[0], t[0]); */              /*  184: d0088f51cbff34d258dd3db21a5d66bb23ba0 */\+/* sqr(t[0], t[0]); */              /*  185: 1a0111ea397fe69a4b1ba7b6434bacd7647740 */\+/* sqr(t[0], t[0]); */              /*  186: 340223d472ffcd3496374f6c869759aec8ee80 */\+sqr_n_mul(t[0], t[0], 7, t[11]);    /*  187: 340223d472ffcd3496374f6c869759aec8ee97 */\+/* sqr(t[0], t[0]); */              /*  188: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e */\+/* sqr(t[0], t[0]); */              /*  189: d0088f51cbff34d258dd3db21a5d66bb23ba5c */\+/* sqr(t[0], t[0]); */              /*  190: 1a0111ea397fe69a4b1ba7b6434bacd764774b8 */\+/* sqr(t[0], t[0]); */              /*  191: 340223d472ffcd3496374f6c869759aec8ee970 */\+/* sqr(t[0], t[0]); */              /*  192: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e0 */\+/* sqr(t[0], t[0]); */              /*  193: d0088f51cbff34d258dd3db21a5d66bb23ba5c0 */\+/* sqr(t[0], t[0]); */              /*  194: 1a0111ea397fe69a4b1ba7b6434bacd764774b80 */\+/* sqr(t[0], t[0]); */              /*  195: 340223d472ffcd3496374f6c869759aec8ee9700 */\+/* sqr(t[0], t[0]); */              /*  196: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e00 */\+sqr_n_mul(t[0], t[0], 9, t[10]);    /*  197: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13 */\+/* sqr(t[0], t[0]); */              /*  198: d0088f51cbff34d258dd3db21a5d66bb23ba5c26 */\+/* sqr(t[0], t[0]); */              /*  199: 1a0111ea397fe69a4b1ba7b6434bacd764774b84c */\+sqr_n_mul(t[0], t[0], 2, t[8]);     /*  200: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f */\+/* sqr(t[0], t[0]); */              /*  201: 340223d472ffcd3496374f6c869759aec8ee9709e */\+/* sqr(t[0], t[0]); */              /*  202: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13c */\+/* sqr(t[0], t[0]); */              /*  203: d0088f51cbff34d258dd3db21a5d66bb23ba5c278 */\+/* sqr(t[0], t[0]); */              /*  204: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f0 */\+/* sqr(t[0], t[0]); */              /*  205: 340223d472ffcd3496374f6c869759aec8ee9709e0 */\+sqr_n_mul(t[0], t[0], 5, t[6]);     /*  206: 340223d472ffcd3496374f6c869759aec8ee9709e7 */\+/* sqr(t[0], t[0]); */              /*  207: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce */\+/* sqr(t[0], t[0]); */              /*  208: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c */\+/* sqr(t[0], t[0]); */              /*  209: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38 */\+/* sqr(t[0], t[0]); */              /*  210: 340223d472ffcd3496374f6c869759aec8ee9709e70 */\+/* sqr(t[0], t[0]); */              /*  211: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce0 */\+/* sqr(t[0], t[0]); */              /*  212: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c0 */\+/* sqr(t[0], t[0]); */              /*  213: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f380 */\+sqr_n_mul(t[0], t[0], 7, t[1]);     /*  214: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f385 */\+/* sqr(t[0], t[0]); */              /*  215: 340223d472ffcd3496374f6c869759aec8ee9709e70a */\+/* sqr(t[0], t[0]); */              /*  216: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce14 */\+/* sqr(t[0], t[0]); */              /*  217: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c28 */\+/* sqr(t[0], t[0]); */              /*  218: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f3850 */\+/* sqr(t[0], t[0]); */              /*  219: 340223d472ffcd3496374f6c869759aec8ee9709e70a0 */\+/* sqr(t[0], t[0]); */              /*  220: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce140 */\+/* sqr(t[0], t[0]); */              /*  221: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c280 */\+sqr_n_mul(t[0], t[0], 7, t[9]);     /*  222: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c289 */\+/* sqr(t[0], t[0]); */              /*  223: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512 */\+/* sqr(t[0], t[0]); */              /*  224: 340223d472ffcd3496374f6c869759aec8ee9709e70a24 */\+/* sqr(t[0], t[0]); */              /*  225: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce1448 */\+/* sqr(t[0], t[0]); */              /*  226: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2890 */\+/* sqr(t[0], t[0]); */              /*  227: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f385120 */\+/* sqr(t[0], t[0]); */              /*  228: 340223d472ffcd3496374f6c869759aec8ee9709e70a240 */\+sqr_n_mul(t[0], t[0], 6, t[11]);    /*  229: 340223d472ffcd3496374f6c869759aec8ee9709e70a257 */\+/* sqr(t[0], t[0]); */              /*  230: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144ae */\+/* sqr(t[0], t[0]); */              /*  231: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895c */\+/* sqr(t[0], t[0]); */              /*  232: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512b8 */\+/* sqr(t[0], t[0]); */              /*  233: 340223d472ffcd3496374f6c869759aec8ee9709e70a2570 */\+/* sqr(t[0], t[0]); */              /*  234: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144ae0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  235: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd */\+/* sqr(t[0], t[0]); */              /*  236: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fa */\+/* sqr(t[0], t[0]); */              /*  237: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf4 */\+/* sqr(t[0], t[0]); */              /*  238: 340223d472ffcd3496374f6c869759aec8ee9709e70a257e8 */\+/* sqr(t[0], t[0]); */              /*  239: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd0 */\+/* sqr(t[0], t[0]); */              /*  240: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fa0 */\+sqr_n_mul(t[0], t[0], 5, t[10]);    /*  241: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb3 */\+/* sqr(t[0], t[0]); */              /*  242: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf66 */\+/* sqr(t[0], t[0]); */              /*  243: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ecc */\+/* sqr(t[0], t[0]); */              /*  244: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd98 */\+/* sqr(t[0], t[0]); */              /*  245: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb30 */\+/* sqr(t[0], t[0]); */              /*  246: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf660 */\+sqr_n_mul(t[0], t[0], 5, t[10]);    /*  247: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf673 */\+/* sqr(t[0], t[0]); */              /*  248: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece6 */\+/* sqr(t[0], t[0]); */              /*  249: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc */\+/* sqr(t[0], t[0]); */              /*  250: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb398 */\+/* sqr(t[0], t[0]); */              /*  251: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730 */\+/* sqr(t[0], t[0]); */              /*  252: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece60 */\+/* sqr(t[0], t[0]); */              /*  253: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc0 */\+/* sqr(t[0], t[0]); */              /*  254: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb3980 */\+/* sqr(t[0], t[0]); */              /*  255: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf67300 */\+sqr_n_mul(t[0], t[0], 8, t[3]);     /*  256: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d */\+/* sqr(t[0], t[0]); */              /*  257: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a */\+/* sqr(t[0], t[0]); */              /*  258: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34 */\+/* sqr(t[0], t[0]); */              /*  259: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39868 */\+/* sqr(t[0], t[0]); */              /*  260: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d0 */\+/* sqr(t[0], t[0]); */              /*  261: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a0 */\+/* sqr(t[0], t[0]); */              /*  262: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc340 */\+/* sqr(t[0], t[0]); */              /*  263: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb398680 */\+sqr_n_mul(t[0], t[0], 7, t[2]);     /*  264: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb398695 */\+/* sqr(t[0], t[0]); */              /*  265: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a */\+/* sqr(t[0], t[0]); */              /*  266: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a54 */\+/* sqr(t[0], t[0]); */              /*  267: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a8 */\+/* sqr(t[0], t[0]); */              /*  268: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb3986950 */\+/* sqr(t[0], t[0]); */              /*  269: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0 */\+/* sqr(t[0], t[0]); */              /*  270: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a540 */\+/* sqr(t[0], t[0]); */              /*  271: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a80 */\+/* sqr(t[0], t[0]); */              /*  272: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869500 */\+/* sqr(t[0], t[0]); */              /*  273: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a00 */\+sqr_n_mul(t[0], t[0], 9, t[7]);     /*  274: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f */\+/* sqr(t[0], t[0]); */              /*  275: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541e */\+/* sqr(t[0], t[0]); */              /*  276: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83c */\+/* sqr(t[0], t[0]); */              /*  277: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb398695078 */\+/* sqr(t[0], t[0]); */              /*  278: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f0 */\+/* sqr(t[0], t[0]); */              /*  279: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541e0 */\+sqr_n_mul(t[0], t[0], 5, t[3]);     /*  280: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed */\+/* sqr(t[0], t[0]); */              /*  281: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83da */\+/* sqr(t[0], t[0]); */              /*  282: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b4 */\+/* sqr(t[0], t[0]); */              /*  283: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f68 */\+sqr_n_mul(t[0], t[0], 3, t[8]);     /*  284: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b */\+/* sqr(t[0], t[0]); */              /*  285: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed6 */\+/* sqr(t[0], t[0]); */              /*  286: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac */\+/* sqr(t[0], t[0]); */              /*  287: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b58 */\+/* sqr(t[0], t[0]); */              /*  288: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0 */\+/* sqr(t[0], t[0]); */              /*  289: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed60 */\+/* sqr(t[0], t[0]); */              /*  290: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac0 */\+/* sqr(t[0], t[0]); */              /*  291: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b580 */\+/* sqr(t[0], t[0]); */              /*  292: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b00 */\+sqr_n_mul(t[0], t[0], 8, t[7]);     /*  293: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f */\+/* sqr(t[0], t[0]); */              /*  294: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61e */\+/* sqr(t[0], t[0]); */              /*  295: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3c */\+/* sqr(t[0], t[0]); */              /*  296: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b5878 */\+sqr_n_mul(t[0], t[0], 3, t[8]);     /*  297: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b */\+/* sqr(t[0], t[0]); */              /*  298: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6 */\+/* sqr(t[0], t[0]); */              /*  299: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec */\+/* sqr(t[0], t[0]); */              /*  300: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8 */\+/* sqr(t[0], t[0]); */              /*  301: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b0 */\+/* sqr(t[0], t[0]); */              /*  302: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f60 */\+/* sqr(t[0], t[0]); */              /*  303: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec0 */\+/* sqr(t[0], t[0]); */              /*  304: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d80 */\+sqr_n_mul(t[0], t[0], 7, t[9]);     /*  305: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d89 */\+/* sqr(t[0], t[0]); */              /*  306: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b12 */\+/* sqr(t[0], t[0]); */              /*  307: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f624 */\+/* sqr(t[0], t[0]); */              /*  308: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec48 */\+/* sqr(t[0], t[0]); */              /*  309: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d890 */\+/* sqr(t[0], t[0]); */              /*  310: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120 */\+/* sqr(t[0], t[0]); */              /*  311: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6240 */\+/* sqr(t[0], t[0]); */              /*  312: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec480 */\+/* sqr(t[0], t[0]); */              /*  313: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8900 */\+/* sqr(t[0], t[0]); */              /*  314: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b1200 */\+sqr_n_mul(t[0], t[0], 9, t[7]);     /*  315: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f */\+/* sqr(t[0], t[0]); */              /*  316: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241e */\+/* sqr(t[0], t[0]); */              /*  317: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483c */\+/* sqr(t[0], t[0]); */              /*  318: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d89078 */\+/* sqr(t[0], t[0]); */              /*  319: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f0 */\+/* sqr(t[0], t[0]); */              /*  320: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241e0 */\+/* sqr(t[0], t[0]); */              /*  321: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483c0 */\+sqr_n_mul(t[0], t[0], 6, t[2]);     /*  322: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d5 */\+/* sqr(t[0], t[0]); */              /*  323: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aa */\+/* sqr(t[0], t[0]); */              /*  324: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f54 */\+/* sqr(t[0], t[0]); */              /*  325: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241ea8 */\+/* sqr(t[0], t[0]); */              /*  326: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d50 */\+/* sqr(t[0], t[0]); */              /*  327: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aa0 */\+/* sqr(t[0], t[0]); */              /*  328: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f540 */\+sqr_n_mul(t[0], t[0], 6, t[4]);     /*  329: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55f */\+/* sqr(t[0], t[0]); */              /*  330: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabe */\+/* sqr(t[0], t[0]); */              /*  331: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57c */\+/* sqr(t[0], t[0]); */              /*  332: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaf8 */\+/* sqr(t[0], t[0]); */              /*  333: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55f0 */\+/* sqr(t[0], t[0]); */              /*  334: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabe0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  335: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabff */\+/* sqr(t[0], t[0]); */              /*  336: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fe */\+/* sqr(t[0], t[0]); */              /*  337: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffc */\+/* sqr(t[0], t[0]); */              /*  338: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ff8 */\+/* sqr(t[0], t[0]); */              /*  339: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabff0 */\+/* sqr(t[0], t[0]); */              /*  340: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fe0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  341: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fff */\+/* sqr(t[0], t[0]); */              /*  342: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aafffe */\+/* sqr(t[0], t[0]); */              /*  343: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55fffc */\+/* sqr(t[0], t[0]); */              /*  344: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfff8 */\+/* sqr(t[0], t[0]); */              /*  345: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fff0 */\+sqr_n_mul(t[0], t[0], 4, t[3]);     /*  346: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd */\+/* sqr(t[0], t[0]); */              /*  347: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffa */\+/* sqr(t[0], t[0]); */              /*  348: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff4 */\+/* sqr(t[0], t[0]); */              /*  349: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffe8 */\+sqr_n_mul(t[0], t[0], 3, t[8]);     /*  350: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb */\+/* sqr(t[0], t[0]); */              /*  351: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd6 */\+/* sqr(t[0], t[0]); */              /*  352: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac */\+/* sqr(t[0], t[0]); */              /*  353: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58 */\+/* sqr(t[0], t[0]); */              /*  354: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb0 */\+/* sqr(t[0], t[0]); */              /*  355: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd60 */\+/* sqr(t[0], t[0]); */              /*  356: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac0 */\+/* sqr(t[0], t[0]); */              /*  357: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff580 */\+/* sqr(t[0], t[0]); */              /*  358: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb00 */\+sqr_n_mul(t[0], t[0], 8, t[2]);     /*  359: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb15 */\+/* sqr(t[0], t[0]); */              /*  360: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a */\+/* sqr(t[0], t[0]); */              /*  361: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54 */\+/* sqr(t[0], t[0]); */              /*  362: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a8 */\+/* sqr(t[0], t[0]); */              /*  363: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb150 */\+/* sqr(t[0], t[0]); */              /*  364: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a0 */\+/* sqr(t[0], t[0]); */              /*  365: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac540 */\+/* sqr(t[0], t[0]); */              /*  366: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a80 */\+sqr_n_mul(t[0], t[0], 7, t[4]);     /*  367: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9f */\+/* sqr(t[0], t[0]); */              /*  368: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153e */\+/* sqr(t[0], t[0]); */              /*  369: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7c */\+/* sqr(t[0], t[0]); */              /*  370: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54f8 */\+/* sqr(t[0], t[0]); */              /*  371: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9f0 */\+/* sqr(t[0], t[0]); */              /*  372: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153e0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  373: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ff */\+/* sqr(t[0], t[0]); */              /*  374: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7fe */\+/* sqr(t[0], t[0]); */              /*  375: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffc */\+/* sqr(t[0], t[0]); */              /*  376: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ff8 */\+/* sqr(t[0], t[0]); */              /*  377: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ff0 */\+/* sqr(t[0], t[0]); */              /*  378: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7fe0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  379: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7fff */\+/* sqr(t[0], t[0]); */              /*  380: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54fffe */\+/* sqr(t[0], t[0]); */              /*  381: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9fffc */\+/* sqr(t[0], t[0]); */              /*  382: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153fff8 */\+/* sqr(t[0], t[0]); */              /*  383: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7fff0 */\+sqr_n_mul(t[0], t[0], 4, t[7]);     /*  384: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff */\+/* sqr(t[0], t[0]); */              /*  385: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffe */\+/* sqr(t[0], t[0]); */              /*  386: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffc */\+/* sqr(t[0], t[0]); */              /*  387: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffff8 */\+/* sqr(t[0], t[0]); */              /*  388: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff0 */\+sqr_n_mul(t[0], t[0], 4, t[6]);     /*  389: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff7 */\+/* sqr(t[0], t[0]); */              /*  390: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee */\+/* sqr(t[0], t[0]); */              /*  391: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdc */\+/* sqr(t[0], t[0]); */              /*  392: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb8 */\+/* sqr(t[0], t[0]); */              /*  393: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff70 */\+/* sqr(t[0], t[0]); */              /*  394: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee0 */\+/* sqr(t[0], t[0]); */              /*  395: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdc0 */\+/* sqr(t[0], t[0]); */              /*  396: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb80 */\+sqr_n_mul(t[0], t[0], 7, t[4]);     /*  397: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9f */\+/* sqr(t[0], t[0]); */              /*  398: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73e */\+/* sqr(t[0], t[0]); */              /*  399: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7c */\+/* sqr(t[0], t[0]); */              /*  400: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcf8 */\+/* sqr(t[0], t[0]); */              /*  401: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9f0 */\+/* sqr(t[0], t[0]); */              /*  402: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73e0 */\+sqr_n_mul(t[0], t[0], 5, t[5]);     /*  403: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fd */\+/* sqr(t[0], t[0]); */              /*  404: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fa */\+/* sqr(t[0], t[0]); */              /*  405: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff4 */\+/* sqr(t[0], t[0]); */              /*  406: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9fe8 */\+/* sqr(t[0], t[0]); */              /*  407: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fd0 */\+/* sqr(t[0], t[0]); */              /*  408: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fa0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  409: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbf */\+/* sqr(t[0], t[0]); */              /*  410: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7e */\+/* sqr(t[0], t[0]); */              /*  411: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9fefc */\+/* sqr(t[0], t[0]); */              /*  412: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdf8 */\+/* sqr(t[0], t[0]); */              /*  413: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbf0 */\+/* sqr(t[0], t[0]); */              /*  414: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7e0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  415: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7ff */\+/* sqr(t[0], t[0]); */              /*  416: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffe */\+/* sqr(t[0], t[0]); */              /*  417: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffc */\+/* sqr(t[0], t[0]); */              /*  418: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbff8 */\+/* sqr(t[0], t[0]); */              /*  419: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7ff0 */\+/* sqr(t[0], t[0]); */              /*  420: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffe0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  421: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffff */\+/* sqr(t[0], t[0]); */              /*  422: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffe */\+/* sqr(t[0], t[0]); */              /*  423: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffc */\+/* sqr(t[0], t[0]); */              /*  424: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fff8 */\+/* sqr(t[0], t[0]); */              /*  425: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffff0 */\+/* sqr(t[0], t[0]); */              /*  426: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffe0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  427: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffff */\+/* sqr(t[0], t[0]); */              /*  428: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbffffe */\+/* sqr(t[0], t[0]); */              /*  429: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7ffffc */\+/* sqr(t[0], t[0]); */              /*  430: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9fefffff8 */\+/* sqr(t[0], t[0]); */              /*  431: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffff0 */\+/* sqr(t[0], t[0]); */              /*  432: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbffffe0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  433: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbffffff */\+/* sqr(t[0], t[0]); */              /*  434: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffe */\+/* sqr(t[0], t[0]); */              /*  435: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffc */\+/* sqr(t[0], t[0]); */              /*  436: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffff8 */\+/* sqr(t[0], t[0]); */              /*  437: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbffffff0 */\+/* sqr(t[0], t[0]); */              /*  438: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffe0 */\+sqr_n_mul(t[0], t[0], 5, t[4]);     /*  439: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffff */\+/* sqr(t[0], t[0]); */              /*  440: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9fefffffffe */\+/* sqr(t[0], t[0]); */              /*  441: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdfffffffc */\+/* sqr(t[0], t[0]); */              /*  442: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffffff8 */\+/* sqr(t[0], t[0]); */              /*  443: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffff0 */\+sqr_n_mul(t[0], t[0], 4, t[3]);     /*  444: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffffd */\+/* sqr(t[0], t[0]); */              /*  445: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa */\+/* sqr(t[0], t[0]); */              /*  446: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff4 */\+/* sqr(t[0], t[0]); */              /*  447: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffffffe8 */\+/* sqr(t[0], t[0]); */              /*  448: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffffd0 */\+/* sqr(t[0], t[0]); */              /*  449: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa0 */\+/* sqr(t[0], t[0]); */              /*  450: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff40 */\+sqr_n_mul(t[0], t[0], 6, t[2]);     /*  451: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff55 */\+/* sqr(t[0], t[0]); */              /*  452: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffffffeaa */\+/* sqr(t[0], t[0]); */              /*  453: d0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffffd54 */\+/* sqr(t[0], t[0]); */              /*  454: 1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa8 */\+/* sqr(t[0], t[0]); */              /*  455: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff550 */\+sqr_n_mul(t[0], t[0], 4, t[1]);     /*  456: 340223d472ffcd3496374f6c869759aec8ee9709e70a257ece61a541ed61ec483d57fffd62a7ffff73fdffffffff555 */\+sqr(out, t[0]);                     /*  457: 680447a8e5ff9a692c6e9ed90d2eb35d91dd2e13ce144afd9cc34a83dac3d8907aaffffac54ffffee7fbfffffffeaaa */\+} while(0)
+ vendor/external/blst/src/sqrt.c view
@@ -0,0 +1,261 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "fields.h"++#ifdef __OPTIMIZE_SIZE__+static void recip_sqrt_fp_3mod4(vec384 out, const vec384 inp)+{+    static const byte BLS_12_381_P_minus_3_div_4[] = {+        TO_BYTES(0xee7fbfffffffeaaa), TO_BYTES(0x07aaffffac54ffff),+        TO_BYTES(0xd9cc34a83dac3d89), TO_BYTES(0xd91dd2e13ce144af),+        TO_BYTES(0x92c6e9ed90d2eb35), TO_BYTES(0x0680447a8e5ff9a6)+    };++    exp_mont_384(out, inp, BLS_12_381_P_minus_3_div_4, 379, BLS12_381_P, p0);+}+#else+# if 1+/*+ * "383"-bit variant omits full reductions at the ends of squarings,+ * which results in up to ~15% improvement. [One can improve further+ * by omitting full reductions even after multiplications and+ * performing final reduction at the very end of the chain.]+ */+static inline void sqr_n_mul_fp(vec384 out, const vec384 a, size_t count,+                                const vec384 b)+{   sqr_n_mul_mont_383(out, a, count, BLS12_381_P, p0, b);   }+# else+static void sqr_n_mul_fp(vec384 out, const vec384 a, size_t count,+                         const vec384 b)+{+    while(count--) {+        sqr_fp(out, a);+        a = out;+    }+    mul_fp(out, out, b);+}+# endif++# define sqr(ret,a)		sqr_fp(ret,a)+# define mul(ret,a,b)		mul_fp(ret,a,b)+# define sqr_n_mul(ret,a,n,b)	sqr_n_mul_fp(ret,a,n,b)++# include "sqrt-addchain.h"+static void recip_sqrt_fp_3mod4(vec384 out, const vec384 inp)+{+    RECIP_SQRT_MOD_BLS12_381_P(out, inp, vec384);+}+# undef RECIP_SQRT_MOD_BLS12_381_P++# undef sqr_n_mul+# undef sqr+# undef mul+#endif++static bool_t recip_sqrt_fp(vec384 out, const vec384 inp)+{+    vec384 t0, t1;+    bool_t ret;++    recip_sqrt_fp_3mod4(t0, inp);++    mul_fp(t1, t0, inp);+    sqr_fp(t1, t1);+    ret = vec_is_equal(t1, inp, sizeof(t1));+    vec_copy(out, t0, sizeof(t0));++    return ret;+}++static bool_t sqrt_fp(vec384 out, const vec384 inp)+{+    vec384 t0, t1;+    bool_t ret;++    recip_sqrt_fp_3mod4(t0, inp);++    mul_fp(t0, t0, inp);+    sqr_fp(t1, t0);+    ret = vec_is_equal(t1, inp, sizeof(t1));+    vec_copy(out, t0, sizeof(t0));++    return ret;+}++int blst_fp_sqrt(vec384 out, const vec384 inp)+{   return (int)sqrt_fp(out, inp);   }++int blst_fp_is_square(const vec384 inp)+{+    return (int)ct_is_square_mod_384(inp, BLS12_381_P);+}++static bool_t sqrt_align_fp2(vec384x out, const vec384x ret,+                             const vec384x sqrt, const vec384x inp)+{+    static const vec384x sqrt_minus_1 = { { 0 }, { ONE_MONT_P } };+    static const vec384x sqrt_sqrt_minus_1 = {+      /*+       * "magic" number is ±2^((p-3)/4)%p, which is "1/sqrt(2)",+       * in quotes because 2*"1/sqrt(2)"^2 == -1 mod p, not 1,+       * but it pivots into "complex" plane nevertheless...+       */+      { TO_LIMB_T(0x3e2f585da55c9ad1), TO_LIMB_T(0x4294213d86c18183),+        TO_LIMB_T(0x382844c88b623732), TO_LIMB_T(0x92ad2afd19103e18),+        TO_LIMB_T(0x1d794e4fac7cf0b9), TO_LIMB_T(0x0bd592fc7d825ec8) },+      { TO_LIMB_T(0x7bcfa7a25aa30fda), TO_LIMB_T(0xdc17dec12a927e7c),+        TO_LIMB_T(0x2f088dd86b4ebef1), TO_LIMB_T(0xd1ca2087da74d4a7),+        TO_LIMB_T(0x2da2596696cebc1d), TO_LIMB_T(0x0e2b7eedbbfd87d2) }+    };+    static const vec384x sqrt_minus_sqrt_minus_1 = {+      { TO_LIMB_T(0x7bcfa7a25aa30fda), TO_LIMB_T(0xdc17dec12a927e7c),+        TO_LIMB_T(0x2f088dd86b4ebef1), TO_LIMB_T(0xd1ca2087da74d4a7),+        TO_LIMB_T(0x2da2596696cebc1d), TO_LIMB_T(0x0e2b7eedbbfd87d2) },+      { TO_LIMB_T(0x7bcfa7a25aa30fda), TO_LIMB_T(0xdc17dec12a927e7c),+        TO_LIMB_T(0x2f088dd86b4ebef1), TO_LIMB_T(0xd1ca2087da74d4a7),+        TO_LIMB_T(0x2da2596696cebc1d), TO_LIMB_T(0x0e2b7eedbbfd87d2) }+    };+    vec384x coeff, t0, t1;+    bool_t is_sqrt, flag;++    /*+     * Instead of multiple trial squarings we can perform just one+     * and see if the result is "rotated by multiple of 90°" in+     * relation to |inp|, and "rotate" |ret| accordingly.+     */+    sqr_fp2(t0, sqrt);+    /* "sqrt(|inp|)"^2 = (a + b*i)^2 = (a^2-b^2) + 2ab*i */++    /* (a^2-b^2) + 2ab*i == |inp| ? |ret| is spot on */+    sub_fp2(t1, t0, inp);+    is_sqrt = vec_is_zero(t1, sizeof(t1));+    vec_copy(coeff, BLS12_381_Rx.p2, sizeof(coeff));++    /* -(a^2-b^2) - 2ab*i == |inp| ? "rotate |ret| by 90°" */+    add_fp2(t1, t0, inp);+    vec_select(coeff, sqrt_minus_1, coeff, sizeof(coeff),+               flag = vec_is_zero(t1, sizeof(t1)));+    is_sqrt |= flag;++    /* 2ab - (a^2-b^2)*i == |inp| ? "rotate |ret| by 135°" */+    sub_fp(t1[0], t0[0], inp[1]);+    add_fp(t1[1], t0[1], inp[0]);+    vec_select(coeff, sqrt_sqrt_minus_1, coeff, sizeof(coeff),+               flag = vec_is_zero(t1, sizeof(t1)));+    is_sqrt |= flag;++    /* -2ab + (a^2-b^2)*i == |inp| ? "rotate |ret| by 45°" */+    add_fp(t1[0], t0[0], inp[1]);+    sub_fp(t1[1], t0[1], inp[0]);+    vec_select(coeff, sqrt_minus_sqrt_minus_1, coeff, sizeof(coeff),+               flag = vec_is_zero(t1, sizeof(t1)));+    is_sqrt |= flag;++    /* actual "rotation" */+    mul_fp2(out, ret, coeff);++    return is_sqrt;+}++/*+ * |inp| = a + b*i+ */+static bool_t recip_sqrt_fp2(vec384x out, const vec384x inp,+                                          const vec384x recip_ZZZ,+                                          const vec384x magic_ZZZ)+{+    vec384 aa, bb, cc;+    vec384x inp_;+    bool_t is_sqrt;++    sqr_fp(aa, inp[0]);+    sqr_fp(bb, inp[1]);+    add_fp(aa, aa, bb);++    is_sqrt = recip_sqrt_fp(cc, aa);  /* 1/sqrt(a²+b²)                    */++    /* if |inp| doesn't have quadratic residue, multiply by "1/Z³" ...    */+    mul_fp2(inp_, inp, recip_ZZZ);+    /* ... and adjust |aa| and |cc| accordingly                           */+    {+        vec384 za, zc;++        mul_fp(za, aa, magic_ZZZ[0]); /* aa*(za² + zb²)                   */+        mul_fp(zc, cc, magic_ZZZ[1]); /* cc*(za² + zb²)^((p-3)/4)         */+        vec_select(aa, aa, za, sizeof(aa), is_sqrt);+        vec_select(cc, cc, zc, sizeof(cc), is_sqrt);+    }+    vec_select(inp_, inp, inp_, sizeof(inp_), is_sqrt);++    mul_fp(aa, aa, cc);               /* sqrt(a²+b²)                      */++    sub_fp(bb, inp_[0], aa);+    add_fp(aa, inp_[0], aa);+    vec_select(aa, bb, aa, sizeof(aa), vec_is_zero(aa, sizeof(aa)));+    div_by_2_fp(aa, aa);              /* (a ± sqrt(a²+b²))/2              */++    /* if it says "no sqrt," final "align" will find right one...         */+    (void)recip_sqrt_fp(out[0], aa);  /* 1/sqrt((a ± sqrt(a²+b²))/2)      */++    div_by_2_fp(out[1], inp_[1]);+    mul_fp(out[1], out[1], out[0]);   /* b/(2*sqrt((a ± sqrt(a²+b²))/2))  */+    mul_fp(out[0], out[0], aa);       /* sqrt((a ± sqrt(a²+b²))/2)        */++    /* bound to succeed                                                   */+    (void)sqrt_align_fp2(out, out, out, inp_);++    mul_fp(out[0], out[0], cc);       /* inverse the result               */+    mul_fp(out[1], out[1], cc);+    neg_fp(out[1], out[1]);++    return is_sqrt;+}++static bool_t sqrt_fp2(vec384x out, const vec384x inp)+{+    vec384x ret;+    vec384 aa, bb;++    sqr_fp(aa, inp[0]);+    sqr_fp(bb, inp[1]);+    add_fp(aa, aa, bb);++    /* don't pay attention to return value, final "align" will tell...    */+    (void)sqrt_fp(aa, aa);            /* sqrt(a²+b²)                      */++    sub_fp(bb, inp[0], aa);+    add_fp(aa, inp[0], aa);+    vec_select(aa, bb, aa, sizeof(aa), vec_is_zero(aa, sizeof(aa)));+    div_by_2_fp(aa, aa);              /* (a ± sqrt(a²+b²))/2              */++    /* if it says "no sqrt," final "align" will find right one...         */+    (void)recip_sqrt_fp(ret[0], aa);  /* 1/sqrt((a ± sqrt(a²+b²))/2)      */++    div_by_2_fp(ret[1], inp[1]);+    mul_fp(ret[1], ret[1], ret[0]);   /* b/(2*sqrt((a ± sqrt(a²+b²))/2))  */+    mul_fp(ret[0], ret[0], aa);       /* sqrt((a ± sqrt(a²+b²))/2)        */++    /*+     * Now see if |ret| is or can be made sqrt(|inp|)...+     */++    return sqrt_align_fp2(out, ret, ret, inp);+}++int blst_fp2_sqrt(vec384x out, const vec384x inp)+{   return (int)sqrt_fp2(out, inp);   }++int blst_fp2_is_square(const vec384x inp)+{+    vec384 aa, bb;++    sqr_fp(aa, inp[0]);+    sqr_fp(bb, inp[1]);+    add_fp(aa, aa, bb);++    return (int)ct_is_square_mod_384(aa, BLS12_381_P);+}
+ vendor/external/blst/src/vect.c view
@@ -0,0 +1,176 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */++#include "vect.h"++#ifdef __BLST_NO_ASM__+# include "no_asm.h"+#endif++/*+ * Following are some reference C implementations to assist new+ * assembly modules development, as starting-point stand-ins and for+ * cross-checking. In order to "polyfil" specific subroutine redefine+ * it on compiler command line, e.g. -Dmul_mont_384x=_mul_mont_384x.+ */++#ifdef lshift_mod_384+inline void lshift_mod_384(vec384 ret, const vec384 a, size_t n,+                           const vec384 mod)+{+    while(n--)+        add_mod_384(ret, a, a, mod), a = ret;+}+#endif++#ifdef mul_by_8_mod_384+inline void mul_by_8_mod_384(vec384 ret, const vec384 a, const vec384 mod)+{   lshift_mod_384(ret, a, 3, mod);   }+#endif++#ifdef mul_by_3_mod_384+inline void mul_by_3_mod_384(vec384 ret, const vec384 a, const vec384 mod)+{+    vec384 t;++    add_mod_384(t, a, a, mod);+    add_mod_384(ret, t, a, mod);+}+#endif++#ifdef mul_by_3_mod_384x+inline void mul_by_3_mod_384x(vec384x ret, const vec384x a, const vec384 mod)+{+    mul_by_3_mod_384(ret[0], a[0], mod);+    mul_by_3_mod_384(ret[1], a[1], mod);+}+#endif++#ifdef mul_by_8_mod_384x+inline void mul_by_8_mod_384x(vec384x ret, const vec384x a, const vec384 mod)+{+    mul_by_8_mod_384(ret[0], a[0], mod);+    mul_by_8_mod_384(ret[1], a[1], mod);+}+#endif++#ifdef mul_by_1_plus_i_mod_384x+inline void mul_by_1_plus_i_mod_384x(vec384x ret, const vec384x a,+                                     const vec384 mod)+{+    vec384 t;++    add_mod_384(t, a[0], a[1], mod);+    sub_mod_384(ret[0], a[0], a[1], mod);+    vec_copy(ret[1], t, sizeof(t));+}+#endif++#ifdef add_mod_384x+inline void add_mod_384x(vec384x ret, const vec384x a, const vec384x b,+                         const vec384 mod)+{+    add_mod_384(ret[0], a[0], b[0], mod);+    add_mod_384(ret[1], a[1], b[1], mod);+}+#endif++#ifdef sub_mod_384x+inline void sub_mod_384x(vec384x ret, const vec384x a, const vec384x b,+                         const vec384 mod)+{+    sub_mod_384(ret[0], a[0], b[0], mod);+    sub_mod_384(ret[1], a[1], b[1], mod);+}+#endif++#ifdef lshift_mod_384x+inline void lshift_mod_384x(vec384x ret, const vec384x a, size_t n,+                            const vec384 mod)+{+    lshift_mod_384(ret[0], a[0], n, mod);+    lshift_mod_384(ret[1], a[1], n, mod);+}+#endif++#if defined(mul_mont_384x) && !(defined(__ADX__) && !defined(__BLST_PORTABLE__))+void mul_mont_384x(vec384x ret, const vec384x a, const vec384x b,+                   const vec384 mod, limb_t n0)+{+    vec768 t0, t1, t2;+    vec384 aa, bb;++    mul_384(t0, a[0], b[0]);+    mul_384(t1, a[1], b[1]);++    add_mod_384(aa, a[0], a[1], mod);+    add_mod_384(bb, b[0], b[1], mod);+    mul_384(t2, aa, bb);+    sub_mod_384x384(t2, t2, t0, mod);+    sub_mod_384x384(t2, t2, t1, mod);++    sub_mod_384x384(t0, t0, t1, mod);++    redc_mont_384(ret[0], t0, mod, n0);+    redc_mont_384(ret[1], t2, mod, n0);+}+#endif++#if defined(sqr_mont_384x) && !(defined(__ADX__) && !defined(__BLST_PORTABLE__))+void sqr_mont_384x(vec384x ret, const vec384x a, const vec384 mod, limb_t n0)+{+    vec384 t0, t1;++    add_mod_384(t0, a[0], a[1], mod);+    sub_mod_384(t1, a[0], a[1], mod);++    mul_mont_384(ret[1], a[0], a[1], mod, n0);+    add_mod_384(ret[1], ret[1], ret[1], mod);++    mul_mont_384(ret[0], t0, t1, mod, n0);+}+#endif++limb_t div_3_limbs(const limb_t dividend_top[2], limb_t d_lo, limb_t d_hi);+limb_t quot_rem_128(limb_t *quot_rem, const limb_t *divisor, limb_t quotient);+limb_t quot_rem_64(limb_t *quot_rem, const limb_t *divisor, limb_t quotient);++/*+ * Divide 255-bit |val| by z^2 yielding 128-bit quotient and remainder in place.+ */+static void div_by_zz(limb_t val[])+{+    static const limb_t zz[] = { TO_LIMB_T(0x0000000100000000),+                                 TO_LIMB_T(0xac45a4010001a402) };+    size_t loop, zz_len = sizeof(zz)/sizeof(zz[0]);+    limb_t d_lo, d_hi;++    d_lo = zz[zz_len - 2];+    d_hi = zz[zz_len - 1];+    for (loop = zz_len, zz_len--; loop--;) {+        limb_t q = div_3_limbs(val + loop + zz_len, d_lo, d_hi);+        (void)quot_rem_128(val + loop, zz, q);+    }+    /* remainder is in low half of val[], quotient is in high */+}++/*+ * Divide 128-bit |val| by z yielding 64-bit quotient and remainder in place.+ */+static void div_by_z(limb_t val[])+{+    static const limb_t z[] = { TO_LIMB_T(0xd201000000010000) };+    size_t loop, z_len = sizeof(z)/sizeof(z[0]);+    limb_t d_lo, d_hi;++    d_lo = (sizeof(z) == sizeof(limb_t)) ? 0 : z[z_len - 2];+    d_hi = z[z_len - 1];+    for (loop = z_len, z_len--; loop--;) {+        limb_t q = div_3_limbs(val + loop + z_len, d_lo, d_hi);+        (void)quot_rem_64(val + loop, z, q);+    }+    /* remainder is in low half of val[], quotient is in high */+}
+ vendor/external/blst/src/vect.h view
@@ -0,0 +1,438 @@+/*+ * Copyright Supranational LLC+ * Licensed under the Apache License, Version 2.0, see LICENSE for details.+ * SPDX-License-Identifier: Apache-2.0+ */+#ifndef __BLS12_381_ASM_VECT_H__+#define __BLS12_381_ASM_VECT_H__++#include <stddef.h>++#if defined(__BLST_NO_ASM__) || defined(__wasm64__)+/* cardano-c: portable no-assembly build. Use 32-bit limbs with a 64-bit+ * double-limb (the reference C path in no_asm.h), which compiles on every+ * target including WASM and the armv6/armv7 cross builds. This branch is+ * tested first so that forcing __BLST_NO_ASM__ on x86_64/aarch64 selects the+ * portable C path instead of the (intentionally absent) assembly modules. */+typedef unsigned int limb_t;+# define LIMB_T_BITS    32+# ifndef __BLST_NO_ASM__+#  define __BLST_NO_ASM__+# endif++#elif defined(__x86_64__) || defined(__aarch64__)+/* These are available even in ILP32 flavours, but even then they are+ * capable of performing 64-bit operations as efficiently as in *P64. */+typedef unsigned long long limb_t;+# define LIMB_T_BITS    64++#elif defined(_WIN64)   /* Win64 is P64 */+typedef unsigned __int64 limb_t;+# define LIMB_T_BITS    64++#else                   /* 32 bits on 32-bit platforms, 64 - on 64-bit */+typedef unsigned long limb_t;+#  ifdef _LP64+#   define LIMB_T_BITS   64+#  else+#   define LIMB_T_BITS   32+#   define __BLST_NO_ASM__+#  endif+#endif++/*+ * Why isn't LIMB_T_BITS defined as 8*sizeof(limb_t)? Because pre-processor+ * knows nothing about sizeof(anything)...+ */+#if LIMB_T_BITS == 64+# define TO_LIMB_T(limb64)     limb64+#else+# define TO_LIMB_T(limb64)     (limb_t)limb64,(limb_t)(limb64>>32)+#endif++#define NLIMBS(bits)   (bits/LIMB_T_BITS)++typedef limb_t vec256[NLIMBS(256)];+typedef limb_t vec512[NLIMBS(512)];+typedef limb_t vec384[NLIMBS(384)];+typedef limb_t vec768[NLIMBS(768)];+typedef vec384 vec384x[2];      /* 0 is "real" part, 1 is "imaginary" */++typedef unsigned char byte;+#define TO_BYTES(limb64)    (byte)limb64,(byte)(limb64>>8),\+                            (byte)(limb64>>16),(byte)(limb64>>24),\+                            (byte)(limb64>>32),(byte)(limb64>>40),\+                            (byte)(limb64>>48),(byte)(limb64>>56)+typedef byte pow256[256/8];++/*+ * Internal Boolean type, Boolean by value, hence safe to cast to or+ * reinterpret as 'bool'.+ */+typedef limb_t bool_t;++/*+ * Assembly subroutines...+ */+#if defined(__ADX__) /* e.g. -march=broadwell */ && !defined(__BLST_PORTABLE__)\+                                                 && !defined(__BLST_NO_ASM__)+# define mul_mont_sparse_256 mulx_mont_sparse_256+# define sqr_mont_sparse_256 sqrx_mont_sparse_256+# define from_mont_256 fromx_mont_256+# define redc_mont_256 redcx_mont_256+# define mul_mont_384 mulx_mont_384+# define sqr_mont_384 sqrx_mont_384+# define sqr_n_mul_mont_384 sqrx_n_mul_mont_384+# define sqr_n_mul_mont_383 sqrx_n_mul_mont_383+# define mul_384 mulx_384+# define sqr_384 sqrx_384+# define redc_mont_384 redcx_mont_384+# define from_mont_384 fromx_mont_384+# define sgn0_pty_mont_384 sgn0x_pty_mont_384+# define sgn0_pty_mont_384x sgn0x_pty_mont_384x+# define ct_inverse_mod_383 ctx_inverse_mod_383+#elif defined(__BLST_NO_ASM__)+# define ct_inverse_mod_383 ct_inverse_mod_384+#endif++void mul_mont_sparse_256(vec256 ret, const vec256 a, const vec256 b,+                         const vec256 p, limb_t n0);+void sqr_mont_sparse_256(vec256 ret, const vec256 a, const vec256 p, limb_t n0);+void redc_mont_256(vec256 ret, const vec512 a, const vec256 p, limb_t n0);+void from_mont_256(vec256 ret, const vec256 a, const vec256 p, limb_t n0);++void add_mod_256(vec256 ret, const vec256 a, const vec256 b, const vec256 p);+void sub_mod_256(vec256 ret, const vec256 a, const vec256 b, const vec256 p);+void mul_by_3_mod_256(vec256 ret, const vec256 a, const vec256 p);+void cneg_mod_256(vec256 ret, const vec256 a, bool_t flag, const vec256 p);+void lshift_mod_256(vec256 ret, const vec256 a, size_t count, const vec256 p);+void rshift_mod_256(vec256 ret, const vec256 a, size_t count, const vec256 p);+bool_t eucl_inverse_mod_256(vec256 ret, const vec256 a, const vec256 p,+                            const vec256 one);+limb_t check_mod_256(const pow256 a, const vec256 p);+limb_t add_n_check_mod_256(pow256 ret, const pow256 a, const pow256 b,+                                       const vec256 p);+limb_t sub_n_check_mod_256(pow256 ret, const pow256 a, const pow256 b,+                                       const vec256 p);++void vec_prefetch(const void *ptr, size_t len);++void mul_mont_384(vec384 ret, const vec384 a, const vec384 b,+                  const vec384 p, limb_t n0);+void sqr_mont_384(vec384 ret, const vec384 a, const vec384 p, limb_t n0);+void sqr_n_mul_mont_384(vec384 ret, const vec384 a, size_t count,+                        const vec384 p, limb_t n0, const vec384 b);+void sqr_n_mul_mont_383(vec384 ret, const vec384 a, size_t count,+                        const vec384 p, limb_t n0, const vec384 b);++void mul_384(vec768 ret, const vec384 a, const vec384 b);+void sqr_384(vec768 ret, const vec384 a);+void redc_mont_384(vec384 ret, const vec768 a, const vec384 p, limb_t n0);+void from_mont_384(vec384 ret, const vec384 a, const vec384 p, limb_t n0);+limb_t sgn0_pty_mont_384(const vec384 a, const vec384 p, limb_t n0);+limb_t sgn0_pty_mont_384x(const vec384x a, const vec384 p, limb_t n0);+limb_t sgn0_pty_mod_384(const vec384 a, const vec384 p);+limb_t sgn0_pty_mod_384x(const vec384x a, const vec384 p);++void add_mod_384(vec384 ret, const vec384 a, const vec384 b, const vec384 p);+void sub_mod_384(vec384 ret, const vec384 a, const vec384 b, const vec384 p);+void mul_by_8_mod_384(vec384 ret, const vec384 a, const vec384 p);+void mul_by_3_mod_384(vec384 ret, const vec384 a, const vec384 p);+void cneg_mod_384(vec384 ret, const vec384 a, bool_t flag, const vec384 p);+void lshift_mod_384(vec384 ret, const vec384 a, size_t count, const vec384 p);+void rshift_mod_384(vec384 ret, const vec384 a, size_t count, const vec384 p);+void div_by_2_mod_384(vec384 ret, const vec384 a, const vec384 p);+void ct_inverse_mod_383(vec768 ret, const vec384 inp, const vec384 mod,+                                                      const vec384 modx);+void ct_inverse_mod_256(vec512 ret, const vec256 inp, const vec256 mod,+                                                      const vec256 modx);+bool_t ct_is_square_mod_384(const vec384 inp, const vec384 mod);++#if defined(__ADX__) /* e.g. -march=broadwell */ && !defined(__BLST_PORTABLE__)+# define mul_mont_384x mulx_mont_384x+# define sqr_mont_384x sqrx_mont_384x+# define sqr_mont_382x sqrx_mont_382x+# define mul_382x mulx_382x+# define sqr_382x sqrx_382x+#endif++void mul_mont_384x(vec384x ret, const vec384x a, const vec384x b,+                   const vec384 p, limb_t n0);+void sqr_mont_384x(vec384x ret, const vec384x a, const vec384 p, limb_t n0);+void sqr_mont_382x(vec384x ret, const vec384x a, const vec384 p, limb_t n0);+void mul_382x(vec768 ret[2], const vec384x a, const vec384x b, const vec384 p);+void sqr_382x(vec768 ret[2], const vec384x a, const vec384 p);++void add_mod_384x(vec384x ret, const vec384x a, const vec384x b,+                  const vec384 p);+void sub_mod_384x(vec384x ret, const vec384x a, const vec384x b,+                  const vec384 p);+void mul_by_8_mod_384x(vec384x ret, const vec384x a, const vec384 p);+void mul_by_3_mod_384x(vec384x ret, const vec384x a, const vec384 p);+void mul_by_1_plus_i_mod_384x(vec384x ret, const vec384x a, const vec384 p);+void add_mod_384x384(vec768 ret, const vec768 a, const vec768 b,+                     const vec384 p);+void sub_mod_384x384(vec768 ret, const vec768 a, const vec768 b,+                     const vec384 p);++/*+ * C subroutines+ */+static void exp_mont_384(vec384 out, const vec384 inp, const byte *pow,+                         size_t pow_bits, const vec384 p, limb_t n0);+static void exp_mont_384x(vec384x out, const vec384x inp, const byte *pow,+                          size_t pow_bits, const vec384 p, limb_t n0);+static void div_by_zz(limb_t val[]);+static void div_by_z(limb_t val[]);++#ifdef __UINTPTR_TYPE__+typedef __UINTPTR_TYPE__ uptr_t;+#else+typedef const void *uptr_t;+#endif++#if !defined(restrict)+# if !defined(__STDC_VERSION__) || __STDC_VERSION__<199901+#  if defined(__GNUC__) && __GNUC__>=2+#   define restrict __restrict__+#  elif defined(_MSC_VER)+#   define restrict __restrict+#  else+#   define restrict+#  endif+# endif+#endif++#if !defined(inline) && !defined(__cplusplus)+# if !defined(__STDC_VERSION__) || __STDC_VERSION__<199901+#  if defined(__GNUC__) && __GNUC__>=2+#   define inline __inline__+#  elif defined(_MSC_VER)+#   define inline __inline+#  else+#   define inline+#  endif+# endif+#endif++#if defined(__GNUC__) || defined(__clang__)+# define launder(var) __asm__ __volatile__("" : "+r"(var))+#else+# define launder(var)+#endif++static inline bool_t is_bit_set(const byte *v, size_t i)+{+    bool_t ret = (v[i/8] >> (i%8)) & 1;+    launder(ret);+    return ret;+}++static inline bool_t byte_is_zero(unsigned char c)+{+    limb_t ret = ((limb_t)(c) - 1) >> (LIMB_T_BITS - 1);+    launder(ret);+    return ret;+}++static inline bool_t bytes_are_zero(const unsigned char *a, size_t num)+{+    unsigned char acc;+    size_t i;++    for (acc = 0, i = 0; i < num; i++)+        acc |= a[i];++    return byte_is_zero(acc);+}++static inline void vec_cswap(void *restrict a, void *restrict b, size_t num,+                             bool_t cbit)+{+    limb_t ai, *ap = (limb_t *)a;+    limb_t bi, *bp = (limb_t *)b;+    limb_t xorm, mask;+    size_t i;++    launder(cbit);+    mask = (limb_t)0 - cbit;++    num /= sizeof(limb_t);++    for (i = 0; i < num; i++) {+        xorm = ((ai = ap[i]) ^ (bi = bp[i])) & mask;+        ap[i] = ai ^ xorm;+        bp[i] = bi ^ xorm;+    }+}++/* ret = bit ? a : b */+void vec_select_32(void *ret, const void *a, const void *b, bool_t sel_a);+void vec_select_48(void *ret, const void *a, const void *b, bool_t sel_a);+void vec_select_96(void *ret, const void *a, const void *b, bool_t sel_a);+void vec_select_144(void *ret, const void *a, const void *b, bool_t sel_a);+void vec_select_192(void *ret, const void *a, const void *b, bool_t sel_a);+void vec_select_288(void *ret, const void *a, const void *b, bool_t sel_a);+static inline void vec_select(void *ret, const void *a, const void *b,+                              size_t num, bool_t sel_a)+{+    launder(sel_a);+#ifndef __BLST_NO_ASM__+    if (num == 32)          vec_select_32(ret, a, b, sel_a);+    else if (num == 48)     vec_select_48(ret, a, b, sel_a);+    else if (num == 96)     vec_select_96(ret, a, b, sel_a);+    else if (num == 144)    vec_select_144(ret, a, b, sel_a);+    else if (num == 192)    vec_select_192(ret, a, b, sel_a);+    else if (num == 288)    vec_select_288(ret, a, b, sel_a);+#else+    if (0) ;+#endif+    else {+        limb_t bi;+        volatile limb_t *rp = (limb_t *)ret;+        const limb_t *ap = (const limb_t *)a;+        const limb_t *bp = (const limb_t *)b;+        limb_t xorm, mask = (limb_t)0 - sel_a;+        size_t i;++        num /= sizeof(limb_t);++        for (i = 0; i < num; i++) {+            xorm = (ap[i] ^ (bi = bp[i])) & mask;+            rp[i] = bi ^ xorm;+        }+    }+}++static inline bool_t is_zero(limb_t l)+{+    limb_t ret = (~l & (l - 1)) >> (LIMB_T_BITS - 1);+    launder(ret);+    return ret;+}++static inline bool_t vec_is_zero(const void *a, size_t num)+{+    const limb_t *ap = (const limb_t *)a;+    limb_t acc;+    size_t i;++#ifndef __BLST_NO_ASM__+    bool_t vec_is_zero_16x(const void *a, size_t num);+    if ((num & 15) == 0)+        return vec_is_zero_16x(a, num);+#endif++    num /= sizeof(limb_t);++    for (acc = 0, i = 0; i < num; i++)+        acc |= ap[i];++    return is_zero(acc);+}++static inline bool_t vec_is_equal(const void *a, const void *b, size_t num)+{+    const limb_t *ap = (const limb_t *)a;+    const limb_t *bp = (const limb_t *)b;+    limb_t acc;+    size_t i;++#ifndef __BLST_NO_ASM__+    bool_t vec_is_equal_16x(const void *a, const void *b, size_t num);+    if ((num & 15) == 0)+        return vec_is_equal_16x(a, b, num);+#endif++    num /= sizeof(limb_t);++    for (acc = 0, i = 0; i < num; i++)+        acc |= ap[i] ^ bp[i];++    return is_zero(acc);+}++static inline void cneg_mod_384x(vec384x ret, const vec384x a, bool_t flag,+                                 const vec384 p)+{+    cneg_mod_384(ret[0], a[0], flag, p);+    cneg_mod_384(ret[1], a[1], flag, p);+}++static inline void vec_copy(void *restrict ret, const void *a, size_t num)+{+    limb_t *rp = (limb_t *)ret;+    const limb_t *ap = (const limb_t *)a;+    size_t i;++    num /= sizeof(limb_t);++    for (i = 0; i < num; i++)+        rp[i] = ap[i];+}++static inline void vec_zero(void *ret, size_t num)+{+    volatile limb_t *rp = (volatile limb_t *)ret;+    size_t i;++    num /= sizeof(limb_t);++    for (i = 0; i < num; i++)+        rp[i] = 0;++#if defined(__GNUC__) || defined(__clang__)+    __asm__ __volatile__("" : : "r"(ret) : "memory");+#endif+}++static inline void vec_czero(void *ret, size_t num, bool_t cbit)+{+    limb_t *rp = (limb_t *)ret;+    size_t i;+    limb_t mask;++    launder(cbit);+    mask = (limb_t)0 - (cbit^1);++    num /= sizeof(limb_t);++    for (i = 0; i < num; i++)+        rp[i] &= mask;+}++/*+ * Some compilers get arguably overzealous(*) when passing pointer to+ * multi-dimensional array [such as vec384x] as 'const' argument.+ * General direction seems to be to legitimize such constification,+ * so it's argued that suppressing the warning is appropriate.+ *+ * (*)  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1923.htm+ */+#if defined(__INTEL_COMPILER)+# pragma warning(disable:167)+# pragma warning(disable:556)+#elif defined(__GNUC__) && !defined(__clang__)+# pragma GCC diagnostic ignored "-Wpedantic"+#elif defined(_MSC_VER)+# pragma warning(disable: 4127 4189)+#endif++#if !defined(__wasm__) && __STDC_HOSTED__-0 != 0+# include <stdlib.h>+#endif++#if defined(__GNUC__)+# ifndef alloca+#  define alloca(s) __builtin_alloca(s)+# endif+#elif defined(__sun)+# include <alloca.h>+#elif defined(_WIN32)+# include <malloc.h>+# ifndef alloca+#  define alloca(s) _alloca(s)+# endif+#endif++#endif /* __BLS12_381_ASM_VECT_H__ */
+ vendor/external/gmp/README view
@@ -0,0 +1,79 @@+Copyright 2011-2013, 2018 Free Software Foundation, Inc.++This file is part of the GNU MP Library.++The GNU MP Library is free software; you can redistribute it and/or modify+it under the terms of either:++  * the GNU Lesser General Public License as published by the Free+    Software Foundation; either version 3 of the License, or (at your+    option) any later version.++or++  * the GNU General Public License as published by the Free Software+    Foundation; either version 2 of the License, or (at your option) any+    later version.++or both in parallel, as here.++The GNU MP Library is distributed in the hope that it will be useful, but+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License+for more details.++You should have received copies of the GNU General Public License and the+GNU Lesser General Public License along with the GNU MP Library.  If not,+see https://www.gnu.org/licenses/.+++This is "mini-gmp", a small implementation of a subset of GMP's mpn,+mpz and mpq interfaces.++It is intended for applications which need arithmetic on numbers+larger than a machine word, but which don't need to handle very large+numbers very efficiently. Those applications can include a copy of+mini-gmp to get a GMP-compatible interface with small footprint. One+can also arrange for optional linking with the real GMP library, using+mini-gmp as a fallback when for some reason GMP is not available, or+not desired as a dependency.++The supported GMP subset of the mpn and mpz interfaces is declared in+mini-gmp.h, and implemented in mini-gmp.c. The implemented+functions are fully compatible with the corresponding GMP functions,+as specified in the GMP manual, with a few exceptions:++  mpz_export and mpz_import support only NAILS = 0.++  The REALLOC_FUNC and FREE_FUNC registered with+  mp_set_memory_functions does not get the correct size of the+  allocated block in the corresponding argument. mini-gmp always+  passes zero for these rarely used arguments.++  When mpz_get_str allocates the block, it can be longer than needed.++The performance target for mini-gmp is to be at most 10 times slower+than the real GMP library, for numbers of size up to a few hundred+bits. No asymptotically fast algorithms are included in mini-gmp, so+it will be many orders of magnitude slower than GMP for very large+numbers.++The supported GMP subset of the mpq layer is declared in mini-mpq.h,+and implemented in mini-mpq.c.++You should never "install" mini-gmp. Applications can either just+#include mini-gmp.c (but then, beware that it defines several macros+and functions outside of the advertised interface), and if needed+#include mini-mpq.c in a later line (order is important). Or compile+mini-gmp.c and mini-mpq.c as separate compilation units, and use the+declarations in mini-gmp.h and mini-mpq.h.++The tests subdirectory contains a testsuite. To use it, you need GMP+and GNU make. Just run make check in the tests directory. If the+hard-coded compiler settings are not right, you have to either edit the+Makefile or pass overriding values on the make command line (e.g.,+make CC=cc check).++The initial version of mini-gmp was put together by Niels Möller+<nisse@lysator.liu.se>, with a fair amount of copy-and-paste from the+GMP sources.
+ vendor/external/gmp/mini-gmp.c view
@@ -0,0 +1,4572 @@+/* mini-gmp, a minimalistic implementation of a GNU GMP subset.++   Contributed to the GNU project by Niels Möller++Copyright 1991-1997, 1999-2019 Free Software Foundation, Inc.++This file is part of the GNU MP Library.++The GNU MP Library is free software; you can redistribute it and/or modify+it under the terms of either:++  * the GNU Lesser General Public License as published by the Free+    Software Foundation; either version 3 of the License, or (at your+    option) any later version.++or++  * the GNU General Public License as published by the Free Software+    Foundation; either version 2 of the License, or (at your option) any+    later version.++or both in parallel, as here.++The GNU MP Library is distributed in the hope that it will be useful, but+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License+for more details.++You should have received copies of the GNU General Public License and the+GNU Lesser General Public License along with the GNU MP Library.  If not,+see https://www.gnu.org/licenses/.  */++/* NOTE: All functions in this file which are not declared in+   mini-gmp.h are internal, and are not intended to be compatible+   with GMP or with future versions of mini-gmp. */++/* Much of the material copied from GMP files, including: gmp-impl.h,+   longlong.h, mpn/generic/add_n.c, mpn/generic/addmul_1.c,+   mpn/generic/lshift.c, mpn/generic/mul_1.c,+   mpn/generic/mul_basecase.c, mpn/generic/rshift.c,+   mpn/generic/sbpi1_div_qr.c, mpn/generic/sub_n.c,+   mpn/generic/submul_1.c. */++#include <assert.h>+#include <ctype.h>+#include <limits.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++#include "mini-gmp.h"++#if !defined(MINI_GMP_DONT_USE_FLOAT_H)+#include <float.h>+#endif+++/* Macros */+#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)++#define GMP_LIMB_MAX ((mp_limb_t) ~ (mp_limb_t) 0)+#define GMP_LIMB_HIGHBIT ((mp_limb_t) 1 << (GMP_LIMB_BITS - 1))++#define GMP_HLIMB_BIT ((mp_limb_t) 1 << (GMP_LIMB_BITS / 2))+#define GMP_LLIMB_MASK (GMP_HLIMB_BIT - 1)++#define GMP_ULONG_BITS (sizeof(unsigned long) * CHAR_BIT)+#define GMP_ULONG_HIGHBIT ((unsigned long) 1 << (GMP_ULONG_BITS - 1))++#define GMP_ABS(x) ((x) >= 0 ? (x) : -(x))+#define GMP_NEG_CAST(T,x) (-((T)((x) + 1) - 1))++#define GMP_MIN(a, b) ((a) < (b) ? (a) : (b))+#define GMP_MAX(a, b) ((a) > (b) ? (a) : (b))++#define GMP_CMP(a,b) (((a) > (b)) - ((a) < (b)))++#if defined(DBL_MANT_DIG) && FLT_RADIX == 2+#define GMP_DBL_MANT_BITS DBL_MANT_DIG+#else+#define GMP_DBL_MANT_BITS (53)+#endif++/* Return non-zero if xp,xsize and yp,ysize overlap.+   If xp+xsize<=yp there's no overlap, or if yp+ysize<=xp there's no+   overlap.  If both these are false, there's an overlap. */+#define GMP_MPN_OVERLAP_P(xp, xsize, yp, ysize)				\+  ((xp) + (xsize) > (yp) && (yp) + (ysize) > (xp))++#define gmp_assert_nocarry(x) do { \+    mp_limb_t __cy = (x);	   \+    assert (__cy == 0);		   \+  } while (0)++#define gmp_clz(count, x) do {						\+    mp_limb_t __clz_x = (x);						\+    unsigned __clz_c = 0;						\+    int LOCAL_SHIFT_BITS = 8;						\+    if (GMP_LIMB_BITS > LOCAL_SHIFT_BITS)				\+      for (;								\+	   (__clz_x & ((mp_limb_t) 0xff << (GMP_LIMB_BITS - 8))) == 0;	\+	   __clz_c += 8)						\+	{ __clz_x <<= LOCAL_SHIFT_BITS;	}				\+    for (; (__clz_x & GMP_LIMB_HIGHBIT) == 0; __clz_c++)		\+      __clz_x <<= 1;							\+    (count) = __clz_c;							\+  } while (0)++#define gmp_ctz(count, x) do {						\+    mp_limb_t __ctz_x = (x);						\+    unsigned __ctz_c = 0;						\+    gmp_clz (__ctz_c, __ctz_x & - __ctz_x);				\+    (count) = GMP_LIMB_BITS - 1 - __ctz_c;				\+  } while (0)++#define gmp_add_ssaaaa(sh, sl, ah, al, bh, bl) \+  do {									\+    mp_limb_t __x;							\+    __x = (al) + (bl);							\+    (sh) = (ah) + (bh) + (__x < (al));					\+    (sl) = __x;								\+  } while (0)++#define gmp_sub_ddmmss(sh, sl, ah, al, bh, bl) \+  do {									\+    mp_limb_t __x;							\+    __x = (al) - (bl);							\+    (sh) = (ah) - (bh) - ((al) < (bl));					\+    (sl) = __x;								\+  } while (0)++#define gmp_umul_ppmm(w1, w0, u, v)					\+  do {									\+    int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;				\+    if (sizeof(unsigned int) * CHAR_BIT >= 2 * GMP_LIMB_BITS)		\+      {									\+	unsigned int __ww = (unsigned int) (u) * (v);			\+	w0 = (mp_limb_t) __ww;						\+	w1 = (mp_limb_t) (__ww >> LOCAL_GMP_LIMB_BITS);			\+      }									\+    else if (GMP_ULONG_BITS >= 2 * GMP_LIMB_BITS)			\+      {									\+	unsigned long int __ww = (unsigned long int) (u) * (v);		\+	w0 = (mp_limb_t) __ww;						\+	w1 = (mp_limb_t) (__ww >> LOCAL_GMP_LIMB_BITS);			\+      }									\+    else {								\+      mp_limb_t __x0, __x1, __x2, __x3;					\+      unsigned __ul, __vl, __uh, __vh;					\+      mp_limb_t __u = (u), __v = (v);					\+									\+      __ul = __u & GMP_LLIMB_MASK;					\+      __uh = __u >> (GMP_LIMB_BITS / 2);				\+      __vl = __v & GMP_LLIMB_MASK;					\+      __vh = __v >> (GMP_LIMB_BITS / 2);				\+									\+      __x0 = (mp_limb_t) __ul * __vl;					\+      __x1 = (mp_limb_t) __ul * __vh;					\+      __x2 = (mp_limb_t) __uh * __vl;					\+      __x3 = (mp_limb_t) __uh * __vh;					\+									\+      __x1 += __x0 >> (GMP_LIMB_BITS / 2);/* this can't give carry */	\+      __x1 += __x2;		/* but this indeed can */		\+      if (__x1 < __x2)		/* did we get it? */			\+	__x3 += GMP_HLIMB_BIT;	/* yes, add it in the proper pos. */	\+									\+      (w1) = __x3 + (__x1 >> (GMP_LIMB_BITS / 2));			\+      (w0) = (__x1 << (GMP_LIMB_BITS / 2)) + (__x0 & GMP_LLIMB_MASK);	\+    }									\+  } while (0)++#define gmp_udiv_qrnnd_preinv(q, r, nh, nl, d, di)			\+  do {									\+    mp_limb_t _qh, _ql, _r, _mask;					\+    gmp_umul_ppmm (_qh, _ql, (nh), (di));				\+    gmp_add_ssaaaa (_qh, _ql, _qh, _ql, (nh) + 1, (nl));		\+    _r = (nl) - _qh * (d);						\+    _mask = -(mp_limb_t) (_r > _ql); /* both > and >= are OK */		\+    _qh += _mask;							\+    _r += _mask & (d);							\+    if (_r >= (d))							\+      {									\+	_r -= (d);							\+	_qh++;								\+      }									\+									\+    (r) = _r;								\+    (q) = _qh;								\+  } while (0)++#define gmp_udiv_qr_3by2(q, r1, r0, n2, n1, n0, d1, d0, dinv)		\+  do {									\+    mp_limb_t _q0, _t1, _t0, _mask;					\+    gmp_umul_ppmm ((q), _q0, (n2), (dinv));				\+    gmp_add_ssaaaa ((q), _q0, (q), _q0, (n2), (n1));			\+									\+    /* Compute the two most significant limbs of n - q'd */		\+    (r1) = (n1) - (d1) * (q);						\+    gmp_sub_ddmmss ((r1), (r0), (r1), (n0), (d1), (d0));		\+    gmp_umul_ppmm (_t1, _t0, (d0), (q));				\+    gmp_sub_ddmmss ((r1), (r0), (r1), (r0), _t1, _t0);			\+    (q)++;								\+									\+    /* Conditionally adjust q and the remainders */			\+    _mask = - (mp_limb_t) ((r1) >= _q0);				\+    (q) += _mask;							\+    gmp_add_ssaaaa ((r1), (r0), (r1), (r0), _mask & (d1), _mask & (d0)); \+    if ((r1) >= (d1))							\+      {									\+	if ((r1) > (d1) || (r0) >= (d0))				\+	  {								\+	    (q)++;							\+	    gmp_sub_ddmmss ((r1), (r0), (r1), (r0), (d1), (d0));	\+	  }								\+      }									\+  } while (0)++/* Swap macros. */+#define MP_LIMB_T_SWAP(x, y)						\+  do {									\+    mp_limb_t __mp_limb_t_swap__tmp = (x);				\+    (x) = (y);								\+    (y) = __mp_limb_t_swap__tmp;					\+  } while (0)+#define MP_SIZE_T_SWAP(x, y)						\+  do {									\+    mp_size_t __mp_size_t_swap__tmp = (x);				\+    (x) = (y);								\+    (y) = __mp_size_t_swap__tmp;					\+  } while (0)+#define MP_BITCNT_T_SWAP(x,y)			\+  do {						\+    mp_bitcnt_t __mp_bitcnt_t_swap__tmp = (x);	\+    (x) = (y);					\+    (y) = __mp_bitcnt_t_swap__tmp;		\+  } while (0)+#define MP_PTR_SWAP(x, y)						\+  do {									\+    mp_ptr __mp_ptr_swap__tmp = (x);					\+    (x) = (y);								\+    (y) = __mp_ptr_swap__tmp;						\+  } while (0)+#define MP_SRCPTR_SWAP(x, y)						\+  do {									\+    mp_srcptr __mp_srcptr_swap__tmp = (x);				\+    (x) = (y);								\+    (y) = __mp_srcptr_swap__tmp;					\+  } while (0)++#define MPN_PTR_SWAP(xp,xs, yp,ys)					\+  do {									\+    MP_PTR_SWAP (xp, yp);						\+    MP_SIZE_T_SWAP (xs, ys);						\+  } while(0)+#define MPN_SRCPTR_SWAP(xp,xs, yp,ys)					\+  do {									\+    MP_SRCPTR_SWAP (xp, yp);						\+    MP_SIZE_T_SWAP (xs, ys);						\+  } while(0)++#define MPZ_PTR_SWAP(x, y)						\+  do {									\+    mpz_ptr __mpz_ptr_swap__tmp = (x);					\+    (x) = (y);								\+    (y) = __mpz_ptr_swap__tmp;						\+  } while (0)+#define MPZ_SRCPTR_SWAP(x, y)						\+  do {									\+    mpz_srcptr __mpz_srcptr_swap__tmp = (x);				\+    (x) = (y);								\+    (y) = __mpz_srcptr_swap__tmp;					\+  } while (0)++const int mp_bits_per_limb = GMP_LIMB_BITS;++/* Memory allocation and other helper functions. */+static void+gmp_die (const char *msg)+{+  fprintf (stderr, "%s\n", msg);+  abort();+}++static void *+gmp_default_alloc (size_t size)+{+  void *p;++  assert (size > 0);++  p = malloc (size);+  if (!p)+    gmp_die("gmp_default_alloc: Virtual memory exhausted.");++  return p;+}++static void *+gmp_default_realloc (void *old, size_t unused_old_size, size_t new_size)+{+  void * p;++  p = realloc (old, new_size);++  if (!p)+    gmp_die("gmp_default_realloc: Virtual memory exhausted.");++  return p;+}++static void+gmp_default_free (void *p, size_t unused_size)+{+  free (p);+}++static void * (*gmp_allocate_func) (size_t) = gmp_default_alloc;+static void * (*gmp_reallocate_func) (void *, size_t, size_t) = gmp_default_realloc;+static void (*gmp_free_func) (void *, size_t) = gmp_default_free;++void+mp_get_memory_functions (void *(**alloc_func) (size_t),+			 void *(**realloc_func) (void *, size_t, size_t),+			 void (**free_func) (void *, size_t))+{+  if (alloc_func)+    *alloc_func = gmp_allocate_func;++  if (realloc_func)+    *realloc_func = gmp_reallocate_func;++  if (free_func)+    *free_func = gmp_free_func;+}++void+mp_set_memory_functions (void *(*alloc_func) (size_t),+			 void *(*realloc_func) (void *, size_t, size_t),+			 void (*free_func) (void *, size_t))+{+  if (!alloc_func)+    alloc_func = gmp_default_alloc;+  if (!realloc_func)+    realloc_func = gmp_default_realloc;+  if (!free_func)+    free_func = gmp_default_free;++  gmp_allocate_func = alloc_func;+  gmp_reallocate_func = realloc_func;+  gmp_free_func = free_func;+}++#define gmp_xalloc(size) ((*gmp_allocate_func)((size)))+#define gmp_free(p) ((*gmp_free_func) ((p), 0))++static mp_ptr+gmp_xalloc_limbs (mp_size_t size)+{+  return (mp_ptr) gmp_xalloc (size * sizeof (mp_limb_t));+}++static mp_ptr+gmp_xrealloc_limbs (mp_ptr old, mp_size_t size)+{+  assert (size > 0);+  return (mp_ptr) (*gmp_reallocate_func) (old, 0, size * sizeof (mp_limb_t));+}+++/* MPN interface */++void+mpn_copyi (mp_ptr d, mp_srcptr s, mp_size_t n)+{+  mp_size_t i;+  for (i = 0; i < n; i++)+    d[i] = s[i];+}++void+mpn_copyd (mp_ptr d, mp_srcptr s, mp_size_t n)+{+  while (--n >= 0)+    d[n] = s[n];+}++int+mpn_cmp (mp_srcptr ap, mp_srcptr bp, mp_size_t n)+{+  while (--n >= 0)+    {+      if (ap[n] != bp[n])+	return ap[n] > bp[n] ? 1 : -1;+    }+  return 0;+}++static int+mpn_cmp4 (mp_srcptr ap, mp_size_t an, mp_srcptr bp, mp_size_t bn)+{+  if (an != bn)+    return an < bn ? -1 : 1;+  else+    return mpn_cmp (ap, bp, an);+}++static mp_size_t+mpn_normalized_size (mp_srcptr xp, mp_size_t n)+{+  while (n > 0 && xp[n-1] == 0)+    --n;+  return n;+}++int+mpn_zero_p(mp_srcptr rp, mp_size_t n)+{+  return mpn_normalized_size (rp, n) == 0;+}++void+mpn_zero (mp_ptr rp, mp_size_t n)+{+  while (--n >= 0)+    rp[n] = 0;+}++mp_limb_t+mpn_add_1 (mp_ptr rp, mp_srcptr ap, mp_size_t n, mp_limb_t b)+{+  mp_size_t i;++  assert (n > 0);+  i = 0;+  do+    {+      mp_limb_t r = ap[i] + b;+      /* Carry out */+      b = (r < b);+      rp[i] = r;+    }+  while (++i < n);++  return b;+}++mp_limb_t+mpn_add_n (mp_ptr rp, mp_srcptr ap, mp_srcptr bp, mp_size_t n)+{+  mp_size_t i;+  mp_limb_t cy;++  for (i = 0, cy = 0; i < n; i++)+    {+      mp_limb_t a, b, r;+      a = ap[i]; b = bp[i];+      r = a + cy;+      cy = (r < cy);+      r += b;+      cy += (r < b);+      rp[i] = r;+    }+  return cy;+}++mp_limb_t+mpn_add (mp_ptr rp, mp_srcptr ap, mp_size_t an, mp_srcptr bp, mp_size_t bn)+{+  mp_limb_t cy;++  assert (an >= bn);++  cy = mpn_add_n (rp, ap, bp, bn);+  if (an > bn)+    cy = mpn_add_1 (rp + bn, ap + bn, an - bn, cy);+  return cy;+}++mp_limb_t+mpn_sub_1 (mp_ptr rp, mp_srcptr ap, mp_size_t n, mp_limb_t b)+{+  mp_size_t i;++  assert (n > 0);++  i = 0;+  do+    {+      mp_limb_t a = ap[i];+      /* Carry out */+      mp_limb_t cy = a < b;+      rp[i] = a - b;+      b = cy;+    }+  while (++i < n);++  return b;+}++mp_limb_t+mpn_sub_n (mp_ptr rp, mp_srcptr ap, mp_srcptr bp, mp_size_t n)+{+  mp_size_t i;+  mp_limb_t cy;++  for (i = 0, cy = 0; i < n; i++)+    {+      mp_limb_t a, b;+      a = ap[i]; b = bp[i];+      b += cy;+      cy = (b < cy);+      cy += (a < b);+      rp[i] = a - b;+    }+  return cy;+}++mp_limb_t+mpn_sub (mp_ptr rp, mp_srcptr ap, mp_size_t an, mp_srcptr bp, mp_size_t bn)+{+  mp_limb_t cy;++  assert (an >= bn);++  cy = mpn_sub_n (rp, ap, bp, bn);+  if (an > bn)+    cy = mpn_sub_1 (rp + bn, ap + bn, an - bn, cy);+  return cy;+}++mp_limb_t+mpn_mul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)+{+  mp_limb_t ul, cl, hpl, lpl;++  assert (n >= 1);++  cl = 0;+  do+    {+      ul = *up++;+      gmp_umul_ppmm (hpl, lpl, ul, vl);++      lpl += cl;+      cl = (lpl < cl) + hpl;++      *rp++ = lpl;+    }+  while (--n != 0);++  return cl;+}++mp_limb_t+mpn_addmul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)+{+  mp_limb_t ul, cl, hpl, lpl, rl;++  assert (n >= 1);++  cl = 0;+  do+    {+      ul = *up++;+      gmp_umul_ppmm (hpl, lpl, ul, vl);++      lpl += cl;+      cl = (lpl < cl) + hpl;++      rl = *rp;+      lpl = rl + lpl;+      cl += lpl < rl;+      *rp++ = lpl;+    }+  while (--n != 0);++  return cl;+}++mp_limb_t+mpn_submul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)+{+  mp_limb_t ul, cl, hpl, lpl, rl;++  assert (n >= 1);++  cl = 0;+  do+    {+      ul = *up++;+      gmp_umul_ppmm (hpl, lpl, ul, vl);++      lpl += cl;+      cl = (lpl < cl) + hpl;++      rl = *rp;+      lpl = rl - lpl;+      cl += lpl > rl;+      *rp++ = lpl;+    }+  while (--n != 0);++  return cl;+}++mp_limb_t+mpn_mul (mp_ptr rp, mp_srcptr up, mp_size_t un, mp_srcptr vp, mp_size_t vn)+{+  assert (un >= vn);+  assert (vn >= 1);+  assert (!GMP_MPN_OVERLAP_P(rp, un + vn, up, un));+  assert (!GMP_MPN_OVERLAP_P(rp, un + vn, vp, vn));++  /* We first multiply by the low order limb. This result can be+     stored, not added, to rp. We also avoid a loop for zeroing this+     way. */++  rp[un] = mpn_mul_1 (rp, up, un, vp[0]);++  /* Now accumulate the product of up[] and the next higher limb from+     vp[]. */++  while (--vn >= 1)+    {+      rp += 1, vp += 1;+      rp[un] = mpn_addmul_1 (rp, up, un, vp[0]);+    }+  return rp[un];+}++void+mpn_mul_n (mp_ptr rp, mp_srcptr ap, mp_srcptr bp, mp_size_t n)+{+  mpn_mul (rp, ap, n, bp, n);+}++void+mpn_sqr (mp_ptr rp, mp_srcptr ap, mp_size_t n)+{+  mpn_mul (rp, ap, n, ap, n);+}++mp_limb_t+mpn_lshift (mp_ptr rp, mp_srcptr up, mp_size_t n, unsigned int cnt)+{+  mp_limb_t high_limb, low_limb;+  unsigned int tnc;+  mp_limb_t retval;++  assert (n >= 1);+  assert (cnt >= 1);+  assert (cnt < GMP_LIMB_BITS);++  up += n;+  rp += n;++  tnc = GMP_LIMB_BITS - cnt;+  low_limb = *--up;+  retval = low_limb >> tnc;+  high_limb = (low_limb << cnt);++  while (--n != 0)+    {+      low_limb = *--up;+      *--rp = high_limb | (low_limb >> tnc);+      high_limb = (low_limb << cnt);+    }+  *--rp = high_limb;++  return retval;+}++mp_limb_t+mpn_rshift (mp_ptr rp, mp_srcptr up, mp_size_t n, unsigned int cnt)+{+  mp_limb_t high_limb, low_limb;+  unsigned int tnc;+  mp_limb_t retval;++  assert (n >= 1);+  assert (cnt >= 1);+  assert (cnt < GMP_LIMB_BITS);++  tnc = GMP_LIMB_BITS - cnt;+  high_limb = *up++;+  retval = (high_limb << tnc);+  low_limb = high_limb >> cnt;++  while (--n != 0)+    {+      high_limb = *up++;+      *rp++ = low_limb | (high_limb << tnc);+      low_limb = high_limb >> cnt;+    }+  *rp = low_limb;++  return retval;+}++static mp_bitcnt_t+mpn_common_scan (mp_limb_t limb, mp_size_t i, mp_srcptr up, mp_size_t un,+		 mp_limb_t ux)+{+  unsigned cnt;++  assert (ux == 0 || ux == GMP_LIMB_MAX);+  assert (0 <= i && i <= un );++  while (limb == 0)+    {+      i++;+      if (i == un)+	return (ux == 0 ? ~(mp_bitcnt_t) 0 : un * GMP_LIMB_BITS);+      limb = ux ^ up[i];+    }+  gmp_ctz (cnt, limb);+  return (mp_bitcnt_t) i * GMP_LIMB_BITS + cnt;+}++mp_bitcnt_t+mpn_scan1 (mp_srcptr ptr, mp_bitcnt_t bit)+{+  mp_size_t i;+  i = bit / GMP_LIMB_BITS;++  return mpn_common_scan ( ptr[i] & (GMP_LIMB_MAX << (bit % GMP_LIMB_BITS)),+			  i, ptr, i, 0);+}++mp_bitcnt_t+mpn_scan0 (mp_srcptr ptr, mp_bitcnt_t bit)+{+  mp_size_t i;+  i = bit / GMP_LIMB_BITS;++  return mpn_common_scan (~ptr[i] & (GMP_LIMB_MAX << (bit % GMP_LIMB_BITS)),+			  i, ptr, i, GMP_LIMB_MAX);+}++void+mpn_com (mp_ptr rp, mp_srcptr up, mp_size_t n)+{+  while (--n >= 0)+    *rp++ = ~ *up++;+}++mp_limb_t+mpn_neg (mp_ptr rp, mp_srcptr up, mp_size_t n)+{+  while (*up == 0)+    {+      *rp = 0;+      if (!--n)+	return 0;+      ++up; ++rp;+    }+  *rp = - *up;+  mpn_com (++rp, ++up, --n);+  return 1;+}+++/* MPN division interface. */++/* The 3/2 inverse is defined as++     m = floor( (B^3-1) / (B u1 + u0)) - B+*/+mp_limb_t+mpn_invert_3by2 (mp_limb_t u1, mp_limb_t u0)+{+  mp_limb_t r, m;++  {+    mp_limb_t p, ql;+    unsigned ul, uh, qh;++    /* For notation, let b denote the half-limb base, so that B = b^2.+       Split u1 = b uh + ul. */+    ul = u1 & GMP_LLIMB_MASK;+    uh = u1 >> (GMP_LIMB_BITS / 2);++    /* Approximation of the high half of quotient. Differs from the 2/1+       inverse of the half limb uh, since we have already subtracted+       u0. */+    qh = (u1 ^ GMP_LIMB_MAX) / uh;++    /* Adjust to get a half-limb 3/2 inverse, i.e., we want++       qh' = floor( (b^3 - 1) / u) - b = floor ((b^3 - b u - 1) / u+	   = floor( (b (~u) + b-1) / u),++       and the remainder++       r = b (~u) + b-1 - qh (b uh + ul)+       = b (~u - qh uh) + b-1 - qh ul++       Subtraction of qh ul may underflow, which implies adjustments.+       But by normalization, 2 u >= B > qh ul, so we need to adjust by+       at most 2.+    */++    r = ((~u1 - (mp_limb_t) qh * uh) << (GMP_LIMB_BITS / 2)) | GMP_LLIMB_MASK;++    p = (mp_limb_t) qh * ul;+    /* Adjustment steps taken from udiv_qrnnd_c */+    if (r < p)+      {+	qh--;+	r += u1;+	if (r >= u1) /* i.e. we didn't get carry when adding to r */+	  if (r < p)+	    {+	      qh--;+	      r += u1;+	    }+      }+    r -= p;++    /* Low half of the quotient is++       ql = floor ( (b r + b-1) / u1).++       This is a 3/2 division (on half-limbs), for which qh is a+       suitable inverse. */++    p = (r >> (GMP_LIMB_BITS / 2)) * qh + r;+    /* Unlike full-limb 3/2, we can add 1 without overflow. For this to+       work, it is essential that ql is a full mp_limb_t. */+    ql = (p >> (GMP_LIMB_BITS / 2)) + 1;++    /* By the 3/2 trick, we don't need the high half limb. */+    r = (r << (GMP_LIMB_BITS / 2)) + GMP_LLIMB_MASK - ql * u1;++    if (r >= (GMP_LIMB_MAX & (p << (GMP_LIMB_BITS / 2))))+      {+	ql--;+	r += u1;+      }+    m = ((mp_limb_t) qh << (GMP_LIMB_BITS / 2)) + ql;+    if (r >= u1)+      {+	m++;+	r -= u1;+      }+  }++  /* Now m is the 2/1 inverse of u1. If u0 > 0, adjust it to become a+     3/2 inverse. */+  if (u0 > 0)+    {+      mp_limb_t th, tl;+      r = ~r;+      r += u0;+      if (r < u0)+	{+	  m--;+	  if (r >= u1)+	    {+	      m--;+	      r -= u1;+	    }+	  r -= u1;+	}+      gmp_umul_ppmm (th, tl, u0, m);+      r += th;+      if (r < th)+	{+	  m--;+	  m -= ((r > u1) | ((r == u1) & (tl > u0)));+	}+    }++  return m;+}++struct gmp_div_inverse+{+  /* Normalization shift count. */+  unsigned shift;+  /* Normalized divisor (d0 unused for mpn_div_qr_1) */+  mp_limb_t d1, d0;+  /* Inverse, for 2/1 or 3/2. */+  mp_limb_t di;+};++static void+mpn_div_qr_1_invert (struct gmp_div_inverse *inv, mp_limb_t d)+{+  unsigned shift;++  assert (d > 0);+  gmp_clz (shift, d);+  inv->shift = shift;+  inv->d1 = d << shift;+  inv->di = mpn_invert_limb (inv->d1);+}++static void+mpn_div_qr_2_invert (struct gmp_div_inverse *inv,+		     mp_limb_t d1, mp_limb_t d0)+{+  unsigned shift;++  assert (d1 > 0);+  gmp_clz (shift, d1);+  inv->shift = shift;+  if (shift > 0)+    {+      d1 = (d1 << shift) | (d0 >> (GMP_LIMB_BITS - shift));+      d0 <<= shift;+    }+  inv->d1 = d1;+  inv->d0 = d0;+  inv->di = mpn_invert_3by2 (d1, d0);+}++static void+mpn_div_qr_invert (struct gmp_div_inverse *inv,+		   mp_srcptr dp, mp_size_t dn)+{+  assert (dn > 0);++  if (dn == 1)+    mpn_div_qr_1_invert (inv, dp[0]);+  else if (dn == 2)+    mpn_div_qr_2_invert (inv, dp[1], dp[0]);+  else+    {+      unsigned shift;+      mp_limb_t d1, d0;++      d1 = dp[dn-1];+      d0 = dp[dn-2];+      assert (d1 > 0);+      gmp_clz (shift, d1);+      inv->shift = shift;+      if (shift > 0)+	{+	  d1 = (d1 << shift) | (d0 >> (GMP_LIMB_BITS - shift));+	  d0 = (d0 << shift) | (dp[dn-3] >> (GMP_LIMB_BITS - shift));+	}+      inv->d1 = d1;+      inv->d0 = d0;+      inv->di = mpn_invert_3by2 (d1, d0);+    }+}++/* Not matching current public gmp interface, rather corresponding to+   the sbpi1_div_* functions. */+static mp_limb_t+mpn_div_qr_1_preinv (mp_ptr qp, mp_srcptr np, mp_size_t nn,+		     const struct gmp_div_inverse *inv)+{+  mp_limb_t d, di;+  mp_limb_t r;+  mp_ptr tp = NULL;++  if (inv->shift > 0)+    {+      /* Shift, reusing qp area if possible. In-place shift if qp == np. */+      tp = qp ? qp : gmp_xalloc_limbs (nn);+      r = mpn_lshift (tp, np, nn, inv->shift);+      np = tp;+    }+  else+    r = 0;++  d = inv->d1;+  di = inv->di;+  while (--nn >= 0)+    {+      mp_limb_t q;++      gmp_udiv_qrnnd_preinv (q, r, r, np[nn], d, di);+      if (qp)+	qp[nn] = q;+    }+  if ((inv->shift > 0) && (tp != qp))+    gmp_free (tp);++  return r >> inv->shift;+}++static void+mpn_div_qr_2_preinv (mp_ptr qp, mp_ptr np, mp_size_t nn,+		     const struct gmp_div_inverse *inv)+{+  unsigned shift;+  mp_size_t i;+  mp_limb_t d1, d0, di, r1, r0;++  assert (nn >= 2);+  shift = inv->shift;+  d1 = inv->d1;+  d0 = inv->d0;+  di = inv->di;++  if (shift > 0)+    r1 = mpn_lshift (np, np, nn, shift);+  else+    r1 = 0;++  r0 = np[nn - 1];++  i = nn - 2;+  do+    {+      mp_limb_t n0, q;+      n0 = np[i];+      gmp_udiv_qr_3by2 (q, r1, r0, r1, r0, n0, d1, d0, di);++      if (qp)+	qp[i] = q;+    }+  while (--i >= 0);++  if (shift > 0)+    {+      assert ((r0 & (GMP_LIMB_MAX >> (GMP_LIMB_BITS - shift))) == 0);+      r0 = (r0 >> shift) | (r1 << (GMP_LIMB_BITS - shift));+      r1 >>= shift;+    }++  np[1] = r1;+  np[0] = r0;+}++static void+mpn_div_qr_pi1 (mp_ptr qp,+		mp_ptr np, mp_size_t nn, mp_limb_t n1,+		mp_srcptr dp, mp_size_t dn,+		mp_limb_t dinv)+{+  mp_size_t i;++  mp_limb_t d1, d0;+  mp_limb_t cy, cy1;+  mp_limb_t q;++  assert (dn > 2);+  assert (nn >= dn);++  d1 = dp[dn - 1];+  d0 = dp[dn - 2];++  assert ((d1 & GMP_LIMB_HIGHBIT) != 0);+  /* Iteration variable is the index of the q limb.+   *+   * We divide <n1, np[dn-1+i], np[dn-2+i], np[dn-3+i],..., np[i]>+   * by            <d1,          d0,        dp[dn-3],  ..., dp[0] >+   */++  i = nn - dn;+  do+    {+      mp_limb_t n0 = np[dn-1+i];++      if (n1 == d1 && n0 == d0)+	{+	  q = GMP_LIMB_MAX;+	  mpn_submul_1 (np+i, dp, dn, q);+	  n1 = np[dn-1+i];	/* update n1, last loop's value will now be invalid */+	}+      else+	{+	  gmp_udiv_qr_3by2 (q, n1, n0, n1, n0, np[dn-2+i], d1, d0, dinv);++	  cy = mpn_submul_1 (np + i, dp, dn-2, q);++	  cy1 = n0 < cy;+	  n0 = n0 - cy;+	  cy = n1 < cy1;+	  n1 = n1 - cy1;+	  np[dn-2+i] = n0;++	  if (cy != 0)+	    {+	      n1 += d1 + mpn_add_n (np + i, np + i, dp, dn - 1);+	      q--;+	    }+	}++      if (qp)+	qp[i] = q;+    }+  while (--i >= 0);++  np[dn - 1] = n1;+}++static void+mpn_div_qr_preinv (mp_ptr qp, mp_ptr np, mp_size_t nn,+		   mp_srcptr dp, mp_size_t dn,+		   const struct gmp_div_inverse *inv)+{+  assert (dn > 0);+  assert (nn >= dn);++  if (dn == 1)+    np[0] = mpn_div_qr_1_preinv (qp, np, nn, inv);+  else if (dn == 2)+    mpn_div_qr_2_preinv (qp, np, nn, inv);+  else+    {+      mp_limb_t nh;+      unsigned shift;++      assert (inv->d1 == dp[dn-1]);+      assert (inv->d0 == dp[dn-2]);+      assert ((inv->d1 & GMP_LIMB_HIGHBIT) != 0);++      shift = inv->shift;+      if (shift > 0)+	nh = mpn_lshift (np, np, nn, shift);+      else+	nh = 0;++      mpn_div_qr_pi1 (qp, np, nn, nh, dp, dn, inv->di);++      if (shift > 0)+	gmp_assert_nocarry (mpn_rshift (np, np, dn, shift));+    }+}++static void+mpn_div_qr (mp_ptr qp, mp_ptr np, mp_size_t nn, mp_srcptr dp, mp_size_t dn)+{+  struct gmp_div_inverse inv;+  mp_ptr tp = NULL;++  assert (dn > 0);+  assert (nn >= dn);++  mpn_div_qr_invert (&inv, dp, dn);+  if (dn > 2 && inv.shift > 0)+    {+      tp = gmp_xalloc_limbs (dn);+      gmp_assert_nocarry (mpn_lshift (tp, dp, dn, inv.shift));+      dp = tp;+    }+  mpn_div_qr_preinv (qp, np, nn, dp, dn, &inv);+  if (tp)+    gmp_free (tp);+}+++/* MPN base conversion. */+static unsigned+mpn_base_power_of_two_p (unsigned b)+{+  switch (b)+    {+    case 2: return 1;+    case 4: return 2;+    case 8: return 3;+    case 16: return 4;+    case 32: return 5;+    case 64: return 6;+    case 128: return 7;+    case 256: return 8;+    default: return 0;+    }+}++struct mpn_base_info+{+  /* bb is the largest power of the base which fits in one limb, and+     exp is the corresponding exponent. */+  unsigned exp;+  mp_limb_t bb;+};++static void+mpn_get_base_info (struct mpn_base_info *info, mp_limb_t b)+{+  mp_limb_t m;+  mp_limb_t p;+  unsigned exp;++  m = GMP_LIMB_MAX / b;+  for (exp = 1, p = b; p <= m; exp++)+    p *= b;++  info->exp = exp;+  info->bb = p;+}++static mp_bitcnt_t+mpn_limb_size_in_base_2 (mp_limb_t u)+{+  unsigned shift;++  assert (u > 0);+  gmp_clz (shift, u);+  return GMP_LIMB_BITS - shift;+}++static size_t+mpn_get_str_bits (unsigned char *sp, unsigned bits, mp_srcptr up, mp_size_t un)+{+  unsigned char mask;+  size_t sn, j;+  mp_size_t i;+  unsigned shift;++  sn = ((un - 1) * GMP_LIMB_BITS + mpn_limb_size_in_base_2 (up[un-1])+	+ bits - 1) / bits;++  mask = (1U << bits) - 1;++  for (i = 0, j = sn, shift = 0; j-- > 0;)+    {+      unsigned char digit = up[i] >> shift;++      shift += bits;++      if (shift >= GMP_LIMB_BITS && ++i < un)+	{+	  shift -= GMP_LIMB_BITS;+	  digit |= up[i] << (bits - shift);+	}+      sp[j] = digit & mask;+    }+  return sn;+}++/* We generate digits from the least significant end, and reverse at+   the end. */+static size_t+mpn_limb_get_str (unsigned char *sp, mp_limb_t w,+		  const struct gmp_div_inverse *binv)+{+  mp_size_t i;+  for (i = 0; w > 0; i++)+    {+      mp_limb_t h, l, r;++      h = w >> (GMP_LIMB_BITS - binv->shift);+      l = w << binv->shift;++      gmp_udiv_qrnnd_preinv (w, r, h, l, binv->d1, binv->di);+      assert ((r & (GMP_LIMB_MAX >> (GMP_LIMB_BITS - binv->shift))) == 0);+      r >>= binv->shift;++      sp[i] = r;+    }+  return i;+}++static size_t+mpn_get_str_other (unsigned char *sp,+		   int base, const struct mpn_base_info *info,+		   mp_ptr up, mp_size_t un)+{+  struct gmp_div_inverse binv;+  size_t sn;+  size_t i;++  mpn_div_qr_1_invert (&binv, base);++  sn = 0;++  if (un > 1)+    {+      struct gmp_div_inverse bbinv;+      mpn_div_qr_1_invert (&bbinv, info->bb);++      do+	{+	  mp_limb_t w;+	  size_t done;+	  w = mpn_div_qr_1_preinv (up, up, un, &bbinv);+	  un -= (up[un-1] == 0);+	  done = mpn_limb_get_str (sp + sn, w, &binv);++	  for (sn += done; done < info->exp; done++)+	    sp[sn++] = 0;+	}+      while (un > 1);+    }+  sn += mpn_limb_get_str (sp + sn, up[0], &binv);++  /* Reverse order */+  for (i = 0; 2*i + 1 < sn; i++)+    {+      unsigned char t = sp[i];+      sp[i] = sp[sn - i - 1];+      sp[sn - i - 1] = t;+    }++  return sn;+}++size_t+mpn_get_str (unsigned char *sp, int base, mp_ptr up, mp_size_t un)+{+  unsigned bits;++  assert (un > 0);+  assert (up[un-1] > 0);++  bits = mpn_base_power_of_two_p (base);+  if (bits)+    return mpn_get_str_bits (sp, bits, up, un);+  else+    {+      struct mpn_base_info info;++      mpn_get_base_info (&info, base);+      return mpn_get_str_other (sp, base, &info, up, un);+    }+}++static mp_size_t+mpn_set_str_bits (mp_ptr rp, const unsigned char *sp, size_t sn,+		  unsigned bits)+{+  mp_size_t rn;+  size_t j;+  unsigned shift;++  for (j = sn, rn = 0, shift = 0; j-- > 0; )+    {+      if (shift == 0)+	{+	  rp[rn++] = sp[j];+	  shift += bits;+	}+      else+	{+	  rp[rn-1] |= (mp_limb_t) sp[j] << shift;+	  shift += bits;+	  if (shift >= GMP_LIMB_BITS)+	    {+	      shift -= GMP_LIMB_BITS;+	      if (shift > 0)+		rp[rn++] = (mp_limb_t) sp[j] >> (bits - shift);+	    }+	}+    }+  rn = mpn_normalized_size (rp, rn);+  return rn;+}++/* Result is usually normalized, except for all-zero input, in which+   case a single zero limb is written at *RP, and 1 is returned. */+static mp_size_t+mpn_set_str_other (mp_ptr rp, const unsigned char *sp, size_t sn,+		   mp_limb_t b, const struct mpn_base_info *info)+{+  mp_size_t rn;+  mp_limb_t w;+  unsigned k;+  size_t j;++  assert (sn > 0);++  k = 1 + (sn - 1) % info->exp;++  j = 0;+  w = sp[j++];+  while (--k != 0)+    w = w * b + sp[j++];++  rp[0] = w;++  for (rn = 1; j < sn;)+    {+      mp_limb_t cy;++      w = sp[j++];+      for (k = 1; k < info->exp; k++)+	w = w * b + sp[j++];++      cy = mpn_mul_1 (rp, rp, rn, info->bb);+      cy += mpn_add_1 (rp, rp, rn, w);+      if (cy > 0)+	rp[rn++] = cy;+    }+  assert (j == sn);++  return rn;+}++mp_size_t+mpn_set_str (mp_ptr rp, const unsigned char *sp, size_t sn, int base)+{+  unsigned bits;++  if (sn == 0)+    return 0;++  bits = mpn_base_power_of_two_p (base);+  if (bits)+    return mpn_set_str_bits (rp, sp, sn, bits);+  else+    {+      struct mpn_base_info info;++      mpn_get_base_info (&info, base);+      return mpn_set_str_other (rp, sp, sn, base, &info);+    }+}+++/* MPZ interface */+void+mpz_init (mpz_t r)+{+  static const mp_limb_t dummy_limb = GMP_LIMB_MAX & 0xc1a0;++  r->_mp_alloc = 0;+  r->_mp_size = 0;+  r->_mp_d = (mp_ptr) &dummy_limb;+}++/* The utility of this function is a bit limited, since many functions+   assigns the result variable using mpz_swap. */+void+mpz_init2 (mpz_t r, mp_bitcnt_t bits)+{+  mp_size_t rn;++  bits -= (bits != 0);		/* Round down, except if 0 */+  rn = 1 + bits / GMP_LIMB_BITS;++  r->_mp_alloc = rn;+  r->_mp_size = 0;+  r->_mp_d = gmp_xalloc_limbs (rn);+}++void+mpz_clear (mpz_t r)+{+  if (r->_mp_alloc)+    gmp_free (r->_mp_d);+}++static mp_ptr+mpz_realloc (mpz_t r, mp_size_t size)+{+  size = GMP_MAX (size, 1);++  if (r->_mp_alloc)+    r->_mp_d = gmp_xrealloc_limbs (r->_mp_d, size);+  else+    r->_mp_d = gmp_xalloc_limbs (size);+  r->_mp_alloc = size;++  if (GMP_ABS (r->_mp_size) > size)+    r->_mp_size = 0;++  return r->_mp_d;+}++/* Realloc for an mpz_t WHAT if it has less than NEEDED limbs.  */+#define MPZ_REALLOC(z,n) ((n) > (z)->_mp_alloc			\+			  ? mpz_realloc(z,n)			\+			  : (z)->_mp_d)++/* MPZ assignment and basic conversions. */+void+mpz_set_si (mpz_t r, signed long int x)+{+  if (x >= 0)+    mpz_set_ui (r, x);+  else /* (x < 0) */+    if (GMP_LIMB_BITS < GMP_ULONG_BITS)+      {+	mpz_set_ui (r, GMP_NEG_CAST (unsigned long int, x));+	mpz_neg (r, r);+      }+  else+    {+      r->_mp_size = -1;+      MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (unsigned long int, x);+    }+}++void+mpz_set_ui (mpz_t r, unsigned long int x)+{+  if (x > 0)+    {+      r->_mp_size = 1;+      MPZ_REALLOC (r, 1)[0] = x;+      if (GMP_LIMB_BITS < GMP_ULONG_BITS)+	{+	  int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;+	  while (x >>= LOCAL_GMP_LIMB_BITS)+	    {+	      ++ r->_mp_size;+	      MPZ_REALLOC (r, r->_mp_size)[r->_mp_size - 1] = x;+	    }+	}+    }+  else+    r->_mp_size = 0;+}++void+mpz_set (mpz_t r, const mpz_t x)+{+  /* Allow the NOP r == x */+  if (r != x)+    {+      mp_size_t n;+      mp_ptr rp;++      n = GMP_ABS (x->_mp_size);+      rp = MPZ_REALLOC (r, n);++      mpn_copyi (rp, x->_mp_d, n);+      r->_mp_size = x->_mp_size;+    }+}++void+mpz_init_set_si (mpz_t r, signed long int x)+{+  mpz_init (r);+  mpz_set_si (r, x);+}++void+mpz_init_set_ui (mpz_t r, unsigned long int x)+{+  mpz_init (r);+  mpz_set_ui (r, x);+}++void+mpz_init_set (mpz_t r, const mpz_t x)+{+  mpz_init (r);+  mpz_set (r, x);+}++int+mpz_fits_slong_p (const mpz_t u)+{+  return (LONG_MAX + LONG_MIN == 0 || mpz_cmp_ui (u, LONG_MAX) <= 0) &&+    mpz_cmpabs_ui (u, GMP_NEG_CAST (unsigned long int, LONG_MIN)) <= 0;+}++static int+mpn_absfits_ulong_p (mp_srcptr up, mp_size_t un)+{+  int ulongsize = GMP_ULONG_BITS / GMP_LIMB_BITS;+  mp_limb_t ulongrem = 0;++  if (GMP_ULONG_BITS % GMP_LIMB_BITS != 0)+    ulongrem = (mp_limb_t) (ULONG_MAX >> GMP_LIMB_BITS * ulongsize) + 1;++  return un <= ulongsize || (up[ulongsize] < ulongrem && un == ulongsize + 1);+}++int+mpz_fits_ulong_p (const mpz_t u)+{+  mp_size_t us = u->_mp_size;++  return us >= 0 && mpn_absfits_ulong_p (u->_mp_d, us);+}++long int+mpz_get_si (const mpz_t u)+{+  unsigned long r = mpz_get_ui (u);+  unsigned long c = -LONG_MAX - LONG_MIN;++  if (u->_mp_size < 0)+    /* This expression is necessary to properly handle -LONG_MIN */+    return -(long) c - (long) ((r - c) & LONG_MAX);+  else+    return (long) (r & LONG_MAX);+}++unsigned long int+mpz_get_ui (const mpz_t u)+{+  if (GMP_LIMB_BITS < GMP_ULONG_BITS)+    {+      int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;+      unsigned long r = 0;+      mp_size_t n = GMP_ABS (u->_mp_size);+      n = GMP_MIN (n, 1 + (mp_size_t) (GMP_ULONG_BITS - 1) / GMP_LIMB_BITS);+      while (--n >= 0)+	r = (r << LOCAL_GMP_LIMB_BITS) + u->_mp_d[n];+      return r;+    }++  return u->_mp_size == 0 ? 0 : u->_mp_d[0];+}++size_t+mpz_size (const mpz_t u)+{+  return GMP_ABS (u->_mp_size);+}++mp_limb_t+mpz_getlimbn (const mpz_t u, mp_size_t n)+{+  if (n >= 0 && n < GMP_ABS (u->_mp_size))+    return u->_mp_d[n];+  else+    return 0;+}++void+mpz_realloc2 (mpz_t x, mp_bitcnt_t n)+{+  mpz_realloc (x, 1 + (n - (n != 0)) / GMP_LIMB_BITS);+}++mp_srcptr+mpz_limbs_read (mpz_srcptr x)+{+  return x->_mp_d;+}++mp_ptr+mpz_limbs_modify (mpz_t x, mp_size_t n)+{+  assert (n > 0);+  return MPZ_REALLOC (x, n);+}++mp_ptr+mpz_limbs_write (mpz_t x, mp_size_t n)+{+  return mpz_limbs_modify (x, n);+}++void+mpz_limbs_finish (mpz_t x, mp_size_t xs)+{+  mp_size_t xn;+  xn = mpn_normalized_size (x->_mp_d, GMP_ABS (xs));+  x->_mp_size = xs < 0 ? -xn : xn;+}++static mpz_srcptr+mpz_roinit_normal_n (mpz_t x, mp_srcptr xp, mp_size_t xs)+{+  x->_mp_alloc = 0;+  x->_mp_d = (mp_ptr) xp;+  x->_mp_size = xs;+  return x;+}++mpz_srcptr+mpz_roinit_n (mpz_t x, mp_srcptr xp, mp_size_t xs)+{+  mpz_roinit_normal_n (x, xp, xs);+  mpz_limbs_finish (x, xs);+  return x;+}+++/* Conversions and comparison to double. */+void+mpz_set_d (mpz_t r, double x)+{+  int sign;+  mp_ptr rp;+  mp_size_t rn, i;+  double B;+  double Bi;+  mp_limb_t f;++  /* x != x is true when x is a NaN, and x == x * 0.5 is true when x is+     zero or infinity. */+  if (x != x || x == x * 0.5)+    {+      r->_mp_size = 0;+      return;+    }++  sign = x < 0.0 ;+  if (sign)+    x = - x;++  if (x < 1.0)+    {+      r->_mp_size = 0;+      return;+    }+  B = 4.0 * (double) (GMP_LIMB_HIGHBIT >> 1);+  Bi = 1.0 / B;+  for (rn = 1; x >= B; rn++)+    x *= Bi;++  rp = MPZ_REALLOC (r, rn);++  f = (mp_limb_t) x;+  x -= f;+  assert (x < 1.0);+  i = rn-1;+  rp[i] = f;+  while (--i >= 0)+    {+      x = B * x;+      f = (mp_limb_t) x;+      x -= f;+      assert (x < 1.0);+      rp[i] = f;+    }++  r->_mp_size = sign ? - rn : rn;+}++void+mpz_init_set_d (mpz_t r, double x)+{+  mpz_init (r);+  mpz_set_d (r, x);+}++double+mpz_get_d (const mpz_t u)+{+  int m;+  mp_limb_t l;+  mp_size_t un;+  double x;+  double B = 4.0 * (double) (GMP_LIMB_HIGHBIT >> 1);++  un = GMP_ABS (u->_mp_size);++  if (un == 0)+    return 0.0;++  l = u->_mp_d[--un];+  gmp_clz (m, l);+  m = m + GMP_DBL_MANT_BITS - GMP_LIMB_BITS;+  if (m < 0)+    l &= GMP_LIMB_MAX << -m;++  for (x = l; --un >= 0;)+    {+      x = B*x;+      if (m > 0) {+	l = u->_mp_d[un];+	m -= GMP_LIMB_BITS;+	if (m < 0)+	  l &= GMP_LIMB_MAX << -m;+	x += l;+      }+    }++  if (u->_mp_size < 0)+    x = -x;++  return x;+}++int+mpz_cmpabs_d (const mpz_t x, double d)+{+  mp_size_t xn;+  double B, Bi;+  mp_size_t i;++  xn = x->_mp_size;+  d = GMP_ABS (d);++  if (xn != 0)+    {+      xn = GMP_ABS (xn);++      B = 4.0 * (double) (GMP_LIMB_HIGHBIT >> 1);+      Bi = 1.0 / B;++      /* Scale d so it can be compared with the top limb. */+      for (i = 1; i < xn; i++)+	d *= Bi;++      if (d >= B)+	return -1;++      /* Compare floor(d) to top limb, subtract and cancel when equal. */+      for (i = xn; i-- > 0;)+	{+	  mp_limb_t f, xl;++	  f = (mp_limb_t) d;+	  xl = x->_mp_d[i];+	  if (xl > f)+	    return 1;+	  else if (xl < f)+	    return -1;+	  d = B * (d - f);+	}+    }+  return - (d > 0.0);+}++int+mpz_cmp_d (const mpz_t x, double d)+{+  if (x->_mp_size < 0)+    {+      if (d >= 0.0)+	return -1;+      else+	return -mpz_cmpabs_d (x, d);+    }+  else+    {+      if (d < 0.0)+	return 1;+      else+	return mpz_cmpabs_d (x, d);+    }+}+++/* MPZ comparisons and the like. */+int+mpz_sgn (const mpz_t u)+{+  return GMP_CMP (u->_mp_size, 0);+}++int+mpz_cmp_si (const mpz_t u, long v)+{+  mp_size_t usize = u->_mp_size;++  if (v >= 0)+    return mpz_cmp_ui (u, v);+  else if (usize >= 0)+    return 1;+  else+    return - mpz_cmpabs_ui (u, GMP_NEG_CAST (unsigned long int, v));+}++int+mpz_cmp_ui (const mpz_t u, unsigned long v)+{+  mp_size_t usize = u->_mp_size;++  if (usize < 0)+    return -1;+  else+    return mpz_cmpabs_ui (u, v);+}++int+mpz_cmp (const mpz_t a, const mpz_t b)+{+  mp_size_t asize = a->_mp_size;+  mp_size_t bsize = b->_mp_size;++  if (asize != bsize)+    return (asize < bsize) ? -1 : 1;+  else if (asize >= 0)+    return mpn_cmp (a->_mp_d, b->_mp_d, asize);+  else+    return mpn_cmp (b->_mp_d, a->_mp_d, -asize);+}++int+mpz_cmpabs_ui (const mpz_t u, unsigned long v)+{+  mp_size_t un = GMP_ABS (u->_mp_size);++  if (! mpn_absfits_ulong_p (u->_mp_d, un))+    return 1;+  else+    {+      unsigned long uu = mpz_get_ui (u);+      return GMP_CMP(uu, v);+    }+}++int+mpz_cmpabs (const mpz_t u, const mpz_t v)+{+  return mpn_cmp4 (u->_mp_d, GMP_ABS (u->_mp_size),+		   v->_mp_d, GMP_ABS (v->_mp_size));+}++void+mpz_abs (mpz_t r, const mpz_t u)+{+  mpz_set (r, u);+  r->_mp_size = GMP_ABS (r->_mp_size);+}++void+mpz_neg (mpz_t r, const mpz_t u)+{+  mpz_set (r, u);+  r->_mp_size = -r->_mp_size;+}++void+mpz_swap (mpz_t u, mpz_t v)+{+  MP_SIZE_T_SWAP (u->_mp_size, v->_mp_size);+  MP_SIZE_T_SWAP (u->_mp_alloc, v->_mp_alloc);+  MP_PTR_SWAP (u->_mp_d, v->_mp_d);+}+++/* MPZ addition and subtraction */+++void+mpz_add_ui (mpz_t r, const mpz_t a, unsigned long b)+{+  mpz_t bb;+  mpz_init_set_ui (bb, b);+  mpz_add (r, a, bb);+  mpz_clear (bb);+}++void+mpz_sub_ui (mpz_t r, const mpz_t a, unsigned long b)+{+  mpz_ui_sub (r, b, a);+  mpz_neg (r, r);+}++void+mpz_ui_sub (mpz_t r, unsigned long a, const mpz_t b)+{+  mpz_neg (r, b);+  mpz_add_ui (r, r, a);+}++static mp_size_t+mpz_abs_add (mpz_t r, const mpz_t a, const mpz_t b)+{+  mp_size_t an = GMP_ABS (a->_mp_size);+  mp_size_t bn = GMP_ABS (b->_mp_size);+  mp_ptr rp;+  mp_limb_t cy;++  if (an < bn)+    {+      MPZ_SRCPTR_SWAP (a, b);+      MP_SIZE_T_SWAP (an, bn);+    }++  rp = MPZ_REALLOC (r, an + 1);+  cy = mpn_add (rp, a->_mp_d, an, b->_mp_d, bn);++  rp[an] = cy;++  return an + cy;+}++static mp_size_t+mpz_abs_sub (mpz_t r, const mpz_t a, const mpz_t b)+{+  mp_size_t an = GMP_ABS (a->_mp_size);+  mp_size_t bn = GMP_ABS (b->_mp_size);+  int cmp;+  mp_ptr rp;++  cmp = mpn_cmp4 (a->_mp_d, an, b->_mp_d, bn);+  if (cmp > 0)+    {+      rp = MPZ_REALLOC (r, an);+      gmp_assert_nocarry (mpn_sub (rp, a->_mp_d, an, b->_mp_d, bn));+      return mpn_normalized_size (rp, an);+    }+  else if (cmp < 0)+    {+      rp = MPZ_REALLOC (r, bn);+      gmp_assert_nocarry (mpn_sub (rp, b->_mp_d, bn, a->_mp_d, an));+      return -mpn_normalized_size (rp, bn);+    }+  else+    return 0;+}++void+mpz_add (mpz_t r, const mpz_t a, const mpz_t b)+{+  mp_size_t rn;++  if ( (a->_mp_size ^ b->_mp_size) >= 0)+    rn = mpz_abs_add (r, a, b);+  else+    rn = mpz_abs_sub (r, a, b);++  r->_mp_size = a->_mp_size >= 0 ? rn : - rn;+}++void+mpz_sub (mpz_t r, const mpz_t a, const mpz_t b)+{+  mp_size_t rn;++  if ( (a->_mp_size ^ b->_mp_size) >= 0)+    rn = mpz_abs_sub (r, a, b);+  else+    rn = mpz_abs_add (r, a, b);++  r->_mp_size = a->_mp_size >= 0 ? rn : - rn;+}+++/* MPZ multiplication */+void+mpz_mul_si (mpz_t r, const mpz_t u, long int v)+{+  if (v < 0)+    {+      mpz_mul_ui (r, u, GMP_NEG_CAST (unsigned long int, v));+      mpz_neg (r, r);+    }+  else+    mpz_mul_ui (r, u, v);+}++void+mpz_mul_ui (mpz_t r, const mpz_t u, unsigned long int v)+{+  mpz_t vv;+  mpz_init_set_ui (vv, v);+  mpz_mul (r, u, vv);+  mpz_clear (vv);+  return;+}++void+mpz_mul (mpz_t r, const mpz_t u, const mpz_t v)+{+  int sign;+  mp_size_t un, vn, rn;+  mpz_t t;+  mp_ptr tp;++  un = u->_mp_size;+  vn = v->_mp_size;++  if (un == 0 || vn == 0)+    {+      r->_mp_size = 0;+      return;+    }++  sign = (un ^ vn) < 0;++  un = GMP_ABS (un);+  vn = GMP_ABS (vn);++  mpz_init2 (t, (un + vn) * GMP_LIMB_BITS);++  tp = t->_mp_d;+  if (un >= vn)+    mpn_mul (tp, u->_mp_d, un, v->_mp_d, vn);+  else+    mpn_mul (tp, v->_mp_d, vn, u->_mp_d, un);++  rn = un + vn;+  rn -= tp[rn-1] == 0;++  t->_mp_size = sign ? - rn : rn;+  mpz_swap (r, t);+  mpz_clear (t);+}++void+mpz_mul_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t bits)+{+  mp_size_t un, rn;+  mp_size_t limbs;+  unsigned shift;+  mp_ptr rp;++  un = GMP_ABS (u->_mp_size);+  if (un == 0)+    {+      r->_mp_size = 0;+      return;+    }++  limbs = bits / GMP_LIMB_BITS;+  shift = bits % GMP_LIMB_BITS;++  rn = un + limbs + (shift > 0);+  rp = MPZ_REALLOC (r, rn);+  if (shift > 0)+    {+      mp_limb_t cy = mpn_lshift (rp + limbs, u->_mp_d, un, shift);+      rp[rn-1] = cy;+      rn -= (cy == 0);+    }+  else+    mpn_copyd (rp + limbs, u->_mp_d, un);++  mpn_zero (rp, limbs);++  r->_mp_size = (u->_mp_size < 0) ? - rn : rn;+}++void+mpz_addmul_ui (mpz_t r, const mpz_t u, unsigned long int v)+{+  mpz_t t;+  mpz_init_set_ui (t, v);+  mpz_mul (t, u, t);+  mpz_add (r, r, t);+  mpz_clear (t);+}++void+mpz_submul_ui (mpz_t r, const mpz_t u, unsigned long int v)+{+  mpz_t t;+  mpz_init_set_ui (t, v);+  mpz_mul (t, u, t);+  mpz_sub (r, r, t);+  mpz_clear (t);+}++void+mpz_addmul (mpz_t r, const mpz_t u, const mpz_t v)+{+  mpz_t t;+  mpz_init (t);+  mpz_mul (t, u, v);+  mpz_add (r, r, t);+  mpz_clear (t);+}++void+mpz_submul (mpz_t r, const mpz_t u, const mpz_t v)+{+  mpz_t t;+  mpz_init (t);+  mpz_mul (t, u, v);+  mpz_sub (r, r, t);+  mpz_clear (t);+}+++/* MPZ division */+enum mpz_div_round_mode { GMP_DIV_FLOOR, GMP_DIV_CEIL, GMP_DIV_TRUNC };++/* Allows q or r to be zero. Returns 1 iff remainder is non-zero. */+static int+mpz_div_qr (mpz_t q, mpz_t r,+	    const mpz_t n, const mpz_t d, enum mpz_div_round_mode mode)+{+  mp_size_t ns, ds, nn, dn, qs;+  ns = n->_mp_size;+  ds = d->_mp_size;++  if (ds == 0)+    gmp_die("mpz_div_qr: Divide by zero.");++  if (ns == 0)+    {+      if (q)+	q->_mp_size = 0;+      if (r)+	r->_mp_size = 0;+      return 0;+    }++  nn = GMP_ABS (ns);+  dn = GMP_ABS (ds);++  qs = ds ^ ns;++  if (nn < dn)+    {+      if (mode == GMP_DIV_CEIL && qs >= 0)+	{+	  /* q = 1, r = n - d */+	  if (r)+	    mpz_sub (r, n, d);+	  if (q)+	    mpz_set_ui (q, 1);+	}+      else if (mode == GMP_DIV_FLOOR && qs < 0)+	{+	  /* q = -1, r = n + d */+	  if (r)+	    mpz_add (r, n, d);+	  if (q)+	    mpz_set_si (q, -1);+	}+      else+	{+	  /* q = 0, r = d */+	  if (r)+	    mpz_set (r, n);+	  if (q)+	    q->_mp_size = 0;+	}+      return 1;+    }+  else+    {+      mp_ptr np, qp;+      mp_size_t qn, rn;+      mpz_t tq, tr;++      mpz_init_set (tr, n);+      np = tr->_mp_d;++      qn = nn - dn + 1;++      if (q)+	{+	  mpz_init2 (tq, qn * GMP_LIMB_BITS);+	  qp = tq->_mp_d;+	}+      else+	qp = NULL;++      mpn_div_qr (qp, np, nn, d->_mp_d, dn);++      if (qp)+	{+	  qn -= (qp[qn-1] == 0);++	  tq->_mp_size = qs < 0 ? -qn : qn;+	}+      rn = mpn_normalized_size (np, dn);+      tr->_mp_size = ns < 0 ? - rn : rn;++      if (mode == GMP_DIV_FLOOR && qs < 0 && rn != 0)+	{+	  if (q)+	    mpz_sub_ui (tq, tq, 1);+	  if (r)+	    mpz_add (tr, tr, d);+	}+      else if (mode == GMP_DIV_CEIL && qs >= 0 && rn != 0)+	{+	  if (q)+	    mpz_add_ui (tq, tq, 1);+	  if (r)+	    mpz_sub (tr, tr, d);+	}++      if (q)+	{+	  mpz_swap (tq, q);+	  mpz_clear (tq);+	}+      if (r)+	mpz_swap (tr, r);++      mpz_clear (tr);++      return rn != 0;+    }+}++void+mpz_cdiv_qr (mpz_t q, mpz_t r, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (q, r, n, d, GMP_DIV_CEIL);+}++void+mpz_fdiv_qr (mpz_t q, mpz_t r, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (q, r, n, d, GMP_DIV_FLOOR);+}++void+mpz_tdiv_qr (mpz_t q, mpz_t r, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (q, r, n, d, GMP_DIV_TRUNC);+}++void+mpz_cdiv_q (mpz_t q, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (q, NULL, n, d, GMP_DIV_CEIL);+}++void+mpz_fdiv_q (mpz_t q, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (q, NULL, n, d, GMP_DIV_FLOOR);+}++void+mpz_tdiv_q (mpz_t q, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (q, NULL, n, d, GMP_DIV_TRUNC);+}++void+mpz_cdiv_r (mpz_t r, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (NULL, r, n, d, GMP_DIV_CEIL);+}++void+mpz_fdiv_r (mpz_t r, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (NULL, r, n, d, GMP_DIV_FLOOR);+}++void+mpz_tdiv_r (mpz_t r, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (NULL, r, n, d, GMP_DIV_TRUNC);+}++void+mpz_mod (mpz_t r, const mpz_t n, const mpz_t d)+{+  mpz_div_qr (NULL, r, n, d, d->_mp_size >= 0 ? GMP_DIV_FLOOR : GMP_DIV_CEIL);+}++static void+mpz_div_q_2exp (mpz_t q, const mpz_t u, mp_bitcnt_t bit_index,+		enum mpz_div_round_mode mode)+{+  mp_size_t un, qn;+  mp_size_t limb_cnt;+  mp_ptr qp;+  int adjust;++  un = u->_mp_size;+  if (un == 0)+    {+      q->_mp_size = 0;+      return;+    }+  limb_cnt = bit_index / GMP_LIMB_BITS;+  qn = GMP_ABS (un) - limb_cnt;+  bit_index %= GMP_LIMB_BITS;++  if (mode == ((un > 0) ? GMP_DIV_CEIL : GMP_DIV_FLOOR)) /* un != 0 here. */+    /* Note: Below, the final indexing at limb_cnt is valid because at+       that point we have qn > 0. */+    adjust = (qn <= 0+	      || !mpn_zero_p (u->_mp_d, limb_cnt)+	      || (u->_mp_d[limb_cnt]+		  & (((mp_limb_t) 1 << bit_index) - 1)));+  else+    adjust = 0;++  if (qn <= 0)+    qn = 0;+  else+    {+      qp = MPZ_REALLOC (q, qn);++      if (bit_index != 0)+	{+	  mpn_rshift (qp, u->_mp_d + limb_cnt, qn, bit_index);+	  qn -= qp[qn - 1] == 0;+	}+      else+	{+	  mpn_copyi (qp, u->_mp_d + limb_cnt, qn);+	}+    }++  q->_mp_size = qn;++  if (adjust)+    mpz_add_ui (q, q, 1);+  if (un < 0)+    mpz_neg (q, q);+}++static void+mpz_div_r_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t bit_index,+		enum mpz_div_round_mode mode)+{+  mp_size_t us, un, rn;+  mp_ptr rp;+  mp_limb_t mask;++  us = u->_mp_size;+  if (us == 0 || bit_index == 0)+    {+      r->_mp_size = 0;+      return;+    }+  rn = (bit_index + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;+  assert (rn > 0);++  rp = MPZ_REALLOC (r, rn);+  un = GMP_ABS (us);++  mask = GMP_LIMB_MAX >> (rn * GMP_LIMB_BITS - bit_index);++  if (rn > un)+    {+      /* Quotient (with truncation) is zero, and remainder is+	 non-zero */+      if (mode == ((us > 0) ? GMP_DIV_CEIL : GMP_DIV_FLOOR)) /* us != 0 here. */+	{+	  /* Have to negate and sign extend. */+	  mp_size_t i;++	  gmp_assert_nocarry (! mpn_neg (rp, u->_mp_d, un));+	  for (i = un; i < rn - 1; i++)+	    rp[i] = GMP_LIMB_MAX;++	  rp[rn-1] = mask;+	  us = -us;+	}+      else+	{+	  /* Just copy */+	  if (r != u)+	    mpn_copyi (rp, u->_mp_d, un);++	  rn = un;+	}+    }+  else+    {+      if (r != u)+	mpn_copyi (rp, u->_mp_d, rn - 1);++      rp[rn-1] = u->_mp_d[rn-1] & mask;++      if (mode == ((us > 0) ? GMP_DIV_CEIL : GMP_DIV_FLOOR)) /* us != 0 here. */+	{+	  /* If r != 0, compute 2^{bit_count} - r. */+	  mpn_neg (rp, rp, rn);++	  rp[rn-1] &= mask;++	  /* us is not used for anything else, so we can modify it+	     here to indicate flipped sign. */+	  us = -us;+	}+    }+  rn = mpn_normalized_size (rp, rn);+  r->_mp_size = us < 0 ? -rn : rn;+}++void+mpz_cdiv_q_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t cnt)+{+  mpz_div_q_2exp (r, u, cnt, GMP_DIV_CEIL);+}++void+mpz_fdiv_q_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t cnt)+{+  mpz_div_q_2exp (r, u, cnt, GMP_DIV_FLOOR);+}++void+mpz_tdiv_q_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t cnt)+{+  mpz_div_q_2exp (r, u, cnt, GMP_DIV_TRUNC);+}++void+mpz_cdiv_r_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t cnt)+{+  mpz_div_r_2exp (r, u, cnt, GMP_DIV_CEIL);+}++void+mpz_fdiv_r_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t cnt)+{+  mpz_div_r_2exp (r, u, cnt, GMP_DIV_FLOOR);+}++void+mpz_tdiv_r_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t cnt)+{+  mpz_div_r_2exp (r, u, cnt, GMP_DIV_TRUNC);+}++void+mpz_divexact (mpz_t q, const mpz_t n, const mpz_t d)+{+  gmp_assert_nocarry (mpz_div_qr (q, NULL, n, d, GMP_DIV_TRUNC));+}++int+mpz_divisible_p (const mpz_t n, const mpz_t d)+{+  return mpz_div_qr (NULL, NULL, n, d, GMP_DIV_TRUNC) == 0;+}++int+mpz_congruent_p (const mpz_t a, const mpz_t b, const mpz_t m)+{+  mpz_t t;+  int res;++  /* a == b (mod 0) iff a == b */+  if (mpz_sgn (m) == 0)+    return (mpz_cmp (a, b) == 0);++  mpz_init (t);+  mpz_sub (t, a, b);+  res = mpz_divisible_p (t, m);+  mpz_clear (t);++  return res;+}++static unsigned long+mpz_div_qr_ui (mpz_t q, mpz_t r,+	       const mpz_t n, unsigned long d, enum mpz_div_round_mode mode)+{+  unsigned long ret;+  mpz_t rr, dd;++  mpz_init (rr);+  mpz_init_set_ui (dd, d);+  mpz_div_qr (q, rr, n, dd, mode);+  mpz_clear (dd);+  ret = mpz_get_ui (rr);++  if (r)+    mpz_swap (r, rr);+  mpz_clear (rr);++  return ret;+}++unsigned long+mpz_cdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (q, r, n, d, GMP_DIV_CEIL);+}++unsigned long+mpz_fdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (q, r, n, d, GMP_DIV_FLOOR);+}++unsigned long+mpz_tdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (q, r, n, d, GMP_DIV_TRUNC);+}++unsigned long+mpz_cdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_CEIL);+}++unsigned long+mpz_fdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_FLOOR);+}++unsigned long+mpz_tdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_TRUNC);+}++unsigned long+mpz_cdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_CEIL);+}+unsigned long+mpz_fdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_FLOOR);+}+unsigned long+mpz_tdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_TRUNC);+}++unsigned long+mpz_cdiv_ui (const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_CEIL);+}++unsigned long+mpz_fdiv_ui (const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_FLOOR);+}++unsigned long+mpz_tdiv_ui (const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_TRUNC);+}++unsigned long+mpz_mod_ui (mpz_t r, const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_FLOOR);+}++void+mpz_divexact_ui (mpz_t q, const mpz_t n, unsigned long d)+{+  gmp_assert_nocarry (mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_TRUNC));+}++int+mpz_divisible_ui_p (const mpz_t n, unsigned long d)+{+  return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_TRUNC) == 0;+}+++/* GCD */+static mp_limb_t+mpn_gcd_11 (mp_limb_t u, mp_limb_t v)+{+  unsigned shift;++  assert ( (u | v) > 0);++  if (u == 0)+    return v;+  else if (v == 0)+    return u;++  gmp_ctz (shift, u | v);++  u >>= shift;+  v >>= shift;++  if ( (u & 1) == 0)+    MP_LIMB_T_SWAP (u, v);++  while ( (v & 1) == 0)+    v >>= 1;++  while (u != v)+    {+      if (u > v)+	{+	  u -= v;+	  do+	    u >>= 1;+	  while ( (u & 1) == 0);+	}+      else+	{+	  v -= u;+	  do+	    v >>= 1;+	  while ( (v & 1) == 0);+	}+    }+  return u << shift;+}++unsigned long+mpz_gcd_ui (mpz_t g, const mpz_t u, unsigned long v)+{+  mpz_t t;+  mpz_init_set_ui(t, v);+  mpz_gcd (t, u, t);+  if (v > 0)+    v = mpz_get_ui (t);++  if (g)+    mpz_swap (t, g);++  mpz_clear (t);++  return v;+}++static mp_bitcnt_t+mpz_make_odd (mpz_t r)+{+  mp_bitcnt_t shift;++  assert (r->_mp_size > 0);+  /* Count trailing zeros, equivalent to mpn_scan1, because we know that there is a 1 */+  shift = mpn_common_scan (r->_mp_d[0], 0, r->_mp_d, 0, 0);+  mpz_tdiv_q_2exp (r, r, shift);++  return shift;+}++void+mpz_gcd (mpz_t g, const mpz_t u, const mpz_t v)+{+  mpz_t tu, tv;+  mp_bitcnt_t uz, vz, gz;++  if (u->_mp_size == 0)+    {+      mpz_abs (g, v);+      return;+    }+  if (v->_mp_size == 0)+    {+      mpz_abs (g, u);+      return;+    }++  mpz_init (tu);+  mpz_init (tv);++  mpz_abs (tu, u);+  uz = mpz_make_odd (tu);+  mpz_abs (tv, v);+  vz = mpz_make_odd (tv);+  gz = GMP_MIN (uz, vz);++  if (tu->_mp_size < tv->_mp_size)+    mpz_swap (tu, tv);++  mpz_tdiv_r (tu, tu, tv);+  if (tu->_mp_size == 0)+    {+      mpz_swap (g, tv);+    }+  else+    for (;;)+      {+	int c;++	mpz_make_odd (tu);+	c = mpz_cmp (tu, tv);+	if (c == 0)+	  {+	    mpz_swap (g, tu);+	    break;+	  }+	if (c < 0)+	  mpz_swap (tu, tv);++	if (tv->_mp_size == 1)+	  {+	    mp_limb_t vl = tv->_mp_d[0];+	    mp_limb_t ul = mpz_tdiv_ui (tu, vl);+	    mpz_set_ui (g, mpn_gcd_11 (ul, vl));+	    break;+	  }+	mpz_sub (tu, tu, tv);+      }+  mpz_clear (tu);+  mpz_clear (tv);+  mpz_mul_2exp (g, g, gz);+}++void+mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t u, const mpz_t v)+{+  mpz_t tu, tv, s0, s1, t0, t1;+  mp_bitcnt_t uz, vz, gz;+  mp_bitcnt_t power;++  if (u->_mp_size == 0)+    {+      /* g = 0 u + sgn(v) v */+      signed long sign = mpz_sgn (v);+      mpz_abs (g, v);+      if (s)+	s->_mp_size = 0;+      if (t)+	mpz_set_si (t, sign);+      return;+    }++  if (v->_mp_size == 0)+    {+      /* g = sgn(u) u + 0 v */+      signed long sign = mpz_sgn (u);+      mpz_abs (g, u);+      if (s)+	mpz_set_si (s, sign);+      if (t)+	t->_mp_size = 0;+      return;+    }++  mpz_init (tu);+  mpz_init (tv);+  mpz_init (s0);+  mpz_init (s1);+  mpz_init (t0);+  mpz_init (t1);++  mpz_abs (tu, u);+  uz = mpz_make_odd (tu);+  mpz_abs (tv, v);+  vz = mpz_make_odd (tv);+  gz = GMP_MIN (uz, vz);++  uz -= gz;+  vz -= gz;++  /* Cofactors corresponding to odd gcd. gz handled later. */+  if (tu->_mp_size < tv->_mp_size)+    {+      mpz_swap (tu, tv);+      MPZ_SRCPTR_SWAP (u, v);+      MPZ_PTR_SWAP (s, t);+      MP_BITCNT_T_SWAP (uz, vz);+    }++  /* Maintain+   *+   * u = t0 tu + t1 tv+   * v = s0 tu + s1 tv+   *+   * where u and v denote the inputs with common factors of two+   * eliminated, and det (s0, t0; s1, t1) = 2^p. Then+   *+   * 2^p tu =  s1 u - t1 v+   * 2^p tv = -s0 u + t0 v+   */++  /* After initial division, tu = q tv + tu', we have+   *+   * u = 2^uz (tu' + q tv)+   * v = 2^vz tv+   *+   * or+   *+   * t0 = 2^uz, t1 = 2^uz q+   * s0 = 0,    s1 = 2^vz+   */++  mpz_setbit (t0, uz);+  mpz_tdiv_qr (t1, tu, tu, tv);+  mpz_mul_2exp (t1, t1, uz);++  mpz_setbit (s1, vz);+  power = uz + vz;++  if (tu->_mp_size > 0)+    {+      mp_bitcnt_t shift;+      shift = mpz_make_odd (tu);+      mpz_mul_2exp (t0, t0, shift);+      mpz_mul_2exp (s0, s0, shift);+      power += shift;++      for (;;)+	{+	  int c;+	  c = mpz_cmp (tu, tv);+	  if (c == 0)+	    break;++	  if (c < 0)+	    {+	      /* tv = tv' + tu+	       *+	       * u = t0 tu + t1 (tv' + tu) = (t0 + t1) tu + t1 tv'+	       * v = s0 tu + s1 (tv' + tu) = (s0 + s1) tu + s1 tv' */++	      mpz_sub (tv, tv, tu);+	      mpz_add (t0, t0, t1);+	      mpz_add (s0, s0, s1);++	      shift = mpz_make_odd (tv);+	      mpz_mul_2exp (t1, t1, shift);+	      mpz_mul_2exp (s1, s1, shift);+	    }+	  else+	    {+	      mpz_sub (tu, tu, tv);+	      mpz_add (t1, t0, t1);+	      mpz_add (s1, s0, s1);++	      shift = mpz_make_odd (tu);+	      mpz_mul_2exp (t0, t0, shift);+	      mpz_mul_2exp (s0, s0, shift);+	    }+	  power += shift;+	}+    }++  /* Now tv = odd part of gcd, and -s0 and t0 are corresponding+     cofactors. */++  mpz_mul_2exp (tv, tv, gz);+  mpz_neg (s0, s0);++  /* 2^p g = s0 u + t0 v. Eliminate one factor of two at a time. To+     adjust cofactors, we need u / g and v / g */++  mpz_divexact (s1, v, tv);+  mpz_abs (s1, s1);+  mpz_divexact (t1, u, tv);+  mpz_abs (t1, t1);++  while (power-- > 0)+    {+      /* s0 u + t0 v = (s0 - v/g) u - (t0 + u/g) v */+      if (mpz_odd_p (s0) || mpz_odd_p (t0))+	{+	  mpz_sub (s0, s0, s1);+	  mpz_add (t0, t0, t1);+	}+      assert (mpz_even_p (t0) && mpz_even_p (s0));+      mpz_tdiv_q_2exp (s0, s0, 1);+      mpz_tdiv_q_2exp (t0, t0, 1);+    }++  /* Arrange so that |s| < |u| / 2g */+  mpz_add (s1, s0, s1);+  if (mpz_cmpabs (s0, s1) > 0)+    {+      mpz_swap (s0, s1);+      mpz_sub (t0, t0, t1);+    }+  if (u->_mp_size < 0)+    mpz_neg (s0, s0);+  if (v->_mp_size < 0)+    mpz_neg (t0, t0);++  mpz_swap (g, tv);+  if (s)+    mpz_swap (s, s0);+  if (t)+    mpz_swap (t, t0);++  mpz_clear (tu);+  mpz_clear (tv);+  mpz_clear (s0);+  mpz_clear (s1);+  mpz_clear (t0);+  mpz_clear (t1);+}++void+mpz_lcm (mpz_t r, const mpz_t u, const mpz_t v)+{+  mpz_t g;++  if (u->_mp_size == 0 || v->_mp_size == 0)+    {+      r->_mp_size = 0;+      return;+    }++  mpz_init (g);++  mpz_gcd (g, u, v);+  mpz_divexact (g, u, g);+  mpz_mul (r, g, v);++  mpz_clear (g);+  mpz_abs (r, r);+}++void+mpz_lcm_ui (mpz_t r, const mpz_t u, unsigned long v)+{+  if (v == 0 || u->_mp_size == 0)+    {+      r->_mp_size = 0;+      return;+    }++  v /= mpz_gcd_ui (NULL, u, v);+  mpz_mul_ui (r, u, v);++  mpz_abs (r, r);+}++int+mpz_invert (mpz_t r, const mpz_t u, const mpz_t m)+{+  mpz_t g, tr;+  int invertible;++  if (u->_mp_size == 0 || mpz_cmpabs_ui (m, 1) <= 0)+    return 0;++  mpz_init (g);+  mpz_init (tr);++  mpz_gcdext (g, tr, NULL, u, m);+  invertible = (mpz_cmp_ui (g, 1) == 0);++  if (invertible)+    {+      if (tr->_mp_size < 0)+	{+	  if (m->_mp_size >= 0)+	    mpz_add (tr, tr, m);+	  else+	    mpz_sub (tr, tr, m);+	}+      mpz_swap (r, tr);+    }++  mpz_clear (g);+  mpz_clear (tr);+  return invertible;+}+++/* Higher level operations (sqrt, pow and root) */++void+mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e)+{+  unsigned long bit;+  mpz_t tr;+  mpz_init_set_ui (tr, 1);++  bit = GMP_ULONG_HIGHBIT;+  do+    {+      mpz_mul (tr, tr, tr);+      if (e & bit)+	mpz_mul (tr, tr, b);+      bit >>= 1;+    }+  while (bit > 0);++  mpz_swap (r, tr);+  mpz_clear (tr);+}++void+mpz_ui_pow_ui (mpz_t r, unsigned long blimb, unsigned long e)+{+  mpz_t b;++  mpz_init_set_ui (b, blimb);+  mpz_pow_ui (r, b, e);+  mpz_clear (b);+}++void+mpz_powm (mpz_t r, const mpz_t b, const mpz_t e, const mpz_t m)+{+  mpz_t tr;+  mpz_t base;+  mp_size_t en, mn;+  mp_srcptr mp;+  struct gmp_div_inverse minv;+  unsigned shift;+  mp_ptr tp = NULL;++  en = GMP_ABS (e->_mp_size);+  mn = GMP_ABS (m->_mp_size);+  if (mn == 0)+    gmp_die ("mpz_powm: Zero modulo.");++  if (en == 0)+    {+      mpz_set_ui (r, 1);+      return;+    }++  mp = m->_mp_d;+  mpn_div_qr_invert (&minv, mp, mn);+  shift = minv.shift;++  if (shift > 0)+    {+      /* To avoid shifts, we do all our reductions, except the final+	 one, using a *normalized* m. */+      minv.shift = 0;++      tp = gmp_xalloc_limbs (mn);+      gmp_assert_nocarry (mpn_lshift (tp, mp, mn, shift));+      mp = tp;+    }++  mpz_init (base);++  if (e->_mp_size < 0)+    {+      if (!mpz_invert (base, b, m))+	gmp_die ("mpz_powm: Negative exponent and non-invertible base.");+    }+  else+    {+      mp_size_t bn;+      mpz_abs (base, b);++      bn = base->_mp_size;+      if (bn >= mn)+	{+	  mpn_div_qr_preinv (NULL, base->_mp_d, base->_mp_size, mp, mn, &minv);+	  bn = mn;+	}++      /* We have reduced the absolute value. Now take care of the+	 sign. Note that we get zero represented non-canonically as+	 m. */+      if (b->_mp_size < 0)+	{+	  mp_ptr bp = MPZ_REALLOC (base, mn);+	  gmp_assert_nocarry (mpn_sub (bp, mp, mn, bp, bn));+	  bn = mn;+	}+      base->_mp_size = mpn_normalized_size (base->_mp_d, bn);+    }+  mpz_init_set_ui (tr, 1);++  while (--en >= 0)+    {+      mp_limb_t w = e->_mp_d[en];+      mp_limb_t bit;++      bit = GMP_LIMB_HIGHBIT;+      do+	{+	  mpz_mul (tr, tr, tr);+	  if (w & bit)+	    mpz_mul (tr, tr, base);+	  if (tr->_mp_size > mn)+	    {+	      mpn_div_qr_preinv (NULL, tr->_mp_d, tr->_mp_size, mp, mn, &minv);+	      tr->_mp_size = mpn_normalized_size (tr->_mp_d, mn);+	    }+	  bit >>= 1;+	}+      while (bit > 0);+    }++  /* Final reduction */+  if (tr->_mp_size >= mn)+    {+      minv.shift = shift;+      mpn_div_qr_preinv (NULL, tr->_mp_d, tr->_mp_size, mp, mn, &minv);+      tr->_mp_size = mpn_normalized_size (tr->_mp_d, mn);+    }+  if (tp)+    gmp_free (tp);++  mpz_swap (r, tr);+  mpz_clear (tr);+  mpz_clear (base);+}++void+mpz_powm_ui (mpz_t r, const mpz_t b, unsigned long elimb, const mpz_t m)+{+  mpz_t e;++  mpz_init_set_ui (e, elimb);+  mpz_powm (r, b, e, m);+  mpz_clear (e);+}++/* x=trunc(y^(1/z)), r=y-x^z */+void+mpz_rootrem (mpz_t x, mpz_t r, const mpz_t y, unsigned long z)+{+  int sgn;+  mpz_t t, u;++  sgn = y->_mp_size < 0;+  if ((~z & sgn) != 0)+    gmp_die ("mpz_rootrem: Negative argument, with even root.");+  if (z == 0)+    gmp_die ("mpz_rootrem: Zeroth root.");++  if (mpz_cmpabs_ui (y, 1) <= 0) {+    if (x)+      mpz_set (x, y);+    if (r)+      r->_mp_size = 0;+    return;+  }++  mpz_init (u);+  mpz_init (t);+  mpz_setbit (t, mpz_sizeinbase (y, 2) / z + 1);++  if (z == 2) /* simplify sqrt loop: z-1 == 1 */+    do {+      mpz_swap (u, t);			/* u = x */+      mpz_tdiv_q (t, y, u);		/* t = y/x */+      mpz_add (t, t, u);		/* t = y/x + x */+      mpz_tdiv_q_2exp (t, t, 1);	/* x'= (y/x + x)/2 */+    } while (mpz_cmpabs (t, u) < 0);	/* |x'| < |x| */+  else /* z != 2 */ {+    mpz_t v;++    mpz_init (v);+    if (sgn)+      mpz_neg (t, t);++    do {+      mpz_swap (u, t);			/* u = x */+      mpz_pow_ui (t, u, z - 1);		/* t = x^(z-1) */+      mpz_tdiv_q (t, y, t);		/* t = y/x^(z-1) */+      mpz_mul_ui (v, u, z - 1);		/* v = x*(z-1) */+      mpz_add (t, t, v);		/* t = y/x^(z-1) + x*(z-1) */+      mpz_tdiv_q_ui (t, t, z);		/* x'=(y/x^(z-1) + x*(z-1))/z */+    } while (mpz_cmpabs (t, u) < 0);	/* |x'| < |x| */++    mpz_clear (v);+  }++  if (r) {+    mpz_pow_ui (t, u, z);+    mpz_sub (r, y, t);+  }+  if (x)+    mpz_swap (x, u);+  mpz_clear (u);+  mpz_clear (t);+}++int+mpz_root (mpz_t x, const mpz_t y, unsigned long z)+{+  int res;+  mpz_t r;++  mpz_init (r);+  mpz_rootrem (x, r, y, z);+  res = r->_mp_size == 0;+  mpz_clear (r);++  return res;+}++/* Compute s = floor(sqrt(u)) and r = u - s^2. Allows r == NULL */+void+mpz_sqrtrem (mpz_t s, mpz_t r, const mpz_t u)+{+  mpz_rootrem (s, r, u, 2);+}++void+mpz_sqrt (mpz_t s, const mpz_t u)+{+  mpz_rootrem (s, NULL, u, 2);+}++int+mpz_perfect_square_p (const mpz_t u)+{+  if (u->_mp_size <= 0)+    return (u->_mp_size == 0);+  else+    return mpz_root (NULL, u, 2);+}++int+mpn_perfect_square_p (mp_srcptr p, mp_size_t n)+{+  mpz_t t;++  assert (n > 0);+  assert (p [n-1] != 0);+  return mpz_root (NULL, mpz_roinit_normal_n (t, p, n), 2);+}++mp_size_t+mpn_sqrtrem (mp_ptr sp, mp_ptr rp, mp_srcptr p, mp_size_t n)+{+  mpz_t s, r, u;+  mp_size_t res;++  assert (n > 0);+  assert (p [n-1] != 0);++  mpz_init (r);+  mpz_init (s);+  mpz_rootrem (s, r, mpz_roinit_normal_n (u, p, n), 2);++  assert (s->_mp_size == (n+1)/2);+  mpn_copyd (sp, s->_mp_d, s->_mp_size);+  mpz_clear (s);+  res = r->_mp_size;+  if (rp)+    mpn_copyd (rp, r->_mp_d, res);+  mpz_clear (r);+  return res;+}++/* Combinatorics */++void+mpz_mfac_uiui (mpz_t x, unsigned long n, unsigned long m)+{+  mpz_set_ui (x, n + (n == 0));+  if (m + 1 < 2) return;+  while (n > m + 1)+    mpz_mul_ui (x, x, n -= m);+}++void+mpz_2fac_ui (mpz_t x, unsigned long n)+{+  mpz_mfac_uiui (x, n, 2);+}++void+mpz_fac_ui (mpz_t x, unsigned long n)+{+  mpz_mfac_uiui (x, n, 1);+}++void+mpz_bin_uiui (mpz_t r, unsigned long n, unsigned long k)+{+  mpz_t t;++  mpz_set_ui (r, k <= n);++  if (k > (n >> 1))+    k = (k <= n) ? n - k : 0;++  mpz_init (t);+  mpz_fac_ui (t, k);++  for (; k > 0; --k)+    mpz_mul_ui (r, r, n--);++  mpz_divexact (r, r, t);+  mpz_clear (t);+}+++/* Primality testing */++/* Computes Kronecker (a/b) with odd b, a!=0 and GCD(a,b) = 1 */+/* Adapted from JACOBI_BASE_METHOD==4 in mpn/generic/jacbase.c */+static int+gmp_jacobi_coprime (mp_limb_t a, mp_limb_t b)+{+  int c, bit = 0;++  assert (b & 1);+  assert (a != 0);+  /* assert (mpn_gcd_11 (a, b) == 1); */++  /* Below, we represent a and b shifted right so that the least+     significant one bit is implicit. */+  b >>= 1;++  gmp_ctz(c, a);+  a >>= 1;++  do+    {+      a >>= c;+      /* (2/b) = -1 if b = 3 or 5 mod 8 */+      bit ^= c & (b ^ (b >> 1));+      if (a < b)+	{+	  bit ^= a & b;+	  a = b - a;+	  b -= a;+	}+      else+	{+	  a -= b;+	  assert (a != 0);+	}++      gmp_ctz(c, a);+      ++c;+    }+  while (b > 0);++  return bit & 1 ? -1 : 1;+}++static void+gmp_lucas_step_k_2k (mpz_t V, mpz_t Qk, const mpz_t n)+{+  mpz_mod (Qk, Qk, n);+  /* V_{2k} <- V_k ^ 2 - 2Q^k */+  mpz_mul (V, V, V);+  mpz_submul_ui (V, Qk, 2);+  mpz_tdiv_r (V, V, n);+  /* Q^{2k} = (Q^k)^2 */+  mpz_mul (Qk, Qk, Qk);+}++/* Computes V_k, Q^k (mod n) for the Lucas' sequence */+/* with P=1, Q=Q; k = (n>>b0)|1. */+/* Requires an odd n > 4; b0 > 0; -2*Q must not overflow a long */+/* Returns (U_k == 0) and sets V=V_k and Qk=Q^k. */+static int+gmp_lucas_mod (mpz_t V, mpz_t Qk, long Q,+	       mp_bitcnt_t b0, const mpz_t n)+{+  mp_bitcnt_t bs;+  mpz_t U;+  int res;++  assert (b0 > 0);+  assert (Q <= - (LONG_MIN / 2));+  assert (Q >= - (LONG_MAX / 2));+  assert (mpz_cmp_ui (n, 4) > 0);+  assert (mpz_odd_p (n));++  mpz_init_set_ui (U, 1); /* U1 = 1 */+  mpz_set_ui (V, 1); /* V1 = 1 */+  mpz_set_si (Qk, Q);++  for (bs = mpz_sizeinbase (n, 2) - 1; --bs >= b0;)+    {+      /* U_{2k} <- U_k * V_k */+      mpz_mul (U, U, V);+      /* V_{2k} <- V_k ^ 2 - 2Q^k */+      /* Q^{2k} = (Q^k)^2 */+      gmp_lucas_step_k_2k (V, Qk, n);++      /* A step k->k+1 is performed if the bit in $n$ is 1	*/+      /* mpz_tstbit(n,bs) or the bit is 0 in $n$ but	*/+      /* should be 1 in $n+1$ (bs == b0)			*/+      if (b0 == bs || mpz_tstbit (n, bs))+	{+	  /* Q^{k+1} <- Q^k * Q */+	  mpz_mul_si (Qk, Qk, Q);+	  /* U_{k+1} <- (U_k + V_k) / 2 */+	  mpz_swap (U, V); /* Keep in V the old value of U_k */+	  mpz_add (U, U, V);+	  /* We have to compute U/2, so we need an even value, */+	  /* equivalent (mod n) */+	  if (mpz_odd_p (U))+	    mpz_add (U, U, n);+	  mpz_tdiv_q_2exp (U, U, 1);+	  /* V_{k+1} <-(D*U_k + V_k) / 2 =+			U_{k+1} + (D-1)/2*U_k = U_{k+1} - 2Q*U_k */+	  mpz_mul_si (V, V, -2*Q);+	  mpz_add (V, U, V);+	  mpz_tdiv_r (V, V, n);+	}+      mpz_tdiv_r (U, U, n);+    }++  res = U->_mp_size == 0;+  mpz_clear (U);+  return res;+}++/* Performs strong Lucas' test on x, with parameters suggested */+/* for the BPSW test. Qk is only passed to recycle a variable. */+/* Requires GCD (x,6) = 1.*/+static int+gmp_stronglucas (const mpz_t x, mpz_t Qk)+{+  mp_bitcnt_t b0;+  mpz_t V, n;+  mp_limb_t maxD, D; /* The absolute value is stored. */+  long Q;+  mp_limb_t tl;++  /* Test on the absolute value. */+  mpz_roinit_normal_n (n, x->_mp_d, GMP_ABS (x->_mp_size));++  assert (mpz_odd_p (n));+  /* assert (mpz_gcd_ui (NULL, n, 6) == 1); */+  if (mpz_root (Qk, n, 2))+    return 0; /* A square is composite. */++  /* Check Ds up to square root (in case, n is prime)+     or avoid overflows */+  maxD = (Qk->_mp_size == 1) ? Qk->_mp_d [0] - 1 : GMP_LIMB_MAX;++  D = 3;+  /* Search a D such that (D/n) = -1 in the sequence 5,-7,9,-11,.. */+  /* For those Ds we have (D/n) = (n/|D|) */+  do+    {+      if (D >= maxD)+	return 1 + (D != GMP_LIMB_MAX); /* (1 + ! ~ D) */+      D += 2;+      tl = mpz_tdiv_ui (n, D);+      if (tl == 0)+	return 0;+    }+  while (gmp_jacobi_coprime (tl, D) == 1);++  mpz_init (V);++  /* n-(D/n) = n+1 = d*2^{b0}, with d = (n>>b0) | 1 */+  b0 = mpz_scan0 (n, 0);++  /* D= P^2 - 4Q; P = 1; Q = (1-D)/4 */+  Q = (D & 2) ? (long) (D >> 2) + 1 : -(long) (D >> 2);++  if (! gmp_lucas_mod (V, Qk, Q, b0, n))	/* If Ud != 0 */+    while (V->_mp_size != 0 && --b0 != 0)	/* while Vk != 0 */+      /* V <- V ^ 2 - 2Q^k */+      /* Q^{2k} = (Q^k)^2 */+      gmp_lucas_step_k_2k (V, Qk, n);++  mpz_clear (V);+  return (b0 != 0);+}++static int+gmp_millerrabin (const mpz_t n, const mpz_t nm1, mpz_t y,+		 const mpz_t q, mp_bitcnt_t k)+{+  assert (k > 0);++  /* Caller must initialize y to the base. */+  mpz_powm (y, y, q, n);++  if (mpz_cmp_ui (y, 1) == 0 || mpz_cmp (y, nm1) == 0)+    return 1;++  while (--k > 0)+    {+      mpz_powm_ui (y, y, 2, n);+      if (mpz_cmp (y, nm1) == 0)+	return 1;+      /* y == 1 means that the previous y was a non-trivial square root+	 of 1 (mod n). y == 0 means that n is a power of the base.+	 In either case, n is not prime. */+      if (mpz_cmp_ui (y, 1) <= 0)+	return 0;+    }+  return 0;+}++/* This product is 0xc0cfd797, and fits in 32 bits. */+#define GMP_PRIME_PRODUCT \+  (3UL*5UL*7UL*11UL*13UL*17UL*19UL*23UL*29UL)++/* Bit (p+1)/2 is set, for each odd prime <= 61 */+#define GMP_PRIME_MASK 0xc96996dcUL++int+mpz_probab_prime_p (const mpz_t n, int reps)+{+  mpz_t nm1;+  mpz_t q;+  mpz_t y;+  mp_bitcnt_t k;+  int is_prime;+  int j;++  /* Note that we use the absolute value of n only, for compatibility+     with the real GMP. */+  if (mpz_even_p (n))+    return (mpz_cmpabs_ui (n, 2) == 0) ? 2 : 0;++  /* Above test excludes n == 0 */+  assert (n->_mp_size != 0);++  if (mpz_cmpabs_ui (n, 64) < 0)+    return (GMP_PRIME_MASK >> (n->_mp_d[0] >> 1)) & 2;++  if (mpz_gcd_ui (NULL, n, GMP_PRIME_PRODUCT) != 1)+    return 0;++  /* All prime factors are >= 31. */+  if (mpz_cmpabs_ui (n, 31*31) < 0)+    return 2;++  mpz_init (nm1);+  mpz_init (q);++  /* Find q and k, where q is odd and n = 1 + 2**k * q.  */+  mpz_abs (nm1, n);+  nm1->_mp_d[0] -= 1;+  k = mpz_scan1 (nm1, 0);+  mpz_tdiv_q_2exp (q, nm1, k);++  /* BPSW test */+  mpz_init_set_ui (y, 2);+  is_prime = gmp_millerrabin (n, nm1, y, q, k) && gmp_stronglucas (n, y);+  reps -= 24; /* skip the first 24 repetitions */++  /* Use Miller-Rabin, with a deterministic sequence of bases, a[j] =+     j^2 + j + 41 using Euler's polynomial. We potentially stop early,+     if a[j] >= n - 1. Since n >= 31*31, this can happen only if reps >+     30 (a[30] == 971 > 31*31 == 961). */++  for (j = 0; is_prime & (j < reps); j++)+    {+      mpz_set_ui (y, (unsigned long) j*j+j+41);+      if (mpz_cmp (y, nm1) >= 0)+	{+	  /* Don't try any further bases. This "early" break does not affect+	     the result for any reasonable reps value (<=5000 was tested) */+	  assert (j >= 30);+	  break;+	}+      is_prime = gmp_millerrabin (n, nm1, y, q, k);+    }+  mpz_clear (nm1);+  mpz_clear (q);+  mpz_clear (y);++  return is_prime;+}+++/* Logical operations and bit manipulation. */++/* Numbers are treated as if represented in two's complement (and+   infinitely sign extended). For a negative values we get the two's+   complement from -x = ~x + 1, where ~ is bitwise complement.+   Negation transforms++     xxxx10...0++   into++     yyyy10...0++   where yyyy is the bitwise complement of xxxx. So least significant+   bits, up to and including the first one bit, are unchanged, and+   the more significant bits are all complemented.++   To change a bit from zero to one in a negative number, subtract the+   corresponding power of two from the absolute value. This can never+   underflow. To change a bit from one to zero, add the corresponding+   power of two, and this might overflow. E.g., if x = -001111, the+   two's complement is 110001. Clearing the least significant bit, we+   get two's complement 110000, and -010000. */++int+mpz_tstbit (const mpz_t d, mp_bitcnt_t bit_index)+{+  mp_size_t limb_index;+  unsigned shift;+  mp_size_t ds;+  mp_size_t dn;+  mp_limb_t w;+  int bit;++  ds = d->_mp_size;+  dn = GMP_ABS (ds);+  limb_index = bit_index / GMP_LIMB_BITS;+  if (limb_index >= dn)+    return ds < 0;++  shift = bit_index % GMP_LIMB_BITS;+  w = d->_mp_d[limb_index];+  bit = (w >> shift) & 1;++  if (ds < 0)+    {+      /* d < 0. Check if any of the bits below is set: If so, our bit+	 must be complemented. */+      if (shift > 0 && (mp_limb_t) (w << (GMP_LIMB_BITS - shift)) > 0)+	return bit ^ 1;+      while (--limb_index >= 0)+	if (d->_mp_d[limb_index] > 0)+	  return bit ^ 1;+    }+  return bit;+}++static void+mpz_abs_add_bit (mpz_t d, mp_bitcnt_t bit_index)+{+  mp_size_t dn, limb_index;+  mp_limb_t bit;+  mp_ptr dp;++  dn = GMP_ABS (d->_mp_size);++  limb_index = bit_index / GMP_LIMB_BITS;+  bit = (mp_limb_t) 1 << (bit_index % GMP_LIMB_BITS);++  if (limb_index >= dn)+    {+      mp_size_t i;+      /* The bit should be set outside of the end of the number.+	 We have to increase the size of the number. */+      dp = MPZ_REALLOC (d, limb_index + 1);++      dp[limb_index] = bit;+      for (i = dn; i < limb_index; i++)+	dp[i] = 0;+      dn = limb_index + 1;+    }+  else+    {+      mp_limb_t cy;++      dp = d->_mp_d;++      cy = mpn_add_1 (dp + limb_index, dp + limb_index, dn - limb_index, bit);+      if (cy > 0)+	{+	  dp = MPZ_REALLOC (d, dn + 1);+	  dp[dn++] = cy;+	}+    }++  d->_mp_size = (d->_mp_size < 0) ? - dn : dn;+}++static void+mpz_abs_sub_bit (mpz_t d, mp_bitcnt_t bit_index)+{+  mp_size_t dn, limb_index;+  mp_ptr dp;+  mp_limb_t bit;++  dn = GMP_ABS (d->_mp_size);+  dp = d->_mp_d;++  limb_index = bit_index / GMP_LIMB_BITS;+  bit = (mp_limb_t) 1 << (bit_index % GMP_LIMB_BITS);++  assert (limb_index < dn);++  gmp_assert_nocarry (mpn_sub_1 (dp + limb_index, dp + limb_index,+				 dn - limb_index, bit));+  dn = mpn_normalized_size (dp, dn);+  d->_mp_size = (d->_mp_size < 0) ? - dn : dn;+}++void+mpz_setbit (mpz_t d, mp_bitcnt_t bit_index)+{+  if (!mpz_tstbit (d, bit_index))+    {+      if (d->_mp_size >= 0)+	mpz_abs_add_bit (d, bit_index);+      else+	mpz_abs_sub_bit (d, bit_index);+    }+}++void+mpz_clrbit (mpz_t d, mp_bitcnt_t bit_index)+{+  if (mpz_tstbit (d, bit_index))+    {+      if (d->_mp_size >= 0)+	mpz_abs_sub_bit (d, bit_index);+      else+	mpz_abs_add_bit (d, bit_index);+    }+}++void+mpz_combit (mpz_t d, mp_bitcnt_t bit_index)+{+  if (mpz_tstbit (d, bit_index) ^ (d->_mp_size < 0))+    mpz_abs_sub_bit (d, bit_index);+  else+    mpz_abs_add_bit (d, bit_index);+}++void+mpz_com (mpz_t r, const mpz_t u)+{+  mpz_add_ui (r, u, 1);+  mpz_neg (r, r);+}++void+mpz_and (mpz_t r, const mpz_t u, const mpz_t v)+{+  mp_size_t un, vn, rn, i;+  mp_ptr up, vp, rp;++  mp_limb_t ux, vx, rx;+  mp_limb_t uc, vc, rc;+  mp_limb_t ul, vl, rl;++  un = GMP_ABS (u->_mp_size);+  vn = GMP_ABS (v->_mp_size);+  if (un < vn)+    {+      MPZ_SRCPTR_SWAP (u, v);+      MP_SIZE_T_SWAP (un, vn);+    }+  if (vn == 0)+    {+      r->_mp_size = 0;+      return;+    }++  uc = u->_mp_size < 0;+  vc = v->_mp_size < 0;+  rc = uc & vc;++  ux = -uc;+  vx = -vc;+  rx = -rc;++  /* If the smaller input is positive, higher limbs don't matter. */+  rn = vx ? un : vn;++  rp = MPZ_REALLOC (r, rn + (mp_size_t) rc);++  up = u->_mp_d;+  vp = v->_mp_d;++  i = 0;+  do+    {+      ul = (up[i] ^ ux) + uc;+      uc = ul < uc;++      vl = (vp[i] ^ vx) + vc;+      vc = vl < vc;++      rl = ( (ul & vl) ^ rx) + rc;+      rc = rl < rc;+      rp[i] = rl;+    }+  while (++i < vn);+  assert (vc == 0);++  for (; i < rn; i++)+    {+      ul = (up[i] ^ ux) + uc;+      uc = ul < uc;++      rl = ( (ul & vx) ^ rx) + rc;+      rc = rl < rc;+      rp[i] = rl;+    }+  if (rc)+    rp[rn++] = rc;+  else+    rn = mpn_normalized_size (rp, rn);++  r->_mp_size = rx ? -rn : rn;+}++void+mpz_ior (mpz_t r, const mpz_t u, const mpz_t v)+{+  mp_size_t un, vn, rn, i;+  mp_ptr up, vp, rp;++  mp_limb_t ux, vx, rx;+  mp_limb_t uc, vc, rc;+  mp_limb_t ul, vl, rl;++  un = GMP_ABS (u->_mp_size);+  vn = GMP_ABS (v->_mp_size);+  if (un < vn)+    {+      MPZ_SRCPTR_SWAP (u, v);+      MP_SIZE_T_SWAP (un, vn);+    }+  if (vn == 0)+    {+      mpz_set (r, u);+      return;+    }++  uc = u->_mp_size < 0;+  vc = v->_mp_size < 0;+  rc = uc | vc;++  ux = -uc;+  vx = -vc;+  rx = -rc;++  /* If the smaller input is negative, by sign extension higher limbs+     don't matter. */+  rn = vx ? vn : un;++  rp = MPZ_REALLOC (r, rn + (mp_size_t) rc);++  up = u->_mp_d;+  vp = v->_mp_d;++  i = 0;+  do+    {+      ul = (up[i] ^ ux) + uc;+      uc = ul < uc;++      vl = (vp[i] ^ vx) + vc;+      vc = vl < vc;++      rl = ( (ul | vl) ^ rx) + rc;+      rc = rl < rc;+      rp[i] = rl;+    }+  while (++i < vn);+  assert (vc == 0);++  for (; i < rn; i++)+    {+      ul = (up[i] ^ ux) + uc;+      uc = ul < uc;++      rl = ( (ul | vx) ^ rx) + rc;+      rc = rl < rc;+      rp[i] = rl;+    }+  if (rc)+    rp[rn++] = rc;+  else+    rn = mpn_normalized_size (rp, rn);++  r->_mp_size = rx ? -rn : rn;+}++void+mpz_xor (mpz_t r, const mpz_t u, const mpz_t v)+{+  mp_size_t un, vn, i;+  mp_ptr up, vp, rp;++  mp_limb_t ux, vx, rx;+  mp_limb_t uc, vc, rc;+  mp_limb_t ul, vl, rl;++  un = GMP_ABS (u->_mp_size);+  vn = GMP_ABS (v->_mp_size);+  if (un < vn)+    {+      MPZ_SRCPTR_SWAP (u, v);+      MP_SIZE_T_SWAP (un, vn);+    }+  if (vn == 0)+    {+      mpz_set (r, u);+      return;+    }++  uc = u->_mp_size < 0;+  vc = v->_mp_size < 0;+  rc = uc ^ vc;++  ux = -uc;+  vx = -vc;+  rx = -rc;++  rp = MPZ_REALLOC (r, un + (mp_size_t) rc);++  up = u->_mp_d;+  vp = v->_mp_d;++  i = 0;+  do+    {+      ul = (up[i] ^ ux) + uc;+      uc = ul < uc;++      vl = (vp[i] ^ vx) + vc;+      vc = vl < vc;++      rl = (ul ^ vl ^ rx) + rc;+      rc = rl < rc;+      rp[i] = rl;+    }+  while (++i < vn);+  assert (vc == 0);++  for (; i < un; i++)+    {+      ul = (up[i] ^ ux) + uc;+      uc = ul < uc;++      rl = (ul ^ ux) + rc;+      rc = rl < rc;+      rp[i] = rl;+    }+  if (rc)+    rp[un++] = rc;+  else+    un = mpn_normalized_size (rp, un);++  r->_mp_size = rx ? -un : un;+}++static unsigned+gmp_popcount_limb (mp_limb_t x)+{+  unsigned c;++  /* Do 16 bits at a time, to avoid limb-sized constants. */+  int LOCAL_SHIFT_BITS = 16;+  for (c = 0; x > 0;)+    {+      unsigned w = x - ((x >> 1) & 0x5555);+      w = ((w >> 2) & 0x3333) + (w & 0x3333);+      w =  (w >> 4) + w;+      w = ((w >> 8) & 0x000f) + (w & 0x000f);+      c += w;+      if (GMP_LIMB_BITS > LOCAL_SHIFT_BITS)+	x >>= LOCAL_SHIFT_BITS;+      else+	x = 0;+    }+  return c;+}++mp_bitcnt_t+mpn_popcount (mp_srcptr p, mp_size_t n)+{+  mp_size_t i;+  mp_bitcnt_t c;++  for (c = 0, i = 0; i < n; i++)+    c += gmp_popcount_limb (p[i]);++  return c;+}++mp_bitcnt_t+mpz_popcount (const mpz_t u)+{+  mp_size_t un;++  un = u->_mp_size;++  if (un < 0)+    return ~(mp_bitcnt_t) 0;++  return mpn_popcount (u->_mp_d, un);+}++mp_bitcnt_t+mpz_hamdist (const mpz_t u, const mpz_t v)+{+  mp_size_t un, vn, i;+  mp_limb_t uc, vc, ul, vl, comp;+  mp_srcptr up, vp;+  mp_bitcnt_t c;++  un = u->_mp_size;+  vn = v->_mp_size;++  if ( (un ^ vn) < 0)+    return ~(mp_bitcnt_t) 0;++  comp = - (uc = vc = (un < 0));+  if (uc)+    {+      assert (vn < 0);+      un = -un;+      vn = -vn;+    }++  up = u->_mp_d;+  vp = v->_mp_d;++  if (un < vn)+    MPN_SRCPTR_SWAP (up, un, vp, vn);++  for (i = 0, c = 0; i < vn; i++)+    {+      ul = (up[i] ^ comp) + uc;+      uc = ul < uc;++      vl = (vp[i] ^ comp) + vc;+      vc = vl < vc;++      c += gmp_popcount_limb (ul ^ vl);+    }+  assert (vc == 0);++  for (; i < un; i++)+    {+      ul = (up[i] ^ comp) + uc;+      uc = ul < uc;++      c += gmp_popcount_limb (ul ^ comp);+    }++  return c;+}++mp_bitcnt_t+mpz_scan1 (const mpz_t u, mp_bitcnt_t starting_bit)+{+  mp_ptr up;+  mp_size_t us, un, i;+  mp_limb_t limb, ux;++  us = u->_mp_size;+  un = GMP_ABS (us);+  i = starting_bit / GMP_LIMB_BITS;++  /* Past the end there's no 1 bits for u>=0, or an immediate 1 bit+     for u<0. Notice this test picks up any u==0 too. */+  if (i >= un)+    return (us >= 0 ? ~(mp_bitcnt_t) 0 : starting_bit);++  up = u->_mp_d;+  ux = 0;+  limb = up[i];++  if (starting_bit != 0)+    {+      if (us < 0)+	{+	  ux = mpn_zero_p (up, i);+	  limb = ~ limb + ux;+	  ux = - (mp_limb_t) (limb >= ux);+	}++      /* Mask to 0 all bits before starting_bit, thus ignoring them. */+      limb &= GMP_LIMB_MAX << (starting_bit % GMP_LIMB_BITS);+    }++  return mpn_common_scan (limb, i, up, un, ux);+}++mp_bitcnt_t+mpz_scan0 (const mpz_t u, mp_bitcnt_t starting_bit)+{+  mp_ptr up;+  mp_size_t us, un, i;+  mp_limb_t limb, ux;++  us = u->_mp_size;+  ux = - (mp_limb_t) (us >= 0);+  un = GMP_ABS (us);+  i = starting_bit / GMP_LIMB_BITS;++  /* When past end, there's an immediate 0 bit for u>=0, or no 0 bits for+     u<0.  Notice this test picks up all cases of u==0 too. */+  if (i >= un)+    return (ux ? starting_bit : ~(mp_bitcnt_t) 0);++  up = u->_mp_d;+  limb = up[i] ^ ux;++  if (ux == 0)+    limb -= mpn_zero_p (up, i); /* limb = ~(~limb + zero_p) */++  /* Mask all bits before starting_bit, thus ignoring them. */+  limb &= GMP_LIMB_MAX << (starting_bit % GMP_LIMB_BITS);++  return mpn_common_scan (limb, i, up, un, ux);+}+++/* MPZ base conversion. */++size_t+mpz_sizeinbase (const mpz_t u, int base)+{+  mp_size_t un;+  mp_srcptr up;+  mp_ptr tp;+  mp_bitcnt_t bits;+  struct gmp_div_inverse bi;+  size_t ndigits;++  assert (base >= 2);+  assert (base <= 62);++  un = GMP_ABS (u->_mp_size);+  if (un == 0)+    return 1;++  up = u->_mp_d;++  bits = (un - 1) * GMP_LIMB_BITS + mpn_limb_size_in_base_2 (up[un-1]);+  switch (base)+    {+    case 2:+      return bits;+    case 4:+      return (bits + 1) / 2;+    case 8:+      return (bits + 2) / 3;+    case 16:+      return (bits + 3) / 4;+    case 32:+      return (bits + 4) / 5;+      /* FIXME: Do something more clever for the common case of base+	 10. */+    }++  tp = gmp_xalloc_limbs (un);+  mpn_copyi (tp, up, un);+  mpn_div_qr_1_invert (&bi, base);++  ndigits = 0;+  do+    {+      ndigits++;+      mpn_div_qr_1_preinv (tp, tp, un, &bi);+      un -= (tp[un-1] == 0);+    }+  while (un > 0);++  gmp_free (tp);+  return ndigits;+}++char *+mpz_get_str (char *sp, int base, const mpz_t u)+{+  unsigned bits;+  const char *digits;+  mp_size_t un;+  size_t i, sn;++  digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";+  if (base > 1)+    {+      if (base <= 36)+	digits = "0123456789abcdefghijklmnopqrstuvwxyz";+      else if (base > 62)+	return NULL;+    }+  else if (base >= -1)+    base = 10;+  else+    {+      base = -base;+      if (base > 36)+	return NULL;+    }++  sn = 1 + mpz_sizeinbase (u, base);+  if (!sp)+    sp = (char *) gmp_xalloc (1 + sn);++  un = GMP_ABS (u->_mp_size);++  if (un == 0)+    {+      sp[0] = '0';+      sp[1] = '\0';+      return sp;+    }++  i = 0;++  if (u->_mp_size < 0)+    sp[i++] = '-';++  bits = mpn_base_power_of_two_p (base);++  if (bits)+    /* Not modified in this case. */+    sn = i + mpn_get_str_bits ((unsigned char *) sp + i, bits, u->_mp_d, un);+  else+    {+      struct mpn_base_info info;+      mp_ptr tp;++      mpn_get_base_info (&info, base);+      tp = gmp_xalloc_limbs (un);+      mpn_copyi (tp, u->_mp_d, un);++      sn = i + mpn_get_str_other ((unsigned char *) sp + i, base, &info, tp, un);+      gmp_free (tp);+    }++  for (; i < sn; i++)+    sp[i] = digits[(unsigned char) sp[i]];++  sp[sn] = '\0';+  return sp;+}++int+mpz_set_str (mpz_t r, const char *sp, int base)+{+  unsigned bits, value_of_a;+  mp_size_t rn, alloc;+  mp_ptr rp;+  size_t dn;+  int sign;+  unsigned char *dp;++  assert (base == 0 || (base >= 2 && base <= 62));++  while (isspace( (unsigned char) *sp))+    sp++;++  sign = (*sp == '-');+  sp += sign;++  if (base == 0)+    {+      if (sp[0] == '0')+	{+	  if (sp[1] == 'x' || sp[1] == 'X')+	    {+	      base = 16;+	      sp += 2;+	    }+	  else if (sp[1] == 'b' || sp[1] == 'B')+	    {+	      base = 2;+	      sp += 2;+	    }+	  else+	    base = 8;+	}+      else+	base = 10;+    }++  if (!*sp)+    {+      r->_mp_size = 0;+      return -1;+    }+  dp = (unsigned char *) gmp_xalloc (strlen (sp));++  value_of_a = (base > 36) ? 36 : 10;+  for (dn = 0; *sp; sp++)+    {+      unsigned digit;++      if (isspace ((unsigned char) *sp))+	continue;+      else if (*sp >= '0' && *sp <= '9')+	digit = *sp - '0';+      else if (*sp >= 'a' && *sp <= 'z')+	digit = *sp - 'a' + value_of_a;+      else if (*sp >= 'A' && *sp <= 'Z')+	digit = *sp - 'A' + 10;+      else+	digit = base; /* fail */++      if (digit >= (unsigned) base)+	{+	  gmp_free (dp);+	  r->_mp_size = 0;+	  return -1;+	}++      dp[dn++] = digit;+    }++  if (!dn)+    {+      gmp_free (dp);+      r->_mp_size = 0;+      return -1;+    }+  bits = mpn_base_power_of_two_p (base);++  if (bits > 0)+    {+      alloc = (dn * bits + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;+      rp = MPZ_REALLOC (r, alloc);+      rn = mpn_set_str_bits (rp, dp, dn, bits);+    }+  else+    {+      struct mpn_base_info info;+      mpn_get_base_info (&info, base);+      alloc = (dn + info.exp - 1) / info.exp;+      rp = MPZ_REALLOC (r, alloc);+      rn = mpn_set_str_other (rp, dp, dn, base, &info);+      /* Normalization, needed for all-zero input. */+      assert (rn > 0);+      rn -= rp[rn-1] == 0;+    }+  assert (rn <= alloc);+  gmp_free (dp);++  r->_mp_size = sign ? - rn : rn;++  return 0;+}++int+mpz_init_set_str (mpz_t r, const char *sp, int base)+{+  mpz_init (r);+  return mpz_set_str (r, sp, base);+}++size_t+mpz_out_str (FILE *stream, int base, const mpz_t x)+{+  char *str;+  size_t len;++  str = mpz_get_str (NULL, base, x);+  if (!str)+    return 0;+  len = strlen (str);+  len = fwrite (str, 1, len, stream);+  gmp_free (str);+  return len;+}+++static int+gmp_detect_endian (void)+{+  static const int i = 2;+  const unsigned char *p = (const unsigned char *) &i;+  return 1 - *p;+}++/* Import and export. Does not support nails. */+void+mpz_import (mpz_t r, size_t count, int order, size_t size, int endian,+	    size_t nails, const void *src)+{+  const unsigned char *p;+  ptrdiff_t word_step;+  mp_ptr rp;+  mp_size_t rn;++  /* The current (partial) limb. */+  mp_limb_t limb;+  /* The number of bytes already copied to this limb (starting from+     the low end). */+  size_t bytes;+  /* The index where the limb should be stored, when completed. */+  mp_size_t i;++  if (nails != 0)+    gmp_die ("mpz_import: Nails not supported.");++  assert (order == 1 || order == -1);+  assert (endian >= -1 && endian <= 1);++  if (endian == 0)+    endian = gmp_detect_endian ();++  p = (unsigned char *) src;++  word_step = (order != endian) ? 2 * size : 0;++  /* Process bytes from the least significant end, so point p at the+     least significant word. */+  if (order == 1)+    {+      p += size * (count - 1);+      word_step = - word_step;+    }++  /* And at least significant byte of that word. */+  if (endian == 1)+    p += (size - 1);++  rn = (size * count + sizeof(mp_limb_t) - 1) / sizeof(mp_limb_t);+  rp = MPZ_REALLOC (r, rn);++  for (limb = 0, bytes = 0, i = 0; count > 0; count--, p += word_step)+    {+      size_t j;+      for (j = 0; j < size; j++, p -= (ptrdiff_t) endian)+	{+	  limb |= (mp_limb_t) *p << (bytes++ * CHAR_BIT);+	  if (bytes == sizeof(mp_limb_t))+	    {+	      rp[i++] = limb;+	      bytes = 0;+	      limb = 0;+	    }+	}+    }+  assert (i + (bytes > 0) == rn);+  if (limb != 0)+    rp[i++] = limb;+  else+    i = mpn_normalized_size (rp, i);++  r->_mp_size = i;+}++void *+mpz_export (void *r, size_t *countp, int order, size_t size, int endian,+	    size_t nails, const mpz_t u)+{+  size_t count;+  mp_size_t un;++  if (nails != 0)+    gmp_die ("mpz_import: Nails not supported.");++  assert (order == 1 || order == -1);+  assert (endian >= -1 && endian <= 1);+  assert (size > 0 || u->_mp_size == 0);++  un = u->_mp_size;+  count = 0;+  if (un != 0)+    {+      size_t k;+      unsigned char *p;+      ptrdiff_t word_step;+      /* The current (partial) limb. */+      mp_limb_t limb;+      /* The number of bytes left to do in this limb. */+      size_t bytes;+      /* The index where the limb was read. */+      mp_size_t i;++      un = GMP_ABS (un);++      /* Count bytes in top limb. */+      limb = u->_mp_d[un-1];+      assert (limb != 0);++      k = (GMP_LIMB_BITS <= CHAR_BIT);+      if (!k)+	{+	  do {+	    int LOCAL_CHAR_BIT = CHAR_BIT;+	    k++; limb >>= LOCAL_CHAR_BIT;+	  } while (limb != 0);+	}+      /* else limb = 0; */++      count = (k + (un-1) * sizeof (mp_limb_t) + size - 1) / size;++      if (!r)+	r = gmp_xalloc (count * size);++      if (endian == 0)+	endian = gmp_detect_endian ();++      p = (unsigned char *) r;++      word_step = (order != endian) ? 2 * size : 0;++      /* Process bytes from the least significant end, so point p at the+	 least significant word. */+      if (order == 1)+	{+	  p += size * (count - 1);+	  word_step = - word_step;+	}++      /* And at least significant byte of that word. */+      if (endian == 1)+	p += (size - 1);++      for (bytes = 0, i = 0, k = 0; k < count; k++, p += word_step)+	{+	  size_t j;+	  for (j = 0; j < size; ++j, p -= (ptrdiff_t) endian)+	    {+	      if (sizeof (mp_limb_t) == 1)+		{+		  if (i < un)+		    *p = u->_mp_d[i++];+		  else+		    *p = 0;+		}+	      else+		{+		  int LOCAL_CHAR_BIT = CHAR_BIT;+		  if (bytes == 0)+		    {+		      if (i < un)+			limb = u->_mp_d[i++];+		      bytes = sizeof (mp_limb_t);+		    }+		  *p = limb;+		  limb >>= LOCAL_CHAR_BIT;+		  bytes--;+		}+	    }+	}+      assert (i == un);+      assert (k == count);+    }++  if (countp)+    *countp = count;++  return r;+}
+ vendor/external/gmp/mini-gmp.h view
@@ -0,0 +1,309 @@+/* mini-gmp, a minimalistic implementation of a GNU GMP subset.++Copyright 2011-2015, 2017, 2019-2020 Free Software Foundation, Inc.++This file is part of the GNU MP Library.++The GNU MP Library is free software; you can redistribute it and/or modify+it under the terms of either:++  * the GNU Lesser General Public License as published by the Free+    Software Foundation; either version 3 of the License, or (at your+    option) any later version.++or++  * the GNU General Public License as published by the Free Software+    Foundation; either version 2 of the License, or (at your option) any+    later version.++or both in parallel, as here.++The GNU MP Library is distributed in the hope that it will be useful, but+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License+for more details.++You should have received copies of the GNU General Public License and the+GNU Lesser General Public License along with the GNU MP Library.  If not,+see https://www.gnu.org/licenses/.  */++/* About mini-gmp: This is a minimal implementation of a subset of the+   GMP interface. It is intended for inclusion into applications which+   have modest bignums needs, as a fallback when the real GMP library+   is not installed.++   This file defines the public interface. */++#ifndef __MINI_GMP_H__+#define __MINI_GMP_H__++/* For size_t */+#include <stddef.h>++#if defined(__EMSCRIPTEN__)+#include <emscripten.h>+#endif++#if defined (__cplusplus)+extern "C" {+#endif++void mp_set_memory_functions (void *(*) (size_t),+			      void *(*) (void *, size_t, size_t),+			      void (*) (void *, size_t));++void mp_get_memory_functions (void *(**) (size_t),+			      void *(**) (void *, size_t, size_t),+			      void (**) (void *, size_t));++#ifndef MINI_GMP_LIMB_TYPE+#define MINI_GMP_LIMB_TYPE long+#endif++typedef unsigned MINI_GMP_LIMB_TYPE mp_limb_t;+typedef long mp_size_t;+typedef unsigned long mp_bitcnt_t;++typedef mp_limb_t *mp_ptr;+typedef const mp_limb_t *mp_srcptr;++typedef struct+{+  int _mp_alloc;		/* Number of *limbs* allocated and pointed+				   to by the _mp_d field.  */+  int _mp_size;			/* abs(_mp_size) is the number of limbs the+				   last field points to.  If _mp_size is+				   negative this is a negative number.  */+  mp_limb_t *_mp_d;		/* Pointer to the limbs.  */+} __mpz_struct;++typedef __mpz_struct mpz_t[1];++typedef __mpz_struct *mpz_ptr;+typedef const __mpz_struct *mpz_srcptr;++extern const int mp_bits_per_limb;++void mpn_copyi (mp_ptr, mp_srcptr, mp_size_t);+void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t);+void mpn_zero (mp_ptr, mp_size_t);++int mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t);+int mpn_zero_p (mp_srcptr, mp_size_t);++mp_limb_t mpn_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);+mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);+mp_limb_t mpn_add (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);++mp_limb_t mpn_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);+mp_limb_t mpn_sub_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);+mp_limb_t mpn_sub (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);++mp_limb_t mpn_mul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);+mp_limb_t mpn_addmul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);+mp_limb_t mpn_submul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);++mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);+void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);+void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t);+int mpn_perfect_square_p (mp_srcptr, mp_size_t);+mp_size_t mpn_sqrtrem (mp_ptr, mp_ptr, mp_srcptr, mp_size_t);++mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int);+mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int);++mp_bitcnt_t mpn_scan0 (mp_srcptr, mp_bitcnt_t);+mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t);++void mpn_com (mp_ptr, mp_srcptr, mp_size_t);+mp_limb_t mpn_neg (mp_ptr, mp_srcptr, mp_size_t);++mp_bitcnt_t mpn_popcount (mp_srcptr, mp_size_t);++mp_limb_t mpn_invert_3by2 (mp_limb_t, mp_limb_t);+#define mpn_invert_limb(x) mpn_invert_3by2 ((x), 0)++size_t mpn_get_str (unsigned char *, int, mp_ptr, mp_size_t);+mp_size_t mpn_set_str (mp_ptr, const unsigned char *, size_t, int);++void mpz_init (mpz_t);+void mpz_init2 (mpz_t, mp_bitcnt_t);+void mpz_clear (mpz_t);++#define mpz_odd_p(z)   (((z)->_mp_size != 0) & (int) (z)->_mp_d[0])+#define mpz_even_p(z)  (! mpz_odd_p (z))++int mpz_sgn (const mpz_t);+int mpz_cmp_si (const mpz_t, long);+int mpz_cmp_ui (const mpz_t, unsigned long);+int mpz_cmp (const mpz_t, const mpz_t);+int mpz_cmpabs_ui (const mpz_t, unsigned long);+int mpz_cmpabs (const mpz_t, const mpz_t);+int mpz_cmp_d (const mpz_t, double);+int mpz_cmpabs_d (const mpz_t, double);++void mpz_abs (mpz_t, const mpz_t);+void mpz_neg (mpz_t, const mpz_t);+void mpz_swap (mpz_t, mpz_t);++void mpz_add_ui (mpz_t, const mpz_t, unsigned long);+void mpz_add (mpz_t, const mpz_t, const mpz_t);+void mpz_sub_ui (mpz_t, const mpz_t, unsigned long);+void mpz_ui_sub (mpz_t, unsigned long, const mpz_t);+void mpz_sub (mpz_t, const mpz_t, const mpz_t);++void mpz_mul_si (mpz_t, const mpz_t, long int);+void mpz_mul_ui (mpz_t, const mpz_t, unsigned long int);+void mpz_mul (mpz_t, const mpz_t, const mpz_t);+void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t);+void mpz_addmul_ui (mpz_t, const mpz_t, unsigned long int);+void mpz_addmul (mpz_t, const mpz_t, const mpz_t);+void mpz_submul_ui (mpz_t, const mpz_t, unsigned long int);+void mpz_submul (mpz_t, const mpz_t, const mpz_t);++void mpz_cdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);+void mpz_fdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);+void mpz_tdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);+void mpz_cdiv_q (mpz_t, const mpz_t, const mpz_t);+void mpz_fdiv_q (mpz_t, const mpz_t, const mpz_t);+void mpz_tdiv_q (mpz_t, const mpz_t, const mpz_t);+void mpz_cdiv_r (mpz_t, const mpz_t, const mpz_t);+void mpz_fdiv_r (mpz_t, const mpz_t, const mpz_t);+void mpz_tdiv_r (mpz_t, const mpz_t, const mpz_t);++void mpz_cdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);+void mpz_fdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);+void mpz_tdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);+void mpz_cdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t);+void mpz_fdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t);+void mpz_tdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t);++void mpz_mod (mpz_t, const mpz_t, const mpz_t);++void mpz_divexact (mpz_t, const mpz_t, const mpz_t);++int mpz_divisible_p (const mpz_t, const mpz_t);+int mpz_congruent_p (const mpz_t, const mpz_t, const mpz_t);++unsigned long mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long);+unsigned long mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long);+unsigned long mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long);+unsigned long mpz_cdiv_q_ui (mpz_t, const mpz_t, unsigned long);+unsigned long mpz_fdiv_q_ui (mpz_t, const mpz_t, unsigned long);+unsigned long mpz_tdiv_q_ui (mpz_t, const mpz_t, unsigned long);+unsigned long mpz_cdiv_r_ui (mpz_t, const mpz_t, unsigned long);+unsigned long mpz_fdiv_r_ui (mpz_t, const mpz_t, unsigned long);+unsigned long mpz_tdiv_r_ui (mpz_t, const mpz_t, unsigned long);+unsigned long mpz_cdiv_ui (const mpz_t, unsigned long);+unsigned long mpz_fdiv_ui (const mpz_t, unsigned long);+unsigned long mpz_tdiv_ui (const mpz_t, unsigned long);++unsigned long mpz_mod_ui (mpz_t, const mpz_t, unsigned long);++void mpz_divexact_ui (mpz_t, const mpz_t, unsigned long);++int mpz_divisible_ui_p (const mpz_t, unsigned long);++unsigned long mpz_gcd_ui (mpz_t, const mpz_t, unsigned long);+void mpz_gcd (mpz_t, const mpz_t, const mpz_t);+void mpz_gcdext (mpz_t, mpz_t, mpz_t, const mpz_t, const mpz_t);+void mpz_lcm_ui (mpz_t, const mpz_t, unsigned long);+void mpz_lcm (mpz_t, const mpz_t, const mpz_t);+int mpz_invert (mpz_t, const mpz_t, const mpz_t);++void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t);+void mpz_sqrt (mpz_t, const mpz_t);+int mpz_perfect_square_p (const mpz_t);++void mpz_pow_ui (mpz_t, const mpz_t, unsigned long);+void mpz_ui_pow_ui (mpz_t, unsigned long, unsigned long);+void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t);+void mpz_powm_ui (mpz_t, const mpz_t, unsigned long, const mpz_t);++void mpz_rootrem (mpz_t, mpz_t, const mpz_t, unsigned long);+int mpz_root (mpz_t, const mpz_t, unsigned long);++void mpz_fac_ui (mpz_t, unsigned long);+void mpz_2fac_ui (mpz_t, unsigned long);+void mpz_mfac_uiui (mpz_t, unsigned long, unsigned long);+void mpz_bin_uiui (mpz_t, unsigned long, unsigned long);++int mpz_probab_prime_p (const mpz_t, int);++int mpz_tstbit (const mpz_t, mp_bitcnt_t);+void mpz_setbit (mpz_t, mp_bitcnt_t);+void mpz_clrbit (mpz_t, mp_bitcnt_t);+void mpz_combit (mpz_t, mp_bitcnt_t);++void mpz_com (mpz_t, const mpz_t);+void mpz_and (mpz_t, const mpz_t, const mpz_t);+void mpz_ior (mpz_t, const mpz_t, const mpz_t);+void mpz_xor (mpz_t, const mpz_t, const mpz_t);++mp_bitcnt_t mpz_popcount (const mpz_t);+mp_bitcnt_t mpz_hamdist (const mpz_t, const mpz_t);+mp_bitcnt_t mpz_scan0 (const mpz_t, mp_bitcnt_t);+mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t);++int mpz_fits_slong_p (const mpz_t);+int mpz_fits_ulong_p (const mpz_t);+long int mpz_get_si (const mpz_t);+unsigned long int mpz_get_ui (const mpz_t);+double mpz_get_d (const mpz_t);+size_t mpz_size (const mpz_t);+mp_limb_t mpz_getlimbn (const mpz_t, mp_size_t);++void mpz_realloc2 (mpz_t, mp_bitcnt_t);+mp_srcptr mpz_limbs_read (mpz_srcptr);+mp_ptr mpz_limbs_modify (mpz_t, mp_size_t);+mp_ptr mpz_limbs_write (mpz_t, mp_size_t);+void mpz_limbs_finish (mpz_t, mp_size_t);+mpz_srcptr mpz_roinit_n (mpz_t, mp_srcptr, mp_size_t);++#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}++void mpz_set_si (mpz_t, signed long int);+void mpz_set_ui (mpz_t, unsigned long int);+void mpz_set (mpz_t, const mpz_t);+void mpz_set_d (mpz_t, double);++void mpz_init_set_si (mpz_t, signed long int);+void mpz_init_set_ui (mpz_t, unsigned long int);+void mpz_init_set (mpz_t, const mpz_t);+void mpz_init_set_d (mpz_t, double);++size_t mpz_sizeinbase (const mpz_t, int);+char *mpz_get_str (char *, int, const mpz_t);+int mpz_set_str (mpz_t, const char *, int);+int mpz_init_set_str (mpz_t, const char *, int);++/* This long list taken from gmp.h. */+/* For reference, "defined(EOF)" cannot be used here.  In g++ 2.95.4,+   <iostream> defines EOF but not FILE.  */+#if defined (FILE)                                              \+  || defined (H_STDIO)                                          \+  || defined (_H_STDIO)               /* AIX */                 \+  || defined (_STDIO_H)               /* glibc, Sun, SCO */     \+  || defined (_STDIO_H_)              /* BSD, OSF */            \+  || defined (__STDIO_H)              /* Borland */             \+  || defined (__STDIO_H__)            /* IRIX */                \+  || defined (_STDIO_INCLUDED)        /* HPUX */                \+  || defined (__dj_include_stdio_h_)  /* DJGPP */               \+  || defined (_FILE_DEFINED)          /* Microsoft */           \+  || defined (__STDIO__)              /* Apple MPW MrC */       \+  || defined (_MSL_STDIO_H)           /* Metrowerks */          \+  || defined (_STDIO_H_INCLUDED)      /* QNX4 */		\+  || defined (_ISO_STDIO_ISO_H)       /* Sun C++ */		\+  || defined (__STDIO_LOADED)         /* VMS */			\+  || defined (__DEFINED_FILE)         /* musl */+size_t mpz_out_str (FILE *, int, const mpz_t);+#endif++void mpz_import (mpz_t, size_t, int, size_t, int, size_t, const void *);+void *mpz_export (void *, size_t *, int, size_t, int, size_t, const mpz_t);++#if defined (__cplusplus)+}+#endif+#endif /* __MINI_GMP_H__ */
+ vendor/external/libsodium/LICENSE view
@@ -0,0 +1,18 @@+/*+ * ISC License+ *+ * Copyright (c) 2013-2023+ * Frank Denis <j at pureftpd dot org>+ *+ * Permission to use, copy, modify, and/or distribute this software for any+ * purpose with or without fee is hereby granted, provided that the above+ * copyright notice and this permission notice appear in all copies.+ *+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.+ */
+ vendor/external/libsodium/README.markdown view
@@ -0,0 +1,46 @@+[![GitHub CI](https://github.com/jedisct1/libsodium/workflows/CI/badge.svg)](https://github.com/jedisct1/libsodium/actions)+[![Windows build status](https://ci.appveyor.com/api/projects/status/fu8s2elx25il98hj?svg=true)](https://ci.appveyor.com/project/jedisct1/libsodium)+[![Coverity Scan Build Status](https://scan.coverity.com/projects/2397/badge.svg)](https://scan.coverity.com/projects/2397)+[![Azure build status](https://jedisct1.visualstudio.com/Libsodium/_apis/build/status/jedisct1.libsodium?branchName=stable)](https://jedisct1.visualstudio.com/Libsodium/_build/latest?definitionId=3&branchName=stable)+[![CodeQL scan](https://github.com/jedisct1/libsodium/workflows/CodeQL%20scan/badge.svg)](https://github.com/jedisct1/libsodium/actions)++![libsodium](https://raw.github.com/jedisct1/libsodium/master/logo.png)+============++Sodium is a new, easy-to-use software library for encryption,+decryption, signatures, password hashing and more.++It is a portable, cross-compilable, installable, packageable+fork of [NaCl](http://nacl.cr.yp.to/), with a compatible API, and an+extended API to improve usability even further.++Its goal is to provide all of the core operations needed to build+higher-level cryptographic tools.++Sodium supports a variety of compilers and operating systems,+including Windows (with MingW or Visual Studio, x86 and x64), iOS, Android,+as well as Javascript and Webassembly.++## Documentation++The documentation is available on Gitbook and built from the+[libsodium-doc](https://github.com/jedisct1/libsodium-doc) repository:++* [libsodium documentation](https://doc.libsodium.org) - online, requires Javascript.++## Integrity Checking++The integrity checking instructions (including the signing key for libsodium)+are available in the [installation](https://download.libsodium.org/doc/installation#integrity-checking)+section of the documentation.++## Community++A mailing-list is available to discuss libsodium.++In order to join, just send a random mail to `sodium-subscribe` {at}+`pureftpd` {dot} `org`.++## License++[ISC license](https://en.wikipedia.org/wiki/ISC_license).
+ vendor/external/libsodium/crypto_aead/chacha20poly1305/aead_chacha20poly1305.c view
@@ -0,0 +1,400 @@++#include <stdint.h>+#include <stdlib.h>+#include <limits.h>+#include <string.h>++#include "core.h"+#include "crypto_aead_chacha20poly1305.h"+#include "crypto_onetimeauth_poly1305.h"+#include "crypto_stream_chacha20.h"+#include "crypto_verify_16.h"+#include "randombytes.h"+#include "utils.h"++#include "private/chacha20_ietf_ext.h"+#include "private/common.h"++static const unsigned char _pad0[16] = { 0 };++int+crypto_aead_chacha20poly1305_encrypt_detached(unsigned char *c,+                                              unsigned char *mac,+                                              unsigned long long *maclen_p,+                                              const unsigned char *m,+                                              unsigned long long mlen,+                                              const unsigned char *ad,+                                              unsigned long long adlen,+                                              const unsigned char *nsec,+                                              const unsigned char *npub,+                                              const unsigned char *k)+{+    crypto_onetimeauth_poly1305_state state;+    unsigned char                     block0[64U];+    unsigned char                     slen[8U];++    (void) nsec;+    crypto_stream_chacha20(block0, sizeof block0, npub, k);+    crypto_onetimeauth_poly1305_init(&state, block0);+    sodium_memzero(block0, sizeof block0);++    crypto_onetimeauth_poly1305_update(&state, ad, adlen);+    STORE64_LE(slen, (uint64_t) adlen);+    crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);++    crypto_stream_chacha20_xor_ic(c, m, mlen, npub, 1U, k);++    crypto_onetimeauth_poly1305_update(&state, c, mlen);+    STORE64_LE(slen, (uint64_t) mlen);+    crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);++    crypto_onetimeauth_poly1305_final(&state, mac);+    sodium_memzero(&state, sizeof state);++    if (maclen_p != NULL) {+        *maclen_p = crypto_aead_chacha20poly1305_ABYTES;+    }+    return 0;+}++int+crypto_aead_chacha20poly1305_encrypt(unsigned char *c,+                                     unsigned long long *clen_p,+                                     const unsigned char *m,+                                     unsigned long long mlen,+                                     const unsigned char *ad,+                                     unsigned long long adlen,+                                     const unsigned char *nsec,+                                     const unsigned char *npub,+                                     const unsigned char *k)+{+    unsigned long long clen = 0ULL;+    int                ret;++    if (mlen > crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    ret = crypto_aead_chacha20poly1305_encrypt_detached(c,+                                                        c + mlen, NULL,+                                                        m, mlen,+                                                        ad, adlen,+                                                        nsec, npub, k);+    if (clen_p != NULL) {+        if (ret == 0) {+            clen = mlen + crypto_aead_chacha20poly1305_ABYTES;+        }+        *clen_p = clen;+    }+    return ret;+}++int+crypto_aead_chacha20poly1305_ietf_encrypt_detached(unsigned char *c,+                                                   unsigned char *mac,+                                                   unsigned long long *maclen_p,+                                                   const unsigned char *m,+                                                   unsigned long long mlen,+                                                   const unsigned char *ad,+                                                   unsigned long long adlen,+                                                   const unsigned char *nsec,+                                                   const unsigned char *npub,+                                                   const unsigned char *k)+{+    crypto_onetimeauth_poly1305_state state;+    unsigned char                     block0[64U];+    unsigned char                     slen[8U];++    (void) nsec;+    crypto_stream_chacha20_ietf(block0, sizeof block0, npub, k);+    crypto_onetimeauth_poly1305_init(&state, block0);+    sodium_memzero(block0, sizeof block0);++    crypto_onetimeauth_poly1305_update(&state, ad, adlen);+    crypto_onetimeauth_poly1305_update(&state, _pad0, (0x10 - adlen) & 0xf);++    crypto_stream_chacha20_ietf_xor_ic(c, m, mlen, npub, 1U, k);++    crypto_onetimeauth_poly1305_update(&state, c, mlen);+    crypto_onetimeauth_poly1305_update(&state, _pad0, (0x10 - mlen) & 0xf);++    STORE64_LE(slen, (uint64_t) adlen);+    crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);++    STORE64_LE(slen, (uint64_t) mlen);+    crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);++    crypto_onetimeauth_poly1305_final(&state, mac);+    sodium_memzero(&state, sizeof state);++    if (maclen_p != NULL) {+        *maclen_p = crypto_aead_chacha20poly1305_ietf_ABYTES;+    }+    return 0;+}++int+crypto_aead_chacha20poly1305_ietf_encrypt(unsigned char *c,+                                          unsigned long long *clen_p,+                                          const unsigned char *m,+                                          unsigned long long mlen,+                                          const unsigned char *ad,+                                          unsigned long long adlen,+                                          const unsigned char *nsec,+                                          const unsigned char *npub,+                                          const unsigned char *k)+{+    unsigned long long clen = 0ULL;+    int                ret;++    if (mlen > crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    ret = crypto_aead_chacha20poly1305_ietf_encrypt_detached(c,+                                                             c + mlen, NULL,+                                                             m, mlen,+                                                             ad, adlen,+                                                             nsec, npub, k);+    if (clen_p != NULL) {+        if (ret == 0) {+            clen = mlen + crypto_aead_chacha20poly1305_ietf_ABYTES;+        }+        *clen_p = clen;+    }+    return ret;+}++int+crypto_aead_chacha20poly1305_decrypt_detached(unsigned char *m,+                                              unsigned char *nsec,+                                              const unsigned char *c,+                                              unsigned long long clen,+                                              const unsigned char *mac,+                                              const unsigned char *ad,+                                              unsigned long long adlen,+                                              const unsigned char *npub,+                                              const unsigned char *k)+{+    crypto_onetimeauth_poly1305_state state;+    unsigned char                     block0[64U];+    unsigned char                     slen[8U];+    unsigned char                     computed_mac[crypto_aead_chacha20poly1305_ABYTES];+    unsigned long long                mlen;+    int                               ret;++    (void) nsec;+    crypto_stream_chacha20(block0, sizeof block0, npub, k);+    crypto_onetimeauth_poly1305_init(&state, block0);+    sodium_memzero(block0, sizeof block0);++    crypto_onetimeauth_poly1305_update(&state, ad, adlen);+    STORE64_LE(slen, (uint64_t) adlen);+    crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);++    mlen = clen;+    crypto_onetimeauth_poly1305_update(&state, c, mlen);+    STORE64_LE(slen, (uint64_t) mlen);+    crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);++    crypto_onetimeauth_poly1305_final(&state, computed_mac);+    sodium_memzero(&state, sizeof state);++    COMPILER_ASSERT(sizeof computed_mac == 16U);+    ret = crypto_verify_16(computed_mac, mac);+    sodium_memzero(computed_mac, sizeof computed_mac);+    if (m == NULL) {+        return ret;+    }+    if (ret != 0) {+        memset(m, 0, mlen);+        return -1;+    }+    crypto_stream_chacha20_xor_ic(m, c, mlen, npub, 1U, k);++    return 0;+}++int+crypto_aead_chacha20poly1305_decrypt(unsigned char *m,+                                     unsigned long long *mlen_p,+                                     unsigned char *nsec,+                                     const unsigned char *c,+                                     unsigned long long clen,+                                     const unsigned char *ad,+                                     unsigned long long adlen,+                                     const unsigned char *npub,+                                     const unsigned char *k)+{+    unsigned long long mlen = 0ULL;+    int                ret = -1;++    if (clen >= crypto_aead_chacha20poly1305_ABYTES) {+        ret = crypto_aead_chacha20poly1305_decrypt_detached+            (m, nsec,+             c, clen - crypto_aead_chacha20poly1305_ABYTES,+             c + clen - crypto_aead_chacha20poly1305_ABYTES,+             ad, adlen, npub, k);+    }+    if (mlen_p != NULL) {+        if (ret == 0) {+            mlen = clen - crypto_aead_chacha20poly1305_ABYTES;+        }+        *mlen_p = mlen;+    }+    return ret;+}++int+crypto_aead_chacha20poly1305_ietf_decrypt_detached(unsigned char *m,+                                                   unsigned char *nsec,+                                                   const unsigned char *c,+                                                   unsigned long long clen,+                                                   const unsigned char *mac,+                                                   const unsigned char *ad,+                                                   unsigned long long adlen,+                                                   const unsigned char *npub,+                                                   const unsigned char *k)+{+    crypto_onetimeauth_poly1305_state state;+    unsigned char                     block0[64U];+    unsigned char                     slen[8U];+    unsigned char                     computed_mac[crypto_aead_chacha20poly1305_ietf_ABYTES];+    unsigned long long                mlen;+    int                               ret;++    (void) nsec;+    crypto_stream_chacha20_ietf(block0, sizeof block0, npub, k);+    crypto_onetimeauth_poly1305_init(&state, block0);+    sodium_memzero(block0, sizeof block0);++    crypto_onetimeauth_poly1305_update(&state, ad, adlen);+    crypto_onetimeauth_poly1305_update(&state, _pad0, (0x10 - adlen) & 0xf);++    mlen = clen;+    crypto_onetimeauth_poly1305_update(&state, c, mlen);+    crypto_onetimeauth_poly1305_update(&state, _pad0, (0x10 - mlen) & 0xf);++    STORE64_LE(slen, (uint64_t) adlen);+    crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);++    STORE64_LE(slen, (uint64_t) mlen);+    crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);++    crypto_onetimeauth_poly1305_final(&state, computed_mac);+    sodium_memzero(&state, sizeof state);++    COMPILER_ASSERT(sizeof computed_mac == 16U);+    ret = crypto_verify_16(computed_mac, mac);+    sodium_memzero(computed_mac, sizeof computed_mac);+    if (m == NULL) {+        return ret;+    }+    if (ret != 0) {+        memset(m, 0, mlen);+        return -1;+    }+    crypto_stream_chacha20_ietf_xor_ic(m, c, mlen, npub, 1U, k);++    return 0;+}++int+crypto_aead_chacha20poly1305_ietf_decrypt(unsigned char *m,+                                          unsigned long long *mlen_p,+                                          unsigned char *nsec,+                                          const unsigned char *c,+                                          unsigned long long clen,+                                          const unsigned char *ad,+                                          unsigned long long adlen,+                                          const unsigned char *npub,+                                          const unsigned char *k)+{+    unsigned long long mlen = 0ULL;+    int                ret = -1;++    if (clen >= crypto_aead_chacha20poly1305_ietf_ABYTES) {+        ret = crypto_aead_chacha20poly1305_ietf_decrypt_detached+            (m, nsec,+             c, clen - crypto_aead_chacha20poly1305_ietf_ABYTES,+             c + clen - crypto_aead_chacha20poly1305_ietf_ABYTES,+             ad, adlen, npub, k);+    }+    if (mlen_p != NULL) {+        if (ret == 0) {+            mlen = clen - crypto_aead_chacha20poly1305_ietf_ABYTES;+        }+        *mlen_p = mlen;+    }+    return ret;+}++size_t+crypto_aead_chacha20poly1305_ietf_keybytes(void)+{+    return crypto_aead_chacha20poly1305_ietf_KEYBYTES;+}++size_t+crypto_aead_chacha20poly1305_ietf_npubbytes(void)+{+    return crypto_aead_chacha20poly1305_ietf_NPUBBYTES;+}++size_t+crypto_aead_chacha20poly1305_ietf_nsecbytes(void)+{+    return crypto_aead_chacha20poly1305_ietf_NSECBYTES;+}++size_t+crypto_aead_chacha20poly1305_ietf_abytes(void)+{+    return crypto_aead_chacha20poly1305_ietf_ABYTES;+}++size_t+crypto_aead_chacha20poly1305_ietf_messagebytes_max(void)+{+    return crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX;+}++void+crypto_aead_chacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_chacha20poly1305_ietf_KEYBYTES])+{+    randombytes_buf(k, crypto_aead_chacha20poly1305_ietf_KEYBYTES);+}++size_t+crypto_aead_chacha20poly1305_keybytes(void)+{+    return crypto_aead_chacha20poly1305_KEYBYTES;+}++size_t+crypto_aead_chacha20poly1305_npubbytes(void)+{+    return crypto_aead_chacha20poly1305_NPUBBYTES;+}++size_t+crypto_aead_chacha20poly1305_nsecbytes(void)+{+    return crypto_aead_chacha20poly1305_NSECBYTES;+}++size_t+crypto_aead_chacha20poly1305_abytes(void)+{+    return crypto_aead_chacha20poly1305_ABYTES;+}++size_t+crypto_aead_chacha20poly1305_messagebytes_max(void)+{+    return crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX;+}++void+crypto_aead_chacha20poly1305_keygen(unsigned char k[crypto_aead_chacha20poly1305_KEYBYTES])+{+    randombytes_buf(k, crypto_aead_chacha20poly1305_KEYBYTES);+}
+ vendor/external/libsodium/crypto_auth/crypto_auth.c view
@@ -0,0 +1,41 @@++#include "crypto_auth.h"+#include "randombytes.h"++size_t+crypto_auth_bytes(void)+{+    return crypto_auth_BYTES;+}++size_t+crypto_auth_keybytes(void)+{+    return crypto_auth_KEYBYTES;+}++const char *+crypto_auth_primitive(void)+{+    return crypto_auth_PRIMITIVE;+}++int+crypto_auth(unsigned char *out, const unsigned char *in,+            unsigned long long inlen, const unsigned char *k)+{+    return crypto_auth_hmacsha512256(out, in, inlen, k);+}++int+crypto_auth_verify(const unsigned char *h, const unsigned char *in,+                   unsigned long long inlen,const unsigned char *k)+{+    return crypto_auth_hmacsha512256_verify(h, in, inlen, k);+}++void+crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES])+{+    randombytes_buf(k, crypto_auth_KEYBYTES);+}
+ vendor/external/libsodium/crypto_auth/hmacsha256/auth_hmacsha256.c view
@@ -0,0 +1,118 @@++#include <stddef.h>+#include <stdint.h>+#include <string.h>++#include "crypto_auth_hmacsha256.h"+#include "crypto_hash_sha256.h"+#include "crypto_verify_32.h"+#include "randombytes.h"+#include "utils.h"++size_t+crypto_auth_hmacsha256_bytes(void)+{+    return crypto_auth_hmacsha256_BYTES;+}++size_t+crypto_auth_hmacsha256_keybytes(void)+{+    return crypto_auth_hmacsha256_KEYBYTES;+}++size_t+crypto_auth_hmacsha256_statebytes(void)+{+    return sizeof(crypto_auth_hmacsha256_state);+}++void+crypto_auth_hmacsha256_keygen(unsigned char k[crypto_auth_hmacsha256_KEYBYTES])+{+    randombytes_buf(k, crypto_auth_hmacsha256_KEYBYTES);+}++int+crypto_auth_hmacsha256_init(crypto_auth_hmacsha256_state *state,+                            const unsigned char *key, size_t keylen)+{+    unsigned char pad[64];+    unsigned char khash[32];+    size_t        i;++    if (keylen > 64) {+        crypto_hash_sha256_init(&state->ictx);+        crypto_hash_sha256_update(&state->ictx, key, keylen);+        crypto_hash_sha256_final(&state->ictx, khash);+        key    = khash;+        keylen = 32;+    }+    crypto_hash_sha256_init(&state->ictx);+    memset(pad, 0x36, 64);+    for (i = 0; i < keylen; i++) {+        pad[i] ^= key[i];+    }+    crypto_hash_sha256_update(&state->ictx, pad, 64);++    crypto_hash_sha256_init(&state->octx);+    memset(pad, 0x5c, 64);+    for (i = 0; i < keylen; i++) {+        pad[i] ^= key[i];+    }+    crypto_hash_sha256_update(&state->octx, pad, 64);++    sodium_memzero((void *) pad, sizeof pad);+    sodium_memzero((void *) khash, sizeof khash);++    return 0;+}++int+crypto_auth_hmacsha256_update(crypto_auth_hmacsha256_state *state,+                              const unsigned char *in, unsigned long long inlen)+{+    crypto_hash_sha256_update(&state->ictx, in, inlen);++    return 0;+}++int+crypto_auth_hmacsha256_final(crypto_auth_hmacsha256_state *state,+                             unsigned char                *out)+{+    unsigned char ihash[32];++    crypto_hash_sha256_final(&state->ictx, ihash);+    crypto_hash_sha256_update(&state->octx, ihash, 32);+    crypto_hash_sha256_final(&state->octx, out);++    sodium_memzero((void *) ihash, sizeof ihash);++    return 0;+}++int+crypto_auth_hmacsha256(unsigned char *out, const unsigned char *in,+                       unsigned long long inlen, const unsigned char *k)+{+    crypto_auth_hmacsha256_state state;++    crypto_auth_hmacsha256_init(&state, k, crypto_auth_hmacsha256_KEYBYTES);+    crypto_auth_hmacsha256_update(&state, in, inlen);+    crypto_auth_hmacsha256_final(&state, out);++    return 0;+}++int+crypto_auth_hmacsha256_verify(const unsigned char *h, const unsigned char *in,+                              unsigned long long inlen, const unsigned char *k)+{+    unsigned char correct[32];++    crypto_auth_hmacsha256(correct, in, inlen, k);++    return crypto_verify_32(h, correct) | (-(h == correct)) |+           sodium_memcmp(correct, h, 32);+}
+ vendor/external/libsodium/crypto_auth/hmacsha512/auth_hmacsha512.c view
@@ -0,0 +1,118 @@++#include <stddef.h>+#include <stdint.h>+#include <string.h>++#include "crypto_auth_hmacsha512.h"+#include "crypto_hash_sha512.h"+#include "crypto_verify_64.h"+#include "randombytes.h"+#include "utils.h"++size_t+crypto_auth_hmacsha512_bytes(void)+{+    return crypto_auth_hmacsha512_BYTES;+}++size_t+crypto_auth_hmacsha512_keybytes(void)+{+    return crypto_auth_hmacsha512_KEYBYTES;+}++size_t+crypto_auth_hmacsha512_statebytes(void)+{+    return sizeof(crypto_auth_hmacsha512_state);+}++void+crypto_auth_hmacsha512_keygen(unsigned char k[crypto_auth_hmacsha512_KEYBYTES])+{+    randombytes_buf(k, crypto_auth_hmacsha512_KEYBYTES);+}++int+crypto_auth_hmacsha512_init(crypto_auth_hmacsha512_state *state,+                            const unsigned char *key, size_t keylen)+{+    unsigned char pad[128];+    unsigned char khash[64];+    size_t        i;++    if (keylen > 128) {+        crypto_hash_sha512_init(&state->ictx);+        crypto_hash_sha512_update(&state->ictx, key, keylen);+        crypto_hash_sha512_final(&state->ictx, khash);+        key    = khash;+        keylen = 64;+    }+    crypto_hash_sha512_init(&state->ictx);+    memset(pad, 0x36, 128);+    for (i = 0; i < keylen; i++) {+        pad[i] ^= key[i];+    }+    crypto_hash_sha512_update(&state->ictx, pad, 128);++    crypto_hash_sha512_init(&state->octx);+    memset(pad, 0x5c, 128);+    for (i = 0; i < keylen; i++) {+        pad[i] ^= key[i];+    }+    crypto_hash_sha512_update(&state->octx, pad, 128);++    sodium_memzero((void *) pad, sizeof pad);+    sodium_memzero((void *) khash, sizeof khash);++    return 0;+}++int+crypto_auth_hmacsha512_update(crypto_auth_hmacsha512_state *state,+                              const unsigned char *in, unsigned long long inlen)+{+    crypto_hash_sha512_update(&state->ictx, in, inlen);++    return 0;+}++int+crypto_auth_hmacsha512_final(crypto_auth_hmacsha512_state *state,+                             unsigned char                *out)+{+    unsigned char ihash[64];++    crypto_hash_sha512_final(&state->ictx, ihash);+    crypto_hash_sha512_update(&state->octx, ihash, 64);+    crypto_hash_sha512_final(&state->octx, out);++    sodium_memzero((void *) ihash, sizeof ihash);++    return 0;+}++int+crypto_auth_hmacsha512(unsigned char *out, const unsigned char *in,+                       unsigned long long inlen, const unsigned char *k)+{+    crypto_auth_hmacsha512_state state;++    crypto_auth_hmacsha512_init(&state, k, crypto_auth_hmacsha512_KEYBYTES);+    crypto_auth_hmacsha512_update(&state, in, inlen);+    crypto_auth_hmacsha512_final(&state, out);++    return 0;+}++int+crypto_auth_hmacsha512_verify(const unsigned char *h, const unsigned char *in,+                              unsigned long long inlen, const unsigned char *k)+{+    unsigned char correct[64];++    crypto_auth_hmacsha512(correct, in, inlen, k);++    return crypto_verify_64(h, correct) | (-(h == correct)) |+           sodium_memcmp(correct, h, 64);+}
+ vendor/external/libsodium/crypto_auth/hmacsha512256/auth_hmacsha512256.c view
@@ -0,0 +1,93 @@++#include <stddef.h>+#include <stdint.h>+#include <string.h>++#include "crypto_auth_hmacsha512.h"+#include "crypto_auth_hmacsha512256.h"+#include "crypto_hash_sha512.h"+#include "crypto_verify_32.h"+#include "randombytes.h"+#include "utils.h"++size_t+crypto_auth_hmacsha512256_bytes(void)+{+    return crypto_auth_hmacsha512256_BYTES;+}++size_t+crypto_auth_hmacsha512256_keybytes(void)+{+    return crypto_auth_hmacsha512256_KEYBYTES;+}++size_t+crypto_auth_hmacsha512256_statebytes(void)+{+    return sizeof(crypto_auth_hmacsha512256_state);+}++void+crypto_auth_hmacsha512256_keygen(+    unsigned char k[crypto_auth_hmacsha512256_KEYBYTES])+{+    randombytes_buf(k, crypto_auth_hmacsha512256_KEYBYTES);+}++int+crypto_auth_hmacsha512256_init(crypto_auth_hmacsha512256_state *state,+                               const unsigned char *key, size_t keylen)+{+    return crypto_auth_hmacsha512_init((crypto_auth_hmacsha512_state *) state,+                                       key, keylen);+}++int+crypto_auth_hmacsha512256_update(crypto_auth_hmacsha512256_state *state,+                                 const unsigned char             *in,+                                 unsigned long long               inlen)+{+    return crypto_auth_hmacsha512_update((crypto_auth_hmacsha512_state *) state,+                                         in, inlen);+}++int+crypto_auth_hmacsha512256_final(crypto_auth_hmacsha512256_state *state,+                                unsigned char                   *out)+{+    unsigned char out0[64];++    crypto_auth_hmacsha512_final((crypto_auth_hmacsha512_state *) state, out0);+    memcpy(out, out0, 32);++    return 0;+}++int+crypto_auth_hmacsha512256(unsigned char *out, const unsigned char *in,+                          unsigned long long inlen, const unsigned char *k)+{+    crypto_auth_hmacsha512256_state state;++    crypto_auth_hmacsha512256_init(&state, k,+                                   crypto_auth_hmacsha512256_KEYBYTES);+    crypto_auth_hmacsha512256_update(&state, in, inlen);+    crypto_auth_hmacsha512256_final(&state, out);++    return 0;+}++int+crypto_auth_hmacsha512256_verify(const unsigned char *h,+                                 const unsigned char *in,+                                 unsigned long long   inlen,+                                 const unsigned char *k)+{+    unsigned char correct[32];++    crypto_auth_hmacsha512256(correct, in, inlen, k);++    return crypto_verify_32(h, correct) | (-(h == correct)) |+           sodium_memcmp(correct, h, 32);+}
+ vendor/external/libsodium/crypto_core/ed25519/core_ed25519.c view
@@ -0,0 +1,225 @@++#include <stdint.h>++#include "crypto_core_ed25519.h"+#include "private/common.h"+#include "private/ed25519_ref10.h"+#include "randombytes.h"+#include "utils.h"++int+crypto_core_ed25519_is_valid_point(const unsigned char *p)+{+    ge25519_p3 p_p3;++    if (ge25519_is_canonical(p) == 0 ||+        ge25519_has_small_order(p) != 0 ||+        ge25519_frombytes(&p_p3, p) != 0 ||+        ge25519_is_on_curve(&p_p3) == 0 ||+        ge25519_is_on_main_subgroup(&p_p3) == 0) {+        return 0;+    }+    return 1;+}++int+crypto_core_ed25519_add(unsigned char *r,+                        const unsigned char *p, const unsigned char *q)+{+    ge25519_p3     p_p3, q_p3, r_p3;+    ge25519_p1p1   r_p1p1;+    ge25519_cached q_cached;++    if (ge25519_frombytes(&p_p3, p) != 0 || ge25519_is_on_curve(&p_p3) == 0 ||+        ge25519_frombytes(&q_p3, q) != 0 || ge25519_is_on_curve(&q_p3) == 0) {+        return -1;+    }+    ge25519_p3_to_cached(&q_cached, &q_p3);+    ge25519_add(&r_p1p1, &p_p3, &q_cached);+    ge25519_p1p1_to_p3(&r_p3, &r_p1p1);+    ge25519_p3_tobytes(r, &r_p3);++    return 0;+}++int+crypto_core_ed25519_sub(unsigned char *r,+                        const unsigned char *p, const unsigned char *q)+{+    ge25519_p3     p_p3, q_p3, r_p3;+    ge25519_p1p1   r_p1p1;+    ge25519_cached q_cached;++    if (ge25519_frombytes(&p_p3, p) != 0 || ge25519_is_on_curve(&p_p3) == 0 ||+        ge25519_frombytes(&q_p3, q) != 0 || ge25519_is_on_curve(&q_p3) == 0) {+        return -1;+    }+    ge25519_p3_to_cached(&q_cached, &q_p3);+    ge25519_sub(&r_p1p1, &p_p3, &q_cached);+    ge25519_p1p1_to_p3(&r_p3, &r_p1p1);+    ge25519_p3_tobytes(r, &r_p3);++    return 0;+}++int+crypto_core_ed25519_from_uniform(unsigned char *p, const unsigned char *r)+{+    ge25519_from_uniform(p, r);++    return 0;+}++int+crypto_core_ed25519_from_hash(unsigned char *p, const unsigned char *h)+{+    ge25519_from_hash(p, h);++    return 0;+}++void+crypto_core_ed25519_random(unsigned char *p)+{+    unsigned char h[crypto_core_ed25519_UNIFORMBYTES];++    randombytes_buf(h, sizeof h);+    (void) crypto_core_ed25519_from_uniform(p, h);+}++void+crypto_core_ed25519_scalar_random(unsigned char *r)+{+    do {+        randombytes_buf(r, crypto_core_ed25519_SCALARBYTES);+        r[crypto_core_ed25519_SCALARBYTES - 1] &= 0x1f;+    } while (sc25519_is_canonical(r) == 0 ||+             sodium_is_zero(r, crypto_core_ed25519_SCALARBYTES));+}++int+crypto_core_ed25519_scalar_invert(unsigned char *recip, const unsigned char *s)+{+    sc25519_invert(recip, s);++    return - sodium_is_zero(s, crypto_core_ed25519_SCALARBYTES);+}++/* 2^252+27742317777372353535851937790883648493 */+static const unsigned char L[] = {+    0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7,+    0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10+};++void+crypto_core_ed25519_scalar_negate(unsigned char *neg, const unsigned char *s)+{+    unsigned char t_[crypto_core_ed25519_NONREDUCEDSCALARBYTES];+    unsigned char s_[crypto_core_ed25519_NONREDUCEDSCALARBYTES];++    COMPILER_ASSERT(crypto_core_ed25519_NONREDUCEDSCALARBYTES >=+                    2 * crypto_core_ed25519_SCALARBYTES);+    memset(t_, 0, sizeof t_);+    memset(s_, 0, sizeof s_);+    memcpy(t_ + crypto_core_ed25519_SCALARBYTES, L,+           crypto_core_ed25519_SCALARBYTES);+    memcpy(s_, s, crypto_core_ed25519_SCALARBYTES);+    sodium_sub(t_, s_, sizeof t_);+    sc25519_reduce(t_);+    memcpy(neg, t_, crypto_core_ed25519_SCALARBYTES);+}++void+crypto_core_ed25519_scalar_complement(unsigned char *comp,+                                      const unsigned char *s)+{+    unsigned char t_[crypto_core_ed25519_NONREDUCEDSCALARBYTES];+    unsigned char s_[crypto_core_ed25519_NONREDUCEDSCALARBYTES];++    COMPILER_ASSERT(crypto_core_ed25519_NONREDUCEDSCALARBYTES >=+                    2 * crypto_core_ed25519_SCALARBYTES);+    memset(t_, 0, sizeof t_);+    memset(s_, 0, sizeof s_);+    t_[0]++;+    memcpy(t_ + crypto_core_ed25519_SCALARBYTES, L,+           crypto_core_ed25519_SCALARBYTES);+    memcpy(s_, s, crypto_core_ed25519_SCALARBYTES);+    sodium_sub(t_, s_, sizeof t_);+    sc25519_reduce(t_);+    memcpy(comp, t_, crypto_core_ed25519_SCALARBYTES);+}++void+crypto_core_ed25519_scalar_add(unsigned char *z, const unsigned char *x,+                               const unsigned char *y)+{+    unsigned char x_[crypto_core_ed25519_NONREDUCEDSCALARBYTES];+    unsigned char y_[crypto_core_ed25519_NONREDUCEDSCALARBYTES];++    memset(x_, 0, sizeof x_);+    memset(y_, 0, sizeof y_);+    memcpy(x_, x, crypto_core_ed25519_SCALARBYTES);+    memcpy(y_, y, crypto_core_ed25519_SCALARBYTES);+    sodium_add(x_, y_, crypto_core_ed25519_SCALARBYTES);+    crypto_core_ed25519_scalar_reduce(z, x_);+}++void+crypto_core_ed25519_scalar_sub(unsigned char *z, const unsigned char *x,+                               const unsigned char *y)+{+    unsigned char yn[crypto_core_ed25519_SCALARBYTES];++    crypto_core_ed25519_scalar_negate(yn, y);+    crypto_core_ed25519_scalar_add(z, x, yn);+}++void+crypto_core_ed25519_scalar_mul(unsigned char *z, const unsigned char *x,+                               const unsigned char *y)+{+    sc25519_mul(z, x, y);+}++void+crypto_core_ed25519_scalar_reduce(unsigned char *r,+                                  const unsigned char *s)+{+    unsigned char t[crypto_core_ed25519_NONREDUCEDSCALARBYTES];++    memcpy(t, s, sizeof t);+    sc25519_reduce(t);+    memcpy(r, t, crypto_core_ed25519_SCALARBYTES);+    sodium_memzero(t, sizeof t);+}++size_t+crypto_core_ed25519_bytes(void)+{+    return crypto_core_ed25519_BYTES;+}++size_t+crypto_core_ed25519_nonreducedscalarbytes(void)+{+    return crypto_core_ed25519_NONREDUCEDSCALARBYTES;+}++size_t+crypto_core_ed25519_uniformbytes(void)+{+    return crypto_core_ed25519_UNIFORMBYTES;+}++size_t+crypto_core_ed25519_hashbytes(void)+{+    return crypto_core_ed25519_HASHBYTES;+}++size_t+crypto_core_ed25519_scalarbytes(void)+{+    return crypto_core_ed25519_SCALARBYTES;+}
+ vendor/external/libsodium/crypto_core/ed25519/core_ristretto255.c view
@@ -0,0 +1,156 @@++#include <stdint.h>++#include "crypto_core_ed25519.h"+#include "crypto_core_ristretto255.h"+#include "private/common.h"+#include "private/ed25519_ref10.h"+#include "randombytes.h"+#include "utils.h"++int+crypto_core_ristretto255_is_valid_point(const unsigned char *p)+{+    ge25519_p3 p_p3;++    if (ristretto255_frombytes(&p_p3, p) != 0) {+        return 0;+    }+    return 1;+}++int+crypto_core_ristretto255_add(unsigned char *r,+                             const unsigned char *p, const unsigned char *q)+{+    ge25519_p3     p_p3, q_p3, r_p3;+    ge25519_p1p1   r_p1p1;+    ge25519_cached q_cached;++    if (ristretto255_frombytes(&p_p3, p) != 0 ||+        ristretto255_frombytes(&q_p3, q) != 0) {+        return -1;+    }+    ge25519_p3_to_cached(&q_cached, &q_p3);+    ge25519_add(&r_p1p1, &p_p3, &q_cached);+    ge25519_p1p1_to_p3(&r_p3, &r_p1p1);+    ristretto255_p3_tobytes(r, &r_p3);++    return 0;+}++int+crypto_core_ristretto255_sub(unsigned char *r,+                             const unsigned char *p, const unsigned char *q)+{+    ge25519_p3     p_p3, q_p3, r_p3;+    ge25519_p1p1   r_p1p1;+    ge25519_cached q_cached;++    if (ristretto255_frombytes(&p_p3, p) != 0 ||+        ristretto255_frombytes(&q_p3, q) != 0) {+        return -1;+    }+    ge25519_p3_to_cached(&q_cached, &q_p3);+    ge25519_sub(&r_p1p1, &p_p3, &q_cached);+    ge25519_p1p1_to_p3(&r_p3, &r_p1p1);+    ristretto255_p3_tobytes(r, &r_p3);++    return 0;+}++int+crypto_core_ristretto255_from_hash(unsigned char *p, const unsigned char *r)+{+    ristretto255_from_hash(p, r);++    return 0;+}++void+crypto_core_ristretto255_random(unsigned char *p)+{+    unsigned char h[crypto_core_ristretto255_HASHBYTES];++    randombytes_buf(h, sizeof h);+    (void) crypto_core_ristretto255_from_hash(p, h);+}++void+crypto_core_ristretto255_scalar_random(unsigned char *r)+{+    crypto_core_ed25519_scalar_random(r);+}++int+crypto_core_ristretto255_scalar_invert(unsigned char *recip,+                                       const unsigned char *s)+{+    return crypto_core_ed25519_scalar_invert(recip, s);+}++void+crypto_core_ristretto255_scalar_negate(unsigned char *neg,+                                       const unsigned char *s)+{+    crypto_core_ed25519_scalar_negate(neg, s);+}++void+crypto_core_ristretto255_scalar_complement(unsigned char *comp,+                                           const unsigned char *s)+{+    crypto_core_ed25519_scalar_complement(comp, s);+}++void+crypto_core_ristretto255_scalar_add(unsigned char *z, const unsigned char *x,+                                    const unsigned char *y)+{+    crypto_core_ed25519_scalar_add(z, x, y);+}++void+crypto_core_ristretto255_scalar_sub(unsigned char *z, const unsigned char *x,+                                    const unsigned char *y)+{+    crypto_core_ed25519_scalar_sub(z, x, y);+}++void+crypto_core_ristretto255_scalar_mul(unsigned char *z, const unsigned char *x,+                                    const unsigned char *y)+{+    sc25519_mul(z, x, y);+}++void+crypto_core_ristretto255_scalar_reduce(unsigned char *r,+                                       const unsigned char *s)+{+    crypto_core_ed25519_scalar_reduce(r, s);+}++size_t+crypto_core_ristretto255_bytes(void)+{+    return crypto_core_ristretto255_BYTES;+}++size_t+crypto_core_ristretto255_nonreducedscalarbytes(void)+{+    return crypto_core_ristretto255_NONREDUCEDSCALARBYTES;+}++size_t+crypto_core_ristretto255_hashbytes(void)+{+    return crypto_core_ristretto255_HASHBYTES;+}++size_t+crypto_core_ristretto255_scalarbytes(void)+{+    return crypto_core_ristretto255_SCALARBYTES;+}
+ vendor/external/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c view
@@ -0,0 +1,2858 @@+#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include "crypto_verify_32.h"+#include "private/common.h"+#include "private/ed25519_ref10.h"+#include "utils.h"++static inline uint64_t+load_3(const unsigned char *in)+{+    uint64_t result;++    result = (uint64_t) in[0];+    result |= ((uint64_t) in[1]) << 8;+    result |= ((uint64_t) in[2]) << 16;++    return result;+}++static inline uint64_t+load_4(const unsigned char *in)+{+    uint64_t result;++    result = (uint64_t) in[0];+    result |= ((uint64_t) in[1]) << 8;+    result |= ((uint64_t) in[2]) << 16;+    result |= ((uint64_t) in[3]) << 24;++    return result;+}++/*+ * Field arithmetic:+ * Use 5*51 bit limbs on 64-bit systems with support for 128 bit arithmetic,+ * and 10*25.5 bit limbs elsewhere.+ *+ * Functions used elsewhere that are candidates for inlining are defined+ * via "private/curve25519_ref10.h".+ */++#ifdef HAVE_TI_MODE+# include "fe_51/constants.h"+# include "fe_51/fe.h"+#else+# include "fe_25_5/constants.h"+# include "fe_25_5/fe.h"+#endif++void+fe25519_invert(fe25519 out, const fe25519 z)+{+    fe25519 t0;+    fe25519 t1;+    fe25519 t2;+    fe25519 t3;+    int     i;++    fe25519_sq(t0, z);+    fe25519_sq(t1, t0);+    fe25519_sq(t1, t1);+    fe25519_mul(t1, z, t1);+    fe25519_mul(t0, t0, t1);+    fe25519_sq(t2, t0);+    fe25519_mul(t1, t1, t2);+    fe25519_sq(t2, t1);+    for (i = 1; i < 5; ++i) {+        fe25519_sq(t2, t2);+    }+    fe25519_mul(t1, t2, t1);+    fe25519_sq(t2, t1);+    for (i = 1; i < 10; ++i) {+        fe25519_sq(t2, t2);+    }+    fe25519_mul(t2, t2, t1);+    fe25519_sq(t3, t2);+    for (i = 1; i < 20; ++i) {+        fe25519_sq(t3, t3);+    }+    fe25519_mul(t2, t3, t2);+    for (i = 1; i < 11; ++i) {+        fe25519_sq(t2, t2);+    }+    fe25519_mul(t1, t2, t1);+    fe25519_sq(t2, t1);+    for (i = 1; i < 50; ++i) {+        fe25519_sq(t2, t2);+    }+    fe25519_mul(t2, t2, t1);+    fe25519_sq(t3, t2);+    for (i = 1; i < 100; ++i) {+        fe25519_sq(t3, t3);+    }+    fe25519_mul(t2, t3, t2);+    for (i = 1; i < 51; ++i) {+        fe25519_sq(t2, t2);+    }+    fe25519_mul(t1, t2, t1);+    for (i = 1; i < 6; ++i) {+        fe25519_sq(t1, t1);+    }+    fe25519_mul(out, t1, t0);+}++static void+fe25519_pow22523(fe25519 out, const fe25519 z)+{+    fe25519 t0;+    fe25519 t1;+    fe25519 t2;+    int     i;++    fe25519_sq(t0, z);+    fe25519_sq(t1, t0);+    fe25519_sq(t1, t1);+    fe25519_mul(t1, z, t1);+    fe25519_mul(t0, t0, t1);+    fe25519_sq(t0, t0);+    fe25519_mul(t0, t1, t0);+    fe25519_sq(t1, t0);+    for (i = 1; i < 5; ++i) {+        fe25519_sq(t1, t1);+    }+    fe25519_mul(t0, t1, t0);+    fe25519_sq(t1, t0);+    for (i = 1; i < 10; ++i) {+        fe25519_sq(t1, t1);+    }+    fe25519_mul(t1, t1, t0);+    fe25519_sq(t2, t1);+    for (i = 1; i < 20; ++i) {+        fe25519_sq(t2, t2);+    }+    fe25519_mul(t1, t2, t1);+    for (i = 1; i < 11; ++i) {+        fe25519_sq(t1, t1);+    }+    fe25519_mul(t0, t1, t0);+    fe25519_sq(t1, t0);+    for (i = 1; i < 50; ++i) {+        fe25519_sq(t1, t1);+    }+    fe25519_mul(t1, t1, t0);+    fe25519_sq(t2, t1);+    for (i = 1; i < 100; ++i) {+        fe25519_sq(t2, t2);+    }+    fe25519_mul(t1, t2, t1);+    for (i = 1; i < 51; ++i) {+        fe25519_sq(t1, t1);+    }+    fe25519_mul(t0, t1, t0);+    fe25519_sq(t0, t0);+    fe25519_sq(t0, t0);+    fe25519_mul(out, t0, z);+}++static inline void+fe25519_cneg(fe25519 h, const fe25519 f, unsigned int b)+{+    fe25519 negf;++    fe25519_neg(negf, f);+    fe25519_copy(h, f);+    fe25519_cmov(h, negf, b);+}++static inline void+fe25519_abs(fe25519 h, const fe25519 f)+{+    fe25519_cneg(h, f, fe25519_isnegative(f));+}++static inline void+fe25519_sqmul(fe25519 s, const int n, const fe25519 a)+{+    int i;++    for (i = 0; i < n; i++) {+        fe25519_sq(s, s);+    }+    fe25519_mul(s, s, a);+}++static unsigned int+fe25519_notsquare(const fe25519 x)+{+    fe25519       _10, _11, _1100, _1111, _11110000, _11111111;+    fe25519       t, u, v;+    unsigned char s[32];++    /* Jacobi symbol - x^((p-1)/2) */+    fe25519_mul(_10, x, x);+    fe25519_mul(_11, x, _10);+    fe25519_sq(_1100, _11);+    fe25519_sq(_1100, _1100);+    fe25519_mul(_1111, _11, _1100);+    fe25519_sq(_11110000, _1111);+    fe25519_sq(_11110000, _11110000);+    fe25519_sq(_11110000, _11110000);+    fe25519_sq(_11110000, _11110000);+    fe25519_mul(_11111111, _1111, _11110000);+    fe25519_copy(t, _11111111);+    fe25519_sqmul(t, 2, _11);+    fe25519_copy(u, t);+    fe25519_sqmul(t, 10, u);+    fe25519_sqmul(t, 10, u);+    fe25519_copy(v, t);+    fe25519_sqmul(t, 30, v);+    fe25519_copy(v, t);+    fe25519_sqmul(t, 60, v);+    fe25519_copy(v, t);+    fe25519_sqmul(t, 120, v);+    fe25519_sqmul(t, 10, u);+    fe25519_sqmul(t, 3, _11);+    fe25519_sq(t, t);++    fe25519_tobytes(s, t);++    return s[1] & 1;+}++/*+ r = p + q+ */++void+ge25519_add(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q)+{+    fe25519 t0;++    fe25519_add(r->X, p->Y, p->X);+    fe25519_sub(r->Y, p->Y, p->X);+    fe25519_mul(r->Z, r->X, q->YplusX);+    fe25519_mul(r->Y, r->Y, q->YminusX);+    fe25519_mul(r->T, q->T2d, p->T);+    fe25519_mul(r->X, p->Z, q->Z);+    fe25519_add(t0, r->X, r->X);+    fe25519_sub(r->X, r->Z, r->Y);+    fe25519_add(r->Y, r->Z, r->Y);+    fe25519_add(r->Z, t0, r->T);+    fe25519_sub(r->T, t0, r->T);+}++static void+slide_vartime(signed char *r, const unsigned char *a)+{+    int i;+    int b;+    int k;+    int ribs;+    int cmp;++    for (i = 0; i < 256; ++i) {+        r[i] = 1 & (a[i >> 3] >> (i & 7));+    }+    for (i = 0; i < 256; ++i) {+        if (! r[i]) {+            continue;+        }+        for (b = 1; b <= 6 && i + b < 256; ++b) {+            if (! r[i + b]) {+                continue;+            }+            ribs = r[i + b] << b;+            cmp = r[i] + ribs;+            if (cmp <= 15) {+                r[i] = cmp;+                r[i + b] = 0;+            } else {+                cmp = r[i] - ribs;+                if (cmp < -15) {+                    break;+                }+                r[i] = cmp;+                for (k = i + b; k < 256; ++k) {+                    if (! r[k]) {+                        r[k] = 1;+                        break;+                    }+                    r[k] = 0;+                }+            }+        }+    }+}++int+ge25519_frombytes(ge25519_p3 *h, const unsigned char *s)+{+    fe25519 u;+    fe25519 v;+    fe25519 vxx;+    fe25519 m_root_check, p_root_check;+    fe25519 negx;+    fe25519 x_sqrtm1;+    int     has_m_root, has_p_root;++    fe25519_frombytes(h->Y, s);+    fe25519_1(h->Z);+    fe25519_sq(u, h->Y);+    fe25519_mul(v, u, d);+    fe25519_sub(u, u, h->Z); /* u = y^2-1 */+    fe25519_add(v, v, h->Z); /* v = dy^2+1 */++    fe25519_mul(h->X, u, v);+    fe25519_pow22523(h->X, h->X);+    fe25519_mul(h->X, u, h->X); /* u((uv)^((q-5)/8)) */++    fe25519_sq(vxx, h->X);+    fe25519_mul(vxx, vxx, v);+    fe25519_sub(m_root_check, vxx, u); /* vx^2-u */+    fe25519_add(p_root_check, vxx, u); /* vx^2+u */+    has_m_root = fe25519_iszero(m_root_check);+    has_p_root = fe25519_iszero(p_root_check);+    fe25519_mul(x_sqrtm1, h->X, sqrtm1); /* x*sqrt(-1) */+    fe25519_cmov(h->X, x_sqrtm1, 1 - has_m_root);++    fe25519_neg(negx, h->X);+    fe25519_cmov(h->X, negx, fe25519_isnegative(h->X) ^ (s[31] >> 7));+    fe25519_mul(h->T, h->X, h->Y);++    return (has_m_root | has_p_root) - 1;+}++int+ge25519_frombytes_negate_vartime(ge25519_p3 *h, const unsigned char *s)+{+    fe25519 u;+    fe25519 v;+    fe25519 v3;+    fe25519 vxx;+    fe25519 m_root_check, p_root_check;++    fe25519_frombytes(h->Y, s);+    fe25519_1(h->Z);+    fe25519_sq(u, h->Y);+    fe25519_mul(v, u, d);+    fe25519_sub(u, u, h->Z); /* u = y^2-1 */+    fe25519_add(v, v, h->Z); /* v = dy^2+1 */++    fe25519_sq(v3, v);+    fe25519_mul(v3, v3, v); /* v3 = v^3 */+    fe25519_sq(h->X, v3);+    fe25519_mul(h->X, h->X, v);+    fe25519_mul(h->X, h->X, u); /* x = uv^7 */++    fe25519_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */+    fe25519_mul(h->X, h->X, v3);+    fe25519_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */++    fe25519_sq(vxx, h->X);+    fe25519_mul(vxx, vxx, v);+    fe25519_sub(m_root_check, vxx, u); /* vx^2-u */+    if (fe25519_iszero(m_root_check) == 0) {+        fe25519_add(p_root_check, vxx, u); /* vx^2+u */+        if (fe25519_iszero(p_root_check) == 0) {+            return -1;+        }+        fe25519_mul(h->X, h->X, sqrtm1);+    }++    if (fe25519_isnegative(h->X) == (s[31] >> 7)) {+        fe25519_neg(h->X, h->X);+    }+    fe25519_mul(h->T, h->X, h->Y);++    return 0;+}++/*+ r = p + q+ */++static void+ge25519_madd(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_precomp *q)+{+    fe25519 t0;++    fe25519_add(r->X, p->Y, p->X);+    fe25519_sub(r->Y, p->Y, p->X);+    fe25519_mul(r->Z, r->X, q->yplusx);+    fe25519_mul(r->Y, r->Y, q->yminusx);+    fe25519_mul(r->T, q->xy2d, p->T);+    fe25519_add(t0, p->Z, p->Z);+    fe25519_sub(r->X, r->Z, r->Y);+    fe25519_add(r->Y, r->Z, r->Y);+    fe25519_add(r->Z, t0, r->T);+    fe25519_sub(r->T, t0, r->T);+}++/*+ r = p - q+ */++static void+ge25519_msub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_precomp *q)+{+    fe25519 t0;++    fe25519_add(r->X, p->Y, p->X);+    fe25519_sub(r->Y, p->Y, p->X);+    fe25519_mul(r->Z, r->X, q->yminusx);+    fe25519_mul(r->Y, r->Y, q->yplusx);+    fe25519_mul(r->T, q->xy2d, p->T);+    fe25519_add(t0, p->Z, p->Z);+    fe25519_sub(r->X, r->Z, r->Y);+    fe25519_add(r->Y, r->Z, r->Y);+    fe25519_sub(r->Z, t0, r->T);+    fe25519_add(r->T, t0, r->T);+}++/*+ r = p+ */++void+ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p)+{+    fe25519_mul(r->X, p->X, p->T);+    fe25519_mul(r->Y, p->Y, p->Z);+    fe25519_mul(r->Z, p->Z, p->T);+}++/*+ r = p+ */++void+ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p)+{+    fe25519_mul(r->X, p->X, p->T);+    fe25519_mul(r->Y, p->Y, p->Z);+    fe25519_mul(r->Z, p->Z, p->T);+    fe25519_mul(r->T, p->X, p->Y);+}++static void+ge25519_p2_0(ge25519_p2 *h)+{+    fe25519_0(h->X);+    fe25519_1(h->Y);+    fe25519_1(h->Z);+}++/*+ r = 2 * p+ */++static void+ge25519_p2_dbl(ge25519_p1p1 *r, const ge25519_p2 *p)+{+    fe25519 t0;++    fe25519_sq(r->X, p->X);+    fe25519_sq(r->Z, p->Y);+    fe25519_sq2(r->T, p->Z);+    fe25519_add(r->Y, p->X, p->Y);+    fe25519_sq(t0, r->Y);+    fe25519_add(r->Y, r->Z, r->X);+    fe25519_sub(r->Z, r->Z, r->X);+    fe25519_sub(r->X, t0, r->Y);+    fe25519_sub(r->T, r->T, r->Z);+}++static void+ge25519_p3_0(ge25519_p3 *h)+{+    fe25519_0(h->X);+    fe25519_1(h->Y);+    fe25519_1(h->Z);+    fe25519_0(h->T);+}++static void+ge25519_cached_0(ge25519_cached *h)+{+    fe25519_1(h->YplusX);+    fe25519_1(h->YminusX);+    fe25519_1(h->Z);+    fe25519_0(h->T2d);+}++/*+ r = p+ */++void+ge25519_p3_to_cached(ge25519_cached *r, const ge25519_p3 *p)+{+    fe25519_add(r->YplusX, p->Y, p->X);+    fe25519_sub(r->YminusX, p->Y, p->X);+    fe25519_copy(r->Z, p->Z);+    fe25519_mul(r->T2d, p->T, d2);+}++static void+ge25519_p3_to_precomp(ge25519_precomp *pi, const ge25519_p3 *p)+{+    fe25519 recip;+    fe25519 x;+    fe25519 y;+    fe25519 xy;++    fe25519_invert(recip, p->Z);+    fe25519_mul(x, p->X, recip);+    fe25519_mul(y, p->Y, recip);+    fe25519_add(pi->yplusx, y, x);+    fe25519_sub(pi->yminusx, y, x);+    fe25519_mul(xy, x, y);+    fe25519_mul(pi->xy2d, xy, d2);+}++/*+ r = p+ */++static void+ge25519_p3_to_p2(ge25519_p2 *r, const ge25519_p3 *p)+{+    fe25519_copy(r->X, p->X);+    fe25519_copy(r->Y, p->Y);+    fe25519_copy(r->Z, p->Z);+}++void+ge25519_p3_tobytes(unsigned char *s, const ge25519_p3 *h)+{+    fe25519 recip;+    fe25519 x;+    fe25519 y;++    fe25519_invert(recip, h->Z);+    fe25519_mul(x, h->X, recip);+    fe25519_mul(y, h->Y, recip);+    fe25519_tobytes(s, y);+    s[31] ^= fe25519_isnegative(x) << 7;+}++/*+ r = 2 * p+ */++static void+ge25519_p3_dbl(ge25519_p1p1 *r, const ge25519_p3 *p)+{+    ge25519_p2 q;+    ge25519_p3_to_p2(&q, p);+    ge25519_p2_dbl(r, &q);+}++static void+ge25519_precomp_0(ge25519_precomp *h)+{+    fe25519_1(h->yplusx);+    fe25519_1(h->yminusx);+    fe25519_0(h->xy2d);+}++static unsigned char+equal(signed char b, signed char c)+{+    unsigned char ub = b;+    unsigned char uc = c;+    unsigned char x  = ub ^ uc; /* 0: yes; 1..255: no */+    uint32_t      y  = (uint32_t) x; /* 0: yes; 1..255: no */++    y -= 1;   /* 4294967295: yes; 0..254: no */+    y >>= 31; /* 1: yes; 0: no */++    return y;+}++static unsigned char+negative(signed char b)+{+    /* 18446744073709551361..18446744073709551615: yes; 0..255: no */+    uint64_t x = b;++    x >>= 63; /* 1: yes; 0: no */++    return x;+}++static void+ge25519_cmov(ge25519_precomp *t, const ge25519_precomp *u, unsigned char b)+{+    fe25519_cmov(t->yplusx, u->yplusx, b);+    fe25519_cmov(t->yminusx, u->yminusx, b);+    fe25519_cmov(t->xy2d, u->xy2d, b);+}++static void+ge25519_cmov_cached(ge25519_cached *t, const ge25519_cached *u, unsigned char b)+{+    fe25519_cmov(t->YplusX, u->YplusX, b);+    fe25519_cmov(t->YminusX, u->YminusX, b);+    fe25519_cmov(t->Z, u->Z, b);+    fe25519_cmov(t->T2d, u->T2d, b);+}++static void+ge25519_cmov8(ge25519_precomp *t, const ge25519_precomp precomp[8], const signed char b)+{+    ge25519_precomp     minust;+    const unsigned char bnegative = negative(b);+    const unsigned char babs      = b - (((-bnegative) & b) * ((signed char) 1 << 1));++    ge25519_precomp_0(t);+    ge25519_cmov(t, &precomp[0], equal(babs, 1));+    ge25519_cmov(t, &precomp[1], equal(babs, 2));+    ge25519_cmov(t, &precomp[2], equal(babs, 3));+    ge25519_cmov(t, &precomp[3], equal(babs, 4));+    ge25519_cmov(t, &precomp[4], equal(babs, 5));+    ge25519_cmov(t, &precomp[5], equal(babs, 6));+    ge25519_cmov(t, &precomp[6], equal(babs, 7));+    ge25519_cmov(t, &precomp[7], equal(babs, 8));+    fe25519_copy(minust.yplusx, t->yminusx);+    fe25519_copy(minust.yminusx, t->yplusx);+    fe25519_neg(minust.xy2d, t->xy2d);+    ge25519_cmov(t, &minust, bnegative);+}++static void+ge25519_cmov8_base(ge25519_precomp *t, const int pos, const signed char b)+{+    static const ge25519_precomp base[32][8] = { /* base[i][j] = (j+1)*256^i*B */+#ifdef HAVE_TI_MODE+# include "fe_51/base.h"+#else+# include "fe_25_5/base.h"+#endif+    };+    ge25519_cmov8(t, base[pos], b);+}++static void+ge25519_cmov8_cached(ge25519_cached *t, const ge25519_cached cached[8], const signed char b)+{+    ge25519_cached      minust;+    const unsigned char bnegative = negative(b);+    const unsigned char babs      = b - (((-bnegative) & b) * ((signed char) 1 << 1));++    ge25519_cached_0(t);+    ge25519_cmov_cached(t, &cached[0], equal(babs, 1));+    ge25519_cmov_cached(t, &cached[1], equal(babs, 2));+    ge25519_cmov_cached(t, &cached[2], equal(babs, 3));+    ge25519_cmov_cached(t, &cached[3], equal(babs, 4));+    ge25519_cmov_cached(t, &cached[4], equal(babs, 5));+    ge25519_cmov_cached(t, &cached[5], equal(babs, 6));+    ge25519_cmov_cached(t, &cached[6], equal(babs, 7));+    ge25519_cmov_cached(t, &cached[7], equal(babs, 8));+    fe25519_copy(minust.YplusX, t->YminusX);+    fe25519_copy(minust.YminusX, t->YplusX);+    fe25519_copy(minust.Z, t->Z);+    fe25519_neg(minust.T2d, t->T2d);+    ge25519_cmov_cached(t, &minust, bnegative);+}++/*+ r = p - q+ */++void+ge25519_sub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q)+{+    fe25519 t0;++    fe25519_add(r->X, p->Y, p->X);+    fe25519_sub(r->Y, p->Y, p->X);+    fe25519_mul(r->Z, r->X, q->YminusX);+    fe25519_mul(r->Y, r->Y, q->YplusX);+    fe25519_mul(r->T, q->T2d, p->T);+    fe25519_mul(r->X, p->Z, q->Z);+    fe25519_add(t0, r->X, r->X);+    fe25519_sub(r->X, r->Z, r->Y);+    fe25519_add(r->Y, r->Z, r->Y);+    fe25519_sub(r->Z, t0, r->T);+    fe25519_add(r->T, t0, r->T);+}++void+ge25519_tobytes(unsigned char *s, const ge25519_p2 *h)+{+    fe25519 recip;+    fe25519 x;+    fe25519 y;++    fe25519_invert(recip, h->Z);+    fe25519_mul(x, h->X, recip);+    fe25519_mul(y, h->Y, recip);+    fe25519_tobytes(s, y);+    s[31] ^= fe25519_isnegative(x) << 7;+}++/*+ r = a * A + b * B+ where a = a[0]+256*a[1]+...+256^31 a[31].+ and b = b[0]+256*b[1]+...+256^31 b[31].+ B is the Ed25519 base point (x,4/5) with x positive.++ Only used for signatures verification.+ */++void+ge25519_double_scalarmult_vartime(ge25519_p2 *r, const unsigned char *a,+                                  const ge25519_p3 *A, const unsigned char *b)+{+    static const ge25519_precomp Bi[8] = {+#ifdef HAVE_TI_MODE+# include "fe_51/base2.h"+#else+# include "fe_25_5/base2.h"+#endif+    };+    signed char    aslide[256];+    signed char    bslide[256];+    ge25519_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */+    ge25519_p1p1   t;+    ge25519_p3     u;+    ge25519_p3     A2;+    int            i;++    slide_vartime(aslide, a);+    slide_vartime(bslide, b);++    ge25519_p3_to_cached(&Ai[0], A);++    ge25519_p3_dbl(&t, A);+    ge25519_p1p1_to_p3(&A2, &t);++    ge25519_add(&t, &A2, &Ai[0]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[1], &u);++    ge25519_add(&t, &A2, &Ai[1]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[2], &u);++    ge25519_add(&t, &A2, &Ai[2]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[3], &u);++    ge25519_add(&t, &A2, &Ai[3]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[4], &u);++    ge25519_add(&t, &A2, &Ai[4]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[5], &u);++    ge25519_add(&t, &A2, &Ai[5]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[6], &u);++    ge25519_add(&t, &A2, &Ai[6]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[7], &u);++    ge25519_p2_0(r);++    for (i = 255; i >= 0; --i) {+        if (aslide[i] || bslide[i]) {+            break;+        }+    }++    for (; i >= 0; --i) {+        ge25519_p2_dbl(&t, r);++        if (aslide[i] > 0) {+            ge25519_p1p1_to_p3(&u, &t);+            ge25519_add(&t, &u, &Ai[aslide[i] / 2]);+        } else if (aslide[i] < 0) {+            ge25519_p1p1_to_p3(&u, &t);+            ge25519_sub(&t, &u, &Ai[(-aslide[i]) / 2]);+        }++        if (bslide[i] > 0) {+            ge25519_p1p1_to_p3(&u, &t);+            ge25519_madd(&t, &u, &Bi[bslide[i] / 2]);+        } else if (bslide[i] < 0) {+            ge25519_p1p1_to_p3(&u, &t);+            ge25519_msub(&t, &u, &Bi[(-bslide[i]) / 2]);+        }++        ge25519_p1p1_to_p2(r, &t);+    }+}++/*+ h = a * p+ where a = a[0]+256*a[1]+...+256^31 a[31]++ Preconditions:+ a[31] <= 127++ p is public+ */++void+ge25519_scalarmult(ge25519_p3 *h, const unsigned char *a, const ge25519_p3 *p)+{+    signed char     e[64];+    signed char     carry;+    ge25519_p1p1    r;+    ge25519_p2      s;+    ge25519_p1p1    t2, t3, t4, t5, t6, t7, t8;+    ge25519_p3      p2, p3, p4, p5, p6, p7, p8;+    ge25519_cached  pi[8];+    ge25519_cached  t;+    int             i;++    ge25519_p3_to_cached(&pi[1 - 1], p);   /* p */++    ge25519_p3_dbl(&t2, p);+    ge25519_p1p1_to_p3(&p2, &t2);+    ge25519_p3_to_cached(&pi[2 - 1], &p2); /* 2p = 2*p */++    ge25519_add(&t3, p, &pi[2 - 1]);+    ge25519_p1p1_to_p3(&p3, &t3);+    ge25519_p3_to_cached(&pi[3 - 1], &p3); /* 3p = 2p+p */++    ge25519_p3_dbl(&t4, &p2);+    ge25519_p1p1_to_p3(&p4, &t4);+    ge25519_p3_to_cached(&pi[4 - 1], &p4); /* 4p = 2*2p */++    ge25519_add(&t5, p, &pi[4 - 1]);+    ge25519_p1p1_to_p3(&p5, &t5);+    ge25519_p3_to_cached(&pi[5 - 1], &p5); /* 5p = 4p+p */++    ge25519_p3_dbl(&t6, &p3);+    ge25519_p1p1_to_p3(&p6, &t6);+    ge25519_p3_to_cached(&pi[6 - 1], &p6); /* 6p = 2*3p */++    ge25519_add(&t7, p, &pi[6 - 1]);+    ge25519_p1p1_to_p3(&p7, &t7);+    ge25519_p3_to_cached(&pi[7 - 1], &p7); /* 7p = 6p+p */++    ge25519_p3_dbl(&t8, &p4);+    ge25519_p1p1_to_p3(&p8, &t8);+    ge25519_p3_to_cached(&pi[8 - 1], &p8); /* 8p = 2*4p */++    for (i = 0; i < 32; ++i) {+        e[2 * i + 0] = (a[i] >> 0) & 15;+        e[2 * i + 1] = (a[i] >> 4) & 15;+    }+    /* each e[i] is between 0 and 15 */+    /* e[63] is between 0 and 7 */++    carry = 0;+    for (i = 0; i < 63; ++i) {+        e[i] += carry;+        carry = e[i] + 8;+        carry >>= 4;+        e[i] -= carry * ((signed char) 1 << 4);+    }+    e[63] += carry;+    /* each e[i] is between -8 and 8 */++    ge25519_p3_0(h);++    for (i = 63; i != 0; i--) {+        ge25519_cmov8_cached(&t, pi, e[i]);+        ge25519_add(&r, h, &t);++        ge25519_p1p1_to_p2(&s, &r);+        ge25519_p2_dbl(&r, &s);+        ge25519_p1p1_to_p2(&s, &r);+        ge25519_p2_dbl(&r, &s);+        ge25519_p1p1_to_p2(&s, &r);+        ge25519_p2_dbl(&r, &s);+        ge25519_p1p1_to_p2(&s, &r);+        ge25519_p2_dbl(&r, &s);++        ge25519_p1p1_to_p3(h, &r);  /* *16 */+    }+    ge25519_cmov8_cached(&t, pi, e[i]);+    ge25519_add(&r, h, &t);++    ge25519_p1p1_to_p3(h, &r);+}++/*+ h = a * B (with precomputation)+ where a = a[0]+256*a[1]+...+256^31 a[31]+ B is the Ed25519 base point (x,4/5) with x positive+ (as bytes: 0x5866666666666666666666666666666666666666666666666666666666666666)++ Preconditions:+ a[31] <= 127+ */++void+ge25519_scalarmult_base(ge25519_p3 *h, const unsigned char *a)+{+    signed char     e[64];+    signed char     carry;+    ge25519_p1p1    r;+    ge25519_p2      s;+    ge25519_precomp t;+    int             i;++    for (i = 0; i < 32; ++i) {+        e[2 * i + 0] = (a[i] >> 0) & 15;+        e[2 * i + 1] = (a[i] >> 4) & 15;+    }+    /* each e[i] is between 0 and 15 */+    /* e[63] is between 0 and 7 */++    carry = 0;+    for (i = 0; i < 63; ++i) {+        e[i] += carry;+        carry = e[i] + 8;+        carry >>= 4;+        e[i] -= carry * ((signed char) 1 << 4);+    }+    e[63] += carry;+    /* each e[i] is between -8 and 8 */++    ge25519_p3_0(h);++    for (i = 1; i < 64; i += 2) {+        ge25519_cmov8_base(&t, i / 2, e[i]);+        ge25519_madd(&r, h, &t);+        ge25519_p1p1_to_p3(h, &r);+    }++    ge25519_p3_dbl(&r, h);+    ge25519_p1p1_to_p2(&s, &r);+    ge25519_p2_dbl(&r, &s);+    ge25519_p1p1_to_p2(&s, &r);+    ge25519_p2_dbl(&r, &s);+    ge25519_p1p1_to_p2(&s, &r);+    ge25519_p2_dbl(&r, &s);+    ge25519_p1p1_to_p3(h, &r);++    for (i = 0; i < 64; i += 2) {+        ge25519_cmov8_base(&t, i / 2, e[i]);+        ge25519_madd(&r, h, &t);+        ge25519_p1p1_to_p3(h, &r);+    }+}++/* multiply by the order of the main subgroup l = 2^252+27742317777372353535851937790883648493 */+static void+ge25519_mul_l(ge25519_p3 *r, const ge25519_p3 *A)+{+    static const signed char aslide[253] = {+        13, 0, 0, 0, 0, -1, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, -13, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, -13, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 3, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 7, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1+    };+    ge25519_cached Ai[8];+    ge25519_p1p1   t;+    ge25519_p3     u;+    ge25519_p3     A2;+    int            i;++    ge25519_p3_to_cached(&Ai[0], A);+    ge25519_p3_dbl(&t, A);+    ge25519_p1p1_to_p3(&A2, &t);+    ge25519_add(&t, &A2, &Ai[0]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[1], &u);+    ge25519_add(&t, &A2, &Ai[1]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[2], &u);+    ge25519_add(&t, &A2, &Ai[2]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[3], &u);+    ge25519_add(&t, &A2, &Ai[3]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[4], &u);+    ge25519_add(&t, &A2, &Ai[4]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[5], &u);+    ge25519_add(&t, &A2, &Ai[5]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[6], &u);+    ge25519_add(&t, &A2, &Ai[6]);+    ge25519_p1p1_to_p3(&u, &t);+    ge25519_p3_to_cached(&Ai[7], &u);++    ge25519_p3_0(r);++    for (i = 252; i >= 0; --i) {+        ge25519_p3_dbl(&t, r);++        if (aslide[i] > 0) {+            ge25519_p1p1_to_p3(&u, &t);+            ge25519_add(&t, &u, &Ai[aslide[i] / 2]);+        } else if (aslide[i] < 0) {+            ge25519_p1p1_to_p3(&u, &t);+            ge25519_sub(&t, &u, &Ai[(-aslide[i]) / 2]);+        }++        ge25519_p1p1_to_p3(r, &t);+    }+}++int+ge25519_is_on_curve(const ge25519_p3 *p)+{+    fe25519 x2;+    fe25519 y2;+    fe25519 z2;+    fe25519 z4;+    fe25519 t0;+    fe25519 t1;++    fe25519_sq(x2, p->X);+    fe25519_sq(y2, p->Y);+    fe25519_sq(z2, p->Z);+    fe25519_sub(t0, y2, x2);+    fe25519_mul(t0, t0, z2);++    fe25519_mul(t1, x2, y2);+    fe25519_mul(t1, t1, d);+    fe25519_sq(z4, z2);+    fe25519_add(t1, t1, z4);+    fe25519_sub(t0, t0, t1);++    return fe25519_iszero(t0);+}++int+ge25519_is_on_main_subgroup(const ge25519_p3 *p)+{+    ge25519_p3 pl;++    ge25519_mul_l(&pl, p);++    return fe25519_iszero(pl.X);+}++int+ge25519_is_canonical(const unsigned char *s)+{+    unsigned char c;+    unsigned char d;+    unsigned int  i;++    c = (s[31] & 0x7f) ^ 0x7f;+    for (i = 30; i > 0; i--) {+        c |= s[i] ^ 0xff;+    }+    c = (((unsigned int) c) - 1U) >> 8;+    d = (0xed - 1U - (unsigned int) s[0]) >> 8;++    return 1 - (c & d & 1);+}++int+ge25519_has_small_order(const unsigned char s[32])+{+    CRYPTO_ALIGN(16)+    static const unsigned char blacklist[][32] = {+        /* 0 (order 4) */+        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },+        /* 1 (order 1) */+        { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },+        /* 2707385501144840649318225287225658788936804267575313519463743609750303402022+           (order 8) */+        { 0x26, 0xe8, 0x95, 0x8f, 0xc2, 0xb2, 0x27, 0xb0, 0x45, 0xc3, 0xf4,+          0x89, 0xf2, 0xef, 0x98, 0xf0, 0xd5, 0xdf, 0xac, 0x05, 0xd3, 0xc6,+          0x33, 0x39, 0xb1, 0x38, 0x02, 0x88, 0x6d, 0x53, 0xfc, 0x05 },+        /* 55188659117513257062467267217118295137698188065244968500265048394206261417927+           (order 8) */+        { 0xc7, 0x17, 0x6a, 0x70, 0x3d, 0x4d, 0xd8, 0x4f, 0xba, 0x3c, 0x0b,+          0x76, 0x0d, 0x10, 0x67, 0x0f, 0x2a, 0x20, 0x53, 0xfa, 0x2c, 0x39,+          0xcc, 0xc6, 0x4e, 0xc7, 0xfd, 0x77, 0x92, 0xac, 0x03, 0x7a },+        /* p-1 (order 2) */+        { 0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f },+        /* p (=0, order 4) */+        { 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f },+        /* p+1 (=1, order 1) */+        { 0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }+    };+    unsigned char c[7] = { 0 };+    unsigned int  k;+    size_t        i, j;++    COMPILER_ASSERT(7 == sizeof blacklist / sizeof blacklist[0]);+    for (j = 0; j < 31; j++) {+        for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {+            c[i] |= s[j] ^ blacklist[i][j];+        }+    }+    for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {+        c[i] |= (s[j] & 0x7f) ^ blacklist[i][j];+    }+    k = 0;+    for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {+        k |= (c[i] - 1);+    }+    return (int) ((k >> 8) & 1);+}++/*+ Input:+ a[0]+256*a[1]+...+256^31*a[31] = a+ b[0]+256*b[1]+...+256^31*b[31] = b+ *+ Output:+ s[0]+256*s[1]+...+256^31*s[31] = (ab) mod l+ where l = 2^252 + 27742317777372353535851937790883648493.+ */++void+sc25519_mul(unsigned char s[32], const unsigned char a[32], const unsigned char b[32])+{+    int64_t a0  = 2097151 & load_3(a);+    int64_t a1  = 2097151 & (load_4(a + 2) >> 5);+    int64_t a2  = 2097151 & (load_3(a + 5) >> 2);+    int64_t a3  = 2097151 & (load_4(a + 7) >> 7);+    int64_t a4  = 2097151 & (load_4(a + 10) >> 4);+    int64_t a5  = 2097151 & (load_3(a + 13) >> 1);+    int64_t a6  = 2097151 & (load_4(a + 15) >> 6);+    int64_t a7  = 2097151 & (load_3(a + 18) >> 3);+    int64_t a8  = 2097151 & load_3(a + 21);+    int64_t a9  = 2097151 & (load_4(a + 23) >> 5);+    int64_t a10 = 2097151 & (load_3(a + 26) >> 2);+    int64_t a11 = (load_4(a + 28) >> 7);++    int64_t b0  = 2097151 & load_3(b);+    int64_t b1  = 2097151 & (load_4(b + 2) >> 5);+    int64_t b2  = 2097151 & (load_3(b + 5) >> 2);+    int64_t b3  = 2097151 & (load_4(b + 7) >> 7);+    int64_t b4  = 2097151 & (load_4(b + 10) >> 4);+    int64_t b5  = 2097151 & (load_3(b + 13) >> 1);+    int64_t b6  = 2097151 & (load_4(b + 15) >> 6);+    int64_t b7  = 2097151 & (load_3(b + 18) >> 3);+    int64_t b8  = 2097151 & load_3(b + 21);+    int64_t b9  = 2097151 & (load_4(b + 23) >> 5);+    int64_t b10 = 2097151 & (load_3(b + 26) >> 2);+    int64_t b11 = (load_4(b + 28) >> 7);++    int64_t s0;+    int64_t s1;+    int64_t s2;+    int64_t s3;+    int64_t s4;+    int64_t s5;+    int64_t s6;+    int64_t s7;+    int64_t s8;+    int64_t s9;+    int64_t s10;+    int64_t s11;+    int64_t s12;+    int64_t s13;+    int64_t s14;+    int64_t s15;+    int64_t s16;+    int64_t s17;+    int64_t s18;+    int64_t s19;+    int64_t s20;+    int64_t s21;+    int64_t s22;+    int64_t s23;++    int64_t carry0;+    int64_t carry1;+    int64_t carry2;+    int64_t carry3;+    int64_t carry4;+    int64_t carry5;+    int64_t carry6;+    int64_t carry7;+    int64_t carry8;+    int64_t carry9;+    int64_t carry10;+    int64_t carry11;+    int64_t carry12;+    int64_t carry13;+    int64_t carry14;+    int64_t carry15;+    int64_t carry16;+    int64_t carry17;+    int64_t carry18;+    int64_t carry19;+    int64_t carry20;+    int64_t carry21;+    int64_t carry22;++    s0 = a0 * b0;+    s1 = a0 * b1 + a1 * b0;+    s2 = a0 * b2 + a1 * b1 + a2 * b0;+    s3 = a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;+    s4 = a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;+    s5 = a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;+    s6 = a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0;+    s7 = a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 ++         a6 * b1 + a7 * b0;+    s8 = a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 ++         a6 * b2 + a7 * b1 + a8 * b0;+    s9 = a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 ++         a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;+    s10 = a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 ++          a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;+    s11 = a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 ++          a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;+    s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 ++          a7 * b5 + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;+    s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 ++          a8 * b5 + a9 * b4 + a10 * b3 + a11 * b2;+    s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 ++          a9 * b5 + a10 * b4 + a11 * b3;+    s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 ++          a10 * b5 + a11 * b4;+    s16 =+        a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;+    s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;+    s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;+    s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;+    s20 = a9 * b11 + a10 * b10 + a11 * b9;+    s21 = a10 * b11 + a11 * b10;+    s22 = a11 * b11;+    s23 = 0;++    carry0 = (s0 + (int64_t) (1L << 20)) >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry2 = (s2 + (int64_t) (1L << 20)) >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry4 = (s4 + (int64_t) (1L << 20)) >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry6 = (s6 + (int64_t) (1L << 20)) >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry8 = (s8 + (int64_t) (1L << 20)) >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry10 = (s10 + (int64_t) (1L << 20)) >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);+    carry12 = (s12 + (int64_t) (1L << 20)) >> 21;+    s13 += carry12;+    s12 -= carry12 * ((uint64_t) 1L << 21);+    carry14 = (s14 + (int64_t) (1L << 20)) >> 21;+    s15 += carry14;+    s14 -= carry14 * ((uint64_t) 1L << 21);+    carry16 = (s16 + (int64_t) (1L << 20)) >> 21;+    s17 += carry16;+    s16 -= carry16 * ((uint64_t) 1L << 21);+    carry18 = (s18 + (int64_t) (1L << 20)) >> 21;+    s19 += carry18;+    s18 -= carry18 * ((uint64_t) 1L << 21);+    carry20 = (s20 + (int64_t) (1L << 20)) >> 21;+    s21 += carry20;+    s20 -= carry20 * ((uint64_t) 1L << 21);+    carry22 = (s22 + (int64_t) (1L << 20)) >> 21;+    s23 += carry22;+    s22 -= carry22 * ((uint64_t) 1L << 21);++    carry1 = (s1 + (int64_t) (1L << 20)) >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry3 = (s3 + (int64_t) (1L << 20)) >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry5 = (s5 + (int64_t) (1L << 20)) >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry7 = (s7 + (int64_t) (1L << 20)) >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry9 = (s9 + (int64_t) (1L << 20)) >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry11 = (s11 + (int64_t) (1L << 20)) >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);+    carry13 = (s13 + (int64_t) (1L << 20)) >> 21;+    s14 += carry13;+    s13 -= carry13 * ((uint64_t) 1L << 21);+    carry15 = (s15 + (int64_t) (1L << 20)) >> 21;+    s16 += carry15;+    s15 -= carry15 * ((uint64_t) 1L << 21);+    carry17 = (s17 + (int64_t) (1L << 20)) >> 21;+    s18 += carry17;+    s17 -= carry17 * ((uint64_t) 1L << 21);+    carry19 = (s19 + (int64_t) (1L << 20)) >> 21;+    s20 += carry19;+    s19 -= carry19 * ((uint64_t) 1L << 21);+    carry21 = (s21 + (int64_t) (1L << 20)) >> 21;+    s22 += carry21;+    s21 -= carry21 * ((uint64_t) 1L << 21);++    s11 += s23 * 666643;+    s12 += s23 * 470296;+    s13 += s23 * 654183;+    s14 -= s23 * 997805;+    s15 += s23 * 136657;+    s16 -= s23 * 683901;++    s10 += s22 * 666643;+    s11 += s22 * 470296;+    s12 += s22 * 654183;+    s13 -= s22 * 997805;+    s14 += s22 * 136657;+    s15 -= s22 * 683901;++    s9 += s21 * 666643;+    s10 += s21 * 470296;+    s11 += s21 * 654183;+    s12 -= s21 * 997805;+    s13 += s21 * 136657;+    s14 -= s21 * 683901;++    s8 += s20 * 666643;+    s9 += s20 * 470296;+    s10 += s20 * 654183;+    s11 -= s20 * 997805;+    s12 += s20 * 136657;+    s13 -= s20 * 683901;++    s7 += s19 * 666643;+    s8 += s19 * 470296;+    s9 += s19 * 654183;+    s10 -= s19 * 997805;+    s11 += s19 * 136657;+    s12 -= s19 * 683901;++    s6 += s18 * 666643;+    s7 += s18 * 470296;+    s8 += s18 * 654183;+    s9 -= s18 * 997805;+    s10 += s18 * 136657;+    s11 -= s18 * 683901;++    carry6 = (s6 + (int64_t) (1L << 20)) >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry8 = (s8 + (int64_t) (1L << 20)) >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry10 = (s10 + (int64_t) (1L << 20)) >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);+    carry12 = (s12 + (int64_t) (1L << 20)) >> 21;+    s13 += carry12;+    s12 -= carry12 * ((uint64_t) 1L << 21);+    carry14 = (s14 + (int64_t) (1L << 20)) >> 21;+    s15 += carry14;+    s14 -= carry14 * ((uint64_t) 1L << 21);+    carry16 = (s16 + (int64_t) (1L << 20)) >> 21;+    s17 += carry16;+    s16 -= carry16 * ((uint64_t) 1L << 21);++    carry7 = (s7 + (int64_t) (1L << 20)) >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry9 = (s9 + (int64_t) (1L << 20)) >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry11 = (s11 + (int64_t) (1L << 20)) >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);+    carry13 = (s13 + (int64_t) (1L << 20)) >> 21;+    s14 += carry13;+    s13 -= carry13 * ((uint64_t) 1L << 21);+    carry15 = (s15 + (int64_t) (1L << 20)) >> 21;+    s16 += carry15;+    s15 -= carry15 * ((uint64_t) 1L << 21);++    s5 += s17 * 666643;+    s6 += s17 * 470296;+    s7 += s17 * 654183;+    s8 -= s17 * 997805;+    s9 += s17 * 136657;+    s10 -= s17 * 683901;++    s4 += s16 * 666643;+    s5 += s16 * 470296;+    s6 += s16 * 654183;+    s7 -= s16 * 997805;+    s8 += s16 * 136657;+    s9 -= s16 * 683901;++    s3 += s15 * 666643;+    s4 += s15 * 470296;+    s5 += s15 * 654183;+    s6 -= s15 * 997805;+    s7 += s15 * 136657;+    s8 -= s15 * 683901;++    s2 += s14 * 666643;+    s3 += s14 * 470296;+    s4 += s14 * 654183;+    s5 -= s14 * 997805;+    s6 += s14 * 136657;+    s7 -= s14 * 683901;++    s1 += s13 * 666643;+    s2 += s13 * 470296;+    s3 += s13 * 654183;+    s4 -= s13 * 997805;+    s5 += s13 * 136657;+    s6 -= s13 * 683901;++    s0 += s12 * 666643;+    s1 += s12 * 470296;+    s2 += s12 * 654183;+    s3 -= s12 * 997805;+    s4 += s12 * 136657;+    s5 -= s12 * 683901;+    s12 = 0;++    carry0 = (s0 + (int64_t) (1L << 20)) >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry2 = (s2 + (int64_t) (1L << 20)) >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry4 = (s4 + (int64_t) (1L << 20)) >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry6 = (s6 + (int64_t) (1L << 20)) >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry8 = (s8 + (int64_t) (1L << 20)) >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry10 = (s10 + (int64_t) (1L << 20)) >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);++    carry1 = (s1 + (int64_t) (1L << 20)) >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry3 = (s3 + (int64_t) (1L << 20)) >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry5 = (s5 + (int64_t) (1L << 20)) >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry7 = (s7 + (int64_t) (1L << 20)) >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry9 = (s9 + (int64_t) (1L << 20)) >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry11 = (s11 + (int64_t) (1L << 20)) >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);++    s0 += s12 * 666643;+    s1 += s12 * 470296;+    s2 += s12 * 654183;+    s3 -= s12 * 997805;+    s4 += s12 * 136657;+    s5 -= s12 * 683901;+    s12 = 0;++    carry0 = s0 >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry1 = s1 >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry2 = s2 >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry3 = s3 >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry4 = s4 >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry5 = s5 >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry6 = s6 >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry7 = s7 >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry8 = s8 >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry9 = s9 >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry10 = s10 >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);+    carry11 = s11 >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);++    s0 += s12 * 666643;+    s1 += s12 * 470296;+    s2 += s12 * 654183;+    s3 -= s12 * 997805;+    s4 += s12 * 136657;+    s5 -= s12 * 683901;++    carry0 = s0 >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry1 = s1 >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry2 = s2 >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry3 = s3 >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry4 = s4 >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry5 = s5 >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry6 = s6 >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry7 = s7 >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry8 = s8 >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry9 = s9 >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry10 = s10 >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);++    s[0]  = s0 >> 0;+    s[1]  = s0 >> 8;+    s[2]  = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));+    s[3]  = s1 >> 3;+    s[4]  = s1 >> 11;+    s[5]  = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));+    s[6]  = s2 >> 6;+    s[7]  = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));+    s[8]  = s3 >> 1;+    s[9]  = s3 >> 9;+    s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));+    s[11] = s4 >> 4;+    s[12] = s4 >> 12;+    s[13] = (s4 >> 20) | (s5 * ((uint64_t) 1 << 1));+    s[14] = s5 >> 7;+    s[15] = (s5 >> 15) | (s6 * ((uint64_t) 1 << 6));+    s[16] = s6 >> 2;+    s[17] = s6 >> 10;+    s[18] = (s6 >> 18) | (s7 * ((uint64_t) 1 << 3));+    s[19] = s7 >> 5;+    s[20] = s7 >> 13;+    s[21] = s8 >> 0;+    s[22] = s8 >> 8;+    s[23] = (s8 >> 16) | (s9 * ((uint64_t) 1 << 5));+    s[24] = s9 >> 3;+    s[25] = s9 >> 11;+    s[26] = (s9 >> 19) | (s10 * ((uint64_t) 1 << 2));+    s[27] = s10 >> 6;+    s[28] = (s10 >> 14) | (s11 * ((uint64_t) 1 << 7));+    s[29] = s11 >> 1;+    s[30] = s11 >> 9;+    s[31] = s11 >> 17;+}++/*+ Input:+ a[0]+256*a[1]+...+256^31*a[31] = a+ b[0]+256*b[1]+...+256^31*b[31] = b+ c[0]+256*c[1]+...+256^31*c[31] = c+ *+ Output:+ s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l+ where l = 2^252 + 27742317777372353535851937790883648493.+ */++void+sc25519_muladd(unsigned char s[32], const unsigned char a[32],+               const unsigned char b[32], const unsigned char c[32])+{+    int64_t a0  = 2097151 & load_3(a);+    int64_t a1  = 2097151 & (load_4(a + 2) >> 5);+    int64_t a2  = 2097151 & (load_3(a + 5) >> 2);+    int64_t a3  = 2097151 & (load_4(a + 7) >> 7);+    int64_t a4  = 2097151 & (load_4(a + 10) >> 4);+    int64_t a5  = 2097151 & (load_3(a + 13) >> 1);+    int64_t a6  = 2097151 & (load_4(a + 15) >> 6);+    int64_t a7  = 2097151 & (load_3(a + 18) >> 3);+    int64_t a8  = 2097151 & load_3(a + 21);+    int64_t a9  = 2097151 & (load_4(a + 23) >> 5);+    int64_t a10 = 2097151 & (load_3(a + 26) >> 2);+    int64_t a11 = (load_4(a + 28) >> 7);++    int64_t b0  = 2097151 & load_3(b);+    int64_t b1  = 2097151 & (load_4(b + 2) >> 5);+    int64_t b2  = 2097151 & (load_3(b + 5) >> 2);+    int64_t b3  = 2097151 & (load_4(b + 7) >> 7);+    int64_t b4  = 2097151 & (load_4(b + 10) >> 4);+    int64_t b5  = 2097151 & (load_3(b + 13) >> 1);+    int64_t b6  = 2097151 & (load_4(b + 15) >> 6);+    int64_t b7  = 2097151 & (load_3(b + 18) >> 3);+    int64_t b8  = 2097151 & load_3(b + 21);+    int64_t b9  = 2097151 & (load_4(b + 23) >> 5);+    int64_t b10 = 2097151 & (load_3(b + 26) >> 2);+    int64_t b11 = (load_4(b + 28) >> 7);++    int64_t c0  = 2097151 & load_3(c);+    int64_t c1  = 2097151 & (load_4(c + 2) >> 5);+    int64_t c2  = 2097151 & (load_3(c + 5) >> 2);+    int64_t c3  = 2097151 & (load_4(c + 7) >> 7);+    int64_t c4  = 2097151 & (load_4(c + 10) >> 4);+    int64_t c5  = 2097151 & (load_3(c + 13) >> 1);+    int64_t c6  = 2097151 & (load_4(c + 15) >> 6);+    int64_t c7  = 2097151 & (load_3(c + 18) >> 3);+    int64_t c8  = 2097151 & load_3(c + 21);+    int64_t c9  = 2097151 & (load_4(c + 23) >> 5);+    int64_t c10 = 2097151 & (load_3(c + 26) >> 2);+    int64_t c11 = (load_4(c + 28) >> 7);++    int64_t s0;+    int64_t s1;+    int64_t s2;+    int64_t s3;+    int64_t s4;+    int64_t s5;+    int64_t s6;+    int64_t s7;+    int64_t s8;+    int64_t s9;+    int64_t s10;+    int64_t s11;+    int64_t s12;+    int64_t s13;+    int64_t s14;+    int64_t s15;+    int64_t s16;+    int64_t s17;+    int64_t s18;+    int64_t s19;+    int64_t s20;+    int64_t s21;+    int64_t s22;+    int64_t s23;++    int64_t carry0;+    int64_t carry1;+    int64_t carry2;+    int64_t carry3;+    int64_t carry4;+    int64_t carry5;+    int64_t carry6;+    int64_t carry7;+    int64_t carry8;+    int64_t carry9;+    int64_t carry10;+    int64_t carry11;+    int64_t carry12;+    int64_t carry13;+    int64_t carry14;+    int64_t carry15;+    int64_t carry16;+    int64_t carry17;+    int64_t carry18;+    int64_t carry19;+    int64_t carry20;+    int64_t carry21;+    int64_t carry22;++    s0 = c0 + a0 * b0;+    s1 = c1 + a0 * b1 + a1 * b0;+    s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0;+    s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;+    s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;+    s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;+    s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 ++         a6 * b0;+    s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 ++         a6 * b1 + a7 * b0;+    s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 ++         a6 * b2 + a7 * b1 + a8 * b0;+    s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 ++         a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;+    s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 ++          a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;+    s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 ++          a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;+    s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 ++          a7 * b5 + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;+    s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 ++          a8 * b5 + a9 * b4 + a10 * b3 + a11 * b2;+    s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 ++          a9 * b5 + a10 * b4 + a11 * b3;+    s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 ++          a10 * b5 + a11 * b4;+    s16 =+        a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;+    s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;+    s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;+    s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;+    s20 = a9 * b11 + a10 * b10 + a11 * b9;+    s21 = a10 * b11 + a11 * b10;+    s22 = a11 * b11;+    s23 = 0;++    carry0 = (s0 + (int64_t) (1L << 20)) >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry2 = (s2 + (int64_t) (1L << 20)) >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry4 = (s4 + (int64_t) (1L << 20)) >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry6 = (s6 + (int64_t) (1L << 20)) >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry8 = (s8 + (int64_t) (1L << 20)) >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry10 = (s10 + (int64_t) (1L << 20)) >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);+    carry12 = (s12 + (int64_t) (1L << 20)) >> 21;+    s13 += carry12;+    s12 -= carry12 * ((uint64_t) 1L << 21);+    carry14 = (s14 + (int64_t) (1L << 20)) >> 21;+    s15 += carry14;+    s14 -= carry14 * ((uint64_t) 1L << 21);+    carry16 = (s16 + (int64_t) (1L << 20)) >> 21;+    s17 += carry16;+    s16 -= carry16 * ((uint64_t) 1L << 21);+    carry18 = (s18 + (int64_t) (1L << 20)) >> 21;+    s19 += carry18;+    s18 -= carry18 * ((uint64_t) 1L << 21);+    carry20 = (s20 + (int64_t) (1L << 20)) >> 21;+    s21 += carry20;+    s20 -= carry20 * ((uint64_t) 1L << 21);+    carry22 = (s22 + (int64_t) (1L << 20)) >> 21;+    s23 += carry22;+    s22 -= carry22 * ((uint64_t) 1L << 21);++    carry1 = (s1 + (int64_t) (1L << 20)) >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry3 = (s3 + (int64_t) (1L << 20)) >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry5 = (s5 + (int64_t) (1L << 20)) >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry7 = (s7 + (int64_t) (1L << 20)) >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry9 = (s9 + (int64_t) (1L << 20)) >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry11 = (s11 + (int64_t) (1L << 20)) >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);+    carry13 = (s13 + (int64_t) (1L << 20)) >> 21;+    s14 += carry13;+    s13 -= carry13 * ((uint64_t) 1L << 21);+    carry15 = (s15 + (int64_t) (1L << 20)) >> 21;+    s16 += carry15;+    s15 -= carry15 * ((uint64_t) 1L << 21);+    carry17 = (s17 + (int64_t) (1L << 20)) >> 21;+    s18 += carry17;+    s17 -= carry17 * ((uint64_t) 1L << 21);+    carry19 = (s19 + (int64_t) (1L << 20)) >> 21;+    s20 += carry19;+    s19 -= carry19 * ((uint64_t) 1L << 21);+    carry21 = (s21 + (int64_t) (1L << 20)) >> 21;+    s22 += carry21;+    s21 -= carry21 * ((uint64_t) 1L << 21);++    s11 += s23 * 666643;+    s12 += s23 * 470296;+    s13 += s23 * 654183;+    s14 -= s23 * 997805;+    s15 += s23 * 136657;+    s16 -= s23 * 683901;++    s10 += s22 * 666643;+    s11 += s22 * 470296;+    s12 += s22 * 654183;+    s13 -= s22 * 997805;+    s14 += s22 * 136657;+    s15 -= s22 * 683901;++    s9 += s21 * 666643;+    s10 += s21 * 470296;+    s11 += s21 * 654183;+    s12 -= s21 * 997805;+    s13 += s21 * 136657;+    s14 -= s21 * 683901;++    s8 += s20 * 666643;+    s9 += s20 * 470296;+    s10 += s20 * 654183;+    s11 -= s20 * 997805;+    s12 += s20 * 136657;+    s13 -= s20 * 683901;++    s7 += s19 * 666643;+    s8 += s19 * 470296;+    s9 += s19 * 654183;+    s10 -= s19 * 997805;+    s11 += s19 * 136657;+    s12 -= s19 * 683901;++    s6 += s18 * 666643;+    s7 += s18 * 470296;+    s8 += s18 * 654183;+    s9 -= s18 * 997805;+    s10 += s18 * 136657;+    s11 -= s18 * 683901;++    carry6 = (s6 + (int64_t) (1L << 20)) >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry8 = (s8 + (int64_t) (1L << 20)) >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry10 = (s10 + (int64_t) (1L << 20)) >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);+    carry12 = (s12 + (int64_t) (1L << 20)) >> 21;+    s13 += carry12;+    s12 -= carry12 * ((uint64_t) 1L << 21);+    carry14 = (s14 + (int64_t) (1L << 20)) >> 21;+    s15 += carry14;+    s14 -= carry14 * ((uint64_t) 1L << 21);+    carry16 = (s16 + (int64_t) (1L << 20)) >> 21;+    s17 += carry16;+    s16 -= carry16 * ((uint64_t) 1L << 21);++    carry7 = (s7 + (int64_t) (1L << 20)) >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry9 = (s9 + (int64_t) (1L << 20)) >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry11 = (s11 + (int64_t) (1L << 20)) >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);+    carry13 = (s13 + (int64_t) (1L << 20)) >> 21;+    s14 += carry13;+    s13 -= carry13 * ((uint64_t) 1L << 21);+    carry15 = (s15 + (int64_t) (1L << 20)) >> 21;+    s16 += carry15;+    s15 -= carry15 * ((uint64_t) 1L << 21);++    s5 += s17 * 666643;+    s6 += s17 * 470296;+    s7 += s17 * 654183;+    s8 -= s17 * 997805;+    s9 += s17 * 136657;+    s10 -= s17 * 683901;++    s4 += s16 * 666643;+    s5 += s16 * 470296;+    s6 += s16 * 654183;+    s7 -= s16 * 997805;+    s8 += s16 * 136657;+    s9 -= s16 * 683901;++    s3 += s15 * 666643;+    s4 += s15 * 470296;+    s5 += s15 * 654183;+    s6 -= s15 * 997805;+    s7 += s15 * 136657;+    s8 -= s15 * 683901;++    s2 += s14 * 666643;+    s3 += s14 * 470296;+    s4 += s14 * 654183;+    s5 -= s14 * 997805;+    s6 += s14 * 136657;+    s7 -= s14 * 683901;++    s1 += s13 * 666643;+    s2 += s13 * 470296;+    s3 += s13 * 654183;+    s4 -= s13 * 997805;+    s5 += s13 * 136657;+    s6 -= s13 * 683901;++    s0 += s12 * 666643;+    s1 += s12 * 470296;+    s2 += s12 * 654183;+    s3 -= s12 * 997805;+    s4 += s12 * 136657;+    s5 -= s12 * 683901;+    s12 = 0;++    carry0 = (s0 + (int64_t) (1L << 20)) >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry2 = (s2 + (int64_t) (1L << 20)) >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry4 = (s4 + (int64_t) (1L << 20)) >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry6 = (s6 + (int64_t) (1L << 20)) >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry8 = (s8 + (int64_t) (1L << 20)) >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry10 = (s10 + (int64_t) (1L << 20)) >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);++    carry1 = (s1 + (int64_t) (1L << 20)) >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry3 = (s3 + (int64_t) (1L << 20)) >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry5 = (s5 + (int64_t) (1L << 20)) >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry7 = (s7 + (int64_t) (1L << 20)) >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry9 = (s9 + (int64_t) (1L << 20)) >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry11 = (s11 + (int64_t) (1L << 20)) >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);++    s0 += s12 * 666643;+    s1 += s12 * 470296;+    s2 += s12 * 654183;+    s3 -= s12 * 997805;+    s4 += s12 * 136657;+    s5 -= s12 * 683901;+    s12 = 0;++    carry0 = s0 >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry1 = s1 >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry2 = s2 >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry3 = s3 >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry4 = s4 >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry5 = s5 >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry6 = s6 >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry7 = s7 >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry8 = s8 >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry9 = s9 >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry10 = s10 >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);+    carry11 = s11 >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);++    s0 += s12 * 666643;+    s1 += s12 * 470296;+    s2 += s12 * 654183;+    s3 -= s12 * 997805;+    s4 += s12 * 136657;+    s5 -= s12 * 683901;++    carry0 = s0 >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry1 = s1 >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry2 = s2 >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry3 = s3 >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry4 = s4 >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry5 = s5 >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry6 = s6 >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry7 = s7 >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry8 = s8 >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry9 = s9 >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry10 = s10 >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);++    s[0]  = s0 >> 0;+    s[1]  = s0 >> 8;+    s[2]  = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));+    s[3]  = s1 >> 3;+    s[4]  = s1 >> 11;+    s[5]  = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));+    s[6]  = s2 >> 6;+    s[7]  = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));+    s[8]  = s3 >> 1;+    s[9]  = s3 >> 9;+    s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));+    s[11] = s4 >> 4;+    s[12] = s4 >> 12;+    s[13] = (s4 >> 20) | (s5 * ((uint64_t) 1 << 1));+    s[14] = s5 >> 7;+    s[15] = (s5 >> 15) | (s6 * ((uint64_t) 1 << 6));+    s[16] = s6 >> 2;+    s[17] = s6 >> 10;+    s[18] = (s6 >> 18) | (s7 * ((uint64_t) 1 << 3));+    s[19] = s7 >> 5;+    s[20] = s7 >> 13;+    s[21] = s8 >> 0;+    s[22] = s8 >> 8;+    s[23] = (s8 >> 16) | (s9 * ((uint64_t) 1 << 5));+    s[24] = s9 >> 3;+    s[25] = s9 >> 11;+    s[26] = (s9 >> 19) | (s10 * ((uint64_t) 1 << 2));+    s[27] = s10 >> 6;+    s[28] = (s10 >> 14) | (s11 * ((uint64_t) 1 << 7));+    s[29] = s11 >> 1;+    s[30] = s11 >> 9;+    s[31] = s11 >> 17;+}++/*+ Input:+ a[0]+256*a[1]+...+256^31*a[31] = a+ *+ Output:+ s[0]+256*s[1]+...+256^31*s[31] = a^2 mod l+ where l = 2^252 + 27742317777372353535851937790883648493.+ */++static inline void+sc25519_sq(unsigned char *s, const unsigned char *a)+{+    sc25519_mul(s, a, a);+}++/*+ Input:+ s[0]+256*a[1]+...+256^31*a[31] = a+ n+ *+ Output:+ s[0]+256*s[1]+...+256^31*s[31] = x * s^(s^n) mod l+ where l = 2^252 + 27742317777372353535851937790883648493.+ Overwrites s in place.+ */++static inline void+sc25519_sqmul(unsigned char s[32], const int n, const unsigned char a[32])+{+    int i;++    for (i = 0; i < n; i++) {+        sc25519_sq(s, s);+    }+    sc25519_mul(s, s, a);+}++void+sc25519_invert(unsigned char recip[32], const unsigned char s[32])+{+    unsigned char _10[32], _100[32], _1000[32], _10000[32], _100000[32],+        _1000000[32], _10010011[32], _10010111[32], _100110[32], _1010[32],+        _1010000[32], _1010011[32], _1011[32], _10110[32], _10111101[32],+        _11[32], _1100011[32], _1100111[32], _11010011[32], _1101011[32],+        _11100111[32], _11101011[32], _11110101[32];++    sc25519_sq(_10, s);+    sc25519_mul(_11, s, _10);+    sc25519_mul(_100, s, _11);+    sc25519_sq(_1000, _100);+    sc25519_mul(_1010, _10, _1000);+    sc25519_mul(_1011, s, _1010);+    sc25519_sq(_10000, _1000);+    sc25519_sq(_10110, _1011);+    sc25519_mul(_100000, _1010, _10110);+    sc25519_mul(_100110, _10000, _10110);+    sc25519_sq(_1000000, _100000);+    sc25519_mul(_1010000, _10000, _1000000);+    sc25519_mul(_1010011, _11, _1010000);+    sc25519_mul(_1100011, _10000, _1010011);+    sc25519_mul(_1100111, _100, _1100011);+    sc25519_mul(_1101011, _100, _1100111);+    sc25519_mul(_10010011, _1000000, _1010011);+    sc25519_mul(_10010111, _100, _10010011);+    sc25519_mul(_10111101, _100110, _10010111);+    sc25519_mul(_11010011, _10110, _10111101);+    sc25519_mul(_11100111, _1010000, _10010111);+    sc25519_mul(_11101011, _100, _11100111);+    sc25519_mul(_11110101, _1010, _11101011);++    sc25519_mul(recip, _1011, _11110101);+    sc25519_sqmul(recip, 126, _1010011);+    sc25519_sqmul(recip, 9, _10);+    sc25519_mul(recip, recip, _11110101);+    sc25519_sqmul(recip, 7, _1100111);+    sc25519_sqmul(recip, 9, _11110101);+    sc25519_sqmul(recip, 11, _10111101);+    sc25519_sqmul(recip, 8, _11100111);+    sc25519_sqmul(recip, 9, _1101011);+    sc25519_sqmul(recip, 6, _1011);+    sc25519_sqmul(recip, 14, _10010011);+    sc25519_sqmul(recip, 10, _1100011);+    sc25519_sqmul(recip, 9, _10010111);+    sc25519_sqmul(recip, 10, _11110101);+    sc25519_sqmul(recip, 8, _11010011);+    sc25519_sqmul(recip, 8, _11101011);+}++/*+ Input:+ s[0]+256*s[1]+...+256^63*s[63] = s+ *+ Output:+ s[0]+256*s[1]+...+256^31*s[31] = s mod l+ where l = 2^252 + 27742317777372353535851937790883648493.+ Overwrites s in place.+ */++void+sc25519_reduce(unsigned char s[64])+{+    int64_t s0  = 2097151 & load_3(s);+    int64_t s1  = 2097151 & (load_4(s + 2) >> 5);+    int64_t s2  = 2097151 & (load_3(s + 5) >> 2);+    int64_t s3  = 2097151 & (load_4(s + 7) >> 7);+    int64_t s4  = 2097151 & (load_4(s + 10) >> 4);+    int64_t s5  = 2097151 & (load_3(s + 13) >> 1);+    int64_t s6  = 2097151 & (load_4(s + 15) >> 6);+    int64_t s7  = 2097151 & (load_3(s + 18) >> 3);+    int64_t s8  = 2097151 & load_3(s + 21);+    int64_t s9  = 2097151 & (load_4(s + 23) >> 5);+    int64_t s10 = 2097151 & (load_3(s + 26) >> 2);+    int64_t s11 = 2097151 & (load_4(s + 28) >> 7);+    int64_t s12 = 2097151 & (load_4(s + 31) >> 4);+    int64_t s13 = 2097151 & (load_3(s + 34) >> 1);+    int64_t s14 = 2097151 & (load_4(s + 36) >> 6);+    int64_t s15 = 2097151 & (load_3(s + 39) >> 3);+    int64_t s16 = 2097151 & load_3(s + 42);+    int64_t s17 = 2097151 & (load_4(s + 44) >> 5);+    int64_t s18 = 2097151 & (load_3(s + 47) >> 2);+    int64_t s19 = 2097151 & (load_4(s + 49) >> 7);+    int64_t s20 = 2097151 & (load_4(s + 52) >> 4);+    int64_t s21 = 2097151 & (load_3(s + 55) >> 1);+    int64_t s22 = 2097151 & (load_4(s + 57) >> 6);+    int64_t s23 = (load_4(s + 60) >> 3);++    int64_t carry0;+    int64_t carry1;+    int64_t carry2;+    int64_t carry3;+    int64_t carry4;+    int64_t carry5;+    int64_t carry6;+    int64_t carry7;+    int64_t carry8;+    int64_t carry9;+    int64_t carry10;+    int64_t carry11;+    int64_t carry12;+    int64_t carry13;+    int64_t carry14;+    int64_t carry15;+    int64_t carry16;++    s11 += s23 * 666643;+    s12 += s23 * 470296;+    s13 += s23 * 654183;+    s14 -= s23 * 997805;+    s15 += s23 * 136657;+    s16 -= s23 * 683901;++    s10 += s22 * 666643;+    s11 += s22 * 470296;+    s12 += s22 * 654183;+    s13 -= s22 * 997805;+    s14 += s22 * 136657;+    s15 -= s22 * 683901;++    s9 += s21 * 666643;+    s10 += s21 * 470296;+    s11 += s21 * 654183;+    s12 -= s21 * 997805;+    s13 += s21 * 136657;+    s14 -= s21 * 683901;++    s8 += s20 * 666643;+    s9 += s20 * 470296;+    s10 += s20 * 654183;+    s11 -= s20 * 997805;+    s12 += s20 * 136657;+    s13 -= s20 * 683901;++    s7 += s19 * 666643;+    s8 += s19 * 470296;+    s9 += s19 * 654183;+    s10 -= s19 * 997805;+    s11 += s19 * 136657;+    s12 -= s19 * 683901;++    s6 += s18 * 666643;+    s7 += s18 * 470296;+    s8 += s18 * 654183;+    s9 -= s18 * 997805;+    s10 += s18 * 136657;+    s11 -= s18 * 683901;++    carry6 = (s6 + (int64_t) (1L << 20)) >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry8 = (s8 + (int64_t) (1L << 20)) >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry10 = (s10 + (int64_t) (1L << 20)) >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);+    carry12 = (s12 + (int64_t) (1L << 20)) >> 21;+    s13 += carry12;+    s12 -= carry12 * ((uint64_t) 1L << 21);+    carry14 = (s14 + (int64_t) (1L << 20)) >> 21;+    s15 += carry14;+    s14 -= carry14 * ((uint64_t) 1L << 21);+    carry16 = (s16 + (int64_t) (1L << 20)) >> 21;+    s17 += carry16;+    s16 -= carry16 * ((uint64_t) 1L << 21);++    carry7 = (s7 + (int64_t) (1L << 20)) >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry9 = (s9 + (int64_t) (1L << 20)) >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry11 = (s11 + (int64_t) (1L << 20)) >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);+    carry13 = (s13 + (int64_t) (1L << 20)) >> 21;+    s14 += carry13;+    s13 -= carry13 * ((uint64_t) 1L << 21);+    carry15 = (s15 + (int64_t) (1L << 20)) >> 21;+    s16 += carry15;+    s15 -= carry15 * ((uint64_t) 1L << 21);++    s5 += s17 * 666643;+    s6 += s17 * 470296;+    s7 += s17 * 654183;+    s8 -= s17 * 997805;+    s9 += s17 * 136657;+    s10 -= s17 * 683901;++    s4 += s16 * 666643;+    s5 += s16 * 470296;+    s6 += s16 * 654183;+    s7 -= s16 * 997805;+    s8 += s16 * 136657;+    s9 -= s16 * 683901;++    s3 += s15 * 666643;+    s4 += s15 * 470296;+    s5 += s15 * 654183;+    s6 -= s15 * 997805;+    s7 += s15 * 136657;+    s8 -= s15 * 683901;++    s2 += s14 * 666643;+    s3 += s14 * 470296;+    s4 += s14 * 654183;+    s5 -= s14 * 997805;+    s6 += s14 * 136657;+    s7 -= s14 * 683901;++    s1 += s13 * 666643;+    s2 += s13 * 470296;+    s3 += s13 * 654183;+    s4 -= s13 * 997805;+    s5 += s13 * 136657;+    s6 -= s13 * 683901;++    s0 += s12 * 666643;+    s1 += s12 * 470296;+    s2 += s12 * 654183;+    s3 -= s12 * 997805;+    s4 += s12 * 136657;+    s5 -= s12 * 683901;+    s12 = 0;++    carry0 = (s0 + (int64_t) (1L << 20)) >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry2 = (s2 + (int64_t) (1L << 20)) >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry4 = (s4 + (int64_t) (1L << 20)) >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry6 = (s6 + (int64_t) (1L << 20)) >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry8 = (s8 + (int64_t) (1L << 20)) >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry10 = (s10 + (int64_t) (1L << 20)) >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);++    carry1 = (s1 + (int64_t) (1L << 20)) >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry3 = (s3 + (int64_t) (1L << 20)) >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry5 = (s5 + (int64_t) (1L << 20)) >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry7 = (s7 + (int64_t) (1L << 20)) >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry9 = (s9 + (int64_t) (1L << 20)) >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry11 = (s11 + (int64_t) (1L << 20)) >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);++    s0 += s12 * 666643;+    s1 += s12 * 470296;+    s2 += s12 * 654183;+    s3 -= s12 * 997805;+    s4 += s12 * 136657;+    s5 -= s12 * 683901;+    s12 = 0;++    carry0 = s0 >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry1 = s1 >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry2 = s2 >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry3 = s3 >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry4 = s4 >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry5 = s5 >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry6 = s6 >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry7 = s7 >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry8 = s8 >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry9 = s9 >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry10 = s10 >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);+    carry11 = s11 >> 21;+    s12 += carry11;+    s11 -= carry11 * ((uint64_t) 1L << 21);++    s0 += s12 * 666643;+    s1 += s12 * 470296;+    s2 += s12 * 654183;+    s3 -= s12 * 997805;+    s4 += s12 * 136657;+    s5 -= s12 * 683901;++    carry0 = s0 >> 21;+    s1 += carry0;+    s0 -= carry0 * ((uint64_t) 1L << 21);+    carry1 = s1 >> 21;+    s2 += carry1;+    s1 -= carry1 * ((uint64_t) 1L << 21);+    carry2 = s2 >> 21;+    s3 += carry2;+    s2 -= carry2 * ((uint64_t) 1L << 21);+    carry3 = s3 >> 21;+    s4 += carry3;+    s3 -= carry3 * ((uint64_t) 1L << 21);+    carry4 = s4 >> 21;+    s5 += carry4;+    s4 -= carry4 * ((uint64_t) 1L << 21);+    carry5 = s5 >> 21;+    s6 += carry5;+    s5 -= carry5 * ((uint64_t) 1L << 21);+    carry6 = s6 >> 21;+    s7 += carry6;+    s6 -= carry6 * ((uint64_t) 1L << 21);+    carry7 = s7 >> 21;+    s8 += carry7;+    s7 -= carry7 * ((uint64_t) 1L << 21);+    carry8 = s8 >> 21;+    s9 += carry8;+    s8 -= carry8 * ((uint64_t) 1L << 21);+    carry9 = s9 >> 21;+    s10 += carry9;+    s9 -= carry9 * ((uint64_t) 1L << 21);+    carry10 = s10 >> 21;+    s11 += carry10;+    s10 -= carry10 * ((uint64_t) 1L << 21);++    s[0]  = s0 >> 0;+    s[1]  = s0 >> 8;+    s[2]  = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));+    s[3]  = s1 >> 3;+    s[4]  = s1 >> 11;+    s[5]  = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));+    s[6]  = s2 >> 6;+    s[7]  = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));+    s[8]  = s3 >> 1;+    s[9]  = s3 >> 9;+    s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));+    s[11] = s4 >> 4;+    s[12] = s4 >> 12;+    s[13] = (s4 >> 20) | (s5 * ((uint64_t) 1 << 1));+    s[14] = s5 >> 7;+    s[15] = (s5 >> 15) | (s6 * ((uint64_t) 1 << 6));+    s[16] = s6 >> 2;+    s[17] = s6 >> 10;+    s[18] = (s6 >> 18) | (s7 * ((uint64_t) 1 << 3));+    s[19] = s7 >> 5;+    s[20] = s7 >> 13;+    s[21] = s8 >> 0;+    s[22] = s8 >> 8;+    s[23] = (s8 >> 16) | (s9 * ((uint64_t) 1 << 5));+    s[24] = s9 >> 3;+    s[25] = s9 >> 11;+    s[26] = (s9 >> 19) | (s10 * ((uint64_t) 1 << 2));+    s[27] = s10 >> 6;+    s[28] = (s10 >> 14) | (s11 * ((uint64_t) 1 << 7));+    s[29] = s11 >> 1;+    s[30] = s11 >> 9;+    s[31] = s11 >> 17;+}++int+sc25519_is_canonical(const unsigned char s[32])+{+    /* 2^252+27742317777372353535851937790883648493 */+    static const unsigned char L[32] = {+        0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7,+        0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10+    };+    unsigned char c = 0;+    unsigned char n = 1;+    unsigned int  i = 32;++    do {+        i--;+        c |= ((s[i] - L[i]) >> 8) & n;+        n &= ((s[i] ^ L[i]) - 1) >> 8;+    } while (i != 0);++    return (c != 0);+}++/* multiply by the cofactor */+static void+ge25519_clear_cofactor(ge25519_p3 *p3)+{+    ge25519_p1p1 p1;+    ge25519_p2   p2;++    ge25519_p3_dbl(&p1, p3);+    ge25519_p1p1_to_p2(&p2, &p1);+    ge25519_p2_dbl(&p1, &p2);+    ge25519_p1p1_to_p2(&p2, &p1);+    ge25519_p2_dbl(&p1, &p2);+    ge25519_p1p1_to_p3(p3, &p1);+}++static void+ge25519_elligator2(unsigned char s[32], const fe25519 r, const unsigned char x_sign)+{+    fe25519      gx;+    fe25519      negx;+    fe25519      rr2;+    fe25519      x, x2, x3;+    ge25519_p3   p3;+    unsigned int notsquare;++    fe25519_sq2(rr2, r);+    rr2[0]++;+    fe25519_invert(rr2, rr2);+    fe25519_mul32(x, rr2, curve25519_A[0]);+    fe25519_neg(x, x);++    fe25519_sq(x2, x);+    fe25519_mul(x3, x, x2);+    fe25519_add(gx, x3, x);+    fe25519_mul32(x2, x2, curve25519_A[0]);+    fe25519_add(gx, x2, gx);++    notsquare = fe25519_notsquare(gx);+    fe25519_neg(negx, x);+    fe25519_cmov(x, negx, notsquare);+    fe25519_0(x2);+    fe25519_cmov(x2, curve25519_A, notsquare);+    fe25519_sub(x, x, x2);++    /* yed = (x-1)/(x+1) */+    {+        fe25519 one;+        fe25519 x_plus_one;+        fe25519 x_plus_one_inv;+        fe25519 x_minus_one;+        fe25519 yed;++        fe25519_1(one);+        fe25519_add(x_plus_one, x, one);+        fe25519_sub(x_minus_one, x, one);+        fe25519_invert(x_plus_one_inv, x_plus_one);+        fe25519_mul(yed, x_minus_one, x_plus_one_inv);+        fe25519_tobytes(s, yed);+    }++    /* recover x */+    s[31] |= x_sign;+    if (ge25519_frombytes(&p3, s) != 0) {+        abort(); /* LCOV_EXCL_LINE */+    }++    ge25519_clear_cofactor(&p3);+    ge25519_p3_tobytes(s, &p3);+}++void+ge25519_from_uniform(unsigned char s[32], const unsigned char r[32])+{+    fe25519       r_fe;+    unsigned char x_sign;++    memcpy(s, r, 32);+    x_sign = s[31] & 0x80;+    s[31] &= 0x7f;+    fe25519_frombytes(r_fe, s);+    ge25519_elligator2(s, r_fe, x_sign);+}++void+ge25519_from_hash(unsigned char s[32], const unsigned char h[64])+{+    unsigned char fl[32];+    unsigned char gl[32];+    fe25519       fe_f;+    fe25519       fe_g;+    size_t        i;+    unsigned char x_sign;++    x_sign = h[0] & 0x80;+    for (i = 0; i < 32; i++) {+        fl[i] = h[63 - i];+        gl[i] = h[31 - i];+    }+    fl[31] &= 0x7f;+    gl[31] &= 0x7f;+    fe25519_frombytes(fe_f, fl);+    fe25519_frombytes(fe_g, gl);+    fe_f[0] += (h[32] >> 7) * 19;+    for (i = 0; i < sizeof (fe25519) / sizeof fe_f[0]; i++) {+        fe_f[i] += 38 * fe_g[i];+    }+    fe25519_reduce(fe_f, fe_f);+    ge25519_elligator2(s, fe_f, x_sign);+}++/* Ristretto group */++static int+ristretto255_sqrt_ratio_m1(fe25519 x, const fe25519 u, const fe25519 v)+{+    fe25519 v3;+    fe25519 vxx;+    fe25519 m_root_check, p_root_check, f_root_check;+    fe25519 x_sqrtm1;+    int     has_m_root, has_p_root, has_f_root;++    fe25519_sq(v3, v);+    fe25519_mul(v3, v3, v); /* v3 = v^3 */+    fe25519_sq(x, v3);+    fe25519_mul(x, x, v);+    fe25519_mul(x, x, u); /* x = uv^7 */++    fe25519_pow22523(x, x); /* x = (uv^7)^((q-5)/8) */+    fe25519_mul(x, x, v3);+    fe25519_mul(x, x, u); /* x = uv^3(uv^7)^((q-5)/8) */++    fe25519_sq(vxx, x);+    fe25519_mul(vxx, vxx, v); /* vx^2 */+    fe25519_sub(m_root_check, vxx, u); /* vx^2-u */+    fe25519_add(p_root_check, vxx, u); /* vx^2+u */+    fe25519_mul(f_root_check, u, sqrtm1); /* u*sqrt(-1) */+    fe25519_add(f_root_check, vxx, f_root_check); /* vx^2+u*sqrt(-1) */+    has_m_root = fe25519_iszero(m_root_check);+    has_p_root = fe25519_iszero(p_root_check);+    has_f_root = fe25519_iszero(f_root_check);+    fe25519_mul(x_sqrtm1, x, sqrtm1); /* x*sqrt(-1) */++    fe25519_cmov(x, x_sqrtm1, has_p_root | has_f_root);+    fe25519_abs(x, x);++    return has_m_root | has_p_root;+}++static int+ristretto255_is_canonical(const unsigned char *s)+{+    unsigned char c;+    unsigned char d;+    unsigned char e;+    unsigned int  i;++    c = (s[31] & 0x7f) ^ 0x7f;+    for (i = 30; i > 0; i--) {+        c |= s[i] ^ 0xff;+    }+    c = (((unsigned int) c) - 1U) >> 8;+    d = (0xed - 1U - (unsigned int) s[0]) >> 8;+    e = s[31] >> 7;++    return 1 - (((c & d) | e | s[0]) & 1);+}++int+ristretto255_frombytes(ge25519_p3 *h, const unsigned char *s)+{+    fe25519 inv_sqrt;+    fe25519 one;+    fe25519 s_;+    fe25519 ss;+    fe25519 u1, u2;+    fe25519 u1u1, u2u2;+    fe25519 v;+    fe25519 v_u2u2;+    int     was_square;++    if (ristretto255_is_canonical(s) == 0) {+        return -1;+    }+    fe25519_frombytes(s_, s);+    fe25519_sq(ss, s_);                /* ss = s^2 */++    fe25519_1(u1);+    fe25519_sub(u1, u1, ss);           /* u1 = 1-ss */+    fe25519_sq(u1u1, u1);              /* u1u1 = u1^2 */++    fe25519_1(u2);+    fe25519_add(u2, u2, ss);           /* u2 = 1+ss */+    fe25519_sq(u2u2, u2);              /* u2u2 = u2^2 */++    fe25519_mul(v, d, u1u1);           /* v = d*u1^2 */+    fe25519_neg(v, v);                 /* v = -d*u1^2 */+    fe25519_sub(v, v, u2u2);           /* v = -(d*u1^2)-u2^2 */++    fe25519_mul(v_u2u2, v, u2u2);      /* v_u2u2 = v*u2^2 */++    fe25519_1(one);+    was_square = ristretto255_sqrt_ratio_m1(inv_sqrt, one, v_u2u2);+    fe25519_mul(h->X, inv_sqrt, u2);+    fe25519_mul(h->Y, inv_sqrt, h->X);+    fe25519_mul(h->Y, h->Y, v);++    fe25519_mul(h->X, h->X, s_);+    fe25519_add(h->X, h->X, h->X);+    fe25519_abs(h->X, h->X);+    fe25519_mul(h->Y, u1, h->Y);+    fe25519_1(h->Z);+    fe25519_mul(h->T, h->X, h->Y);++    return - ((1 - was_square) |+              fe25519_isnegative(h->T) | fe25519_iszero(h->Y));+}++void+ristretto255_p3_tobytes(unsigned char *s, const ge25519_p3 *h)+{+    fe25519 den1, den2;+    fe25519 den_inv;+    fe25519 eden;+    fe25519 inv_sqrt;+    fe25519 ix, iy;+    fe25519 one;+    fe25519 s_;+    fe25519 t_z_inv;+    fe25519 u1, u2;+    fe25519 u1_u2u2;+    fe25519 x_, y_;+    fe25519 x_z_inv;+    fe25519 z_inv;+    fe25519 zmy;+    int     rotate;++    fe25519_add(u1, h->Z, h->Y);       /* u1 = Z+Y */+    fe25519_sub(zmy, h->Z, h->Y);      /* zmy = Z-Y */+    fe25519_mul(u1, u1, zmy);          /* u1 = (Z+Y)*(Z-Y) */+    fe25519_mul(u2, h->X, h->Y);       /* u2 = X*Y */++    fe25519_sq(u1_u2u2, u2);           /* u1_u2u2 = u2^2 */+    fe25519_mul(u1_u2u2, u1, u1_u2u2); /* u1_u2u2 = u1*u2^2 */++    fe25519_1(one);+    (void) ristretto255_sqrt_ratio_m1(inv_sqrt, one, u1_u2u2);+    fe25519_mul(den1, inv_sqrt, u1);   /* den1 = inv_sqrt*u1 */+    fe25519_mul(den2, inv_sqrt, u2);   /* den2 = inv_sqrt*u2 */+    fe25519_mul(z_inv, den1, den2);    /* z_inv = den1*den2 */+    fe25519_mul(z_inv, z_inv, h->T);   /* z_inv = den1*den2*T */++    fe25519_mul(ix, h->X, sqrtm1);     /* ix = X*sqrt(-1) */+    fe25519_mul(iy, h->Y, sqrtm1);     /* iy = Y*sqrt(-1) */+    fe25519_mul(eden, den1, invsqrtamd); /* eden = den1/sqrt(a-d) */++    fe25519_mul(t_z_inv, h->T, z_inv); /* t_z_inv = T*z_inv */+    rotate = fe25519_isnegative(t_z_inv);++    fe25519_copy(x_, h->X);+    fe25519_copy(y_, h->Y);+    fe25519_copy(den_inv, den2);++    fe25519_cmov(x_, iy, rotate);+    fe25519_cmov(y_, ix, rotate);+    fe25519_cmov(den_inv, eden, rotate);++    fe25519_mul(x_z_inv, x_, z_inv);+    fe25519_cneg(y_, y_, fe25519_isnegative(x_z_inv));++    fe25519_sub(s_, h->Z, y_);+    fe25519_mul(s_, den_inv, s_);+    fe25519_abs(s_, s_);+    fe25519_tobytes(s, s_);+}++static void+ristretto255_elligator(ge25519_p3 *p, const fe25519 t)+{+    fe25519 c;+    fe25519 n;+    fe25519 one;+    fe25519 r;+    fe25519 rpd;+    fe25519 s, s_prime;+    fe25519 ss;+    fe25519 u, v;+    fe25519 w0, w1, w2, w3;+    int     wasnt_square;++    fe25519_1(one);+    fe25519_sq(r, t);                  /* r = t^2 */+    fe25519_mul(r, sqrtm1, r);         /* r = sqrt(-1)*t^2 */+    fe25519_add(u, r, one);            /* u = r+1 */+    fe25519_mul(u, u, onemsqd);        /* u = (r+1)*(1-d^2) */+    fe25519_1(c);+    fe25519_neg(c, c);                 /* c = -1 */+    fe25519_add(rpd, r, d);            /* rpd = r+d */+    fe25519_mul(v, r, d);              /* v = r*d */+    fe25519_sub(v, c, v);              /* v = c-r*d */+    fe25519_mul(v, v, rpd);            /* v = (c-r*d)*(r+d) */++    wasnt_square = 1 - ristretto255_sqrt_ratio_m1(s, u, v);+    fe25519_mul(s_prime, s, t);+    fe25519_abs(s_prime, s_prime);+    fe25519_neg(s_prime, s_prime);     /* s_prime = -|s*t| */+    fe25519_cmov(s, s_prime, wasnt_square);+    fe25519_cmov(c, r, wasnt_square);++    fe25519_sub(n, r, one);            /* n = r-1 */+    fe25519_mul(n, n, c);              /* n = c*(r-1) */+    fe25519_mul(n, n, sqdmone);        /* n = c*(r-1)*(d-1)^2 */+    fe25519_sub(n, n, v);              /* n =  c*(r-1)*(d-1)^2-v */++    fe25519_add(w0, s, s);             /* w0 = 2s */+    fe25519_mul(w0, w0, v);            /* w0 = 2s*v */+    fe25519_mul(w1, n, sqrtadm1);      /* w1 = n*sqrt(ad-1) */+    fe25519_sq(ss, s);                 /* ss = s^2 */+    fe25519_sub(w2, one, ss);          /* w2 = 1-s^2 */+    fe25519_add(w3, one, ss);          /* w3 = 1+s^2 */++    fe25519_mul(p->X, w0, w3);+    fe25519_mul(p->Y, w2, w1);+    fe25519_mul(p->Z, w1, w3);+    fe25519_mul(p->T, w0, w2);+}++void+ristretto255_from_hash(unsigned char s[32], const unsigned char h[64])+{+    fe25519        r0, r1;+    ge25519_cached p1_cached;+    ge25519_p1p1   p_p1p1;+    ge25519_p3     p0, p1;+    ge25519_p3     p;++    fe25519_frombytes(r0, h);+    fe25519_frombytes(r1, h + 32);+    ristretto255_elligator(&p0, r0);+    ristretto255_elligator(&p1, r1);+    ge25519_p3_to_cached(&p1_cached, &p1);+    ge25519_add(&p_p1p1, &p0, &p1_cached);+    ge25519_p1p1_to_p3(&p, &p_p1p1);+    ristretto255_p3_tobytes(s, &p);+}
+ vendor/external/libsodium/crypto_core/ed25519/ref10/fe_25_5/base.h view
@@ -0,0 +1,1344 @@+{ /* 0/31 */+  {+    { 25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605 },+    { -12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378 },+    { -8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546 }+  },+  {+    { -12815894, -12976347, -21581243, 11784320, -25355658, -2750717, -11717903, -3814571, -358445, -10211303 },+    { -21703237, 6903825, 27185491, 6451973, -29577724, -9554005, -15616551, 11189268, -26829678, -5319081 },+    { 26966642, 11152617, 32442495, 15396054, 14353839, -12752335, -3128826, -9541118, -15472047, -4166697 }+  },+  {+    { 15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, -14772189, 28944400, -1550024 },+    { 16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, -11775962, 7689662, 11199574 },+    { 30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, 10017326, -17749093, -9920357 }+  },+  {+    { -17036878, 13921892, 10945806, -6033431, 27105052, -16084379, -28926210, 15006023, 3284568, -6276540 },+    { 23599295, -8306047, -11193664, -7687416, 13236774, 10506355, 7464579, 9656445, 13059162, 10374397 },+    { 7798556, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664, -3839045, -641708, -101325 }+  },+  {+    { 10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, 14515107, -15438304, 10819380 },+    { 4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, 12483688, -12668491, 5581306 },+    { 19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, 13850243, -23678021, -15815942 }+  },+  {+    { -15371964, -12862754, 32573250, 4720197, -26436522, 5875511, -19188627, -15224819, -9818940, -12085777 },+    { -8549212, 109983, 15149363, 2178705, 22900618, 4543417, 3044240, -15689887, 1762328, 14866737 },+    { -18199695, -15951423, -10473290, 1707278, -17185920, 3916101, -28236412, 3959421, 27914454, 4383652 }+  },+  {+    { 5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, 5230134, -23952439, -15175766 },+    { -30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, 16520125, 30598449, 7715701 },+    { 28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, 1370708, 29794553, -1409300 }+  },+  {+    { 14499471, -2729599, -33191113, -4254652, 28494862, 14271267, 30290735, 10876454, -33154098, 2381726 },+    { -7195431, -2655363, -14730155, 462251, -27724326, 3941372, -6236617, 3696005, -32300832, 15351955 },+    { 27431194, 8222322, 16448760, -3907995, -18707002, 11938355, -32961401, -2970515, 29551813, 10109425 }+  }+},+{ /* 1/31 */+  {+    { -13657040, -13155431, -31283750, 11777098, 21447386, 6519384, -2378284, -1627556, 10092783, -4764171 },+    { 27939166, 14210322, 4677035, 16277044, -22964462, -12398139, -32508754, 12005538, -17810127, 12803510 },+    { 17228999, -15661624, -1233527, 300140, -1224870, -11714777, 30364213, -9038194, 18016357, 4397660 }+  },+  {+    { -10958843, -7690207, 4776341, -14954238, 27850028, -15602212, -26619106, 14544525, -17477504, 982639 },+    { 29253598, 15796703, -2863982, -9908884, 10057023, 3163536, 7332899, -4120128, -21047696, 9934963 },+    { 5793303, 16271923, -24131614, -10116404, 29188560, 1206517, -14747930, 4559895, -30123922, -10897950 }+  },+  {+    { -27643952, -11493006, 16282657, -11036493, 28414021, -15012264, 24191034, 4541697, -13338309, 5500568 },+    { 12650548, -1497113, 9052871, 11355358, -17680037, -8400164, -17430592, 12264343, 10874051, 13524335 },+    { 25556948, -3045990, 714651, 2510400, 23394682, -10415330, 33119038, 5080568, -22528059, 5376628 }+  },+  {+    { -26088264, -4011052, -17013699, -3537628, -6726793, 1920897, -22321305, -9447443, 4535768, 1569007 },+    { -2255422, 14606630, -21692440, -8039818, 28430649, 8775819, -30494562, 3044290, 31848280, 12543772 },+    { -22028579, 2943893, -31857513, 6777306, 13784462, -4292203, -27377195, -2062731, 7718482, 14474653 }+  },+  {+    { 2385315, 2454213, -22631320, 46603, -4437935, -15680415, 656965, -7236665, 24316168, -5253567 },+    { 13741529, 10911568, -33233417, -8603737, -20177830, -1033297, 33040651, -13424532, -20729456, 8321686 },+    { 21060490, -2212744, 15712757, -4336099, 1639040, 10656336, 23845965, -11874838, -9984458, 608372 }+  },+  {+    { -13672732, -15087586, -10889693, -7557059, -6036909, 11305547, 1123968, -6780577, 27229399, 23887 },+    { -23244140, -294205, -11744728, 14712571, -29465699, -2029617, 12797024, -6440308, -1633405, 16678954 },+    { -29500620, 4770662, -16054387, 14001338, 7830047, 9564805, -1508144, -4795045, -17169265, 4904953 }+  },+  {+    { 24059557, 14617003, 19037157, -15039908, 19766093, -14906429, 5169211, 16191880, 2128236, -4326833 },+    { -16981152, 4124966, -8540610, -10653797, 30336522, -14105247, -29806336, 916033, -6882542, -2986532 },+    { -22630907, 12419372, -7134229, -7473371, -16478904, 16739175, 285431, 2763829, 15736322, 4143876 }+  },+  {+    { 2379352, 11839345, -4110402, -5988665, 11274298, 794957, 212801, -14594663, 23527084, -16458268 },+    { 33431127, -11130478, -17838966, -15626900, 8909499, 8376530, -32625340, 4087881, -15188911, -14416214 },+    { 1767683, 7197987, -13205226, -2022635, -13091350, 448826, 5799055, 4357868, -4774191, -16323038 }+  }+},+{ /* 2/31 */+  {+    { 6721966, 13833823, -23523388, -1551314, 26354293, -11863321, 23365147, -3949732, 7390890, 2759800 },+    { 4409041, 2052381, 23373853, 10530217, 7676779, -12885954, 21302353, -4264057, 1244380, -12919645 },+    { -4421239, 7169619, 4982368, -2957590, 30256825, -2777540, 14086413, 9208236, 15886429, 16489664 }+  },+  {+    { 1996075, 10375649, 14346367, 13311202, -6874135, -16438411, -13693198, 398369, -30606455, -712933 },+    { -25307465, 9795880, -2777414, 14878809, -33531835, 14780363, 13348553, 12076947, -30836462, 5113182 },+    { -17770784, 11797796, 31950843, 13929123, -25888302, 12288344, -30341101, -7336386, 13847711, 5387222 }+  },+  {+    { -18582163, -3416217, 17824843, -2340966, 22744343, -10442611, 8763061, 3617786, -19600662, 10370991 },+    { 20246567, -14369378, 22358229, -543712, 18507283, -10413996, 14554437, -8746092, 32232924, 16763880 },+    { 9648505, 10094563, 26416693, 14745928, -30374318, -6472621, 11094161, 15689506, 3140038, -16510092 }+  },+  {+    { -16160072, 5472695, 31895588, 4744994, 8823515, 10365685, -27224800, 9448613, -28774454, 366295 },+    { 19153450, 11523972, -11096490, -6503142, -24647631, 5420647, 28344573, 8041113, 719605, 11671788 },+    { 8678025, 2694440, -6808014, 2517372, 4964326, 11152271, -15432916, -15266516, 27000813, -10195553 }+  },+  {+    { -15157904, 7134312, 8639287, -2814877, -7235688, 10421742, 564065, 5336097, 6750977, -14521026 },+    { 11836410, -3979488, 26297894, 16080799, 23455045, 15735944, 1695823, -8819122, 8169720, 16220347 },+    { -18115838, 8653647, 17578566, -6092619, -8025777, -16012763, -11144307, -2627664, -5990708, -14166033 }+  },+  {+    { -23308498, -10968312, 15213228, -10081214, -30853605, -11050004, 27884329, 2847284, 2655861, 1738395 },+    { -27537433, -14253021, -25336301, -8002780, -9370762, 8129821, 21651608, -3239336, -19087449, -11005278 },+    { 1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092, 5821408, 10478196, 8544890 }+  },+  {+    { 32173121, -16129311, 24896207, 3921497, 22579056, -3410854, 19270449, 12217473, 17789017, -3395995 },+    { -30552961, -2228401, -15578829, -10147201, 13243889, 517024, 15479401, -3853233, 30460520, 1052596 },+    { -11614875, 13323618, 32618793, 8175907, -15230173, 12596687, 27491595, -4612359, 3179268, -9478891 }+  },+  {+    { 31947069, -14366651, -4640583, -15339921, -15125977, -6039709, -14756777, -16411740, 19072640, -9511060 },+    { 11685058, 11822410, 3158003, -13952594, 33402194, -4165066, 5977896, -5215017, 473099, 5040608 },+    { -20290863, 8198642, -27410132, 11602123, 1290375, -2799760, 28326862, 1721092, -19558642, -3131606 }+  }+},+{ /* 3/31 */+  {+    { 7881532, 10687937, 7578723, 7738378, -18951012, -2553952, 21820786, 8076149, -27868496, 11538389 },+    { -19935666, 3899861, 18283497, -6801568, -15728660, -11249211, 8754525, 7446702, -5676054, 5797016 },+    { -11295600, -3793569, -15782110, -7964573, 12708869, -8456199, 2014099, -9050574, -2369172, -5877341 }+  },+  {+    { -22472376, -11568741, -27682020, 1146375, 18956691, 16640559, 1192730, -3714199, 15123619, 10811505 },+    { 14352098, -3419715, -18942044, 10822655, 32750596, 4699007, -70363, 15776356, -28886779, -11974553 },+    { -28241164, -8072475, -4978962, -5315317, 29416931, 1847569, -20654173, -16484855, 4714547, -9600655 }+  },+  {+    { 15200332, 8368572, 19679101, 15970074, -31872674, 1959451, 24611599, -4543832, -11745876, 12340220 },+    { 12876937, -10480056, 33134381, 6590940, -6307776, 14872440, 9613953, 8241152, 15370987, 9608631 },+    { -4143277, -12014408, 8446281, -391603, 4407738, 13629032, -7724868, 15866074, -28210621, -8814099 }+  },+  {+    { 26660628, -15677655, 8393734, 358047, -7401291, 992988, -23904233, 858697, 20571223, 8420556 },+    { 14620715, 13067227, -15447274, 8264467, 14106269, 15080814, 33531827, 12516406, -21574435, -12476749 },+    { 236881, 10476226, 57258, -14677024, 6472998, 2466984, 17258519, 7256740, 8791136, 15069930 }+  },+  {+    { 1276410, -9371918, 22949635, -16322807, -23493039, -5702186, 14711875, 4874229, -30663140, -2331391 },+    { 5855666, 4990204, -13711848, 7294284, -7804282, 1924647, -1423175, -7912378, -33069337, 9234253 },+    { 20590503, -9018988, 31529744, -7352666, -2706834, 10650548, 31559055, -11609587, 18979186, 13396066 }+  },+  {+    { 24474287, 4968103, 22267082, 4407354, 24063882, -8325180, -18816887, 13594782, 33514650, 7021958 },+    { -11566906, -6565505, -21365085, 15928892, -26158305, 4315421, -25948728, -3916677, -21480480, 12868082 },+    { -28635013, 13504661, 19988037, -2132761, 21078225, 6443208, -21446107, 2244500, -12455797, -8089383 }+  },+  {+    { -30595528, 13793479, -5852820, 319136, -25723172, -6263899, 33086546, 8957937, -15233648, 5540521 },+    { -11630176, -11503902, -8119500, -7643073, 2620056, 1022908, -23710744, -1568984, -16128528, -14962807 },+    { 23152971, 775386, 27395463, 14006635, -9701118, 4649512, 1689819, 892185, -11513277, -15205948 }+  },+  {+    { 9770129, 9586738, 26496094, 4324120, 1556511, -3550024, 27453819, 4763127, -19179614, 5867134 },+    { -32765025, 1927590, 31726409, -4753295, 23962434, -16019500, 27846559, 5931263, -29749703, -16108455 },+    { 27461885, -2977536, 22380810, 1815854, -23033753, -3031938, 7283490, -15148073, -19526700, 7734629 }+  }+},+{ /* 4/31 */+  {+    { -8010264, -9590817, -11120403, 6196038, 29344158, -13430885, 7585295, -3176626, 18549497, 15302069 },+    { -32658337, -6171222, -7672793, -11051681, 6258878, 13504381, 10458790, -6418461, -8872242, 8424746 },+    { 24687205, 8613276, -30667046, -3233545, 1863892, -1830544, 19206234, 7134917, -11284482, -828919 }+  },+  {+    { 11334899, -9218022, 8025293, 12707519, 17523892, -10476071, 10243738, -14685461, -5066034, 16498837 },+    { 8911542, 6887158, -9584260, -6958590, 11145641, -9543680, 17303925, -14124238, 6536641, 10543906 },+    { -28946384, 15479763, -17466835, 568876, -1497683, 11223454, -2669190, -16625574, -27235709, 8876771 }+  },+  {+    { -25742899, -12566864, -15649966, -846607, -33026686, -796288, -33481822, 15824474, -604426, -9039817 },+    { 10330056, 70051, 7957388, -9002667, 9764902, 15609756, 27698697, -4890037, 1657394, 3084098 },+    { 10477963, -7470260, 12119566, -13250805, 29016247, -5365589, 31280319, 14396151, -30233575, 15272409 }+  },+  {+    { -12288309, 3169463, 28813183, 16658753, 25116432, -5630466, -25173957, -12636138, -25014757, 1950504 },+    { -26180358, 9489187, 11053416, -14746161, -31053720, 5825630, -8384306, -8767532, 15341279, 8373727 },+    { 28685821, 7759505, -14378516, -12002860, -31971820, 4079242, 298136, -10232602, -2878207, 15190420 }+  },+  {+    { -32932876, 13806336, -14337485, -15794431, -24004620, 10940928, 8669718, 2742393, -26033313, -6875003 },+    { -1580388, -11729417, -25979658, -11445023, -17411874, -10912854, 9291594, -16247779, -12154742, 6048605 },+    { -30305315, 14843444, 1539301, 11864366, 20201677, 1900163, 13934231, 5128323, 11213262, 9168384 }+  },+  {+    { -26280513, 11007847, 19408960, -940758, -18592965, -4328580, -5088060, -11105150, 20470157, -16398701 },+    { -23136053, 9282192, 14855179, -15390078, -7362815, -14408560, -22783952, 14461608, 14042978, 5230683 },+    { 29969567, -2741594, -16711867, -8552442, 9175486, -2468974, 21556951, 3506042, -5933891, -12449708 }+  },+  {+    { -3144746, 8744661, 19704003, 4581278, -20430686, 6830683, -21284170, 8971513, -28539189, 15326563 },+    { -19464629, 10110288, -17262528, -3503892, -23500387, 1355669, -15523050, 15300988, -20514118, 9168260 },+    { -5353335, 4488613, -23803248, 16314347, 7780487, -15638939, -28948358, 9601605, 33087103, -9011387 }+  },+  {+    { -19443170, -15512900, -20797467, -12445323, -29824447, 10229461, -27444329, -15000531, -5996870, 15664672 },+    { 23294591, -16632613, -22650781, -8470978, 27844204, 11461195, 13099750, -2460356, 18151676, 13417686 },+    { -24722913, -4176517, -31150679, 5988919, -26858785, 6685065, 1661597, -12551441, 15271676, -15452665 }+  }+},+{ /* 5/31 */+  {+    { 11433042, -13228665, 8239631, -5279517, -1985436, -725718, -18698764, 2167544, -6921301, -13440182 },+    { -31436171, 15575146, 30436815, 12192228, -22463353, 9395379, -9917708, -8638997, 12215110, 12028277 },+    { 14098400, 6555944, 23007258, 5757252, -15427832, -12950502, 30123440, 4617780, -16900089, -655628 }+  },+  {+    { -4026201, -15240835, 11893168, 13718664, -14809462, 1847385, -15819999, 10154009, 23973261, -12684474 },+    { -26531820, -3695990, -1908898, 2534301, -31870557, -16550355, 18341390, -11419951, 32013174, -10103539 },+    { -25479301, 10876443, -11771086, -14625140, -12369567, 1838104, 21911214, 6354752, 4425632, -837822 }+  },+  {+    { -10433389, -14612966, 22229858, -3091047, -13191166, 776729, -17415375, -12020462, 4725005, 14044970 },+    { 19268650, -7304421, 1555349, 8692754, -21474059, -9910664, 6347390, -1411784, -19522291, -16109756 },+    { -24864089, 12986008, -10898878, -5558584, -11312371, -148526, 19541418, 8180106, 9282262, 10282508 }+  },+  {+    { -26205082, 4428547, -8661196, -13194263, 4098402, -14165257, 15522535, 8372215, 5542595, -10702683 },+    { -10562541, 14895633, 26814552, -16673850, -17480754, -2489360, -2781891, 6993761, -18093885, 10114655 },+    { -20107055, -929418, 31422704, 10427861, -7110749, 6150669, -29091755, -11529146, 25953725, -106158 }+  },+  {+    { -4234397, -8039292, -9119125, 3046000, 2101609, -12607294, 19390020, 6094296, -3315279, 12831125 },+    { -15998678, 7578152, 5310217, 14408357, -33548620, -224739, 31575954, 6326196, 7381791, -2421839 },+    { -20902779, 3296811, 24736065, -16328389, 18374254, 7318640, 6295303, 8082724, -15362489, 12339664 }+  },+  {+    { 27724736, 2291157, 6088201, -14184798, 1792727, 5857634, 13848414, 15768922, 25091167, 14856294 },+    { -18866652, 8331043, 24373479, 8541013, -701998, -9269457, 12927300, -12695493, -22182473, -9012899 },+    { -11423429, -5421590, 11632845, 3405020, 30536730, -11674039, -27260765, 13866390, 30146206, 9142070 }+  },+  {+    { 3924129, -15307516, -13817122, -10054960, 12291820, -668366, -27702774, 9326384, -8237858, 4171294 },+    { -15921940, 16037937, 6713787, 16606682, -21612135, 2790944, 26396185, 3731949, 345228, -5462949 },+    { -21327538, 13448259, 25284571, 1143661, 20614966, -8849387, 2031539, -12391231, -16253183, -13582083 }+  },+  {+    { 31016211, -16722429, 26371392, -14451233, -5027349, 14854137, 17477601, 3842657, 28012650, -16405420 },+    { -5075835, 9368966, -8562079, -4600902, -15249953, 6970560, -9189873, 16292057, -8867157, 3507940 },+    { 29439664, 3537914, 23333589, 6997794, -17555561, -11018068, -15209202, -15051267, -9164929, 6580396 }+  }+},+{ /* 6/31 */+  {+    { -12185861, -7679788, 16438269, 10826160, -8696817, -6235611, 17860444, -9273846, -2095802, 9304567 },+    { 20714564, -4336911, 29088195, 7406487, 11426967, -5095705, 14792667, -14608617, 5289421, -477127 },+    { -16665533, -10650790, -6160345, -13305760, 9192020, -1802462, 17271490, 12349094, 26939669, -3752294 }+  },+  {+    { -12889898, 9373458, 31595848, 16374215, 21471720, 13221525, -27283495, -12348559, -3698806, 117887 },+    { 22263325, -6560050, 3984570, -11174646, -15114008, -566785, 28311253, 5358056, -23319780, 541964 },+    { 16259219, 3261970, 2309254, -15534474, -16885711, -4581916, 24134070, -16705829, -13337066, -13552195 }+  },+  {+    { 9378160, -13140186, -22845982, -12745264, 28198281, -7244098, -2399684, -717351, 690426, 14876244 },+    { 24977353, -314384, -8223969, -13465086, 28432343, -1176353, -13068804, -12297348, -22380984, 6618999 },+    { -1538174, 11685646, 12944378, 13682314, -24389511, -14413193, 8044829, -13817328, 32239829, -5652762 }+  },+  {+    { -18603066, 4762990, -926250, 8885304, -28412480, -3187315, 9781647, -10350059, 32779359, 5095274 },+    { -33008130, -5214506, -32264887, -3685216, 9460461, -9327423, -24601656, 14506724, 21639561, -2630236 },+    { -16400943, -13112215, 25239338, 15531969, 3987758, -4499318, -1289502, -6863535, 17874574, 558605 }+  },+  {+    { -13600129, 10240081, 9171883, 16131053, -20869254, 9599700, 33499487, 5080151, 2085892, 5119761 },+    { -22205145, -2519528, -16381601, 414691, -25019550, 2170430, 30634760, -8363614, -31999993, -5759884 },+    { -6845704, 15791202, 8550074, -1312654, 29928809, -12092256, 27534430, -7192145, -22351378, 12961482 }+  },+  {+    { -24492060, -9570771, 10368194, 11582341, -23397293, -2245287, 16533930, 8206996, -30194652, -5159638 },+    { -11121496, -3382234, 2307366, 6362031, -135455, 8868177, -16835630, 7031275, 7589640, 8945490 },+    { -32152748, 8917967, 6661220, -11677616, -1192060, -15793393, 7251489, -11182180, 24099109, -14456170 }+  },+  {+    { 5019558, -7907470, 4244127, -14714356, -26933272, 6453165, -19118182, -13289025, -6231896, -10280736 },+    { 10853594, 10721687, 26480089, 5861829, -22995819, 1972175, -1866647, -10557898, -3363451, -6441124 },+    { -17002408, 5906790, 221599, -6563147, 7828208, -13248918, 24362661, -2008168, -13866408, 7421392 }+  },+  {+    { 8139927, -6546497, 32257646, -5890546, 30375719, 1886181, -21175108, 15441252, 28826358, -4123029 },+    { 6267086, 9695052, 7709135, -16603597, -32869068, -1886135, 14795160, -7840124, 13746021, -1742048 },+    { 28584902, 7787108, -6732942, -15050729, 22846041, -7571236, -3181936, -363524, 4771362, -8419958 }+  }+},+{ /* 7/31 */+  {+    { 24949256, 6376279, -27466481, -8174608, -18646154, -9930606, 33543569, -12141695, 3569627, 11342593 },+    { 26514989, 4740088, 27912651, 3697550, 19331575, -11472339, 6809886, 4608608, 7325975, -14801071 },+    { -11618399, -14554430, -24321212, 7655128, -1369274, 5214312, -27400540, 10258390, -17646694, -8186692 }+  },+  {+    { 11431204, 15823007, 26570245, 14329124, 18029990, 4796082, -31446179, 15580664, 9280358, -3973687 },+    { -160783, -10326257, -22855316, -4304997, -20861367, -13621002, -32810901, -11181622, -15545091, 4387441 },+    { -20799378, 12194512, 3937617, -5805892, -27154820, 9340370, -24513992, 8548137, 20617071, -7482001 }+  },+  {+    { -938825, -3930586, -8714311, 16124718, 24603125, -6225393, -13775352, -11875822, 24345683, 10325460 },+    { -19855277, -1568885, -22202708, 8714034, 14007766, 6928528, 16318175, -1010689, 4766743, 3552007 },+    { -21751364, -16730916, 1351763, -803421, -4009670, 3950935, 3217514, 14481909, 10988822, -3994762 }+  },+  {+    { 15564307, -14311570, 3101243, 5684148, 30446780, -8051356, 12677127, -6505343, -8295852, 13296005 },+    { -9442290, 6624296, -30298964, -11913677, -4670981, -2057379, 31521204, 9614054, -30000824, 12074674 },+    { 4771191, -135239, 14290749, -13089852, 27992298, 14998318, -1413936, -1556716, 29832613, -16391035 }+  },+  {+    { 7064884, -7541174, -19161962, -5067537, -18891269, -2912736, 25825242, 5293297, -27122660, 13101590 },+    { -2298563, 2439670, -7466610, 1719965, -27267541, -16328445, 32512469, -5317593, -30356070, -4190957 },+    { -30006540, 10162316, -33180176, 3981723, -16482138, -13070044, 14413974, 9515896, 19568978, 9628812 }+  },+  {+    { 33053803, 199357, 15894591, 1583059, 27380243, -4580435, -17838894, -6106839, -6291786, 3437740 },+    { -18978877, 3884493, 19469877, 12726490, 15913552, 13614290, -22961733, 70104, 7463304, 4176122 },+    { -27124001, 10659917, 11482427, -16070381, 12771467, -6635117, -32719404, -5322751, 24216882, 5944158 }+  },+  {+    { 8894125, 7450974, -2664149, -9765752, -28080517, -12389115, 19345746, 14680796, 11632993, 5847885 },+    { 26942781, -2315317, 9129564, -4906607, 26024105, 11769399, -11518837, 6367194, -9727230, 4782140 },+    { 19916461, -4828410, -22910704, -11414391, 25606324, -5972441, 33253853, 8220911, 6358847, -1873857 }+  },+  {+    { 801428, -2081702, 16569428, 11065167, 29875704, 96627, 7908388, -4480480, -13538503, 1387155 },+    { 19646058, 5720633, -11416706, 12814209, 11607948, 12749789, 14147075, 15156355, -21866831, 11835260 },+    { 19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523, 15467869, -26560550, 5052483 }+  }+},+{ /* 8/31 */+  {+    { -3017432, 10058206, 1980837, 3964243, 22160966, 12322533, -6431123, -12618185, 12228557, -7003677 },+    { 32944382, 14922211, -22844894, 5188528, 21913450, -8719943, 4001465, 13238564, -6114803, 8653815 },+    { 22865569, -4652735, 27603668, -12545395, 14348958, 8234005, 24808405, 5719875, 28483275, 2841751 }+  },+  {+    { -16420968, -1113305, -327719, -12107856, 21886282, -15552774, -1887966, -315658, 19932058, -12739203 },+    { -11656086, 10087521, -8864888, -5536143, -19278573, -3055912, 3999228, 13239134, -4777469, -13910208 },+    { 1382174, -11694719, 17266790, 9194690, -13324356, 9720081, 20403944, 11284705, -14013818, 3093230 }+  },+  {+    { 16650921, -11037932, -1064178, 1570629, -8329746, 7352753, -302424, 16271225, -24049421, -6691850 },+    { -21911077, -5927941, -4611316, -5560156, -31744103, -10785293, 24123614, 15193618, -21652117, -16739389 },+    { -9935934, -4289447, -25279823, 4372842, 2087473, 10399484, 31870908, 14690798, 17361620, 11864968 }+  },+  {+    { -11307610, 6210372, 13206574, 5806320, -29017692, -13967200, -12331205, -7486601, -25578460, -16240689 },+    { 14668462, -12270235, 26039039, 15305210, 25515617, 4542480, 10453892, 6577524, 9145645, -6443880 },+    { 5974874, 3053895, -9433049, -10385191, -31865124, 3225009, -7972642, 3936128, -5652273, -3050304 }+  },+  {+    { 30625386, -4729400, -25555961, -12792866, -20484575, 7695099, 17097188, -16303496, -27999779, 1803632 },+    { -3553091, 9865099, -5228566, 4272701, -5673832, -16689700, 14911344, 12196514, -21405489, 7047412 },+    { 20093277, 9920966, -11138194, -5343857, 13161587, 12044805, -32856851, 4124601, -32343828, -10257566 }+  },+  {+    { -20788824, 14084654, -13531713, 7842147, 19119038, -13822605, 4752377, -8714640, -21679658, 2288038 },+    { -26819236, -3283715, 29965059, 3039786, -14473765, 2540457, 29457502, 14625692, -24819617, 12570232 },+    { -1063558, -11551823, 16920318, 12494842, 1278292, -5869109, -21159943, -3498680, -11974704, 4724943 }+  },+  {+    { 17960970, -11775534, -4140968, -9702530, -8876562, -1410617, -12907383, -8659932, -29576300, 1903856 },+    { 23134274, -14279132, -10681997, -1611936, 20684485, 15770816, -12989750, 3190296, 26955097, 14109738 },+    { 15308788, 5320727, -30113809, -14318877, 22902008, 7767164, 29425325, -11277562, 31960942, 11934971 }+  },+  {+    { -27395711, 8435796, 4109644, 12222639, -24627868, 14818669, 20638173, 4875028, 10491392, 1379718 },+    { -13159415, 9197841, 3875503, -8936108, -1383712, -5879801, 33518459, 16176658, 21432314, 12180697 },+    { -11787308, 11500838, 13787581, -13832590, -22430679, 10140205, 1465425, 12689540, -10301319, -13872883 }+  }+},+{ /* 9/31 */+  {+    { 5414091, -15386041, -21007664, 9643570, 12834970, 1186149, -2622916, -1342231, 26128231, 6032912 },+    { -26337395, -13766162, 32496025, -13653919, 17847801, -12669156, 3604025, 8316894, -25875034, -10437358 },+    { 3296484, 6223048, 24680646, -12246460, -23052020, 5903205, -8862297, -4639164, 12376617, 3188849 }+  },+  {+    { 29190488, -14659046, 27549113, -1183516, 3520066, -10697301, 32049515, -7309113, -16109234, -9852307 },+    { -14744486, -9309156, 735818, -598978, -20407687, -5057904, 25246078, -15795669, 18640741, -960977 },+    { -6928835, -16430795, 10361374, 5642961, 4910474, 12345252, -31638386, -494430, 10530747, 1053335 }+  },+  {+    { -29265967, -14186805, -13538216, -12117373, -19457059, -10655384, -31462369, -2948985, 24018831, 15026644 },+    { -22592535, -3145277, -2289276, 5953843, -13440189, 9425631, 25310643, 13003497, -2314791, -15145616 },+    { -27419985, -603321, -8043984, -1669117, -26092265, 13987819, -27297622, 187899, -23166419, -2531735 }+  },+  {+    { -21744398, -13810475, 1844840, 5021428, -10434399, -15911473, 9716667, 16266922, -5070217, 726099 },+    { 29370922, -6053998, 7334071, -15342259, 9385287, 2247707, -13661962, -4839461, 30007388, -15823341 },+    { -936379, 16086691, 23751945, -543318, -1167538, -5189036, 9137109, 730663, 9835848, 4555336 }+  },+  {+    { -23376435, 1410446, -22253753, -12899614, 30867635, 15826977, 17693930, 544696, -11985298, 12422646 },+    { 31117226, -12215734, -13502838, 6561947, -9876867, -12757670, -5118685, -4096706, 29120153, 13924425 },+    { -17400879, -14233209, 19675799, -2734756, -11006962, -5858820, -9383939, -11317700, 7240931, -237388 }+  },+  {+    { -31361739, -11346780, -15007447, -5856218, -22453340, -12152771, 1222336, 4389483, 3293637, -15551743 },+    { -16684801, -14444245, 11038544, 11054958, -13801175, -3338533, -24319580, 7733547, 12796905, -6335822 },+    { -8759414, -10817836, -25418864, 10783769, -30615557, -9746811, -28253339, 3647836, 3222231, -11160462 }+  },+  {+    { 18606113, 1693100, -25448386, -15170272, 4112353, 10045021, 23603893, -2048234, -7550776, 2484985 },+    { 9255317, -3131197, -12156162, -1004256, 13098013, -9214866, 16377220, -2102812, -19802075, -3034702 },+    { -22729289, 7496160, -5742199, 11329249, 19991973, -3347502, -31718148, 9936966, -30097688, -10618797 }+  },+  {+    { 21878590, -5001297, 4338336, 13643897, -3036865, 13160960, 19708896, 5415497, -7360503, -4109293 },+    { 27736861, 10103576, 12500508, 8502413, -3413016, -9633558, 10436918, -1550276, -23659143, -8132100 },+    { 19492550, -12104365, -29681976, -852630, -3208171, 12403437, 30066266, 8367329, 13243957, 8709688 }+  }+},+{ /* 10/31 */+  {+    { 12015105, 2801261, 28198131, 10151021, 24818120, -4743133, -11194191, -5645734, 5150968, 7274186 },+    { 2831366, -12492146, 1478975, 6122054, 23825128, -12733586, 31097299, 6083058, 31021603, -9793610 },+    { -2529932, -2229646, 445613, 10720828, -13849527, -11505937, -23507731, 16354465, 15067285, -14147707 }+  },+  {+    { 7840942, 14037873, -33364863, 15934016, -728213, -3642706, 21403988, 1057586, -19379462, -12403220 },+    { 915865, -16469274, 15608285, -8789130, -24357026, 6060030, -17371319, 8410997, -7220461, 16527025 },+    { 32922597, -556987, 20336074, -16184568, 10903705, -5384487, 16957574, 52992, 23834301, 6588044 }+  },+  {+    { 32752030, 11232950, 3381995, -8714866, 22652988, -10744103, 17159699, 16689107, -20314580, -1305992 },+    { -4689649, 9166776, -25710296, -10847306, 11576752, 12733943, 7924251, -2752281, 1976123, -7249027 },+    { 21251222, 16309901, -2983015, -6783122, 30810597, 12967303, 156041, -3371252, 12331345, -8237197 }+  },+  {+    { 8651614, -4477032, -16085636, -4996994, 13002507, 2950805, 29054427, -5106970, 10008136, -4667901 },+    { 31486080, 15114593, -14261250, 12951354, 14369431, -7387845, 16347321, -13662089, 8684155, -10532952 },+    { 19443825, 11385320, 24468943, -9659068, -23919258, 2187569, -26263207, -6086921, 31316348, 14219878 }+  },+  {+    { -28594490, 1193785, 32245219, 11392485, 31092169, 15722801, 27146014, 6992409, 29126555, 9207390 },+    { 32382935, 1110093, 18477781, 11028262, -27411763, -7548111, -4980517, 10843782, -7957600, -14435730 },+    { 2814918, 7836403, 27519878, -7868156, -20894015, -11553689, -21494559, 8550130, 28346258, 1994730 }+  },+  {+    { -19578299, 8085545, -14000519, -3948622, 2785838, -16231307, -19516951, 7174894, 22628102, 8115180 },+    { -30405132, 955511, -11133838, -15078069, -32447087, -13278079, -25651578, 3317160, -9943017, 930272 },+    { -15303681, -6833769, 28856490, 1357446, 23421993, 1057177, 24091212, -1388970, -22765376, -10650715 }+  },+  {+    { -22751231, -5303997, -12907607, -12768866, -15811511, -7797053, -14839018, -16554220, -1867018, 8398970 },+    { -31969310, 2106403, -4736360, 1362501, 12813763, 16200670, 22981545, -6291273, 18009408, -15772772 },+    { -17220923, -9545221, -27784654, 14166835, 29815394, 7444469, 29551787, -3727419, 19288549, 1325865 }+  },+  {+    { 15100157, -15835752, -23923978, -1005098, -26450192, 15509408, 12376730, -3479146, 33166107, -8042750 },+    { 20909231, 13023121, -9209752, 16251778, -5778415, -8094914, 12412151, 10018715, 2213263, -13878373 },+    { 32529814, -11074689, 30361439, -16689753, -9135940, 1513226, 22922121, 6382134, -5766928, 8371348 }+  }+},+{ /* 11/31 */+  {+    { 9923462, 11271500, 12616794, 3544722, -29998368, -1721626, 12891687, -8193132, -26442943, 10486144 },+    { -22597207, -7012665, 8587003, -8257861, 4084309, -12970062, 361726, 2610596, -23921530, -11455195 },+    { 5408411, -1136691, -4969122, 10561668, 24145918, 14240566, 31319731, -4235541, 19985175, -3436086 }+  },+  {+    { -13994457, 16616821, 14549246, 3341099, 32155958, 13648976, -17577068, 8849297, 65030, 8370684 },+    { -8320926, -12049626, 31204563, 5839400, -20627288, -1057277, -19442942, 6922164, 12743482, -9800518 },+    { -2361371, 12678785, 28815050, 4759974, -23893047, 4884717, 23783145, 11038569, 18800704, 255233 }+  },+  {+    { -5269658, -1773886, 13957886, 7990715, 23132995, 728773, 13393847, 9066957, 19258688, -14753793 },+    { -2936654, -10827535, -10432089, 14516793, -3640786, 4372541, -31934921, 2209390, -1524053, 2055794 },+    { 580882, 16705327, 5468415, -2683018, -30926419, -14696000, -7203346, -8994389, -30021019, 7394435 }+  },+  {+    { 23838809, 1822728, -15738443, 15242727, 8318092, -3733104, -21672180, -3492205, -4821741, 14799921 },+    { 13345610, 9759151, 3371034, -16137791, 16353039, 8577942, 31129804, 13496856, -9056018, 7402518 },+    { 2286874, -4435931, -20042458, -2008336, -13696227, 5038122, 11006906, -15760352, 8205061, 1607563 }+  },+  {+    { 14414086, -8002132, 3331830, -3208217, 22249151, -5594188, 18364661, -2906958, 30019587, -9029278 },+    { -27688051, 1585953, -10775053, 931069, -29120221, -11002319, -14410829, 12029093, 9944378, 8024 },+    { 4368715, -3709630, 29874200, -15022983, -20230386, -11410704, -16114594, -999085, -8142388, 5640030 }+  },+  {+    { 10299610, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887, -16694564, 15219798, -14327783 },+    { 27425505, -5719081, 3055006, 10660664, 23458024, 595578, -15398605, -1173195, -18342183, 9742717 },+    { 6744077, 2427284, 26042789, 2720740, -847906, 1118974, 32324614, 7406442, 12420155, 1994844 }+  },+  {+    { 14012521, -5024720, -18384453, -9578469, -26485342, -3936439, -13033478, -10909803, 24319929, -6446333 },+    { 16412690, -4507367, 10772641, 15929391, -17068788, -4658621, 10555945, -10484049, -30102368, -4739048 },+    { 22397382, -7767684, -9293161, -12792868, 17166287, -9755136, -27333065, 6199366, 21880021, -12250760 }+  },+  {+    { -4283307, 5368523, -31117018, 8163389, -30323063, 3209128, 16557151, 8890729, 8840445, 4957760 },+    { -15447727, 709327, -6919446, -10870178, -29777922, 6522332, -21720181, 12130072, -14796503, 5005757 },+    { -2114751, -14308128, 23019042, 15765735, -25269683, 6002752, 10183197, -13239326, -16395286, -2176112 }+  }+},+{ /* 12/31 */+  {+    { -19025756, 1632005, 13466291, -7995100, -23640451, 16573537, -32013908, -3057104, 22208662, 2000468 },+    { 3065073, -1412761, -25598674, -361432, -17683065, -5703415, -8164212, 11248527, -3691214, -7414184 },+    { 10379208, -6045554, 8877319, 1473647, -29291284, -12507580, 16690915, 2553332, -3132688, 16400289 }+  },+  {+    { 15716668, 1254266, -18472690, 7446274, -8448918, 6344164, -22097271, -7285580, 26894937, 9132066 },+    { 24158887, 12938817, 11085297, -8177598, -28063478, -4457083, -30576463, 64452, -6817084, -2692882 },+    { 13488534, 7794716, 22236231, 5989356, 25426474, -12578208, 2350710, -3418511, -4688006, 2364226 }+  },+  {+    { 16335052, 9132434, 25640582, 6678888, 1725628, 8517937, -11807024, -11697457, 15445875, -7798101 },+    { 29004207, -7867081, 28661402, -640412, -12794003, -7943086, 31863255, -4135540, -278050, -15759279 },+    { -6122061, -14866665, -28614905, 14569919, -10857999, -3591829, 10343412, -6976290, -29828287, -10815811 }+  },+  {+    { 27081650, 3463984, 14099042, -4517604, 1616303, -6205604, 29542636, 15372179, 17293797, 960709 },+    { 20263915, 11434237, -5765435, 11236810, 13505955, -10857102, -16111345, 6493122, -19384511, 7639714 },+    { -2830798, -14839232, 25403038, -8215196, -8317012, -16173699, 18006287, -16043750, 29994677, -15808121 }+  },+  {+    { 9769828, 5202651, -24157398, -13631392, -28051003, -11561624, -24613141, -13860782, -31184575, 709464 },+    { 12286395, 13076066, -21775189, -1176622, -25003198, 4057652, -32018128, -8890874, 16102007, 13205847 },+    { 13733362, 5599946, 10557076, 3195751, -5557991, 8536970, -25540170, 8525972, 10151379, 10394400 }+  },+  {+    { 4024660, -16137551, 22436262, 12276534, -9099015, -2686099, 19698229, 11743039, -33302334, 8934414 },+    { -15879800, -4525240, -8580747, -2934061, 14634845, -698278, -9449077, 3137094, -11536886, 11721158 },+    { 17555939, -5013938, 8268606, 2331751, -22738815, 9761013, 9319229, 8835153, -9205489, -1280045 }+  },+  {+    { -461409, -7830014, 20614118, 16688288, -7514766, -4807119, 22300304, 505429, 6108462, -6183415 },+    { -5070281, 12367917, -30663534, 3234473, 32617080, -8422642, 29880583, -13483331, -26898490, -7867459 },+    { -31975283, 5726539, 26934134, 10237677, -3173717, -605053, 24199304, 3795095, 7592688, -14992079 }+  },+  {+    { 21594432, -14964228, 17466408, -4077222, 32537084, 2739898, 6407723, 12018833, -28256052, 4298412 },+    { -20650503, -11961496, -27236275, 570498, 3767144, -1717540, 13891942, -1569194, 13717174, 10805743 },+    { -14676630, -15644296, 15287174, 11927123, 24177847, -8175568, -796431, 14860609, -26938930, -5863836 }+  }+},+{ /* 13/31 */+  {+    { 12962541, 5311799, -10060768, 11658280, 18855286, -7954201, 13286263, -12808704, -4381056, 9882022 },+    { 18512079, 11319350, -20123124, 15090309, 18818594, 5271736, -22727904, 3666879, -23967430, -3299429 },+    { -6789020, -3146043, 16192429, 13241070, 15898607, -14206114, -10084880, -6661110, -2403099, 5276065 }+  },+  {+    { 30169808, -5317648, 26306206, -11750859, 27814964, 7069267, 7152851, 3684982, 1449224, 13082861 },+    { 10342826, 3098505, 2119311, 193222, 25702612, 12233820, 23697382, 15056736, -21016438, -8202000 },+    { -33150110, 3261608, 22745853, 7948688, 19370557, -15177665, -26171976, 6482814, -10300080, -11060101 }+  },+  {+    { 32869458, -5408545, 25609743, 15678670, -10687769, -15471071, 26112421, 2521008, -22664288, 6904815 },+    { 29506923, 4457497, 3377935, -9796444, -30510046, 12935080, 1561737, 3841096, -29003639, -6657642 },+    { 10340844, -6630377, -18656632, -2278430, 12621151, -13339055, 30878497, -11824370, -25584551, 5181966 }+  },+  {+    { 25940115, -12658025, 17324188, -10307374, -8671468, 15029094, 24396252, -16450922, -2322852, -12388574 },+    { -21765684, 9916823, -1300409, 4079498, -1028346, 11909559, 1782390, 12641087, 20603771, -6561742 },+    { -18882287, -11673380, 24849422, 11501709, 13161720, -4768874, 1925523, 11914390, 4662781, 7820689 }+  },+  {+    { 12241050, -425982, 8132691, 9393934, 32846760, -1599620, 29749456, 12172924, 16136752, 15264020 },+    { -10349955, -14680563, -8211979, 2330220, -17662549, -14545780, 10658213, 6671822, 19012087, 3772772 },+    { 3753511, -3421066, 10617074, 2028709, 14841030, -6721664, 28718732, -15762884, 20527771, 12988982 }+  },+  {+    { -14822485, -5797269, -3707987, 12689773, -898983, -10914866, -24183046, -10564943, 3299665, -12424953 },+    { -16777703, -15253301, -9642417, 4978983, 3308785, 8755439, 6943197, 6461331, -25583147, 8991218 },+    { -17226263, 1816362, -1673288, -6086439, 31783888, -8175991, -32948145, 7417950, -30242287, 1507265 }+  },+  {+    { 29692663, 6829891, -10498800, 4334896, 20945975, -11906496, -28887608, 8209391, 14606362, -10647073 },+    { -3481570, 8707081, 32188102, 5672294, 22096700, 1711240, -33020695, 9761487, 4170404, -2085325 },+    { -11587470, 14855945, -4127778, -1531857, -26649089, 15084046, 22186522, 16002000, -14276837, -8400798 }+  },+  {+    { -4811456, 13761029, -31703877, -2483919, -3312471, 7869047, -7113572, -9620092, 13240845, 10965870 },+    { -7742563, -8256762, -14768334, -13656260, -23232383, 12387166, 4498947, 14147411, 29514390, 4302863 },+    { -13413405, -12407859, 20757302, -13801832, 14785143, 8976368, -5061276, -2144373, 17846988, -13971927 }+  }+},+{ /* 14/31 */+  {+    { -2244452, -754728, -4597030, -1066309, -6247172, 1455299, -21647728, -9214789, -5222701, 12650267 },+    { -9906797, -16070310, 21134160, 12198166, -27064575, 708126, 387813, 13770293, -19134326, 10958663 },+    { 22470984, 12369526, 23446014, -5441109, -21520802, -9698723, -11772496, -11574455, -25083830, 4271862 }+  },+  {+    { -25169565, -10053642, -19909332, 15361595, -5984358, 2159192, 75375, -4278529, -32526221, 8469673 },+    { 15854970, 4148314, -8893890, 7259002, 11666551, 13824734, -30531198, 2697372, 24154791, -9460943 },+    { 15446137, -15806644, 29759747, 14019369, 30811221, -9610191, -31582008, 12840104, 24913809, 9815020 }+  },+  {+    { -4709286, -5614269, -31841498, -12288893, -14443537, 10799414, -9103676, 13438769, 18735128, 9466238 },+    { 11933045, 9281483, 5081055, -5183824, -2628162, -4905629, -7727821, -10896103, -22728655, 16199064 },+    { 14576810, 379472, -26786533, -8317236, -29426508, -10812974, -102766, 1876699, 30801119, 2164795 }+  },+  {+    { 15995086, 3199873, 13672555, 13712240, -19378835, -4647646, -13081610, -15496269, -13492807, 1268052 },+    { -10290614, -3659039, -3286592, 10948818, 23037027, 3794475, -3470338, -12600221, -17055369, 3565904 },+    { 29210088, -9419337, -5919792, -4952785, 10834811, -13327726, -16512102, -10820713, -27162222, -14030531 }+  },+  {+    { -13161890, 15508588, 16663704, -8156150, -28349942, 9019123, -29183421, -3769423, 2244111, -14001979 },+    { -5152875, -3800936, -9306475, -6071583, 16243069, 14684434, -25673088, -16180800, 13491506, 4641841 },+    { 10813417, 643330, -19188515, -728916, 30292062, -16600078, 27548447, -7721242, 14476989, -12767431 }+  },+  {+    { 10292079, 9984945, 6481436, 8279905, -7251514, 7032743, 27282937, -1644259, -27912810, 12651324 },+    { -31185513, -813383, 22271204, 11835308, 10201545, 15351028, 17099662, 3988035, 21721536, -3148940 },+    { 10202177, -6545839, -31373232, -9574638, -32150642, -8119683, -12906320, 3852694, 13216206, 14842320 }+  },+  {+    { -15815640, -10601066, -6538952, -7258995, -6984659, -6581778, -31500847, 13765824, -27434397, 9900184 },+    { 14465505, -13833331, -32133984, -14738873, -27443187, 12990492, 33046193, 15796406, -7051866, -8040114 },+    { 30924417, -8279620, 6359016, -12816335, 16508377, 9071735, -25488601, 15413635, 9524356, -7018878 }+  },+  {+    { 12274201, -13175547, 32627641, -1785326, 6736625, 13267305, 5237659, -5109483, 15663516, 4035784 },+    { -2951309, 8903985, 17349946, 601635, -16432815, -4612556, -13732739, -15889334, -22258478, 4659091 },+    { -16916263, -4952973, -30393711, -15158821, 20774812, 15897498, 5736189, 15026997, -2178256, -13455585 }+  }+},+{ /* 15/31 */+  {+    { -8858980, -2219056, 28571666, -10155518, -474467, -10105698, -3801496, 278095, 23440562, -290208 },+    { 10226241, -5928702, 15139956, 120818, -14867693, 5218603, 32937275, 11551483, -16571960, -7442864 },+    { 17932739, -12437276, -24039557, 10749060, 11316803, 7535897, 22503767, 5561594, -3646624, 3898661 }+  },+  {+    { 7749907, -969567, -16339731, -16464, -25018111, 15122143, -1573531, 7152530, 21831162, 1245233 },+    { 26958459, -14658026, 4314586, 8346991, -5677764, 11960072, -32589295, -620035, -30402091, -16716212 },+    { -12165896, 9166947, 33491384, 13673479, 29787085, 13096535, 6280834, 14587357, -22338025, 13987525 }+  },+  {+    { -24349909, 7778775, 21116000, 15572597, -4833266, -5357778, -4300898, -5124639, -7469781, -2858068 },+    { 9681908, -6737123, -31951644, 13591838, -6883821, 386950, 31622781, 6439245, -14581012, 4091397 },+    { -8426427, 1470727, -28109679, -1596990, 3978627, -5123623, -19622683, 12092163, 29077877, -14741988 }+  },+  {+    { 5269168, -6859726, -13230211, -8020715, 25932563, 1763552, -5606110, -5505881, -20017847, 2357889 },+    { 32264008, -15407652, -5387735, -1160093, -2091322, -3946900, 23104804, -12869908, 5727338, 189038 },+    { 14609123, -8954470, -6000566, -16622781, -14577387, -7743898, -26745169, 10942115, -25888931, -14884697 }+  },+  {+    { 20513500, 5557931, -15604613, 7829531, 26413943, -2019404, -21378968, 7471781, 13913677, -5137875 },+    { -25574376, 11967826, 29233242, 12948236, -6754465, 4713227, -8940970, 14059180, 12878652, 8511905 },+    { -25656801, 3393631, -2955415, -7075526, -2250709, 9366908, -30223418, 6812974, 5568676, -3127656 }+  },+  {+    { 11630004, 12144454, 2116339, 13606037, 27378885, 15676917, -17408753, -13504373, -14395196, 8070818 },+    { 27117696, -10007378, -31282771, -5570088, 1127282, 12772488, -29845906, 10483306, -11552749, -1028714 },+    { 10637467, -5688064, 5674781, 1072708, -26343588, -6982302, -1683975, 9177853, -27493162, 15431203 }+  },+  {+    { 20525145, 10892566, -12742472, 12779443, -29493034, 16150075, -28240519, 14943142, -15056790, -7935931 },+    { -30024462, 5626926, -551567, -9981087, 753598, 11981191, 25244767, -3239766, -3356550, 9594024 },+    { -23752644, 2636870, -5163910, -10103818, 585134, 7877383, 11345683, -6492290, 13352335, -10977084 }+  },+  {+    { -1931799, -5407458, 3304649, -12884869, 17015806, -4877091, -29783850, -7752482, -13215537, -319204 },+    { 20239939, 6607058, 6203985, 3483793, -18386976, -779229, -20723742, 15077870, -22750759, 14523817 },+    { 27406042, -6041657, 27423596, -4497394, 4996214, 10002360, -28842031, -4545494, -30172742, -4805667 }+  }+},+{ /* 16/31 */+  {+    { 11374242, 12660715, 17861383, -12540833, 10935568, 1099227, -13886076, -9091740, -27727044, 11358504 },+    { -12730809, 10311867, 1510375, 10778093, -2119455, -9145702, 32676003, 11149336, -26123651, 4985768 },+    { -19096303, 341147, -6197485, -239033, 15756973, -8796662, -983043, 13794114, -19414307, -15621255 }+  },+  {+    { 6490081, 11940286, 25495923, -7726360, 8668373, -8751316, 3367603, 6970005, -1691065, -9004790 },+    { 1656497, 13457317, 15370807, 6364910, 13605745, 8362338, -19174622, -5475723, -16796596, -5031438 },+    { -22273315, -13524424, -64685, -4334223, -18605636, -10921968, -20571065, -7007978, -99853, -10237333 }+  },+  {+    { 17747465, 10039260, 19368299, -4050591, -20630635, -16041286, 31992683, -15857976, -29260363, -5511971 },+    { 31932027, -4986141, -19612382, 16366580, 22023614, 88450, 11371999, -3744247, 4882242, -10626905 },+    { 29796507, 37186, 19818052, 10115756, -11829032, 3352736, 18551198, 3272828, -5190932, -4162409 }+  },+  {+    { 12501286, 4044383, -8612957, -13392385, -32430052, 5136599, -19230378, -3529697, 330070, -3659409 },+    { 6384877, 2899513, 17807477, 7663917, -2358888, 12363165, 25366522, -8573892, -271295, 12071499 },+    { -8365515, -4042521, 25133448, -4517355, -6211027, 2265927, -32769618, 1936675, -5159697, 3829363 }+  },+  {+    { 28425966, -5835433, -577090, -4697198, -14217555, 6870930, 7921550, -6567787, 26333140, 14267664 },+    { -11067219, 11871231, 27385719, -10559544, -4585914, -11189312, 10004786, -8709488, -21761224, 8930324 },+    { -21197785, -16396035, 25654216, -1725397, 12282012, 11008919, 1541940, 4757911, -26491501, -16408940 }+  },+  {+    { 13537262, -7759490, -20604840, 10961927, -5922820, -13218065, -13156584, 6217254, -15943699, 13814990 },+    { -17422573, 15157790, 18705543, 29619, 24409717, -260476, 27361681, 9257833, -1956526, -1776914 },+    { -25045300, -10191966, 15366585, 15166509, -13105086, 8423556, -29171540, 12361135, -18685978, 4578290 }+  },+  {+    { 24579768, 3711570, 1342322, -11180126, -27005135, 14124956, -22544529, 14074919, 21964432, 8235257 },+    { -6528613, -2411497, 9442966, -5925588, 12025640, -1487420, -2981514, -1669206, 13006806, 2355433 },+    { -16304899, -13605259, -6632427, -5142349, 16974359, -10911083, 27202044, 1719366, 1141648, -12796236 }+  },+  {+    { -12863944, -13219986, -8318266, -11018091, -6810145, -4843894, 13475066, -3133972, 32674895, 13715045 },+    { 11423335, -5468059, 32344216, 8962751, 24989809, 9241752, -13265253, 16086212, -28740881, -15642093 },+    { -1409668, 12530728, -6368726, 10847387, 19531186, -14132160, -11709148, 7791794, -27245943, 4383347 }+  }+},+{ /* 17/31 */+  {+    { -28970898, 5271447, -1266009, -9736989, -12455236, 16732599, -4862407, -4906449, 27193557, 6245191 },+    { -15193956, 5362278, -1783893, 2695834, 4960227, 12840725, 23061898, 3260492, 22510453, 8577507 },+    { -12632451, 11257346, -32692994, 13548177, -721004, 10879011, 31168030, 13952092, -29571492, -3635906 }+  },+  {+    { 3877321, -9572739, 32416692, 5405324, -11004407, -13656635, 3759769, 11935320, 5611860, 8164018 },+    { -16275802, 14667797, 15906460, 12155291, -22111149, -9039718, 32003002, -8832289, 5773085, -8422109 },+    { -23788118, -8254300, 1950875, 8937633, 18686727, 16459170, -905725, 12376320, 31632953, 190926 }+  },+  {+    { -24593607, -16138885, -8423991, 13378746, 14162407, 6901328, -8288749, 4508564, -25341555, -3627528 },+    { 8884438, -5884009, 6023974, 10104341, -6881569, -4941533, 18722941, -14786005, -1672488, 827625 },+    { -32720583, -16289296, -32503547, 7101210, 13354605, 2659080, -1800575, -14108036, -24878478, 1541286 }+  },+  {+    { 2901347, -1117687, 3880376, -10059388, -17620940, -3612781, -21802117, -3567481, 20456845, -1885033 },+    { 27019610, 12299467, -13658288, -1603234, -12861660, -4861471, -19540150, -5016058, 29439641, 15138866 },+    { 21536104, -6626420, -32447818, -10690208, -22408077, 5175814, -5420040, -16361163, 7779328, 109896 }+  },+  {+    { 30279744, 14648750, -8044871, 6425558, 13639621, -743509, 28698390, 12180118, 23177719, -554075 },+    { 26572847, 3405927, -31701700, 12890905, -19265668, 5335866, -6493768, 2378492, 4439158, -13279347 },+    { -22716706, 3489070, -9225266, -332753, 18875722, -1140095, 14819434, -12731527, -17717757, -5461437 }+  },+  {+    { -5056483, 16566551, 15953661, 3767752, -10436499, 15627060, -820954, 2177225, 8550082, -15114165 },+    { -18473302, 16596775, -381660, 15663611, 22860960, 15585581, -27844109, -3582739, -23260460, -8428588 },+    { -32480551, 15707275, -8205912, -5652081, 29464558, 2713815, -22725137, 15860482, -21902570, 1494193 }+  },+  {+    { -19562091, -14087393, -25583872, -9299552, 13127842, 759709, 21923482, 16529112, 8742704, 12967017 },+    { -28464899, 1553205, 32536856, -10473729, -24691605, -406174, -8914625, -2933896, -29903758, 15553883 },+    { 21877909, 3230008, 9881174, 10539357, -4797115, 2841332, 11543572, 14513274, 19375923, -12647961 }+  },+  {+    { 8832269, -14495485, 13253511, 5137575, 5037871, 4078777, 24880818, -6222716, 2862653, 9455043 },+    { 29306751, 5123106, 20245049, -14149889, 9592566, 8447059, -2077124, -2990080, 15511449, 4789663 },+    { -20679756, 7004547, 8824831, -9434977, -4045704, -3750736, -5754762, 108893, 23513200, 16652362 }+  }+},+{ /* 18/31 */+  {+    { -33256173, 4144782, -4476029, -6579123, 10770039, -7155542, -6650416, -12936300, -18319198, 10212860 },+    { 2756081, 8598110, 7383731, -6859892, 22312759, -1105012, 21179801, 2600940, -9988298, -12506466 },+    { -24645692, 13317462, -30449259, -15653928, 21365574, -10869657, 11344424, 864440, -2499677, -16710063 }+  },+  {+    { -26432803, 6148329, -17184412, -14474154, 18782929, -275997, -22561534, 211300, 2719757, 4940997 },+    { -1323882, 3911313, -6948744, 14759765, -30027150, 7851207, 21690126, 8518463, 26699843, 5276295 },+    { -13149873, -6429067, 9396249, 365013, 24703301, -10488939, 1321586, 149635, -15452774, 7159369 }+  },+  {+    { 9987780, -3404759, 17507962, 9505530, 9731535, -2165514, 22356009, 8312176, 22477218, -8403385 },+    { 18155857, -16504990, 19744716, 9006923, 15154154, -10538976, 24256460, -4864995, -22548173, 9334109 },+    { 2986088, -4911893, 10776628, -3473844, 10620590, -7083203, -21413845, 14253545, -22587149, 536906 }+  },+  {+    { 4377756, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551, 10589625, 10838060, -15420424 },+    { -19342404, 867880, 9277171, -3218459, -14431572, -1986443, 19295826, -15796950, 6378260, 699185 },+    { 7895026, 4057113, -7081772, -13077756, -17886831, -323126, -716039, 15693155, -5045064, -13373962 }+  },+  {+    { -7737563, -5869402, -14566319, -7406919, 11385654, 13201616, 31730678, -10962840, -3918636, -9669325 },+    { 10188286, -15770834, -7336361, 13427543, 22223443, 14896287, 30743455, 7116568, -21786507, 5427593 },+    { 696102, 13206899, 27047647, -10632082, 15285305, -9853179, 10798490, -4578720, 19236243, 12477404 }+  },+  {+    { -11229439, 11243796, -17054270, -8040865, -788228, -8167967, -3897669, 11180504, -23169516, 7733644 },+    { 17800790, -14036179, -27000429, -11766671, 23887827, 3149671, 23466177, -10538171, 10322027, 15313801 },+    { 26246234, 11968874, 32263343, -5468728, 6830755, -13323031, -15794704, -101982, -24449242, 10890804 }+  },+  {+    { -31365647, 10271363, -12660625, -6267268, 16690207, -13062544, -14982212, 16484931, 25180797, -5334884 },+    { -586574, 10376444, -32586414, -11286356, 19801893, 10997610, 2276632, 9482883, 316878, 13820577 },+    { -9882808, -4510367, -2115506, 16457136, -11100081, 11674996, 30756178, -7515054, 30696930, -3712849 }+  },+  {+    { 32988917, -9603412, 12499366, 7910787, -10617257, -11931514, -7342816, -9985397, -32349517, 7392473 },+    { -8855661, 15927861, 9866406, -3649411, -2396914, -16655781, -30409476, -9134995, 25112947, -2926644 },+    { -2504044, -436966, 25621774, -5678772, 15085042, -5479877, -24884878, -13526194, 5537438, -13914319 }+  }+},+{ /* 19/31 */+  {+    { -11225584, 2320285, -9584280, 10149187, -33444663, 5808648, -14876251, -1729667, 31234590, 6090599 },+    { -9633316, 116426, 26083934, 2897444, -6364437, -2688086, 609721, 15878753, -6970405, -9034768 },+    { -27757857, 247744, -15194774, -9002551, 23288161, -10011936, -23869595, 6503646, 20650474, 1804084 }+  },+  {+    { -27589786, 15456424, 8972517, 8469608, 15640622, 4439847, 3121995, -10329713, 27842616, -202328 },+    { -15306973, 2839644, 22530074, 10026331, 4602058, 5048462, 28248656, 5031932, -11375082, 12714369 },+    { 20807691, -7270825, 29286141, 11421711, -27876523, -13868230, -21227475, 1035546, -19733229, 12796920 }+  },+  {+    { 12076899, -14301286, -8785001, -11848922, -25012791, 16400684, -17591495, -12899438, 3480665, -15182815 },+    { -32361549, 5457597, 28548107, 7833186, 7303070, -11953545, -24363064, -15921875, -33374054, 2771025 },+    { -21389266, 421932, 26597266, 6860826, 22486084, -6737172, -17137485, -4210226, -24552282, 15673397 }+  },+  {+    { -20184622, 2338216, 19788685, -9620956, -4001265, -8740893, -20271184, 4733254, 3727144, -12934448 },+    { 6120119, 814863, -11794402, -622716, 6812205, -15747771, 2019594, 7975683, 31123697, -10958981 },+    { 30069250, -11435332, 30434654, 2958439, 18399564, -976289, 12296869, 9204260, -16432438, 9648165 }+  },+  {+    { 32705432, -1550977, 30705658, 7451065, -11805606, 9631813, 3305266, 5248604, -26008332, -11377501 },+    { 17219865, 2375039, -31570947, -5575615, -19459679, 9219903, 294711, 15298639, 2662509, -16297073 },+    { -1172927, -7558695, -4366770, -4287744, -21346413, -8434326, 32087529, -1222777, 32247248, -14389861 }+  },+  {+    { 14312628, 1221556, 17395390, -8700143, -4945741, -8684635, -28197744, -9637817, -16027623, -13378845 },+    { -1428825, -9678990, -9235681, 6549687, -7383069, -468664, 23046502, 9803137, 17597934, 2346211 },+    { 18510800, 15337574, 26171504, 981392, -22241552, 7827556, -23491134, -11323352, 3059833, -11782870 }+  },+  {+    { 10141598, 6082907, 17829293, -1947643, 9830092, 13613136, -25556636, -5544586, -33502212, 3592096 },+    { 33114168, -15889352, -26525686, -13343397, 33076705, 8716171, 1151462, 1521897, -982665, -6837803 },+    { -32939165, -4255815, 23947181, -324178, -33072974, -12305637, -16637686, 3891704, 26353178, 693168 }+  },+  {+    { 30374239, 1595580, -16884039, 13186931, 4600344, 406904, 9585294, -400668, 31375464, 14369965 },+    { -14370654, -7772529, 1510301, 6434173, -18784789, -6262728, 32732230, -13108839, 17901441, 16011505 },+    { 18171223, -11934626, -12500402, 15197122, -11038147, -15230035, -19172240, -16046376, 8764035, 12309598 }+  }+},+{ /* 20/31 */+  {+    { 5975908, -5243188, -19459362, -9681747, -11541277, 14015782, -23665757, 1228319, 17544096, -10593782 },+    { 5811932, -1715293, 3442887, -2269310, -18367348, -8359541, -18044043, -15410127, -5565381, 12348900 },+    { -31399660, 11407555, 25755363, 6891399, -3256938, 14872274, -24849353, 8141295, -10632534, -585479 }+  },+  {+    { -12675304, 694026, -5076145, 13300344, 14015258, -14451394, -9698672, -11329050, 30944593, 1130208 },+    { 8247766, -6710942, -26562381, -7709309, -14401939, -14648910, 4652152, 2488540, 23550156, -271232 },+    { 17294316, -3788438, 7026748, 15626851, 22990044, 113481, 2267737, -5908146, -408818, -137719 }+  },+  {+    { 16091085, -16253926, 18599252, 7340678, 2137637, -1221657, -3364161, 14550936, 3260525, -7166271 },+    { -4910104, -13332887, 18550887, 10864893, -16459325, -7291596, -23028869, -13204905, -12748722, 2701326 },+    { -8574695, 16099415, 4629974, -16340524, -20786213, -6005432, -10018363, 9276971, 11329923, 1862132 }+  },+  {+    { 14763076, -15903608, -30918270, 3689867, 3511892, 10313526, -21951088, 12219231, -9037963, -940300 },+    { 8894987, -3446094, 6150753, 3013931, 301220, 15693451, -31981216, -2909717, -15438168, 11595570 },+    { 15214962, 3537601, -26238722, -14058872, 4418657, -15230761, 13947276, 10730794, -13489462, -4363670 }+  },+  {+    { -2538306, 7682793, 32759013, 263109, -29984731, -7955452, -22332124, -10188635, 977108, 699994 },+    { -12466472, 4195084, -9211532, 550904, -15565337, 12917920, 19118110, -439841, -30534533, -14337913 },+    { 31788461, -14507657, 4799989, 7372237, 8808585, -14747943, 9408237, -10051775, 12493932, -5409317 }+  },+  {+    { -25680606, 5260744, -19235809, -6284470, -3695942, 16566087, 27218280, 2607121, 29375955, 6024730 },+    { 842132, -2794693, -4763381, -8722815, 26332018, -12405641, 11831880, 6985184, -9940361, 2854096 },+    { -4847262, -7969331, 2516242, -5847713, 9695691, -7221186, 16512645, 960770, 12121869, 16648078 }+  },+  {+    { -15218652, 14667096, -13336229, 2013717, 30598287, -464137, -31504922, -7882064, 20237806, 2838411 },+    { -19288047, 4453152, 15298546, -16178388, 22115043, -15972604, 12544294, -13470457, 1068881, -12499905 },+    { -9558883, -16518835, 33238498, 13506958, 30505848, -1114596, -8486907, -2630053, 12521378, 4845654 }+  },+  {+    { -28198521, 10744108, -2958380, 10199664, 7759311, -13088600, 3409348, -873400, -6482306, -12885870 },+    { -23561822, 6230156, -20382013, 10655314, -24040585, -11621172, 10477734, -1240216, -3113227, 13974498 },+    { 12966261, 15550616, -32038948, -1615346, 21025980, -629444, 5642325, 7188737, 18895762, 12629579 }+  }+},+{ /* 21/31 */+  {+    { 14741879, -14946887, 22177208, -11721237, 1279741, 8058600, 11758140, 789443, 32195181, 3895677 },+    { 10758205, 15755439, -4509950, 9243698, -4879422, 6879879, -2204575, -3566119, -8982069, 4429647 },+    { -2453894, 15725973, -20436342, -10410672, -5803908, -11040220, -7135870, -11642895, 18047436, -15281743 }+  },+  {+    { -25173001, -11307165, 29759956, 11776784, -22262383, -15820455, 10993114, -12850837, -17620701, -9408468 },+    { 21987233, 700364, -24505048, 14972008, -7774265, -5718395, 32155026, 2581431, -29958985, 8773375 },+    { -25568350, 454463, -13211935, 16126715, 25240068, 8594567, 20656846, 12017935, -7874389, -13920155 }+  },+  {+    { 6028182, 6263078, -31011806, -11301710, -818919, 2461772, -31841174, -5468042, -1721788, -2776725 },+    { -12278994, 16624277, 987579, -5922598, 32908203, 1248608, 7719845, -4166698, 28408820, 6816612 },+    { -10358094, -8237829, 19549651, -12169222, 22082623, 16147817, 20613181, 13982702, -10339570, 5067943 }+  },+  {+    { -30505967, -3821767, 12074681, 13582412, -19877972, 2443951, -19719286, 12746132, 5331210, -10105944 },+    { 30528811, 3601899, -1957090, 4619785, -27361822, -15436388, 24180793, -12570394, 27679908, -1648928 },+    { 9402404, -13957065, 32834043, 10838634, -26580150, -13237195, 26653274, -8685565, 22611444, -12715406 }+  },+  {+    { 22190590, 1118029, 22736441, 15130463, -30460692, -5991321, 19189625, -4648942, 4854859, 6622139 },+    { -8310738, -2953450, -8262579, -3388049, -10401731, -271929, 13424426, -3567227, 26404409, 13001963 },+    { -31241838, -15415700, -2994250, 8939346, 11562230, -12840670, -26064365, -11621720, -15405155, 11020693 }+  },+  {+    { 1866042, -7949489, -7898649, -10301010, 12483315, 13477547, 3175636, -12424163, 28761762, 1406734 },+    { -448555, -1777666, 13018551, 3194501, -9580420, -11161737, 24760585, -4347088, 25577411, -13378680 },+    { -24290378, 4759345, -690653, -1852816, 2066747, 10693769, -29595790, 9884936, -9368926, 4745410 }+  },+  {+    { -9141284, 6049714, -19531061, -4341411, -31260798, 9944276, -15462008, -11311852, 10931924, -11931931 },+    { -16561513, 14112680, -8012645, 4817318, -8040464, -11414606, -22853429, 10856641, -20470770, 13434654 },+    { 22759489, -10073434, -16766264, -1871422, 13637442, -10168091, 1765144, -12654326, 28445307, -5364710 }+  },+  {+    { 29875063, 12493613, 2795536, -3786330, 1710620, 15181182, -10195717, -8788675, 9074234, 1167180 },+    { -26205683, 11014233, -9842651, -2635485, -26908120, 7532294, -18716888, -9535498, 3843903, 9367684 },+    { -10969595, -6403711, 9591134, 9582310, 11349256, 108879, 16235123, 8601684, -139197, 4242895 }+  }+},+{ /* 22/31 */+  {+    { 22092954, -13191123, -2042793, -11968512, 32186753, -11517388, -6574341, 2470660, -27417366, 16625501 },+    { -11057722, 3042016, 13770083, -9257922, 584236, -544855, -7770857, 2602725, -27351616, 14247413 },+    { 6314175, -10264892, -32772502, 15957557, -10157730, 168750, -8618807, 14290061, 27108877, -1180880 }+  },+  {+    { -8586597, -7170966, 13241782, 10960156, -32991015, -13794596, 33547976, -11058889, -27148451, 981874 },+    { 22833440, 9293594, -32649448, -13618667, -9136966, 14756819, -22928859, -13970780, -10479804, -16197962 },+    { -7768587, 3326786, -28111797, 10783824, 19178761, 14905060, 22680049, 13906969, -15933690, 3797899 }+  },+  {+    { 21721356, -4212746, -12206123, 9310182, -3882239, -13653110, 23740224, -2709232, 20491983, -8042152 },+    { 9209270, -15135055, -13256557, -6167798, -731016, 15289673, 25947805, 15286587, 30997318, -6703063 },+    { 7392032, 16618386, 23946583, -8039892, -13265164, -1533858, -14197445, -2321576, 17649998, -250080 }+  },+  {+    { -9301088, -14193827, 30609526, -3049543, -25175069, -1283752, -15241566, -9525724, -2233253, 7662146 },+    { -17558673, 1763594, -33114336, 15908610, -30040870, -12174295, 7335080, -8472199, -3174674, 3440183 },+    { -19889700, -5977008, -24111293, -9688870, 10799743, -16571957, 40450, -4431835, 4862400, 1133 }+  },+  {+    { -32856209, -7873957, -5422389, 14860950, -16319031, 7956142, 7258061, 311861, -30594991, -7379421 },+    { -3773428, -1565936, 28985340, 7499440, 24445838, 9325937, 29727763, 16527196, 18278453, 15405622 },+    { -4381906, 8508652, -19898366, -3674424, -5984453, 15149970, -13313598, 843523, -21875062, 13626197 }+  },+  {+    { 2281448, -13487055, -10915418, -2609910, 1879358, 16164207, -10783882, 3953792, 13340839, 15928663 },+    { 31727126, -7179855, -18437503, -8283652, 2875793, -16390330, -25269894, -7014826, -23452306, 5964753 },+    { 4100420, -5959452, -17179337, 6017714, -18705837, 12227141, -26684835, 11344144, 2538215, -7570755 }+  },+  {+    { -9433605, 6123113, 11159803, -2156608, 30016280, 14966241, -20474983, 1485421, -629256, -15958862 },+    { -26804558, 4260919, 11851389, 9658551, -32017107, 16367492, -20205425, -13191288, 11659922, -11115118 },+    { 26180396, 10015009, -30844224, -8581293, 5418197, 9480663, 2231568, -10170080, 33100372, -1306171 }+  },+  {+    { 15121113, -5201871, -10389905, 15427821, -27509937, -15992507, 21670947, 4486675, -5931810, -14466380 },+    { 16166486, -9483733, -11104130, 6023908, -31926798, -1364923, 2340060, -16254968, -10735770, -10039824 },+    { 28042865, -3557089, -12126526, 12259706, -3717498, -6945899, 6766453, -8689599, 18036436, 5803270 }+  }+},+{ /* 23/31 */+  {+    { -817581, 6763912, 11803561, 1585585, 10958447, -2671165, 23855391, 4598332, -6159431, -14117438 },+    { -31031306, -14256194, 17332029, -2383520, 31312682, -5967183, 696309, 50292, -20095739, 11763584 },+    { -594563, -2514283, -32234153, 12643980, 12650761, 14811489, 665117, -12613632, -19773211, -10713562 }+  },+  {+    { 30464590, -11262872, -4127476, -12734478, 19835327, -7105613, -24396175, 2075773, -17020157, 992471 },+    { 18357185, -6994433, 7766382, 16342475, -29324918, 411174, 14578841, 8080033, -11574335, -10601610 },+    { 19598397, 10334610, 12555054, 2555664, 18821899, -10339780, 21873263, 16014234, 26224780, 16452269 }+  },+  {+    { -30223925, 5145196, 5944548, 16385966, 3976735, 2009897, -11377804, -7618186, -20533829, 3698650 },+    { 14187449, 3448569, -10636236, -10810935, -22663880, -3433596, 7268410, -10890444, 27394301, 12015369 },+    { 19695761, 16087646, 28032085, 12999827, 6817792, 11427614, 20244189, -1312777, -13259127, -3402461 }+  },+  {+    { 30860103, 12735208, -1888245, -4699734, -16974906, 2256940, -8166013, 12298312, -8550524, -10393462 },+    { -5719826, -11245325, -1910649, 15569035, 26642876, -7587760, -5789354, -15118654, -4976164, 12651793 },+    { -2848395, 9953421, 11531313, -5282879, 26895123, -12697089, -13118820, -16517902, 9768698, -2533218 }+  },+  {+    { -24719459, 1894651, -287698, -4704085, 15348719, -8156530, 32767513, 12765450, 4940095, 10678226 },+    { 18860224, 15980149, -18987240, -1562570, -26233012, -11071856, -7843882, 13944024, -24372348, 16582019 },+    { -15504260, 4970268, -29893044, 4175593, -20993212, -2199756, -11704054, 15444560, -11003761, 7989037 }+  },+  {+    { 31490452, 5568061, -2412803, 2182383, -32336847, 4531686, -32078269, 6200206, -19686113, -14800171 },+    { -17308668, -15879940, -31522777, -2831, -32887382, 16375549, 8680158, -16371713, 28550068, -6857132 },+    { -28126887, -5688091, 16837845, -1820458, -6850681, 12700016, -30039981, 4364038, 1155602, 5988841 }+  },+  {+    { 21890435, -13272907, -12624011, 12154349, -7831873, 15300496, 23148983, -4470481, 24618407, 8283181 },+    { -33136107, -10512751, 9975416, 6841041, -31559793, 16356536, 3070187, -7025928, 1466169, 10740210 },+    { -1509399, -15488185, -13503385, -10655916, 32799044, 909394, -13938903, -5779719, -32164649, -15327040 }+  },+  {+    { 3960823, -14267803, -28026090, -15918051, -19404858, 13146868, 15567327, 951507, -3260321, -573935 },+    { 24740841, 5052253, -30094131, 8961361, 25877428, 6165135, -24368180, 14397372, -7380369, -6144105 },+    { -28888365, 3510803, -28103278, -1158478, -11238128, -10631454, -15441463, -14453128, -1625486, -6494814 }+  }+},+{ /* 24/31 */+  {+    { 793299, -9230478, 8836302, -6235707, -27360908, -2369593, 33152843, -4885251, -9906200, -621852 },+    { 5666233, 525582, 20782575, -8038419, -24538499, 14657740, 16099374, 1468826, -6171428, -15186581 },+    { -4859255, -3779343, -2917758, -6748019, 7778750, 11688288, -30404353, -9871238, -1558923, -9863646 }+  },+  {+    { 10896332, -7719704, 824275, 472601, -19460308, 3009587, 25248958, 14783338, -30581476, -15757844 },+    { 10566929, 12612572, -31944212, 11118703, -12633376, 12362879, 21752402, 8822496, 24003793, 14264025 },+    { 27713862, -7355973, -11008240, 9227530, 27050101, 2504721, 23886875, -13117525, 13958495, -5732453 }+  },+  {+    { -23481610, 4867226, -27247128, 3900521, 29838369, -8212291, -31889399, -10041781, 7340521, -15410068 },+    { 4646514, -8011124, -22766023, -11532654, 23184553, 8566613, 31366726, -1381061, -15066784, -10375192 },+    { -17270517, 12723032, -16993061, 14878794, 21619651, -6197576, 27584817, 3093888, -8843694, 3849921 }+  },+  {+    { -9064912, 2103172, 25561640, -15125738, -5239824, 9582958, 32477045, -9017955, 5002294, -15550259 },+    { -12057553, -11177906, 21115585, -13365155, 8808712, -12030708, 16489530, 13378448, -25845716, 12741426 },+    { -5946367, 10645103, -30911586, 15390284, -3286982, -7118677, 24306472, 15852464, 28834118, -7646072 }+  },+  {+    { -17335748, -9107057, -24531279, 9434953, -8472084, -583362, -13090771, 455841, 20461858, 5491305 },+    { 13669248, -16095482, -12481974, -10203039, -14569770, -11893198, -24995986, 11293807, -28588204, -9421832 },+    { 28497928, 6272777, -33022994, 14470570, 8906179, -1225630, 18504674, -14165166, 29867745, -8795943 }+  },+  {+    { -16207023, 13517196, -27799630, -13697798, 24009064, -6373891, -6367600, -13175392, 22853429, -4012011 },+    { 24191378, 16712145, -13931797, 15217831, 14542237, 1646131, 18603514, -11037887, 12876623, -2112447 },+    { 17902668, 4518229, -411702, -2829247, 26878217, 5258055, -12860753, 608397, 16031844, 3723494 }+  },+  {+    { -28632773, 12763728, -20446446, 7577504, 33001348, -13017745, 17558842, -7872890, 23896954, -4314245 },+    { -20005381, -12011952, 31520464, 605201, 2543521, 5991821, -2945064, 7229064, -9919646, -8826859 },+    { 28816045, 298879, -28165016, -15920938, 19000928, -1665890, -12680833, -2949325, -18051778, -2082915 }+  },+  {+    { 16000882, -344896, 3493092, -11447198, -29504595, -13159789, 12577740, 16041268, -19715240, 7847707 },+    { 10151868, 10572098, 27312476, 7922682, 14825339, 4723128, -32855931, -6519018, -10020567, 3852848 },+    { -11430470, 15697596, -21121557, -4420647, 5386314, 15063598, 16514493, -15932110, 29330899, -15076224 }+  }+},+{ /* 25/31 */+  {+    { -25499735, -4378794, -15222908, -6901211, 16615731, 2051784, 3303702, 15490, -27548796, 12314391 },+    { 15683520, -6003043, 18109120, -9980648, 15337968, -5997823, -16717435, 15921866, 16103996, -3731215 },+    { -23169824, -10781249, 13588192, -1628807, -3798557, -1074929, -19273607, 5402699, -29815713, -9841101 }+  },+  {+    { 23190676, 2384583, -32714340, 3462154, -29903655, -1529132, -11266856, 8911517, -25205859, 2739713 },+    { 21374101, -3554250, -33524649, 9874411, 15377179, 11831242, -33529904, 6134907, 4931255, 11987849 },+    { -7732, -2978858, -16223486, 7277597, 105524, -322051, -31480539, 13861388, -30076310, 10117930 }+  },+  {+    { -29501170, -10744872, -26163768, 13051539, -25625564, 5089643, -6325503, 6704079, 12890019, 15728940 },+    { -21972360, -11771379, -951059, -4418840, 14704840, 2695116, 903376, -10428139, 12885167, 8311031 },+    { -17516482, 5352194, 10384213, -13811658, 7506451, 13453191, 26423267, 4384730, 1888765, -5435404 }+  },+  {+    { -25817338, -3107312, -13494599, -3182506, 30896459, -13921729, -32251644, -12707869, -19464434, -3340243 },+    { -23607977, -2665774, -526091, 4651136, 5765089, 4618330, 6092245, 14845197, 17151279, -9854116 },+    { -24830458, -12733720, -15165978, 10367250, -29530908, -265356, 22825805, -7087279, -16866484, 16176525 }+  },+  {+    { -23583256, 6564961, 20063689, 3798228, -4740178, 7359225, 2006182, -10363426, -28746253, -10197509 },+    { -10626600, -4486402, -13320562, -5125317, 3432136, -6393229, 23632037, -1940610, 32808310, 1099883 },+    { 15030977, 5768825, -27451236, -2887299, -6427378, -15361371, -15277896, -6809350, 2051441, -15225865 }+  },+  {+    { -3362323, -7239372, 7517890, 9824992, 23555850, 295369, 5148398, -14154188, -22686354, 16633660 },+    { 4577086, -16752288, 13249841, -15304328, 19958763, -14537274, 18559670, -10759549, 8402478, -9864273 },+    { -28406330, -1051581, -26790155, -907698, -17212414, -11030789, 9453451, -14980072, 17983010, 9967138 }+  },+  {+    { -25762494, 6524722, 26585488, 9969270, 24709298, 1220360, -1677990, 7806337, 17507396, 3651560 },+    { -10420457, -4118111, 14584639, 15971087, -15768321, 8861010, 26556809, -5574557, -18553322, -11357135 },+    { 2839101, 14284142, 4029895, 3472686, 14402957, 12689363, -26642121, 8459447, -5605463, -7621941 }+  },+  {+    { -4839289, -3535444, 9744961, 2871048, 25113978, 3187018, -25110813, -849066, 17258084, -7977739 },+    { 18164541, -10595176, -17154882, -1542417, 19237078, -9745295, 23357533, -15217008, 26908270, 12150756 },+    { -30264870, -7647865, 5112249, -7036672, -1499807, -6974257, 43168, -5537701, -32302074, 16215819 }+  }+},+{ /* 26/31 */+  {+    { -6898905, 9824394, -12304779, -4401089, -31397141, -6276835, 32574489, 12532905, -7503072, -8675347 },+    { -27343522, -16515468, -27151524, -10722951, 946346, 16291093, 254968, 7168080, 21676107, -1943028 },+    { 21260961, -8424752, -16831886, -11920822, -23677961, 3968121, -3651949, -6215466, -3556191, -7913075 }+  },+  {+    { 16544754, 13250366, -16804428, 15546242, -4583003, 12757258, -2462308, -8680336, -18907032, -9662799 },+    { -2415239, -15577728, 18312303, 4964443, -15272530, -12653564, 26820651, 16690659, 25459437, -4564609 },+    { -25144690, 11425020, 28423002, -11020557, -6144921, -15826224, 9142795, -2391602, -6432418, -1644817 }+  },+  {+    { -23104652, 6253476, 16964147, -3768872, -25113972, -12296437, -27457225, -16344658, 6335692, 7249989 },+    { -30333227, 13979675, 7503222, -12368314, -11956721, -4621693, -30272269, 2682242, 25993170, -12478523 },+    { 4364628, 5930691, 32304656, -10044554, -8054781, 15091131, 22857016, -10598955, 31820368, 15075278 }+  },+  {+    { 31879134, -8918693, 17258761, 90626, -8041836, -4917709, 24162788, -9650886, -17970238, 12833045 },+    { 19073683, 14851414, -24403169, -11860168, 7625278, 11091125, -19619190, 2074449, -9413939, 14905377 },+    { 24483667, -11935567, -2518866, -11547418, -1553130, 15355506, -25282080, 9253129, 27628530, -7555480 }+  },+  {+    { 17597607, 8340603, 19355617, 552187, 26198470, -3176583, 4593324, -9157582, -14110875, 15297016 },+    { 510886, 14337390, -31785257, 16638632, 6328095, 2713355, -20217417, -11864220, 8683221, 2921426 },+    { 18606791, 11874196, 27155355, -5281482, -24031742, 6265446, -25178240, -1278924, 4674690, 13890525 }+  },+  {+    { 13609624, 13069022, -27372361, -13055908, 24360586, 9592974, 14977157, 9835105, 4389687, 288396 },+    { 9922506, -519394, 13613107, 5883594, -18758345, -434263, -12304062, 8317628, 23388070, 16052080 },+    { 12720016, 11937594, -31970060, -5028689, 26900120, 8561328, -20155687, -11632979, -14754271, -10812892 }+  },+  {+    { 15961858, 14150409, 26716931, -665832, -22794328, 13603569, 11829573, 7467844, -28822128, 929275 },+    { 11038231, -11582396, -27310482, -7316562, -10498527, -16307831, -23479533, -9371869, -21393143, 2465074 },+    { 20017163, -4323226, 27915242, 1529148, 12396362, 15675764, 13817261, -9658066, 2463391, -4622140 }+  },+  {+    { -16358878, -12663911, -12065183, 4996454, -1256422, 1073572, 9583558, 12851107, 4003896, 12673717 },+    { -1731589, -15155870, -3262930, 16143082, 19294135, 13385325, 14741514, -9103726, 7903886, 2348101 },+    { 24536016, -16515207, 12715592, -3862155, 1511293, 10047386, -3842346, -7129159, -28377538, 10048127 }+  }+},+{ /* 27/31 */+  {+    { -12622226, -6204820, 30718825, 2591312, -10617028, 12192840, 18873298, -7297090, -32297756, 15221632 },+    { -26478122, -11103864, 11546244, -1852483, 9180880, 7656409, -21343950, 2095755, 29769758, 6593415 },+    { -31994208, -2907461, 4176912, 3264766, 12538965, -868111, 26312345, -6118678, 30958054, 8292160 }+  },+  {+    { 31429822, -13959116, 29173532, 15632448, 12174511, -2760094, 32808831, 3977186, 26143136, -3148876 },+    { 22648901, 1402143, -22799984, 13746059, 7936347, 365344, -8668633, -1674433, -3758243, -2304625 },+    { -15491917, 8012313, -2514730, -12702462, -23965846, -10254029, -1612713, -1535569, -16664475, 8194478 }+  },+  {+    { 27338066, -7507420, -7414224, 10140405, -19026427, -6589889, 27277191, 8855376, 28572286, 3005164 },+    { 26287124, 4821776, 25476601, -4145903, -3764513, -15788984, -18008582, 1182479, -26094821, -13079595 },+    { -7171154, 3178080, 23970071, 6201893, -17195577, -4489192, -21876275, -13982627, 32208683, -1198248 }+  },+  {+    { -16657702, 2817643, -10286362, 14811298, 6024667, 13349505, -27315504, -10497842, -27672585, -11539858 },+    { 15941029, -9405932, -21367050, 8062055, 31876073, -238629, -15278393, -1444429, 15397331, -4130193 },+    { 8934485, -13485467, -23286397, -13423241, -32446090, 14047986, 31170398, -1441021, -27505566, 15087184 }+  },+  {+    { -18357243, -2156491, 24524913, -16677868, 15520427, -6360776, -15502406, 11461896, 16788528, -5868942 },+    { -1947386, 16013773, 21750665, 3714552, -17401782, -16055433, -3770287, -10323320, 31322514, -11615635 },+    { 21426655, -5650218, -13648287, -5347537, -28812189, -4920970, -18275391, -14621414, 13040862, -12112948 }+  },+  {+    { 11293895, 12478086, -27136401, 15083750, -29307421, 14748872, 14555558, -13417103, 1613711, 4896935 },+    { -25894883, 15323294, -8489791, -8057900, 25967126, -13425460, 2825960, -4897045, -23971776, -11267415 },+    { -15924766, -5229880, -17443532, 6410664, 3622847, 10243618, 20615400, 12405433, -23753030, -8436416 }+  },+  {+    { -7091295, 12556208, -20191352, 9025187, -17072479, 4333801, 4378436, 2432030, 23097949, -566018 },+    { 4565804, -16025654, 20084412, -7842817, 1724999, 189254, 24767264, 10103221, -18512313, 2424778 },+    { 366633, -11976806, 8173090, -6890119, 30788634, 5745705, -7168678, 1344109, -3642553, 12412659 }+  },+  {+    { -24001791, 7690286, 14929416, -168257, -32210835, -13412986, 24162697, -15326504, -3141501, 11179385 },+    { 18289522, -14724954, 8056945, 16430056, -21729724, 7842514, -6001441, -1486897, -18684645, -11443503 },+    { 476239, 6601091, -6152790, -9723375, 17503545, -4863900, 27672959, 13403813, 11052904, 5219329 }+  }+},+{ /* 28/31 */+  {+    { 20678546, -8375738, -32671898, 8849123, -5009758, 14574752, 31186971, -3973730, 9014762, -8579056 },+    { -13644050, -10350239, -15962508, 5075808, -1514661, -11534600, -33102500, 9160280, 8473550, -3256838 },+    { 24900749, 14435722, 17209120, -15292541, -22592275, 9878983, -7689309, -16335821, -24568481, 11788948 }+  },+  {+    { -3118155, -11395194, -13802089, 14797441, 9652448, -6845904, -20037437, 10410733, -24568470, -1458691 },+    { -15659161, 16736706, -22467150, 10215878, -9097177, 7563911, 11871841, -12505194, -18513325, 8464118 },+    { -23400612, 8348507, -14585951, -861714, -3950205, -6373419, 14325289, 8628612, 33313881, -8370517 }+  },+  {+    { -20186973, -4967935, 22367356, 5271547, -1097117, -4788838, -24805667, -10236854, -8940735, -5818269 },+    { -6948785, -1795212, -32625683, -16021179, 32635414, -7374245, 15989197, -12838188, 28358192, -4253904 },+    { -23561781, -2799059, -32351682, -1661963, -9147719, 10429267, -16637684, 4072016, -5351664, 5596589 }+  },+  {+    { -28236598, -3390048, 12312896, 6213178, 3117142, 16078565, 29266239, 2557221, 1768301, 15373193 },+    { -7243358, -3246960, -4593467, -7553353, -127927, -912245, -1090902, -4504991, -24660491, 3442910 },+    { -30210571, 5124043, 14181784, 8197961, 18964734, -11939093, 22597931, 7176455, -18585478, 13365930 }+  },+  {+    { -7877390, -1499958, 8324673, 4690079, 6261860, 890446, 24538107, -8570186, -9689599, -3031667 },+    { 25008904, -10771599, -4305031, -9638010, 16265036, 15721635, 683793, -11823784, 15723479, -15163481 },+    { -9660625, 12374379, -27006999, -7026148, -7724114, -12314514, 11879682, 5400171, 519526, -1235876 }+  },+  {+    { 22258397, -16332233, -7869817, 14613016, -22520255, -2950923, -20353881, 7315967, 16648397, 7605640 },+    { -8081308, -8464597, -8223311, 9719710, 19259459, -15348212, 23994942, -5281555, -9468848, 4763278 },+    { -21699244, 9220969, -15730624, 1084137, -25476107, -2852390, 31088447, -7764523, -11356529, 728112 }+  },+  {+    { 26047220, -11751471, -6900323, -16521798, 24092068, 9158119, -4273545, -12555558, -29365436, -5498272 },+    { 17510331, -322857, 5854289, 8403524, 17133918, -3112612, -28111007, 12327945, 10750447, 10014012 },+    { -10312768, 3936952, 9156313, -8897683, 16498692, -994647, -27481051, -666732, 3424691, 7540221 }+  },+  {+    { 30322361, -6964110, 11361005, -4143317, 7433304, 4989748, -7071422, -16317219, -9244265, 15258046 },+    { 13054562, -2779497, 19155474, 469045, -12482797, 4566042, 5631406, 2711395, 1062915, -5136345 },+    { -19240248, -11254599, -29509029, -7499965, -5835763, 13005411, -6066489, 12194497, 32960380, 1459310 }+  }+},+{ /* 29/31 */+  {+    { 19852034, 7027924, 23669353, 10020366, 8586503, -6657907, 394197, -6101885, 18638003, -11174937 },+    { 31395534, 15098109, 26581030, 8030562, -16527914, -5007134, 9012486, -7584354, -6643087, -5442636 },+    { -9192165, -2347377, -1997099, 4529534, 25766844, 607986, -13222, 9677543, -32294889, -6456008 }+  },+  {+    { -2444496, -149937, 29348902, 8186665, 1873760, 12489863, -30934579, -7839692, -7852844, -8138429 },+    { -15236356, -15433509, 7766470, 746860, 26346930, -10221762, -27333451, 10754588, -9431476, 5203576 },+    { 31834314, 14135496, -770007, 5159118, 20917671, -16768096, -7467973, -7337524, 31809243, 7347066 }+  },+  {+    { -9606723, -11874240, 20414459, 13033986, 13716524, -11691881, 19797970, -12211255, 15192876, -2087490 },+    { -12663563, -2181719, 1168162, -3804809, 26747877, -14138091, 10609330, 12694420, 33473243, -13382104 },+    { 33184999, 11180355, 15832085, -11385430, -1633671, 225884, 15089336, -11023903, -6135662, 14480053 }+  },+  {+    { 31308717, -5619998, 31030840, -1897099, 15674547, -6582883, 5496208, 13685227, 27595050, 8737275 },+    { -20318852, -15150239, 10933843, -16178022, 8335352, -7546022, -31008351, -12610604, 26498114, 66511 },+    { 22644454, -8761729, -16671776, 4884562, -3105614, -13559366, 30540766, -4286747, -13327787, -7515095 }+  },+  {+    { -28017847, 9834845, 18617207, -2681312, -3401956, -13307506, 8205540, 13585437, -17127465, 15115439 },+    { 23711543, -672915, 31206561, -8362711, 6164647, -9709987, -33535882, -1426096, 8236921, 16492939 },+    { -23910559, -13515526, -26299483, -4503841, 25005590, -7687270, 19574902, 10071562, 6708380, -6222424 }+  },+  {+    { 2101391, -4930054, 19702731, 2367575, -15427167, 1047675, 5301017, 9328700, 29955601, -11678310 },+    { 3096359, 9271816, -21620864, -15521844, -14847996, -7592937, -25892142, -12635595, -9917575, 6216608 },+    { -32615849, 338663, -25195611, 2510422, -29213566, -13820213, 24822830, -6146567, -26767480, 7525079 }+  },+  {+    { -23066649, -13985623, 16133487, -7896178, -3389565, 778788, -910336, -2782495, -19386633, 11994101 },+    { 21691500, -13624626, -641331, -14367021, 3285881, -3483596, -25064666, 9718258, -7477437, 13381418 },+    { 18445390, -4202236, 14979846, 11622458, -1727110, -3582980, 23111648, -6375247, 28535282, 15779576 }+  },+  {+    { 30098053, 3089662, -9234387, 16662135, -21306940, 11308411, -14068454, 12021730, 9955285, -16303356 },+    { 9734894, -14576830, -7473633, -9138735, 2060392, 11313496, -18426029, 9924399, 20194861, 13380996 },+    { -26378102, -7965207, -22167821, 15789297, -18055342, -6168792, -1984914, 15707771, 26342023, 10146099 }+  }+},+{ /* 30/31 */+  {+    { -26016874, -219943, 21339191, -41388, 19745256, -2878700, -29637280, 2227040, 21612326, -545728 },+    { -13077387, 1184228, 23562814, -5970442, -20351244, -6348714, 25764461, 12243797, -20856566, 11649658 },+    { -10031494, 11262626, 27384172, 2271902, 26947504, -15997771, 39944, 6114064, 33514190, 2333242 }+  },+  {+    { -21433588, -12421821, 8119782, 7219913, -21830522, -9016134, -6679750, -12670638, 24350578, -13450001 },+    { -4116307, -11271533, -23886186, 4843615, -30088339, 690623, -31536088, -10406836, 8317860, 12352766 },+    { 18200138, -14475911, -33087759, -2696619, -23702521, -9102511, -23552096, -2287550, 20712163, 6719373 }+  },+  {+    { 26656208, 6075253, -7858556, 1886072, -28344043, 4262326, 11117530, -3763210, 26224235, -3297458 },+    { -17168938, -14854097, -3395676, -16369877, -19954045, 14050420, 21728352, 9493610, 18620611, -16428628 },+    { -13323321, 13325349, 11432106, 5964811, 18609221, 6062965, -5269471, -9725556, -30701573, -16479657 }+  },+  {+    { -23860538, -11233159, 26961357, 1640861, -32413112, -16737940, 12248509, -5240639, 13735342, 1934062 },+    { 25089769, 6742589, 17081145, -13406266, 21909293, -16067981, -15136294, -3765346, -21277997, 5473616 },+    { 31883677, -7961101, 1083432, -11572403, 22828471, 13290673, -7125085, 12469656, 29111212, -5451014 }+  },+  {+    { 24244947, -15050407, -26262976, 2791540, -14997599, 16666678, 24367466, 6388839, -10295587, 452383 },+    { -25640782, -3417841, 5217916, 16224624, 19987036, -4082269, -24236251, -5915248, 15766062, 8407814 },+    { -20406999, 13990231, 15495425, 16395525, 5377168, 15166495, -8917023, -4388953, -8067909, 2276718 }+  },+  {+    { 30157918, 12924066, -17712050, 9245753, 19895028, 3368142, -23827587, 5096219, 22740376, -7303417 },+    { 2041139, -14256350, 7783687, 13876377, -25946985, -13352459, 24051124, 13742383, -15637599, 13295222 },+    { 33338237, -8505733, 12532113, 7977527, 9106186, -1715251, -17720195, -4612972, -4451357, -14669444 }+  },+  {+    { -20045281, 5454097, -14346548, 6447146, 28862071, 1883651, -2469266, -4141880, 7770569, 9620597 },+    { 23208068, 7979712, 33071466, 8149229, 1758231, -10834995, 30945528, -1694323, -33502340, -14767970 },+    { 1439958, -16270480, -1079989, -793782, 4625402, 10647766, -5043801, 1220118, 30494170, -11440799 }+  },+  {+    { -5037580, -13028295, -2970559, -3061767, 15640974, -6701666, -26739026, 926050, -1684339, -13333647 },+    { 13908495, -3549272, 30919928, -6273825, -21521863, 7989039, 9021034, 9078865, 3353509, 4033511 },+    { -29663431, -15113610, 32259991, -344482, 24295849, -12912123, 23161163, 8839127, 27485041, 7356032 }+  }+},+{ /* 31/31 */+  {+    { 9661027, 705443, 11980065, -5370154, -1628543, 14661173, -6346142, 2625015, 28431036, -16771834 },+    { -23839233, -8311415, -25945511, 7480958, -17681669, -8354183, -22545972, 14150565, 15970762, 4099461 },+    { 29262576, 16756590, 26350592, -8793563, 8529671, -11208050, 13617293, -9937143, 11465739, 8317062 }+  },+  {+    { -25493081, -6962928, 32500200, -9419051, -23038724, -2302222, 14898637, 3848455, 20969334, -5157516 },+    { -20384450, -14347713, -18336405, 13884722, -33039454, 2842114, -21610826, -3649888, 11177095, 14989547 },+    { -24496721, -11716016, 16959896, 2278463, 12066309, 10137771, 13515641, 2581286, -28487508, 9930240 }+  },+  {+    { -17751622, -2097826, 16544300, -13009300, -15914807, -14949081, 18345767, -13403753, 16291481, -5314038 },+    { -33229194, 2553288, 32678213, 9875984, 8534129, 6889387, -9676774, 6957617, 4368891, 9788741 },+    { 16660756, 7281060, -10830758, 12911820, 20108584, -8101676, -21722536, -8613148, 16250552, -11111103 }+  },+  {+    { -19765507, 2390526, -16551031, 14161980, 1905286, 6414907, 4689584, 10604807, -30190403, 4782747 },+    { -1354539, 14736941, -7367442, -13292886, 7710542, -14155590, -9981571, 4383045, 22546403, 437323 },+    { 31665577, -12180464, -16186830, 1491339, -18368625, 3294682, 27343084, 2786261, -30633590, -14097016 }+  },+  {+    { -14467279, -683715, -33374107, 7448552, 19294360, 14334329, -19690631, 2355319, -19284671, -6114373 },+    { 15121312, -15796162, 6377020, -6031361, -10798111, -12957845, 18952177, 15496498, -29380133, 11754228 },+    { -2637277, -13483075, 8488727, -14303896, 12728761, -1622493, 7141596, 11724556, 22761615, -10134141 }+  },+  {+    { 16918416, 11729663, -18083579, 3022987, -31015732, -13339659, -28741185, -12227393, 32851222, 11717399 },+    { 11166634, 7338049, -6722523, 4531520, -29468672, -7302055, 31474879, 3483633, -1193175, -4030831 },+    { -185635, 9921305, 31456609, -13536438, -12013818, 13348923, 33142652, 6546660, -19985279, -3948376 }+  },+  {+    { -32460596, 11266712, -11197107, -7899103, 31703694, 3855903, -8537131, -12833048, -30772034, -15486313 },+    { -18006477, 12709068, 3991746, -6479188, -21491523, -10550425, -31135347, -16049879, 10928917, 3011958 },+    { -6957757, -15594337, 31696059, 334240, 29576716, 14796075, -30831056, -12805180, 18008031, 10258577 }+  },+  {+    { -22448644, 15655569, 7018479, -4410003, -30314266, -1201591, -1853465, 1367120, 25127874, 6671743 },+    { 29701166, -14373934, -10878120, 9279288, -17568, 13127210, 21382910, 11042292, 25838796, 4642684 },+    { -20430234, 14955537, -24126347, 8124619, -5369288, -5990470, 30468147, -13900640, 18423289, 4177476 }+  }+}
+ vendor/external/libsodium/crypto_core/ed25519/ref10/fe_25_5/base2.h view
@@ -0,0 +1,40 @@+{+  { 25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605 },+  { -12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378 },+  { -8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546 }+},+{+  { 15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, -14772189, 28944400, -1550024 },+  { 16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, -11775962, 7689662, 11199574 },+  { 30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, 10017326, -17749093, -9920357 }+},+{+  { 10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, 14515107, -15438304, 10819380 },+  { 4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, 12483688, -12668491, 5581306 },+  { 19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, 13850243, -23678021, -15815942 }+},+{+  { 5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, 5230134, -23952439, -15175766 },+  { -30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, 16520125, 30598449, 7715701 },+  { 28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, 1370708, 29794553, -1409300 }+},+{+  { -22518993, -6692182, 14201702, -8745502, -23510406, 8844726, 18474211, -1361450, -13062696, 13821877 },+  { -6455177, -7839871, 3374702, -4740862, -27098617, -10571707, 31655028, -7212327, 18853322, -14220951 },+  { 4566830, -12963868, -28974889, -12240689, -7602672, -2830569, -8514358, -10431137, 2207753, -3209784 }+},+{+  { -25154831, -4185821, 29681144, 7868801, -6854661, -9423865, -12437364, -663000, -31111463, -16132436 },+  { 25576264, -2703214, 7349804, -11814844, 16472782, 9300885, 3844789, 15725684, 171356, 6466918 },+  { 23103977, 13316479, 9739013, -16149481, 817875, -15038942, 8965339, -14088058, -30714912, 16193877 }+},+{+  { -33521811, 3180713, -2394130, 14003687, -16903474, -16270840, 17238398, 4729455, -18074513, 9256800 },+  { -25182317, -4174131, 32336398, 5036987, -21236817, 11360617, 22616405, 9761698, -19827198, 630305 },+  { -13720693, 2639453, -24237460, -7406481, 9494427, -5774029, -6554551, -15960994, -2449256, -14291300 }+},+{+  { -3151181, -5046075, 9282714, 6866145, -31907062, -863023, -18940575, 15033784, 25105118, -7894876 },+  { -24326370, 15950226, -31801215, -14592823, -11662737, -5090925, 1573892, -2625887, 2198790, -15804619 },+  { -3099351, 10324967, -2241613, 7453183, -5446979, -2735503, -13812022, -16236442, -32461234, -12290683 }+}
+ vendor/external/libsodium/crypto_core/ed25519/ref10/fe_25_5/constants.h view
@@ -0,0 +1,40 @@+/* 37095705934669439343138083508754565189542113879843219016388785533085940283555 */+static const fe25519 d = {+    -10913610, 13857413, -15372611, 6949391,   114729, -8787816, -6275908, -3247719, -18696448, -12055116+};++/* 2 * d =+ * 16295367250680780974490674513165176452449235426866156013048779062215315747161+ */+static const fe25519 d2 = {+    -21827239, -5839606,  -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199 };++/* sqrt(-1) */+static const fe25519 sqrtm1 = {+    -32595792, -7943725,  9377950,  3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482+};++/* A = 486662 */+static const fe25519 curve25519_A = {+    486662, 0, 0, 0, 0, 0, 0, 0, 0, 0+};++/* sqrt(ad - 1) with a = -1 (mod p) */+static const fe25519 sqrtadm1 = {+    24849947, -153582, -23613485, 6347715, -21072328, -667138, -25271143, -15367704, -870347, 14525639+};++/* 1 / sqrt(a - d) */+static const fe25519 invsqrtamd = {+    6111485, 4156064, -27798727, 12243468, -25904040, 120897, 20826367, -7060776, 6093568, -1986012+};++/* 1 - d ^ 2 */+static const fe25519 onemsqd = {+    6275446, -16617371, -22938544, -3773710, 11667077, 7397348, -27922721, 1766195, -24433858, 672203+};++/* (d - 1) ^ 2 */+static const fe25519 sqdmone = {+    15551795, -11097455, -13425098, -10125071, -11896535, 10178284, -26634327, 4729244, -5282110, -10116402+};
+ vendor/external/libsodium/crypto_core/ed25519/ref10/fe_25_5/fe.h view
@@ -0,0 +1,220 @@+/*+ Ignores top bit of s.+ */++void+fe25519_frombytes(fe25519 h, const unsigned char *s)+{+    int64_t h0 = load_4(s);+    int64_t h1 = load_3(s + 4) << 6;+    int64_t h2 = load_3(s + 7) << 5;+    int64_t h3 = load_3(s + 10) << 3;+    int64_t h4 = load_3(s + 13) << 2;+    int64_t h5 = load_4(s + 16);+    int64_t h6 = load_3(s + 20) << 7;+    int64_t h7 = load_3(s + 23) << 5;+    int64_t h8 = load_3(s + 26) << 4;+    int64_t h9 = (load_3(s + 29) & 8388607) << 2;++    int64_t carry0;+    int64_t carry1;+    int64_t carry2;+    int64_t carry3;+    int64_t carry4;+    int64_t carry5;+    int64_t carry6;+    int64_t carry7;+    int64_t carry8;+    int64_t carry9;++    carry9 = (h9 + (int64_t)(1L << 24)) >> 25;+    h0 += carry9 * 19;+    h9 -= carry9 * ((uint64_t) 1L << 25);+    carry1 = (h1 + (int64_t)(1L << 24)) >> 25;+    h2 += carry1;+    h1 -= carry1 * ((uint64_t) 1L << 25);+    carry3 = (h3 + (int64_t)(1L << 24)) >> 25;+    h4 += carry3;+    h3 -= carry3 * ((uint64_t) 1L << 25);+    carry5 = (h5 + (int64_t)(1L << 24)) >> 25;+    h6 += carry5;+    h5 -= carry5 * ((uint64_t) 1L << 25);+    carry7 = (h7 + (int64_t)(1L << 24)) >> 25;+    h8 += carry7;+    h7 -= carry7 * ((uint64_t) 1L << 25);++    carry0 = (h0 + (int64_t)(1L << 25)) >> 26;+    h1 += carry0;+    h0 -= carry0 * ((uint64_t) 1L << 26);+    carry2 = (h2 + (int64_t)(1L << 25)) >> 26;+    h3 += carry2;+    h2 -= carry2 * ((uint64_t) 1L << 26);+    carry4 = (h4 + (int64_t)(1L << 25)) >> 26;+    h5 += carry4;+    h4 -= carry4 * ((uint64_t) 1L << 26);+    carry6 = (h6 + (int64_t)(1L << 25)) >> 26;+    h7 += carry6;+    h6 -= carry6 * ((uint64_t) 1L << 26);+    carry8 = (h8 + (int64_t)(1L << 25)) >> 26;+    h9 += carry8;+    h8 -= carry8 * ((uint64_t) 1L << 26);++    h[0] = (int32_t) h0;+    h[1] = (int32_t) h1;+    h[2] = (int32_t) h2;+    h[3] = (int32_t) h3;+    h[4] = (int32_t) h4;+    h[5] = (int32_t) h5;+    h[6] = (int32_t) h6;+    h[7] = (int32_t) h7;+    h[8] = (int32_t) h8;+    h[9] = (int32_t) h9;+}++/*+ Preconditions:+ |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.++ Write p=2^255-19; q=floor(h/p).+ Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).++ Proof:+ Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4.+ Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4.++ Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9).+ Then 0<y<1.++ Write r=h-pq.+ Have 0<=r<=p-1=2^255-20.+ Thus 0<=r+19(2^-255)r<r+19(2^-255)2^255<=2^255-1.++ Write x=r+19(2^-255)r+y.+ Then 0<x<2^255 so floor(2^(-255)x) = 0 so floor(q+2^(-255)x) = q.++ Have q+2^(-255)x = 2^(-255)(h + 19 2^(-25) h9 + 2^(-1))+ so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.+*/++static void+fe25519_reduce(fe25519 h, const fe25519 f)+{+    int32_t h0 = f[0];+    int32_t h1 = f[1];+    int32_t h2 = f[2];+    int32_t h3 = f[3];+    int32_t h4 = f[4];+    int32_t h5 = f[5];+    int32_t h6 = f[6];+    int32_t h7 = f[7];+    int32_t h8 = f[8];+    int32_t h9 = f[9];++    int32_t q;+    int32_t carry0, carry1, carry2, carry3, carry4, carry5, carry6, carry7, carry8, carry9;++    q = (19 * h9 + ((uint32_t) 1L << 24)) >> 25;+    q = (h0 + q) >> 26;+    q = (h1 + q) >> 25;+    q = (h2 + q) >> 26;+    q = (h3 + q) >> 25;+    q = (h4 + q) >> 26;+    q = (h5 + q) >> 25;+    q = (h6 + q) >> 26;+    q = (h7 + q) >> 25;+    q = (h8 + q) >> 26;+    q = (h9 + q) >> 25;++    /* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */+    h0 += 19 * q;+    /* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */++    carry0 = h0 >> 26;+    h1 += carry0;+    h0 -= carry0 * ((uint32_t) 1L << 26);+    carry1 = h1 >> 25;+    h2 += carry1;+    h1 -= carry1 * ((uint32_t) 1L << 25);+    carry2 = h2 >> 26;+    h3 += carry2;+    h2 -= carry2 * ((uint32_t) 1L << 26);+    carry3 = h3 >> 25;+    h4 += carry3;+    h3 -= carry3 * ((uint32_t) 1L << 25);+    carry4 = h4 >> 26;+    h5 += carry4;+    h4 -= carry4 * ((uint32_t) 1L << 26);+    carry5 = h5 >> 25;+    h6 += carry5;+    h5 -= carry5 * ((uint32_t) 1L << 25);+    carry6 = h6 >> 26;+    h7 += carry6;+    h6 -= carry6 * ((uint32_t) 1L << 26);+    carry7 = h7 >> 25;+    h8 += carry7;+    h7 -= carry7 * ((uint32_t) 1L << 25);+    carry8 = h8 >> 26;+    h9 += carry8;+    h8 -= carry8 * ((uint32_t) 1L << 26);+    carry9 = h9 >> 25;+    h9 -= carry9 * ((uint32_t) 1L << 25);++    h[0] = h0;+    h[1] = h1;+    h[2] = h2;+    h[3] = h3;+    h[4] = h4;+    h[5] = h5;+    h[6] = h6;+    h[7] = h7;+    h[8] = h8;+    h[9] = h9;+}++/*+ Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20.+ Have h0+...+2^230 h9 between 0 and 2^255-1;+ evidently 2^255 h10-2^255 q = 0.++ Goal: Output h0+...+2^230 h9.+ */++void+fe25519_tobytes(unsigned char *s, const fe25519 h)+{+    fe25519 t;++    fe25519_reduce(t, h);+    s[0]  = t[0] >> 0;+    s[1]  = t[0] >> 8;+    s[2]  = t[0] >> 16;+    s[3]  = (t[0] >> 24) | (t[1] * ((uint32_t) 1 << 2));+    s[4]  = t[1] >> 6;+    s[5]  = t[1] >> 14;+    s[6]  = (t[1] >> 22) | (t[2] * ((uint32_t) 1 << 3));+    s[7]  = t[2] >> 5;+    s[8]  = t[2] >> 13;+    s[9]  = (t[2] >> 21) | (t[3] * ((uint32_t) 1 << 5));+    s[10] = t[3] >> 3;+    s[11] = t[3] >> 11;+    s[12] = (t[3] >> 19) | (t[4] * ((uint32_t) 1 << 6));+    s[13] = t[4] >> 2;+    s[14] = t[4] >> 10;+    s[15] = t[4] >> 18;+    s[16] = t[5] >> 0;+    s[17] = t[5] >> 8;+    s[18] = t[5] >> 16;+    s[19] = (t[5] >> 24) | (t[6] * ((uint32_t) 1 << 1));+    s[20] = t[6] >> 7;+    s[21] = t[6] >> 15;+    s[22] = (t[6] >> 23) | (t[7] * ((uint32_t) 1 << 3));+    s[23] = t[7] >> 5;+    s[24] = t[7] >> 13;+    s[25] = (t[7] >> 21) | (t[8] * ((uint32_t) 1 << 4));+    s[26] = t[8] >> 4;+    s[27] = t[8] >> 12;+    s[28] = (t[8] >> 20) | (t[9] * ((uint32_t) 1 << 6));+    s[29] = t[9] >> 2;+    s[30] = t[9] >> 10;+    s[31] = t[9] >> 18;+}
+ vendor/external/libsodium/crypto_core/ed25519/ref10/fe_51/base.h view
@@ -0,0 +1,1344 @@+{ /* 0/31 */+  {+    { 1288382639258501, 245678601348599, 269427782077623, 1462984067271730, 137412439391563 },+    { 62697248952638, 204681361388450, 631292143396476, 338455783676468, 1213667448819585 },+    { 301289933810280, 1259582250014073, 1422107436869536, 796239922652654, 1953934009299142 }+  },+  {+    { 1380971894829527, 790832306631236, 2067202295274102, 1995808275510000, 1566530869037010 },+    { 463307831301544, 432984605774163, 1610641361907204, 750899048855000, 1894842303421586 },+    { 748439484463711, 1033211726465151, 1396005112841647, 1611506220286469, 1972177495910992 }+  },+  {+    { 1601611775252272, 1720807796594148, 1132070835939856, 1260455018889551, 2147779492816911 },+    { 316559037616741, 2177824224946892, 1459442586438991, 1461528397712656, 751590696113597 },+    { 1850748884277385, 1200145853858453, 1068094770532492, 672251375690438, 1586055907191707 }+  },+  {+    { 934282339813791, 1846903124198670, 1172395437954843, 1007037127761661, 1830588347719256 },+    { 1694390458783935, 1735906047636159, 705069562067493, 648033061693059, 696214010414170 },+    { 1121406372216585, 192876649532226, 190294192191717, 1994165897297032, 2245000007398739 }+  },+  {+    { 769950342298419, 132954430919746, 844085933195555, 974092374476333, 726076285546016 },+    { 425251763115706, 608463272472562, 442562545713235, 837766094556764, 374555092627893 },+    { 1086255230780037, 274979815921559, 1960002765731872, 929474102396301, 1190409889297339 }+  },+  {+    { 1388594989461809, 316767091099457, 394298842192982, 1230079486801005, 1440737038838979 },+    { 7380825640100, 146210432690483, 304903576448906, 1198869323871120, 997689833219095 },+    { 1181317918772081, 114573476638901, 262805072233344, 265712217171332, 294181933805782 }+  },+  {+    { 665000864555967, 2065379846933859, 370231110385876, 350988370788628, 1233371373142985 },+    { 2019367628972465, 676711900706637, 110710997811333, 1108646842542025, 517791959672113 },+    { 965130719900578, 247011430587952, 526356006571389, 91986625355052, 2157223321444601 }+  },+  {+    { 2068619540119183, 1966274918058806, 957728544705549, 729906502578991, 159834893065166 },+    { 2073601412052185, 31021124762708, 264500969797082, 248034690651703, 1030252227928288 },+    { 551790716293402, 1989538725166328, 801169423371717, 2052451893578887, 678432056995012 }+  }+},+{ /* 1/31 */+  {+    { 1368953770187805, 790347636712921, 437508475667162, 2142576377050580, 1932081720066286 },+    { 953638594433374, 1092333936795051, 1419774766716690, 805677984380077, 859228993502513 },+    { 1200766035879111, 20142053207432, 1465634435977050, 1645256912097844, 295121984874596 }+  },+  {+    { 1735718747031557, 1248237894295956, 1204753118328107, 976066523550493, 65943769534592 },+    { 1060098822528990, 1586825862073490, 212301317240126, 1975302711403555, 666724059764335 },+    { 1091990273418756, 1572899409348578, 80968014455247, 306009358661350, 1520450739132526 }+  },+  {+    { 1480517209436112, 1511153322193952, 1244343858991172, 304788150493241, 369136856496443 },+    { 2151330273626164, 762045184746182, 1688074332551515, 823046109005759, 907602769079491 },+    { 2047386910586836, 168470092900250, 1552838872594810, 340951180073789, 360819374702533 }+  },+  {+    { 1982622644432056, 2014393600336956, 128909208804214, 1617792623929191, 105294281913815 },+    { 980234343912898, 1712256739246056, 588935272190264, 204298813091998, 841798321043288 },+    { 197561292938973, 454817274782871, 1963754960082318, 2113372252160468, 971377527342673 }+  },+  {+    { 164699448829328, 3127451757672, 1199504971548753, 1766155447043652, 1899238924683527 },+    { 732262946680281, 1674412764227063, 2182456405662809, 1350894754474250, 558458873295247 },+    { 2103305098582922, 1960809151316468, 715134605001343, 1454892949167181, 40827143824949 }+  },+  {+    { 1239289043050212, 1744654158124578, 758702410031698, 1796762995074688, 1603056663766 },+    { 2232056027107988, 987343914584615, 2115594492994461, 1819598072792159, 1119305654014850 },+    { 320153677847348, 939613871605645, 641883205761567, 1930009789398224, 329165806634126 }+  },+  {+    { 980930490474130, 1242488692177893, 1251446316964684, 1086618677993530, 1961430968465772 },+    { 276821765317453, 1536835591188030, 1305212741412361, 61473904210175, 2051377036983058 },+    { 833449923882501, 1750270368490475, 1123347002068295, 185477424765687, 278090826653186 }+  },+  {+    { 794524995833413, 1849907304548286, 53348672473145, 1272368559505217, 1147304168324779 },+    { 1504846112759364, 1203096289004681, 562139421471418, 274333017451844, 1284344053775441 },+    { 483048732424432, 2116063063343382, 30120189902313, 292451576741007, 1156379271702225 }+  }+},+{ /* 2/31 */+  {+    { 928372153029038, 2147692869914564, 1455665844462196, 1986737809425946, 185207050258089 },+    { 137732961814206, 706670923917341, 1387038086865771, 1965643813686352, 1384777115696347 },+    { 481144981981577, 2053319313589856, 2065402289827512, 617954271490316, 1106602634668125 }+  },+  {+    { 696298019648792, 893299659040895, 1148636718636009, 26734077349617, 2203955659340681 },+    { 657390353372855, 998499966885562, 991893336905797, 810470207106761, 343139804608786 },+    { 791736669492960, 934767652997115, 824656780392914, 1759463253018643, 361530362383518 }+  },+  {+    { 2022541353055597, 2094700262587466, 1551008075025686, 242785517418164, 695985404963562 },+    { 1287487199965223, 2215311941380308, 1552928390931986, 1664859529680196, 1125004975265243 },+    { 677434665154918, 989582503122485, 1817429540898386, 1052904935475344, 1143826298169798 }+  },+  {+    { 367266328308408, 318431188922404, 695629353755355, 634085657580832, 24581612564426 },+    { 773360688841258, 1815381330538070, 363773437667376, 539629987070205, 783280434248437 },+    { 180820816194166, 168937968377394, 748416242794470, 1227281252254508, 1567587861004268 }+  },+  {+    { 478775558583645, 2062896624554807, 699391259285399, 358099408427873, 1277310261461761 },+    { 1984740906540026, 1079164179400229, 1056021349262661, 1659958556483663, 1088529069025527 },+    { 580736401511151, 1842931091388998, 1177201471228238, 2075460256527244, 1301133425678027 }+  },+  {+    { 1515728832059182, 1575261009617579, 1510246567196186, 191078022609704, 116661716289141 },+    { 1295295738269652, 1714742313707026, 545583042462581, 2034411676262552, 1513248090013606 },+    { 230710545179830, 30821514358353, 760704303452229, 390668103790604, 573437871383156 }+  },+  {+    { 1169380107545646, 263167233745614, 2022901299054448, 819900753251120, 2023898464874585 },+    { 2102254323485823, 1570832666216754, 34696906544624, 1993213739807337, 70638552271463 },+    { 894132856735058, 548675863558441, 845349339503395, 1942269668326667, 1615682209874691 }+  },+  {+    { 1287670217537834, 1222355136884920, 1846481788678694, 1150426571265110, 1613523400722047 },+    { 793388516527298, 1315457083650035, 1972286999342417, 1901825953052455, 338269477222410 },+    { 550201530671806, 778605267108140, 2063911101902983, 115500557286349, 2041641272971022 }+  }+},+{ /* 3/31 */+  {+    { 717255318455100, 519313764361315, 2080406977303708, 541981206705521, 774328150311600 },+    { 261715221532238, 1795354330069993, 1496878026850283, 499739720521052, 389031152673770 },+    { 1997217696294013, 1717306351628065, 1684313917746180, 1644426076011410, 1857378133465451 }+  },+  {+    { 1475434724792648, 76931896285979, 1116729029771667, 2002544139318042, 725547833803938 },+    { 2022306639183567, 726296063571875, 315345054448644, 1058733329149221, 1448201136060677 },+    { 1710065158525665, 1895094923036397, 123988286168546, 1145519900776355, 1607510767693874 }+  },+  {+    { 561605375422540, 1071733543815037, 131496498800990, 1946868434569999, 828138133964203 },+    { 1548495173745801, 442310529226540, 998072547000384, 553054358385281, 644824326376171 },+    { 1445526537029440, 2225519789662536, 914628859347385, 1064754194555068, 1660295614401091 }+  },+  {+    { 1199690223111956, 24028135822341, 66638289244341, 57626156285975, 565093967979607 },+    { 876926774220824, 554618976488214, 1012056309841565, 839961821554611, 1414499340307677 },+    { 703047626104145, 1266841406201770, 165556500219173, 486991595001879, 1011325891650656 }+  },+  {+    { 1622861044480487, 1156394801573634, 1869132565415504, 327103985777730, 2095342781472284 },+    { 334886927423922, 489511099221528, 129160865966726, 1720809113143481, 619700195649254 },+    { 1646545795166119, 1758370782583567, 714746174550637, 1472693650165135, 898994790308209 }+  },+  {+    { 333403773039279, 295772542452938, 1693106465353610, 912330357530760, 471235657950362 },+    { 1811196219982022, 1068969825533602, 289602974833439, 1988956043611592, 863562343398367 },+    { 906282429780072, 2108672665779781, 432396390473936, 150625823801893, 1708930497638539 }+  },+  {+    { 925664675702328, 21416848568684, 1831436641861340, 601157008940113, 371818055044496 },+    { 1479786007267725, 1738881859066675, 68646196476567, 2146507056100328, 1247662817535471 },+    { 52035296774456, 939969390708103, 312023458773250, 59873523517659, 1231345905848899 }+  },+  {+    { 643355106415761, 290186807495774, 2013561737429023, 319648069511546, 393736678496162 },+    { 129358342392716, 1932811617704777, 1176749390799681, 398040349861790, 1170779668090425 },+    { 2051980782668029, 121859921510665, 2048329875753063, 1235229850149665, 519062146124755 }+  }+},+{ /* 4/31 */+  {+    { 1608170971973096, 415809060360428, 1350468408164766, 2038620059057678, 1026904485989112 },+    { 1837656083115103, 1510134048812070, 906263674192061, 1821064197805734, 565375124676301 },+    { 578027192365650, 2034800251375322, 2128954087207123, 478816193810521, 2196171989962750 }+  },+  {+    { 1633188840273139, 852787172373708, 1548762607215796, 1266275218902681, 1107218203325133 },+    { 462189358480054, 1784816734159228, 1611334301651368, 1303938263943540, 707589560319424 },+    { 1038829280972848, 38176604650029, 753193246598573, 1136076426528122, 595709990562434 }+  },+  {+    { 1408451820859834, 2194984964010833, 2198361797561729, 1061962440055713, 1645147963442934 },+    { 4701053362120, 1647641066302348, 1047553002242085, 1923635013395977, 206970314902065 },+    { 1750479161778571, 1362553355169293, 1891721260220598, 966109370862782, 1024913988299801 }+  },+  {+    { 212699049131723, 1117950018299775, 1873945661751056, 1403802921984058, 130896082652698 },+    { 636808533673210, 1262201711667560, 390951380330599, 1663420692697294, 561951321757406 },+    { 520731594438141, 1446301499955692, 273753264629267, 1565101517999256, 1019411827004672 }+  },+  {+    { 926527492029409, 1191853477411379, 734233225181171, 184038887541270, 1790426146325343 },+    { 1464651961852572, 1483737295721717, 1519450561335517, 1161429831763785, 405914998179977 },+    { 996126634382301, 796204125879525, 127517800546509, 344155944689303, 615279846169038 }+  },+  {+    { 738724080975276, 2188666632415296, 1961313708559162, 1506545807547587, 1151301638969740 },+    { 622917337413835, 1218989177089035, 1284857712846592, 970502061709359, 351025208117090 },+    { 2067814584765580, 1677855129927492, 2086109782475197, 235286517313238, 1416314046739645 }+  },+  {+    { 586844262630358, 307444381952195, 458399356043426, 602068024507062, 1028548203415243 },+    { 678489922928203, 2016657584724032, 90977383049628, 1026831907234582, 615271492942522 },+    { 301225714012278, 1094837270268560, 1202288391010439, 644352775178361, 1647055902137983 }+  },+  {+    { 1210746697896478, 1416608304244708, 686487477217856, 1245131191434135, 1051238336855737 },+    { 1135604073198207, 1683322080485474, 769147804376683, 2086688130589414, 900445683120379 },+    { 1971518477615628, 401909519527336, 448627091057375, 1409486868273821, 1214789035034363 }+  }+},+{ /* 5/31 */+  {+    { 1364039144731711, 1897497433586190, 2203097701135459, 145461396811251, 1349844460790699 },+    { 1045230323257973, 818206601145807, 630513189076103, 1672046528998132, 807204017562437 },+    { 439961968385997, 386362664488986, 1382706320807688, 309894000125359, 2207801346498567 }+  },+  {+    { 1229004686397588, 920643968530863, 123975893911178, 681423993215777, 1400559197080973 },+    { 2003766096898049, 170074059235165, 1141124258967971, 1485419893480973, 1573762821028725 },+    { 729905708611432, 1270323270673202, 123353058984288, 426460209632942, 2195574535456672 }+  },+  {+    { 1271140255321235, 2044363183174497, 52125387634689, 1445120246694705, 942541986339084 },+    { 1761608437466135, 583360847526804, 1586706389685493, 2157056599579261, 1170692369685772 },+    { 871476219910823, 1878769545097794, 2241832391238412, 548957640601001, 690047440233174 }+  },+  {+    { 297194732135507, 1366347803776820, 1301185512245601, 561849853336294, 1533554921345731 },+    { 999628998628371, 1132836708493400, 2084741674517453, 469343353015612, 678782988708035 },+    { 2189427607417022, 699801937082607, 412764402319267, 1478091893643349, 2244675696854460 }+  },+  {+    { 1712292055966563, 204413590624874, 1405738637332841, 408981300829763, 861082219276721 },+    { 508561155940631, 966928475686665, 2236717801150132, 424543858577297, 2089272956986143 },+    { 221245220129925, 1156020201681217, 491145634799213, 542422431960839, 828100817819207 }+  },+  {+    { 153756971240384, 1299874139923977, 393099165260502, 1058234455773022, 996989038681183 },+    { 559086812798481, 573177704212711, 1629737083816402, 1399819713462595, 1646954378266038 },+    { 1887963056288059, 228507035730124, 1468368348640282, 930557653420194, 613513962454686 }+  },+  {+    { 1224529808187553, 1577022856702685, 2206946542980843, 625883007765001, 279930793512158 },+    { 1076287717051609, 1114455570543035, 187297059715481, 250446884292121, 1885187512550540 },+    { 902497362940219, 76749815795675, 1657927525633846, 1420238379745202, 1340321636548352 }+  },+  {+    { 1129576631190784, 1281994010027327, 996844254743018, 257876363489249, 1150850742055018 },+    { 628740660038789, 1943038498527841, 467786347793886, 1093341428303375, 235413859513003 },+    { 237425418909360, 469614029179605, 1512389769174935, 1241726368345357, 441602891065214 }+  }+},+{ /* 6/31 */+  {+    { 1736417953058555, 726531315520508, 1833335034432527, 1629442561574747, 624418919286085 },+    { 1960754663920689, 497040957888962, 1909832851283095, 1271432136996826, 2219780368020940 },+    { 1537037379417136, 1358865369268262, 2130838645654099, 828733687040705, 1999987652890901 }+  },+  {+    { 629042105241814, 1098854999137608, 887281544569320, 1423102019874777, 7911258951561 },+    { 1811562332665373, 1501882019007673, 2213763501088999, 359573079719636, 36370565049116 },+    { 218907117361280, 1209298913016966, 1944312619096112, 1130690631451061, 1342327389191701 }+  },+  {+    { 1369976867854704, 1396479602419169, 1765656654398856, 2203659200586299, 998327836117241 },+    { 2230701885562825, 1348173180338974, 2172856128624598, 1426538746123771, 444193481326151 },+    { 784210426627951, 918204562375674, 1284546780452985, 1324534636134684, 1872449409642708 }+  },+  {+    { 319638829540294, 596282656808406, 2037902696412608, 1557219121643918, 341938082688094 },+    { 1901860206695915, 2004489122065736, 1625847061568236, 973529743399879, 2075287685312905 },+    { 1371853944110545, 1042332820512553, 1949855697918254, 1791195775521505, 37487364849293 }+  },+  {+    { 687200189577855, 1082536651125675, 644224940871546, 340923196057951, 343581346747396 },+    { 2082717129583892, 27829425539422, 145655066671970, 1690527209845512, 1865260509673478 },+    { 1059729620568824, 2163709103470266, 1440302280256872, 1769143160546397, 869830310425069 }+  },+  {+    { 1609516219779025, 777277757338817, 2101121130363987, 550762194946473, 1905542338659364 },+    { 2024821921041576, 426948675450149, 595133284085473, 471860860885970, 600321679413000 },+    { 598474602406721, 1468128276358244, 1191923149557635, 1501376424093216, 1281662691293476 }+  },+  {+    { 1721138489890707, 1264336102277790, 433064545421287, 1359988423149466, 1561871293409447 },+    { 719520245587143, 393380711632345, 132350400863381, 1543271270810729, 1819543295798660 },+    { 396397949784152, 1811354474471839, 1362679985304303, 2117033964846756, 498041172552279 }+  },+  {+    { 1812471844975748, 1856491995543149, 126579494584102, 1036244859282620, 1975108050082550 },+    { 650623932407995, 1137551288410575, 2125223403615539, 1725658013221271, 2134892965117796 },+    { 522584000310195, 1241762481390450, 1743702789495384, 2227404127826575, 1686746002148897 }+  }+},+{ /* 7/31 */+  {+    { 427904865186312, 1703211129693455, 1585368107547509, 1436984488744336, 761188534613978 },+    { 318101947455002, 248138407995851, 1481904195303927, 309278454311197, 1258516760217879 },+    { 1275068538599310, 513726919533379, 349926553492294, 688428871968420, 1702400196000666 }+  },+  {+    { 1061864036265233, 961611260325381, 321859632700838, 1045600629959517, 1985130202504038 },+    { 1558816436882417, 1962896332636523, 1337709822062152, 1501413830776938, 294436165831932 },+    { 818359826554971, 1862173000996177, 626821592884859, 573655738872376, 1749691246745455 }+  },+  {+    { 1988022651432119, 1082111498586040, 1834020786104821, 1454826876423687, 692929915223122 },+    { 2146513703733331, 584788900394667, 464965657279958, 2183973639356127, 238371159456790 },+    { 1129007025494441, 2197883144413266, 265142755578169, 971864464758890, 1983715884903702 }+  },+  {+    { 1291366624493075, 381456718189114, 1711482489312444, 1815233647702022, 892279782992467 },+    { 444548969917454, 1452286453853356, 2113731441506810, 645188273895859, 810317625309512 },+    { 2242724082797924, 1373354730327868, 1006520110883049, 2147330369940688, 1151816104883620 }+  },+  {+    { 1745720200383796, 1911723143175317, 2056329390702074, 355227174309849, 879232794371100 },+    { 163723479936298, 115424889803150, 1156016391581227, 1894942220753364, 1970549419986329 },+    { 681981452362484, 267208874112496, 1374683991933094, 638600984916117, 646178654558546 }+  },+  {+    { 13378654854251, 106237307029567, 1944412051589651, 1841976767925457, 230702819835573 },+    { 260683893467075, 854060306077237, 913639551980112, 4704576840123, 280254810808712 },+    { 715374893080287, 1173334812210491, 1806524662079626, 1894596008000979, 398905715033393 }+  },+  {+    { 500026409727661, 1596431288195371, 1420380351989370, 985211561521489, 392444930785633 },+    { 2096421546958141, 1922523000950363, 789831022876840, 427295144688779, 320923973161730 },+    { 1927770723575450, 1485792977512719, 1850996108474547, 551696031508956, 2126047405475647 }+  },+  {+    { 2112099158080148, 742570803909715, 6484558077432, 1951119898618916, 93090382703416 },+    { 383905201636970, 859946997631870, 855623867637644, 1017125780577795, 794250831877809 },+    { 77571826285752, 999304298101753, 487841111777762, 1038031143212339, 339066367948762 }+  }+},+{ /* 8/31 */+  {+    { 674994775520533, 266035846330789, 826951213393478, 1405007746162285, 1781791018620876 },+    { 1001412661522686, 348196197067298, 1666614366723946, 888424995032760, 580747687801357 },+    { 1939560076207777, 1409892634407635, 552574736069277, 383854338280405, 190706709864139 }+  },+  {+    { 2177087163428741, 1439255351721944, 1208070840382793, 2230616362004769, 1396886392021913 },+    { 676962063230039, 1880275537148808, 2046721011602706, 888463247083003, 1318301552024067 },+    { 1466980508178206, 617045217998949, 652303580573628, 757303753529064, 207583137376902 }+  },+  {+    { 1511056752906902, 105403126891277, 493434892772846, 1091943425335976, 1802717338077427 },+    { 1853982405405128, 1878664056251147, 1528011020803992, 1019626468153565, 1128438412189035 },+    { 1963939888391106, 293456433791664, 697897559513649, 985882796904380, 796244541237972 }+  },+  {+    { 416770998629779, 389655552427054, 1314476859406756, 1749382513022778, 1161905598739491 },+    { 1428358296490651, 1027115282420478, 304840698058337, 441410174026628, 1819358356278573 },+    { 204943430200135, 1554861433819175, 216426658514651, 264149070665950, 2047097371738319 }+  },+  {+    { 1934415182909034, 1393285083565062, 516409331772960, 1157690734993892, 121039666594268 },+    { 662035583584445, 286736105093098, 1131773000510616, 818494214211439, 472943792054479 },+    { 665784778135882, 1893179629898606, 808313193813106, 276797254706413, 1563426179676396 }+  },+  {+    { 945205108984232, 526277562959295, 1324180513733566, 1666970227868664, 153547609289173 },+    { 2031433403516252, 203996615228162, 170487168837083, 981513604791390, 843573964916831 },+    { 1476570093962618, 838514669399805, 1857930577281364, 2017007352225784, 317085545220047 }+  },+  {+    { 1461557121912842, 1600674043318359, 2157134900399597, 1670641601940616, 127765583803283 },+    { 1293543509393474, 2143624609202546, 1058361566797508, 214097127393994, 946888515472729 },+    { 357067959932916, 1290876214345711, 521245575443703, 1494975468601005, 800942377643885 }+  },+  {+    { 566116659100033, 820247422481740, 994464017954148, 327157611686365, 92591318111744 },+    { 617256647603209, 1652107761099439, 1857213046645471, 1085597175214970, 817432759830522 },+    { 771808161440705, 1323510426395069, 680497615846440, 851580615547985, 1320806384849017 }+  }+},+{ /* 9/31 */+  {+    { 1219260086131915, 647169006596815, 79601124759706, 2161724213426748, 404861897060198 },+    { 1327968293887866, 1335500852943256, 1401587164534264, 558137311952440, 1551360549268902 },+    { 417621685193956, 1429953819744454, 396157358457099, 1940470778873255, 214000046234152 }+  },+  {+    { 1268047918491973, 2172375426948536, 1533916099229249, 1761293575457130, 1590622667026765 },+    { 1627072914981959, 2211603081280073, 1912369601616504, 1191770436221309, 2187309757525860 },+    { 1149147819689533, 378692712667677, 828475842424202, 2218619146419342, 70688125792186 }+  },+  {+    { 1299739417079761, 1438616663452759, 1536729078504412, 2053896748919838, 1008421032591246 },+    { 2040723824657366, 399555637875075, 632543375452995, 872649937008051, 1235394727030233 },+    { 2211311599327900, 2139787259888175, 938706616835350, 12609661139114, 2081897930719789 }+  },+  {+    { 1324994503390450, 336982330582631, 1183998925654177, 1091654665913274, 48727673971319 },+    { 1845522914617879, 1222198248335542, 150841072760134, 1927029069940982, 1189913404498011 },+    { 1079559557592645, 2215338383666441, 1903569501302605, 49033973033940, 305703433934152 }+  },+  {+    { 94653405416909, 1386121349852999, 1062130477891762, 36553947479274, 833669648948846 },+    { 1432015813136298, 440364795295369, 1395647062821501, 1976874522764578, 934452372723352 },+    { 1296625309219774, 2068273464883862, 1858621048097805, 1492281814208508, 2235868981918946 }+  },+  {+    { 1490330266465570, 1858795661361448, 1436241134969763, 294573218899647, 1208140011028933 },+    { 1282462923712748, 741885683986255, 2027754642827561, 518989529541027, 1826610009555945 },+    { 1525827120027511, 723686461809551, 1597702369236987, 244802101764964, 1502833890372311 }+  },+  {+    { 113622036244513, 1233740067745854, 674109952278496, 2114345180342965, 166764512856263 },+    { 2041668749310338, 2184405322203901, 1633400637611036, 2110682505536899, 2048144390084644 },+    { 503058759232932, 760293024620937, 2027152777219493, 666858468148475, 1539184379870952 }+  },+  {+    { 1916168475367211, 915626432541343, 883217071712575, 363427871374304, 1976029821251593 },+    { 678039535434506, 570587290189340, 1605302676614120, 2147762562875701, 1706063797091704 },+    { 1439489648586438, 2194580753290951, 832380563557396, 561521973970522, 584497280718389 }+  }+},+{ /* 10/31 */+  {+    { 187989455492609, 681223515948275, 1933493571072456, 1872921007304880, 488162364135671 },+    { 1413466089534451, 410844090765630, 1397263346404072, 408227143123410, 1594561803147811 },+    { 2102170800973153, 719462588665004, 1479649438510153, 1097529543970028, 1302363283777685 }+  },+  {+    { 942065717847195, 1069313679352961, 2007341951411051, 70973416446291, 1419433790163706 },+    { 1146565545556377, 1661971299445212, 406681704748893, 564452436406089, 1109109865829139 },+    { 2214421081775077, 1165671861210569, 1890453018796184, 3556249878661, 442116172656317 }+  },+  {+    { 753830546620811, 1666955059895019, 1530775289309243, 1119987029104146, 2164156153857580 },+    { 615171919212796, 1523849404854568, 854560460547503, 2067097370290715, 1765325848586042 },+    { 1094538949313667, 1796592198908825, 870221004284388, 2025558921863561, 1699010892802384 }+  },+  {+    { 1951351290725195, 1916457206844795, 198025184438026, 1909076887557595, 1938542290318919 },+    { 1014323197538413, 869150639940606, 1756009942696599, 1334952557375672, 1544945379082874 },+    { 764055910920305, 1603590757375439, 146805246592357, 1843313433854297, 954279890114939 }+  },+  {+    { 80113526615750, 764536758732259, 1055139345100233, 469252651759390, 617897512431515 },+    { 74497112547268, 740094153192149, 1745254631717581, 727713886503130, 1283034364416928 },+    { 525892105991110, 1723776830270342, 1476444848991936, 573789489857760, 133864092632978 }+  },+  {+    { 542611720192581, 1986812262899321, 1162535242465837, 481498966143464, 544600533583622 },+    { 64123227344372, 1239927720647794, 1360722983445904, 222610813654661, 62429487187991 },+    { 1793193323953132, 91096687857833, 70945970938921, 2158587638946380, 1537042406482111 }+  },+  {+    { 1895854577604609, 1394895708949416, 1728548428495944, 1140864900240149, 563645333603061 },+    { 141358280486863, 91435889572504, 1087208572552643, 1829599652522921, 1193307020643647 },+    { 1611230858525381, 950720175540785, 499589887488610, 2001656988495019, 88977313255908 }+  },+  {+    { 1189080501479658, 2184348804772597, 1040818725742319, 2018318290311834, 1712060030915354 },+    { 873966876953756, 1090638350350440, 1708559325189137, 672344594801910, 1320437969700239 },+    { 1508590048271766, 1131769479776094, 101550868699323, 428297785557897, 561791648661744 }+  }+},+{ /* 11/31 */+  {+    { 756417570499462, 237882279232602, 2136263418594016, 1701968045454886, 703713185137472 },+    { 1781187809325462, 1697624151492346, 1381393690939988, 175194132284669, 1483054666415238 },+    { 2175517777364616, 708781536456029, 955668231122942, 1967557500069555, 2021208005604118 }+  },+  {+    { 1115135966606887, 224217372950782, 915967306279222, 593866251291540, 561747094208006 },+    { 1443163092879439, 391875531646162, 2180847134654632, 464538543018753, 1594098196837178 },+    { 850858855888869, 319436476624586, 327807784938441, 740785849558761, 17128415486016 }+  },+  {+    { 2132756334090067, 536247820155645, 48907151276867, 608473197600695, 1261689545022784 },+    { 1525176236978354, 974205476721062, 293436255662638, 148269621098039, 137961998433963 },+    { 1121075518299410, 2071745529082111, 1265567917414828, 1648196578317805, 496232102750820 }+  },+  {+    { 122321229299801, 1022922077493685, 2001275453369484, 2017441881607947, 993205880778002 },+    { 654925550560074, 1168810995576858, 575655959430926, 905758704861388, 496774564663534 },+    { 1954109525779738, 2117022646152485, 338102630417180, 1194140505732026, 107881734943492 }+  },+  {+    { 1714785840001267, 2036500018681589, 1876380234251966, 2056717182974196, 1645855254384642 },+    { 106431476499341, 62482972120563, 1513446655109411, 807258751769522, 538491469114 },+    { 2002850762893643, 1243624520538135, 1486040410574605, 2184752338181213, 378495998083531 }+  },+  {+    { 922510868424903, 1089502620807680, 402544072617374, 1131446598479839, 1290278588136533 },+    { 1867998812076769, 715425053580701, 39968586461416, 2173068014586163, 653822651801304 },+    { 162892278589453, 182585796682149, 75093073137630, 497037941226502, 133871727117371 }+  },+  {+    { 1914596576579670, 1608999621851578, 1987629837704609, 1519655314857977, 1819193753409464 },+    { 1949315551096831, 1069003344994464, 1939165033499916, 1548227205730856, 1933767655861407 },+    { 1730519386931635, 1393284965610134, 1597143735726030, 416032382447158, 1429665248828629 }+  },+  {+    { 360275475604565, 547835731063078, 215360904187529, 596646739879007, 332709650425085 },+    { 47602113726801, 1522314509708010, 437706261372925, 814035330438027, 335930650933545 },+    { 1291597595523886, 1058020588994081, 402837842324045, 1363323695882781, 2105763393033193 }+  }+},+{ /* 12/31 */+  {+    { 109521982566564, 1715257748585139, 1112231216891516, 2046641005101484, 134249157157013 },+    { 2156991030936798, 2227544497153325, 1869050094431622, 754875860479115, 1754242344267058 },+    { 1846089562873800, 98894784984326, 1412430299204844, 171351226625762, 1100604760929008 }+  },+  {+    { 84172382130492, 499710970700046, 425749630620778, 1762872794206857, 612842602127960 },+    { 868309334532756, 1703010512741873, 1952690008738057, 4325269926064, 2071083554962116 },+    { 523094549451158, 401938899487815, 1407690589076010, 2022387426254453, 158660516411257 }+  },+  {+    { 612867287630009, 448212612103814, 571629077419196, 1466796750919376, 1728478129663858 },+    { 1723848973783452, 2208822520534681, 1718748322776940, 1974268454121942, 1194212502258141 },+    { 1254114807944608, 977770684047110, 2010756238954993, 1783628927194099, 1525962994408256 }+  },+  {+    { 232464058235826, 1948628555342434, 1835348780427694, 1031609499437291, 64472106918373 },+    { 767338676040683, 754089548318405, 1523192045639075, 435746025122062, 512692508440385 },+    { 1255955808701983, 1700487367990941, 1166401238800299, 1175121994891534, 1190934801395380 }+  },+  {+    { 349144008168292, 1337012557669162, 1475912332999108, 1321618454900458, 47611291904320 },+    { 877519947135419, 2172838026132651, 272304391224129, 1655143327559984, 886229406429814 },+    { 375806028254706, 214463229793940, 572906353144089, 572168269875638, 697556386112979 }+  },+  {+    { 1168827102357844, 823864273033637, 2071538752104697, 788062026895924, 599578340743362 },+    { 1948116082078088, 2054898304487796, 2204939184983900, 210526805152138, 786593586607626 },+    { 1915320147894736, 156481169009469, 655050471180417, 592917090415421, 2165897438660879 }+  },+  {+    { 1726336468579724, 1119932070398949, 1929199510967666, 33918788322959, 1836837863503150 },+    { 829996854845988, 217061778005138, 1686565909803640, 1346948817219846, 1723823550730181 },+    { 384301494966394, 687038900403062, 2211195391021739, 254684538421383, 1245698430589680 }+  },+  {+    { 1247567493562688, 1978182094455847, 183871474792955, 806570235643435, 288461518067916 },+    { 1449077384734201, 38285445457996, 2136537659177832, 2146493000841573, 725161151123125 },+    { 1201928866368855, 800415690605445, 1703146756828343, 997278587541744, 1858284414104014 }+  }+},+{ /* 13/31 */+  {+    { 356468809648877, 782373916933152, 1718002439402870, 1392222252219254, 663171266061951 },+    { 759628738230460, 1012693474275852, 353780233086498, 246080061387552, 2030378857679162 },+    { 2040672435071076, 888593182036908, 1298443657189359, 1804780278521327, 354070726137060 }+  },+  {+    { 1894938527423184, 1463213041477277, 474410505497651, 247294963033299, 877975941029128 },+    { 207937160991127, 12966911039119, 820997788283092, 1010440472205286, 1701372890140810 },+    { 218882774543183, 533427444716285, 1233243976733245, 435054256891319, 1509568989549904 }+  },+  {+    { 1888838535711826, 1052177758340622, 1213553803324135, 169182009127332, 463374268115872 },+    { 299137589460312, 1594371588983567, 868058494039073, 257771590636681, 1805012993142921 },+    { 1806842755664364, 2098896946025095, 1356630998422878, 1458279806348064, 347755825962072 }+  },+  {+    { 1402334161391744, 1560083671046299, 1008585416617747, 1147797150908892, 1420416683642459 },+    { 665506704253369, 273770475169863, 799236974202630, 848328990077558, 1811448782807931 },+    { 1468412523962641, 771866649897997, 1931766110147832, 799561180078482, 524837559150077 }+  },+  {+    { 2223212657821850, 630416247363666, 2144451165500328, 816911130947791, 1024351058410032 },+    { 1266603897524861, 156378408858100, 1275649024228779, 447738405888420, 253186462063095 },+    { 2022215964509735, 136144366993649, 1800716593296582, 1193970603800203, 871675847064218 }+  },+  {+    { 1862751661970328, 851596246739884, 1519315554814041, 1542798466547449, 1417975335901520 },+    { 1228168094547481, 334133883362894, 587567568420081, 433612590281181, 603390400373205 },+    { 121893973206505, 1843345804916664, 1703118377384911, 497810164760654, 101150811654673 }+  },+  {+    { 458346255946468, 290909935619344, 1452768413850679, 550922875254215, 1537286854336538 },+    { 584322311184395, 380661238802118, 114839394528060, 655082270500073, 2111856026034852 },+    { 996965581008991, 2148998626477022, 1012273164934654, 1073876063914522, 1688031788934939 }+  },+  {+    { 923487018849600, 2085106799623355, 528082801620136, 1606206360876188, 735907091712524 },+    { 1697697887804317, 1335343703828273, 831288615207040, 949416685250051, 288760277392022 },+    { 1419122478109648, 1325574567803701, 602393874111094, 2107893372601700, 1314159682671307 }+  }+},+{ /* 14/31 */+  {+    { 2201150872731804, 2180241023425241, 97663456423163, 1633405770247824, 848945042443986 },+    { 1173339555550611, 818605084277583, 47521504364289, 924108720564965, 735423405754506 },+    { 830104860549448, 1886653193241086, 1600929509383773, 1475051275443631, 286679780900937 }+  },+  {+    { 1577111294832995, 1030899169768747, 144900916293530, 1964672592979567, 568390100955250 },+    { 278388655910247, 487143369099838, 927762205508727, 181017540174210, 1616886700741287 },+    { 1191033906638969, 940823957346562, 1606870843663445, 861684761499847, 658674867251089 }+  },+  {+    { 1875032594195546, 1427106132796197, 724736390962158, 901860512044740, 635268497268760 },+    { 622869792298357, 1903919278950367, 1922588621661629, 1520574711600434, 1087100760174640 },+    { 25465949416618, 1693639527318811, 1526153382657203, 125943137857169, 145276964043999 }+  },+  {+    { 214739857969358, 920212862967915, 1939901550972269, 1211862791775221, 85097515720120 },+    { 2006245852772938, 734762734836159, 254642929763427, 1406213292755966, 239303749517686 },+    { 1619678837192149, 1919424032779215, 1357391272956794, 1525634040073113, 1310226789796241 }+  },+  {+    { 1040763709762123, 1704449869235352, 605263070456329, 1998838089036355, 1312142911487502 },+    { 1996723311435669, 1844342766567060, 985455700466044, 1165924681400960, 311508689870129 },+    { 43173156290518, 2202883069785309, 1137787467085917, 1733636061944606, 1394992037553852 }+  },+  {+    { 670078326344559, 555655025059356, 471959386282438, 2141455487356409, 849015953823125 },+    { 2197214573372804, 794254097241315, 1030190060513737, 267632515541902, 2040478049202624 },+    { 1812516004670529, 1609256702920783, 1706897079364493, 258549904773295, 996051247540686 }+  },+  {+    { 1540374301420584, 1764656898914615, 1810104162020396, 923808779163088, 664390074196579 },+    { 1323460699404750, 1262690757880991, 871777133477900, 1060078894988977, 1712236889662886 },+    { 1696163952057966, 1391710137550823, 608793846867416, 1034391509472039, 1780770894075012 }+  },+  {+    { 1367603834210841, 2131988646583224, 890353773628144, 1908908219165595, 270836895252891 },+    { 597536315471731, 40375058742586, 1942256403956049, 1185484645495932, 312666282024145 },+    { 1919411405316294, 1234508526402192, 1066863051997083, 1008444703737597, 1348810787701552 }+  }+},+{ /* 15/31 */+  {+    { 2102881477513865, 1570274565945361, 1573617900503708, 18662635732583, 2232324307922098 },+    { 1853931367696942, 8107973870707, 350214504129299, 775206934582587, 1752317649166792 },+    { 1417148368003523, 721357181628282, 505725498207811, 373232277872983, 261634707184480 }+  },+  {+    { 2186733281493267, 2250694917008620, 1014829812957440, 479998161452389, 83566193876474 },+    { 1268116367301224, 560157088142809, 802626839600444, 2210189936605713, 1129993785579988 },+    { 615183387352312, 917611676109240, 878893615973325, 978940963313282, 938686890583575 }+  },+  {+    { 522024729211672, 1045059315315808, 1892245413707790, 1907891107684253, 2059998109500714 },+    { 1799679152208884, 912132775900387, 25967768040979, 432130448590461, 274568990261996 },+    { 98698809797682, 2144627600856209, 1907959298569602, 811491302610148, 1262481774981493 }+  },+  {+    { 1791451399743152, 1713538728337276, 118349997257490, 1882306388849954, 158235232210248 },+    { 1217809823321928, 2173947284933160, 1986927836272325, 1388114931125539, 12686131160169 },+    { 1650875518872272, 1136263858253897, 1732115601395988, 734312880662190, 1252904681142109 }+  },+  {+    { 372986456113865, 525430915458171, 2116279931702135, 501422713587815, 1907002872974925 },+    { 803147181835288, 868941437997146, 316299302989663, 943495589630550, 571224287904572 },+    { 227742695588364, 1776969298667369, 628602552821802, 457210915378118, 2041906378111140 }+  },+  {+    { 815000523470260, 913085688728307, 1052060118271173, 1345536665214223, 541623413135555 },+    { 1580216071604333, 1877997504342444, 857147161260913, 703522726778478, 2182763974211603 },+    { 1870080310923419, 71988220958492, 1783225432016732, 615915287105016, 1035570475990230 }+  },+  {+    { 730987750830150, 857613889540280, 1083813157271766, 1002817255970169, 1719228484436074 },+    { 377616581647602, 1581980403078513, 804044118130621, 2034382823044191, 643844048472185 },+    { 176957326463017, 1573744060478586, 528642225008045, 1816109618372371, 1515140189765006 }+  },+  {+    { 1888911448245718, 1387110895611080, 1924503794066429, 1731539523700949, 2230378382645454 },+    { 443392177002051, 233793396845137, 2199506622312416, 1011858706515937, 974676837063129 },+    { 1846351103143623, 1949984838808427, 671247021915253, 1946756846184401, 1929296930380217 }+  }+},+{ /* 16/31 */+  {+    { 849646212452002, 1410198775302919, 73767886183695, 1641663456615812, 762256272452411 },+    { 692017667358279, 723305578826727, 1638042139863265, 748219305990306, 334589200523901 },+    { 22893968530686, 2235758574399251, 1661465835630252, 925707319443452, 1203475116966621 }+  },+  {+    { 801299035785166, 1733292596726131, 1664508947088596, 467749120991922, 1647498584535623 },+    { 903105258014366, 427141894933047, 561187017169777, 1884330244401954, 1914145708422219 },+    { 1344191060517578, 1960935031767890, 1518838929955259, 1781502350597190, 1564784025565682 }+  },+  {+    { 673723351748086, 1979969272514923, 1175287312495508, 1187589090978666, 1881897672213940 },+    { 1917185587363432, 1098342571752737, 5935801044414, 2000527662351839, 1538640296181569 },+    { 2495540013192, 678856913479236, 224998292422872, 219635787698590, 1972465269000940 }+  },+  {+    { 271413961212179, 1353052061471651, 344711291283483, 2014925838520662, 2006221033113941 },+    { 194583029968109, 514316781467765, 829677956235672, 1676415686873082, 810104584395840 },+    { 1980510813313589, 1948645276483975, 152063780665900, 129968026417582, 256984195613935 }+  },+  {+    { 1860190562533102, 1936576191345085, 461100292705964, 1811043097042830, 957486749306835 },+    { 796664815624365, 1543160838872951, 1500897791837765, 1667315977988401, 599303877030711 },+    { 1151480509533204, 2136010406720455, 738796060240027, 319298003765044, 1150614464349587 }+  },+  {+    { 1731069268103150, 735642447616087, 1364750481334268, 417232839982871, 927108269127661 },+    { 1017222050227968, 1987716148359, 2234319589635701, 621282683093392, 2132553131763026 },+    { 1567828528453324, 1017807205202360, 565295260895298, 829541698429100, 307243822276582 }+  },+  {+    { 249079270936248, 1501514259790706, 947909724204848, 944551802437487, 552658763982480 },+    { 2089966982947227, 1854140343916181, 2151980759220007, 2139781292261749, 158070445864917 },+    { 1338766321464554, 1906702607371284, 1519569445519894, 115384726262267, 1393058953390992 }+  },+  {+    { 1364621558265400, 1512388234908357, 1926731583198686, 2041482526432505, 920401122333774 },+    { 1884844597333588, 601480070269079, 620203503079537, 1079527400117915, 1202076693132015 },+    { 840922919763324, 727955812569642, 1303406629750194, 522898432152867, 294161410441865 }+  }+},+{ /* 17/31 */+  {+    { 353760790835310, 1598361541848743, 1122905698202299, 1922533590158905, 419107700666580 },+    { 359856369838236, 180914355488683, 861726472646627, 218807937262986, 575626773232501 },+    { 755467689082474, 909202735047934, 730078068932500, 936309075711518, 2007798262842972 }+  },+  {+    { 1609384177904073, 362745185608627, 1335318541768201, 800965770436248, 547877979267412 },+    { 984339177776787, 815727786505884, 1645154585713747, 1659074964378553, 1686601651984156 },+    { 1697863093781930, 599794399429786, 1104556219769607, 830560774794755, 12812858601017 }+  },+  {+    { 1168737550514982, 897832437380552, 463140296333799, 302564600022547, 2008360505135501 },+    { 1856930662813910, 678090852002597, 1920179140755167, 1259527833759868, 55540971895511 },+    { 1158643631044921, 476554103621892, 178447851439725, 1305025542653569, 103433927680625 }+  },+  {+    { 2176793111709008, 1576725716350391, 2009350167273523, 2012390194631546, 2125297410909580 },+    { 825403285195098, 2144208587560784, 1925552004644643, 1915177840006985, 1015952128947864 },+    { 1807108316634472, 1534392066433717, 347342975407218, 1153820745616376, 7375003497471 }+  },+  {+    { 983061001799725, 431211889901241, 2201903782961093, 817393911064341, 2214616493042167 },+    { 228567918409756, 865093958780220, 358083886450556, 159617889659320, 1360637926292598 },+    { 234147501399755, 2229469128637390, 2175289352258889, 1397401514549353, 1885288963089922 }+  },+  {+    { 1111762412951562, 252849572507389, 1048714233823341, 146111095601446, 1237505378776770 },+    { 1113790697840279, 1051167139966244, 1045930658550944, 2011366241542643, 1686166824620755 },+    { 1054097349305049, 1872495070333352, 182121071220717, 1064378906787311, 100273572924182 }+  },+  {+    { 1306410853171605, 1627717417672447, 50983221088417, 1109249951172250, 870201789081392 },+    { 104233794644221, 1548919791188248, 2224541913267306, 2054909377116478, 1043803389015153 },+    { 216762189468802, 707284285441622, 190678557969733, 973969342604308, 1403009538434867 }+  },+  {+    { 1279024291038477, 344776835218310, 273722096017199, 1834200436811442, 634517197663804 },+    { 343805853118335, 1302216857414201, 566872543223541, 2051138939539004, 321428858384280 },+    { 470067171324852, 1618629234173951, 2000092177515639, 7307679772789, 1117521120249968 }+  }+},+{ /* 18/31 */+  {+    { 278151578291475, 1810282338562947, 1771599529530998, 1383659409671631, 685373414471841 },+    { 577009397403102, 1791440261786291, 2177643735971638, 174546149911960, 1412505077782326 },+    { 893719721537457, 1201282458018197, 1522349501711173, 58011597740583, 1130406465887139 }+  },+  {+    { 412607348255453, 1280455764199780, 2233277987330768, 14180080401665, 331584698417165 },+    { 262483770854550, 990511055108216, 526885552771698, 571664396646158, 354086190278723 },+    { 1820352417585487, 24495617171480, 1547899057533253, 10041836186225, 480457105094042 }+  },+  {+    { 2023310314989233, 637905337525881, 2106474638900687, 557820711084072, 1687858215057826 },+    { 1144168702609745, 604444390410187, 1544541121756138, 1925315550126027, 626401428894002 },+    { 1922168257351784, 2018674099908659, 1776454117494445, 956539191509034, 36031129147635 }+  },+  {+    { 544644538748041, 1039872944430374, 876750409130610, 710657711326551, 1216952687484972 },+    { 58242421545916, 2035812695641843, 2118491866122923, 1191684463816273, 46921517454099 },+    { 272268252444639, 1374166457774292, 2230115177009552, 1053149803909880, 1354288411641016 }+  },+  {+    { 1857910905368338, 1754729879288912, 885945464109877, 1516096106802166, 1602902393369811 },+    { 1193437069800958, 901107149704790, 999672920611411, 477584824802207, 364239578697845 },+    { 886299989548838, 1538292895758047, 1590564179491896, 1944527126709657, 837344427345298 }+  },+  {+    { 754558365378305, 1712186480903618, 1703656826337531, 750310918489786, 518996040250900 },+    { 1309847803895382, 1462151862813074, 211370866671570, 1544595152703681, 1027691798954090 },+    { 803217563745370, 1884799722343599, 1357706345069218, 2244955901722095, 730869460037413 }+  },+  {+    { 689299471295966, 1831210565161071, 1375187341585438, 1106284977546171, 1893781834054269 },+    { 696351368613042, 1494385251239250, 738037133616932, 636385507851544, 927483222611406 },+    { 1949114198209333, 1104419699537997, 783495707664463, 1747473107602770, 2002634765788641 }+  },+  {+    { 1607325776830197, 530883941415333, 1451089452727895, 1581691157083423, 496100432831154 },+    { 1068900648804224, 2006891997072550, 1134049269345549, 1638760646180091, 2055396084625778 },+    { 2222475519314561, 1870703901472013, 1884051508440561, 1344072275216753, 1318025677799069 }+  }+},+{ /* 19/31 */+  {+    { 155711679280656, 681100400509288, 389811735211209, 2135723811340709, 408733211204125 },+    { 7813206966729, 194444201427550, 2071405409526507, 1065605076176312, 1645486789731291 },+    { 16625790644959, 1647648827778410, 1579910185572704, 436452271048548, 121070048451050 }+  },+  {+    { 1037263028552531, 568385780377829, 297953104144430, 1558584511931211, 2238221839292471 },+    { 190565267697443, 672855706028058, 338796554369226, 337687268493904, 853246848691734 },+    { 1763863028400139, 766498079432444, 1321118624818005, 69494294452268, 858786744165651 }+  },+  {+    { 1292056768563024, 1456632109855638, 1100631247050184, 1386133165675321, 1232898350193752 },+    { 366253102478259, 525676242508811, 1449610995265438, 1183300845322183, 185960306491545 },+    { 28315355815982, 460422265558930, 1799675876678724, 1969256312504498, 1051823843138725 }+  },+  {+    { 156914999361983, 1606148405719949, 1665208410108430, 317643278692271, 1383783705665320 },+    { 54684536365732, 2210010038536222, 1194984798155308, 535239027773705, 1516355079301361 },+    { 1484387703771650, 198537510937949, 2186282186359116, 617687444857508, 647477376402122 }+  },+  {+    { 2147715541830533, 500032538445817, 646380016884826, 352227855331122, 1488268620408052 },+    { 159386186465542, 1877626593362941, 618737197060512, 1026674284330807, 1158121760792685 },+    { 1744544377739822, 1964054180355661, 1685781755873170, 2169740670377448, 1286112621104591 }+  },+  {+    { 81977249784993, 1667943117713086, 1668983819634866, 1605016835177615, 1353960708075544 },+    { 1602253788689063, 439542044889886, 2220348297664483, 657877410752869, 157451572512238 },+    { 1029287186166717, 65860128430192, 525298368814832, 1491902500801986, 1461064796385400 }+  },+  {+    { 408216988729246, 2121095722306989, 913562102267595, 1879708920318308, 241061448436731 },+    { 1185483484383269, 1356339572588553, 584932367316448, 102132779946470, 1792922621116791 },+    { 1966196870701923, 2230044620318636, 1425982460745905, 261167817826569, 46517743394330 }+  },+  {+    { 107077591595359, 884959942172345, 27306869797400, 2224911448949390, 964352058245223 },+    { 1730194207717538, 431790042319772, 1831515233279467, 1372080552768581, 1074513929381760 },+    { 1450880638731607, 1019861580989005, 1229729455116861, 1174945729836143, 826083146840706 }+  }+},+{ /* 20/31 */+  {+    { 1899935429242705, 1602068751520477, 940583196550370, 82431069053859, 1540863155745696 },+    { 2136688454840028, 2099509000964294, 1690800495246475, 1217643678575476, 828720645084218 },+    { 765548025667841, 462473984016099, 998061409979798, 546353034089527, 2212508972466858 }+  },+  {+    { 46575283771160, 892570971573071, 1281983193144090, 1491520128287375, 75847005908304 },+    { 1801436127943107, 1734436817907890, 1268728090345068, 167003097070711, 2233597765834956 },+    { 1997562060465113, 1048700225534011, 7615603985628, 1855310849546841, 2242557647635213 }+  },+  {+    { 1161017320376250, 492624580169043, 2169815802355237, 976496781732542, 1770879511019629 },+    { 1357044908364776, 729130645262438, 1762469072918979, 1365633616878458, 181282906404941 },+    { 1080413443139865, 1155205815510486, 1848782073549786, 622566975152580, 124965574467971 }+  },+  {+    { 1184526762066993, 247622751762817, 692129017206356, 820018689412496, 2188697339828085 },+    { 2020536369003019, 202261491735136, 1053169669150884, 2056531979272544, 778165514694311 },+    { 237404399610207, 1308324858405118, 1229680749538400, 720131409105291, 1958958863624906 }+  },+  {+    { 515583508038846, 17656978857189, 1717918437373989, 1568052070792483, 46975803123923 },+    { 281527309158085, 36970532401524, 866906920877543, 2222282602952734, 1289598729589882 },+    { 1278207464902042, 494742455008756, 1262082121427081, 1577236621659884, 1888786707293291 }+  },+  {+    { 353042527954210, 1830056151907359, 1111731275799225, 174960955838824, 404312815582675 },+    { 2064251142068628, 1666421603389706, 1419271365315441, 468767774902855, 191535130366583 },+    { 1716987058588002, 1859366439773457, 1767194234188234, 64476199777924, 1117233614485261 }+  },+  {+    { 984292135520292, 135138246951259, 2220652137473167, 1722843421165029, 190482558012909 },+    { 298845952651262, 1166086588952562, 1179896526238434, 1347812759398693, 1412945390096208 },+    { 1143239552672925, 906436640714209, 2177000572812152, 2075299936108548, 325186347798433 }+  },+  {+    { 721024854374772, 684487861263316, 1373438744094159, 2193186935276995, 1387043709851261 },+    { 418098668140962, 715065997721283, 1471916138376055, 2168570337288357, 937812682637044 },+    { 1043584187226485, 2143395746619356, 2209558562919611, 482427979307092, 847556718384018 }+  }+},+{ /* 21/31 */+  {+    { 1248731221520759, 1465200936117687, 540803492710140, 52978634680892, 261434490176109 },+    { 1057329623869501, 620334067429122, 461700859268034, 2012481616501857, 297268569108938 },+    { 1055352180870759, 1553151421852298, 1510903185371259, 1470458349428097, 1226259419062731 }+  },+  {+    { 1492988790301668, 790326625573331, 1190107028409745, 1389394752159193, 1620408196604194 },+    { 47000654413729, 1004754424173864, 1868044813557703, 173236934059409, 588771199737015 },+    { 30498470091663, 1082245510489825, 576771653181956, 806509986132686, 1317634017056939 }+  },+  {+    { 420308055751555, 1493354863316002, 165206721528088, 1884845694919786, 2065456951573059 },+    { 1115636332012334, 1854340990964155, 83792697369514, 1972177451994021, 457455116057587 },+    { 1698968457310898, 1435137169051090, 1083661677032510, 938363267483709, 340103887207182 }+  },+  {+    { 1995325341336574, 911500251774648, 164010755403692, 855378419194762, 1573601397528842 },+    { 241719380661528, 310028521317150, 1215881323380194, 1408214976493624, 2141142156467363 },+    { 1315157046163473, 727368447885818, 1363466668108618, 1668921439990361, 1398483384337907 }+  },+  {+    { 75029678299646, 1015388206460473, 1849729037055212, 1939814616452984, 444404230394954 },+    { 2053597130993710, 2024431685856332, 2233550957004860, 2012407275509545, 872546993104440 },+    { 1217269667678610, 599909351968693, 1390077048548598, 1471879360694802, 739586172317596 }+  },+  {+    { 1718318639380794, 1560510726633958, 904462881159922, 1418028351780052, 94404349451937 },+    { 2132502667405250, 214379346175414, 1502748313768060, 1960071701057800, 1353971822643138 },+    { 319394212043702, 2127459436033571, 717646691535162, 663366796076914, 318459064945314 }+  },+  {+    { 405989424923593, 1960452633787083, 667349034401665, 1492674260767112, 1451061489880787 },+    { 947085906234007, 323284730494107, 1485778563977200, 728576821512394, 901584347702286 },+    { 1575783124125742, 2126210792434375, 1569430791264065, 1402582372904727, 1891780248341114 }+  },+  {+    { 838432205560695, 1997703511451664, 1018791879907867, 1662001808174331, 78328132957753 },+    { 739152638255629, 2074935399403557, 505483666745895, 1611883356514088, 628654635394878 },+    { 1822054032121349, 643057948186973, 7306757352712, 577249257962099, 284735863382083 }+  }+},+{ /* 22/31 */+  {+    { 1366558556363930, 1448606567552086, 1478881020944768, 165803179355898, 1115718458123498 },+    { 204146226972102, 1630511199034723, 2215235214174763, 174665910283542, 956127674017216 },+    { 1562934578796716, 1070893489712745, 11324610642270, 958989751581897, 2172552325473805 }+  },+  {+    { 1770564423056027, 735523631664565, 1326060113795289, 1509650369341127, 65892421582684 },+    { 623682558650637, 1337866509471512, 990313350206649, 1314236615762469, 1164772974270275 },+    { 223256821462517, 723690150104139, 1000261663630601, 933280913953265, 254872671543046 }+  },+  {+    { 1969087237026041, 624795725447124, 1335555107635969, 2069986355593023, 1712100149341902 },+    { 1236103475266979, 1837885883267218, 1026072585230455, 1025865513954973, 1801964901432134 },+    { 1115241013365517, 1712251818829143, 2148864332502771, 2096001471438138, 2235017246626125 }+  },+  {+    { 1299268198601632, 2047148477845621, 2165648650132450, 1612539282026145, 514197911628890 },+    { 118352772338543, 1067608711804704, 1434796676193498, 1683240170548391, 230866769907437 },+    { 1850689576796636, 1601590730430274, 1139674615958142, 1954384401440257, 76039205311 }+  },+  {+    { 1723387471374172, 997301467038410, 533927635123657, 20928644693965, 1756575222802513 },+    { 2146711623855116, 503278928021499, 625853062251406, 1109121378393107, 1033853809911861 },+    { 571005965509422, 2005213373292546, 1016697270349626, 56607856974274, 914438579435146 }+  },+  {+    { 1346698876211176, 2076651707527589, 1084761571110205, 265334478828406, 1068954492309671 },+    { 1769967932677654, 1695893319756416, 1151863389675920, 1781042784397689, 400287774418285 },+    { 1851867764003121, 403841933237558, 820549523771987, 761292590207581, 1743735048551143 }+  },+  {+    { 410915148140008, 2107072311871739, 1004367461876503, 99684895396761, 1180818713503224 },+    { 285945406881439, 648174397347453, 1098403762631981, 1366547441102991, 1505876883139217 },+    { 672095903120153, 1675918957959872, 636236529315028, 1569297300327696, 2164144194785875 }+  },+  {+    { 1902708175321798, 1035343530915438, 1178560808893263, 301095684058146, 1280977479761118 },+    { 1615357281742403, 404257611616381, 2160201349780978, 1160947379188955, 1578038619549541 },+    { 2013087639791217, 822734930507457, 1785668418619014, 1668650702946164, 389450875221715 }+  }+},+{ /* 23/31 */+  {+    { 453918449698368, 106406819929001, 2072540975937135, 308588860670238, 1304394580755385 },+    { 1295082798350326, 2091844511495996, 1851348972587817, 3375039684596, 789440738712837 },+    { 2083069137186154, 848523102004566, 993982213589257, 1405313299916317, 1532824818698468 }+  },+  {+    { 1495961298852430, 1397203457344779, 1774950217066942, 139302743555696, 66603584342787 },+    { 1782411379088302, 1096724939964781, 27593390721418, 542241850291353, 1540337798439873 },+    { 693543956581437, 171507720360750, 1557908942697227, 1074697073443438, 1104093109037196 }+  },+  {+    { 345288228393419, 1099643569747172, 134881908403743, 1740551994106740, 248212179299770 },+    { 231429562203065, 1526290236421172, 2021375064026423, 1520954495658041, 806337791525116 },+    { 1079623667189886, 872403650198613, 766894200588288, 2163700860774109, 2023464507911816 }+  },+  {+    { 854645372543796, 1936406001954827, 151460662541253, 825325739271555, 1554306377287556 },+    { 1497138821904622, 1044820250515590, 1742593886423484, 1237204112746837, 849047450816987 },+    { 667962773375330, 1897271816877105, 1399712621683474, 1143302161683099, 2081798441209593 }+  },+  {+    { 127147851567005, 1936114012888110, 1704424366552046, 856674880716312, 716603621335359 },+    { 1072409664800960, 2146937497077528, 1508780108920651, 935767602384853, 1112800433544068 },+    { 333549023751292, 280219272863308, 2104176666454852, 1036466864875785, 536135186520207 }+  },+  {+    { 373666279883137, 146457241530109, 304116267127857, 416088749147715, 1258577131183391 },+    { 1186115062588401, 2251609796968486, 1098944457878953, 1153112761201374, 1791625503417267 },+    { 1870078460219737, 2129630962183380, 852283639691142, 292865602592851, 401904317342226 }+  },+  {+    { 1361070124828035, 815664541425524, 1026798897364671, 1951790935390647, 555874891834790 },+    { 1546301003424277, 459094500062839, 1097668518375311, 1780297770129643, 720763293687608 },+    { 1212405311403990, 1536693382542438, 61028431067459, 1863929423417129, 1223219538638038 }+  },+  {+    { 1294303766540260, 1183557465955093, 882271357233093, 63854569425375, 2213283684565087 },+    { 339050984211414, 601386726509773, 413735232134068, 966191255137228, 1839475899458159 },+    { 235605972169408, 2174055643032978, 1538335001838863, 1281866796917192, 1815940222628465 }+  }+},+{ /* 24/31 */+  {+    { 1632352921721536, 1833328609514701, 2092779091951987, 1923956201873226, 2210068022482919 },+    { 35271216625062, 1712350667021807, 983664255668860, 98571260373038, 1232645608559836 },+    { 1998172393429622, 1798947921427073, 784387737563581, 1589352214827263, 1589861734168180 }+  },+  {+    { 1733739258725305, 31715717059538, 201969945218860, 992093044556990, 1194308773174556 },+    { 846415389605137, 746163495539180, 829658752826080, 592067705956946, 957242537821393 },+    { 1758148849754419, 619249044817679, 168089007997045, 1371497636330523, 1867101418880350 }+  },+  {+    { 326633984209635, 261759506071016, 1700682323676193, 1577907266349064, 1217647663383016 },+    { 1714182387328607, 1477856482074168, 574895689942184, 2159118410227270, 1555532449716575 },+    { 853828206885131, 998498946036955, 1835887550391235, 207627336608048, 258363815956050 }+  },+  {+    { 141141474651677, 1236728744905256, 643101419899887, 1646615130509173, 1208239602291765 },+    { 1501663228068911, 1354879465566912, 1444432675498247, 897812463852601, 855062598754348 },+    { 714380763546606, 1032824444965790, 1774073483745338, 1063840874947367, 1738680636537158 }+  },+  {+    { 1640635546696252, 633168953192112, 2212651044092396, 30590958583852, 368515260889378 },+    { 1171650314802029, 1567085444565577, 1453660792008405, 757914533009261, 1619511342778196 },+    { 420958967093237, 971103481109486, 2169549185607107, 1301191633558497, 1661514101014240 }+  },+  {+    { 907123651818302, 1332556122804146, 1824055253424487, 1367614217442959, 1982558335973172 },+    { 1121533090144639, 1021251337022187, 110469995947421, 1511059774758394, 2110035908131662 },+    { 303213233384524, 2061932261128138, 352862124777736, 40828818670255, 249879468482660 }+  },+  {+    { 856559257852200, 508517664949010, 1378193767894916, 1723459126947129, 1962275756614521 },+    { 1445691340537320, 40614383122127, 402104303144865, 485134269878232, 1659439323587426 },+    { 20057458979482, 1183363722525800, 2140003847237215, 2053873950687614, 2112017736174909 }+  },+  {+    { 2228654250927986, 1483591363415267, 1368661293910956, 1076511285177291, 526650682059608 },+    { 709481497028540, 531682216165724, 316963769431931, 1814315888453765, 258560242424104 },+    { 1053447823660455, 1955135194248683, 1010900954918985, 1182614026976701, 1240051576966610 }+  }+},+{ /* 25/31 */+  {+    { 1957943897155497, 1788667368028035, 137692910029106, 1039519607062, 826404763313028 },+    { 1848942433095597, 1582009882530495, 1849292741020143, 1068498323302788, 2001402229799484 },+    { 1528282417624269, 2142492439828191, 2179662545816034, 362568973150328, 1591374675250271 }+  },+  {+    { 160026679434388, 232341189218716, 2149181472355545, 598041771119831, 183859001910173 },+    { 2013278155187349, 662660471354454, 793981225706267, 411706605985744, 804490933124791 },+    { 2051892037280204, 488391251096321, 2230187337030708, 930221970662692, 679002758255210 }+  },+  {+    { 1530723630438670, 875873929577927, 341560134269988, 449903119530753, 1055551308214179 },+    { 1461835919309432, 1955256480136428, 180866187813063, 1551979252664528, 557743861963950 },+    { 359179641731115, 1324915145732949, 902828372691474, 294254275669987, 1887036027752957 }+  },+  {+    { 2043271609454323, 2038225437857464, 1317528426475850, 1398989128982787, 2027639881006861 },+    { 2072902725256516, 312132452743412, 309930885642209, 996244312618453, 1590501300352303 },+    { 1397254305160710, 695734355138021, 2233992044438756, 1776180593969996, 1085588199351115 }+  },+  {+    { 440567051331029, 254894786356681, 493869224930222, 1556322069683366, 1567456540319218 },+    { 1950722461391320, 1907845598854797, 1822757481635527, 2121567704750244, 73811931471221 },+    { 387139307395758, 2058036430315676, 1220915649965325, 1794832055328951, 1230009312169328 }+  },+  {+    { 1765973779329517, 659344059446977, 19821901606666, 1301928341311214, 1116266004075885 },+    { 1127572801181483, 1224743760571696, 1276219889847274, 1529738721702581, 1589819666871853 },+    { 2181229378964934, 2190885205260020, 1511536077659137, 1246504208580490, 668883326494241 }+  },+  {+    { 437866655573314, 669026411194768, 81896997980338, 523874406393178, 245052060935236 },+    { 1975438052228868, 1071801519999806, 594652299224319, 1877697652668809, 1489635366987285 },+    { 958592545673770, 233048016518599, 851568750216589, 567703851596087, 1740300006094761 }+  },+  {+    { 2014540178270324, 192672779514432, 213877182641530, 2194819933853411, 1716422829364835 },+    { 1540769606609725, 2148289943846077, 1597804156127445, 1230603716683868, 815423458809453 },+    { 1738560251245018, 1779576754536888, 1783765347671392, 1880170990446751, 1088225159617541 }+  }+},+{ /* 26/31 */+  {+    { 659303913929492, 1956447718227573, 1830568515922666, 841069049744408, 1669607124206368 },+    { 1143465490433355, 1532194726196059, 1093276745494697, 481041706116088, 2121405433561163 },+    { 1686424298744462, 1451806974487153, 266296068846582, 1834686947542675, 1720762336132256 }+  },+  {+    { 889217026388959, 1043290623284660, 856125087551909, 1669272323124636, 1603340330827879 },+    { 1206396181488998, 333158148435054, 1402633492821422, 1120091191722026, 1945474114550509 },+    { 766720088232571, 1512222781191002, 1189719893490790, 2091302129467914, 2141418006894941 }+  },+  {+    { 419663647306612, 1998875112167987, 1426599870253707, 1154928355379510, 486538532138187 },+    { 938160078005954, 1421776319053174, 1941643234741774, 180002183320818, 1414380336750546 },+    { 398001940109652, 1577721237663248, 1012748649830402, 1540516006905144, 1011684812884559 }+  },+  {+    { 1653276489969630, 6081825167624, 1921777941170836, 1604139841794531, 861211053640641 },+    { 996661541407379, 1455877387952927, 744312806857277, 139213896196746, 1000282908547789 },+    { 1450817495603008, 1476865707053229, 1030490562252053, 620966950353376, 1744760161539058 }+  },+  {+    { 559728410002599, 37056661641185, 2038622963352006, 1637244893271723, 1026565352238948 },+    { 962165956135846, 1116599660248791, 182090178006815, 1455605467021751, 196053588803284 },+    { 796863823080135, 1897365583584155, 420466939481601, 2165972651724672, 932177357788289 }+  },+  {+    { 877047233620632, 1375632631944375, 643773611882121, 660022738847877, 19353932331831 },+    { 2216943882299338, 394841323190322, 2222656898319671, 558186553950529, 1077236877025190 },+    { 801118384953213, 1914330175515892, 574541023311511, 1471123787903705, 1526158900256288 }+  },+  {+    { 949617889087234, 2207116611267331, 912920039141287, 501158539198789, 62362560771472 },+    { 1474518386765335, 1760793622169197, 1157399790472736, 1622864308058898, 165428294422792 },+    { 1961673048027128, 102619413083113, 1051982726768458, 1603657989805485, 1941613251499678 }+  },+  {+    { 1401939116319266, 335306339903072, 72046196085786, 862423201496006, 850518754531384 },+    { 1234706593321979, 1083343891215917, 898273974314935, 1640859118399498, 157578398571149 },+    { 1143483057726416, 1992614991758919, 674268662140796, 1773370048077526, 674318359920189 }+  }+},+{ /* 27/31 */+  {+    { 1835401379538542, 173900035308392, 818247630716732, 1762100412152786, 1021506399448291 },+    { 1506632088156630, 2127481795522179, 513812919490255, 140643715928370, 442476620300318 },+    { 2056683376856736, 219094741662735, 2193541883188309, 1841182310235800, 556477468664293 }+  },+  {+    { 1315019427910827, 1049075855992603, 2066573052986543, 266904467185534, 2040482348591520 },+    { 94096246544434, 922482381166992, 24517828745563, 2139430508542503, 2097139044231004 },+    { 537697207950515, 1399352016347350, 1563663552106345, 2148749520888918, 549922092988516 }+  },+  {+    { 1747985413252434, 680511052635695, 1809559829982725, 594274250930054, 201673170745982 },+    { 323583936109569, 1973572998577657, 1192219029966558, 79354804385273, 1374043025560347 },+    { 213277331329947, 416202017849623, 1950535221091783, 1313441578103244, 2171386783823658 }+  },+  {+    { 189088804229831, 993969372859110, 895870121536987, 1547301535298256, 1477373024911350 },+    { 1620578418245010, 541035331188469, 2235785724453865, 2154865809088198, 1974627268751826 },+    { 1346805451740245, 1350981335690626, 942744349501813, 2155094562545502, 1012483751693409 }+  },+  {+    { 2107080134091762, 1132567062788208, 1824935377687210, 769194804343737, 1857941799971888 },+    { 1074666112436467, 249279386739593, 1174337926625354, 1559013532006480, 1472287775519121 },+    { 1872620123779532, 1892932666768992, 1921559078394978, 1270573311796160, 1438913646755037 }+  },+  {+    { 837390187648199, 1012253300223599, 989780015893987, 1351393287739814, 328627746545550 },+    { 1028328827183114, 1711043289969857, 1350832470374933, 1923164689604327, 1495656368846911 },+    { 1900828492104143, 430212361082163, 687437570852799, 832514536673512, 1685641495940794 }+  },+  {+    { 842632847936398, 605670026766216, 290836444839585, 163210774892356, 2213815011799645 },+    { 1176336383453996, 1725477294339771, 12700622672454, 678015708818208, 162724078519879 },+    { 1448049969043497, 1789411762943521, 385587766217753, 90201620913498, 832999441066823 }+  },+  {+    { 516086333293313, 2240508292484616, 1351669528166508, 1223255565316488, 750235824427138 },+    { 1263624896582495, 1102602401673328, 526302183714372, 2152015839128799, 1483839308490010 },+    { 442991718646863, 1599275157036458, 1925389027579192, 899514691371390, 350263251085160 }+  }+},+{ /* 28/31 */+  {+    { 1689713572022143, 593854559254373, 978095044791970, 1985127338729499, 1676069120347625 },+    { 1557207018622683, 340631692799603, 1477725909476187, 614735951619419, 2033237123746766 },+    { 968764929340557, 1225534776710944, 662967304013036, 1155521416178595, 791142883466590 }+  },+  {+    { 1487081286167458, 993039441814934, 1792378982844640, 698652444999874, 2153908693179754 },+    { 1123181311102823, 685575944875442, 507605465509927, 1412590462117473, 568017325228626 },+    { 560258797465417, 2193971151466401, 1824086900849026, 579056363542056, 1690063960036441 }+  },+  {+    { 1918407319222416, 353767553059963, 1930426334528099, 1564816146005724, 1861342381708096 },+    { 2131325168777276, 1176636658428908, 1756922641512981, 1390243617176012, 1966325177038383 },+    { 2063958120364491, 2140267332393533, 699896251574968, 273268351312140, 375580724713232 }+  },+  {+    { 2024297515263178, 416959329722687, 1079014235017302, 171612225573183, 1031677520051053 },+    { 2033900009388450, 1744902869870788, 2190580087917640, 1949474984254121, 231049754293748 },+    { 343868674606581, 550155864008088, 1450580864229630, 481603765195050, 896972360018042 }+  },+  {+    { 2151139328380127, 314745882084928, 59756825775204, 1676664391494651, 2048348075599360 },+    { 1528930066340597, 1605003907059576, 1055061081337675, 1458319101947665, 1234195845213142 },+    { 830430507734812, 1780282976102377, 1425386760709037, 362399353095425, 2168861579799910 }+  },+  {+    { 1155762232730333, 980662895504006, 2053766700883521, 490966214077606, 510405877041357 },+    { 1683750316716132, 652278688286128, 1221798761193539, 1897360681476669, 319658166027343 },+    { 618808732869972, 72755186759744, 2060379135624181, 1730731526741822, 48862757828238 }+  },+  {+    { 1463171970593505, 1143040711767452, 614590986558883, 1409210575145591, 1882816996436803 },+    { 2230133264691131, 563950955091024, 2042915975426398, 827314356293472, 672028980152815 },+    { 264204366029760, 1654686424479449, 2185050199932931, 2207056159091748, 506015669043634 }+  },+  {+    { 1784446333136569, 1973746527984364, 334856327359575, 1156769775884610, 1023950124675478 },+    { 2065270940578383, 31477096270353, 306421879113491, 181958643936686, 1907105536686083 },+    { 1496516440779464, 1748485652986458, 872778352227340, 818358834654919, 97932669284220 }+  }+},+{ /* 29/31 */+  {+    { 471636015770351, 672455402793577, 1804995246884103, 1842309243470804, 1501862504981682 },+    { 1013216974933691, 538921919682598, 1915776722521558, 1742822441583877, 1886550687916656 },+    { 2094270000643336, 303971879192276, 40801275554748, 649448917027930, 1818544418535447 }+  },+  {+    { 2241737709499165, 549397817447461, 838180519319392, 1725686958520781, 1705639080897747 },+    { 1216074541925116, 50120933933509, 1565829004133810, 721728156134580, 349206064666188 },+    { 948617110470858, 346222547451945, 1126511960599975, 1759386906004538, 493053284802266 }+  },+  {+    { 1454933046815146, 874696014266362, 1467170975468588, 1432316382418897, 2111710746366763 },+    { 2105387117364450, 1996463405126433, 1303008614294500, 851908115948209, 1353742049788635 },+    { 750300956351719, 1487736556065813, 15158817002104, 1511998221598392, 971739901354129 }+  },+  {+    { 1874648163531693, 2124487685930551, 1810030029384882, 918400043048335, 586348627300650 },+    { 1235084464747900, 1166111146432082, 1745394857881591, 1405516473883040, 4463504151617 },+    { 1663810156463827, 327797390285791, 1341846161759410, 1964121122800605, 1747470312055380 }+  },+  {+    { 660005247548233, 2071860029952887, 1358748199950107, 911703252219107, 1014379923023831 },+    { 2206641276178231, 1690587809721504, 1600173622825126, 2156096097634421, 1106822408548216 },+    { 1344788193552206, 1949552134239140, 1735915881729557, 675891104100469, 1834220014427292 }+  },+  {+    { 1920949492387964, 158885288387530, 70308263664033, 626038464897817, 1468081726101009 },+    { 622221042073383, 1210146474039168, 1742246422343683, 1403839361379025, 417189490895736 },+    { 22727256592983, 168471543384997, 1324340989803650, 1839310709638189, 504999476432775 }+  },+  {+    { 1313240518756327, 1721896294296942, 52263574587266, 2065069734239232, 804910473424630 },+    { 1337466662091884, 1287645354669772, 2018019646776184, 652181229374245, 898011753211715 },+    { 1969792547910734, 779969968247557, 2011350094423418, 1823964252907487, 1058949448296945 }+  },+  {+    { 207343737062002, 1118176942430253, 758894594548164, 806764629546266, 1157700123092949 },+    { 1273565321399022, 1638509681964574, 759235866488935, 666015124346707, 897983460943405 },+    { 1717263794012298, 1059601762860786, 1837819172257618, 1054130665797229, 680893204263559 }+  }+},+{ /* 30/31 */+  {+    { 2237039662793603, 2249022333361206, 2058613546633703, 149454094845279, 2215176649164582 },+    { 79472182719605, 1851130257050174, 1825744808933107, 821667333481068, 781795293511946 },+    { 755822026485370, 152464789723500, 1178207602290608, 410307889503239, 156581253571278 }+  },+  {+    { 1418185496130297, 484520167728613, 1646737281442950, 1401487684670265, 1349185550126961 },+    { 1495380034400429, 325049476417173, 46346894893933, 1553408840354856, 828980101835683 },+    { 1280337889310282, 2070832742866672, 1640940617225222, 2098284908289951, 450929509534434 }+  },+  {+    { 407703353998781, 126572141483652, 286039827513621, 1999255076709338, 2030511179441770 },+    { 1254958221100483, 1153235960999843, 942907704968834, 637105404087392, 1149293270147267 },+    { 894249020470196, 400291701616810, 406878712230981, 1599128793487393, 1145868722604026 }+  },+  {+    { 1497955250203334, 110116344653260, 1128535642171976, 1900106496009660, 129792717460909 },+    { 452487513298665, 1352120549024569, 1173495883910956, 1999111705922009, 367328130454226 },+    { 1717539401269642, 1475188995688487, 891921989653942, 836824441505699, 1885988485608364 }+  },+  {+    { 1241784121422547, 187337051947583, 1118481812236193, 428747751936362, 30358898927325 },+    { 2022432361201842, 1088816090685051, 1977843398539868, 1854834215890724, 564238862029357 },+    { 938868489100585, 1100285072929025, 1017806255688848, 1957262154788833, 152787950560442 }+  },+  {+    { 867319417678923, 620471962942542, 226032203305716, 342001443957629, 1761675818237336 },+    { 1295072362439987, 931227904689414, 1355731432641687, 922235735834035, 892227229410209 },+    { 1680989767906154, 535362787031440, 2136691276706570, 1942228485381244, 1267350086882274 }+  },+  {+    { 366018233770527, 432660629755596, 126409707644535, 1973842949591662, 645627343442376 },+    { 535509430575217, 546885533737322, 1524675609547799, 2138095752851703, 1260738089896827 },+    { 1159906385590467, 2198530004321610, 714559485023225, 81880727882151, 1484020820037082 }+  },+  {+    { 1377485731340769, 2046328105512000, 1802058637158797, 62146136768173, 1356993908853901 },+    { 2013612215646735, 1830770575920375, 536135310219832, 609272325580394, 270684344495013 },+    { 1237542585982777, 2228682050256790, 1385281931622824, 593183794882890, 493654978552689 }+  }+},+{ /* 31/31 */+  {+    { 47341488007760, 1891414891220257, 983894663308928, 176161768286818, 1126261115179708 },+    { 1694030170963455, 502038567066200, 1691160065225467, 949628319562187, 275110186693066 },+    { 1124515748676336, 1661673816593408, 1499640319059718, 1584929449166988, 558148594103306 }+  },+  {+    { 1784525599998356, 1619698033617383, 2097300287550715, 258265458103756, 1905684794832758 },+    { 1288941072872766, 931787902039402, 190731008859042, 2006859954667190, 1005931482221702 },+    { 1465551264822703, 152905080555927, 680334307368453, 173227184634745, 666407097159852 }+  },+  {+    { 2111017076203943, 1378760485794347, 1248583954016456, 1352289194864422, 1895180776543896 },+    { 171348223915638, 662766099800389, 462338943760497, 466917763340314, 656911292869115 },+    { 488623681976577, 866497561541722, 1708105560937768, 1673781214218839, 1506146329818807 }+  },+  {+    { 160425464456957, 950394373239689, 430497123340934, 711676555398832, 320964687779005 },+    { 988979367990485, 1359729327576302, 1301834257246029, 294141160829308, 29348272277475 },+    { 1434382743317910, 100082049942065, 221102347892623, 186982837860588, 1305765053501834 }+  },+  {+    { 2205916462268190, 499863829790820, 961960554686616, 158062762756985, 1841471168298305 },+    { 1191737341426592, 1847042034978363, 1382213545049056, 1039952395710448, 788812858896859 },+    { 1346965964571152, 1291881610839830, 2142916164336056, 786821641205979, 1571709146321039 }+  },+  {+    { 787164375951248, 202869205373189, 1356590421032140, 1431233331032510, 786341368775957 },+    { 492448143532951, 304105152670757, 1761767168301056, 233782684697790, 1981295323106089 },+    { 665807507761866, 1343384868355425, 895831046139653, 439338948736892, 1986828765695105 }+  },+  {+    { 756096210874553, 1721699973539149, 258765301727885, 1390588532210645, 1212530909934781 },+    { 852891097972275, 1816988871354562, 1543772755726524, 1174710635522444, 202129090724628 },+    { 1205281565824323, 22430498399418, 992947814485516, 1392458699738672, 688441466734558 }+  },+  {+    { 1050627428414972, 1955849529137135, 2171162376368357, 91745868298214, 447733118757826 },+    { 1287181461435438, 622722465530711, 880952150571872, 741035693459198, 311565274989772 },+    { 1003649078149734, 545233927396469, 1849786171789880, 1318943684880434, 280345687170552 }+  }+}
+ vendor/external/libsodium/crypto_core/ed25519/ref10/fe_51/base2.h view
@@ -0,0 +1,40 @@+{+  { 1288382639258501, 245678601348599, 269427782077623, 1462984067271730, 137412439391563 },+  { 62697248952638, 204681361388450, 631292143396476, 338455783676468, 1213667448819585 },+  { 301289933810280, 1259582250014073, 1422107436869536, 796239922652654, 1953934009299142 }+},+{+  { 1601611775252272, 1720807796594148, 1132070835939856, 1260455018889551, 2147779492816911 },+  { 316559037616741, 2177824224946892, 1459442586438991, 1461528397712656, 751590696113597 },+  { 1850748884277385, 1200145853858453, 1068094770532492, 672251375690438, 1586055907191707 }+},+{+  { 769950342298419, 132954430919746, 844085933195555, 974092374476333, 726076285546016 },+  { 425251763115706, 608463272472562, 442562545713235, 837766094556764, 374555092627893 },+  { 1086255230780037, 274979815921559, 1960002765731872, 929474102396301, 1190409889297339 }+},+{+  { 665000864555967, 2065379846933859, 370231110385876, 350988370788628, 1233371373142985 },+  { 2019367628972465, 676711900706637, 110710997811333, 1108646842542025, 517791959672113 },+  { 965130719900578, 247011430587952, 526356006571389, 91986625355052, 2157223321444601 }+},+{+  { 1802695059465007, 1664899123557221, 593559490740857, 2160434469266659, 927570450755031 },+  { 1725674970513508, 1933645953859181, 1542344539275782, 1767788773573747, 1297447965928905 },+  { 1381809363726107, 1430341051343062, 2061843536018959, 1551778050872521, 2036394857967624 }+},+{+  { 1970894096313054, 528066325833207, 1619374932191227, 2207306624415883, 1169170329061080 },+  { 2070390218572616, 1458919061857835, 624171843017421, 1055332792707765, 433987520732508 },+  { 893653801273833, 1168026499324677, 1242553501121234, 1306366254304474, 1086752658510815 }+},+{+  { 213454002618221, 939771523987438, 1159882208056014, 317388369627517, 621213314200687 },+  { 1971678598905747, 338026507889165, 762398079972271, 655096486107477, 42299032696322 },+  { 177130678690680, 1754759263300204, 1864311296286618, 1180675631479880, 1292726903152791 }+},+{+  { 1913163449625248, 460779200291993, 2193883288642314, 1008900146920800, 1721983679009502 },+  { 1070401523076875, 1272492007800961, 1910153608563310, 2075579521696771, 1191169788841221 },+  { 692896803108118, 500174642072499, 2068223309439677, 1162190621851337, 1426986007309901 }+}
+ vendor/external/libsodium/crypto_core/ed25519/ref10/fe_51/constants.h view
@@ -0,0 +1,41 @@+/* 37095705934669439343138083508754565189542113879843219016388785533085940283555 */+static const fe25519 d = {+    929955233495203, 466365720129213, 1662059464998953, 2033849074728123, 1442794654840575+};++/* 2 * d =+ * 16295367250680780974490674513165176452449235426866156013048779062215315747161+ */+static const fe25519 d2 = {+    1859910466990425, 932731440258426, 1072319116312658, 1815898335770999, 633789495995903+};++/* sqrt(-1) */+static const fe25519 sqrtm1 = {+    1718705420411056, 234908883556509, 2233514472574048, 2117202627021982, 765476049583133+};++/* A = 486662 */+static const fe25519 curve25519_A = {+    486662, 0, 0, 0, 0+};++/* sqrt(ad - 1) with a = -1 (mod p) */+static const fe25519 sqrtadm1 = {+    2241493124984347, 425987919032274, 2207028919301688, 1220490630685848, 974799131293748+};++/* 1 / sqrt(a - d) */+static const fe25519 invsqrtamd = {+    278908739862762, 821645201101625, 8113234426968, 1777959178193151, 2118520810568447+};++/* 1 - d ^ 2 */+static const fe25519 onemsqd = {+    1136626929484150, 1998550399581263, 496427632559748, 118527312129759, 45110755273534+};++/* (d - 1) ^ 2 */+static const fe25519 sqdmone = {+    1507062230895904, 1572317787530805, 683053064812840, 317374165784489, 1572899562415810+};
+ vendor/external/libsodium/crypto_core/ed25519/ref10/fe_51/fe.h view
@@ -0,0 +1,116 @@+/*+ Ignores top bit of s.+ */++void+fe25519_frombytes(fe25519 h, const unsigned char *s)+{+    const uint64_t mask = 0x7ffffffffffffULL;+    uint64_t h0, h1, h2, h3, h4;++    h0 = (LOAD64_LE(s     )      ) & mask;+    h1 = (LOAD64_LE(s +  6) >>  3) & mask;+    h2 = (LOAD64_LE(s + 12) >>  6) & mask;+    h3 = (LOAD64_LE(s + 19) >>  1) & mask;+    h4 = (LOAD64_LE(s + 24) >> 12) & mask;++    h[0] = h0;+    h[1] = h1;+    h[2] = h2;+    h[3] = h3;+    h[4] = h4;+}++static void+fe25519_reduce(fe25519 h, const fe25519 f)+{+    const uint64_t mask = 0x7ffffffffffffULL;+    uint128_t t[5];++    t[0] = f[0];+    t[1] = f[1];+    t[2] = f[2];+    t[3] = f[3];+    t[4] = f[4];++    t[1] += t[0] >> 51;+    t[0] &= mask;+    t[2] += t[1] >> 51;+    t[1] &= mask;+    t[3] += t[2] >> 51;+    t[2] &= mask;+    t[4] += t[3] >> 51;+    t[3] &= mask;+    t[0] += 19 * (t[4] >> 51);+    t[4] &= mask;++    t[1] += t[0] >> 51;+    t[0] &= mask;+    t[2] += t[1] >> 51;+    t[1] &= mask;+    t[3] += t[2] >> 51;+    t[2] &= mask;+    t[4] += t[3] >> 51;+    t[3] &= mask;+    t[0] += 19 * (t[4] >> 51);+    t[4] &= mask;++    /* now t is between 0 and 2^255-1, properly carried. */+    /* case 1: between 0 and 2^255-20. case 2: between 2^255-19 and 2^255-1. */++    t[0] += 19ULL;++    t[1] += t[0] >> 51;+    t[0] &= mask;+    t[2] += t[1] >> 51;+    t[1] &= mask;+    t[3] += t[2] >> 51;+    t[2] &= mask;+    t[4] += t[3] >> 51;+    t[3] &= mask;+    t[0] += 19ULL * (t[4] >> 51);+    t[4] &= mask;++    /* now between 19 and 2^255-1 in both cases, and offset by 19. */++    t[0] += 0x8000000000000 - 19ULL;+    t[1] += 0x8000000000000 - 1ULL;+    t[2] += 0x8000000000000 - 1ULL;+    t[3] += 0x8000000000000 - 1ULL;+    t[4] += 0x8000000000000 - 1ULL;++    /* now between 2^255 and 2^256-20, and offset by 2^255. */++    t[1] += t[0] >> 51;+    t[0] &= mask;+    t[2] += t[1] >> 51;+    t[1] &= mask;+    t[3] += t[2] >> 51;+    t[2] &= mask;+    t[4] += t[3] >> 51;+    t[3] &= mask;+    t[4] &= mask;++    h[0] = t[0];+    h[1] = t[1];+    h[2] = t[2];+    h[3] = t[3];+    h[4] = t[4];+}++void+fe25519_tobytes(unsigned char *s, const fe25519 h)+{+    fe25519  t;+    uint64_t t0, t1, t2, t3;++    fe25519_reduce(t, h);+    t0 = t[0] | (t[1] << 51);+    t1 = (t[1] >> 13) | (t[2] << 38);+    t2 = (t[2] >> 26) | (t[3] << 25);+    t3 = (t[3] >> 39) | (t[4] << 12);+    STORE64_LE(s +  0, t0);+    STORE64_LE(s +  8, t1);+    STORE64_LE(s + 16, t2);+    STORE64_LE(s + 24, t3);+}
+ vendor/external/libsodium/crypto_core/hchacha20/core_hchacha20.c view
@@ -0,0 +1,93 @@++#include <stdint.h>+#include <stdlib.h>++#include "crypto_core_hchacha20.h"+#include "private/common.h"++#define QUARTERROUND(A, B, C, D)     \+  do {                               \+      A += B; D = ROTL32(D ^ A, 16); \+      C += D; B = ROTL32(B ^ C, 12); \+      A += B; D = ROTL32(D ^ A,  8); \+      C += D; B = ROTL32(B ^ C,  7); \+  } while(0)++int+crypto_core_hchacha20(unsigned char *out, const unsigned char *in,+                      const unsigned char *k, const unsigned char *c)+{+    int      i;+    uint32_t x0, x1, x2, x3, x4, x5, x6, x7;+    uint32_t x8, x9, x10, x11, x12, x13, x14, x15;++    if (c == NULL) {+        x0 = 0x61707865;+        x1 = 0x3320646e;+        x2 = 0x79622d32;+        x3 = 0x6b206574;+    } else {+        x0 = LOAD32_LE(c +  0);+        x1 = LOAD32_LE(c +  4);+        x2 = LOAD32_LE(c +  8);+        x3 = LOAD32_LE(c + 12);+    }+    x4  = LOAD32_LE(k +  0);+    x5  = LOAD32_LE(k +  4);+    x6  = LOAD32_LE(k +  8);+    x7  = LOAD32_LE(k + 12);+    x8  = LOAD32_LE(k + 16);+    x9  = LOAD32_LE(k + 20);+    x10 = LOAD32_LE(k + 24);+    x11 = LOAD32_LE(k + 28);+    x12 = LOAD32_LE(in +  0);+    x13 = LOAD32_LE(in +  4);+    x14 = LOAD32_LE(in +  8);+    x15 = LOAD32_LE(in + 12);++    for (i = 0; i < 10; i++) {+        QUARTERROUND(x0, x4,  x8, x12);+        QUARTERROUND(x1, x5,  x9, x13);+        QUARTERROUND(x2, x6, x10, x14);+        QUARTERROUND(x3, x7, x11, x15);+        QUARTERROUND(x0, x5, x10, x15);+        QUARTERROUND(x1, x6, x11, x12);+        QUARTERROUND(x2, x7,  x8, x13);+        QUARTERROUND(x3, x4,  x9, x14);+    }++    STORE32_LE(out +  0, x0);+    STORE32_LE(out +  4, x1);+    STORE32_LE(out +  8, x2);+    STORE32_LE(out + 12, x3);+    STORE32_LE(out + 16, x12);+    STORE32_LE(out + 20, x13);+    STORE32_LE(out + 24, x14);+    STORE32_LE(out + 28, x15);++    return 0;+}++size_t+crypto_core_hchacha20_outputbytes(void)+{+    return crypto_core_hchacha20_OUTPUTBYTES;+}++size_t+crypto_core_hchacha20_inputbytes(void)+{+    return crypto_core_hchacha20_INPUTBYTES;+}++size_t+crypto_core_hchacha20_keybytes(void)+{+    return crypto_core_hchacha20_KEYBYTES;+}++size_t+crypto_core_hchacha20_constbytes(void)+{+    return crypto_core_hchacha20_CONSTBYTES;+}
+ vendor/external/libsodium/crypto_core/hsalsa20/core_hsalsa20.c view
@@ -0,0 +1,21 @@+#include "crypto_core_hsalsa20.h"++size_t+crypto_core_hsalsa20_outputbytes(void) {+    return crypto_core_hsalsa20_OUTPUTBYTES;+}++size_t+crypto_core_hsalsa20_inputbytes(void) {+    return crypto_core_hsalsa20_INPUTBYTES;+}++size_t+crypto_core_hsalsa20_keybytes(void) {+    return crypto_core_hsalsa20_KEYBYTES;+}++size_t+crypto_core_hsalsa20_constbytes(void) {+    return crypto_core_hsalsa20_CONSTBYTES;+}
+ vendor/external/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20_ref2.c view
@@ -0,0 +1,95 @@+/*+version 20080912+D. J. Bernstein+Public domain.+*/++#include <stdint.h>+#include <stdlib.h>++#include "crypto_core_hsalsa20.h"+#include "private/common.h"++#define ROUNDS 20+#define U32C(v) (v##U)++int+crypto_core_hsalsa20(unsigned char *out,+                     const unsigned char *in,+                     const unsigned char *k,+                     const unsigned char *c)+{+    uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8,+             x9, x10, x11, x12, x13, x14,  x15;+    int      i;++    if (c == NULL) {+        x0 = U32C(0x61707865);+        x5 = U32C(0x3320646e);+        x10 = U32C(0x79622d32);+        x15 = U32C(0x6b206574);+    } else {+        x0 = LOAD32_LE(c + 0);+        x5 = LOAD32_LE(c + 4);+        x10 = LOAD32_LE(c + 8);+        x15 = LOAD32_LE(c + 12);+    }+    x1 = LOAD32_LE(k + 0);+    x2 = LOAD32_LE(k + 4);+    x3 = LOAD32_LE(k + 8);+    x4 = LOAD32_LE(k + 12);+    x11 = LOAD32_LE(k + 16);+    x12 = LOAD32_LE(k + 20);+    x13 = LOAD32_LE(k + 24);+    x14 = LOAD32_LE(k + 28);+    x6 = LOAD32_LE(in + 0);+    x7 = LOAD32_LE(in + 4);+    x8 = LOAD32_LE(in + 8);+    x9 = LOAD32_LE(in + 12);++    for (i = ROUNDS; i > 0; i -= 2) {+        x4 ^= ROTL32(x0 + x12, 7);+        x8 ^= ROTL32(x4 + x0, 9);+        x12 ^= ROTL32(x8 + x4, 13);+        x0 ^= ROTL32(x12 + x8, 18);+        x9 ^= ROTL32(x5 + x1, 7);+        x13 ^= ROTL32(x9 + x5, 9);+        x1 ^= ROTL32(x13 + x9, 13);+        x5 ^= ROTL32(x1 + x13, 18);+        x14 ^= ROTL32(x10 + x6, 7);+        x2 ^= ROTL32(x14 + x10, 9);+        x6 ^= ROTL32(x2 + x14, 13);+        x10 ^= ROTL32(x6 + x2, 18);+        x3 ^= ROTL32(x15 + x11, 7);+        x7 ^= ROTL32(x3 + x15, 9);+        x11 ^= ROTL32(x7 + x3, 13);+        x15 ^= ROTL32(x11 + x7, 18);+        x1 ^= ROTL32(x0 + x3, 7);+        x2 ^= ROTL32(x1 + x0, 9);+        x3 ^= ROTL32(x2 + x1, 13);+        x0 ^= ROTL32(x3 + x2, 18);+        x6 ^= ROTL32(x5 + x4, 7);+        x7 ^= ROTL32(x6 + x5, 9);+        x4 ^= ROTL32(x7 + x6, 13);+        x5 ^= ROTL32(x4 + x7, 18);+        x11 ^= ROTL32(x10 + x9, 7);+        x8 ^= ROTL32(x11 + x10, 9);+        x9 ^= ROTL32(x8 + x11, 13);+        x10 ^= ROTL32(x9 + x8, 18);+        x12 ^= ROTL32(x15 + x14, 7);+        x13 ^= ROTL32(x12 + x15, 9);+        x14 ^= ROTL32(x13 + x12, 13);+        x15 ^= ROTL32(x14 + x13, 18);+    }++    STORE32_LE(out + 0, x0);+    STORE32_LE(out + 4, x5);+    STORE32_LE(out + 8, x10);+    STORE32_LE(out + 12, x15);+    STORE32_LE(out + 16, x6);+    STORE32_LE(out + 20, x7);+    STORE32_LE(out + 24, x8);+    STORE32_LE(out + 28, x9);++    return 0;+}
+ vendor/external/libsodium/crypto_core/salsa/ref/core_salsa_ref.c view
@@ -0,0 +1,195 @@++#include <stdint.h>+#include <stdlib.h>++#include "crypto_core_salsa20.h"+#include "crypto_core_salsa2012.h"+#include "crypto_core_salsa208.h"+#include "private/common.h"++static void+crypto_core_salsa(unsigned char *out, const unsigned char *in,+                  const unsigned char *k, const unsigned char *c,+                  const int rounds)+{+    uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14,+        x15;+    uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14,+        j15;+    int i;++    j0  = x0  = 0x61707865;+    j5  = x5  = 0x3320646e;+    j10 = x10 = 0x79622d32;+    j15 = x15 = 0x6b206574;+    if (c != NULL) {+        j0  = x0  = LOAD32_LE(c + 0);+        j5  = x5  = LOAD32_LE(c + 4);+        j10 = x10 = LOAD32_LE(c + 8);+        j15 = x15 = LOAD32_LE(c + 12);+    }+    j1  = x1  = LOAD32_LE(k + 0);+    j2  = x2  = LOAD32_LE(k + 4);+    j3  = x3  = LOAD32_LE(k + 8);+    j4  = x4  = LOAD32_LE(k + 12);+    j11 = x11 = LOAD32_LE(k + 16);+    j12 = x12 = LOAD32_LE(k + 20);+    j13 = x13 = LOAD32_LE(k + 24);+    j14 = x14 = LOAD32_LE(k + 28);++    j6  = x6  = LOAD32_LE(in + 0);+    j7  = x7  = LOAD32_LE(in + 4);+    j8  = x8  = LOAD32_LE(in + 8);+    j9  = x9  = LOAD32_LE(in + 12);++    for (i = 0; i < rounds; i += 2) {+        x4  ^= ROTL32(x0  + x12, 7);+        x8  ^= ROTL32(x4  + x0, 9);+        x12 ^= ROTL32(x8  + x4, 13);+        x0  ^= ROTL32(x12 + x8, 18);+        x9  ^= ROTL32(x5  + x1, 7);+        x13 ^= ROTL32(x9  + x5, 9);+        x1  ^= ROTL32(x13 + x9, 13);+        x5  ^= ROTL32(x1  + x13, 18);+        x14 ^= ROTL32(x10 + x6, 7);+        x2  ^= ROTL32(x14 + x10, 9);+        x6  ^= ROTL32(x2  + x14, 13);+        x10 ^= ROTL32(x6  + x2, 18);+        x3  ^= ROTL32(x15 + x11, 7);+        x7  ^= ROTL32(x3  + x15, 9);+        x11 ^= ROTL32(x7  + x3, 13);+        x15 ^= ROTL32(x11 + x7, 18);+        x1  ^= ROTL32(x0  + x3, 7);+        x2  ^= ROTL32(x1  + x0, 9);+        x3  ^= ROTL32(x2  + x1, 13);+        x0  ^= ROTL32(x3  + x2, 18);+        x6  ^= ROTL32(x5  + x4, 7);+        x7  ^= ROTL32(x6  + x5, 9);+        x4  ^= ROTL32(x7  + x6, 13);+        x5  ^= ROTL32(x4  + x7, 18);+        x11 ^= ROTL32(x10 + x9, 7);+        x8  ^= ROTL32(x11 + x10, 9);+        x9  ^= ROTL32(x8  + x11, 13);+        x10 ^= ROTL32(x9  + x8, 18);+        x12 ^= ROTL32(x15 + x14, 7);+        x13 ^= ROTL32(x12 + x15, 9);+        x14 ^= ROTL32(x13 + x12, 13);+        x15 ^= ROTL32(x14 + x13, 18);+    }+    STORE32_LE(out + 0,  x0  + j0);+    STORE32_LE(out + 4,  x1  + j1);+    STORE32_LE(out + 8,  x2  + j2);+    STORE32_LE(out + 12, x3  + j3);+    STORE32_LE(out + 16, x4  + j4);+    STORE32_LE(out + 20, x5  + j5);+    STORE32_LE(out + 24, x6  + j6);+    STORE32_LE(out + 28, x7  + j7);+    STORE32_LE(out + 32, x8  + j8);+    STORE32_LE(out + 36, x9  + j9);+    STORE32_LE(out + 40, x10 + j10);+    STORE32_LE(out + 44, x11 + j11);+    STORE32_LE(out + 48, x12 + j12);+    STORE32_LE(out + 52, x13 + j13);+    STORE32_LE(out + 56, x14 + j14);+    STORE32_LE(out + 60, x15 + j15);+}++int+crypto_core_salsa20(unsigned char *out, const unsigned char *in,+                    const unsigned char *k, const unsigned char *c)+{+    crypto_core_salsa(out, in, k, c, 20);+    return 0;+}++size_t+crypto_core_salsa20_outputbytes(void)+{+    return crypto_core_salsa20_OUTPUTBYTES;+}++size_t+crypto_core_salsa20_inputbytes(void)+{+    return crypto_core_salsa20_INPUTBYTES;+}++size_t+crypto_core_salsa20_keybytes(void)+{+    return crypto_core_salsa20_KEYBYTES;+}++size_t+crypto_core_salsa20_constbytes(void)+{+    return crypto_core_salsa20_CONSTBYTES;+}++#ifndef MINIMAL+/* LCOV_EXCL_START */+int+crypto_core_salsa2012(unsigned char *out, const unsigned char *in,+                      const unsigned char *k, const unsigned char *c)+{+    crypto_core_salsa(out, in, k, c, 12);+    return 0;+}++size_t+crypto_core_salsa2012_outputbytes(void)+{+    return crypto_core_salsa2012_OUTPUTBYTES;+}++size_t+crypto_core_salsa2012_inputbytes(void)+{+    return crypto_core_salsa2012_INPUTBYTES;+}++size_t+crypto_core_salsa2012_keybytes(void)+{+    return crypto_core_salsa2012_KEYBYTES;+}++size_t+crypto_core_salsa2012_constbytes(void)+{+    return crypto_core_salsa2012_CONSTBYTES;+}++int+crypto_core_salsa208(unsigned char *out, const unsigned char *in,+                     const unsigned char *k, const unsigned char *c)+{+    crypto_core_salsa(out, in, k, c, 8);+    return 0;+}++size_t+crypto_core_salsa208_outputbytes(void)+{+    return crypto_core_salsa208_OUTPUTBYTES;+}++size_t+crypto_core_salsa208_inputbytes(void)+{+    return crypto_core_salsa208_INPUTBYTES;+}++size_t+crypto_core_salsa208_keybytes(void)+{+    return crypto_core_salsa208_KEYBYTES;+}++size_t+crypto_core_salsa208_constbytes(void)+{+    return crypto_core_salsa208_CONSTBYTES;+}+/* LCOV_EXCL_END */+#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/generichash_blake2.c view
@@ -0,0 +1,55 @@+#include "crypto_generichash_blake2b.h"+#include "randombytes.h"++size_t+crypto_generichash_blake2b_bytes_min(void) {+    return crypto_generichash_blake2b_BYTES_MIN;+}++size_t+crypto_generichash_blake2b_bytes_max(void) {+    return crypto_generichash_blake2b_BYTES_MAX;+}++size_t+crypto_generichash_blake2b_bytes(void) {+    return crypto_generichash_blake2b_BYTES;+}++size_t+crypto_generichash_blake2b_keybytes_min(void) {+    return crypto_generichash_blake2b_KEYBYTES_MIN;+}++size_t+crypto_generichash_blake2b_keybytes_max(void) {+    return crypto_generichash_blake2b_KEYBYTES_MAX;+}++size_t+crypto_generichash_blake2b_keybytes(void) {+    return crypto_generichash_blake2b_KEYBYTES;+}++size_t+crypto_generichash_blake2b_saltbytes(void) {+    return crypto_generichash_blake2b_SALTBYTES;+}++size_t+crypto_generichash_blake2b_personalbytes(void) {+    return crypto_generichash_blake2b_PERSONALBYTES;+}++size_t+crypto_generichash_blake2b_statebytes(void)+{+    return (sizeof(crypto_generichash_blake2b_state) + (size_t) 63U)+        & ~(size_t) 63U;+}++void+crypto_generichash_blake2b_keygen(unsigned char k[crypto_generichash_blake2b_KEYBYTES])+{+    randombytes_buf(k, crypto_generichash_blake2b_KEYBYTES);+}
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2.h view
@@ -0,0 +1,106 @@+/*+   BLAKE2 reference source code package - reference C implementations++   Written in 2012 by Samuel Neves <sneves@dei.uc.pt>++   To the extent possible under law, the author(s) have dedicated all copyright+   and related and neighboring rights to this software to the public domain+   worldwide. This software is distributed without any warranty.++   All code is triple-licensed under the+   [CC0](http://creativecommons.org/publicdomain/zero/1.0), the+   [OpenSSL Licence](https://www.openssl.org/source/license.html), or+   the [Apache Public License 2.0](http://www.apache.org/licenses/LICENSE-2.0),+   at your choosing.+ */++#ifndef blake2_H+#define blake2_H++#include <stddef.h>+#include <stdint.h>++#include "crypto_generichash_blake2b.h"+#include "export.h"++enum blake2b_constant {+    BLAKE2B_BLOCKBYTES    = 128,+    BLAKE2B_OUTBYTES      = 64,+    BLAKE2B_KEYBYTES      = 64,+    BLAKE2B_SALTBYTES     = 16,+    BLAKE2B_PERSONALBYTES = 16+};++#ifdef __IBMC__+# pragma pack(1)+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)+# pragma pack(1)+#else+# pragma pack(push, 1)+#endif++typedef struct blake2b_param_ {+    uint8_t digest_length;                   /*  1 */+    uint8_t key_length;                      /*  2 */+    uint8_t fanout;                          /*  3 */+    uint8_t depth;                           /*  4 */+    uint8_t leaf_length[4];                  /*  8 */+    uint8_t node_offset[8];                  /* 16 */+    uint8_t node_depth;                      /* 17 */+    uint8_t inner_length;                    /* 18 */+    uint8_t reserved[14];                    /* 32 */+    uint8_t salt[BLAKE2B_SALTBYTES];         /* 48 */+    uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */+} blake2b_param;++typedef struct blake2b_state {+    uint64_t h[8];+    uint64_t t[2];+    uint64_t f[2];+    uint8_t  buf[2 * 128];+    size_t   buflen;+    uint8_t  last_node;+} blake2b_state;++#ifdef __IBMC__+# pragma pack(pop)+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)+# pragma pack()+#else+# pragma pack(pop)+#endif++/* Streaming API */+int blake2b_init(blake2b_state *S, const uint8_t outlen);+int blake2b_init_salt_personal(blake2b_state *S, const uint8_t outlen,+                               const void *salt, const void *personal);+int blake2b_init_key(blake2b_state *S, const uint8_t outlen, const void *key,+                     const uint8_t keylen);+int blake2b_init_key_salt_personal(blake2b_state *S, const uint8_t outlen,+                                   const void *key, const uint8_t keylen,+                                   const void *salt, const void *personal);+int blake2b_init_param(blake2b_state *S, const blake2b_param *P);+int blake2b_update(blake2b_state *S, const uint8_t *in, uint64_t inlen);+int blake2b_final(blake2b_state *S, uint8_t *out, uint8_t outlen);++/* Simple API */+int blake2b(uint8_t *out, const void *in, const void *key, const uint8_t outlen,+            const uint64_t inlen, uint8_t keylen);+int blake2b_salt_personal(uint8_t *out, const void *in, const void *key,+                          const uint8_t outlen, const uint64_t inlen,+                          uint8_t keylen, const void *salt,+                          const void *personal);++typedef int (*blake2b_compress_fn)(blake2b_state *S,+                                   const uint8_t  block[BLAKE2B_BLOCKBYTES]);+int blake2b_pick_best_implementation(void);+int blake2b_compress_ref(blake2b_state *S,+                         const uint8_t  block[BLAKE2B_BLOCKBYTES]);+int blake2b_compress_ssse3(blake2b_state *S,+                           const uint8_t  block[BLAKE2B_BLOCKBYTES]);+int blake2b_compress_sse41(blake2b_state *S,+                           const uint8_t  block[BLAKE2B_BLOCKBYTES]);+int blake2b_compress_avx2(blake2b_state *S,+                          const uint8_t  block[BLAKE2B_BLOCKBYTES]);++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.c view
@@ -0,0 +1,49 @@++#define BLAKE2_USE_SSSE3+#define BLAKE2_USE_SSE41+#define BLAKE2_USE_AVX2++#include <stdint.h>+#include <string.h>++#include "blake2.h"+#include "private/common.h"++#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \+    defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)++# ifdef __GNUC__+#  pragma GCC target("sse2")+#  pragma GCC target("ssse3")+#  pragma GCC target("sse4.1")+#  pragma GCC target("avx2")+# endif++# include <emmintrin.h>+# include <immintrin.h>+# include <smmintrin.h>+# include <tmmintrin.h>+# include "private/sse2_64_32.h"++# include "blake2b-compress-avx2.h"++CRYPTO_ALIGN(64)+static const uint64_t blake2b_IV[8] = {+    0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,+    0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,+    0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL+};++int+blake2b_compress_avx2(blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES])+{+    __m256i a = LOADU(&S->h[0]);+    __m256i b = LOADU(&S->h[4]);+    BLAKE2B_COMPRESS_V1(a, b, block, S->t[0], S->t[1], S->f[0], S->f[1]);+    STOREU(&S->h[0], a);+    STOREU(&S->h[4], b);++    return 0;+}++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.h view
@@ -0,0 +1,142 @@++#ifndef blake2b_compress_avx2_H+#define blake2b_compress_avx2_H++#define LOADU128(p) _mm_loadu_si128((const __m128i *) (p))+#define STOREU128(p, r) _mm_storeu_si128((__m128i *) (p), r)++#define LOADU(p) _mm256_loadu_si256((const __m256i *) (p))+#define STOREU(p, r) _mm256_storeu_si256((__m256i *) (p), r)++#if defined(__INTEL_COMPILER) || defined(_MSC_VER) || defined(__GNUC__)+# define LOAD(p) _mm256_load_si256((const __m256i *) (p))+# define STORE(p, r) _mm256_store_si256((__m256i *) (p), r)+#else+# define LOAD(p) LOADU(p)+# define STORE(p, r) STOREU(p, r)+#endif++static inline uint64_t+LOADU64(const void *p)+{+    uint64_t v;+    memcpy(&v, p, sizeof v);+    return v;+}++#define ROTATE16                                                              \+    _mm256_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9, 2, \+                     3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9)++#define ROTATE24                                                              \+    _mm256_setr_epi8(3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10, 3, \+                     4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10)++#define ADD(a, b) _mm256_add_epi64(a, b)+#define SUB(a, b) _mm256_sub_epi64(a, b)++#define XOR(a, b) _mm256_xor_si256(a, b)+#define AND(a, b) _mm256_and_si256(a, b)+#define OR(a, b) _mm256_or_si256(a, b)++#define ROT32(x) _mm256_shuffle_epi32((x), _MM_SHUFFLE(2, 3, 0, 1))+#define ROT24(x) _mm256_shuffle_epi8((x), ROTATE24)+#define ROT16(x) _mm256_shuffle_epi8((x), ROTATE16)+#define ROT63(x) _mm256_or_si256(_mm256_srli_epi64((x), 63), ADD((x), (x)))++#define BLAKE2B_G1_V1(a, b, c, d, m) \+    do {                             \+        a = ADD(a, m);               \+        a = ADD(a, b);               \+        d = XOR(d, a);               \+        d = ROT32(d);                \+        c = ADD(c, d);               \+        b = XOR(b, c);               \+        b = ROT24(b);                \+    } while (0)++#define BLAKE2B_G2_V1(a, b, c, d, m) \+    do {                             \+        a = ADD(a, m);               \+        a = ADD(a, b);               \+        d = XOR(d, a);               \+        d = ROT16(d);                \+        c = ADD(c, d);               \+        b = XOR(b, c);               \+        b = ROT63(b);                \+    } while (0)++#define BLAKE2B_DIAG_V1(a, b, c, d)                               \+    do {                                                          \+        a = _mm256_permute4x64_epi64(a, _MM_SHUFFLE(2, 1, 0, 3)); \+        d = _mm256_permute4x64_epi64(d, _MM_SHUFFLE(1, 0, 3, 2)); \+        c = _mm256_permute4x64_epi64(c, _MM_SHUFFLE(0, 3, 2, 1)); \+    } while(0)++#define BLAKE2B_UNDIAG_V1(a, b, c, d)                             \+    do {                                                          \+        a = _mm256_permute4x64_epi64(a, _MM_SHUFFLE(0, 3, 2, 1)); \+        d = _mm256_permute4x64_epi64(d, _MM_SHUFFLE(1, 0, 3, 2)); \+        c = _mm256_permute4x64_epi64(c, _MM_SHUFFLE(2, 1, 0, 3)); \+    } while(0)++#include "blake2b-load-avx2.h"++#define BLAKE2B_ROUND_V1(a, b, c, d, r, m) \+    do {                                   \+        __m256i b0;                        \+        BLAKE2B_LOAD_MSG_##r##_1(b0);      \+        BLAKE2B_G1_V1(a, b, c, d, b0);     \+        BLAKE2B_LOAD_MSG_##r##_2(b0);      \+        BLAKE2B_G2_V1(a, b, c, d, b0);     \+        BLAKE2B_DIAG_V1(a, b, c, d);       \+        BLAKE2B_LOAD_MSG_##r##_3(b0);      \+        BLAKE2B_G1_V1(a, b, c, d, b0);     \+        BLAKE2B_LOAD_MSG_##r##_4(b0);      \+        BLAKE2B_G2_V1(a, b, c, d, b0);     \+        BLAKE2B_UNDIAG_V1(a, b, c, d);     \+    } while (0)++#define BLAKE2B_ROUNDS_V1(a, b, c, d, m)       \+    do {                                       \+        BLAKE2B_ROUND_V1(a, b, c, d, 0, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 1, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 2, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 3, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 4, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 5, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 6, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 7, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 8, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 9, (m));  \+        BLAKE2B_ROUND_V1(a, b, c, d, 10, (m)); \+        BLAKE2B_ROUND_V1(a, b, c, d, 11, (m)); \+    } while (0)++#define DECLARE_MESSAGE_WORDS(m)                                         \+    const __m256i m0 = _mm256_broadcastsi128_si256(LOADU128((m) + 0));   \+    const __m256i m1 = _mm256_broadcastsi128_si256(LOADU128((m) + 16));  \+    const __m256i m2 = _mm256_broadcastsi128_si256(LOADU128((m) + 32));  \+    const __m256i m3 = _mm256_broadcastsi128_si256(LOADU128((m) + 48));  \+    const __m256i m4 = _mm256_broadcastsi128_si256(LOADU128((m) + 64));  \+    const __m256i m5 = _mm256_broadcastsi128_si256(LOADU128((m) + 80));  \+    const __m256i m6 = _mm256_broadcastsi128_si256(LOADU128((m) + 96));  \+    const __m256i m7 = _mm256_broadcastsi128_si256(LOADU128((m) + 112)); \+    __m256i       t0, t1;++#define BLAKE2B_COMPRESS_V1(a, b, m, t0, t1, f0, f1)                      \+    do {                                                                  \+        DECLARE_MESSAGE_WORDS(m)                                          \+        const __m256i iv0 = a;                                            \+        const __m256i iv1 = b;                                            \+        __m256i       c   = LOAD(&blake2b_IV[0]);                         \+        __m256i       d =                                                 \+            XOR(LOAD(&blake2b_IV[4]), _mm256_set_epi64x(f1, f0, t1, t0)); \+        BLAKE2B_ROUNDS_V1(a, b, c, d, m);                                 \+        a = XOR(a, c);                                                    \+        b = XOR(b, d);                                                    \+        a = XOR(a, iv0);                                                  \+        b = XOR(b, iv1);                                                  \+    } while (0)++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c view
@@ -0,0 +1,93 @@++#include <stdint.h>+#include <string.h>++#include "blake2.h"+#include "private/common.h"++CRYPTO_ALIGN(64)+static const uint64_t blake2b_IV[8] = {+    0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,+    0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,+    0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL+};++static const uint8_t blake2b_sigma[12][16] = {+    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },+    { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },+    { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },+    { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },+    { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },+    { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },+    { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },+    { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },+    { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },+    { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },+    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },+    { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }+};++int+blake2b_compress_ref(blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES])+{+    uint64_t m[16];+    uint64_t v[16];+    int      i;++    for (i = 0; i < 16; ++i) {+        m[i] = LOAD64_LE(block + i * sizeof m[i]);+    }+    for (i = 0; i < 8; ++i) {+        v[i] = S->h[i];+    }+    v[8]  = blake2b_IV[0];+    v[9]  = blake2b_IV[1];+    v[10] = blake2b_IV[2];+    v[11] = blake2b_IV[3];+    v[12] = S->t[0] ^ blake2b_IV[4];+    v[13] = S->t[1] ^ blake2b_IV[5];+    v[14] = S->f[0] ^ blake2b_IV[6];+    v[15] = S->f[1] ^ blake2b_IV[7];+#define G(r, i, a, b, c, d)                      \+    do {                                         \+        a += b + m[blake2b_sigma[r][2 * i + 0]]; \+        d = ROTR64(d ^ a, 32);                   \+        c += d;                                  \+        b = ROTR64(b ^ c, 24);                   \+        a += b + m[blake2b_sigma[r][2 * i + 1]]; \+        d = ROTR64(d ^ a, 16);                   \+        c += d;                                  \+        b = ROTR64(b ^ c, 63);                   \+    } while (0)+#define ROUND(r)                           \+    do {                                   \+        G(r, 0, v[0], v[4], v[8], v[12]);  \+        G(r, 1, v[1], v[5], v[9], v[13]);  \+        G(r, 2, v[2], v[6], v[10], v[14]); \+        G(r, 3, v[3], v[7], v[11], v[15]); \+        G(r, 4, v[0], v[5], v[10], v[15]); \+        G(r, 5, v[1], v[6], v[11], v[12]); \+        G(r, 6, v[2], v[7], v[8], v[13]);  \+        G(r, 7, v[3], v[4], v[9], v[14]);  \+    } while (0)+    ROUND(0);+    ROUND(1);+    ROUND(2);+    ROUND(3);+    ROUND(4);+    ROUND(5);+    ROUND(6);+    ROUND(7);+    ROUND(8);+    ROUND(9);+    ROUND(10);+    ROUND(11);++    for (i = 0; i < 8; ++i) {+        S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];+    }++#undef G+#undef ROUND+    return 0;+}
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.c view
@@ -0,0 +1,87 @@++#define BLAKE2_USE_SSSE3+#define BLAKE2_USE_SSE41++#include <stdint.h>+#include <string.h>++#include "blake2.h"+#include "private/common.h"++#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && \+    defined(HAVE_SMMINTRIN_H)++# ifdef __GNUC__+#  pragma GCC target("sse2")+#  pragma GCC target("ssse3")+#  pragma GCC target("sse4.1")+# endif++# include <emmintrin.h>+# include <smmintrin.h>+# include <tmmintrin.h>+# include "private/sse2_64_32.h"++# include "blake2b-compress-sse41.h"++CRYPTO_ALIGN(64)+static const uint64_t blake2b_IV[8] = {+    0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,+    0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,+    0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL+};++int+blake2b_compress_sse41(blake2b_state *S,+                       const uint8_t  block[BLAKE2B_BLOCKBYTES])+{+    __m128i       row1l, row1h;+    __m128i       row2l, row2h;+    __m128i       row3l, row3h;+    __m128i       row4l, row4h;+    __m128i       b0, b1;+    __m128i       t0, t1;+    const __m128i r16 =+        _mm_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9);+    const __m128i r24 =+        _mm_setr_epi8(3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10);+    const __m128i m0 = LOADU(block + 00);+    const __m128i m1 = LOADU(block + 16);+    const __m128i m2 = LOADU(block + 32);+    const __m128i m3 = LOADU(block + 48);+    const __m128i m4 = LOADU(block + 64);+    const __m128i m5 = LOADU(block + 80);+    const __m128i m6 = LOADU(block + 96);+    const __m128i m7 = LOADU(block + 112);+    row1l            = LOADU(&S->h[0]);+    row1h            = LOADU(&S->h[2]);+    row2l            = LOADU(&S->h[4]);+    row2h            = LOADU(&S->h[6]);+    row3l            = LOADU(&blake2b_IV[0]);+    row3h            = LOADU(&blake2b_IV[2]);+    row4l            = _mm_xor_si128(LOADU(&blake2b_IV[4]), LOADU(&S->t[0]));+    row4h            = _mm_xor_si128(LOADU(&blake2b_IV[6]), LOADU(&S->f[0]));+    ROUND(0);+    ROUND(1);+    ROUND(2);+    ROUND(3);+    ROUND(4);+    ROUND(5);+    ROUND(6);+    ROUND(7);+    ROUND(8);+    ROUND(9);+    ROUND(10);+    ROUND(11);+    row1l = _mm_xor_si128(row3l, row1l);+    row1h = _mm_xor_si128(row3h, row1h);+    STOREU(&S->h[0], _mm_xor_si128(LOADU(&S->h[0]), row1l));+    STOREU(&S->h[2], _mm_xor_si128(LOADU(&S->h[2]), row1h));+    row2l = _mm_xor_si128(row4l, row2l);+    row2h = _mm_xor_si128(row4h, row2h);+    STOREU(&S->h[4], _mm_xor_si128(LOADU(&S->h[4]), row2l));+    STOREU(&S->h[6], _mm_xor_si128(LOADU(&S->h[6]), row2h));+    return 0;+}++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.h view
@@ -0,0 +1,106 @@++#ifndef blake2b_compress_sse41_H+#define blake2b_compress_sse41_H++#define LOADU(p) _mm_loadu_si128((const __m128i *) (const void *) (p))+#define STOREU(p, r) _mm_storeu_si128((__m128i *) (void *) (p), r)++#if !(defined(_mm_roti_epi64) && defined(__XOP__))+#undef  _mm_roti_epi64+#define _mm_roti_epi64(x, c)                                         \+    (-(c) == 32)                                                     \+        ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2, 3, 0, 1))            \+        : (-(c) == 24)                                               \+              ? _mm_shuffle_epi8((x), r24)                           \+              : (-(c) == 16)                                         \+                    ? _mm_shuffle_epi8((x), r16)                     \+                    : (-(c) == 63)                                   \+                          ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), \+                                          _mm_add_epi64((x), (x)))   \+                          : _mm_xor_si128(_mm_srli_epi64((x), -(c)), \+                                          _mm_slli_epi64((x), 64 - (-(c))))+#endif++#define G1(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1) \+    row1l = _mm_add_epi64(_mm_add_epi64(row1l, b0), row2l);                \+    row1h = _mm_add_epi64(_mm_add_epi64(row1h, b1), row2h);                \+                                                                           \+    row4l = _mm_xor_si128(row4l, row1l);                                   \+    row4h = _mm_xor_si128(row4h, row1h);                                   \+                                                                           \+    row4l = _mm_roti_epi64(row4l, -32);                                    \+    row4h = _mm_roti_epi64(row4h, -32);                                    \+                                                                           \+    row3l = _mm_add_epi64(row3l, row4l);                                   \+    row3h = _mm_add_epi64(row3h, row4h);                                   \+                                                                           \+    row2l = _mm_xor_si128(row2l, row3l);                                   \+    row2h = _mm_xor_si128(row2h, row3h);                                   \+                                                                           \+    row2l = _mm_roti_epi64(row2l, -24);                                    \+    row2h = _mm_roti_epi64(row2h, -24);++#define G2(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1) \+    row1l = _mm_add_epi64(_mm_add_epi64(row1l, b0), row2l);                \+    row1h = _mm_add_epi64(_mm_add_epi64(row1h, b1), row2h);                \+                                                                           \+    row4l = _mm_xor_si128(row4l, row1l);                                   \+    row4h = _mm_xor_si128(row4h, row1h);                                   \+                                                                           \+    row4l = _mm_roti_epi64(row4l, -16);                                    \+    row4h = _mm_roti_epi64(row4h, -16);                                    \+                                                                           \+    row3l = _mm_add_epi64(row3l, row4l);                                   \+    row3h = _mm_add_epi64(row3h, row4h);                                   \+                                                                           \+    row2l = _mm_xor_si128(row2l, row3l);                                   \+    row2h = _mm_xor_si128(row2h, row3h);                                   \+                                                                           \+    row2l = _mm_roti_epi64(row2l, -63);                                    \+    row2h = _mm_roti_epi64(row2h, -63);++#define DIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h) \+    t0    = _mm_alignr_epi8(row2h, row2l, 8);                               \+    t1    = _mm_alignr_epi8(row2l, row2h, 8);                               \+    row2l = t0;                                                             \+    row2h = t1;                                                             \+                                                                            \+    t0    = row3l;                                                          \+    row3l = row3h;                                                          \+    row3h = t0;                                                             \+                                                                            \+    t0    = _mm_alignr_epi8(row4h, row4l, 8);                               \+    t1    = _mm_alignr_epi8(row4l, row4h, 8);                               \+    row4l = t1;                                                             \+    row4h = t0;++#define UNDIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h) \+    t0    = _mm_alignr_epi8(row2l, row2h, 8);                                 \+    t1    = _mm_alignr_epi8(row2h, row2l, 8);                                 \+    row2l = t0;                                                               \+    row2h = t1;                                                               \+                                                                              \+    t0    = row3l;                                                            \+    row3l = row3h;                                                            \+    row3h = t0;                                                               \+                                                                              \+    t0    = _mm_alignr_epi8(row4l, row4h, 8);                                 \+    t1    = _mm_alignr_epi8(row4h, row4l, 8);                                 \+    row4l = t1;                                                               \+    row4h = t0;++#include "blake2b-load-sse41.h"++#define ROUND(r)                                                         \+    LOAD_MSG_##r##_1(b0, b1);                                            \+    G1(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1);  \+    LOAD_MSG_##r##_2(b0, b1);                                            \+    G2(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1);  \+    DIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \+    LOAD_MSG_##r##_3(b0, b1);                                            \+    G1(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1);  \+    LOAD_MSG_##r##_4(b0, b1);                                            \+    G2(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1);  \+    UNDIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h);++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c view
@@ -0,0 +1,90 @@++#include <stdint.h>+#include <string.h>++#include "blake2.h"+#include "private/common.h"++#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)++# ifdef __GNUC__+#  pragma GCC target("sse2")+#  pragma GCC target("ssse3")+# endif++# include <emmintrin.h>+# include <tmmintrin.h>+# include "private/sse2_64_32.h"++# include "blake2b-compress-ssse3.h"++CRYPTO_ALIGN(64)+static const uint64_t blake2b_IV[8] = {+    0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,+    0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,+    0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL+};++int+blake2b_compress_ssse3(blake2b_state *S,+                       const uint8_t  block[BLAKE2B_BLOCKBYTES])+{+    __m128i       row1l, row1h;+    __m128i       row2l, row2h;+    __m128i       row3l, row3h;+    __m128i       row4l, row4h;+    __m128i       b0, b1;+    __m128i       t0, t1;+    const __m128i r16 =+        _mm_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9);+    const __m128i r24 =+        _mm_setr_epi8(3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10);+    const uint64_t m0  = ((const uint64_t *) block)[0];+    const uint64_t m1  = ((const uint64_t *) block)[1];+    const uint64_t m2  = ((const uint64_t *) block)[2];+    const uint64_t m3  = ((const uint64_t *) block)[3];+    const uint64_t m4  = ((const uint64_t *) block)[4];+    const uint64_t m5  = ((const uint64_t *) block)[5];+    const uint64_t m6  = ((const uint64_t *) block)[6];+    const uint64_t m7  = ((const uint64_t *) block)[7];+    const uint64_t m8  = ((const uint64_t *) block)[8];+    const uint64_t m9  = ((const uint64_t *) block)[9];+    const uint64_t m10 = ((const uint64_t *) block)[10];+    const uint64_t m11 = ((const uint64_t *) block)[11];+    const uint64_t m12 = ((const uint64_t *) block)[12];+    const uint64_t m13 = ((const uint64_t *) block)[13];+    const uint64_t m14 = ((const uint64_t *) block)[14];+    const uint64_t m15 = ((const uint64_t *) block)[15];++    row1l = LOADU(&S->h[0]);+    row1h = LOADU(&S->h[2]);+    row2l = LOADU(&S->h[4]);+    row2h = LOADU(&S->h[6]);+    row3l = LOADU(&blake2b_IV[0]);+    row3h = LOADU(&blake2b_IV[2]);+    row4l = _mm_xor_si128(LOADU(&blake2b_IV[4]), LOADU(&S->t[0]));+    row4h = _mm_xor_si128(LOADU(&blake2b_IV[6]), LOADU(&S->f[0]));+    ROUND(0);+    ROUND(1);+    ROUND(2);+    ROUND(3);+    ROUND(4);+    ROUND(5);+    ROUND(6);+    ROUND(7);+    ROUND(8);+    ROUND(9);+    ROUND(10);+    ROUND(11);+    row1l = _mm_xor_si128(row3l, row1l);+    row1h = _mm_xor_si128(row3h, row1h);+    STOREU(&S->h[0], _mm_xor_si128(LOADU(&S->h[0]), row1l));+    STOREU(&S->h[2], _mm_xor_si128(LOADU(&S->h[2]), row1h));+    row2l = _mm_xor_si128(row4l, row2l);+    row2h = _mm_xor_si128(row4h, row2h);+    STOREU(&S->h[4], _mm_xor_si128(LOADU(&S->h[4]), row2l));+    STOREU(&S->h[6], _mm_xor_si128(LOADU(&S->h[6]), row2h));+    return 0;+}++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.h view
@@ -0,0 +1,106 @@++#ifndef blake2b_compress_ssse3_H+#define blake2b_compress_ssse3_H++#define LOADU(p) _mm_loadu_si128((const __m128i *) (const void *) (p))+#define STOREU(p, r) _mm_storeu_si128((__m128i *) (void *) (p), r)++#if !(defined(_mm_roti_epi64) && defined(__XOP__))+#undef  _mm_roti_epi64+#define _mm_roti_epi64(x, c)                                         \+    (-(c) == 32)                                                     \+        ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2, 3, 0, 1))            \+        : (-(c) == 24)                                               \+              ? _mm_shuffle_epi8((x), r24)                           \+              : (-(c) == 16)                                         \+                    ? _mm_shuffle_epi8((x), r16)                     \+                    : (-(c) == 63)                                   \+                          ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), \+                                          _mm_add_epi64((x), (x)))   \+                          : _mm_xor_si128(_mm_srli_epi64((x), -(c)), \+                                          _mm_slli_epi64((x), 64 - (-(c))))+#endif++#define G1(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1) \+    row1l = _mm_add_epi64(_mm_add_epi64(row1l, b0), row2l);                \+    row1h = _mm_add_epi64(_mm_add_epi64(row1h, b1), row2h);                \+                                                                           \+    row4l = _mm_xor_si128(row4l, row1l);                                   \+    row4h = _mm_xor_si128(row4h, row1h);                                   \+                                                                           \+    row4l = _mm_roti_epi64(row4l, -32);                                    \+    row4h = _mm_roti_epi64(row4h, -32);                                    \+                                                                           \+    row3l = _mm_add_epi64(row3l, row4l);                                   \+    row3h = _mm_add_epi64(row3h, row4h);                                   \+                                                                           \+    row2l = _mm_xor_si128(row2l, row3l);                                   \+    row2h = _mm_xor_si128(row2h, row3h);                                   \+                                                                           \+    row2l = _mm_roti_epi64(row2l, -24);                                    \+    row2h = _mm_roti_epi64(row2h, -24);++#define G2(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1) \+    row1l = _mm_add_epi64(_mm_add_epi64(row1l, b0), row2l);                \+    row1h = _mm_add_epi64(_mm_add_epi64(row1h, b1), row2h);                \+                                                                           \+    row4l = _mm_xor_si128(row4l, row1l);                                   \+    row4h = _mm_xor_si128(row4h, row1h);                                   \+                                                                           \+    row4l = _mm_roti_epi64(row4l, -16);                                    \+    row4h = _mm_roti_epi64(row4h, -16);                                    \+                                                                           \+    row3l = _mm_add_epi64(row3l, row4l);                                   \+    row3h = _mm_add_epi64(row3h, row4h);                                   \+                                                                           \+    row2l = _mm_xor_si128(row2l, row3l);                                   \+    row2h = _mm_xor_si128(row2h, row3h);                                   \+                                                                           \+    row2l = _mm_roti_epi64(row2l, -63);                                    \+    row2h = _mm_roti_epi64(row2h, -63);++#define DIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h) \+    t0    = _mm_alignr_epi8(row2h, row2l, 8);                               \+    t1    = _mm_alignr_epi8(row2l, row2h, 8);                               \+    row2l = t0;                                                             \+    row2h = t1;                                                             \+                                                                            \+    t0    = row3l;                                                          \+    row3l = row3h;                                                          \+    row3h = t0;                                                             \+                                                                            \+    t0    = _mm_alignr_epi8(row4h, row4l, 8);                               \+    t1    = _mm_alignr_epi8(row4l, row4h, 8);                               \+    row4l = t1;                                                             \+    row4h = t0;++#define UNDIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h) \+    t0    = _mm_alignr_epi8(row2l, row2h, 8);                                 \+    t1    = _mm_alignr_epi8(row2h, row2l, 8);                                 \+    row2l = t0;                                                               \+    row2h = t1;                                                               \+                                                                              \+    t0    = row3l;                                                            \+    row3l = row3h;                                                            \+    row3h = t0;                                                               \+                                                                              \+    t0    = _mm_alignr_epi8(row4l, row4h, 8);                                 \+    t1    = _mm_alignr_epi8(row4h, row4l, 8);                                 \+    row4l = t1;                                                               \+    row4h = t0;++#include "blake2b-load-sse2.h"++#define ROUND(r)                                                         \+    LOAD_MSG_##r##_1(b0, b1);                                            \+    G1(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1);  \+    LOAD_MSG_##r##_2(b0, b1);                                            \+    G2(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1);  \+    DIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \+    LOAD_MSG_##r##_3(b0, b1);                                            \+    G1(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1);  \+    LOAD_MSG_##r##_4(b0, b1);                                            \+    G2(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h, b0, b1);  \+    UNDIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h);++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-load-avx2.h view
@@ -0,0 +1,340 @@+#ifndef blake2b_load_avx2_H+#define blake2b_load_avx2_H++#define BLAKE2B_LOAD_MSG_0_1(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m0, m1);    \+        t1 = _mm256_unpacklo_epi64(m2, m3);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_0_2(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m0, m1);    \+        t1 = _mm256_unpackhi_epi64(m2, m3);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_0_3(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m7, m4);    \+        t1 = _mm256_unpacklo_epi64(m5, m6);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_0_4(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m7, m4);    \+        t1 = _mm256_unpackhi_epi64(m5, m6);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_1_1(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m7, m2);    \+        t1 = _mm256_unpackhi_epi64(m4, m6);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_1_2(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m5, m4);    \+        t1 = _mm256_alignr_epi8(m3, m7, 8);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_1_3(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m2, m0);    \+        t1 = _mm256_blend_epi32(m5, m0, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_1_4(b0)               \+    do {                                       \+        t0 = _mm256_alignr_epi8(m6, m1, 8);    \+        t1 = _mm256_blend_epi32(m3, m1, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_2_1(b0)               \+    do {                                       \+        t0 = _mm256_alignr_epi8(m6, m5, 8);    \+        t1 = _mm256_unpackhi_epi64(m2, m7);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_2_2(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m4, m0);    \+        t1 = _mm256_blend_epi32(m6, m1, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_2_3(b0)               \+    do {                                       \+        t0 = _mm256_alignr_epi8(m5, m4, 8);    \+        t1 = _mm256_unpackhi_epi64(m1, m3);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_2_4(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m2, m7);    \+        t1 = _mm256_blend_epi32(m0, m3, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_3_1(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m3, m1);    \+        t1 = _mm256_unpackhi_epi64(m6, m5);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_3_2(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m4, m0);    \+        t1 = _mm256_unpacklo_epi64(m6, m7);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_3_3(b0)                                \+    do {                                                        \+        t0 = _mm256_alignr_epi8(m1, m7, 8);                     \+        t1 = _mm256_shuffle_epi32(m2, _MM_SHUFFLE(1, 0, 3, 2)); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0);                  \+    } while (0)++#define BLAKE2B_LOAD_MSG_3_4(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m4, m3);    \+        t1 = _mm256_unpacklo_epi64(m5, m0);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_4_1(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m4, m2);    \+        t1 = _mm256_unpacklo_epi64(m1, m5);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_4_2(b0)               \+    do {                                       \+        t0 = _mm256_blend_epi32(m3, m0, 0x33); \+        t1 = _mm256_blend_epi32(m7, m2, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_4_3(b0)               \+    do {                                       \+        t0 = _mm256_alignr_epi8(m7, m1, 8);    \+        t1 = _mm256_alignr_epi8(m3, m5, 8);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_4_4(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m6, m0);    \+        t1 = _mm256_unpacklo_epi64(m6, m4);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_5_1(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m1, m3);    \+        t1 = _mm256_unpacklo_epi64(m0, m4);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_5_2(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m6, m5);    \+        t1 = _mm256_unpackhi_epi64(m5, m1);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_5_3(b0)               \+    do {                                       \+        t0 = _mm256_alignr_epi8(m2, m0, 8);    \+        t1 = _mm256_unpackhi_epi64(m3, m7);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_5_4(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m4, m6);    \+        t1 = _mm256_alignr_epi8(m7, m2, 8);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_6_1(b0)               \+    do {                                       \+        t0 = _mm256_blend_epi32(m0, m6, 0x33); \+        t1 = _mm256_unpacklo_epi64(m7, m2);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_6_2(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m2, m7);    \+        t1 = _mm256_alignr_epi8(m5, m6, 8);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_6_3(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m4, m0);    \+        t1 = _mm256_blend_epi32(m4, m3, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_6_4(b0)                                \+    do {                                                        \+        t0 = _mm256_unpackhi_epi64(m5, m3);                     \+        t1 = _mm256_shuffle_epi32(m1, _MM_SHUFFLE(1, 0, 3, 2)); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0);                  \+    } while (0)++#define BLAKE2B_LOAD_MSG_7_1(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m6, m3);    \+        t1 = _mm256_blend_epi32(m1, m6, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_7_2(b0)               \+    do {                                       \+        t0 = _mm256_alignr_epi8(m7, m5, 8);    \+        t1 = _mm256_unpackhi_epi64(m0, m4);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_7_3(b0)               \+    do {                                       \+        t0 = _mm256_blend_epi32(m2, m1, 0x33); \+        t1 = _mm256_alignr_epi8(m4, m7, 8);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_7_4(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m5, m0);    \+        t1 = _mm256_unpacklo_epi64(m2, m3);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_8_1(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m3, m7);    \+        t1 = _mm256_alignr_epi8(m0, m5, 8);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_8_2(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m7, m4);    \+        t1 = _mm256_alignr_epi8(m4, m1, 8);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_8_3(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m5, m6);    \+        t1 = _mm256_unpackhi_epi64(m6, m0);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_8_4(b0)               \+    do {                                       \+        t0 = _mm256_alignr_epi8(m1, m2, 8);    \+        t1 = _mm256_alignr_epi8(m2, m3, 8);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_9_1(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m5, m4);    \+        t1 = _mm256_unpackhi_epi64(m3, m0);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_9_2(b0)               \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m1, m2);    \+        t1 = _mm256_blend_epi32(m2, m3, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_9_3(b0)               \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m6, m7);    \+        t1 = _mm256_unpackhi_epi64(m4, m1);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_9_4(b0)               \+    do {                                       \+        t0 = _mm256_blend_epi32(m5, m0, 0x33); \+        t1 = _mm256_unpacklo_epi64(m7, m6);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_10_1(b0)              \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m0, m1);    \+        t1 = _mm256_unpacklo_epi64(m2, m3);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_10_2(b0)              \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m0, m1);    \+        t1 = _mm256_unpackhi_epi64(m2, m3);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_10_3(b0)              \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m7, m4);    \+        t1 = _mm256_unpacklo_epi64(m5, m6);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_10_4(b0)              \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m7, m4);    \+        t1 = _mm256_unpackhi_epi64(m5, m6);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_11_1(b0)              \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m7, m2);    \+        t1 = _mm256_unpackhi_epi64(m4, m6);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_11_2(b0)              \+    do {                                       \+        t0 = _mm256_unpacklo_epi64(m5, m4);    \+        t1 = _mm256_alignr_epi8(m3, m7, 8);    \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_11_3(b0)              \+    do {                                       \+        t0 = _mm256_unpackhi_epi64(m2, m0);    \+        t1 = _mm256_blend_epi32(m5, m0, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#define BLAKE2B_LOAD_MSG_11_4(b0)              \+    do {                                       \+        t0 = _mm256_alignr_epi8(m6, m1, 8);    \+        t1 = _mm256_blend_epi32(m3, m1, 0x33); \+        b0 = _mm256_blend_epi32(t0, t1, 0xF0); \+    } while (0)++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-load-sse2.h view
@@ -0,0 +1,164 @@+/*+   BLAKE2 reference source code package - optimized C implementations++   Written in 2012 by Samuel Neves <sneves@dei.uc.pt>++   To the extent possible under law, the author(s) have dedicated all copyright+   and related and neighboring rights to this software to the public domain+   worldwide. This software is distributed without any warranty.++   You should have received a copy of the CC0 Public Domain Dedication along+   with+   this software. If not, see+   <http://creativecommons.org/publicdomain/zero/1.0/>.+*/++#ifndef blake2b_load_sse2_H+#define blake2b_load_sse2_H++#define LOAD_MSG_0_1(b0, b1)     \+    b0 = _mm_set_epi64x(m2, m0); \+    b1 = _mm_set_epi64x(m6, m4)+#define LOAD_MSG_0_2(b0, b1)     \+    b0 = _mm_set_epi64x(m3, m1); \+    b1 = _mm_set_epi64x(m7, m5)+#define LOAD_MSG_0_3(b0, b1)      \+    b0 = _mm_set_epi64x(m10, m8); \+    b1 = _mm_set_epi64x(m14, m12)+#define LOAD_MSG_0_4(b0, b1)      \+    b0 = _mm_set_epi64x(m11, m9); \+    b1 = _mm_set_epi64x(m15, m13)+#define LOAD_MSG_1_1(b0, b1)      \+    b0 = _mm_set_epi64x(m4, m14); \+    b1 = _mm_set_epi64x(m13, m9)+#define LOAD_MSG_1_2(b0, b1)      \+    b0 = _mm_set_epi64x(m8, m10); \+    b1 = _mm_set_epi64x(m6, m15)+#define LOAD_MSG_1_3(b0, b1)     \+    b0 = _mm_set_epi64x(m0, m1); \+    b1 = _mm_set_epi64x(m5, m11)+#define LOAD_MSG_1_4(b0, b1)      \+    b0 = _mm_set_epi64x(m2, m12); \+    b1 = _mm_set_epi64x(m3, m7)+#define LOAD_MSG_2_1(b0, b1)       \+    b0 = _mm_set_epi64x(m12, m11); \+    b1 = _mm_set_epi64x(m15, m5)+#define LOAD_MSG_2_2(b0, b1)     \+    b0 = _mm_set_epi64x(m0, m8); \+    b1 = _mm_set_epi64x(m13, m2)+#define LOAD_MSG_2_3(b0, b1)      \+    b0 = _mm_set_epi64x(m3, m10); \+    b1 = _mm_set_epi64x(m9, m7)+#define LOAD_MSG_2_4(b0, b1)      \+    b0 = _mm_set_epi64x(m6, m14); \+    b1 = _mm_set_epi64x(m4, m1)+#define LOAD_MSG_3_1(b0, b1)     \+    b0 = _mm_set_epi64x(m3, m7); \+    b1 = _mm_set_epi64x(m11, m13)+#define LOAD_MSG_3_2(b0, b1)     \+    b0 = _mm_set_epi64x(m1, m9); \+    b1 = _mm_set_epi64x(m14, m12)+#define LOAD_MSG_3_3(b0, b1)     \+    b0 = _mm_set_epi64x(m5, m2); \+    b1 = _mm_set_epi64x(m15, m4)+#define LOAD_MSG_3_4(b0, b1)      \+    b0 = _mm_set_epi64x(m10, m6); \+    b1 = _mm_set_epi64x(m8, m0)+#define LOAD_MSG_4_1(b0, b1)     \+    b0 = _mm_set_epi64x(m5, m9); \+    b1 = _mm_set_epi64x(m10, m2)+#define LOAD_MSG_4_2(b0, b1)     \+    b0 = _mm_set_epi64x(m7, m0); \+    b1 = _mm_set_epi64x(m15, m4)+#define LOAD_MSG_4_3(b0, b1)       \+    b0 = _mm_set_epi64x(m11, m14); \+    b1 = _mm_set_epi64x(m3, m6)+#define LOAD_MSG_4_4(b0, b1)      \+    b0 = _mm_set_epi64x(m12, m1); \+    b1 = _mm_set_epi64x(m13, m8)+#define LOAD_MSG_5_1(b0, b1)     \+    b0 = _mm_set_epi64x(m6, m2); \+    b1 = _mm_set_epi64x(m8, m0)+#define LOAD_MSG_5_2(b0, b1)       \+    b0 = _mm_set_epi64x(m10, m12); \+    b1 = _mm_set_epi64x(m3, m11)+#define LOAD_MSG_5_3(b0, b1)     \+    b0 = _mm_set_epi64x(m7, m4); \+    b1 = _mm_set_epi64x(m1, m15)+#define LOAD_MSG_5_4(b0, b1)      \+    b0 = _mm_set_epi64x(m5, m13); \+    b1 = _mm_set_epi64x(m9, m14)+#define LOAD_MSG_6_1(b0, b1)      \+    b0 = _mm_set_epi64x(m1, m12); \+    b1 = _mm_set_epi64x(m4, m14)+#define LOAD_MSG_6_2(b0, b1)      \+    b0 = _mm_set_epi64x(m15, m5); \+    b1 = _mm_set_epi64x(m10, m13)+#define LOAD_MSG_6_3(b0, b1)     \+    b0 = _mm_set_epi64x(m6, m0); \+    b1 = _mm_set_epi64x(m8, m9)+#define LOAD_MSG_6_4(b0, b1)     \+    b0 = _mm_set_epi64x(m3, m7); \+    b1 = _mm_set_epi64x(m11, m2)+#define LOAD_MSG_7_1(b0, b1)      \+    b0 = _mm_set_epi64x(m7, m13); \+    b1 = _mm_set_epi64x(m3, m12)+#define LOAD_MSG_7_2(b0, b1)       \+    b0 = _mm_set_epi64x(m14, m11); \+    b1 = _mm_set_epi64x(m9, m1)+#define LOAD_MSG_7_3(b0, b1)      \+    b0 = _mm_set_epi64x(m15, m5); \+    b1 = _mm_set_epi64x(m2, m8)+#define LOAD_MSG_7_4(b0, b1)     \+    b0 = _mm_set_epi64x(m4, m0); \+    b1 = _mm_set_epi64x(m10, m6)+#define LOAD_MSG_8_1(b0, b1)      \+    b0 = _mm_set_epi64x(m14, m6); \+    b1 = _mm_set_epi64x(m0, m11)+#define LOAD_MSG_8_2(b0, b1)      \+    b0 = _mm_set_epi64x(m9, m15); \+    b1 = _mm_set_epi64x(m8, m3)+#define LOAD_MSG_8_3(b0, b1)       \+    b0 = _mm_set_epi64x(m13, m12); \+    b1 = _mm_set_epi64x(m10, m1)+#define LOAD_MSG_8_4(b0, b1)     \+    b0 = _mm_set_epi64x(m7, m2); \+    b1 = _mm_set_epi64x(m5, m4)+#define LOAD_MSG_9_1(b0, b1)      \+    b0 = _mm_set_epi64x(m8, m10); \+    b1 = _mm_set_epi64x(m1, m7)+#define LOAD_MSG_9_2(b0, b1)     \+    b0 = _mm_set_epi64x(m4, m2); \+    b1 = _mm_set_epi64x(m5, m6)+#define LOAD_MSG_9_3(b0, b1)      \+    b0 = _mm_set_epi64x(m9, m15); \+    b1 = _mm_set_epi64x(m13, m3)+#define LOAD_MSG_9_4(b0, b1)       \+    b0 = _mm_set_epi64x(m14, m11); \+    b1 = _mm_set_epi64x(m0, m12)+#define LOAD_MSG_10_1(b0, b1)    \+    b0 = _mm_set_epi64x(m2, m0); \+    b1 = _mm_set_epi64x(m6, m4)+#define LOAD_MSG_10_2(b0, b1)    \+    b0 = _mm_set_epi64x(m3, m1); \+    b1 = _mm_set_epi64x(m7, m5)+#define LOAD_MSG_10_3(b0, b1)     \+    b0 = _mm_set_epi64x(m10, m8); \+    b1 = _mm_set_epi64x(m14, m12)+#define LOAD_MSG_10_4(b0, b1)     \+    b0 = _mm_set_epi64x(m11, m9); \+    b1 = _mm_set_epi64x(m15, m13)+#define LOAD_MSG_11_1(b0, b1)     \+    b0 = _mm_set_epi64x(m4, m14); \+    b1 = _mm_set_epi64x(m13, m9)+#define LOAD_MSG_11_2(b0, b1)     \+    b0 = _mm_set_epi64x(m8, m10); \+    b1 = _mm_set_epi64x(m6, m15)+#define LOAD_MSG_11_3(b0, b1)    \+    b0 = _mm_set_epi64x(m0, m1); \+    b1 = _mm_set_epi64x(m5, m11)+#define LOAD_MSG_11_4(b0, b1)     \+    b0 = _mm_set_epi64x(m2, m12); \+    b1 = _mm_set_epi64x(m3, m7)++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-load-sse41.h view
@@ -0,0 +1,307 @@+/*+   BLAKE2 reference source code package - optimized C implementations++   Written in 2012 by Samuel Neves <sneves@dei.uc.pt>++   To the extent possible under law, the author(s) have dedicated all copyright+   and related and neighboring rights to this software to the public domain+   worldwide. This software is distributed without any warranty.++   You should have received a copy of the CC0 Public Domain Dedication along+   with+   this software. If not, see+   <http://creativecommons.org/publicdomain/zero/1.0/>.+*/++#ifndef blake2b_load_sse41_H+#define blake2b_load_sse41_H++#define LOAD_MSG_0_1(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m0, m1); \+        b1 = _mm_unpacklo_epi64(m2, m3); \+    } while (0)++#define LOAD_MSG_0_2(b0, b1)             \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m0, m1); \+        b1 = _mm_unpackhi_epi64(m2, m3); \+    } while (0)++#define LOAD_MSG_0_3(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m4, m5); \+        b1 = _mm_unpacklo_epi64(m6, m7); \+    } while (0)++#define LOAD_MSG_0_4(b0, b1)             \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m4, m5); \+        b1 = _mm_unpackhi_epi64(m6, m7); \+    } while (0)++#define LOAD_MSG_1_1(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m7, m2); \+        b1 = _mm_unpackhi_epi64(m4, m6); \+    } while (0)++#define LOAD_MSG_1_2(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m5, m4); \+        b1 = _mm_alignr_epi8(m3, m7, 8); \+    } while (0)++#define LOAD_MSG_1_3(b0, b1)                                 \+    do {                                                     \+        b0 = _mm_shuffle_epi32(m0, _MM_SHUFFLE(1, 0, 3, 2)); \+        b1 = _mm_unpackhi_epi64(m5, m2);                     \+    } while (0)++#define LOAD_MSG_1_4(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m6, m1); \+        b1 = _mm_unpackhi_epi64(m3, m1); \+    } while (0)++#define LOAD_MSG_2_1(b0, b1)             \+    do {                                 \+        b0 = _mm_alignr_epi8(m6, m5, 8); \+        b1 = _mm_unpackhi_epi64(m2, m7); \+    } while (0)++#define LOAD_MSG_2_2(b0, b1)                \+    do {                                    \+        b0 = _mm_unpacklo_epi64(m4, m0);    \+        b1 = _mm_blend_epi16(m1, m6, 0xF0); \+    } while (0)++#define LOAD_MSG_2_3(b0, b1)                \+    do {                                    \+        b0 = _mm_blend_epi16(m5, m1, 0xF0); \+        b1 = _mm_unpackhi_epi64(m3, m4);    \+    } while (0)++#define LOAD_MSG_2_4(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m7, m3); \+        b1 = _mm_alignr_epi8(m2, m0, 8); \+    } while (0)++#define LOAD_MSG_3_1(b0, b1)             \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m3, m1); \+        b1 = _mm_unpackhi_epi64(m6, m5); \+    } while (0)++#define LOAD_MSG_3_2(b0, b1)             \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m4, m0); \+        b1 = _mm_unpacklo_epi64(m6, m7); \+    } while (0)++#define LOAD_MSG_3_3(b0, b1)                \+    do {                                    \+        b0 = _mm_blend_epi16(m1, m2, 0xF0); \+        b1 = _mm_blend_epi16(m2, m7, 0xF0); \+    } while (0)++#define LOAD_MSG_3_4(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m3, m5); \+        b1 = _mm_unpacklo_epi64(m0, m4); \+    } while (0)++#define LOAD_MSG_4_1(b0, b1)             \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m4, m2); \+        b1 = _mm_unpacklo_epi64(m1, m5); \+    } while (0)++#define LOAD_MSG_4_2(b0, b1)                \+    do {                                    \+        b0 = _mm_blend_epi16(m0, m3, 0xF0); \+        b1 = _mm_blend_epi16(m2, m7, 0xF0); \+    } while (0)++#define LOAD_MSG_4_3(b0, b1)                \+    do {                                    \+        b0 = _mm_blend_epi16(m7, m5, 0xF0); \+        b1 = _mm_blend_epi16(m3, m1, 0xF0); \+    } while (0)++#define LOAD_MSG_4_4(b0, b1)                \+    do {                                    \+        b0 = _mm_alignr_epi8(m6, m0, 8);    \+        b1 = _mm_blend_epi16(m4, m6, 0xF0); \+    } while (0)++#define LOAD_MSG_5_1(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m1, m3); \+        b1 = _mm_unpacklo_epi64(m0, m4); \+    } while (0)++#define LOAD_MSG_5_2(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m6, m5); \+        b1 = _mm_unpackhi_epi64(m5, m1); \+    } while (0)++#define LOAD_MSG_5_3(b0, b1)                \+    do {                                    \+        b0 = _mm_blend_epi16(m2, m3, 0xF0); \+        b1 = _mm_unpackhi_epi64(m7, m0);    \+    } while (0)++#define LOAD_MSG_5_4(b0, b1)                \+    do {                                    \+        b0 = _mm_unpackhi_epi64(m6, m2);    \+        b1 = _mm_blend_epi16(m7, m4, 0xF0); \+    } while (0)++#define LOAD_MSG_6_1(b0, b1)                \+    do {                                    \+        b0 = _mm_blend_epi16(m6, m0, 0xF0); \+        b1 = _mm_unpacklo_epi64(m7, m2);    \+    } while (0)++#define LOAD_MSG_6_2(b0, b1)             \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m2, m7); \+        b1 = _mm_alignr_epi8(m5, m6, 8); \+    } while (0)++#define LOAD_MSG_6_3(b0, b1)                                 \+    do {                                                     \+        b0 = _mm_unpacklo_epi64(m0, m3);                     \+        b1 = _mm_shuffle_epi32(m4, _MM_SHUFFLE(1, 0, 3, 2)); \+    } while (0)++#define LOAD_MSG_6_4(b0, b1)                \+    do {                                    \+        b0 = _mm_unpackhi_epi64(m3, m1);    \+        b1 = _mm_blend_epi16(m1, m5, 0xF0); \+    } while (0)++#define LOAD_MSG_7_1(b0, b1)                \+    do {                                    \+        b0 = _mm_unpackhi_epi64(m6, m3);    \+        b1 = _mm_blend_epi16(m6, m1, 0xF0); \+    } while (0)++#define LOAD_MSG_7_2(b0, b1)             \+    do {                                 \+        b0 = _mm_alignr_epi8(m7, m5, 8); \+        b1 = _mm_unpackhi_epi64(m0, m4); \+    } while (0)++#define LOAD_MSG_7_3(b0, b1)             \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m2, m7); \+        b1 = _mm_unpacklo_epi64(m4, m1); \+    } while (0)++#define LOAD_MSG_7_4(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m0, m2); \+        b1 = _mm_unpacklo_epi64(m3, m5); \+    } while (0)++#define LOAD_MSG_8_1(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m3, m7); \+        b1 = _mm_alignr_epi8(m0, m5, 8); \+    } while (0)++#define LOAD_MSG_8_2(b0, b1)             \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m7, m4); \+        b1 = _mm_alignr_epi8(m4, m1, 8); \+    } while (0)++#define LOAD_MSG_8_3(b0, b1)             \+    do {                                 \+        b0 = m6;                         \+        b1 = _mm_alignr_epi8(m5, m0, 8); \+    } while (0)++#define LOAD_MSG_8_4(b0, b1)                \+    do {                                    \+        b0 = _mm_blend_epi16(m1, m3, 0xF0); \+        b1 = m2;                            \+    } while (0)++#define LOAD_MSG_9_1(b0, b1)             \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m5, m4); \+        b1 = _mm_unpackhi_epi64(m3, m0); \+    } while (0)++#define LOAD_MSG_9_2(b0, b1)                \+    do {                                    \+        b0 = _mm_unpacklo_epi64(m1, m2);    \+        b1 = _mm_blend_epi16(m3, m2, 0xF0); \+    } while (0)++#define LOAD_MSG_9_3(b0, b1)             \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m7, m4); \+        b1 = _mm_unpackhi_epi64(m1, m6); \+    } while (0)++#define LOAD_MSG_9_4(b0, b1)             \+    do {                                 \+        b0 = _mm_alignr_epi8(m7, m5, 8); \+        b1 = _mm_unpacklo_epi64(m6, m0); \+    } while (0)++#define LOAD_MSG_10_1(b0, b1)            \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m0, m1); \+        b1 = _mm_unpacklo_epi64(m2, m3); \+    } while (0)++#define LOAD_MSG_10_2(b0, b1)            \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m0, m1); \+        b1 = _mm_unpackhi_epi64(m2, m3); \+    } while (0)++#define LOAD_MSG_10_3(b0, b1)            \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m4, m5); \+        b1 = _mm_unpacklo_epi64(m6, m7); \+    } while (0)++#define LOAD_MSG_10_4(b0, b1)            \+    do {                                 \+        b0 = _mm_unpackhi_epi64(m4, m5); \+        b1 = _mm_unpackhi_epi64(m6, m7); \+    } while (0)++#define LOAD_MSG_11_1(b0, b1)            \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m7, m2); \+        b1 = _mm_unpackhi_epi64(m4, m6); \+    } while (0)++#define LOAD_MSG_11_2(b0, b1)            \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m5, m4); \+        b1 = _mm_alignr_epi8(m3, m7, 8); \+    } while (0)++#define LOAD_MSG_11_3(b0, b1)                                \+    do {                                                     \+        b0 = _mm_shuffle_epi32(m0, _MM_SHUFFLE(1, 0, 3, 2)); \+        b1 = _mm_unpackhi_epi64(m5, m2);                     \+    } while (0)++#define LOAD_MSG_11_4(b0, b1)            \+    do {                                 \+        b0 = _mm_unpacklo_epi64(m6, m1); \+        b1 = _mm_unpackhi_epi64(m3, m1); \+    } while (0)++#endif
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c view
@@ -0,0 +1,438 @@+/*+   BLAKE2 reference source code package - C implementations++   Written in 2012 by Samuel Neves <sneves@dei.uc.pt>++   To the extent possible under law, the author(s) have dedicated all copyright+   and related and neighboring rights to this software to the public domain+   worldwide. This software is distributed without any warranty.++   You should have received a copy of the CC0 Public Domain Dedication along+   with+   this software. If not, see+   <http://creativecommons.org/publicdomain/zero/1.0/>.+*/++#include <assert.h>+#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include "blake2.h"+#include "core.h"+#include "private/common.h"+#include "runtime.h"+#include "utils.h"++static blake2b_compress_fn blake2b_compress = blake2b_compress_ref;++static const uint64_t blake2b_IV[8] = {+    0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,+    0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,+    0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL+};++/* LCOV_EXCL_START */+static inline int+blake2b_set_lastnode(blake2b_state *S)+{+    S->f[1] = -1;+    return 0;+}+/* LCOV_EXCL_STOP */++static inline int+blake2b_is_lastblock(const blake2b_state *S)+{+    return S->f[0] != 0;+}++static inline int+blake2b_set_lastblock(blake2b_state *S)+{+    if (S->last_node) {+        blake2b_set_lastnode(S);+    }+    S->f[0] = -1;+    return 0;+}++static inline int+blake2b_increment_counter(blake2b_state *S, const uint64_t inc)+{+#ifdef HAVE_TI_MODE+    uint128_t t = ((uint128_t) S->t[1] << 64) | S->t[0];+    t += inc;+    S->t[0] = (uint64_t)(t >> 0);+    S->t[1] = (uint64_t)(t >> 64);+#else+    S->t[0] += inc;+    S->t[1] += (S->t[0] < inc);+#endif+    return 0;+}++/* Parameter-related functions */+static inline int+blake2b_param_set_salt(blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES])+{+    memcpy(P->salt, salt, BLAKE2B_SALTBYTES);+    return 0;+}++static inline int+blake2b_param_set_personal(blake2b_param *P,+                           const uint8_t  personal[BLAKE2B_PERSONALBYTES])+{+    memcpy(P->personal, personal, BLAKE2B_PERSONALBYTES);+    return 0;+}++static inline int+blake2b_init0(blake2b_state *S)+{+    int i;++    for (i  = 0; i < 8; i++) {+        S->h[i] = blake2b_IV[i];+    }+    /* zero everything between .t and .last_node */+    memset((void *) &S->t, 0,+           offsetof(blake2b_state, last_node) + sizeof(S->last_node)+           - offsetof(blake2b_state, t));+    return 0;+}++/* init xors IV with input parameter block */+int+blake2b_init_param(blake2b_state *S, const blake2b_param *P)+{+    size_t         i;+    const uint8_t *p;++    COMPILER_ASSERT(sizeof *P == 64);+    blake2b_init0(S);+    p = (const uint8_t *) (P);++    /* IV XOR ParamBlock */+    for (i = 0; i < 8; i++) {+        S->h[i] ^= LOAD64_LE(p + sizeof(S->h[i]) * i);+    }+    return 0;+}++int+blake2b_init(blake2b_state *S, const uint8_t outlen)+{+    blake2b_param P[1];++    if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {+        sodium_misuse();+    }+    P->digest_length = outlen;+    P->key_length    = 0;+    P->fanout        = 1;+    P->depth         = 1;+    STORE32_LE(P->leaf_length, 0);+    STORE64_LE(P->node_offset, 0);+    P->node_depth   = 0;+    P->inner_length = 0;+    memset(P->reserved, 0, sizeof(P->reserved));+    memset(P->salt, 0, sizeof(P->salt));+    memset(P->personal, 0, sizeof(P->personal));+    return blake2b_init_param(S, P);+}++int+blake2b_init_salt_personal(blake2b_state *S, const uint8_t outlen,+                           const void *salt, const void *personal)+{+    blake2b_param P[1];++    if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {+        sodium_misuse();+    }+    P->digest_length = outlen;+    P->key_length    = 0;+    P->fanout        = 1;+    P->depth         = 1;+    STORE32_LE(P->leaf_length, 0);+    STORE64_LE(P->node_offset, 0);+    P->node_depth   = 0;+    P->inner_length = 0;+    memset(P->reserved, 0, sizeof(P->reserved));+    if (salt != NULL) {+        blake2b_param_set_salt(P, (const uint8_t *) salt);+    } else {+        memset(P->salt, 0, sizeof(P->salt));+    }+    if (personal != NULL) {+        blake2b_param_set_personal(P, (const uint8_t *) personal);+    } else {+        memset(P->personal, 0, sizeof(P->personal));+    }+    return blake2b_init_param(S, P);+}++int+blake2b_init_key(blake2b_state *S, const uint8_t outlen, const void *key,+                 const uint8_t keylen)+{+    blake2b_param P[1];++    if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {+        sodium_misuse();+    }+    if (!key || !keylen || keylen > BLAKE2B_KEYBYTES) {+        sodium_misuse(); /* does not return */+    }+    P->digest_length = outlen;+    P->key_length    = keylen;+    P->fanout        = 1;+    P->depth         = 1;+    STORE32_LE(P->leaf_length, 0);+    STORE64_LE(P->node_offset, 0);+    P->node_depth   = 0;+    P->inner_length = 0;+    memset(P->reserved, 0, sizeof(P->reserved));+    memset(P->salt, 0, sizeof(P->salt));+    memset(P->personal, 0, sizeof(P->personal));++    if (blake2b_init_param(S, P) < 0) {+        sodium_misuse();+    }+    {+        uint8_t block[BLAKE2B_BLOCKBYTES];+        memset(block, 0, BLAKE2B_BLOCKBYTES);+        memcpy(block, key, keylen); /* key and keylen cannot be 0 */+        blake2b_update(S, block, BLAKE2B_BLOCKBYTES);+        sodium_memzero(block, BLAKE2B_BLOCKBYTES); /* Burn the key from stack */+    }+    return 0;+}++int+blake2b_init_key_salt_personal(blake2b_state *S, const uint8_t outlen,+                               const void *key, const uint8_t keylen,+                               const void *salt, const void *personal)+{+    blake2b_param P[1];++    if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {+        sodium_misuse();+    }+    if (!key || !keylen || keylen > BLAKE2B_KEYBYTES) {+        sodium_misuse(); /* does not return */+    }+    P->digest_length = outlen;+    P->key_length    = keylen;+    P->fanout        = 1;+    P->depth         = 1;+    STORE32_LE(P->leaf_length, 0);+    STORE64_LE(P->node_offset, 0);+    P->node_depth   = 0;+    P->inner_length = 0;+    memset(P->reserved, 0, sizeof(P->reserved));+    if (salt != NULL) {+        blake2b_param_set_salt(P, (const uint8_t *) salt);+    } else {+        memset(P->salt, 0, sizeof(P->salt));+    }+    if (personal != NULL) {+        blake2b_param_set_personal(P, (const uint8_t *) personal);+    } else {+        memset(P->personal, 0, sizeof(P->personal));+    }++    if (blake2b_init_param(S, P) < 0) {+        sodium_misuse();+    }+    {+        uint8_t block[BLAKE2B_BLOCKBYTES];+        memset(block, 0, BLAKE2B_BLOCKBYTES);+        memcpy(block, key, keylen); /* key and keylen cannot be 0 */+        blake2b_update(S, block, BLAKE2B_BLOCKBYTES);+        sodium_memzero(block, BLAKE2B_BLOCKBYTES); /* Burn the key from stack */+    }+    return 0;+}++/* inlen now in bytes */+int+blake2b_update(blake2b_state *S, const uint8_t *in, uint64_t inlen)+{+    while (inlen > 0) {+        size_t left = S->buflen;+        size_t fill = 2 * BLAKE2B_BLOCKBYTES - left;++        if (inlen > fill) {+            memcpy(S->buf + left, in, fill); /* Fill buffer */+            S->buflen += fill;+            blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);+            blake2b_compress(S, S->buf); /* Compress */+            memcpy(S->buf, S->buf + BLAKE2B_BLOCKBYTES,+                   BLAKE2B_BLOCKBYTES); /* Shift buffer left */+            S->buflen -= BLAKE2B_BLOCKBYTES;+            in += fill;+            inlen -= fill;+        } else /* inlen <= fill */+        {+            memcpy(S->buf + left, in, inlen);+            S->buflen += inlen; /* Be lazy, do not compress */+            in += inlen;+            inlen -= inlen;+        }+    }++    return 0;+}++int+blake2b_final(blake2b_state *S, uint8_t *out, uint8_t outlen)+{+    unsigned char buffer[BLAKE2B_OUTBYTES];++    if (!outlen || outlen > BLAKE2B_OUTBYTES) {+        sodium_misuse();+    }+    if (blake2b_is_lastblock(S)) {+        return -1;+    }+    if (S->buflen > BLAKE2B_BLOCKBYTES) {+        blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);+        blake2b_compress(S, S->buf);+        S->buflen -= BLAKE2B_BLOCKBYTES;+        assert(S->buflen <= BLAKE2B_BLOCKBYTES);+        memcpy(S->buf, S->buf + BLAKE2B_BLOCKBYTES, S->buflen);+    }++    blake2b_increment_counter(S, S->buflen);+    blake2b_set_lastblock(S);+    memset(S->buf + S->buflen, 0,+           2 * BLAKE2B_BLOCKBYTES - S->buflen); /* Padding */+    blake2b_compress(S, S->buf);++    COMPILER_ASSERT(sizeof buffer == 64U);+    STORE64_LE(buffer + 8 * 0, S->h[0]);+    STORE64_LE(buffer + 8 * 1, S->h[1]);+    STORE64_LE(buffer + 8 * 2, S->h[2]);+    STORE64_LE(buffer + 8 * 3, S->h[3]);+    STORE64_LE(buffer + 8 * 4, S->h[4]);+    STORE64_LE(buffer + 8 * 5, S->h[5]);+    STORE64_LE(buffer + 8 * 6, S->h[6]);+    STORE64_LE(buffer + 8 * 7, S->h[7]);+    memcpy(out, buffer, outlen); /* outlen <= BLAKE2B_OUTBYTES (64) */++    sodium_memzero(S->h, sizeof S->h);+    sodium_memzero(S->buf, sizeof S->buf);++    return 0;+}++/* inlen, at least, should be uint64_t. Others can be size_t. */+int+blake2b(uint8_t *out, const void *in, const void *key, const uint8_t outlen,+        const uint64_t inlen, uint8_t keylen)+{+    CRYPTO_ALIGN(64) blake2b_state S[1];++    /* Verify parameters */+    if (NULL == in && inlen > 0) {+        sodium_misuse();+    }+    if (NULL == out) {+        sodium_misuse();+    }+    if (!outlen || outlen > BLAKE2B_OUTBYTES) {+        sodium_misuse();+    }+    if (NULL == key && keylen > 0) {+        sodium_misuse();+    }+    if (keylen > BLAKE2B_KEYBYTES) {+        sodium_misuse();+    }+    if (keylen > 0) {+        if (blake2b_init_key(S, outlen, key, keylen) < 0) {+            sodium_misuse();+        }+    } else {+        if (blake2b_init(S, outlen) < 0) {+            sodium_misuse();+        }+    }++    blake2b_update(S, (const uint8_t *) in, inlen);+    blake2b_final(S, out, outlen);+    return 0;+}++int+blake2b_salt_personal(uint8_t *out, const void *in, const void *key,+                      const uint8_t outlen, const uint64_t inlen,+                      uint8_t keylen, const void *salt, const void *personal)+{+    CRYPTO_ALIGN(64) blake2b_state S[1];++    /* Verify parameters */+    if (NULL == in && inlen > 0) {+        sodium_misuse();+    }+    if (NULL == out) {+        sodium_misuse();+    }+    if (!outlen || outlen > BLAKE2B_OUTBYTES) {+        sodium_misuse();+    }+    if (NULL == key && keylen > 0) {+        sodium_misuse();+    }+    if (keylen > BLAKE2B_KEYBYTES) {+        sodium_misuse();+    }+    if (keylen > 0) {+        if (blake2b_init_key_salt_personal(S, outlen, key, keylen, salt,+                                           personal) < 0) {+            sodium_misuse();+        }+    } else {+        if (blake2b_init_salt_personal(S, outlen, salt, personal) < 0) {+            sodium_misuse();+        }+    }++    blake2b_update(S, (const uint8_t *) in, inlen);+    blake2b_final(S, out, outlen);+    return 0;+}++int+blake2b_pick_best_implementation(void)+{+/* LCOV_EXCL_START */+#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_TMMINTRIN_H) && \+    defined(HAVE_SMMINTRIN_H)+    if (sodium_runtime_has_avx2()) {+        blake2b_compress = blake2b_compress_avx2;+        return 0;+    }+#endif+#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && \+    defined(HAVE_SMMINTRIN_H)+    if (sodium_runtime_has_sse41()) {+        blake2b_compress = blake2b_compress_sse41;+        return 0;+    }+#endif+#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)+    if (sodium_runtime_has_ssse3()) {+        blake2b_compress = blake2b_compress_ssse3;+        return 0;+    }+#endif+    blake2b_compress = blake2b_compress_ref;++    return 0;+    /* LCOV_EXCL_STOP */+}
+ vendor/external/libsodium/crypto_generichash/blake2b/ref/generichash_blake2b.c view
@@ -0,0 +1,116 @@++#include <assert.h>+#include <limits.h>+#include <stdint.h>++#include "blake2.h"+#include "crypto_generichash_blake2b.h"+#include "private/common.h"+#include "private/implementations.h"++int+crypto_generichash_blake2b(unsigned char *out, size_t outlen,+                           const unsigned char *in, unsigned long long inlen,+                           const unsigned char *key, size_t keylen)+{+    if (outlen <= 0U || outlen > BLAKE2B_OUTBYTES ||+        keylen > BLAKE2B_KEYBYTES || inlen > UINT64_MAX) {+        return -1;+    }+    assert(outlen <= UINT8_MAX);+    assert(keylen <= UINT8_MAX);++    return blake2b((uint8_t *) out, in, key, (uint8_t) outlen, (uint64_t) inlen,+                   (uint8_t) keylen);+}++int+crypto_generichash_blake2b_salt_personal(+    unsigned char *out, size_t outlen, const unsigned char *in,+    unsigned long long inlen, const unsigned char *key, size_t keylen,+    const unsigned char *salt, const unsigned char *personal)+{+    if (outlen <= 0U || outlen > BLAKE2B_OUTBYTES ||+        keylen > BLAKE2B_KEYBYTES || inlen > UINT64_MAX) {+        return -1;+    }+    assert(outlen <= UINT8_MAX);+    assert(keylen <= UINT8_MAX);++    return blake2b_salt_personal((uint8_t *) out, in, key, (uint8_t) outlen,+                                 (uint64_t) inlen, (uint8_t) keylen, salt,+                                 personal);+}++int+crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state,+                                const unsigned char *key, const size_t keylen,+                                const size_t outlen)+{+    if (outlen <= 0U || outlen > BLAKE2B_OUTBYTES ||+        keylen > BLAKE2B_KEYBYTES) {+        return -1;+    }+    assert(outlen <= UINT8_MAX);+    assert(keylen <= UINT8_MAX);+    COMPILER_ASSERT(sizeof(blake2b_state) <= sizeof *state);+    if (key == NULL || keylen <= 0U) {+        if (blake2b_init((blake2b_state *) (void *) state, (uint8_t) outlen) != 0) {+            return -1; /* LCOV_EXCL_LINE */+        }+    } else if (blake2b_init_key((blake2b_state *) (void *) state, (uint8_t) outlen, key,+                                (uint8_t) keylen) != 0) {+        return -1; /* LCOV_EXCL_LINE */+    }+    return 0;+}++int+crypto_generichash_blake2b_init_salt_personal(+    crypto_generichash_blake2b_state *state, const unsigned char *key,+    const size_t keylen, const size_t outlen, const unsigned char *salt,+    const unsigned char *personal)+{+    if (outlen <= 0U || outlen > BLAKE2B_OUTBYTES ||+        keylen > BLAKE2B_KEYBYTES) {+        return -1;+    }+    assert(outlen <= UINT8_MAX);+    assert(keylen <= UINT8_MAX);+    if (key == NULL || keylen <= 0U) {+        if (blake2b_init_salt_personal((blake2b_state *) (void *) state,+                                       (uint8_t) outlen, salt, personal) != 0) {+            return -1; /* LCOV_EXCL_LINE */+        }+    } else if (blake2b_init_key_salt_personal((blake2b_state *) (void *) state,+                                              (uint8_t) outlen, key,+                                              (uint8_t) keylen, salt,+                                              personal) != 0) {+        return -1; /* LCOV_EXCL_LINE */+    }+    return 0;+}++int+crypto_generichash_blake2b_update(crypto_generichash_blake2b_state *state,+                                  const unsigned char *in,+                                  unsigned long long inlen)+{+    return blake2b_update((blake2b_state *) (void *) state,+                          (const uint8_t *) in, (uint64_t) inlen);+}++int+crypto_generichash_blake2b_final(crypto_generichash_blake2b_state *state,+                                 unsigned char *out, const size_t outlen)+{+    assert(outlen <= UINT8_MAX);+    return blake2b_final((blake2b_state *) (void *) state,+                         (uint8_t *) out, (uint8_t) outlen);+}++int+_crypto_generichash_blake2b_pick_best_implementation(void)+{+    return blake2b_pick_best_implementation();+}
+ vendor/external/libsodium/crypto_generichash/crypto_generichash.c view
@@ -0,0 +1,91 @@++#include "crypto_generichash.h"+#include "randombytes.h"++size_t+crypto_generichash_bytes_min(void)+{+    return crypto_generichash_BYTES_MIN;+}++size_t+crypto_generichash_bytes_max(void)+{+    return crypto_generichash_BYTES_MAX;+}++size_t+crypto_generichash_bytes(void)+{+    return crypto_generichash_BYTES;+}++size_t+crypto_generichash_keybytes_min(void)+{+    return crypto_generichash_KEYBYTES_MIN;+}++size_t+crypto_generichash_keybytes_max(void)+{+    return crypto_generichash_KEYBYTES_MAX;+}++size_t+crypto_generichash_keybytes(void)+{+    return crypto_generichash_KEYBYTES;+}++const char *+crypto_generichash_primitive(void)+{+    return crypto_generichash_PRIMITIVE;+}++size_t+crypto_generichash_statebytes(void)+{+    return (sizeof(crypto_generichash_state) + (size_t) 63U) & ~(size_t) 63U;+}++int+crypto_generichash(unsigned char *out, size_t outlen, const unsigned char *in,+                   unsigned long long inlen, const unsigned char *key,+                   size_t keylen)+{+    return crypto_generichash_blake2b(out, outlen, in, inlen, key, keylen);+}++int+crypto_generichash_init(crypto_generichash_state *state,+                        const unsigned char *key,+                        const size_t keylen, const size_t outlen)+{+    return crypto_generichash_blake2b_init+        ((crypto_generichash_blake2b_state *) state, key, keylen, outlen);+}++int+crypto_generichash_update(crypto_generichash_state *state,+                          const unsigned char *in,+                          unsigned long long inlen)+{+    return crypto_generichash_blake2b_update+        ((crypto_generichash_blake2b_state *) state, in, inlen);+}++int+crypto_generichash_final(crypto_generichash_state *state,+                         unsigned char *out, const size_t outlen)+{+    return crypto_generichash_blake2b_final+        ((crypto_generichash_blake2b_state *) state, out, outlen);+}++void+crypto_generichash_keygen(unsigned char k[crypto_generichash_KEYBYTES])+{+    randombytes_buf(k, crypto_generichash_KEYBYTES);+}
+ vendor/external/libsodium/crypto_hash/crypto_hash.c view
@@ -0,0 +1,20 @@++#include "crypto_hash.h"++size_t+crypto_hash_bytes(void)+{+    return crypto_hash_BYTES;+}++int+crypto_hash(unsigned char *out, const unsigned char *in,+            unsigned long long inlen)+{+    return crypto_hash_sha512(out, in, inlen);+}++const char *+crypto_hash_primitive(void) {+    return crypto_hash_PRIMITIVE;+}
+ vendor/external/libsodium/crypto_hash/sha256/cp/hash_sha256_cp.c view
@@ -0,0 +1,256 @@++/*-+ * Copyright 2005,2007,2009 Colin Percival+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or without+ * modification, are permitted provided that the following conditions+ * are met:+ * 1. Redistributions of source code must retain the above copyright+ *    notice, this list of conditions and the following disclaimer.+ * 2. Redistributions in binary form must reproduce the above copyright+ *    notice, this list of conditions and the following disclaimer in the+ *    documentation and/or other materials provided with the distribution.+ *+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+ * SUCH DAMAGE.+ *+ */++#include <limits.h>+#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include <sys/types.h>++#include "crypto_hash_sha256.h"+#include "private/common.h"+#include "utils.h"++static void+be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len)+{+    size_t i;++    for (i = 0; i < len / 4; i++) {+        STORE32_BE(dst + i * 4, src[i]);+    }+}++static void+be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len)+{+    size_t i;++    for (i = 0; i < len / 4; i++) {+        dst[i] = LOAD32_BE(src + i * 4);+    }+}++static const uint32_t Krnd[64] = {+    0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,+    0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,+    0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,+    0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,+    0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,+    0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,+    0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,+    0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,+    0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,+    0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,+    0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2+};++#define Ch(x, y, z) ((x & (y ^ z)) ^ z)+#define Maj(x, y, z) ((x & (y | z)) | (y & z))+#define SHR(x, n) (x >> n)+#define ROTR(x, n) ROTR32(x, n)+#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))+#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))+#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3))+#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10))++#define RND(a, b, c, d, e, f, g, h, k) \+    h += S1(e) + Ch(e, f, g) + k;      \+    d += h;                            \+    h += S0(a) + Maj(a, b, c);++#define RNDr(S, W, i, ii)                                                   \+    RND(S[(64 - i) % 8], S[(65 - i) % 8], S[(66 - i) % 8], S[(67 - i) % 8], \+        S[(68 - i) % 8], S[(69 - i) % 8], S[(70 - i) % 8], S[(71 - i) % 8], \+        W[i + ii] + Krnd[i + ii])++#define MSCH(W, ii, i) \+    W[i + ii + 16] =   \+        s1(W[i + ii + 14]) + W[i + ii + 9] + s0(W[i + ii + 1]) + W[i + ii]++static void+SHA256_Transform(uint32_t state[8], const uint8_t block[64], uint32_t W[64],+                 uint32_t S[8])+{+    int i;++    be32dec_vect(W, block, 64);+    memcpy(S, state, 32);+    for (i = 0; i < 64; i += 16) {+        RNDr(S, W, 0, i);+        RNDr(S, W, 1, i);+        RNDr(S, W, 2, i);+        RNDr(S, W, 3, i);+        RNDr(S, W, 4, i);+        RNDr(S, W, 5, i);+        RNDr(S, W, 6, i);+        RNDr(S, W, 7, i);+        RNDr(S, W, 8, i);+        RNDr(S, W, 9, i);+        RNDr(S, W, 10, i);+        RNDr(S, W, 11, i);+        RNDr(S, W, 12, i);+        RNDr(S, W, 13, i);+        RNDr(S, W, 14, i);+        RNDr(S, W, 15, i);+        if (i == 48) {+            break;+        }+        MSCH(W, 0, i);+        MSCH(W, 1, i);+        MSCH(W, 2, i);+        MSCH(W, 3, i);+        MSCH(W, 4, i);+        MSCH(W, 5, i);+        MSCH(W, 6, i);+        MSCH(W, 7, i);+        MSCH(W, 8, i);+        MSCH(W, 9, i);+        MSCH(W, 10, i);+        MSCH(W, 11, i);+        MSCH(W, 12, i);+        MSCH(W, 13, i);+        MSCH(W, 14, i);+        MSCH(W, 15, i);+    }+    for (i = 0; i < 8; i++) {+        state[i] += S[i];+    }+}++static const uint8_t PAD[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+                                 0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+                                 0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+                                 0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+                                 0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };++static void+SHA256_Pad(crypto_hash_sha256_state *state, uint32_t tmp32[64 + 8])+{+    unsigned int r;+    unsigned int i;++    ACQUIRE_FENCE;+    r = (unsigned int) ((state->count >> 3) & 0x3f);+    if (r < 56) {+        for (i = 0; i < 56 - r; i++) {+            state->buf[r + i] = PAD[i];+        }+    } else {+        for (i = 0; i < 64 - r; i++) {+            state->buf[r + i] = PAD[i];+        }+        SHA256_Transform(state->state, state->buf, &tmp32[0], &tmp32[64]);+        memset(&state->buf[0], 0, 56);+    }+    STORE64_BE(&state->buf[56], state->count);+    SHA256_Transform(state->state, state->buf, &tmp32[0], &tmp32[64]);+}++int+crypto_hash_sha256_init(crypto_hash_sha256_state *state)+{+    static const uint32_t sha256_initial_state[8] = { 0x6a09e667, 0xbb67ae85,+                                                      0x3c6ef372, 0xa54ff53a,+                                                      0x510e527f, 0x9b05688c,+                                                      0x1f83d9ab, 0x5be0cd19 };++    state->count = (uint64_t) 0U;+    memcpy(state->state, sha256_initial_state, sizeof sha256_initial_state);++    return 0;+}++int+crypto_hash_sha256_update(crypto_hash_sha256_state *state,+                          const unsigned char *in, unsigned long long inlen)+{+    uint32_t           tmp32[64 + 8];+    unsigned long long i;+    unsigned long long r;++    if (inlen <= 0U) {+        return 0;+    }+    ACQUIRE_FENCE;+    r = (unsigned long long) ((state->count >> 3) & 0x3f);++    state->count += ((uint64_t) inlen) << 3;+    if (inlen < 64 - r) {+        for (i = 0; i < inlen; i++) {+            state->buf[r + i] = in[i];+        }+        return 0;+    }+    for (i = 0; i < 64 - r; i++) {+        state->buf[r + i] = in[i];+    }+    SHA256_Transform(state->state, state->buf, &tmp32[0], &tmp32[64]);+    in += 64 - r;+    inlen -= 64 - r;++    while (inlen >= 64) {+        SHA256_Transform(state->state, in, &tmp32[0], &tmp32[64]);+        in += 64;+        inlen -= 64;+    }+    inlen &= 63;+    for (i = 0; i < inlen; i++) {+        state->buf[i] = in[i];+    }+    sodium_memzero((void *) tmp32, sizeof tmp32);++    return 0;+}++int+crypto_hash_sha256_final(crypto_hash_sha256_state *state, unsigned char *out)+{+    uint32_t tmp32[64 + 8];++    SHA256_Pad(state, tmp32);+    be32enc_vect(out, state->state, 32);+    sodium_memzero((void *) tmp32, sizeof tmp32);+    sodium_memzero((void *) state, sizeof *state);++    return 0;+}++int+crypto_hash_sha256(unsigned char *out, const unsigned char *in,+                   unsigned long long inlen)+{+    crypto_hash_sha256_state state;++    crypto_hash_sha256_init(&state);+    crypto_hash_sha256_update(&state, in, inlen);+    crypto_hash_sha256_final(&state, out);++    return 0;+}
+ vendor/external/libsodium/crypto_hash/sha256/hash_sha256.c view
@@ -0,0 +1,13 @@+#include "crypto_hash_sha256.h"++size_t+crypto_hash_sha256_bytes(void)+{+    return crypto_hash_sha256_BYTES;+}++size_t+crypto_hash_sha256_statebytes(void)+{+    return sizeof(crypto_hash_sha256_state);+}
+ vendor/external/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c view
@@ -0,0 +1,284 @@++/*-+ * Copyright 2005,2007,2009 Colin Percival+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or without+ * modification, are permitted provided that the following conditions+ * are met:+ * 1. Redistributions of source code must retain the above copyright+ *    notice, this list of conditions and the following disclaimer.+ * 2. Redistributions in binary form must reproduce the above copyright+ *    notice, this list of conditions and the following disclaimer in the+ *    documentation and/or other materials provided with the distribution.+ *+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+ * SUCH DAMAGE.+ *+ */++#include <limits.h>+#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include <sys/types.h>++#include "crypto_hash_sha512.h"+#include "private/common.h"+#include "utils.h"++static void+be64enc_vect(unsigned char *dst, const uint64_t *src, size_t len)+{+    size_t i;++    for (i = 0; i < len / 8; i++) {+        STORE64_BE(dst + i * 8, src[i]);+    }+}++static void+be64dec_vect(uint64_t *dst, const unsigned char *src, size_t len)+{+    size_t i;++    for (i = 0; i < len / 8; i++) {+        dst[i] = LOAD64_BE(src + i * 8);+    }+}++static const uint64_t Krnd[80] = {+    0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL,+    0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,+    0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL,+    0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,+    0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL,+    0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,+    0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL,+    0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,+    0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL,+    0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,+    0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL,+    0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,+    0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL,+    0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,+    0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL,+    0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,+    0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL,+    0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,+    0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL,+    0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,+    0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL,+    0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,+    0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL,+    0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,+    0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL,+    0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,+    0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL+};++#define Ch(x, y, z) ((x & (y ^ z)) ^ z)+#define Maj(x, y, z) ((x & (y | z)) | (y & z))+#define SHR(x, n) (x >> n)+#define ROTR(x, n) ROTR64(x, n)+#define S0(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))+#define S1(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))+#define s0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7))+#define s1(x) (ROTR(x, 19) ^ ROTR(x, 61) ^ SHR(x, 6))++#define RND(a, b, c, d, e, f, g, h, k) \+    h += S1(e) + Ch(e, f, g) + k;      \+    d += h;                            \+    h += S0(a) + Maj(a, b, c);++#define RNDr(S, W, i, ii)                                                   \+    RND(S[(80 - i) % 8], S[(81 - i) % 8], S[(82 - i) % 8], S[(83 - i) % 8], \+        S[(84 - i) % 8], S[(85 - i) % 8], S[(86 - i) % 8], S[(87 - i) % 8], \+        W[i + ii] + Krnd[i + ii])++#define MSCH(W, ii, i) \+    W[i + ii + 16] =   \+        s1(W[i + ii + 14]) + W[i + ii + 9] + s0(W[i + ii + 1]) + W[i + ii]++static void+SHA512_Transform(uint64_t *state, const uint8_t block[128], uint64_t W[80],+                 uint64_t S[8])+{+    int i;++    be64dec_vect(W, block, 128);+    memcpy(S, state, 64);+    for (i = 0; i < 80; i += 16) {+        RNDr(S, W, 0, i);+        RNDr(S, W, 1, i);+        RNDr(S, W, 2, i);+        RNDr(S, W, 3, i);+        RNDr(S, W, 4, i);+        RNDr(S, W, 5, i);+        RNDr(S, W, 6, i);+        RNDr(S, W, 7, i);+        RNDr(S, W, 8, i);+        RNDr(S, W, 9, i);+        RNDr(S, W, 10, i);+        RNDr(S, W, 11, i);+        RNDr(S, W, 12, i);+        RNDr(S, W, 13, i);+        RNDr(S, W, 14, i);+        RNDr(S, W, 15, i);+        if (i == 64) {+            break;+        }+        MSCH(W, 0, i);+        MSCH(W, 1, i);+        MSCH(W, 2, i);+        MSCH(W, 3, i);+        MSCH(W, 4, i);+        MSCH(W, 5, i);+        MSCH(W, 6, i);+        MSCH(W, 7, i);+        MSCH(W, 8, i);+        MSCH(W, 9, i);+        MSCH(W, 10, i);+        MSCH(W, 11, i);+        MSCH(W, 12, i);+        MSCH(W, 13, i);+        MSCH(W, 14, i);+        MSCH(W, 15, i);+    }+    for (i = 0; i < 8; i++) {+        state[i] += S[i];+    }+}++static const uint8_t PAD[128] = {+    0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+    0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0+};++static void+SHA512_Pad(crypto_hash_sha512_state *state, uint64_t tmp64[80 + 8])+{+    unsigned int r;+    unsigned int i;++    ACQUIRE_FENCE;+    r = (unsigned int) ((state->count[1] >> 3) & 0x7f);+    if (r < 112) {+        for (i = 0; i < 112 - r; i++) {+            state->buf[r + i] = PAD[i];+        }+    } else {+        for (i = 0; i < 128 - r; i++) {+            state->buf[r + i] = PAD[i];+        }+        SHA512_Transform(state->state, state->buf, &tmp64[0], &tmp64[80]);+        memset(&state->buf[0], 0, 112);+    }+    be64enc_vect(&state->buf[112], state->count, 16);+    SHA512_Transform(state->state, state->buf, &tmp64[0], &tmp64[80]);+}++int+crypto_hash_sha512_init(crypto_hash_sha512_state *state)+{+    static const uint64_t sha512_initial_state[8] = {+        0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,+        0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,+        0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL+    };++    state->count[0] = state->count[1] = (uint64_t) 0U;+    memcpy(state->state, sha512_initial_state, sizeof sha512_initial_state);++    return 0;+}++int+crypto_hash_sha512_update(crypto_hash_sha512_state *state,+                          const unsigned char *in, unsigned long long inlen)+{+    uint64_t           tmp64[80 + 8];+    uint64_t           bitlen[2];+    unsigned long long i;+    unsigned long long r;++    if (inlen <= 0U) {+        return 0;+    }+    ACQUIRE_FENCE;+    r = (unsigned long long) ((state->count[1] >> 3) & 0x7f);++    bitlen[1] = ((uint64_t) inlen) << 3;+    bitlen[0] = ((uint64_t) inlen) >> 61;+    /* LCOV_EXCL_START */+    if ((state->count[1] += bitlen[1]) < bitlen[1]) {+        state->count[0]++;+    }+    /* LCOV_EXCL_STOP */+    state->count[0] += bitlen[0];+    if (inlen < 128 - r) {+        for (i = 0; i < inlen; i++) {+            state->buf[r + i] = in[i];+        }+        return 0;+    }+    for (i = 0; i < 128 - r; i++) {+        state->buf[r + i] = in[i];+    }+    SHA512_Transform(state->state, state->buf, &tmp64[0], &tmp64[80]);+    in += 128 - r;+    inlen -= 128 - r;++    while (inlen >= 128) {+        SHA512_Transform(state->state, in, &tmp64[0], &tmp64[80]);+        in += 128;+        inlen -= 128;+    }+    inlen &= 127;+    for (i = 0; i < inlen; i++) {+        state->buf[i] = in[i];+    }+    sodium_memzero((void *) tmp64, sizeof tmp64);++    return 0;+}++int+crypto_hash_sha512_final(crypto_hash_sha512_state *state, unsigned char *out)+{+    uint64_t tmp64[80 + 8];++    SHA512_Pad(state, tmp64);+    be64enc_vect(out, state->state, 64);+    sodium_memzero((void *) tmp64, sizeof tmp64);+    sodium_memzero((void *) state, sizeof *state);++    return 0;+}++int+crypto_hash_sha512(unsigned char *out, const unsigned char *in,+                   unsigned long long inlen)+{+    crypto_hash_sha512_state state;++    crypto_hash_sha512_init(&state);+    crypto_hash_sha512_update(&state, in, inlen);+    crypto_hash_sha512_final(&state, out);++    return 0;+}
+ vendor/external/libsodium/crypto_hash/sha512/hash_sha512.c view
@@ -0,0 +1,13 @@+#include "crypto_hash_sha512.h"++size_t+crypto_hash_sha512_bytes(void)+{+    return crypto_hash_sha512_BYTES;+}++size_t+crypto_hash_sha512_statebytes(void)+{+    return sizeof(crypto_hash_sha512_state);+}
+ vendor/external/libsodium/crypto_onetimeauth/crypto_onetimeauth.c view
@@ -0,0 +1,71 @@++#include "crypto_onetimeauth.h"+#include "randombytes.h"++size_t+crypto_onetimeauth_statebytes(void)+{+    return sizeof(crypto_onetimeauth_state);+}++size_t+crypto_onetimeauth_bytes(void)+{+    return crypto_onetimeauth_BYTES;+}++size_t+crypto_onetimeauth_keybytes(void)+{+    return crypto_onetimeauth_KEYBYTES;+}++int+crypto_onetimeauth(unsigned char *out, const unsigned char *in,+                   unsigned long long inlen, const unsigned char *k)+{+    return crypto_onetimeauth_poly1305(out, in, inlen, k);+}++int+crypto_onetimeauth_verify(const unsigned char *h, const unsigned char *in,+                          unsigned long long inlen, const unsigned char *k)+{+    return crypto_onetimeauth_poly1305_verify(h, in, inlen, k);+}++int+crypto_onetimeauth_init(crypto_onetimeauth_state *state,+                        const unsigned char *key)+{+    return crypto_onetimeauth_poly1305_init+        ((crypto_onetimeauth_poly1305_state *) state, key);+}++int+crypto_onetimeauth_update(crypto_onetimeauth_state *state,+                          const unsigned char *in,+                          unsigned long long inlen)+{+    return crypto_onetimeauth_poly1305_update+        ((crypto_onetimeauth_poly1305_state *) state, in, inlen);+}++int+crypto_onetimeauth_final(crypto_onetimeauth_state *state,+                         unsigned char *out)+{+    return crypto_onetimeauth_poly1305_final+        ((crypto_onetimeauth_poly1305_state *) state, out);+}++const char *+crypto_onetimeauth_primitive(void)+{+    return crypto_onetimeauth_PRIMITIVE;+}++void crypto_onetimeauth_keygen(unsigned char k[crypto_onetimeauth_KEYBYTES])+{+    randombytes_buf(k, crypto_onetimeauth_KEYBYTES);+}
+ vendor/external/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c view
@@ -0,0 +1,124 @@++#include "poly1305_donna.h"+#include "crypto_verify_16.h"+#include "private/common.h"+#include "utils.h"++#ifdef HAVE_TI_MODE+#include "poly1305_donna64.h"+#else+#include "poly1305_donna32.h"+#endif+#include "../onetimeauth_poly1305.h"++static void+poly1305_update(poly1305_state_internal_t *st, const unsigned char *m,+                unsigned long long bytes)+{+    unsigned long long i;++    /* handle leftover */+    if (st->leftover) {+        unsigned long long want = (poly1305_block_size - st->leftover);++        if (want > bytes) {+            want = bytes;+        }+        for (i = 0; i < want; i++) {+            st->buffer[st->leftover + i] = m[i];+        }+        bytes -= want;+        m += want;+        st->leftover += want;+        if (st->leftover < poly1305_block_size) {+            return;+        }+        poly1305_blocks(st, st->buffer, poly1305_block_size);+        st->leftover = 0;+    }++    /* process full blocks */+    if (bytes >= poly1305_block_size) {+        unsigned long long want = (bytes & ~(poly1305_block_size - 1));++        poly1305_blocks(st, m, want);+        m += want;+        bytes -= want;+    }++    /* store leftover */+    if (bytes) {+        for (i = 0; i < bytes; i++) {+            st->buffer[st->leftover + i] = m[i];+        }+        st->leftover += bytes;+    }+}++static int+crypto_onetimeauth_poly1305_donna(unsigned char *out, const unsigned char *m,+                                  unsigned long long   inlen,+                                  const unsigned char *key)+{+    CRYPTO_ALIGN(64) poly1305_state_internal_t state;++    poly1305_init(&state, key);+    poly1305_update(&state, m, inlen);+    poly1305_finish(&state, out);++    return 0;+}++static int+crypto_onetimeauth_poly1305_donna_init(crypto_onetimeauth_poly1305_state *state,+                                       const unsigned char *key)+{+    COMPILER_ASSERT(sizeof(crypto_onetimeauth_poly1305_state) >=+        sizeof(poly1305_state_internal_t));+    poly1305_init((poly1305_state_internal_t *) (void *) state, key);++    return 0;+}++static int+crypto_onetimeauth_poly1305_donna_update(+    crypto_onetimeauth_poly1305_state *state, const unsigned char *in,+    unsigned long long inlen)+{+    poly1305_update((poly1305_state_internal_t *) (void *) state, in, inlen);++    return 0;+}++static int+crypto_onetimeauth_poly1305_donna_final(+    crypto_onetimeauth_poly1305_state *state, unsigned char *out)+{+    poly1305_finish((poly1305_state_internal_t *) (void *) state, out);++    return 0;+}++static int+crypto_onetimeauth_poly1305_donna_verify(const unsigned char *h,+                                         const unsigned char *in,+                                         unsigned long long   inlen,+                                         const unsigned char *k)+{+    unsigned char correct[16];++    crypto_onetimeauth_poly1305_donna(correct, in, inlen, k);++    return crypto_verify_16(h, correct);+}++struct crypto_onetimeauth_poly1305_implementation+    crypto_onetimeauth_poly1305_donna_implementation = {+        SODIUM_C99(.onetimeauth =) crypto_onetimeauth_poly1305_donna,+        SODIUM_C99(.onetimeauth_verify =)+            crypto_onetimeauth_poly1305_donna_verify,+        SODIUM_C99(.onetimeauth_init =) crypto_onetimeauth_poly1305_donna_init,+        SODIUM_C99(.onetimeauth_update =)+            crypto_onetimeauth_poly1305_donna_update,+        SODIUM_C99(.onetimeauth_final =) crypto_onetimeauth_poly1305_donna_final+    };
+ vendor/external/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h view
@@ -0,0 +1,12 @@+#ifndef poly1305_donna_H+#define poly1305_donna_H++#include <stddef.h>++#include "crypto_onetimeauth_poly1305.h"+#include "external/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.h"++extern struct crypto_onetimeauth_poly1305_implementation+    crypto_onetimeauth_poly1305_donna_implementation;++#endif /* poly1305_donna_H */
+ vendor/external/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h view
@@ -0,0 +1,235 @@+/*+   poly1305 implementation using 32 bit * 32 bit = 64 bit multiplication+   and 64 bit addition+*/++#if defined(_MSC_VER)+# define POLY1305_NOINLINE __declspec(noinline)+#elif defined(__clang__) || defined(__GNUC__)+# define POLY1305_NOINLINE __attribute__((noinline))+#else+# define POLY1305_NOINLINE+#endif++#include "private/common.h"++#define poly1305_block_size 16++/* 17 + sizeof(unsigned long long) + 14*sizeof(unsigned long) */+typedef struct poly1305_state_internal_t {+    unsigned long      r[5];+    unsigned long      h[5];+    unsigned long      pad[4];+    unsigned long long leftover;+    unsigned char      buffer[poly1305_block_size];+    unsigned char      final;+} poly1305_state_internal_t;++static void+poly1305_init(poly1305_state_internal_t *st, const unsigned char key[32])+{+    /* r &= 0xffffffc0ffffffc0ffffffc0fffffff - wiped after finalization */+    st->r[0] = (LOAD32_LE(&key[0])) & 0x3ffffff;+    st->r[1] = (LOAD32_LE(&key[3]) >> 2) & 0x3ffff03;+    st->r[2] = (LOAD32_LE(&key[6]) >> 4) & 0x3ffc0ff;+    st->r[3] = (LOAD32_LE(&key[9]) >> 6) & 0x3f03fff;+    st->r[4] = (LOAD32_LE(&key[12]) >> 8) & 0x00fffff;++    /* h = 0 */+    st->h[0] = 0;+    st->h[1] = 0;+    st->h[2] = 0;+    st->h[3] = 0;+    st->h[4] = 0;++    /* save pad for later */+    st->pad[0] = LOAD32_LE(&key[16]);+    st->pad[1] = LOAD32_LE(&key[20]);+    st->pad[2] = LOAD32_LE(&key[24]);+    st->pad[3] = LOAD32_LE(&key[28]);++    st->leftover = 0;+    st->final    = 0;+}++static void+poly1305_blocks(poly1305_state_internal_t *st, const unsigned char *m,+                unsigned long long bytes)+{+    const unsigned long hibit = (st->final) ? 0UL : (1UL << 24); /* 1 << 128 */+    unsigned long       r0, r1, r2, r3, r4;+    unsigned long       s1, s2, s3, s4;+    unsigned long       h0, h1, h2, h3, h4;+    unsigned long long  d0, d1, d2, d3, d4;+    unsigned long       c;++    r0 = st->r[0];+    r1 = st->r[1];+    r2 = st->r[2];+    r3 = st->r[3];+    r4 = st->r[4];++    s1 = r1 * 5;+    s2 = r2 * 5;+    s3 = r3 * 5;+    s4 = r4 * 5;++    h0 = st->h[0];+    h1 = st->h[1];+    h2 = st->h[2];+    h3 = st->h[3];+    h4 = st->h[4];++    while (bytes >= poly1305_block_size) {+        /* h += m[i] */+        h0 += (LOAD32_LE(m + 0)) & 0x3ffffff;+        h1 += (LOAD32_LE(m + 3) >> 2) & 0x3ffffff;+        h2 += (LOAD32_LE(m + 6) >> 4) & 0x3ffffff;+        h3 += (LOAD32_LE(m + 9) >> 6) & 0x3ffffff;+        h4 += (LOAD32_LE(m + 12) >> 8) | hibit;++        /* h *= r */+        d0 = ((unsigned long long) h0 * r0) + ((unsigned long long) h1 * s4) ++             ((unsigned long long) h2 * s3) + ((unsigned long long) h3 * s2) ++             ((unsigned long long) h4 * s1);+        d1 = ((unsigned long long) h0 * r1) + ((unsigned long long) h1 * r0) ++             ((unsigned long long) h2 * s4) + ((unsigned long long) h3 * s3) ++             ((unsigned long long) h4 * s2);+        d2 = ((unsigned long long) h0 * r2) + ((unsigned long long) h1 * r1) ++             ((unsigned long long) h2 * r0) + ((unsigned long long) h3 * s4) ++             ((unsigned long long) h4 * s3);+        d3 = ((unsigned long long) h0 * r3) + ((unsigned long long) h1 * r2) ++             ((unsigned long long) h2 * r1) + ((unsigned long long) h3 * r0) ++             ((unsigned long long) h4 * s4);+        d4 = ((unsigned long long) h0 * r4) + ((unsigned long long) h1 * r3) ++             ((unsigned long long) h2 * r2) + ((unsigned long long) h3 * r1) ++             ((unsigned long long) h4 * r0);++        /* (partial) h %= p */+        c  = (unsigned long) (d0 >> 26);+        h0 = (unsigned long) d0 & 0x3ffffff;+        d1 += c;+        c  = (unsigned long) (d1 >> 26);+        h1 = (unsigned long) d1 & 0x3ffffff;+        d2 += c;+        c  = (unsigned long) (d2 >> 26);+        h2 = (unsigned long) d2 & 0x3ffffff;+        d3 += c;+        c  = (unsigned long) (d3 >> 26);+        h3 = (unsigned long) d3 & 0x3ffffff;+        d4 += c;+        c  = (unsigned long) (d4 >> 26);+        h4 = (unsigned long) d4 & 0x3ffffff;+        h0 += c * 5;+        c  = (h0 >> 26);+        h0 &= 0x3ffffff;+        h1 += c;++        m += poly1305_block_size;+        bytes -= poly1305_block_size;+    }++    st->h[0] = h0;+    st->h[1] = h1;+    st->h[2] = h2;+    st->h[3] = h3;+    st->h[4] = h4;+}++static POLY1305_NOINLINE void+poly1305_finish(poly1305_state_internal_t *st, unsigned char mac[16])+{+    unsigned long      h0, h1, h2, h3, h4, c;+    unsigned long      g0, g1, g2, g3, g4;+    unsigned long long f;+    unsigned long      mask;++    /* process the remaining block */+    if (st->leftover) {+        unsigned long long i = st->leftover;++        st->buffer[i++] = 1;+        for (; i < poly1305_block_size; i++) {+            st->buffer[i] = 0;+        }+        st->final = 1;+        poly1305_blocks(st, st->buffer, poly1305_block_size);+    }++    /* fully carry h */+    h0 = st->h[0];+    h1 = st->h[1];+    h2 = st->h[2];+    h3 = st->h[3];+    h4 = st->h[4];++    c  = h1 >> 26;+    h1 = h1 & 0x3ffffff;+    h2 += c;+    c  = h2 >> 26;+    h2 = h2 & 0x3ffffff;+    h3 += c;+    c  = h3 >> 26;+    h3 = h3 & 0x3ffffff;+    h4 += c;+    c  = h4 >> 26;+    h4 = h4 & 0x3ffffff;+    h0 += c * 5;+    c  = h0 >> 26;+    h0 = h0 & 0x3ffffff;+    h1 += c;++    /* compute h + -p */+    g0 = h0 + 5;+    c  = g0 >> 26;+    g0 &= 0x3ffffff;+    g1 = h1 + c;+    c  = g1 >> 26;+    g1 &= 0x3ffffff;+    g2 = h2 + c;+    c  = g2 >> 26;+    g2 &= 0x3ffffff;+    g3 = h3 + c;+    c  = g3 >> 26;+    g3 &= 0x3ffffff;+    g4 = h4 + c - (1UL << 26);++    /* select h if h < p, or h + -p if h >= p */+    mask = (g4 >> ((sizeof(unsigned long) * 8) - 1)) - 1;+    g0 &= mask;+    g1 &= mask;+    g2 &= mask;+    g3 &= mask;+    g4 &= mask;+    mask = ~mask;++    h0 = (h0 & mask) | g0;+    h1 = (h1 & mask) | g1;+    h2 = (h2 & mask) | g2;+    h3 = (h3 & mask) | g3;+    h4 = (h4 & mask) | g4;++    /* h = h % (2^128) */+    h0 = ((h0) | (h1 << 26)) & 0xffffffff;+    h1 = ((h1 >> 6) | (h2 << 20)) & 0xffffffff;+    h2 = ((h2 >> 12) | (h3 << 14)) & 0xffffffff;+    h3 = ((h3 >> 18) | (h4 << 8)) & 0xffffffff;++    /* mac = (h + pad) % (2^128) */+    f  = (unsigned long long) h0 + st->pad[0];+    h0 = (unsigned long) f;+    f  = (unsigned long long) h1 + st->pad[1] + (f >> 32);+    h1 = (unsigned long) f;+    f  = (unsigned long long) h2 + st->pad[2] + (f >> 32);+    h2 = (unsigned long) f;+    f  = (unsigned long long) h3 + st->pad[3] + (f >> 32);+    h3 = (unsigned long) f;++    STORE32_LE(mac + 0, (uint32_t) h0);+    STORE32_LE(mac + 4, (uint32_t) h1);+    STORE32_LE(mac + 8, (uint32_t) h2);+    STORE32_LE(mac + 12, (uint32_t) h3);++    /* zero out the state */+    sodium_memzero((void *) st, sizeof *st);+}
+ vendor/external/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h view
@@ -0,0 +1,221 @@+/*+   poly1305 implementation using 64 bit * 64 bit = 128 bit multiplication+   and 128 bit addition+*/++#include "private/common.h"++#define MUL(out, x, y) out = ((uint128_t) x * y)+#define ADD(out, in) out += in+#define ADDLO(out, in) out += in+#define SHR(in, shift) (unsigned long long) (in >> (shift))+#define LO(in) (unsigned long long) (in)++#if defined(_MSC_VER)+# define POLY1305_NOINLINE __declspec(noinline)+#elif defined(__clang__) || defined(__GNUC__)+# define POLY1305_NOINLINE __attribute__((noinline))+#else+# define POLY1305_NOINLINE+#endif++#define poly1305_block_size 16++/* 17 + sizeof(unsigned long long) + 8*sizeof(unsigned long long) */+typedef struct poly1305_state_internal_t {+    unsigned long long r[3];+    unsigned long long h[3];+    unsigned long long pad[2];+    unsigned long long leftover;+    unsigned char      buffer[poly1305_block_size];+    unsigned char      final;+} poly1305_state_internal_t;++static void+poly1305_init(poly1305_state_internal_t *st, const unsigned char key[32])+{+    unsigned long long t0, t1;++    /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */+    t0 = LOAD64_LE(&key[0]);+    t1 = LOAD64_LE(&key[8]);++    /* wiped after finalization */+    st->r[0] = (t0) & 0xffc0fffffff;+    st->r[1] = ((t0 >> 44) | (t1 << 20)) & 0xfffffc0ffff;+    st->r[2] = ((t1 >> 24)) & 0x00ffffffc0f;++    /* h = 0 */+    st->h[0] = 0;+    st->h[1] = 0;+    st->h[2] = 0;++    /* save pad for later */+    st->pad[0] = LOAD64_LE(&key[16]);+    st->pad[1] = LOAD64_LE(&key[24]);++    st->leftover = 0;+    st->final    = 0;+}++static void+poly1305_blocks(poly1305_state_internal_t *st, const unsigned char *m,+                unsigned long long bytes)+{+    const unsigned long long hibit =+        (st->final) ? 0ULL : (1ULL << 40); /* 1 << 128 */+    unsigned long long r0, r1, r2;+    unsigned long long s1, s2;+    unsigned long long h0, h1, h2;+    unsigned long long c;+    uint128_t          d0, d1, d2, d;++    r0 = st->r[0];+    r1 = st->r[1];+    r2 = st->r[2];++    h0 = st->h[0];+    h1 = st->h[1];+    h2 = st->h[2];++    s1 = r1 * (5 << 2);+    s2 = r2 * (5 << 2);++    while (bytes >= poly1305_block_size) {+        unsigned long long t0, t1;++        /* h += m[i] */+        t0 = LOAD64_LE(&m[0]);+        t1 = LOAD64_LE(&m[8]);++        h0 += t0 & 0xfffffffffff;+        h1 += ((t0 >> 44) | (t1 << 20)) & 0xfffffffffff;+        h2 += (((t1 >> 24)) & 0x3ffffffffff) | hibit;++        /* h *= r */+        MUL(d0, h0, r0);+        MUL(d, h1, s2);+        ADD(d0, d);+        MUL(d, h2, s1);+        ADD(d0, d);+        MUL(d1, h0, r1);+        MUL(d, h1, r0);+        ADD(d1, d);+        MUL(d, h2, s2);+        ADD(d1, d);+        MUL(d2, h0, r2);+        MUL(d, h1, r1);+        ADD(d2, d);+        MUL(d, h2, r0);+        ADD(d2, d);++        /* (partial) h %= p */+        c  = SHR(d0, 44);+        h0 = LO(d0) & 0xfffffffffff;+        ADDLO(d1, c);+        c  = SHR(d1, 44);+        h1 = LO(d1) & 0xfffffffffff;+        ADDLO(d2, c);+        c  = SHR(d2, 42);+        h2 = LO(d2) & 0x3ffffffffff;+        h0 += c * 5;+        c  = (h0 >> 44);+        h0 &= 0xfffffffffff;+        h1 += c;++        m += poly1305_block_size;+        bytes -= poly1305_block_size;+    }++    st->h[0] = h0;+    st->h[1] = h1;+    st->h[2] = h2;+}++static POLY1305_NOINLINE void+poly1305_finish(poly1305_state_internal_t *st, unsigned char mac[16])+{+    unsigned long long h0, h1, h2, c;+    unsigned long long g0, g1, g2;+    unsigned long long t0, t1;+    unsigned long long mask;++    /* process the remaining block */+    if (st->leftover) {+        unsigned long long i = st->leftover;++        st->buffer[i] = 1;++        for (i = i + 1; i < poly1305_block_size; i++) {+            st->buffer[i] = 0;+        }+        st->final = 1;+        poly1305_blocks(st, st->buffer, poly1305_block_size);+    }++    /* fully carry h */+    h0 = st->h[0];+    h1 = st->h[1];+    h2 = st->h[2];++    c = h1 >> 44;+    h1 &= 0xfffffffffff;+    h2 += c;+    c = h2 >> 42;+    h2 &= 0x3ffffffffff;+    h0 += c * 5;+    c = h0 >> 44;+    h0 &= 0xfffffffffff;+    h1 += c;+    c = h1 >> 44;+    h1 &= 0xfffffffffff;+    h2 += c;+    c = h2 >> 42;+    h2 &= 0x3ffffffffff;+    h0 += c * 5;+    c = h0 >> 44;+    h0 &= 0xfffffffffff;+    h1 += c;++    /* compute h + -p */+    g0 = h0 + 5;+    c  = g0 >> 44;+    g0 &= 0xfffffffffff;+    g1 = h1 + c;+    c  = g1 >> 44;+    g1 &= 0xfffffffffff;+    g2 = h2 + c - (1ULL << 42);++    /* select h if h < p, or h + -p if h >= p */+    mask = (g2 >> ((sizeof(unsigned long long) * 8) - 1)) - 1;+    g0   &= mask;+    g1   &= mask;+    g2   &= mask;+    mask =  ~mask;+    h0   =  (h0 & mask) | g0;+    h1   =  (h1 & mask) | g1;+    h2   =  (h2 & mask) | g2;++    /* h = (h + pad) */+    t0 = st->pad[0];+    t1 = st->pad[1];++    h0 += ((t0) &0xfffffffffff);+    c = (h0 >> 44);+    h0 &= 0xfffffffffff;+    h1 += (((t0 >> 44) | (t1 << 20)) & 0xfffffffffff) + c;+    c = (h1 >> 44);+    h1 &= 0xfffffffffff;+    h2 += (((t1 >> 24)) & 0x3ffffffffff) + c;+    h2 &= 0x3ffffffffff;++    /* mac = h % (2^128) */+    h0 = (h0) | (h1 << 44);+    h1 = (h1 >> 20) | (h2 << 24);++    STORE64_LE(&mac[0], h0);+    STORE64_LE(&mac[8], h1);++    /* zero out the state */+    sodium_memzero((void *) st, sizeof *st);+}
+ vendor/external/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c view
@@ -0,0 +1,90 @@++#include "onetimeauth_poly1305.h"+#include "crypto_onetimeauth_poly1305.h"+#include "private/common.h"+#include "private/implementations.h"+#include "randombytes.h"+#include "runtime.h"++#include "donna/poly1305_donna.h"+#if defined(HAVE_TI_MODE) && defined(HAVE_EMMINTRIN_H)+# include "sse2/poly1305_sse2.h"+#endif++static const crypto_onetimeauth_poly1305_implementation *implementation =+    &crypto_onetimeauth_poly1305_donna_implementation;++int+crypto_onetimeauth_poly1305(unsigned char *out, const unsigned char *in,+                            unsigned long long inlen, const unsigned char *k)+{+    return implementation->onetimeauth(out, in, inlen, k);+}++int+crypto_onetimeauth_poly1305_verify(const unsigned char *h,+                                   const unsigned char *in,+                                   unsigned long long   inlen,+                                   const unsigned char *k)+{+    return implementation->onetimeauth_verify(h, in, inlen, k);+}++int+crypto_onetimeauth_poly1305_init(crypto_onetimeauth_poly1305_state *state,+                                 const unsigned char *key)+{+    return implementation->onetimeauth_init(state, key);+}++int+crypto_onetimeauth_poly1305_update(crypto_onetimeauth_poly1305_state *state,+                                   const unsigned char *in,+                                   unsigned long long inlen)+{+    return implementation->onetimeauth_update(state, in, inlen);+}++int+crypto_onetimeauth_poly1305_final(crypto_onetimeauth_poly1305_state *state,+                                  unsigned char *out)+{+    return implementation->onetimeauth_final(state, out);+}++size_t+crypto_onetimeauth_poly1305_bytes(void)+{+    return crypto_onetimeauth_poly1305_BYTES;+}++size_t+crypto_onetimeauth_poly1305_keybytes(void)+{+    return crypto_onetimeauth_poly1305_KEYBYTES;+}++size_t+crypto_onetimeauth_poly1305_statebytes(void)+{+    return sizeof(crypto_onetimeauth_poly1305_state);+}++void+crypto_onetimeauth_poly1305_keygen(+    unsigned char k[crypto_onetimeauth_poly1305_KEYBYTES])+{+    randombytes_buf(k, crypto_onetimeauth_poly1305_KEYBYTES);+}++int+_crypto_onetimeauth_poly1305_pick_best_implementation(void)+{+    implementation = &crypto_onetimeauth_poly1305_donna_implementation;+#if defined(HAVE_TI_MODE) && defined(HAVE_EMMINTRIN_H)+    if (sodium_runtime_has_sse2()) {+        implementation = &crypto_onetimeauth_poly1305_sse2_implementation;+    }+#endif+    return 0;+}
+ vendor/external/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.h view
@@ -0,0 +1,21 @@++#ifndef onetimeauth_poly1305_H+#define onetimeauth_poly1305_H++#include "crypto_onetimeauth_poly1305.h"++typedef struct crypto_onetimeauth_poly1305_implementation {+    int (*onetimeauth)(unsigned char *out, const unsigned char *in,+                       unsigned long long inlen, const unsigned char *k);+    int (*onetimeauth_verify)(const unsigned char *h, const unsigned char *in,+                              unsigned long long inlen, const unsigned char *k);+    int (*onetimeauth_init)(crypto_onetimeauth_poly1305_state *state,+                            const unsigned char *              key);+    int (*onetimeauth_update)(crypto_onetimeauth_poly1305_state *state,+                              const unsigned char *              in,+                              unsigned long long                 inlen);+    int (*onetimeauth_final)(crypto_onetimeauth_poly1305_state *state,+                             unsigned char *                    out);+} crypto_onetimeauth_poly1305_implementation;++#endif
+ vendor/external/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c view
@@ -0,0 +1,949 @@++#include <stdint.h>+#include <string.h>++#include "../onetimeauth_poly1305.h"+#include "crypto_verify_16.h"+#include "poly1305_sse2.h"+#include "private/common.h"+#include "utils.h"++#if defined(HAVE_TI_MODE) && defined(HAVE_EMMINTRIN_H)++# ifdef __GNUC__+#  pragma GCC target("sse2")+# endif++# include <emmintrin.h>+# include "private/sse2_64_32.h"++typedef __m128i xmmi;++# if defined(_MSC_VER)+#  define POLY1305_NOINLINE __declspec(noinline)+# elif defined(__clang__) || defined(__GNUC__)+#  define POLY1305_NOINLINE __attribute__((noinline))+# else+#  define POLY1305_NOINLINE+# endif++# define poly1305_block_size 32++enum poly1305_state_flags_t {+    poly1305_started       = 1,+    poly1305_final_shift8  = 4,+    poly1305_final_shift16 = 8,+    poly1305_final_r2_r    = 16, /* use [r^2,r] for the final block */+    poly1305_final_r_1     = 32  /* use [r,1] for the final block */+};++typedef struct poly1305_state_internal_t {+    union {+        uint64_t h[3];+        uint32_t hh[10];+    } H;                                            /*  40 bytes */+    uint32_t           R[5];                        /*  20 bytes */+    uint32_t           R2[5];                       /*  20 bytes */+    uint32_t           R4[5];                       /*  20 bytes */+    uint64_t           pad[2];                      /*  16 bytes */+    uint64_t           flags;                       /*   8 bytes */+    unsigned long long leftover;                    /*   8 bytes */+    unsigned char      buffer[poly1305_block_size]; /*  32 bytes */+} poly1305_state_internal_t;                        /* 164 bytes total */++/*+ * _mm_loadl_epi64() is turned into a simple MOVQ. So, unaligned accesses are+ * totally fine, even though this intrinsic requires a __m128i* input.+ * This confuses dynamic analysis, so force alignment, only in debug mode.+ */+# ifdef DEBUG+static xmmi+_fakealign_mm_loadl_epi64(const void *m)+{+    xmmi tmp;+    memcpy(&tmp, m, 8);++    return _mm_loadl_epi64(&tmp);+}+# define _mm_loadl_epi64(X) _fakealign_mm_loadl_epi64(X)+#endif++/* copy 0-31 bytes */+static inline void+poly1305_block_copy31(unsigned char *dst, const unsigned char *src,+                      unsigned long long bytes)+{+    if (bytes & 16) {+        _mm_store_si128((xmmi *) (void *) dst,+                        _mm_loadu_si128((const xmmi *) (const void *) src));+        src += 16;+        dst += 16;+    }+    if (bytes & 8) {+        memcpy(dst, src, 8);+        src += 8;+        dst += 8;+    }+    if (bytes & 4) {+        memcpy(dst, src, 4);+        src += 4;+        dst += 4;+    }+    if (bytes & 2) {+        memcpy(dst, src, 2);+        src += 2;+        dst += 2;+    }+    if (bytes & 1) {+        *dst = *src;+    }+}++static POLY1305_NOINLINE void+poly1305_init_ext(poly1305_state_internal_t *st, const unsigned char key[32],+                  unsigned long long bytes)+{+    uint32_t          *R;+    uint128_t          d[3];+    uint64_t           r0, r1, r2;+    uint64_t           rt0, rt1, rt2, st2, c;+    uint64_t           t0, t1;+    unsigned long long i;++    if (!bytes) {+        bytes = ~(unsigned long long) 0;+    }+    /* H = 0 */+    _mm_storeu_si128((xmmi *) (void *) &st->H.hh[0], _mm_setzero_si128());+    _mm_storeu_si128((xmmi *) (void *) &st->H.hh[4], _mm_setzero_si128());+    _mm_storeu_si128((xmmi *) (void *) &st->H.hh[8], _mm_setzero_si128());++    /* clamp key */+    memcpy(&t0, key, 8);+    memcpy(&t1, key + 8, 8);+    r0 = t0 & 0xffc0fffffff;+    t0 >>= 44;+    t0 |= t1 << 20;+    r1 = t0 & 0xfffffc0ffff;+    t1 >>= 24;+    r2 = t1 & 0x00ffffffc0f;++    /* r^1 */+    R    = st->R;+    R[0] = (uint32_t)(r0) &0x3ffffff;+    R[1] = (uint32_t)((r0 >> 26) | (r1 << 18)) & 0x3ffffff;+    R[2] = (uint32_t)((r1 >> 8)) & 0x3ffffff;+    R[3] = (uint32_t)((r1 >> 34) | (r2 << 10)) & 0x3ffffff;+    R[4] = (uint32_t)((r2 >> 16));++    /* save pad */+    memcpy(&st->pad[0], key + 16, 8);+    memcpy(&st->pad[1], key + 24, 8);++    rt0 = r0;+    rt1 = r1;+    rt2 = r2;++    /* r^2, r^4 */+    for (i = 0; i < 2; i++) {+        if (i == 0) {+            R = st->R2;+            if (bytes <= 16) {+                break;+            }+        } else if (i == 1) {+            R = st->R4;+            if (bytes < 96) {+                break;+            }+        }+        st2 = rt2 * (5 << 2);++        d[0] = ((uint128_t) rt0 * rt0) + ((uint128_t)(rt1 * 2) * st2);+        d[1] = ((uint128_t) rt2 * st2) + ((uint128_t)(rt0 * 2) * rt1);+        d[2] = ((uint128_t) rt1 * rt1) + ((uint128_t)(rt2 * 2) * rt0);++        rt0 = (uint64_t) d[0] & 0xfffffffffff;+        c   = (uint64_t)(d[0] >> 44);+        d[1] += c;++        rt1 = (uint64_t) d[1] & 0xfffffffffff;+        c   = (uint64_t)(d[1] >> 44);+        d[2] += c;++        rt2 = (uint64_t) d[2] & 0x3ffffffffff;+        c   = (uint64_t)(d[2] >> 42);+        rt0 += c * 5;+        c   = (rt0 >> 44);+        rt0 = rt0 & 0xfffffffffff;+        rt1 += c;+        c   = (rt1 >> 44);+        rt1 = rt1 & 0xfffffffffff;+        rt2 += c; /* even if rt2 overflows, it will still fit in rp4 safely, and+                     is safe to multiply with */++        R[0] = (uint32_t)(rt0) &0x3ffffff;+        R[1] = (uint32_t)((rt0 >> 26) | (rt1 << 18)) & 0x3ffffff;+        R[2] = (uint32_t)((rt1 >> 8)) & 0x3ffffff;+        R[3] = (uint32_t)((rt1 >> 34) | (rt2 << 10)) & 0x3ffffff;+        R[4] = (uint32_t)((rt2 >> 16));+    }+    st->flags    = 0;+    st->leftover = 0U;+}++static POLY1305_NOINLINE void+poly1305_blocks(poly1305_state_internal_t *st, const unsigned char *m,+                unsigned long long bytes)+{+    CRYPTO_ALIGN(64)+    xmmi HIBIT =+        _mm_shuffle_epi32(_mm_cvtsi32_si128(1 << 24), _MM_SHUFFLE(1, 0, 1, 0));+    const xmmi MMASK = _mm_shuffle_epi32(_mm_cvtsi32_si128((1 << 26) - 1),+                                         _MM_SHUFFLE(1, 0, 1, 0));+    const xmmi FIVE =+        _mm_shuffle_epi32(_mm_cvtsi32_si128(5), _MM_SHUFFLE(1, 0, 1, 0));+    xmmi H0, H1, H2, H3, H4;+    xmmi T0, T1, T2, T3, T4, T5, T6, T7, T8;+    xmmi M0, M1, M2, M3, M4;+    xmmi M5, M6, M7, M8;+    xmmi C1, C2;+    xmmi R20, R21, R22, R23, R24, S21, S22, S23, S24;+    xmmi R40, R41, R42, R43, R44, S41, S42, S43, S44;++    if (st->flags & poly1305_final_shift8) {+        HIBIT = _mm_srli_si128(HIBIT, 8);+    }+    if (st->flags & poly1305_final_shift16) {+        HIBIT = _mm_setzero_si128();+    }+    if (!(st->flags & poly1305_started)) {+        /* H = [Mx,My] */+        T5 = _mm_unpacklo_epi64(+            _mm_loadl_epi64((const xmmi *) (const void *) (m + 0)),+            _mm_loadl_epi64((const xmmi *) (const void *) (m + 16)));+        T6 = _mm_unpacklo_epi64(+            _mm_loadl_epi64((const xmmi *) (const void *) (m + 8)),+            _mm_loadl_epi64((const xmmi *) (const void *) (m + 24)));+        H0 = _mm_and_si128(MMASK, T5);+        H1 = _mm_and_si128(MMASK, _mm_srli_epi64(T5, 26));+        T5 = _mm_or_si128(_mm_srli_epi64(T5, 52), _mm_slli_epi64(T6, 12));+        H2 = _mm_and_si128(MMASK, T5);+        H3 = _mm_and_si128(MMASK, _mm_srli_epi64(T5, 26));+        H4 = _mm_srli_epi64(T6, 40);+        H4 = _mm_or_si128(H4, HIBIT);+        m += 32;+        bytes -= 32;+        st->flags |= poly1305_started;+    } else {+        T0 = _mm_loadu_si128((const xmmi *) (const void *) &st->H.hh[0]);+        T1 = _mm_loadu_si128((const xmmi *) (const void *) &st->H.hh[4]);+        T2 = _mm_loadu_si128((const xmmi *) (const void *) &st->H.hh[8]);+        H0 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(1, 1, 0, 0));+        H1 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(3, 3, 2, 2));+        H2 = _mm_shuffle_epi32(T1, _MM_SHUFFLE(1, 1, 0, 0));+        H3 = _mm_shuffle_epi32(T1, _MM_SHUFFLE(3, 3, 2, 2));+        H4 = _mm_shuffle_epi32(T2, _MM_SHUFFLE(1, 1, 0, 0));+    }+    if (st->flags & (poly1305_final_r2_r | poly1305_final_r_1)) {+        if (st->flags & poly1305_final_r2_r) {+            /* use [r^2, r] */+            T2  = _mm_loadu_si128((const xmmi *) (const void *) &st->R[0]);+            T3  = _mm_cvtsi32_si128(st->R[4]);+            T0  = _mm_loadu_si128((const xmmi *) (const void *) &st->R2[0]);+            T1  = _mm_cvtsi32_si128(st->R2[4]);+            T4  = _mm_unpacklo_epi32(T0, T2);+            T5  = _mm_unpackhi_epi32(T0, T2);+            R24 = _mm_unpacklo_epi64(T1, T3);+        } else {+            /* use [r^1, 1] */+            T0  = _mm_loadu_si128((const xmmi *) (const void *) &st->R[0]);+            T1  = _mm_cvtsi32_si128(st->R[4]);+            T2  = _mm_cvtsi32_si128(1);+            T4  = _mm_unpacklo_epi32(T0, T2);+            T5  = _mm_unpackhi_epi32(T0, T2);+            R24 = T1;+        }+        R20 = _mm_shuffle_epi32(T4, _MM_SHUFFLE(1, 1, 0, 0));+        R21 = _mm_shuffle_epi32(T4, _MM_SHUFFLE(3, 3, 2, 2));+        R22 = _mm_shuffle_epi32(T5, _MM_SHUFFLE(1, 1, 0, 0));+        R23 = _mm_shuffle_epi32(T5, _MM_SHUFFLE(3, 3, 2, 2));+    } else {+        /* use [r^2, r^2] */+        T0  = _mm_loadu_si128((const xmmi *) (const void *) &st->R2[0]);+        T1  = _mm_cvtsi32_si128(st->R2[4]);+        R20 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(0, 0, 0, 0));+        R21 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(1, 1, 1, 1));+        R22 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(2, 2, 2, 2));+        R23 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(3, 3, 3, 3));+        R24 = _mm_shuffle_epi32(T1, _MM_SHUFFLE(0, 0, 0, 0));+    }+    S21 = _mm_mul_epu32(R21, FIVE);+    S22 = _mm_mul_epu32(R22, FIVE);+    S23 = _mm_mul_epu32(R23, FIVE);+    S24 = _mm_mul_epu32(R24, FIVE);++    if (bytes >= 64) {+        T0  = _mm_loadu_si128((const xmmi *) (const void *) &st->R4[0]);+        T1  = _mm_cvtsi32_si128(st->R4[4]);+        R40 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(0, 0, 0, 0));+        R41 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(1, 1, 1, 1));+        R42 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(2, 2, 2, 2));+        R43 = _mm_shuffle_epi32(T0, _MM_SHUFFLE(3, 3, 3, 3));+        R44 = _mm_shuffle_epi32(T1, _MM_SHUFFLE(0, 0, 0, 0));+        S41 = _mm_mul_epu32(R41, FIVE);+        S42 = _mm_mul_epu32(R42, FIVE);+        S43 = _mm_mul_epu32(R43, FIVE);+        S44 = _mm_mul_epu32(R44, FIVE);++        while (bytes >= 64) {+            xmmi v00, v01, v02, v03, v04;+            xmmi v10, v11, v12, v13, v14;+            xmmi v20, v21, v22, v23, v24;+            xmmi v30, v31, v32, v33, v34;+            xmmi v40, v41, v42, v43, v44;+            xmmi T14, T15;++            /* H *= [r^4,r^4], preload [Mx,My] */+            T15 = S42;+            T0  = H4;+            T0  = _mm_mul_epu32(T0, S41);+            v01 = H3;+            v01 = _mm_mul_epu32(v01, T15);+            T14 = S43;+            T1  = H4;+            T1  = _mm_mul_epu32(T1, T15);+            v11 = H3;+            v11 = _mm_mul_epu32(v11, T14);+            T2  = H4;+            T2  = _mm_mul_epu32(T2, T14);+            T0  = _mm_add_epi64(T0, v01);+            T15 = S44;+            v02 = H2;+            v02 = _mm_mul_epu32(v02, T14);+            T3  = H4;+            T3  = _mm_mul_epu32(T3, T15);+            T1  = _mm_add_epi64(T1, v11);+            v03 = H1;+            v03 = _mm_mul_epu32(v03, T15);+            v12 = H2;+            v12 = _mm_mul_epu32(v12, T15);+            T0  = _mm_add_epi64(T0, v02);+            T14 = R40;+            v21 = H3;+            v21 = _mm_mul_epu32(v21, T15);+            v31 = H3;+            v31 = _mm_mul_epu32(v31, T14);+            T0  = _mm_add_epi64(T0, v03);+            T4  = H4;+            T4  = _mm_mul_epu32(T4, T14);+            T1  = _mm_add_epi64(T1, v12);+            v04 = H0;+            v04 = _mm_mul_epu32(v04, T14);+            T2  = _mm_add_epi64(T2, v21);+            v13 = H1;+            v13 = _mm_mul_epu32(v13, T14);+            T3  = _mm_add_epi64(T3, v31);+            T15 = R41;+            v22 = H2;+            v22 = _mm_mul_epu32(v22, T14);+            v32 = H2;+            v32 = _mm_mul_epu32(v32, T15);+            T0  = _mm_add_epi64(T0, v04);+            v41 = H3;+            v41 = _mm_mul_epu32(v41, T15);+            T1  = _mm_add_epi64(T1, v13);+            v14 = H0;+            v14 = _mm_mul_epu32(v14, T15);+            T2  = _mm_add_epi64(T2, v22);+            T14 = R42;+            T5  = _mm_unpacklo_epi64(+                _mm_loadl_epi64((const xmmi *) (const void *) (m + 0)),+                _mm_loadl_epi64((const xmmi *) (const void *) (m + 16)));+            v23 = H1;+            v23 = _mm_mul_epu32(v23, T15);+            T3  = _mm_add_epi64(T3, v32);+            v33 = H1;+            v33 = _mm_mul_epu32(v33, T14);+            T4  = _mm_add_epi64(T4, v41);+            v42 = H2;+            v42 = _mm_mul_epu32(v42, T14);+            T1  = _mm_add_epi64(T1, v14);+            T15 = R43;+            T6  = _mm_unpacklo_epi64(+                _mm_loadl_epi64((const xmmi *) (const void *) (m + 8)),+                _mm_loadl_epi64((const xmmi *) (const void *) (m + 24)));+            v24 = H0;+            v24 = _mm_mul_epu32(v24, T14);+            T2  = _mm_add_epi64(T2, v23);+            v34 = H0;+            v34 = _mm_mul_epu32(v34, T15);+            T3  = _mm_add_epi64(T3, v33);+            M0  = _mm_and_si128(MMASK, T5);+            v43 = H1;+            v43 = _mm_mul_epu32(v43, T15);+            T4  = _mm_add_epi64(T4, v42);+            M1  = _mm_and_si128(MMASK, _mm_srli_epi64(T5, 26));+            v44 = H0;+            v44 = _mm_mul_epu32(v44, R44);+            T2  = _mm_add_epi64(T2, v24);+            T5  = _mm_or_si128(_mm_srli_epi64(T5, 52), _mm_slli_epi64(T6, 12));+            T3  = _mm_add_epi64(T3, v34);+            M3  = _mm_and_si128(MMASK, _mm_srli_epi64(T6, 14));+            T4  = _mm_add_epi64(T4, v43);+            M2  = _mm_and_si128(MMASK, T5);+            T4  = _mm_add_epi64(T4, v44);+            M4  = _mm_or_si128(_mm_srli_epi64(T6, 40), HIBIT);++            /* H += [Mx',My'] */+            T5 = _mm_loadu_si128((const xmmi *) (const void *) (m + 32));+            T6 = _mm_loadu_si128((const xmmi *) (const void *) (m + 48));+            T7 = _mm_unpacklo_epi32(T5, T6);+            T8 = _mm_unpackhi_epi32(T5, T6);+            M5 = _mm_unpacklo_epi32(T7, _mm_setzero_si128());+            M6 = _mm_unpackhi_epi32(T7, _mm_setzero_si128());+            M7 = _mm_unpacklo_epi32(T8, _mm_setzero_si128());+            M8 = _mm_unpackhi_epi32(T8, _mm_setzero_si128());+            M6 = _mm_slli_epi64(M6, 6);+            M7 = _mm_slli_epi64(M7, 12);+            M8 = _mm_slli_epi64(M8, 18);+            T0 = _mm_add_epi64(T0, M5);+            T1 = _mm_add_epi64(T1, M6);+            T2 = _mm_add_epi64(T2, M7);+            T3 = _mm_add_epi64(T3, M8);+            T4 = _mm_add_epi64(T4, HIBIT);++            /* H += [Mx,My]*[r^2,r^2] */+            T15 = S22;+            v00 = M4;+            v00 = _mm_mul_epu32(v00, S21);+            v01 = M3;+            v01 = _mm_mul_epu32(v01, T15);+            T14 = S23;+            v10 = M4;+            v10 = _mm_mul_epu32(v10, T15);+            v11 = M3;+            v11 = _mm_mul_epu32(v11, T14);+            T0  = _mm_add_epi64(T0, v00);+            v20 = M4;+            v20 = _mm_mul_epu32(v20, T14);+            T0  = _mm_add_epi64(T0, v01);+            T15 = S24;+            v02 = M2;+            v02 = _mm_mul_epu32(v02, T14);+            T1  = _mm_add_epi64(T1, v10);+            v30 = M4;+            v30 = _mm_mul_epu32(v30, T15);+            T1  = _mm_add_epi64(T1, v11);+            v03 = M1;+            v03 = _mm_mul_epu32(v03, T15);+            T2  = _mm_add_epi64(T2, v20);+            v12 = M2;+            v12 = _mm_mul_epu32(v12, T15);+            T0  = _mm_add_epi64(T0, v02);+            T14 = R20;+            v21 = M3;+            v21 = _mm_mul_epu32(v21, T15);+            T3  = _mm_add_epi64(T3, v30);+            v31 = M3;+            v31 = _mm_mul_epu32(v31, T14);+            T0  = _mm_add_epi64(T0, v03);+            v40 = M4;+            v40 = _mm_mul_epu32(v40, T14);+            T1  = _mm_add_epi64(T1, v12);+            v04 = M0;+            v04 = _mm_mul_epu32(v04, T14);+            T2  = _mm_add_epi64(T2, v21);+            v13 = M1;+            v13 = _mm_mul_epu32(v13, T14);+            T3  = _mm_add_epi64(T3, v31);+            T15 = R21;+            v22 = M2;+            v22 = _mm_mul_epu32(v22, T14);+            T4  = _mm_add_epi64(T4, v40);+            v32 = M2;+            v32 = _mm_mul_epu32(v32, T15);+            T0  = _mm_add_epi64(T0, v04);+            v41 = M3;+            v41 = _mm_mul_epu32(v41, T15);+            T1  = _mm_add_epi64(T1, v13);+            v14 = M0;+            v14 = _mm_mul_epu32(v14, T15);+            T2  = _mm_add_epi64(T2, v22);+            T14 = R22;+            v23 = M1;+            v23 = _mm_mul_epu32(v23, T15);+            T3  = _mm_add_epi64(T3, v32);+            v33 = M1;+            v33 = _mm_mul_epu32(v33, T14);+            T4  = _mm_add_epi64(T4, v41);+            v42 = M2;+            v42 = _mm_mul_epu32(v42, T14);+            T1  = _mm_add_epi64(T1, v14);+            T15 = R23;+            v24 = M0;+            v24 = _mm_mul_epu32(v24, T14);+            T2  = _mm_add_epi64(T2, v23);+            v34 = M0;+            v34 = _mm_mul_epu32(v34, T15);+            T3  = _mm_add_epi64(T3, v33);+            v43 = M1;+            v43 = _mm_mul_epu32(v43, T15);+            T4  = _mm_add_epi64(T4, v42);+            v44 = M0;+            v44 = _mm_mul_epu32(v44, R24);+            T2  = _mm_add_epi64(T2, v24);+            T3  = _mm_add_epi64(T3, v34);+            T4  = _mm_add_epi64(T4, v43);+            T4  = _mm_add_epi64(T4, v44);++            /* reduce */+            C1 = _mm_srli_epi64(T0, 26);+            C2 = _mm_srli_epi64(T3, 26);+            T0 = _mm_and_si128(T0, MMASK);+            T3 = _mm_and_si128(T3, MMASK);+            T1 = _mm_add_epi64(T1, C1);+            T4 = _mm_add_epi64(T4, C2);+            C1 = _mm_srli_epi64(T1, 26);+            C2 = _mm_srli_epi64(T4, 26);+            T1 = _mm_and_si128(T1, MMASK);+            T4 = _mm_and_si128(T4, MMASK);+            T2 = _mm_add_epi64(T2, C1);+            T0 = _mm_add_epi64(T0, _mm_mul_epu32(C2, FIVE));+            C1 = _mm_srli_epi64(T2, 26);+            C2 = _mm_srli_epi64(T0, 26);+            T2 = _mm_and_si128(T2, MMASK);+            T0 = _mm_and_si128(T0, MMASK);+            T3 = _mm_add_epi64(T3, C1);+            T1 = _mm_add_epi64(T1, C2);+            C1 = _mm_srli_epi64(T3, 26);+            T3 = _mm_and_si128(T3, MMASK);+            T4 = _mm_add_epi64(T4, C1);++            /* Final: H = (H*[r^4,r^4] + [Mx,My]*[r^2,r^2] + [Mx',My']) */+            H0 = T0;+            H1 = T1;+            H2 = T2;+            H3 = T3;+            H4 = T4;++            m += 64;+            bytes -= 64;+        }+    }++    if (bytes >= 32) {+        xmmi v01, v02, v03, v04;+        xmmi v11, v12, v13, v14;+        xmmi v21, v22, v23, v24;+        xmmi v31, v32, v33, v34;+        xmmi v41, v42, v43, v44;+        xmmi T14, T15;++        /* H *= [r^2,r^2] */+        T15 = S22;+        T0  = H4;+        T0  = _mm_mul_epu32(T0, S21);+        v01 = H3;+        v01 = _mm_mul_epu32(v01, T15);+        T14 = S23;+        T1  = H4;+        T1  = _mm_mul_epu32(T1, T15);+        v11 = H3;+        v11 = _mm_mul_epu32(v11, T14);+        T2  = H4;+        T2  = _mm_mul_epu32(T2, T14);+        T0  = _mm_add_epi64(T0, v01);+        T15 = S24;+        v02 = H2;+        v02 = _mm_mul_epu32(v02, T14);+        T3  = H4;+        T3  = _mm_mul_epu32(T3, T15);+        T1  = _mm_add_epi64(T1, v11);+        v03 = H1;+        v03 = _mm_mul_epu32(v03, T15);+        v12 = H2;+        v12 = _mm_mul_epu32(v12, T15);+        T0  = _mm_add_epi64(T0, v02);+        T14 = R20;+        v21 = H3;+        v21 = _mm_mul_epu32(v21, T15);+        v31 = H3;+        v31 = _mm_mul_epu32(v31, T14);+        T0  = _mm_add_epi64(T0, v03);+        T4  = H4;+        T4  = _mm_mul_epu32(T4, T14);+        T1  = _mm_add_epi64(T1, v12);+        v04 = H0;+        v04 = _mm_mul_epu32(v04, T14);+        T2  = _mm_add_epi64(T2, v21);+        v13 = H1;+        v13 = _mm_mul_epu32(v13, T14);+        T3  = _mm_add_epi64(T3, v31);+        T15 = R21;+        v22 = H2;+        v22 = _mm_mul_epu32(v22, T14);+        v32 = H2;+        v32 = _mm_mul_epu32(v32, T15);+        T0  = _mm_add_epi64(T0, v04);+        v41 = H3;+        v41 = _mm_mul_epu32(v41, T15);+        T1  = _mm_add_epi64(T1, v13);+        v14 = H0;+        v14 = _mm_mul_epu32(v14, T15);+        T2  = _mm_add_epi64(T2, v22);+        T14 = R22;+        v23 = H1;+        v23 = _mm_mul_epu32(v23, T15);+        T3  = _mm_add_epi64(T3, v32);+        v33 = H1;+        v33 = _mm_mul_epu32(v33, T14);+        T4  = _mm_add_epi64(T4, v41);+        v42 = H2;+        v42 = _mm_mul_epu32(v42, T14);+        T1  = _mm_add_epi64(T1, v14);+        T15 = R23;+        v24 = H0;+        v24 = _mm_mul_epu32(v24, T14);+        T2  = _mm_add_epi64(T2, v23);+        v34 = H0;+        v34 = _mm_mul_epu32(v34, T15);+        T3  = _mm_add_epi64(T3, v33);+        v43 = H1;+        v43 = _mm_mul_epu32(v43, T15);+        T4  = _mm_add_epi64(T4, v42);+        v44 = H0;+        v44 = _mm_mul_epu32(v44, R24);+        T2  = _mm_add_epi64(T2, v24);+        T3  = _mm_add_epi64(T3, v34);+        T4  = _mm_add_epi64(T4, v43);+        T4  = _mm_add_epi64(T4, v44);++        /* H += [Mx,My] */+        if (m) {+            T5 = _mm_loadu_si128((const xmmi *) (const void *) (m + 0));+            T6 = _mm_loadu_si128((const xmmi *) (const void *) (m + 16));+            T7 = _mm_unpacklo_epi32(T5, T6);+            T8 = _mm_unpackhi_epi32(T5, T6);+            M0 = _mm_unpacklo_epi32(T7, _mm_setzero_si128());+            M1 = _mm_unpackhi_epi32(T7, _mm_setzero_si128());+            M2 = _mm_unpacklo_epi32(T8, _mm_setzero_si128());+            M3 = _mm_unpackhi_epi32(T8, _mm_setzero_si128());+            M1 = _mm_slli_epi64(M1, 6);+            M2 = _mm_slli_epi64(M2, 12);+            M3 = _mm_slli_epi64(M3, 18);+            T0 = _mm_add_epi64(T0, M0);+            T1 = _mm_add_epi64(T1, M1);+            T2 = _mm_add_epi64(T2, M2);+            T3 = _mm_add_epi64(T3, M3);+            T4 = _mm_add_epi64(T4, HIBIT);+        }++        /* reduce */+        C1 = _mm_srli_epi64(T0, 26);+        C2 = _mm_srli_epi64(T3, 26);+        T0 = _mm_and_si128(T0, MMASK);+        T3 = _mm_and_si128(T3, MMASK);+        T1 = _mm_add_epi64(T1, C1);+        T4 = _mm_add_epi64(T4, C2);+        C1 = _mm_srli_epi64(T1, 26);+        C2 = _mm_srli_epi64(T4, 26);+        T1 = _mm_and_si128(T1, MMASK);+        T4 = _mm_and_si128(T4, MMASK);+        T2 = _mm_add_epi64(T2, C1);+        T0 = _mm_add_epi64(T0, _mm_mul_epu32(C2, FIVE));+        C1 = _mm_srli_epi64(T2, 26);+        C2 = _mm_srli_epi64(T0, 26);+        T2 = _mm_and_si128(T2, MMASK);+        T0 = _mm_and_si128(T0, MMASK);+        T3 = _mm_add_epi64(T3, C1);+        T1 = _mm_add_epi64(T1, C2);+        C1 = _mm_srli_epi64(T3, 26);+        T3 = _mm_and_si128(T3, MMASK);+        T4 = _mm_add_epi64(T4, C1);++        /* H = (H*[r^2,r^2] + [Mx,My]) */+        H0 = T0;+        H1 = T1;+        H2 = T2;+        H3 = T3;+        H4 = T4;+    }++    if (m) {+        T0 = _mm_shuffle_epi32(H0, _MM_SHUFFLE(0, 0, 2, 0));+        T1 = _mm_shuffle_epi32(H1, _MM_SHUFFLE(0, 0, 2, 0));+        T2 = _mm_shuffle_epi32(H2, _MM_SHUFFLE(0, 0, 2, 0));+        T3 = _mm_shuffle_epi32(H3, _MM_SHUFFLE(0, 0, 2, 0));+        T4 = _mm_shuffle_epi32(H4, _MM_SHUFFLE(0, 0, 2, 0));+        T0 = _mm_unpacklo_epi64(T0, T1);+        T1 = _mm_unpacklo_epi64(T2, T3);+        _mm_storeu_si128((xmmi *) (void *) &st->H.hh[0], T0);+        _mm_storeu_si128((xmmi *) (void *) &st->H.hh[4], T1);+        _mm_storel_epi64((xmmi *) (void *) &st->H.hh[8], T4);+    } else {+        uint32_t t0, t1, t2, t3, t4, b;+        uint64_t h0, h1, h2, g0, g1, g2, c, nc;++        /* H = H[0]+H[1] */+        T0 = H0;+        T1 = H1;+        T2 = H2;+        T3 = H3;+        T4 = H4;++        T0 = _mm_add_epi64(T0, _mm_srli_si128(T0, 8));+        T1 = _mm_add_epi64(T1, _mm_srli_si128(T1, 8));+        T2 = _mm_add_epi64(T2, _mm_srli_si128(T2, 8));+        T3 = _mm_add_epi64(T3, _mm_srli_si128(T3, 8));+        T4 = _mm_add_epi64(T4, _mm_srli_si128(T4, 8));++        t0 = _mm_cvtsi128_si32(T0);+        b  = (t0 >> 26);+        t0 &= 0x3ffffff;+        t1 = _mm_cvtsi128_si32(T1) + b;+        b  = (t1 >> 26);+        t1 &= 0x3ffffff;+        t2 = _mm_cvtsi128_si32(T2) + b;+        b  = (t2 >> 26);+        t2 &= 0x3ffffff;+        t3 = _mm_cvtsi128_si32(T3) + b;+        b  = (t3 >> 26);+        t3 &= 0x3ffffff;+        t4 = _mm_cvtsi128_si32(T4) + b;++        /* everything except t4 is in range, so this is all safe */+        h0 = (((uint64_t) t0) | ((uint64_t) t1 << 26)) & 0xfffffffffffull;+        h1 = (((uint64_t) t1 >> 18) | ((uint64_t) t2 << 8) |+              ((uint64_t) t3 << 34)) &+             0xfffffffffffull;+        h2 = (((uint64_t) t3 >> 10) | ((uint64_t) t4 << 16));++        c = (h2 >> 42);+        h2 &= 0x3ffffffffff;+        h0 += c * 5;+        c = (h0 >> 44);+        h0 &= 0xfffffffffff;+        h1 += c;+        c = (h1 >> 44);+        h1 &= 0xfffffffffff;+        h2 += c;+        c = (h2 >> 42);+        h2 &= 0x3ffffffffff;+        h0 += c * 5;+        c = (h0 >> 44);+        h0 &= 0xfffffffffff;+        h1 += c;++        g0 = h0 + 5;+        c  = (g0 >> 44);+        g0 &= 0xfffffffffff;+        g1 = h1 + c;+        c  = (g1 >> 44);+        g1 &= 0xfffffffffff;+        g2 = h2 + c - ((uint64_t) 1 << 42);++        c  = (g2 >> 63) - 1;+        nc = ~c;+        h0 = (h0 & nc) | (g0 & c);+        h1 = (h1 & nc) | (g1 & c);+        h2 = (h2 & nc) | (g2 & c);++        st->H.h[0] = h0;+        st->H.h[1] = h1;+        st->H.h[2] = h2;+    }+}++static void+poly1305_update(poly1305_state_internal_t *st, const unsigned char *m,+                unsigned long long bytes)+{+    unsigned long long i;++    /* handle leftover */+    if (st->leftover) {+        unsigned long long want = (poly1305_block_size - st->leftover);++        if (want > bytes) {+            want = bytes;+        }+        for (i = 0; i < want; i++) {+            st->buffer[st->leftover + i] = m[i];+        }+        bytes -= want;+        m += want;+        st->leftover += want;+        if (st->leftover < poly1305_block_size) {+            return;+        }+        poly1305_blocks(st, st->buffer, poly1305_block_size);+        st->leftover = 0;+    }++    /* process full blocks */+    if (bytes >= poly1305_block_size) {+        unsigned long long want = (bytes & ~(poly1305_block_size - 1));++        poly1305_blocks(st, m, want);+        m += want;+        bytes -= want;+    }++    /* store leftover */+    if (bytes) {+        for (i = 0; i < bytes; i++) {+            st->buffer[st->leftover + i] = m[i];+        }+        st->leftover += bytes;+    }+}++static POLY1305_NOINLINE void+poly1305_finish_ext(poly1305_state_internal_t *st, const unsigned char *m,+                    unsigned long long leftover, unsigned char mac[16])+{+    uint64_t h0, h1, h2;++    if (leftover) {+        CRYPTO_ALIGN(16) unsigned char final[32] = { 0 };++        poly1305_block_copy31(final, m, leftover);+        if (leftover != 16) {+            final[leftover] = 1;+        }+        st->flags |=+            (leftover >= 16) ? poly1305_final_shift8 : poly1305_final_shift16;+        poly1305_blocks(st, final, 32);+    }++    if (st->flags & poly1305_started) {+        /* finalize, H *= [r^2,r], or H *= [r,1] */+        if (!leftover || (leftover > 16)) {+            st->flags |= poly1305_final_r2_r;+        } else {+            st->flags |= poly1305_final_r_1;+        }+        poly1305_blocks(st, NULL, 32);+    }++    h0 = st->H.h[0];+    h1 = st->H.h[1];+    h2 = st->H.h[2];++    /* pad */+    h0 = ((h0) | (h1 << 44));+    h1 = ((h1 >> 20) | (h2 << 24));+#ifdef HAVE_AMD64_ASM+    __asm__ __volatile__(+        "addq %2, %0 ;\n"+        "adcq %3, %1 ;\n"+        : "+r"(h0), "+r"(h1)+        : "r"(st->pad[0]), "r"(st->pad[1])+        : "flags", "cc");+#else+    {+        uint128_t h;++        memcpy(&h, &st->pad[0], 16);+        h += ((uint128_t) h1 << 64) | h0;+        h0 = (uint64_t) h;+        h1 = (uint64_t)(h >> 64);+    }+#endif+    _mm_storeu_si128((xmmi *) (void *) st + 0, _mm_setzero_si128());+    _mm_storeu_si128((xmmi *) (void *) st + 1, _mm_setzero_si128());+    _mm_storeu_si128((xmmi *) (void *) st + 2, _mm_setzero_si128());+    _mm_storeu_si128((xmmi *) (void *) st + 3, _mm_setzero_si128());+    _mm_storeu_si128((xmmi *) (void *) st + 4, _mm_setzero_si128());+    _mm_storeu_si128((xmmi *) (void *) st + 5, _mm_setzero_si128());+    _mm_storeu_si128((xmmi *) (void *) st + 6, _mm_setzero_si128());+    _mm_storeu_si128((xmmi *) (void *) st + 7, _mm_setzero_si128());++    memcpy(&mac[0], &h0, 8);+    memcpy(&mac[8], &h1, 8);++    sodium_memzero((void *) st, sizeof *st);+}++static void+poly1305_finish(poly1305_state_internal_t *st, unsigned char mac[16])+{+    poly1305_finish_ext(st, st->buffer, st->leftover, mac);+}++static int+crypto_onetimeauth_poly1305_sse2_init(crypto_onetimeauth_poly1305_state *state,+                                      const unsigned char *key)+{+    COMPILER_ASSERT(sizeof(crypto_onetimeauth_poly1305_state) >=+                    sizeof(poly1305_state_internal_t));+    poly1305_init_ext((poly1305_state_internal_t *) (void *) state, key, 0U);++    return 0;+}++static int+crypto_onetimeauth_poly1305_sse2_update(+    crypto_onetimeauth_poly1305_state *state, const unsigned char *in,+    unsigned long long inlen)+{+    poly1305_update((poly1305_state_internal_t *) (void *) state, in, inlen);++    return 0;+}++static int+crypto_onetimeauth_poly1305_sse2_final(crypto_onetimeauth_poly1305_state *state,+                                       unsigned char *out)+{+    poly1305_finish((poly1305_state_internal_t *) (void *) state, out);++    return 0;+}++static int+crypto_onetimeauth_poly1305_sse2(unsigned char *out, const unsigned char *m,+                                 unsigned long long   inlen,+                                 const unsigned char *key)+{+    CRYPTO_ALIGN(64) poly1305_state_internal_t st;+    unsigned long long                         blocks;++    poly1305_init_ext(&st, key, inlen);+    blocks = inlen & ~31;+    if (blocks > 0) {+        poly1305_blocks(&st, m, blocks);+        m += blocks;+        inlen -= blocks;+    }+    poly1305_finish_ext(&st, m, inlen, out);++    return 0;+}++static int+crypto_onetimeauth_poly1305_sse2_verify(const unsigned char *h,+                                        const unsigned char *in,+                                        unsigned long long   inlen,+                                        const unsigned char *k)+{+    unsigned char correct[16];++    crypto_onetimeauth_poly1305_sse2(correct, in, inlen, k);++    return crypto_verify_16(h, correct);+}++struct crypto_onetimeauth_poly1305_implementation+    crypto_onetimeauth_poly1305_sse2_implementation = {+        SODIUM_C99(.onetimeauth =) crypto_onetimeauth_poly1305_sse2,+        SODIUM_C99(.onetimeauth_verify =)+            crypto_onetimeauth_poly1305_sse2_verify,+        SODIUM_C99(.onetimeauth_init =) crypto_onetimeauth_poly1305_sse2_init,+        SODIUM_C99(.onetimeauth_update =)+            crypto_onetimeauth_poly1305_sse2_update,+        SODIUM_C99(.onetimeauth_final =) crypto_onetimeauth_poly1305_sse2_final+    };++#endif
+ vendor/external/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.h view
@@ -0,0 +1,12 @@+#ifndef poly1305_sse2_H+#define poly1305_sse2_H++#include <stddef.h>++#include "crypto_onetimeauth_poly1305.h"+#include "external/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.h"++extern struct crypto_onetimeauth_poly1305_implementation+    crypto_onetimeauth_poly1305_sse2_implementation;++#endif /* poly1305_sse2_H */
+ vendor/external/libsodium/crypto_scalarmult/crypto_scalarmult.c view
@@ -0,0 +1,33 @@++#include "crypto_scalarmult.h"++const char *+crypto_scalarmult_primitive(void)+{+    return crypto_scalarmult_PRIMITIVE;+}++int+crypto_scalarmult_base(unsigned char *q, const unsigned char *n)+{+    return crypto_scalarmult_curve25519_base(q, n);+}++int+crypto_scalarmult(unsigned char *q, const unsigned char *n,+                  const unsigned char *p)+{+    return crypto_scalarmult_curve25519(q, n, p);+}++size_t+crypto_scalarmult_bytes(void)+{+    return crypto_scalarmult_BYTES;+}++size_t+crypto_scalarmult_scalarbytes(void)+{+    return crypto_scalarmult_SCALARBYTES;+}
+ vendor/external/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c view
@@ -0,0 +1,182 @@++#include <stddef.h>+#include <stdint.h>++#include "../scalarmult_curve25519.h"+#include "export.h"+#include "private/ed25519_ref10.h"+#include "utils.h"+#include "x25519_ref10.h"++/*+ * Reject small order points early to mitigate the implications of+ * unexpected optimizations that would affect the ref10 code.+ * See https://eprint.iacr.org/2017/806.pdf for reference.+ */+static int+has_small_order(const unsigned char s[32])+{+    CRYPTO_ALIGN(16)+    static const unsigned char blacklist[][32] = {+        /* 0 (order 4) */+        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },+        /* 1 (order 1) */+        { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },+        /* 325606250916557431795983626356110631294008115727848805560023387167927233504+           (order 8) */+        { 0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3,+          0xfa, 0xf1, 0x9f, 0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32,+          0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00 },+        /* 39382357235489614581723060781553021112529911719440698176882885853963445705823+           (order 8) */+        { 0x5f, 0x9c, 0x95, 0xbc, 0xa3, 0x50, 0x8c, 0x24, 0xb1, 0xd0, 0xb1,+          0x55, 0x9c, 0x83, 0xef, 0x5b, 0x04, 0x44, 0x5c, 0xc4, 0x58, 0x1c,+          0x8e, 0x86, 0xd8, 0x22, 0x4e, 0xdd, 0xd0, 0x9f, 0x11, 0x57 },+        /* p-1 (order 2) */+        { 0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f },+        /* p (=0, order 4) */+        { 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f },+        /* p+1 (=1, order 1) */+        { 0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }+    };+    unsigned char c[7] = { 0 };+    unsigned int  k;+    size_t        i, j;++    COMPILER_ASSERT(7 == sizeof blacklist / sizeof blacklist[0]);+    for (j = 0; j < 31; j++) {+        for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {+            c[i] |= s[j] ^ blacklist[i][j];+        }+    }+    for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {+        c[i] |= (s[j] & 0x7f) ^ blacklist[i][j];+    }+    k = 0;+    for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {+        k |= (c[i] - 1);+    }+    return (int) ((k >> 8) & 1);+}++static int+crypto_scalarmult_curve25519_ref10(unsigned char *q,+                                   const unsigned char *n,+                                   const unsigned char *p)+{+    unsigned char  t[32];+    unsigned int   i;+    fe25519        x1;+    fe25519        x2;+    fe25519        z2;+    fe25519        x3;+    fe25519        z3;+    fe25519        tmp0;+    fe25519        tmp1;+    int            pos;+    unsigned int   swap;+    unsigned int   b;++    if (has_small_order(p)) {+        return -1;+    }+    for (i = 0; i < 32; i++) {+        t[i] = n[i];+    }+    t[0] &= 248;+    t[31] &= 127;+    t[31] |= 64;+    fe25519_frombytes(x1, p);+    fe25519_1(x2);+    fe25519_0(z2);+    fe25519_copy(x3, x1);+    fe25519_1(z3);++    swap = 0;+    for (pos = 254; pos >= 0; --pos) {+        b = t[pos / 8] >> (pos & 7);+        b &= 1;+        swap ^= b;+        fe25519_cswap(x2, x3, swap);+        fe25519_cswap(z2, z3, swap);+        swap = b;+        fe25519_sub(tmp0, x3, z3);+        fe25519_sub(tmp1, x2, z2);+        fe25519_add(x2, x2, z2);+        fe25519_add(z2, x3, z3);+        fe25519_mul(z3, tmp0, x2);+        fe25519_mul(z2, z2, tmp1);+        fe25519_sq(tmp0, tmp1);+        fe25519_sq(tmp1, x2);+        fe25519_add(x3, z3, z2);+        fe25519_sub(z2, z3, z2);+        fe25519_mul(x2, tmp1, tmp0);+        fe25519_sub(tmp1, tmp1, tmp0);+        fe25519_sq(z2, z2);+        fe25519_mul32(z3, tmp1, 121666);+        fe25519_sq(x3, x3);+        fe25519_add(tmp0, tmp0, z3);+        fe25519_mul(z3, x1, z2);+        fe25519_mul(z2, tmp1, tmp0);+    }+    fe25519_cswap(x2, x3, swap);+    fe25519_cswap(z2, z3, swap);++    fe25519_invert(z2, z2);+    fe25519_mul(x2, x2, z2);+    fe25519_tobytes(q, x2);++    sodium_memzero(t, sizeof t);++    return 0;+}++static void+edwards_to_montgomery(fe25519 montgomeryX, const fe25519 edwardsY, const fe25519 edwardsZ)+{+    fe25519 tempX;+    fe25519 tempZ;++    fe25519_add(tempX, edwardsZ, edwardsY);+    fe25519_sub(tempZ, edwardsZ, edwardsY);+    fe25519_invert(tempZ, tempZ);+    fe25519_mul(montgomeryX, tempX, tempZ);+}++static int+crypto_scalarmult_curve25519_ref10_base(unsigned char *q,+                                        const unsigned char *n)+{+    unsigned char *t = q;+    ge25519_p3     A;+    fe25519        pk;+    unsigned int   i;++    for (i = 0; i < 32; i++) {+        t[i] = n[i];+    }+    t[0] &= 248;+    t[31] &= 127;+    t[31] |= 64;+    ge25519_scalarmult_base(&A, t);+    edwards_to_montgomery(pk, A.Y, A.Z);+    fe25519_tobytes(q, pk);++    return 0;+}++struct crypto_scalarmult_curve25519_implementation+    crypto_scalarmult_curve25519_ref10_implementation = {+        SODIUM_C99(.mult =) crypto_scalarmult_curve25519_ref10,+        SODIUM_C99(.mult_base =) crypto_scalarmult_curve25519_ref10_base+    };
+ vendor/external/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.h view
@@ -0,0 +1,10 @@+#ifndef x25519_ref10_H+#define x25519_ref10_H++#include "crypto_scalarmult_curve25519.h"+#include "external/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.h"++extern struct crypto_scalarmult_curve25519_implementation+    crypto_scalarmult_curve25519_ref10_implementation;++#endif
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/consts_namespace.h view
@@ -0,0 +1,20 @@+#ifndef consts_namespace_H+#define consts_namespace_H++#define v0_0 crypto_scalarmult_curve25519_sandy2x_v0_0+#define v1_0 crypto_scalarmult_curve25519_sandy2x_v1_0+#define v2_1 crypto_scalarmult_curve25519_sandy2x_v2_1+#define v9_0 crypto_scalarmult_curve25519_sandy2x_v9_0+#define v9_9 crypto_scalarmult_curve25519_sandy2x_v9_9+#define v19_19 crypto_scalarmult_curve25519_sandy2x_v19_19+#define v38_1 crypto_scalarmult_curve25519_sandy2x_v38_1+#define v38_38 crypto_scalarmult_curve25519_sandy2x_v38_38+#define v121666_121666 crypto_scalarmult_curve25519_sandy2x_v121666_121666+#define m25 crypto_scalarmult_curve25519_sandy2x_m25+#define m26 crypto_scalarmult_curve25519_sandy2x_m26+#define subc0 crypto_scalarmult_curve25519_sandy2x_subc0+#define subc2 crypto_scalarmult_curve25519_sandy2x_subc2+#define REDMASK51 crypto_scalarmult_curve25519_sandy2x_REDMASK51++#endif /* ifndef consts_namespace_H */+
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c view
@@ -0,0 +1,71 @@+/*+   This file is adapted from ref10/scalarmult.c:+   The code for Mongomery ladder is replace by the ladder assembly function;+   Inversion is done in the same way as amd64-51/.+   (fe is first converted into fe51 after Mongomery ladder)+*/++#include <stddef.h>++#ifdef HAVE_AVX_ASM++#include "utils.h"+#include "curve25519_sandy2x.h"+#include "../scalarmult_curve25519.h"+#include "fe.h"+#include "fe51.h"+#include "ladder.h"++#define x1 var[0]+#define x2 var[1]+#define z2 var[2]++static int+crypto_scalarmult_curve25519_sandy2x(unsigned char *q, const unsigned char *n,+                                     const unsigned char *p)+{+    unsigned char  t[32];+    fe             var[3];+    fe51           x_51;+    fe51           z_51;+    unsigned int   i;++    for (i = 0; i < 32; i++) {+        t[i] = n[i];+    }+    t[0] &= 248;+    t[31] &= 127;+    t[31] |= 64;++    fe_frombytes(x1, p);++    ladder(var, t);++    z_51.v[0] = (z2[1] << 26) + z2[0];+    z_51.v[1] = (z2[3] << 26) + z2[2];+    z_51.v[2] = (z2[5] << 26) + z2[4];+    z_51.v[3] = (z2[7] << 26) + z2[6];+    z_51.v[4] = (z2[9] << 26) + z2[8];++    x_51.v[0] = (x2[1] << 26) + x2[0];+    x_51.v[1] = (x2[3] << 26) + x2[2];+    x_51.v[2] = (x2[5] << 26) + x2[4];+    x_51.v[3] = (x2[7] << 26) + x2[6];+    x_51.v[4] = (x2[9] << 26) + x2[8];++    fe51_invert(&z_51, &z_51);+    fe51_mul(&x_51, &x_51, &z_51);+    fe51_pack(q, &x_51);++    sodium_memzero(t, sizeof t);++    return 0;+}++struct crypto_scalarmult_curve25519_implementation+crypto_scalarmult_curve25519_sandy2x_implementation = {+    SODIUM_C99(.mult = ) crypto_scalarmult_curve25519_sandy2x,+    SODIUM_C99(.mult_base = ) NULL+};++#endif
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.h view
@@ -0,0 +1,9 @@+#ifndef curve25519_sandy2x_H+#define curve25519_sandy2x_H++#include "crypto_scalarmult_curve25519.h"++extern struct crypto_scalarmult_curve25519_implementation+    crypto_scalarmult_curve25519_sandy2x_implementation;++#endif
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe.h view
@@ -0,0 +1,26 @@+/*+   This file is adapted from ref10/fe.h:+   All the redundant functions are removed.+*/++#ifndef fe_H+#define fe_H++#include <stdint.h>+#include <stdlib.h>++typedef uint64_t fe[10];++/*+fe means field element.+Here the field is \Z/(2^255-19).+An element t, entries t[0]...t[9], represents the integer+t[0]+2^26 t[1]+2^51 t[2]+2^77 t[3]+2^102 t[4]+...+2^230 t[9].+Bounds on each t[i] vary depending on context.+*/++#define fe_frombytes crypto_scalarmult_curve25519_sandy2x_fe_frombytes++extern void fe_frombytes(fe, const unsigned char *);++#endif
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51.h view
@@ -0,0 +1,35 @@+/*+   This file is adapted from amd64-51/fe25519.h:+   'fe25519' is renamed as 'fe51';+   All the redundant functions are removed;+   New function fe51_nsquare is introduced.+*/++#ifndef fe51_H+#define fe51_H++#ifdef __cplusplus+extern "C" {+#endif++#include <stdint.h>+#include <stdlib.h>++#include "fe51_namespace.h"++typedef struct+{+    uint64_t v[5];+}+fe51;++extern void fe51_pack(unsigned char *, const fe51 *);+extern void fe51_mul(fe51 *, const fe51 *, const fe51 *);+extern void fe51_nsquare(fe51 *, const fe51 *, int);+extern void fe51_invert(fe51 *, const fe51 *);++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c view
@@ -0,0 +1,58 @@+/*+   This file is adapted from amd64-51/fe25519_invert.c:+   Loops of squares are replaced by nsquares for better performance.+*/++#include "fe51.h"++#ifdef HAVE_AVX_ASM++#define fe51_square(x, y) fe51_nsquare(x, y, 1)++void+fe51_invert(fe51 *r, const fe51 *x)+{+    fe51 z2;+    fe51 z9;+    fe51 z11;+    fe51 z2_5_0;+    fe51 z2_10_0;+    fe51 z2_20_0;+    fe51 z2_50_0;+    fe51 z2_100_0;+    fe51 t;++    /* 2 */ fe51_square(&z2,x);+    /* 4 */ fe51_square(&t,&z2);+    /* 8 */ fe51_square(&t,&t);+    /* 9 */ fe51_mul(&z9,&t,x);+    /* 11 */ fe51_mul(&z11,&z9,&z2);+    /* 22 */ fe51_square(&t,&z11);+    /* 2^5 - 2^0 = 31 */ fe51_mul(&z2_5_0,&t,&z9);++    /* 2^10 - 2^5 */ fe51_nsquare(&t,&z2_5_0, 5);+    /* 2^10 - 2^0 */ fe51_mul(&z2_10_0,&t,&z2_5_0);++    /* 2^20 - 2^10 */ fe51_nsquare(&t,&z2_10_0, 10);+    /* 2^20 - 2^0 */ fe51_mul(&z2_20_0,&t,&z2_10_0);++    /* 2^40 - 2^20 */ fe51_nsquare(&t,&z2_20_0, 20);+    /* 2^40 - 2^0 */ fe51_mul(&t,&t,&z2_20_0);++    /* 2^50 - 2^10 */ fe51_nsquare(&t,&t,10);+    /* 2^50 - 2^0 */ fe51_mul(&z2_50_0,&t,&z2_10_0);++    /* 2^100 - 2^50 */ fe51_nsquare(&t,&z2_50_0, 50);+    /* 2^100 - 2^0 */ fe51_mul(&z2_100_0,&t,&z2_50_0);++    /* 2^200 - 2^100 */ fe51_nsquare(&t,&z2_100_0, 100);+    /* 2^200 - 2^0 */ fe51_mul(&t,&t,&z2_100_0);++    /* 2^250 - 2^50 */ fe51_nsquare(&t,&t, 50);+    /* 2^250 - 2^0 */ fe51_mul(&t,&t,&z2_50_0);++    /* 2^255 - 2^5 */ fe51_nsquare(&t,&t,5);+    /* 2^255 - 21 */ fe51_mul(r,&t,&z11);+}++#endif
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_namespace.h view
@@ -0,0 +1,16 @@+#ifndef fe51_namespace_H+#define fe51_namespace_H++#define  fe51              crypto_scalarmult_curve25519_sandy2x_fe51+#define _fe51             _crypto_scalarmult_curve25519_sandy2x_fe51+#define  fe51_pack         crypto_scalarmult_curve25519_sandy2x_fe51_pack+#define _fe51_pack        _crypto_scalarmult_curve25519_sandy2x_fe51_pack+#define  fe51_mul          crypto_scalarmult_curve25519_sandy2x_fe51_mul+#define _fe51_mul         _crypto_scalarmult_curve25519_sandy2x_fe51_mul+#define  fe51_nsquare      crypto_scalarmult_curve25519_sandy2x_fe51_nsquare+#define _fe51_nsquare     _crypto_scalarmult_curve25519_sandy2x_fe51_nsquare++#define  fe51_invert       crypto_scalarmult_curve25519_sandy2x_fe51_invert++#endif /* ifndef fe51_namespace_H */+
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c view
@@ -0,0 +1,78 @@+/*+   This file is basically ref10/fe_frombytes.h.+*/++#include "fe.h"++#ifdef HAVE_AVX_ASM++static uint64_t+load_3(const unsigned char *in)+{+    uint64_t result;+    result = (uint64_t) in[0];+    result |= ((uint64_t) in[1]) << 8;+    result |= ((uint64_t) in[2]) << 16;+    return result;+}++static uint64_t+load_4(const unsigned char *in)+{+    uint64_t result;+    result = (uint64_t) in[0];+    result |= ((uint64_t) in[1]) << 8;+    result |= ((uint64_t) in[2]) << 16;+    result |= ((uint64_t) in[3]) << 24;+    return result;+}++void+fe_frombytes(fe h, const unsigned char *s)+{+    uint64_t h0 = load_4(s);+    uint64_t h1 = load_3(s + 4) << 6;+    uint64_t h2 = load_3(s + 7) << 5;+    uint64_t h3 = load_3(s + 10) << 3;+    uint64_t h4 = load_3(s + 13) << 2;+    uint64_t h5 = load_4(s + 16);+    uint64_t h6 = load_3(s + 20) << 7;+    uint64_t h7 = load_3(s + 23) << 5;+    uint64_t h8 = load_3(s + 26) << 4;+    uint64_t h9 = (load_3(s + 29) & 8388607) << 2;+    uint64_t carry0;+    uint64_t carry1;+    uint64_t carry2;+    uint64_t carry3;+    uint64_t carry4;+    uint64_t carry5;+    uint64_t carry6;+    uint64_t carry7;+    uint64_t carry8;+    uint64_t carry9;++    carry9 = h9 >> 25; h0 += carry9 * 19; h9 &= 0x1FFFFFF;+    carry1 = h1 >> 25; h2 += carry1; h1 &= 0x1FFFFFF;+    carry3 = h3 >> 25; h4 += carry3; h3 &= 0x1FFFFFF;+    carry5 = h5 >> 25; h6 += carry5; h5 &= 0x1FFFFFF;+    carry7 = h7 >> 25; h8 += carry7; h7 &= 0x1FFFFFF;++    carry0 = h0 >> 26; h1 += carry0; h0 &= 0x3FFFFFF;+    carry2 = h2 >> 26; h3 += carry2; h2 &= 0x3FFFFFF;+    carry4 = h4 >> 26; h5 += carry4; h4 &= 0x3FFFFFF;+    carry6 = h6 >> 26; h7 += carry6; h6 &= 0x3FFFFFF;+    carry8 = h8 >> 26; h9 += carry8; h8 &= 0x3FFFFFF;++    h[0] = h0;+    h[1] = h1;+    h[2] = h2;+    h[3] = h3;+    h[4] = h4;+    h[5] = h5;+    h[6] = h6;+    h[7] = h7;+    h[8] = h8;+    h[9] = h9;+}++#endif
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.h view
@@ -0,0 +1,18 @@+#ifndef ladder_H+#define ladder_H++#ifdef __cplusplus+extern "C" {+#endif++#include "fe.h"+#include "ladder_namespace.h"++extern void ladder(fe *, const unsigned char *);++#ifdef __cplusplus+}+#endif++#endif /* ifndef ladder_H */+
+ vendor/external/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_namespace.h view
@@ -0,0 +1,8 @@+#ifndef ladder_namespace_H+#define ladder_namespace_H++#define  ladder  crypto_scalarmult_curve25519_sandy2x_ladder+#define _ladder _crypto_scalarmult_curve25519_sandy2x_ladder++#endif /* ifndef ladder_namespace_H */+
+ vendor/external/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c view
@@ -0,0 +1,60 @@++#include "crypto_scalarmult_curve25519.h"+#include "private/implementations.h"+#include "scalarmult_curve25519.h"+#include "runtime.h"++#ifdef HAVE_AVX_ASM+# include "sandy2x/curve25519_sandy2x.h"+#endif+#include "ref10/x25519_ref10.h"+static const crypto_scalarmult_curve25519_implementation *implementation =+    &crypto_scalarmult_curve25519_ref10_implementation;++int+crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n,+                             const unsigned char *p)+{+    size_t                 i;+    volatile unsigned char d = 0;++    if (implementation->mult(q, n, p) != 0) {+        return -1; /* LCOV_EXCL_LINE */+    }+    for (i = 0; i < crypto_scalarmult_curve25519_BYTES; i++) {+        d |= q[i];+    }+    return -(1 & ((d - 1) >> 8));+}++int+crypto_scalarmult_curve25519_base(unsigned char *q, const unsigned char *n)+{+    return crypto_scalarmult_curve25519_ref10_implementation+        .mult_base(q, n);+}++size_t+crypto_scalarmult_curve25519_bytes(void)+{+    return crypto_scalarmult_curve25519_BYTES;+}++size_t+crypto_scalarmult_curve25519_scalarbytes(void)+{+    return crypto_scalarmult_curve25519_SCALARBYTES;+}++int+_crypto_scalarmult_curve25519_pick_best_implementation(void)+{+    implementation = &crypto_scalarmult_curve25519_ref10_implementation;++#ifdef HAVE_AVX_ASM+    if (sodium_runtime_has_avx()) {+        implementation = &crypto_scalarmult_curve25519_sandy2x_implementation;+    }+#endif+    return 0;+}
+ vendor/external/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.h view
@@ -0,0 +1,11 @@++#ifndef scalarmult_poly1305_H+#define scalarmult_poly1305_H++typedef struct crypto_scalarmult_curve25519_implementation {+    int (*mult)(unsigned char *q, const unsigned char *n,+                const unsigned char *p);+    int (*mult_base)(unsigned char *q, const unsigned char *n);+} crypto_scalarmult_curve25519_implementation;++#endif
+ vendor/external/libsodium/crypto_scalarmult/ed25519/ref10/scalarmult_ed25519_ref10.c view
@@ -0,0 +1,121 @@++#include <string.h>++#include "crypto_scalarmult_ed25519.h"+#include "private/ed25519_ref10.h"+#include "utils.h"++static int+_crypto_scalarmult_ed25519_is_inf(const unsigned char s[32])+{+    unsigned char c;+    unsigned int  i;++    c = s[0] ^ 0x01;+    for (i = 1; i < 31; i++) {+        c |= s[i];+    }+    c |= s[31] & 0x7f;++    return ((((unsigned int) c) - 1U) >> 8) & 1;+}++static inline void+_crypto_scalarmult_ed25519_clamp(unsigned char k[32])+{+    k[0] &= 248;+    k[31] |= 64;+}++static int+_crypto_scalarmult_ed25519(unsigned char *q, const unsigned char *n,+                           const unsigned char *p, const int clamp)+{+    unsigned char *t = q;+    ge25519_p3     Q;+    ge25519_p3     P;+    unsigned int   i;++    if (ge25519_is_canonical(p) == 0 || ge25519_has_small_order(p) != 0 ||+        ge25519_frombytes(&P, p) != 0 || ge25519_is_on_main_subgroup(&P) == 0) {+        return -1;+    }+    for (i = 0; i < 32; ++i) {+        t[i] = n[i];+    }+    if (clamp != 0) {+        _crypto_scalarmult_ed25519_clamp(t);+    }+    t[31] &= 127;++    ge25519_scalarmult(&Q, t, &P);+    ge25519_p3_tobytes(q, &Q);+    if (_crypto_scalarmult_ed25519_is_inf(q) != 0 || sodium_is_zero(n, 32)) {+        return -1;+    }+    return 0;+}++int+crypto_scalarmult_ed25519(unsigned char *q, const unsigned char *n,+                          const unsigned char *p)+{+    return _crypto_scalarmult_ed25519(q, n, p, 1);+}++int+crypto_scalarmult_ed25519_noclamp(unsigned char *q, const unsigned char *n,+                                  const unsigned char *p)+{+    return _crypto_scalarmult_ed25519(q, n, p, 0);+}++static int+_crypto_scalarmult_ed25519_base(unsigned char *q,+                                const unsigned char *n, const int clamp)+{+    unsigned char *t = q;+    ge25519_p3     Q;+    unsigned int   i;++    for (i = 0; i < 32; ++i) {+        t[i] = n[i];+    }+    if (clamp != 0) {+        _crypto_scalarmult_ed25519_clamp(t);+    }+    t[31] &= 127;++    ge25519_scalarmult_base(&Q, t);+    ge25519_p3_tobytes(q, &Q);+    if (_crypto_scalarmult_ed25519_is_inf(q) != 0 || sodium_is_zero(n, 32)) {+        return -1;+    }+    return 0;+}++int+crypto_scalarmult_ed25519_base(unsigned char *q,+                               const unsigned char *n)+{+    return _crypto_scalarmult_ed25519_base(q, n, 1);+}++int+crypto_scalarmult_ed25519_base_noclamp(unsigned char *q,+                                       const unsigned char *n)+{+    return _crypto_scalarmult_ed25519_base(q, n, 0);+}++size_t+crypto_scalarmult_ed25519_bytes(void)+{+    return crypto_scalarmult_ed25519_BYTES;+}++size_t+crypto_scalarmult_ed25519_scalarbytes(void)+{+    return crypto_scalarmult_ed25519_SCALARBYTES;+}
+ vendor/external/libsodium/crypto_secretstream/xchacha20poly1305/secretstream_xchacha20poly1305.c view
@@ -0,0 +1,313 @@+#include <stdint.h>+#include <stdlib.h>+#include <limits.h>+#include <string.h>++#include "core.h"+#include "crypto_aead_chacha20poly1305.h"+#include "crypto_aead_xchacha20poly1305.h"+#include "crypto_core_hchacha20.h"+#include "crypto_onetimeauth_poly1305.h"+#include "crypto_secretstream_xchacha20poly1305.h"+#include "randombytes.h"+#include "utils.h"++#include "private/common.h"++#define crypto_secretstream_xchacha20poly1305_COUNTERBYTES  4U+#define crypto_secretstream_xchacha20poly1305_INONCEBYTES   8U++#define STATE_COUNTER(STATE) ((STATE)->nonce)+#define STATE_INONCE(STATE)  ((STATE)->nonce + \+                              crypto_secretstream_xchacha20poly1305_COUNTERBYTES)++static const unsigned char _pad0[16] = { 0 };++static inline void+_crypto_secretstream_xchacha20poly1305_counter_reset+    (crypto_secretstream_xchacha20poly1305_state *state)+{+    memset(STATE_COUNTER(state), 0,+           crypto_secretstream_xchacha20poly1305_COUNTERBYTES);+    STATE_COUNTER(state)[0] = 1;+}++void+crypto_secretstream_xchacha20poly1305_keygen+   (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])+{+    randombytes_buf(k, crypto_secretstream_xchacha20poly1305_KEYBYTES);+}++int+crypto_secretstream_xchacha20poly1305_init_push+   (crypto_secretstream_xchacha20poly1305_state *state,+    unsigned char out[crypto_secretstream_xchacha20poly1305_HEADERBYTES],+    const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])+{+    COMPILER_ASSERT(crypto_secretstream_xchacha20poly1305_HEADERBYTES ==+                    crypto_core_hchacha20_INPUTBYTES ++                    crypto_secretstream_xchacha20poly1305_INONCEBYTES);+    COMPILER_ASSERT(crypto_secretstream_xchacha20poly1305_HEADERBYTES ==+                    crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);+    COMPILER_ASSERT(sizeof state->nonce ==+                    crypto_secretstream_xchacha20poly1305_INONCEBYTES ++                    crypto_secretstream_xchacha20poly1305_COUNTERBYTES);++    randombytes_buf(out, crypto_secretstream_xchacha20poly1305_HEADERBYTES);+    crypto_core_hchacha20(state->k, out, k, NULL);+    _crypto_secretstream_xchacha20poly1305_counter_reset(state);+    memcpy(STATE_INONCE(state), out + crypto_core_hchacha20_INPUTBYTES,+           crypto_secretstream_xchacha20poly1305_INONCEBYTES);+    memset(state->_pad, 0, sizeof state->_pad);++    return 0;+}++int+crypto_secretstream_xchacha20poly1305_init_pull+   (crypto_secretstream_xchacha20poly1305_state *state,+    const unsigned char in[crypto_secretstream_xchacha20poly1305_HEADERBYTES],+    const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])+{+    crypto_core_hchacha20(state->k, in, k, NULL);+    _crypto_secretstream_xchacha20poly1305_counter_reset(state);+    memcpy(STATE_INONCE(state), in + crypto_core_hchacha20_INPUTBYTES,+           crypto_secretstream_xchacha20poly1305_INONCEBYTES);+    memset(state->_pad, 0, sizeof state->_pad);++    return 0;+}++void+crypto_secretstream_xchacha20poly1305_rekey+    (crypto_secretstream_xchacha20poly1305_state *state)+{+    unsigned char new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES ++                                     crypto_secretstream_xchacha20poly1305_INONCEBYTES];+    size_t        i;++    for (i = 0U; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) {+        new_key_and_inonce[i] = state->k[i];+    }+    for (i = 0U; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) {+        new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i] =+            STATE_INONCE(state)[i];+    }+    crypto_stream_chacha20_ietf_xor(new_key_and_inonce, new_key_and_inonce,+                                    sizeof new_key_and_inonce,+                                    state->nonce, state->k);+    for (i = 0U; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) {+        state->k[i] = new_key_and_inonce[i];+    }+    for (i = 0U; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) {+        STATE_INONCE(state)[i] =+            new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i];+    }+    _crypto_secretstream_xchacha20poly1305_counter_reset(state);+}++int+crypto_secretstream_xchacha20poly1305_push+   (crypto_secretstream_xchacha20poly1305_state *state,+    unsigned char *out, unsigned long long *outlen_p,+    const unsigned char *m, unsigned long long mlen,+    const unsigned char *ad, unsigned long long adlen, unsigned char tag)+{+    crypto_onetimeauth_poly1305_state poly1305_state;+    unsigned char                     block[64U];+    unsigned char                     slen[8U];+    unsigned char                    *c;+    unsigned char                    *mac;++    if (outlen_p != NULL) {+        *outlen_p = 0U;+    }+    COMPILER_ASSERT(crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX+                    <= crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX);+    if (mlen > crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    crypto_stream_chacha20_ietf(block, sizeof block, state->nonce, state->k);+    crypto_onetimeauth_poly1305_init(&poly1305_state, block);+    sodium_memzero(block, sizeof block);++    crypto_onetimeauth_poly1305_update(&poly1305_state, ad, adlen);+    crypto_onetimeauth_poly1305_update(&poly1305_state, _pad0,+                                       (0x10 - adlen) & 0xf);+    memset(block, 0, sizeof block);+    block[0] = tag;++    crypto_stream_chacha20_ietf_xor_ic(block, block, sizeof block,+                                       state->nonce, 1U, state->k);+    crypto_onetimeauth_poly1305_update(&poly1305_state, block, sizeof block);+    out[0] = block[0];++    c = out + (sizeof tag);+    crypto_stream_chacha20_ietf_xor_ic(c, m, mlen, state->nonce, 2U, state->k);+    crypto_onetimeauth_poly1305_update(&poly1305_state, c, mlen);+    crypto_onetimeauth_poly1305_update+        (&poly1305_state, _pad0, (0x10 - (sizeof block) + mlen) & 0xf);++    STORE64_LE(slen, (uint64_t) adlen);+    crypto_onetimeauth_poly1305_update(&poly1305_state, slen, sizeof slen);+    STORE64_LE(slen, (sizeof block) + mlen);+    crypto_onetimeauth_poly1305_update(&poly1305_state, slen, sizeof slen);++    mac = c + mlen;+    crypto_onetimeauth_poly1305_final(&poly1305_state, mac);+    sodium_memzero(&poly1305_state, sizeof poly1305_state);++    COMPILER_ASSERT(crypto_onetimeauth_poly1305_BYTES >=+                    crypto_secretstream_xchacha20poly1305_INONCEBYTES);+    XOR_BUF(STATE_INONCE(state), mac,+            crypto_secretstream_xchacha20poly1305_INONCEBYTES);+    sodium_increment(STATE_COUNTER(state),+                     crypto_secretstream_xchacha20poly1305_COUNTERBYTES);+    if ((tag & crypto_secretstream_xchacha20poly1305_TAG_REKEY) != 0 ||+        sodium_is_zero(STATE_COUNTER(state),+                       crypto_secretstream_xchacha20poly1305_COUNTERBYTES)) {+        crypto_secretstream_xchacha20poly1305_rekey(state);+    }+    if (outlen_p != NULL) {+        *outlen_p = crypto_secretstream_xchacha20poly1305_ABYTES + mlen;+    }+    return 0;+}++int+crypto_secretstream_xchacha20poly1305_pull+   (crypto_secretstream_xchacha20poly1305_state *state,+    unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p,+    const unsigned char *in, unsigned long long inlen,+    const unsigned char *ad, unsigned long long adlen)+{+    crypto_onetimeauth_poly1305_state poly1305_state;+    unsigned char                     block[64U];+    unsigned char                     slen[8U];+    unsigned char                     mac[crypto_onetimeauth_poly1305_BYTES];+    const unsigned char              *c;+    const unsigned char              *stored_mac;+    unsigned long long                mlen;+    unsigned char                     tag;++    if (mlen_p != NULL) {+        *mlen_p = 0U;+    }+    if (tag_p != NULL) {+        *tag_p = 0xff;+    }+    if (inlen < crypto_secretstream_xchacha20poly1305_ABYTES) {+        return -1;+    }+    mlen = inlen - crypto_secretstream_xchacha20poly1305_ABYTES;+    if (mlen > crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    crypto_stream_chacha20_ietf(block, sizeof block, state->nonce, state->k);+    crypto_onetimeauth_poly1305_init(&poly1305_state, block);+    sodium_memzero(block, sizeof block);++    crypto_onetimeauth_poly1305_update(&poly1305_state, ad, adlen);+    crypto_onetimeauth_poly1305_update(&poly1305_state, _pad0,+                                       (0x10 - adlen) & 0xf);++    memset(block, 0, sizeof block);+    block[0] = in[0];+    crypto_stream_chacha20_ietf_xor_ic(block, block, sizeof block,+                                       state->nonce, 1U, state->k);+    tag = block[0];+    block[0] = in[0];+    crypto_onetimeauth_poly1305_update(&poly1305_state, block, sizeof block);++    c = in + (sizeof tag);+    crypto_onetimeauth_poly1305_update(&poly1305_state, c, mlen);+    crypto_onetimeauth_poly1305_update+        (&poly1305_state, _pad0, (0x10 - (sizeof block) + mlen) & 0xf);++    STORE64_LE(slen, (uint64_t) adlen);+    crypto_onetimeauth_poly1305_update(&poly1305_state, slen, sizeof slen);+    STORE64_LE(slen, (sizeof block) + mlen);+    crypto_onetimeauth_poly1305_update(&poly1305_state, slen, sizeof slen);++    crypto_onetimeauth_poly1305_final(&poly1305_state, mac);+    sodium_memzero(&poly1305_state, sizeof poly1305_state);++    stored_mac = c + mlen;+    if (sodium_memcmp(mac, stored_mac, sizeof mac) != 0) {+        sodium_memzero(mac, sizeof mac);+        return -1;+    }++    crypto_stream_chacha20_ietf_xor_ic(m, c, mlen, state->nonce, 2U, state->k);+    XOR_BUF(STATE_INONCE(state), mac,+            crypto_secretstream_xchacha20poly1305_INONCEBYTES);+    sodium_increment(STATE_COUNTER(state),+                     crypto_secretstream_xchacha20poly1305_COUNTERBYTES);+    if ((tag & crypto_secretstream_xchacha20poly1305_TAG_REKEY) != 0 ||+        sodium_is_zero(STATE_COUNTER(state),+                       crypto_secretstream_xchacha20poly1305_COUNTERBYTES)) {+        crypto_secretstream_xchacha20poly1305_rekey(state);+    }+    if (mlen_p != NULL) {+        *mlen_p = mlen;+    }+    if (tag_p != NULL) {+        *tag_p = tag;+    }+    return 0;+}++size_t+crypto_secretstream_xchacha20poly1305_statebytes(void)+{+    return sizeof(crypto_secretstream_xchacha20poly1305_state);+}++size_t+crypto_secretstream_xchacha20poly1305_abytes(void)+{+    return crypto_secretstream_xchacha20poly1305_ABYTES;+}++size_t+crypto_secretstream_xchacha20poly1305_headerbytes(void)+{+    return crypto_secretstream_xchacha20poly1305_HEADERBYTES;+}++size_t+crypto_secretstream_xchacha20poly1305_keybytes(void)+{+    return crypto_secretstream_xchacha20poly1305_KEYBYTES;+}++size_t+crypto_secretstream_xchacha20poly1305_messagebytes_max(void)+{+    return crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX;+}++unsigned char+crypto_secretstream_xchacha20poly1305_tag_message(void)+{+    return crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;+}++unsigned char+crypto_secretstream_xchacha20poly1305_tag_push(void)+{+    return crypto_secretstream_xchacha20poly1305_TAG_PUSH;+}++unsigned char+crypto_secretstream_xchacha20poly1305_tag_rekey(void)+{+    return crypto_secretstream_xchacha20poly1305_TAG_REKEY;+}++unsigned char+crypto_secretstream_xchacha20poly1305_tag_final(void)+{+    return crypto_secretstream_xchacha20poly1305_TAG_FINAL;+}
+ vendor/external/libsodium/crypto_sign/crypto_sign.c view
@@ -0,0 +1,115 @@++#include "crypto_sign.h"++size_t+crypto_sign_statebytes(void)+{+    return sizeof(crypto_sign_state);+}++size_t+crypto_sign_bytes(void)+{+    return crypto_sign_BYTES;+}++size_t+crypto_sign_seedbytes(void)+{+    return crypto_sign_SEEDBYTES;+}++size_t+crypto_sign_publickeybytes(void)+{+    return crypto_sign_PUBLICKEYBYTES;+}++size_t+crypto_sign_secretkeybytes(void)+{+    return crypto_sign_SECRETKEYBYTES;+}++size_t+crypto_sign_messagebytes_max(void)+{+    return crypto_sign_MESSAGEBYTES_MAX;+}++const char *+crypto_sign_primitive(void)+{+    return crypto_sign_PRIMITIVE;+}++int+crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk,+                         const unsigned char *seed)+{+    return crypto_sign_ed25519_seed_keypair(pk, sk, seed);+}++int+crypto_sign_keypair(unsigned char *pk, unsigned char *sk)+{+    return crypto_sign_ed25519_keypair(pk, sk);+}++int+crypto_sign(unsigned char *sm, unsigned long long *smlen_p,+            const unsigned char *m, unsigned long long mlen,+            const unsigned char *sk)+{+    return crypto_sign_ed25519(sm, smlen_p, m, mlen, sk);+}++int+crypto_sign_open(unsigned char *m, unsigned long long *mlen_p,+                 const unsigned char *sm, unsigned long long smlen,+                 const unsigned char *pk)+{+    return crypto_sign_ed25519_open(m, mlen_p, sm, smlen, pk);+}++int+crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p,+                     const unsigned char *m, unsigned long long mlen,+                     const unsigned char *sk)+{+    return crypto_sign_ed25519_detached(sig, siglen_p, m, mlen, sk);+}++int+crypto_sign_verify_detached(const unsigned char *sig, const unsigned char *m,+                            unsigned long long mlen, const unsigned char *pk)+{+    return crypto_sign_ed25519_verify_detached(sig, m, mlen, pk);+}++int+crypto_sign_init(crypto_sign_state *state)+{+    return crypto_sign_ed25519ph_init(state);+}++int+crypto_sign_update(crypto_sign_state *state, const unsigned char *m,+                   unsigned long long mlen)+{+    return crypto_sign_ed25519ph_update(state, m, mlen);+}++int+crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig,+                         unsigned long long *siglen_p, const unsigned char *sk)+{+    return crypto_sign_ed25519ph_final_create(state, sig, siglen_p, sk);+}++int+crypto_sign_final_verify(crypto_sign_state *state, const unsigned char *sig,+                         const unsigned char *pk)+{+    return crypto_sign_ed25519ph_final_verify(state, sig, pk);+}
+ vendor/external/libsodium/crypto_sign/ed25519/ref10/keypair.c view
@@ -0,0 +1,83 @@++#include <string.h>++#include "crypto_hash_sha512.h"+#include "crypto_scalarmult_curve25519.h"+#include "crypto_sign_ed25519.h"+#include "sign_ed25519_ref10.h"+#include "private/ed25519_ref10.h"+#include "randombytes.h"+#include "utils.h"++int+crypto_sign_ed25519_seed_keypair(unsigned char *pk, unsigned char *sk,+                                 const unsigned char *seed)+{+    ge25519_p3 A;++    crypto_hash_sha512(sk, seed, 32);+    sk[0] &= 248;+    sk[31] &= 127;+    sk[31] |= 64;++    ge25519_scalarmult_base(&A, sk);+    ge25519_p3_tobytes(pk, &A);++    memmove(sk, seed, 32);+    memmove(sk + 32, pk, 32);++    return 0;+}++int+crypto_sign_ed25519_keypair(unsigned char *pk, unsigned char *sk)+{+    unsigned char seed[32];+    int           ret;++    randombytes_buf(seed, sizeof seed);+    ret = crypto_sign_ed25519_seed_keypair(pk, sk, seed);+    sodium_memzero(seed, sizeof seed);++    return ret;+}++int+crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,+                                     const unsigned char *ed25519_pk)+{+    ge25519_p3 A;+    fe25519    x;+    fe25519    one_minus_y;++    if (ge25519_has_small_order(ed25519_pk) != 0 ||+        ge25519_frombytes_negate_vartime(&A, ed25519_pk) != 0 ||+        ge25519_is_on_main_subgroup(&A) == 0) {+        return -1;+    }+    fe25519_1(one_minus_y);+    fe25519_sub(one_minus_y, one_minus_y, A.Y);+    fe25519_1(x);+    fe25519_add(x, x, A.Y);+    fe25519_invert(one_minus_y, one_minus_y);+    fe25519_mul(x, x, one_minus_y);+    fe25519_tobytes(curve25519_pk, x);++    return 0;+}++int+crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,+                                     const unsigned char *ed25519_sk)+{+    unsigned char h[crypto_hash_sha512_BYTES];++    crypto_hash_sha512(h, ed25519_sk, 32);+    h[0] &= 248;+    h[31] &= 127;+    h[31] |= 64;+    memcpy(curve25519_sk, h, crypto_scalarmult_curve25519_BYTES);+    sodium_memzero(h, sizeof h);++    return 0;+}
+ vendor/external/libsodium/crypto_sign/ed25519/ref10/obsolete.c view
@@ -0,0 +1,118 @@++#include <limits.h>+#include <stdint.h>+#include <string.h>++#include "crypto_hash_sha512.h"+#include "crypto_sign_edwards25519sha512batch.h"+#include "crypto_verify_32.h"+#include "private/ed25519_ref10.h"+#include "randombytes.h"+#include "utils.h"++/* LCOV_EXCL_START */+int+crypto_sign_edwards25519sha512batch_keypair(unsigned char *pk,+                                            unsigned char *sk)+{+    ge25519_p3 A;++    randombytes_buf(sk, 32);+    crypto_hash_sha512(sk, sk, 32);+    sk[0] &= 248;+    sk[31] &= 127;+    sk[31] |= 64;+    ge25519_scalarmult_base(&A, sk);+    ge25519_p3_tobytes(pk, &A);++    return 0;+}++int+crypto_sign_edwards25519sha512batch(unsigned char       *sm,+                                    unsigned long long  *smlen_p,+                                    const unsigned char *m,+                                    unsigned long long   mlen,+                                    const unsigned char *sk)+{+    crypto_hash_sha512_state hs;+    unsigned char            nonce[64];+    unsigned char            hram[64];+    unsigned char            sig[64];+    ge25519_p3               A;+    ge25519_p3               R;++    crypto_hash_sha512_init(&hs);+    crypto_hash_sha512_update(&hs, sk + 32, 32);+    crypto_hash_sha512_update(&hs, m, mlen);+    crypto_hash_sha512_final(&hs, nonce);+    ge25519_scalarmult_base(&A, sk);+    ge25519_p3_tobytes(sig + 32, &A);+    sc25519_reduce(nonce);+    ge25519_scalarmult_base(&R, nonce);+    ge25519_p3_tobytes(sig, &R);+    crypto_hash_sha512_init(&hs);+    crypto_hash_sha512_update(&hs, sig, 32);+    crypto_hash_sha512_update(&hs, m, mlen);+    crypto_hash_sha512_final(&hs, hram);+    sc25519_reduce(hram);+    sc25519_muladd(sig + 32, hram, nonce, sk);+    sodium_memzero(hram, sizeof hram);+    memmove(sm + 32, m, (size_t) mlen);+    memcpy(sm, sig, 32);+    memcpy(sm + 32 + mlen, sig + 32, 32);+    *smlen_p = mlen + 64U;++    return 0;+}++int+crypto_sign_edwards25519sha512batch_open(unsigned char       *m,+                                         unsigned long long  *mlen_p,+                                         const unsigned char *sm,+                                         unsigned long long   smlen,+                                         const unsigned char *pk)+{+    unsigned char      h[64];+    unsigned char      t1[32], t2[32];+    unsigned long long mlen;+    ge25519_cached     Ai;+    ge25519_p1p1       csa;+    ge25519_p2         cs;+    ge25519_p3         A;+    ge25519_p3         R;+    ge25519_p3         cs3;++    *mlen_p = 0;+    if (smlen < 64 || smlen - 64 > crypto_sign_edwards25519sha512batch_MESSAGEBYTES_MAX) {+        return -1;+    }+    mlen = smlen - 64;+    if (sm[smlen - 1] & 224) {+        return -1;+    }+    if (ge25519_has_small_order(pk) != 0 ||+        ge25519_frombytes_negate_vartime(&A, pk) != 0 ||+        ge25519_has_small_order(sm) != 0 ||+        ge25519_frombytes_negate_vartime(&R, sm) != 0) {+        return -1;+    }+    ge25519_p3_to_cached(&Ai, &A);+    crypto_hash_sha512(h, sm, mlen + 32);+    sc25519_reduce(h);+    ge25519_scalarmult(&cs3, h, &R);+    ge25519_add(&csa, &cs3, &Ai);+    ge25519_p1p1_to_p2(&cs, &csa);+    ge25519_tobytes(t1, &cs);+    t1[31] ^= 1 << 7;+    ge25519_scalarmult_base(&R, sm + 32 + mlen);+    ge25519_p3_tobytes(t2, &R);+    if (crypto_verify_32(t1, t2) != 0) {+        return -1;+    }+    *mlen_p = mlen;+    memmove(m, sm + 32, mlen);++    return 0;+}+/* LCOV_EXCL_END */
+ vendor/external/libsodium/crypto_sign/ed25519/ref10/open.c view
@@ -0,0 +1,98 @@++#include <limits.h>+#include <stdint.h>+#include <string.h>++#include "crypto_hash_sha512.h"+#include "crypto_sign_ed25519.h"+#include "crypto_verify_32.h"+#include "sign_ed25519_ref10.h"+#include "private/common.h"+#include "private/ed25519_ref10.h"+#include "utils.h"++int+_crypto_sign_ed25519_verify_detached(const unsigned char *sig,+                                     const unsigned char *m,+                                     unsigned long long   mlen,+                                     const unsigned char *pk,+                                     int prehashed)+{+    crypto_hash_sha512_state hs;+    unsigned char            h[64];+    unsigned char            rcheck[32];+    ge25519_p3               A;+    ge25519_p2               R;++    ACQUIRE_FENCE;+#ifdef ED25519_COMPAT+    if (sig[63] & 224) {+        return -1;+    }+#else+    if (sc25519_is_canonical(sig + 32) == 0 ||+        ge25519_has_small_order(sig) != 0) {+        return -1;+    }+    if (ge25519_is_canonical(pk) == 0 ||+        ge25519_has_small_order(pk) != 0) {+        return -1;+    }+#endif+    if (ge25519_frombytes_negate_vartime(&A, pk) != 0) {+        return -1;+    }+    _crypto_sign_ed25519_ref10_hinit(&hs, prehashed);+    crypto_hash_sha512_update(&hs, sig, 32);+    crypto_hash_sha512_update(&hs, pk, 32);+    crypto_hash_sha512_update(&hs, m, mlen);+    crypto_hash_sha512_final(&hs, h);+    sc25519_reduce(h);++    ge25519_double_scalarmult_vartime(&R, h, &A, sig + 32);+    ge25519_tobytes(rcheck, &R);++    return crypto_verify_32(rcheck, sig) | (-(rcheck == sig)) |+           sodium_memcmp(sig, rcheck, 32);+}++int+crypto_sign_ed25519_verify_detached(const unsigned char *sig,+                                    const unsigned char *m,+                                    unsigned long long   mlen,+                                    const unsigned char *pk)+{+    return _crypto_sign_ed25519_verify_detached(sig, m, mlen, pk, 0);+}++int+crypto_sign_ed25519_open(unsigned char *m, unsigned long long *mlen_p,+                         const unsigned char *sm, unsigned long long smlen,+                         const unsigned char *pk)+{+    unsigned long long mlen;++    if (smlen < 64 || smlen - 64 > crypto_sign_ed25519_MESSAGEBYTES_MAX) {+        goto badsig;+    }+    mlen = smlen - 64;+    if (crypto_sign_ed25519_verify_detached(sm, sm + 64, mlen, pk) != 0) {+        if (m != NULL) {+            memset(m, 0, mlen);+        }+        goto badsig;+    }+    if (mlen_p != NULL) {+        *mlen_p = mlen;+    }+    if (m != NULL) {+        memmove(m, sm + 64, mlen);+    }+    return 0;++badsig:+    if (mlen_p != NULL) {+        *mlen_p = 0;+    }+    return -1;+}
+ vendor/external/libsodium/crypto_sign/ed25519/ref10/sign.c view
@@ -0,0 +1,128 @@++#include <string.h>++#include "crypto_hash_sha512.h"+#include "crypto_sign_ed25519.h"+#include "sign_ed25519_ref10.h"+#include "private/ed25519_ref10.h"+#include "randombytes.h"+#include "utils.h"++void+_crypto_sign_ed25519_ref10_hinit(crypto_hash_sha512_state *hs, int prehashed)+{+    static const unsigned char DOM2PREFIX[32 + 2] = {+        'S', 'i', 'g', 'E', 'd', '2', '5', '5', '1', '9', ' ',+        'n', 'o', ' ',+        'E', 'd', '2', '5', '5', '1', '9', ' ',+        'c', 'o', 'l', 'l', 'i', 's', 'i', 'o', 'n', 's', 1, 0+    };++    crypto_hash_sha512_init(hs);+    if (prehashed) {+        crypto_hash_sha512_update(hs, DOM2PREFIX, sizeof DOM2PREFIX);+    }+}++static inline void+_crypto_sign_ed25519_clamp(unsigned char k[32])+{+    k[0] &= 248;+    k[31] &= 127;+    k[31] |= 64;+}++#ifdef ED25519_NONDETERMINISTIC+/* r = hash(k || K || noise || pad || M) (mod q) */+static void+_crypto_sign_ed25519_synthetic_r_hv(crypto_hash_sha512_state *hs,+                                    unsigned char tmp[64],+                                    const unsigned char az[64])+{+    crypto_hash_sha512_update(hs, az, 64);+    randombytes_buf(tmp, 32);+    memset(tmp + 32, 0, 32);+    crypto_hash_sha512_update(hs, tmp, 64);+}+#endif++int+_crypto_sign_ed25519_detached(unsigned char *sig, unsigned long long *siglen_p,+                              const unsigned char *m, unsigned long long mlen,+                              const unsigned char *sk, int prehashed)+{+    crypto_hash_sha512_state hs;+    unsigned char            az[64];+    unsigned char            nonce[64];+    unsigned char            hram[64];+    ge25519_p3               R;++    _crypto_sign_ed25519_ref10_hinit(&hs, prehashed);++    crypto_hash_sha512(az, sk, 32);+#ifdef ED25519_NONDETERMINISTIC+    _crypto_sign_ed25519_synthetic_r_hv(&hs, nonce /* tmp */, az);+#else+    crypto_hash_sha512_update(&hs, az + 32, 32);+#endif++    crypto_hash_sha512_update(&hs, m, mlen);+    crypto_hash_sha512_final(&hs, nonce);++    memmove(sig + 32, sk + 32, 32);++    sc25519_reduce(nonce);+    ge25519_scalarmult_base(&R, nonce);+    ge25519_p3_tobytes(sig, &R);++    _crypto_sign_ed25519_ref10_hinit(&hs, prehashed);+    crypto_hash_sha512_update(&hs, sig, 64);+    crypto_hash_sha512_update(&hs, m, mlen);+    crypto_hash_sha512_final(&hs, hram);++    sc25519_reduce(hram);+    _crypto_sign_ed25519_clamp(az);+    sc25519_muladd(sig + 32, hram, az, nonce);++    sodium_memzero(az, sizeof az);+    sodium_memzero(nonce, sizeof nonce);++    if (siglen_p != NULL) {+        *siglen_p = 64U;+    }+    return 0;+}++int+crypto_sign_ed25519_detached(unsigned char *sig, unsigned long long *siglen_p,+                             const unsigned char *m, unsigned long long mlen,+                             const unsigned char *sk)+{+    return _crypto_sign_ed25519_detached(sig, siglen_p, m, mlen, sk, 0);+}++int+crypto_sign_ed25519(unsigned char *sm, unsigned long long *smlen_p,+                    const unsigned char *m, unsigned long long mlen,+                    const unsigned char *sk)+{+    unsigned long long siglen;++    memmove(sm + crypto_sign_ed25519_BYTES, m, mlen);+    /* LCOV_EXCL_START */+    if (crypto_sign_ed25519_detached(+            sm, &siglen, sm + crypto_sign_ed25519_BYTES, mlen, sk) != 0 ||+        siglen != crypto_sign_ed25519_BYTES) {+        if (smlen_p != NULL) {+            *smlen_p = 0;+        }+        memset(sm, 0, mlen + crypto_sign_ed25519_BYTES);+        return -1;+    }+    /* LCOV_EXCL_STOP */++    if (smlen_p != NULL) {+        *smlen_p = mlen + siglen;+    }+    return 0;+}
+ vendor/external/libsodium/crypto_sign/ed25519/ref10/sign_ed25519_ref10.h view
@@ -0,0 +1,18 @@+#ifndef sign_ed25519_ref10_H+#define sign_ed25519_ref10_H++void _crypto_sign_ed25519_ref10_hinit(crypto_hash_sha512_state *hs,+                                      int prehashed);++int _crypto_sign_ed25519_detached(unsigned char *sig,+                                  unsigned long long *siglen_p,+                                  const unsigned char *m,+                                  unsigned long long mlen,+                                  const unsigned char *sk, int prehashed);++int _crypto_sign_ed25519_verify_detached(const unsigned char *sig,+                                         const unsigned char *m,+                                         unsigned long long   mlen,+                                         const unsigned char *pk,+                                         int prehashed);+#endif
+ vendor/external/libsodium/crypto_sign/ed25519/sign_ed25519.c view
@@ -0,0 +1,97 @@++#include <string.h>++#include "crypto_hash_sha512.h"+#include "crypto_sign_ed25519.h"+#include "ref10/sign_ed25519_ref10.h"++size_t+crypto_sign_ed25519ph_statebytes(void)+{+    return sizeof(crypto_sign_ed25519ph_state);+}++size_t+crypto_sign_ed25519_bytes(void)+{+    return crypto_sign_ed25519_BYTES;+}++size_t+crypto_sign_ed25519_seedbytes(void)+{+    return crypto_sign_ed25519_SEEDBYTES;+}++size_t+crypto_sign_ed25519_publickeybytes(void)+{+    return crypto_sign_ed25519_PUBLICKEYBYTES;+}++size_t+crypto_sign_ed25519_secretkeybytes(void)+{+    return crypto_sign_ed25519_SECRETKEYBYTES;+}++size_t+crypto_sign_ed25519_messagebytes_max(void)+{+    return crypto_sign_ed25519_MESSAGEBYTES_MAX;+}++int+crypto_sign_ed25519_sk_to_seed(unsigned char *seed, const unsigned char *sk)+{+    memmove(seed, sk, crypto_sign_ed25519_SEEDBYTES);++    return 0;+}++int+crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk)+{+    memmove(pk, sk + crypto_sign_ed25519_SEEDBYTES,+            crypto_sign_ed25519_PUBLICKEYBYTES);+    return 0;+}++int+crypto_sign_ed25519ph_init(crypto_sign_ed25519ph_state *state)+{+    crypto_hash_sha512_init(&state->hs);+    return 0;+}++int+crypto_sign_ed25519ph_update(crypto_sign_ed25519ph_state *state,+                             const unsigned char *m, unsigned long long mlen)+{+    return crypto_hash_sha512_update(&state->hs, m, mlen);+}++int+crypto_sign_ed25519ph_final_create(crypto_sign_ed25519ph_state *state,+                                   unsigned char               *sig,+                                   unsigned long long          *siglen_p,+                                   const unsigned char         *sk)+{+    unsigned char ph[crypto_hash_sha512_BYTES];++    crypto_hash_sha512_final(&state->hs, ph);++    return _crypto_sign_ed25519_detached(sig, siglen_p, ph, sizeof ph, sk, 1);+}++int+crypto_sign_ed25519ph_final_verify(crypto_sign_ed25519ph_state *state,+                                   const unsigned char         *sig,+                                   const unsigned char         *pk)+{+    unsigned char ph[crypto_hash_sha512_BYTES];++    crypto_hash_sha512_final(&state->hs, ph);++    return _crypto_sign_ed25519_verify_detached(sig, ph, sizeof ph, pk, 1);+}
+ vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c view
@@ -0,0 +1,177 @@++#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include "core.h"+#include "crypto_stream_chacha20.h"+#include "private/common.h"+#include "utils.h"++#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \+        defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)++# ifdef __GNUC__+#  pragma GCC target("sse2")+#  pragma GCC target("ssse3")+#  pragma GCC target("sse4.1")+#  pragma GCC target("avx2")+# endif++# include <emmintrin.h>+# include <immintrin.h>+# include <smmintrin.h>+# include <tmmintrin.h>+# include "private/sse2_64_32.h"++# include "../stream_chacha20.h"+# include "chacha20_dolbeau-avx2.h"++# define ROUNDS 20++typedef struct chacha_ctx {+    uint32_t input[16];+} chacha_ctx;++static void+chacha_keysetup(chacha_ctx *ctx, const uint8_t *k)+{+    ctx->input[0]  = 0x61707865;+    ctx->input[1]  = 0x3320646e;+    ctx->input[2]  = 0x79622d32;+    ctx->input[3]  = 0x6b206574;+    ctx->input[4]  = LOAD32_LE(k + 0);+    ctx->input[5]  = LOAD32_LE(k + 4);+    ctx->input[6]  = LOAD32_LE(k + 8);+    ctx->input[7]  = LOAD32_LE(k + 12);+    ctx->input[8]  = LOAD32_LE(k + 16);+    ctx->input[9]  = LOAD32_LE(k + 20);+    ctx->input[10] = LOAD32_LE(k + 24);+    ctx->input[11] = LOAD32_LE(k + 28);+}++static void+chacha_ivsetup(chacha_ctx *ctx, const uint8_t *iv, const uint8_t *counter)+{+    ctx->input[12] = counter == NULL ? 0 : LOAD32_LE(counter + 0);+    ctx->input[13] = counter == NULL ? 0 : LOAD32_LE(counter + 4);+    ctx->input[14] = LOAD32_LE(iv + 0);+    ctx->input[15] = LOAD32_LE(iv + 4);+}++static void+chacha_ietf_ivsetup(chacha_ctx *ctx, const uint8_t *iv, const uint8_t *counter)+{+    ctx->input[12] = counter == NULL ? 0 : LOAD32_LE(counter);+    ctx->input[13] = LOAD32_LE(iv + 0);+    ctx->input[14] = LOAD32_LE(iv + 4);+    ctx->input[15] = LOAD32_LE(iv + 8);+}++static void+chacha20_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c,+                       unsigned long long bytes)+{+    uint32_t * const x = &ctx->input[0];++    if (!bytes) {+        return; /* LCOV_EXCL_LINE */+    }+# include "u8.h"+# include "u4.h"+# include "u1.h"+# include "u0.h"+}++static int+stream_ref(unsigned char *c, unsigned long long clen, const unsigned char *n,+           const unsigned char *k)+{+    struct chacha_ctx ctx;++    if (!clen) {+        return 0;+    }+    COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8);+    chacha_keysetup(&ctx, k);+    chacha_ivsetup(&ctx, n, NULL);+    memset(c, 0, clen);+    chacha20_encrypt_bytes(&ctx, c, c, clen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_ietf_ext_ref(unsigned char *c, unsigned long long clen,+                    const unsigned char *n, const unsigned char *k)+{+    struct chacha_ctx ctx;++    if (!clen) {+        return 0;+    }+    COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8);+    chacha_keysetup(&ctx, k);+    chacha_ietf_ivsetup(&ctx, n, NULL);+    memset(c, 0, clen);+    chacha20_encrypt_bytes(&ctx, c, c, clen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_ref_xor_ic(unsigned char *c, const unsigned char *m,+                  unsigned long long mlen, const unsigned char *n, uint64_t ic,+                  const unsigned char *k)+{+    struct chacha_ctx ctx;+    uint8_t           ic_bytes[8];+    uint32_t          ic_high;+    uint32_t          ic_low;++    if (!mlen) {+        return 0;+    }+    ic_high = (uint32_t) (ic >> 32);+    ic_low  = (uint32_t) ic;+    STORE32_LE(&ic_bytes[0], ic_low);+    STORE32_LE(&ic_bytes[4], ic_high);+    chacha_keysetup(&ctx, k);+    chacha_ivsetup(&ctx, n, ic_bytes);+    chacha20_encrypt_bytes(&ctx, m, c, mlen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_ietf_ext_ref_xor_ic(unsigned char *c, const unsigned char *m,+                           unsigned long long mlen, const unsigned char *n,+                           uint32_t ic, const unsigned char *k)+{+    struct chacha_ctx ctx;+    uint8_t           ic_bytes[4];++    if (!mlen) {+        return 0;+    }+    STORE32_LE(ic_bytes, ic);+    chacha_keysetup(&ctx, k);+    chacha_ietf_ivsetup(&ctx, n, ic_bytes);+    chacha20_encrypt_bytes(&ctx, m, c, mlen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++struct crypto_stream_chacha20_implementation+    crypto_stream_chacha20_dolbeau_avx2_implementation = {+        SODIUM_C99(.stream =) stream_ref,+        SODIUM_C99(.stream_ietf_ext =) stream_ietf_ext_ref,+        SODIUM_C99(.stream_xor_ic =) stream_ref_xor_ic,+        SODIUM_C99(.stream_ietf_ext_xor_ic =) stream_ietf_ext_ref_xor_ic+    };++#endif
+ vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.h view
@@ -0,0 +1,8 @@++#include <stdint.h>++#include "../stream_chacha20.h"+#include "crypto_stream_chacha20.h"++extern struct crypto_stream_chacha20_implementation+    crypto_stream_chacha20_dolbeau_avx2_implementation;
+ vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c view
@@ -0,0 +1,171 @@++#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include "core.h"+#include "crypto_stream_chacha20.h"+#include "private/common.h"+#include "utils.h"++#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)++# ifdef __GNUC__+#  pragma GCC target("sse2")+#  pragma GCC target("ssse3")+# endif++# include <emmintrin.h>+# include <tmmintrin.h>+# include "private/sse2_64_32.h"++# include "../stream_chacha20.h"+# include "chacha20_dolbeau-ssse3.h"++# define ROUNDS 20++typedef struct chacha_ctx {+    uint32_t input[16];+} chacha_ctx;++static void+chacha_keysetup(chacha_ctx *ctx, const uint8_t *k)+{+    ctx->input[0]  = 0x61707865;+    ctx->input[1]  = 0x3320646e;+    ctx->input[2]  = 0x79622d32;+    ctx->input[3]  = 0x6b206574;+    ctx->input[4]  = LOAD32_LE(k + 0);+    ctx->input[5]  = LOAD32_LE(k + 4);+    ctx->input[6]  = LOAD32_LE(k + 8);+    ctx->input[7]  = LOAD32_LE(k + 12);+    ctx->input[8]  = LOAD32_LE(k + 16);+    ctx->input[9]  = LOAD32_LE(k + 20);+    ctx->input[10] = LOAD32_LE(k + 24);+    ctx->input[11] = LOAD32_LE(k + 28);+}++static void+chacha_ivsetup(chacha_ctx *ctx, const uint8_t *iv, const uint8_t *counter)+{+    ctx->input[12] = counter == NULL ? 0 : LOAD32_LE(counter + 0);+    ctx->input[13] = counter == NULL ? 0 : LOAD32_LE(counter + 4);+    ctx->input[14] = LOAD32_LE(iv + 0);+    ctx->input[15] = LOAD32_LE(iv + 4);+}++static void+chacha_ietf_ivsetup(chacha_ctx *ctx, const uint8_t *iv, const uint8_t *counter)+{+    ctx->input[12] = counter == NULL ? 0 : LOAD32_LE(counter);+    ctx->input[13] = LOAD32_LE(iv + 0);+    ctx->input[14] = LOAD32_LE(iv + 4);+    ctx->input[15] = LOAD32_LE(iv + 8);+}++static void+chacha20_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c,+                       unsigned long long bytes)+{+    uint32_t * const x = &ctx->input[0];++    if (!bytes) {+        return; /* LCOV_EXCL_LINE */+    }+# include "u4.h"+# include "u1.h"+# include "u0.h"+}++static int+stream_ref(unsigned char *c, unsigned long long clen, const unsigned char *n,+           const unsigned char *k)+{+    struct chacha_ctx ctx;++    if (!clen) {+        return 0;+    }+    COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8);+    chacha_keysetup(&ctx, k);+    chacha_ivsetup(&ctx, n, NULL);+    memset(c, 0, clen);+    chacha20_encrypt_bytes(&ctx, c, c, clen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_ietf_ext_ref(unsigned char *c, unsigned long long clen,+                    const unsigned char *n, const unsigned char *k)+{+    struct chacha_ctx ctx;++    if (!clen) {+        return 0;+    }+    COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8);+    chacha_keysetup(&ctx, k);+    chacha_ietf_ivsetup(&ctx, n, NULL);+    memset(c, 0, clen);+    chacha20_encrypt_bytes(&ctx, c, c, clen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_ref_xor_ic(unsigned char *c, const unsigned char *m,+                  unsigned long long mlen, const unsigned char *n, uint64_t ic,+                  const unsigned char *k)+{+    struct chacha_ctx ctx;+    uint8_t           ic_bytes[8];+    uint32_t          ic_high;+    uint32_t          ic_low;++    if (!mlen) {+        return 0;+    }+    ic_high = (uint32_t) (ic >> 32);+    ic_low  = (uint32_t) ic;+    STORE32_LE(&ic_bytes[0], ic_low);+    STORE32_LE(&ic_bytes[4], ic_high);+    chacha_keysetup(&ctx, k);+    chacha_ivsetup(&ctx, n, ic_bytes);+    chacha20_encrypt_bytes(&ctx, m, c, mlen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_ietf_ext_ref_xor_ic(unsigned char *c, const unsigned char *m,+                           unsigned long long mlen, const unsigned char *n,+                           uint32_t ic, const unsigned char *k)+{+    struct chacha_ctx ctx;+    uint8_t           ic_bytes[4];++    if (!mlen) {+        return 0;+    }+    STORE32_LE(ic_bytes, ic);+    chacha_keysetup(&ctx, k);+    chacha_ietf_ivsetup(&ctx, n, ic_bytes);+    chacha20_encrypt_bytes(&ctx, m, c, mlen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++struct crypto_stream_chacha20_implementation+    crypto_stream_chacha20_dolbeau_ssse3_implementation = {+        SODIUM_C99(.stream =) stream_ref,+        SODIUM_C99(.stream_ietf_ext =) stream_ietf_ext_ref,+        SODIUM_C99(.stream_xor_ic =) stream_ref_xor_ic,+        SODIUM_C99(.stream_ietf_ext_xor_ic =) stream_ietf_ext_ref_xor_ic+    };++#endif
+ vendor/external/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.h view
@@ -0,0 +1,8 @@++#include <stdint.h>++#include "../stream_chacha20.h"+#include "crypto_stream_chacha20.h"++extern struct crypto_stream_chacha20_implementation+    crypto_stream_chacha20_dolbeau_ssse3_implementation;
+ vendor/external/libsodium/crypto_stream/chacha20/dolbeau/u0.h view
@@ -0,0 +1,86 @@+if (bytes > 0) {+    __m128i       x_0, x_1, x_2, x_3;+    __m128i       t_1;+    const __m128i rot16 =+        _mm_set_epi8(13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2);+    const __m128i rot8 =+        _mm_set_epi8(14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3);+    uint8_t partialblock[64];++    unsigned int i;++    x_0 = _mm_loadu_si128((const __m128i*) (x + 0));+    x_1 = _mm_loadu_si128((const __m128i*) (x + 4));+    x_2 = _mm_loadu_si128((const __m128i*) (x + 8));+    x_3 = _mm_loadu_si128((const __m128i*) (x + 12));++    for (i = 0; i < ROUNDS; i += 2) {+        x_0 = _mm_add_epi32(x_0, x_1);+        x_3 = _mm_xor_si128(x_3, x_0);+        x_3 = _mm_shuffle_epi8(x_3, rot16);++        x_2 = _mm_add_epi32(x_2, x_3);+        x_1 = _mm_xor_si128(x_1, x_2);++        t_1 = x_1;+        x_1 = _mm_slli_epi32(x_1, 12);+        t_1 = _mm_srli_epi32(t_1, 20);+        x_1 = _mm_xor_si128(x_1, t_1);++        x_0 = _mm_add_epi32(x_0, x_1);+        x_3 = _mm_xor_si128(x_3, x_0);+        x_0 = _mm_shuffle_epi32(x_0, 0x93);+        x_3 = _mm_shuffle_epi8(x_3, rot8);++        x_2 = _mm_add_epi32(x_2, x_3);+        x_3 = _mm_shuffle_epi32(x_3, 0x4e);+        x_1 = _mm_xor_si128(x_1, x_2);+        x_2 = _mm_shuffle_epi32(x_2, 0x39);++        t_1 = x_1;+        x_1 = _mm_slli_epi32(x_1, 7);+        t_1 = _mm_srli_epi32(t_1, 25);+        x_1 = _mm_xor_si128(x_1, t_1);++        x_0 = _mm_add_epi32(x_0, x_1);+        x_3 = _mm_xor_si128(x_3, x_0);+        x_3 = _mm_shuffle_epi8(x_3, rot16);++        x_2 = _mm_add_epi32(x_2, x_3);+        x_1 = _mm_xor_si128(x_1, x_2);++        t_1 = x_1;+        x_1 = _mm_slli_epi32(x_1, 12);+        t_1 = _mm_srli_epi32(t_1, 20);+        x_1 = _mm_xor_si128(x_1, t_1);++        x_0 = _mm_add_epi32(x_0, x_1);+        x_3 = _mm_xor_si128(x_3, x_0);+        x_0 = _mm_shuffle_epi32(x_0, 0x39);+        x_3 = _mm_shuffle_epi8(x_3, rot8);++        x_2 = _mm_add_epi32(x_2, x_3);+        x_3 = _mm_shuffle_epi32(x_3, 0x4e);+        x_1 = _mm_xor_si128(x_1, x_2);+        x_2 = _mm_shuffle_epi32(x_2, 0x93);++        t_1 = x_1;+        x_1 = _mm_slli_epi32(x_1, 7);+        t_1 = _mm_srli_epi32(t_1, 25);+        x_1 = _mm_xor_si128(x_1, t_1);+    }+    x_0 = _mm_add_epi32(x_0, _mm_loadu_si128((const __m128i*) (x + 0)));+    x_1 = _mm_add_epi32(x_1, _mm_loadu_si128((const __m128i*) (x + 4)));+    x_2 = _mm_add_epi32(x_2, _mm_loadu_si128((const __m128i*) (x + 8)));+    x_3 = _mm_add_epi32(x_3, _mm_loadu_si128((const __m128i*) (x + 12)));+    _mm_storeu_si128((__m128i*) (partialblock + 0), x_0);+    _mm_storeu_si128((__m128i*) (partialblock + 16), x_1);+    _mm_storeu_si128((__m128i*) (partialblock + 32), x_2);+    _mm_storeu_si128((__m128i*) (partialblock + 48), x_3);++    for (i = 0; i < bytes; i++) {+        c[i] = m[i] ^ partialblock[i];+    }++    sodium_memzero(partialblock, sizeof partialblock);+}
+ vendor/external/libsodium/crypto_stream/chacha20/dolbeau/u1.h view
@@ -0,0 +1,98 @@+while (bytes >= 64) {+    __m128i       x_0, x_1, x_2, x_3;+    __m128i       t_1;+    const __m128i rot16 =+        _mm_set_epi8(13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2);+    const __m128i rot8 =+        _mm_set_epi8(14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3);++    uint32_t in12;+    uint32_t in13;+    int      i;++    x_0 = _mm_loadu_si128((const __m128i*) (x + 0));+    x_1 = _mm_loadu_si128((const __m128i*) (x + 4));+    x_2 = _mm_loadu_si128((const __m128i*) (x + 8));+    x_3 = _mm_loadu_si128((const __m128i*) (x + 12));++    for (i = 0; i < ROUNDS; i += 2) {+        x_0 = _mm_add_epi32(x_0, x_1);+        x_3 = _mm_xor_si128(x_3, x_0);+        x_3 = _mm_shuffle_epi8(x_3, rot16);++        x_2 = _mm_add_epi32(x_2, x_3);+        x_1 = _mm_xor_si128(x_1, x_2);++        t_1 = x_1;+        x_1 = _mm_slli_epi32(x_1, 12);+        t_1 = _mm_srli_epi32(t_1, 20);+        x_1 = _mm_xor_si128(x_1, t_1);++        x_0 = _mm_add_epi32(x_0, x_1);+        x_3 = _mm_xor_si128(x_3, x_0);+        x_0 = _mm_shuffle_epi32(x_0, 0x93);+        x_3 = _mm_shuffle_epi8(x_3, rot8);++        x_2 = _mm_add_epi32(x_2, x_3);+        x_3 = _mm_shuffle_epi32(x_3, 0x4e);+        x_1 = _mm_xor_si128(x_1, x_2);+        x_2 = _mm_shuffle_epi32(x_2, 0x39);++        t_1 = x_1;+        x_1 = _mm_slli_epi32(x_1, 7);+        t_1 = _mm_srli_epi32(t_1, 25);+        x_1 = _mm_xor_si128(x_1, t_1);++        x_0 = _mm_add_epi32(x_0, x_1);+        x_3 = _mm_xor_si128(x_3, x_0);+        x_3 = _mm_shuffle_epi8(x_3, rot16);++        x_2 = _mm_add_epi32(x_2, x_3);+        x_1 = _mm_xor_si128(x_1, x_2);++        t_1 = x_1;+        x_1 = _mm_slli_epi32(x_1, 12);+        t_1 = _mm_srli_epi32(t_1, 20);+        x_1 = _mm_xor_si128(x_1, t_1);++        x_0 = _mm_add_epi32(x_0, x_1);+        x_3 = _mm_xor_si128(x_3, x_0);+        x_0 = _mm_shuffle_epi32(x_0, 0x39);+        x_3 = _mm_shuffle_epi8(x_3, rot8);++        x_2 = _mm_add_epi32(x_2, x_3);+        x_3 = _mm_shuffle_epi32(x_3, 0x4e);+        x_1 = _mm_xor_si128(x_1, x_2);+        x_2 = _mm_shuffle_epi32(x_2, 0x93);++        t_1 = x_1;+        x_1 = _mm_slli_epi32(x_1, 7);+        t_1 = _mm_srli_epi32(t_1, 25);+        x_1 = _mm_xor_si128(x_1, t_1);+    }+    x_0 = _mm_add_epi32(x_0, _mm_loadu_si128((const __m128i*) (x + 0)));+    x_1 = _mm_add_epi32(x_1, _mm_loadu_si128((const __m128i*) (x + 4)));+    x_2 = _mm_add_epi32(x_2, _mm_loadu_si128((const __m128i*) (x + 8)));+    x_3 = _mm_add_epi32(x_3, _mm_loadu_si128((const __m128i*) (x + 12)));+    x_0 = _mm_xor_si128(x_0, _mm_loadu_si128((const __m128i*) (m + 0)));+    x_1 = _mm_xor_si128(x_1, _mm_loadu_si128((const __m128i*) (m + 16)));+    x_2 = _mm_xor_si128(x_2, _mm_loadu_si128((const __m128i*) (m + 32)));+    x_3 = _mm_xor_si128(x_3, _mm_loadu_si128((const __m128i*) (m + 48)));+    _mm_storeu_si128((__m128i*) (c + 0), x_0);+    _mm_storeu_si128((__m128i*) (c + 16), x_1);+    _mm_storeu_si128((__m128i*) (c + 32), x_2);+    _mm_storeu_si128((__m128i*) (c + 48), x_3);++    in12 = x[12];+    in13 = x[13];+    in12++;+    if (in12 == 0) {+        in13++;+    }+    x[12] = in12;+    x[13] = in13;++    bytes -= 64;+    c += 64;+    m += 64;+}
+ vendor/external/libsodium/crypto_stream/chacha20/dolbeau/u4.h view
@@ -0,0 +1,177 @@++#define VEC4_ROT(A, IMM) \+    _mm_or_si128(_mm_slli_epi32(A, IMM), _mm_srli_epi32(A, (32 - IMM)))++/* same, but replace 2 of the shift/shift/or "rotation" by byte shuffles (8 &+ * 16) (better) */+#define VEC4_QUARTERROUND_SHUFFLE(A, B, C, D) \+    x_##A = _mm_add_epi32(x_##A, x_##B);      \+    t_##A = _mm_xor_si128(x_##D, x_##A);      \+    x_##D = _mm_shuffle_epi8(t_##A, rot16);   \+    x_##C = _mm_add_epi32(x_##C, x_##D);      \+    t_##C = _mm_xor_si128(x_##B, x_##C);      \+    x_##B = VEC4_ROT(t_##C, 12);              \+    x_##A = _mm_add_epi32(x_##A, x_##B);      \+    t_##A = _mm_xor_si128(x_##D, x_##A);      \+    x_##D = _mm_shuffle_epi8(t_##A, rot8);    \+    x_##C = _mm_add_epi32(x_##C, x_##D);      \+    t_##C = _mm_xor_si128(x_##B, x_##C);      \+    x_##B = VEC4_ROT(t_##C, 7)++#define VEC4_QUARTERROUND(A, B, C, D) VEC4_QUARTERROUND_SHUFFLE(A, B, C, D)++if (bytes >= 256) {+    /* constant for shuffling bytes (replacing multiple-of-8 rotates) */+    __m128i rot16 =+        _mm_set_epi8(13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2);+    __m128i rot8 =+        _mm_set_epi8(14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3);++    __m128i x_0  = _mm_set1_epi32(x[0]);+    __m128i x_1  = _mm_set1_epi32(x[1]);+    __m128i x_2  = _mm_set1_epi32(x[2]);+    __m128i x_3  = _mm_set1_epi32(x[3]);+    __m128i x_4  = _mm_set1_epi32(x[4]);+    __m128i x_5  = _mm_set1_epi32(x[5]);+    __m128i x_6  = _mm_set1_epi32(x[6]);+    __m128i x_7  = _mm_set1_epi32(x[7]);+    __m128i x_8  = _mm_set1_epi32(x[8]);+    __m128i x_9  = _mm_set1_epi32(x[9]);+    __m128i x_10 = _mm_set1_epi32(x[10]);+    __m128i x_11 = _mm_set1_epi32(x[11]);+    __m128i x_12;+    __m128i x_13;+    __m128i x_14   = _mm_set1_epi32(x[14]);+    __m128i x_15   = _mm_set1_epi32(x[15]);+    __m128i orig0  = x_0;+    __m128i orig1  = x_1;+    __m128i orig2  = x_2;+    __m128i orig3  = x_3;+    __m128i orig4  = x_4;+    __m128i orig5  = x_5;+    __m128i orig6  = x_6;+    __m128i orig7  = x_7;+    __m128i orig8  = x_8;+    __m128i orig9  = x_9;+    __m128i orig10 = x_10;+    __m128i orig11 = x_11;+    __m128i orig12;+    __m128i orig13;+    __m128i orig14 = x_14;+    __m128i orig15 = x_15;+    __m128i t_0, t_1, t_2, t_3, t_4, t_5, t_6, t_7, t_8, t_9, t_10, t_11, t_12,+        t_13, t_14, t_15;++    uint32_t in12, in13;+    int      i;++    while (bytes >= 256) {+        const __m128i addv12 = _mm_set_epi64x(1, 0);+        const __m128i addv13 = _mm_set_epi64x(3, 2);+        __m128i       t12, t13;+        uint64_t      in1213;++        x_0  = orig0;+        x_1  = orig1;+        x_2  = orig2;+        x_3  = orig3;+        x_4  = orig4;+        x_5  = orig5;+        x_6  = orig6;+        x_7  = orig7;+        x_8  = orig8;+        x_9  = orig9;+        x_10 = orig10;+        x_11 = orig11;+        x_14 = orig14;+        x_15 = orig15;++        in12   = x[12];+        in13   = x[13];+        in1213 = ((uint64_t) in12) | (((uint64_t) in13) << 32);+        t12    = _mm_set1_epi64x(in1213);+        t13    = _mm_set1_epi64x(in1213);++        x_12 = _mm_add_epi64(addv12, t12);+        x_13 = _mm_add_epi64(addv13, t13);++        t12 = _mm_unpacklo_epi32(x_12, x_13);+        t13 = _mm_unpackhi_epi32(x_12, x_13);++        x_12 = _mm_unpacklo_epi32(t12, t13);+        x_13 = _mm_unpackhi_epi32(t12, t13);++        orig12 = x_12;+        orig13 = x_13;++        in1213 += 4;++        x[12] = in1213 & 0xFFFFFFFF;+        x[13] = (in1213 >> 32) & 0xFFFFFFFF;++        for (i = 0; i < ROUNDS; i += 2) {+            VEC4_QUARTERROUND(0, 4, 8, 12);+            VEC4_QUARTERROUND(1, 5, 9, 13);+            VEC4_QUARTERROUND(2, 6, 10, 14);+            VEC4_QUARTERROUND(3, 7, 11, 15);+            VEC4_QUARTERROUND(0, 5, 10, 15);+            VEC4_QUARTERROUND(1, 6, 11, 12);+            VEC4_QUARTERROUND(2, 7, 8, 13);+            VEC4_QUARTERROUND(3, 4, 9, 14);+        }++#define ONEQUAD_TRANSPOSE(A, B, C, D)                                          \+    {                                                                          \+        __m128i t0, t1, t2, t3;                                                \+                                                                               \+        x_##A = _mm_add_epi32(x_##A, orig##A);                                 \+        x_##B = _mm_add_epi32(x_##B, orig##B);                                 \+        x_##C = _mm_add_epi32(x_##C, orig##C);                                 \+        x_##D = _mm_add_epi32(x_##D, orig##D);                                 \+        t_##A = _mm_unpacklo_epi32(x_##A, x_##B);                              \+        t_##B = _mm_unpacklo_epi32(x_##C, x_##D);                              \+        t_##C = _mm_unpackhi_epi32(x_##A, x_##B);                              \+        t_##D = _mm_unpackhi_epi32(x_##C, x_##D);                              \+        x_##A = _mm_unpacklo_epi64(t_##A, t_##B);                              \+        x_##B = _mm_unpackhi_epi64(t_##A, t_##B);                              \+        x_##C = _mm_unpacklo_epi64(t_##C, t_##D);                              \+        x_##D = _mm_unpackhi_epi64(t_##C, t_##D);                              \+                                                                               \+        t0 = _mm_xor_si128(x_##A, _mm_loadu_si128((const __m128i*) (m + 0)));  \+        _mm_storeu_si128((__m128i*) (c + 0), t0);                              \+        t1 = _mm_xor_si128(x_##B, _mm_loadu_si128((const __m128i*) (m + 64))); \+        _mm_storeu_si128((__m128i*) (c + 64), t1);                             \+        t2 =                                                                   \+            _mm_xor_si128(x_##C, _mm_loadu_si128((const __m128i*) (m + 128))); \+        _mm_storeu_si128((__m128i*) (c + 128), t2);                            \+        t3 =                                                                   \+            _mm_xor_si128(x_##D, _mm_loadu_si128((const __m128i*) (m + 192))); \+        _mm_storeu_si128((__m128i*) (c + 192), t3);                            \+    }++#define ONEQUAD(A, B, C, D) ONEQUAD_TRANSPOSE(A, B, C, D)++        ONEQUAD(0, 1, 2, 3);+        m += 16;+        c += 16;+        ONEQUAD(4, 5, 6, 7);+        m += 16;+        c += 16;+        ONEQUAD(8, 9, 10, 11);+        m += 16;+        c += 16;+        ONEQUAD(12, 13, 14, 15);+        m -= 48;+        c -= 48;++#undef ONEQUAD+#undef ONEQUAD_TRANSPOSE++        bytes -= 256;+        c += 256;+        m += 256;+    }+}+#undef VEC4_ROT+#undef VEC4_QUARTERROUND+#undef VEC4_QUARTERROUND_SHUFFLE
+ vendor/external/libsodium/crypto_stream/chacha20/dolbeau/u8.h view
@@ -0,0 +1,326 @@++#define VEC8_ROT(A, IMM) \+    _mm256_or_si256(_mm256_slli_epi32(A, IMM), _mm256_srli_epi32(A, (32 - IMM)))++/* same, but replace 2 of the shift/shift/or "rotation" by byte shuffles (8 &+ * 16) (better) */+#define VEC8_QUARTERROUND_SHUFFLE(A, B, C, D)  \+    x_##A = _mm256_add_epi32(x_##A, x_##B);    \+    t_##A = _mm256_xor_si256(x_##D, x_##A);    \+    x_##D = _mm256_shuffle_epi8(t_##A, rot16); \+    x_##C = _mm256_add_epi32(x_##C, x_##D);    \+    t_##C = _mm256_xor_si256(x_##B, x_##C);    \+    x_##B = VEC8_ROT(t_##C, 12);               \+    x_##A = _mm256_add_epi32(x_##A, x_##B);    \+    t_##A = _mm256_xor_si256(x_##D, x_##A);    \+    x_##D = _mm256_shuffle_epi8(t_##A, rot8);  \+    x_##C = _mm256_add_epi32(x_##C, x_##D);    \+    t_##C = _mm256_xor_si256(x_##B, x_##C);    \+    x_##B = VEC8_ROT(t_##C, 7)++#define VEC8_QUARTERROUND(A, B, C, D) VEC8_QUARTERROUND_SHUFFLE(A, B, C, D)++#define VEC8_LINE1(A, B, C, D)              \+    x_##A = _mm256_add_epi32(x_##A, x_##B); \+    x_##D = _mm256_shuffle_epi8(_mm256_xor_si256(x_##D, x_##A), rot16)+#define VEC8_LINE2(A, B, C, D)              \+    x_##C = _mm256_add_epi32(x_##C, x_##D); \+    x_##B = VEC8_ROT(_mm256_xor_si256(x_##B, x_##C), 12)+#define VEC8_LINE3(A, B, C, D)              \+    x_##A = _mm256_add_epi32(x_##A, x_##B); \+    x_##D = _mm256_shuffle_epi8(_mm256_xor_si256(x_##D, x_##A), rot8)+#define VEC8_LINE4(A, B, C, D)              \+    x_##C = _mm256_add_epi32(x_##C, x_##D); \+    x_##B = VEC8_ROT(_mm256_xor_si256(x_##B, x_##C), 7)++#define VEC8_ROUND_SEQ(A1, B1, C1, D1, A2, B2, C2, D2, A3, B3, C3, D3, A4, B4, \+                       C4, D4)                                                 \+    VEC8_LINE1(A1, B1, C1, D1);                                                \+    VEC8_LINE1(A2, B2, C2, D2);                                                \+    VEC8_LINE1(A3, B3, C3, D3);                                                \+    VEC8_LINE1(A4, B4, C4, D4);                                                \+    VEC8_LINE2(A1, B1, C1, D1);                                                \+    VEC8_LINE2(A2, B2, C2, D2);                                                \+    VEC8_LINE2(A3, B3, C3, D3);                                                \+    VEC8_LINE2(A4, B4, C4, D4);                                                \+    VEC8_LINE3(A1, B1, C1, D1);                                                \+    VEC8_LINE3(A2, B2, C2, D2);                                                \+    VEC8_LINE3(A3, B3, C3, D3);                                                \+    VEC8_LINE3(A4, B4, C4, D4);                                                \+    VEC8_LINE4(A1, B1, C1, D1);                                                \+    VEC8_LINE4(A2, B2, C2, D2);                                                \+    VEC8_LINE4(A3, B3, C3, D3);                                                \+    VEC8_LINE4(A4, B4, C4, D4)++#define VEC8_ROUND_HALF(A1, B1, C1, D1, A2, B2, C2, D2, A3, B3, C3, D3, A4, \+                        B4, C4, D4)                                         \+    VEC8_LINE1(A1, B1, C1, D1);                                             \+    VEC8_LINE1(A2, B2, C2, D2);                                             \+    VEC8_LINE2(A1, B1, C1, D1);                                             \+    VEC8_LINE2(A2, B2, C2, D2);                                             \+    VEC8_LINE3(A1, B1, C1, D1);                                             \+    VEC8_LINE3(A2, B2, C2, D2);                                             \+    VEC8_LINE4(A1, B1, C1, D1);                                             \+    VEC8_LINE4(A2, B2, C2, D2);                                             \+    VEC8_LINE1(A3, B3, C3, D3);                                             \+    VEC8_LINE1(A4, B4, C4, D4);                                             \+    VEC8_LINE2(A3, B3, C3, D3);                                             \+    VEC8_LINE2(A4, B4, C4, D4);                                             \+    VEC8_LINE3(A3, B3, C3, D3);                                             \+    VEC8_LINE3(A4, B4, C4, D4);                                             \+    VEC8_LINE4(A3, B3, C3, D3);                                             \+    VEC8_LINE4(A4, B4, C4, D4)++#define VEC8_ROUND_HALFANDHALF(A1, B1, C1, D1, A2, B2, C2, D2, A3, B3, C3, D3, \+                               A4, B4, C4, D4)                                 \+    VEC8_LINE1(A1, B1, C1, D1);                                                \+    VEC8_LINE1(A2, B2, C2, D2);                                                \+    VEC8_LINE2(A1, B1, C1, D1);                                                \+    VEC8_LINE2(A2, B2, C2, D2);                                                \+    VEC8_LINE1(A3, B3, C3, D3);                                                \+    VEC8_LINE1(A4, B4, C4, D4);                                                \+    VEC8_LINE2(A3, B3, C3, D3);                                                \+    VEC8_LINE2(A4, B4, C4, D4);                                                \+    VEC8_LINE3(A1, B1, C1, D1);                                                \+    VEC8_LINE3(A2, B2, C2, D2);                                                \+    VEC8_LINE4(A1, B1, C1, D1);                                                \+    VEC8_LINE4(A2, B2, C2, D2);                                                \+    VEC8_LINE3(A3, B3, C3, D3);                                                \+    VEC8_LINE3(A4, B4, C4, D4);                                                \+    VEC8_LINE4(A3, B3, C3, D3);                                                \+    VEC8_LINE4(A4, B4, C4, D4)++#define VEC8_ROUND(A1, B1, C1, D1, A2, B2, C2, D2, A3, B3, C3, D3, A4, B4, C4, \+                   D4)                                                         \+    VEC8_ROUND_SEQ(A1, B1, C1, D1, A2, B2, C2, D2, A3, B3, C3, D3, A4, B4, C4, \+                   D4)++if (bytes >= 512) {+    /* constant for shuffling bytes (replacing multiple-of-8 rotates) */+    __m256i rot16 =+        _mm256_set_epi8(13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2,+                        13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2);+    __m256i rot8 =+        _mm256_set_epi8(14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3,+                        14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3);+    uint32_t in12, in13;++    /* the naive way seems as fast (if not a bit faster) than the vector way */+    __m256i x_0  = _mm256_set1_epi32(x[0]);+    __m256i x_1  = _mm256_set1_epi32(x[1]);+    __m256i x_2  = _mm256_set1_epi32(x[2]);+    __m256i x_3  = _mm256_set1_epi32(x[3]);+    __m256i x_4  = _mm256_set1_epi32(x[4]);+    __m256i x_5  = _mm256_set1_epi32(x[5]);+    __m256i x_6  = _mm256_set1_epi32(x[6]);+    __m256i x_7  = _mm256_set1_epi32(x[7]);+    __m256i x_8  = _mm256_set1_epi32(x[8]);+    __m256i x_9  = _mm256_set1_epi32(x[9]);+    __m256i x_10 = _mm256_set1_epi32(x[10]);+    __m256i x_11 = _mm256_set1_epi32(x[11]);+    __m256i x_12;+    __m256i x_13;+    __m256i x_14 = _mm256_set1_epi32(x[14]);+    __m256i x_15 = _mm256_set1_epi32(x[15]);++    __m256i orig0  = x_0;+    __m256i orig1  = x_1;+    __m256i orig2  = x_2;+    __m256i orig3  = x_3;+    __m256i orig4  = x_4;+    __m256i orig5  = x_5;+    __m256i orig6  = x_6;+    __m256i orig7  = x_7;+    __m256i orig8  = x_8;+    __m256i orig9  = x_9;+    __m256i orig10 = x_10;+    __m256i orig11 = x_11;+    __m256i orig12;+    __m256i orig13;+    __m256i orig14 = x_14;+    __m256i orig15 = x_15;+    __m256i t_0, t_1, t_2, t_3, t_4, t_5, t_6, t_7, t_8, t_9, t_10, t_11, t_12,+        t_13, t_14, t_15;++    while (bytes >= 512) {+        const __m256i addv12  = _mm256_set_epi64x(3, 2, 1, 0);+        const __m256i addv13  = _mm256_set_epi64x(7, 6, 5, 4);+        const __m256i permute = _mm256_set_epi32(7, 6, 3, 2, 5, 4, 1, 0);+        __m256i       t12, t13;++        uint64_t in1213;+        int      i;++        x_0  = orig0;+        x_1  = orig1;+        x_2  = orig2;+        x_3  = orig3;+        x_4  = orig4;+        x_5  = orig5;+        x_6  = orig6;+        x_7  = orig7;+        x_8  = orig8;+        x_9  = orig9;+        x_10 = orig10;+        x_11 = orig11;+        x_14 = orig14;+        x_15 = orig15;++        in12   = x[12];+        in13   = x[13];+        in1213 = ((uint64_t) in12) | (((uint64_t) in13) << 32);+        x_12 = x_13 = _mm256_broadcastq_epi64(_mm_cvtsi64_si128(in1213));++        t12 = _mm256_add_epi64(addv12, x_12);+        t13 = _mm256_add_epi64(addv13, x_13);++        x_12 = _mm256_unpacklo_epi32(t12, t13);+        x_13 = _mm256_unpackhi_epi32(t12, t13);++        t12 = _mm256_unpacklo_epi32(x_12, x_13);+        t13 = _mm256_unpackhi_epi32(x_12, x_13);++        /* required because unpack* are intra-lane */+        x_12 = _mm256_permutevar8x32_epi32(t12, permute);+        x_13 = _mm256_permutevar8x32_epi32(t13, permute);++        orig12 = x_12;+        orig13 = x_13;++        in1213 += 8;++        x[12] = in1213 & 0xFFFFFFFF;+        x[13] = (in1213 >> 32) & 0xFFFFFFFF;++        for (i = 0; i < ROUNDS; i += 2) {+            VEC8_ROUND(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);+            VEC8_ROUND(0, 5, 10, 15, 1, 6, 11, 12, 2, 7, 8, 13, 3, 4, 9, 14);+        }++#define ONEQUAD_TRANSPOSE(A, B, C, D)                                     \+    {                                                                     \+        __m128i t0, t1, t2, t3;                                           \+        x_##A = _mm256_add_epi32(x_##A, orig##A);                         \+        x_##B = _mm256_add_epi32(x_##B, orig##B);                         \+        x_##C = _mm256_add_epi32(x_##C, orig##C);                         \+        x_##D = _mm256_add_epi32(x_##D, orig##D);                         \+        t_##A = _mm256_unpacklo_epi32(x_##A, x_##B);                      \+        t_##B = _mm256_unpacklo_epi32(x_##C, x_##D);                      \+        t_##C = _mm256_unpackhi_epi32(x_##A, x_##B);                      \+        t_##D = _mm256_unpackhi_epi32(x_##C, x_##D);                      \+        x_##A = _mm256_unpacklo_epi64(t_##A, t_##B);                      \+        x_##B = _mm256_unpackhi_epi64(t_##A, t_##B);                      \+        x_##C = _mm256_unpacklo_epi64(t_##C, t_##D);                      \+        x_##D = _mm256_unpackhi_epi64(t_##C, t_##D);                      \+        t0    = _mm_xor_si128(_mm256_extracti128_si256(x_##A, 0),         \+                           _mm_loadu_si128((const __m128i*) (m + 0))); \+        _mm_storeu_si128((__m128i*) (c + 0), t0);                         \+        t1 = _mm_xor_si128(_mm256_extracti128_si256(x_##B, 0),            \+                           _mm_loadu_si128((const __m128i*) (m + 64)));   \+        _mm_storeu_si128((__m128i*) (c + 64), t1);                        \+        t2 = _mm_xor_si128(_mm256_extracti128_si256(x_##C, 0),            \+                           _mm_loadu_si128((const __m128i*) (m + 128)));  \+        _mm_storeu_si128((__m128i*) (c + 128), t2);                       \+        t3 = _mm_xor_si128(_mm256_extracti128_si256(x_##D, 0),            \+                           _mm_loadu_si128((const __m128i*) (m + 192)));  \+        _mm_storeu_si128((__m128i*) (c + 192), t3);                       \+        t0 = _mm_xor_si128(_mm256_extracti128_si256(x_##A, 1),            \+                           _mm_loadu_si128((const __m128i*) (m + 256)));  \+        _mm_storeu_si128((__m128i*) (c + 256), t0);                       \+        t1 = _mm_xor_si128(_mm256_extracti128_si256(x_##B, 1),            \+                           _mm_loadu_si128((const __m128i*) (m + 320)));  \+        _mm_storeu_si128((__m128i*) (c + 320), t1);                       \+        t2 = _mm_xor_si128(_mm256_extracti128_si256(x_##C, 1),            \+                           _mm_loadu_si128((const __m128i*) (m + 384)));  \+        _mm_storeu_si128((__m128i*) (c + 384), t2);                       \+        t3 = _mm_xor_si128(_mm256_extracti128_si256(x_##D, 1),            \+                           _mm_loadu_si128((const __m128i*) (m + 448)));  \+        _mm_storeu_si128((__m128i*) (c + 448), t3);                       \+    }++#define ONEQUAD(A, B, C, D) ONEQUAD_TRANSPOSE(A, B, C, D)++#define ONEQUAD_UNPCK(A, B, C, D)                    \+    {                                                \+        x_##A = _mm256_add_epi32(x_##A, orig##A);    \+        x_##B = _mm256_add_epi32(x_##B, orig##B);    \+        x_##C = _mm256_add_epi32(x_##C, orig##C);    \+        x_##D = _mm256_add_epi32(x_##D, orig##D);    \+        t_##A = _mm256_unpacklo_epi32(x_##A, x_##B); \+        t_##B = _mm256_unpacklo_epi32(x_##C, x_##D); \+        t_##C = _mm256_unpackhi_epi32(x_##A, x_##B); \+        t_##D = _mm256_unpackhi_epi32(x_##C, x_##D); \+        x_##A = _mm256_unpacklo_epi64(t_##A, t_##B); \+        x_##B = _mm256_unpackhi_epi64(t_##A, t_##B); \+        x_##C = _mm256_unpacklo_epi64(t_##C, t_##D); \+        x_##D = _mm256_unpackhi_epi64(t_##C, t_##D); \+    }++#define ONEOCTO(A, B, C, D, A2, B2, C2, D2)                          \+    {                                                                \+        ONEQUAD_UNPCK(A, B, C, D);                                   \+        ONEQUAD_UNPCK(A2, B2, C2, D2);                               \+        t_##A  = _mm256_permute2x128_si256(x_##A, x_##A2, 0x20);     \+        t_##A2 = _mm256_permute2x128_si256(x_##A, x_##A2, 0x31);     \+        t_##B  = _mm256_permute2x128_si256(x_##B, x_##B2, 0x20);     \+        t_##B2 = _mm256_permute2x128_si256(x_##B, x_##B2, 0x31);     \+        t_##C  = _mm256_permute2x128_si256(x_##C, x_##C2, 0x20);     \+        t_##C2 = _mm256_permute2x128_si256(x_##C, x_##C2, 0x31);     \+        t_##D  = _mm256_permute2x128_si256(x_##D, x_##D2, 0x20);     \+        t_##D2 = _mm256_permute2x128_si256(x_##D, x_##D2, 0x31);     \+        t_##A  = _mm256_xor_si256(                                   \+            t_##A, _mm256_loadu_si256((const __m256i*) (m + 0)));   \+        t_##B = _mm256_xor_si256(                                    \+            t_##B, _mm256_loadu_si256((const __m256i*) (m + 64)));   \+        t_##C = _mm256_xor_si256(                                    \+            t_##C, _mm256_loadu_si256((const __m256i*) (m + 128)));  \+        t_##D = _mm256_xor_si256(                                    \+            t_##D, _mm256_loadu_si256((const __m256i*) (m + 192)));  \+        t_##A2 = _mm256_xor_si256(                                   \+            t_##A2, _mm256_loadu_si256((const __m256i*) (m + 256))); \+        t_##B2 = _mm256_xor_si256(                                   \+            t_##B2, _mm256_loadu_si256((const __m256i*) (m + 320))); \+        t_##C2 = _mm256_xor_si256(                                   \+            t_##C2, _mm256_loadu_si256((const __m256i*) (m + 384))); \+        t_##D2 = _mm256_xor_si256(                                   \+            t_##D2, _mm256_loadu_si256((const __m256i*) (m + 448))); \+        _mm256_storeu_si256((__m256i*) (c + 0), t_##A);              \+        _mm256_storeu_si256((__m256i*) (c + 64), t_##B);             \+        _mm256_storeu_si256((__m256i*) (c + 128), t_##C);            \+        _mm256_storeu_si256((__m256i*) (c + 192), t_##D);            \+        _mm256_storeu_si256((__m256i*) (c + 256), t_##A2);           \+        _mm256_storeu_si256((__m256i*) (c + 320), t_##B2);           \+        _mm256_storeu_si256((__m256i*) (c + 384), t_##C2);           \+        _mm256_storeu_si256((__m256i*) (c + 448), t_##D2);           \+    }++        ONEOCTO(0, 1, 2, 3, 4, 5, 6, 7);+        m += 32;+        c += 32;+        ONEOCTO(8, 9, 10, 11, 12, 13, 14, 15);+        m -= 32;+        c -= 32;++#undef ONEQUAD+#undef ONEQUAD_TRANSPOSE+#undef ONEQUAD_UNPCK+#undef ONEOCTO++        bytes -= 512;+        c += 512;+        m += 512;+    }+}+#undef VEC8_ROT+#undef VEC8_QUARTERROUND+#undef VEC8_QUARTERROUND_NAIVE+#undef VEC8_QUARTERROUND_SHUFFLE+#undef VEC8_QUARTERROUND_SHUFFLE2+#undef VEC8_LINE1+#undef VEC8_LINE2+#undef VEC8_LINE3+#undef VEC8_LINE4+#undef VEC8_ROUND+#undef VEC8_ROUND_SEQ+#undef VEC8_ROUND_HALF+#undef VEC8_ROUND_HALFANDHALF
+ vendor/external/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c view
@@ -0,0 +1,312 @@++/*+ chacha-merged.c version 20080118+ D. J. Bernstein+ Public domain.+ */++#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include "core.h"+#include "crypto_stream_chacha20.h"+#include "private/common.h"+#include "utils.h"++#include "../stream_chacha20.h"+#include "chacha20_ref.h"++struct chacha_ctx {+    uint32_t input[16];+};++typedef struct chacha_ctx chacha_ctx;++#define U32C(v) (v##U)++#define U32V(v) ((uint32_t)(v) &U32C(0xFFFFFFFF))++#define ROTATE(v, c) (ROTL32(v, c))+#define XOR(v, w) ((v) ^ (w))+#define PLUS(v, w) (U32V((v) + (w)))+#define PLUSONE(v) (PLUS((v), 1))++#define QUARTERROUND(a, b, c, d) \+    a = PLUS(a, b);              \+    d = ROTATE(XOR(d, a), 16);   \+    c = PLUS(c, d);              \+    b = ROTATE(XOR(b, c), 12);   \+    a = PLUS(a, b);              \+    d = ROTATE(XOR(d, a), 8);    \+    c = PLUS(c, d);              \+    b = ROTATE(XOR(b, c), 7);++static void+chacha_keysetup(chacha_ctx *ctx, const uint8_t *k)+{+    ctx->input[0]  = U32C(0x61707865);+    ctx->input[1]  = U32C(0x3320646e);+    ctx->input[2]  = U32C(0x79622d32);+    ctx->input[3]  = U32C(0x6b206574);+    ctx->input[4]  = LOAD32_LE(k + 0);+    ctx->input[5]  = LOAD32_LE(k + 4);+    ctx->input[6]  = LOAD32_LE(k + 8);+    ctx->input[7]  = LOAD32_LE(k + 12);+    ctx->input[8]  = LOAD32_LE(k + 16);+    ctx->input[9]  = LOAD32_LE(k + 20);+    ctx->input[10] = LOAD32_LE(k + 24);+    ctx->input[11] = LOAD32_LE(k + 28);+}++static void+chacha_ivsetup(chacha_ctx *ctx, const uint8_t *iv, const uint8_t *counter)+{+    ctx->input[12] = counter == NULL ? 0 : LOAD32_LE(counter + 0);+    ctx->input[13] = counter == NULL ? 0 : LOAD32_LE(counter + 4);+    ctx->input[14] = LOAD32_LE(iv + 0);+    ctx->input[15] = LOAD32_LE(iv + 4);+}++static void+chacha_ietf_ivsetup(chacha_ctx *ctx, const uint8_t *iv, const uint8_t *counter)+{+    ctx->input[12] = counter == NULL ? 0 : LOAD32_LE(counter);+    ctx->input[13] = LOAD32_LE(iv + 0);+    ctx->input[14] = LOAD32_LE(iv + 4);+    ctx->input[15] = LOAD32_LE(iv + 8);+}++static void+chacha20_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c,+                       unsigned long long bytes)+{+    uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14,+        x15;+    uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14,+        j15;+    uint8_t     *ctarget = NULL;+    uint8_t      tmp[64];+    unsigned int i;++    if (!bytes) {+        return; /* LCOV_EXCL_LINE */+    }+    j0  = ctx->input[0];+    j1  = ctx->input[1];+    j2  = ctx->input[2];+    j3  = ctx->input[3];+    j4  = ctx->input[4];+    j5  = ctx->input[5];+    j6  = ctx->input[6];+    j7  = ctx->input[7];+    j8  = ctx->input[8];+    j9  = ctx->input[9];+    j10 = ctx->input[10];+    j11 = ctx->input[11];+    j12 = ctx->input[12];+    j13 = ctx->input[13];+    j14 = ctx->input[14];+    j15 = ctx->input[15];++    for (;;) {+        if (bytes < 64) {+            memset(tmp, 0, 64);+            for (i = 0; i < bytes; ++i) {+                tmp[i] = m[i];+            }+            m       = tmp;+            ctarget = c;+            c       = tmp;+        }+        x0  = j0;+        x1  = j1;+        x2  = j2;+        x3  = j3;+        x4  = j4;+        x5  = j5;+        x6  = j6;+        x7  = j7;+        x8  = j8;+        x9  = j9;+        x10 = j10;+        x11 = j11;+        x12 = j12;+        x13 = j13;+        x14 = j14;+        x15 = j15;+        for (i = 20; i > 0; i -= 2) {+            QUARTERROUND(x0, x4, x8, x12)+            QUARTERROUND(x1, x5, x9, x13)+            QUARTERROUND(x2, x6, x10, x14)+            QUARTERROUND(x3, x7, x11, x15)+            QUARTERROUND(x0, x5, x10, x15)+            QUARTERROUND(x1, x6, x11, x12)+            QUARTERROUND(x2, x7, x8, x13)+            QUARTERROUND(x3, x4, x9, x14)+        }+        x0  = PLUS(x0, j0);+        x1  = PLUS(x1, j1);+        x2  = PLUS(x2, j2);+        x3  = PLUS(x3, j3);+        x4  = PLUS(x4, j4);+        x5  = PLUS(x5, j5);+        x6  = PLUS(x6, j6);+        x7  = PLUS(x7, j7);+        x8  = PLUS(x8, j8);+        x9  = PLUS(x9, j9);+        x10 = PLUS(x10, j10);+        x11 = PLUS(x11, j11);+        x12 = PLUS(x12, j12);+        x13 = PLUS(x13, j13);+        x14 = PLUS(x14, j14);+        x15 = PLUS(x15, j15);++        x0  = XOR(x0, LOAD32_LE(m + 0));+        x1  = XOR(x1, LOAD32_LE(m + 4));+        x2  = XOR(x2, LOAD32_LE(m + 8));+        x3  = XOR(x3, LOAD32_LE(m + 12));+        x4  = XOR(x4, LOAD32_LE(m + 16));+        x5  = XOR(x5, LOAD32_LE(m + 20));+        x6  = XOR(x6, LOAD32_LE(m + 24));+        x7  = XOR(x7, LOAD32_LE(m + 28));+        x8  = XOR(x8, LOAD32_LE(m + 32));+        x9  = XOR(x9, LOAD32_LE(m + 36));+        x10 = XOR(x10, LOAD32_LE(m + 40));+        x11 = XOR(x11, LOAD32_LE(m + 44));+        x12 = XOR(x12, LOAD32_LE(m + 48));+        x13 = XOR(x13, LOAD32_LE(m + 52));+        x14 = XOR(x14, LOAD32_LE(m + 56));+        x15 = XOR(x15, LOAD32_LE(m + 60));++        j12 = PLUSONE(j12);+        /* LCOV_EXCL_START */+        if (!j12) {+            j13 = PLUSONE(j13);+        }+        /* LCOV_EXCL_STOP */++        STORE32_LE(c + 0, x0);+        STORE32_LE(c + 4, x1);+        STORE32_LE(c + 8, x2);+        STORE32_LE(c + 12, x3);+        STORE32_LE(c + 16, x4);+        STORE32_LE(c + 20, x5);+        STORE32_LE(c + 24, x6);+        STORE32_LE(c + 28, x7);+        STORE32_LE(c + 32, x8);+        STORE32_LE(c + 36, x9);+        STORE32_LE(c + 40, x10);+        STORE32_LE(c + 44, x11);+        STORE32_LE(c + 48, x12);+        STORE32_LE(c + 52, x13);+        STORE32_LE(c + 56, x14);+        STORE32_LE(c + 60, x15);++        if (bytes <= 64) {+            if (bytes < 64) {+                for (i = 0; i < (unsigned int) bytes; ++i) {+                    ctarget[i] = c[i]; /* ctarget cannot be NULL */+                }+            }+            ctx->input[12] = j12;+            ctx->input[13] = j13;++            return;+        }+        bytes -= 64;+        c += 64;+        m += 64;+    }+}++static int+stream_ref(unsigned char *c, unsigned long long clen, const unsigned char *n,+           const unsigned char *k)+{+    struct chacha_ctx ctx;++    if (!clen) {+        return 0;+    }+    COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8);+    chacha_keysetup(&ctx, k);+    chacha_ivsetup(&ctx, n, NULL);+    memset(c, 0, clen);+    chacha20_encrypt_bytes(&ctx, c, c, clen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_ietf_ext_ref(unsigned char *c, unsigned long long clen,+                    const unsigned char *n, const unsigned char *k)+{+    struct chacha_ctx ctx;++    if (!clen) {+        return 0;+    }+    COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8);+    chacha_keysetup(&ctx, k);+    chacha_ietf_ivsetup(&ctx, n, NULL);+    memset(c, 0, clen);+    chacha20_encrypt_bytes(&ctx, c, c, clen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_ref_xor_ic(unsigned char *c, const unsigned char *m,+                  unsigned long long mlen, const unsigned char *n, uint64_t ic,+                  const unsigned char *k)+{+    struct chacha_ctx ctx;+    uint8_t           ic_bytes[8];+    uint32_t          ic_high;+    uint32_t          ic_low;++    if (!mlen) {+        return 0;+    }+    ic_high = U32V(ic >> 32);+    ic_low  = U32V(ic);+    STORE32_LE(&ic_bytes[0], ic_low);+    STORE32_LE(&ic_bytes[4], ic_high);+    chacha_keysetup(&ctx, k);+    chacha_ivsetup(&ctx, n, ic_bytes);+    chacha20_encrypt_bytes(&ctx, m, c, mlen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_ietf_ext_ref_xor_ic(unsigned char *c, const unsigned char *m,+                           unsigned long long mlen, const unsigned char *n,+                           uint32_t ic, const unsigned char *k)+{+    struct chacha_ctx ctx;+    uint8_t           ic_bytes[4];++    if (!mlen) {+        return 0;+    }+    STORE32_LE(ic_bytes, ic);+    chacha_keysetup(&ctx, k);+    chacha_ietf_ivsetup(&ctx, n, ic_bytes);+    chacha20_encrypt_bytes(&ctx, m, c, mlen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++struct crypto_stream_chacha20_implementation+    crypto_stream_chacha20_ref_implementation = {+        SODIUM_C99(.stream =) stream_ref,+        SODIUM_C99(.stream_ietf_ext =) stream_ietf_ext_ref,+        SODIUM_C99(.stream_xor_ic =) stream_ref_xor_ic,+        SODIUM_C99(.stream_ietf_ext_xor_ic =) stream_ietf_ext_ref_xor_ic+    };
+ vendor/external/libsodium/crypto_stream/chacha20/ref/chacha20_ref.h view
@@ -0,0 +1,8 @@++#include <stdint.h>++#include "../stream_chacha20.h"+#include "crypto_stream_chacha20.h"++extern struct crypto_stream_chacha20_implementation+    crypto_stream_chacha20_ref_implementation;
+ vendor/external/libsodium/crypto_stream/chacha20/stream_chacha20.c view
@@ -0,0 +1,184 @@+#include "crypto_stream_chacha20.h"+#include "core.h"+#include "private/chacha20_ietf_ext.h"+#include "private/common.h"+#include "private/implementations.h"+#include "randombytes.h"+#include "runtime.h"+#include "stream_chacha20.h"++#include "ref/chacha20_ref.h"+#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \+    defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)+# include "dolbeau/chacha20_dolbeau-avx2.h"+#endif+#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)+# include "dolbeau/chacha20_dolbeau-ssse3.h"+#endif++static const crypto_stream_chacha20_implementation *implementation =+    &crypto_stream_chacha20_ref_implementation;++size_t+crypto_stream_chacha20_keybytes(void) {+    return crypto_stream_chacha20_KEYBYTES;+}++size_t+crypto_stream_chacha20_noncebytes(void) {+    return crypto_stream_chacha20_NONCEBYTES;+}++size_t+crypto_stream_chacha20_messagebytes_max(void)+{+    return crypto_stream_chacha20_MESSAGEBYTES_MAX;+}++size_t+crypto_stream_chacha20_ietf_keybytes(void) {+    return crypto_stream_chacha20_ietf_KEYBYTES;+}++size_t+crypto_stream_chacha20_ietf_noncebytes(void) {+    return crypto_stream_chacha20_ietf_NONCEBYTES;+}++size_t+crypto_stream_chacha20_ietf_messagebytes_max(void)+{+    return crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX;+}++int+crypto_stream_chacha20(unsigned char *c, unsigned long long clen,+                       const unsigned char *n, const unsigned char *k)+{+    if (clen > crypto_stream_chacha20_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    return implementation->stream(c, clen, n, k);+}++int+crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m,+                              unsigned long long mlen,+                              const unsigned char *n, uint64_t ic,+                              const unsigned char *k)+{+    if (mlen > crypto_stream_chacha20_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    return implementation->stream_xor_ic(c, m, mlen, n, ic, k);+}++int+crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m,+                           unsigned long long mlen, const unsigned char *n,+                           const unsigned char *k)+{+    if (mlen > crypto_stream_chacha20_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    return implementation->stream_xor_ic(c, m, mlen, n, 0U, k);+}++int+crypto_stream_chacha20_ietf_ext(unsigned char *c, unsigned long long clen,+                                const unsigned char *n, const unsigned char *k)+{+    if (clen > crypto_stream_chacha20_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    return implementation->stream_ietf_ext(c, clen, n, k);+}++int+crypto_stream_chacha20_ietf_ext_xor_ic(unsigned char *c, const unsigned char *m,+                                       unsigned long long mlen,+                                       const unsigned char *n, uint32_t ic,+                                       const unsigned char *k)+{+    if (mlen > crypto_stream_chacha20_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    return implementation->stream_ietf_ext_xor_ic(c, m, mlen, n, ic, k);+}++static int+crypto_stream_chacha20_ietf_ext_xor(unsigned char *c, const unsigned char *m,+                                    unsigned long long mlen, const unsigned char *n,+                                    const unsigned char *k)+{+    if (mlen > crypto_stream_chacha20_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    return implementation->stream_ietf_ext_xor_ic(c, m, mlen, n, 0U, k);+}++int+crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen,+                            const unsigned char *n, const unsigned char *k)+{+    if (clen > crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    return crypto_stream_chacha20_ietf_ext(c, clen, n, k);+}++int+crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m,+                                   unsigned long long mlen,+                                   const unsigned char *n, uint32_t ic,+                                   const unsigned char *k)+{+    if ((unsigned long long) ic >+        (64ULL * (1ULL << 32)) / 64ULL - (mlen + 63ULL) / 64ULL) {+        sodium_misuse();+    }+    return crypto_stream_chacha20_ietf_ext_xor_ic(c, m, mlen, n, ic, k);+}++int+crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m,+                                unsigned long long mlen, const unsigned char *n,+                                const unsigned char *k)+{+    if (mlen > crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX) {+        sodium_misuse();+    }+    return crypto_stream_chacha20_ietf_ext_xor(c, m, mlen, n, k);+}++void+crypto_stream_chacha20_ietf_keygen(unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES])+{+    randombytes_buf(k, crypto_stream_chacha20_ietf_KEYBYTES);+}++void+crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES])+{+    randombytes_buf(k, crypto_stream_chacha20_KEYBYTES);+}++int+_crypto_stream_chacha20_pick_best_implementation(void)+{+    implementation = &crypto_stream_chacha20_ref_implementation;+#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \+    defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)+    if (sodium_runtime_has_avx2()) {+        implementation = &crypto_stream_chacha20_dolbeau_avx2_implementation;+        return 0;+    }+#endif+#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)+    if (sodium_runtime_has_ssse3()) {+        implementation = &crypto_stream_chacha20_dolbeau_ssse3_implementation;+        return 0;+    }+#endif+    return 0;+}
+ vendor/external/libsodium/crypto_stream/chacha20/stream_chacha20.h view
@@ -0,0 +1,22 @@++#ifndef stream_chacha20_H+#define stream_chacha20_H++#include <stdint.h>++typedef struct crypto_stream_chacha20_implementation {+    int (*stream)(unsigned char *c, unsigned long long clen,+                  const unsigned char *n, const unsigned char *k);+    int (*stream_ietf_ext)(unsigned char *c, unsigned long long clen,+                           const unsigned char *n, const unsigned char *k);+    int (*stream_xor_ic)(unsigned char *c, const unsigned char *m,+                         unsigned long long mlen,+                         const unsigned char *n, uint64_t ic,+                         const unsigned char *k);+    int (*stream_ietf_ext_xor_ic)(unsigned char *c, const unsigned char *m,+                                  unsigned long long mlen,+                                  const unsigned char *n, uint32_t ic,+                                  const unsigned char *k);+} crypto_stream_chacha20_implementation;++#endif
+ vendor/external/libsodium/crypto_stream/crypto_stream.c view
@@ -0,0 +1,49 @@++#include "crypto_stream.h"+#include "randombytes.h"++size_t+crypto_stream_keybytes(void)+{+    return crypto_stream_KEYBYTES;+}++size_t+crypto_stream_noncebytes(void)+{+    return crypto_stream_NONCEBYTES;+}++size_t+crypto_stream_messagebytes_max(void)+{+    return crypto_stream_MESSAGEBYTES_MAX;+}++const char *+crypto_stream_primitive(void)+{+    return crypto_stream_PRIMITIVE;+}++int+crypto_stream(unsigned char *c, unsigned long long clen,+              const unsigned char *n, const unsigned char *k)+{+    return crypto_stream_xsalsa20(c, clen, n, k);+}+++int+crypto_stream_xor(unsigned char *c, const unsigned char *m,+                  unsigned long long mlen, const unsigned char *n,+                  const unsigned char *k)+{+    return crypto_stream_xsalsa20_xor(c, m, mlen, n, k);+}++void+crypto_stream_keygen(unsigned char k[crypto_stream_KEYBYTES])+{+    randombytes_buf(k, crypto_stream_KEYBYTES);+}
+ vendor/external/libsodium/crypto_stream/salsa20/ref/salsa20_ref.c view
@@ -0,0 +1,120 @@+/*+version 20140420+D. J. Bernstein+Public domain.+*/++#include <stdint.h>++#include "crypto_core_salsa20.h"+#include "crypto_stream_salsa20.h"+#include "utils.h"++#include "../stream_salsa20.h"+#include "salsa20_ref.h"++#ifndef HAVE_AMD64_ASM++static int+stream_ref(unsigned char *c, unsigned long long clen, const unsigned char *n,+           const unsigned char *k)+{+    unsigned char in[16];+    unsigned char block[64];+    unsigned char kcopy[32];+    unsigned int  i;+    unsigned int  u;++    if (!clen) {+        return 0;+    }+    for (i = 0; i < 32; i++) {+        kcopy[i] = k[i];+    }+    for (i = 0; i < 8; i++) {+        in[i] = n[i];+    }+    for (i = 8; i < 16; i++) {+        in[i] = 0;+    }+    while (clen >= 64) {+        crypto_core_salsa20(c, in, kcopy, NULL);+        u = 1;+        for (i = 8; i < 16; i++) {+            u += (unsigned int) in[i];+            in[i] = u;+            u >>= 8;+        }+        clen -= 64;+        c += 64;+    }+    if (clen) {+        crypto_core_salsa20(block, in, kcopy, NULL);+        for (i = 0; i < (unsigned int) clen; i++) {+            c[i] = block[i];+        }+    }+    sodium_memzero(block, sizeof block);+    sodium_memzero(kcopy, sizeof kcopy);++    return 0;+}++static int+stream_ref_xor_ic(unsigned char *c, const unsigned char *m,+                  unsigned long long mlen, const unsigned char *n, uint64_t ic,+                  const unsigned char *k)+{+    unsigned char in[16];+    unsigned char block[64];+    unsigned char kcopy[32];+    unsigned int  i;+    unsigned int  u;++    if (!mlen) {+        return 0;+    }+    for (i = 0; i < 32; i++) {+        kcopy[i] = k[i];+    }+    for (i = 0; i < 8; i++) {+        in[i] = n[i];+    }+    for (i = 8; i < 16; i++) {+        in[i] = (unsigned char) (ic & 0xff);+        ic >>= 8;+    }+    while (mlen >= 64) {+        crypto_core_salsa20(block, in, kcopy, NULL);+        for (i = 0; i < 64; i++) {+            c[i] = m[i] ^ block[i];+        }+        u = 1;+        for (i = 8; i < 16; i++) {+            u += (unsigned int) in[i];+            in[i] = u;+            u >>= 8;+        }+        mlen -= 64;+        c += 64;+        m += 64;+    }+    if (mlen) {+        crypto_core_salsa20(block, in, kcopy, NULL);+        for (i = 0; i < (unsigned int) mlen; i++) {+            c[i] = m[i] ^ block[i];+        }+    }+    sodium_memzero(block, sizeof block);+    sodium_memzero(kcopy, sizeof kcopy);++    return 0;+}++struct crypto_stream_salsa20_implementation+    crypto_stream_salsa20_ref_implementation = {+        SODIUM_C99(.stream =) stream_ref,+        SODIUM_C99(.stream_xor_ic =) stream_ref_xor_ic,+    };++#endif
+ vendor/external/libsodium/crypto_stream/salsa20/ref/salsa20_ref.h view
@@ -0,0 +1,8 @@++#include <stdint.h>++#include "../stream_salsa20.h"+#include "crypto_stream_salsa20.h"++extern struct crypto_stream_salsa20_implementation+    crypto_stream_salsa20_ref_implementation;
+ vendor/external/libsodium/crypto_stream/salsa20/stream_salsa20.c view
@@ -0,0 +1,100 @@+#include "crypto_stream_salsa20.h"+#include "private/common.h"+#include "private/implementations.h"+#include "randombytes.h"+#include "runtime.h"+#include "stream_salsa20.h"++#ifdef HAVE_AMD64_ASM+# include "xmm6/salsa20_xmm6.h"+#else+# include "ref/salsa20_ref.h"+#endif+#if !defined(HAVE_AMD64_ASM) && defined(HAVE_EMMINTRIN_H)+# include "xmm6int/salsa20_xmm6int-sse2.h"+#endif+#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \+    defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)+# include "xmm6int/salsa20_xmm6int-avx2.h"+#endif++#if HAVE_AMD64_ASM+static const crypto_stream_salsa20_implementation *implementation =+    &crypto_stream_salsa20_xmm6_implementation;+#else+static const crypto_stream_salsa20_implementation *implementation =+    &crypto_stream_salsa20_ref_implementation;+#endif++size_t+crypto_stream_salsa20_keybytes(void)+{+    return crypto_stream_salsa20_KEYBYTES;+}++size_t+crypto_stream_salsa20_noncebytes(void)+{+    return crypto_stream_salsa20_NONCEBYTES;+}++size_t+crypto_stream_salsa20_messagebytes_max(void)+{+    return crypto_stream_salsa20_MESSAGEBYTES_MAX;+}++int+crypto_stream_salsa20(unsigned char *c, unsigned long long clen,+                      const unsigned char *n, const unsigned char *k)+{+    return implementation->stream(c, clen, n, k);+}++int+crypto_stream_salsa20_xor_ic(unsigned char *c, const unsigned char *m,+                             unsigned long long mlen,+                             const unsigned char *n, uint64_t ic,+                             const unsigned char *k)+{+    return implementation->stream_xor_ic(c, m, mlen, n, ic, k);+}++int+crypto_stream_salsa20_xor(unsigned char *c, const unsigned char *m,+                          unsigned long long mlen, const unsigned char *n,+                          const unsigned char *k)+{+    return implementation->stream_xor_ic(c, m, mlen, n, 0U, k);+}++void+crypto_stream_salsa20_keygen(unsigned char k[crypto_stream_salsa20_KEYBYTES])+{+    randombytes_buf(k, crypto_stream_salsa20_KEYBYTES);+}++int+_crypto_stream_salsa20_pick_best_implementation(void)+{+#ifdef HAVE_AMD64_ASM+    implementation = &crypto_stream_salsa20_xmm6_implementation;+#else+    implementation = &crypto_stream_salsa20_ref_implementation;+#endif++#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \+    defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)+    if (sodium_runtime_has_avx2()) {+        implementation = &crypto_stream_salsa20_xmm6int_avx2_implementation;+        return 0;+    }+#endif+#if !defined(HAVE_AMD64_ASM) && defined(HAVE_EMMINTRIN_H)+    if (sodium_runtime_has_sse2()) {+        implementation = &crypto_stream_salsa20_xmm6int_sse2_implementation;+        return 0;+    }+#endif+    return 0; /* LCOV_EXCL_LINE */+}
+ vendor/external/libsodium/crypto_stream/salsa20/stream_salsa20.h view
@@ -0,0 +1,16 @@++#ifndef stream_salsa20_H+#define stream_salsa20_H++#include <stdint.h>++typedef struct crypto_stream_salsa20_implementation {+    int (*stream)(unsigned char *c, unsigned long long clen,+                  const unsigned char *n, const unsigned char *k);+    int (*stream_xor_ic)(unsigned char *c, const unsigned char *m,+                         unsigned long long mlen,+                         const unsigned char *n, uint64_t ic,+                         const unsigned char *k);+} crypto_stream_salsa20_implementation;++#endif
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6/salsa20_xmm6.c view
@@ -0,0 +1,31 @@++#include <stdint.h>++#include "utils.h"++#include "../stream_salsa20.h"+#include "salsa20_xmm6.h"++#ifdef HAVE_AMD64_ASM++#ifdef __cplusplus+extern "C" {+#endif+extern int stream_salsa20_xmm6(unsigned char *c, unsigned long long clen,+                               const unsigned char *n, const unsigned char *k);++extern int stream_salsa20_xmm6_xor_ic(unsigned char *c, const unsigned char *m,+                                      unsigned long long mlen,+                                      const unsigned char *n,+                                      uint64_t ic, const unsigned char *k);+#ifdef __cplusplus+}+#endif++struct crypto_stream_salsa20_implementation+    crypto_stream_salsa20_xmm6_implementation = {+        SODIUM_C99(.stream =) stream_salsa20_xmm6,+        SODIUM_C99(.stream_xor_ic =) stream_salsa20_xmm6_xor_ic,+    };++#endif
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6/salsa20_xmm6.h view
@@ -0,0 +1,8 @@++#include <stdint.h>++#include "../stream_salsa20.h"+#include "crypto_stream_salsa20.h"++extern struct crypto_stream_salsa20_implementation+    crypto_stream_salsa20_xmm6_implementation;
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c view
@@ -0,0 +1,131 @@++#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include "crypto_stream_salsa20.h"+#include "private/common.h"+#include "utils.h"++#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \+    defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)++# ifdef __GNUC__+#  pragma GCC target("sse2")+#  pragma GCC target("ssse3")+#  pragma GCC target("sse4.1")+#  pragma GCC target("avx2")+# endif++#include <emmintrin.h>+#include <immintrin.h>+#include <smmintrin.h>+#include <tmmintrin.h>+#include "private/sse2_64_32.h"++# include "../stream_salsa20.h"+# include "salsa20_xmm6int-avx2.h"++# define ROUNDS 20++typedef struct salsa_ctx {+    uint32_t input[16];+} salsa_ctx;++static const int TR[16] = {+    0, 5, 10, 15, 12, 1, 6, 11, 8, 13, 2, 7, 4, 9, 14, 3+};++static void+salsa_keysetup(salsa_ctx *ctx, const uint8_t *k)+{+    ctx->input[TR[1]]  = LOAD32_LE(k + 0);+    ctx->input[TR[2]]  = LOAD32_LE(k + 4);+    ctx->input[TR[3]]  = LOAD32_LE(k + 8);+    ctx->input[TR[4]]  = LOAD32_LE(k + 12);+    ctx->input[TR[11]] = LOAD32_LE(k + 16);+    ctx->input[TR[12]] = LOAD32_LE(k + 20);+    ctx->input[TR[13]] = LOAD32_LE(k + 24);+    ctx->input[TR[14]] = LOAD32_LE(k + 28);+    ctx->input[TR[0]]  = 0x61707865;+    ctx->input[TR[5]]  = 0x3320646e;+    ctx->input[TR[10]] = 0x79622d32;+    ctx->input[TR[15]] = 0x6b206574;+}++static void+salsa_ivsetup(salsa_ctx *ctx, const uint8_t *iv, const uint8_t *counter)+{+    ctx->input[TR[6]] = LOAD32_LE(iv + 0);+    ctx->input[TR[7]] = LOAD32_LE(iv + 4);+    ctx->input[TR[8]] = counter == NULL ? 0 : LOAD32_LE(counter + 0);+    ctx->input[TR[9]] = counter == NULL ? 0 : LOAD32_LE(counter + 4);+}++static void+salsa20_encrypt_bytes(salsa_ctx *ctx, const uint8_t *m, uint8_t *c,+                      unsigned long long bytes)+{+    uint32_t * const x = &ctx->input[0];++    if (!bytes) {+        return; /* LCOV_EXCL_LINE */+    }++#include "u8.h"+#include "u4.h"+#include "u1.h"+#include "u0.h"+}++static int+stream_avx2(unsigned char *c, unsigned long long clen, const unsigned char *n,+            const unsigned char *k)+{+    struct salsa_ctx ctx;++    if (!clen) {+        return 0;+    }+    COMPILER_ASSERT(crypto_stream_salsa20_KEYBYTES == 256 / 8);+    salsa_keysetup(&ctx, k);+    salsa_ivsetup(&ctx, n, NULL);+    memset(c, 0, clen);+    salsa20_encrypt_bytes(&ctx, c, c, clen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_avx2_xor_ic(unsigned char *c, const unsigned char *m,+                   unsigned long long mlen, const unsigned char *n, uint64_t ic,+                   const unsigned char *k)+{+    struct salsa_ctx ctx;+    uint8_t          ic_bytes[8];+    uint32_t         ic_high;+    uint32_t         ic_low;++    if (!mlen) {+        return 0;+    }+    ic_high = (uint32_t) (ic >> 32);+    ic_low  = (uint32_t) ic;+    STORE32_LE(&ic_bytes[0], ic_low);+    STORE32_LE(&ic_bytes[4], ic_high);+    salsa_keysetup(&ctx, k);+    salsa_ivsetup(&ctx, n, ic_bytes);+    salsa20_encrypt_bytes(&ctx, m, c, mlen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++struct crypto_stream_salsa20_implementation+    crypto_stream_salsa20_xmm6int_avx2_implementation = {+        SODIUM_C99(.stream =) stream_avx2,+        SODIUM_C99(.stream_xor_ic =) stream_avx2_xor_ic+    };++#endif
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.h view
@@ -0,0 +1,8 @@++#include <stdint.h>++#include "../stream_salsa20.h"+#include "crypto_stream_salsa20.h"++extern struct crypto_stream_salsa20_implementation+    crypto_stream_salsa20_xmm6int_avx2_implementation;
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c view
@@ -0,0 +1,122 @@++#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include "crypto_stream_salsa20.h"+#include "private/common.h"+#include "utils.h"++#ifdef HAVE_EMMINTRIN_H++# ifdef __GNUC__+#  pragma GCC target("sse2")+# endif+# include <emmintrin.h>+# include "private/sse2_64_32.h"++# include "../stream_salsa20.h"+# include "salsa20_xmm6int-sse2.h"++# define ROUNDS 20++typedef struct salsa_ctx {+    uint32_t input[16];+} salsa_ctx;++static const int TR[16] = {+    0, 5, 10, 15, 12, 1, 6, 11, 8, 13, 2, 7, 4, 9, 14, 3+};++static void+salsa_keysetup(salsa_ctx *ctx, const uint8_t *k)+{+    ctx->input[TR[1]]  = LOAD32_LE(k + 0);+    ctx->input[TR[2]]  = LOAD32_LE(k + 4);+    ctx->input[TR[3]]  = LOAD32_LE(k + 8);+    ctx->input[TR[4]]  = LOAD32_LE(k + 12);+    ctx->input[TR[11]] = LOAD32_LE(k + 16);+    ctx->input[TR[12]] = LOAD32_LE(k + 20);+    ctx->input[TR[13]] = LOAD32_LE(k + 24);+    ctx->input[TR[14]] = LOAD32_LE(k + 28);+    ctx->input[TR[0]]  = 0x61707865;+    ctx->input[TR[5]]  = 0x3320646e;+    ctx->input[TR[10]] = 0x79622d32;+    ctx->input[TR[15]] = 0x6b206574;+}++static void+salsa_ivsetup(salsa_ctx *ctx, const uint8_t *iv, const uint8_t *counter)+{+    ctx->input[TR[6]] = LOAD32_LE(iv + 0);+    ctx->input[TR[7]] = LOAD32_LE(iv + 4);+    ctx->input[TR[8]] = counter == NULL ? 0 : LOAD32_LE(counter + 0);+    ctx->input[TR[9]] = counter == NULL ? 0 : LOAD32_LE(counter + 4);+}++static void+salsa20_encrypt_bytes(salsa_ctx *ctx, const uint8_t *m, uint8_t *c,+                      unsigned long long bytes)+{+    uint32_t * const x = &ctx->input[0];++    if (!bytes) {+        return; /* LCOV_EXCL_LINE */+    }++#include "u4.h"+#include "u1.h"+#include "u0.h"+}++static int+stream_sse2(unsigned char *c, unsigned long long clen, const unsigned char *n,+            const unsigned char *k)+{+    struct salsa_ctx ctx;++    if (!clen) {+        return 0;+    }+    COMPILER_ASSERT(crypto_stream_salsa20_KEYBYTES == 256 / 8);+    salsa_keysetup(&ctx, k);+    salsa_ivsetup(&ctx, n, NULL);+    memset(c, 0, clen);+    salsa20_encrypt_bytes(&ctx, c, c, clen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++static int+stream_sse2_xor_ic(unsigned char *c, const unsigned char *m,+                   unsigned long long mlen, const unsigned char *n, uint64_t ic,+                   const unsigned char *k)+{+    struct salsa_ctx ctx;+    uint8_t          ic_bytes[8];+    uint32_t         ic_high;+    uint32_t         ic_low;++    if (!mlen) {+        return 0;+    }+    ic_high = (uint32_t) (ic >> 32);+    ic_low  = (uint32_t) (ic);+    STORE32_LE(&ic_bytes[0], ic_low);+    STORE32_LE(&ic_bytes[4], ic_high);+    salsa_keysetup(&ctx, k);+    salsa_ivsetup(&ctx, n, ic_bytes);+    salsa20_encrypt_bytes(&ctx, m, c, mlen);+    sodium_memzero(&ctx, sizeof ctx);++    return 0;+}++struct crypto_stream_salsa20_implementation+    crypto_stream_salsa20_xmm6int_sse2_implementation = {+        SODIUM_C99(.stream =) stream_sse2,+        SODIUM_C99(.stream_xor_ic =) stream_sse2_xor_ic+    };++#endif
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.h view
@@ -0,0 +1,8 @@++#include <stdint.h>++#include "../stream_salsa20.h"+#include "crypto_stream_salsa20.h"++extern struct crypto_stream_salsa20_implementation+    crypto_stream_salsa20_xmm6int_sse2_implementation;
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6int/u0.h view
@@ -0,0 +1,195 @@+if (bytes > 0) {+    __m128i diag0 = _mm_loadu_si128((const __m128i *) (x + 0));+    __m128i diag1 = _mm_loadu_si128((const __m128i *) (x + 4));+    __m128i diag2 = _mm_loadu_si128((const __m128i *) (x + 8));+    __m128i diag3 = _mm_loadu_si128((const __m128i *) (x + 12));+    __m128i a0, a1, a2, a3, a4, a5, a6, a7;+    __m128i b0, b1, b2, b3, b4, b5, b6, b7;+    uint8_t partialblock[64] = { 0 };++    unsigned int i;++    a0 = diag1;+    for (i = 0; i < ROUNDS; i += 4) {+        a0    = _mm_add_epi32(a0, diag0);+        a1    = diag0;+        b0    = a0;+        a0    = _mm_slli_epi32(a0, 7);+        b0    = _mm_srli_epi32(b0, 25);+        diag3 = _mm_xor_si128(diag3, a0);++        diag3 = _mm_xor_si128(diag3, b0);++        a1    = _mm_add_epi32(a1, diag3);+        a2    = diag3;+        b1    = a1;+        a1    = _mm_slli_epi32(a1, 9);+        b1    = _mm_srli_epi32(b1, 23);+        diag2 = _mm_xor_si128(diag2, a1);+        diag3 = _mm_shuffle_epi32(diag3, 0x93);+        diag2 = _mm_xor_si128(diag2, b1);++        a2    = _mm_add_epi32(a2, diag2);+        a3    = diag2;+        b2    = a2;+        a2    = _mm_slli_epi32(a2, 13);+        b2    = _mm_srli_epi32(b2, 19);+        diag1 = _mm_xor_si128(diag1, a2);+        diag2 = _mm_shuffle_epi32(diag2, 0x4e);+        diag1 = _mm_xor_si128(diag1, b2);++        a3    = _mm_add_epi32(a3, diag1);+        a4    = diag3;+        b3    = a3;+        a3    = _mm_slli_epi32(a3, 18);+        b3    = _mm_srli_epi32(b3, 14);+        diag0 = _mm_xor_si128(diag0, a3);+        diag1 = _mm_shuffle_epi32(diag1, 0x39);+        diag0 = _mm_xor_si128(diag0, b3);++        a4    = _mm_add_epi32(a4, diag0);+        a5    = diag0;+        b4    = a4;+        a4    = _mm_slli_epi32(a4, 7);+        b4    = _mm_srli_epi32(b4, 25);+        diag1 = _mm_xor_si128(diag1, a4);++        diag1 = _mm_xor_si128(diag1, b4);++        a5    = _mm_add_epi32(a5, diag1);+        a6    = diag1;+        b5    = a5;+        a5    = _mm_slli_epi32(a5, 9);+        b5    = _mm_srli_epi32(b5, 23);+        diag2 = _mm_xor_si128(diag2, a5);+        diag1 = _mm_shuffle_epi32(diag1, 0x93);+        diag2 = _mm_xor_si128(diag2, b5);++        a6    = _mm_add_epi32(a6, diag2);+        a7    = diag2;+        b6    = a6;+        a6    = _mm_slli_epi32(a6, 13);+        b6    = _mm_srli_epi32(b6, 19);+        diag3 = _mm_xor_si128(diag3, a6);+        diag2 = _mm_shuffle_epi32(diag2, 0x4e);+        diag3 = _mm_xor_si128(diag3, b6);++        a7    = _mm_add_epi32(a7, diag3);+        a0    = diag1;+        b7    = a7;+        a7    = _mm_slli_epi32(a7, 18);+        b7    = _mm_srli_epi32(b7, 14);+        diag0 = _mm_xor_si128(diag0, a7);+        diag3 = _mm_shuffle_epi32(diag3, 0x39);+        diag0 = _mm_xor_si128(diag0, b7);++        a0    = _mm_add_epi32(a0, diag0);+        a1    = diag0;+        b0    = a0;+        a0    = _mm_slli_epi32(a0, 7);+        b0    = _mm_srli_epi32(b0, 25);+        diag3 = _mm_xor_si128(diag3, a0);++        diag3 = _mm_xor_si128(diag3, b0);++        a1    = _mm_add_epi32(a1, diag3);+        a2    = diag3;+        b1    = a1;+        a1    = _mm_slli_epi32(a1, 9);+        b1    = _mm_srli_epi32(b1, 23);+        diag2 = _mm_xor_si128(diag2, a1);+        diag3 = _mm_shuffle_epi32(diag3, 0x93);+        diag2 = _mm_xor_si128(diag2, b1);++        a2    = _mm_add_epi32(a2, diag2);+        a3    = diag2;+        b2    = a2;+        a2    = _mm_slli_epi32(a2, 13);+        b2    = _mm_srli_epi32(b2, 19);+        diag1 = _mm_xor_si128(diag1, a2);+        diag2 = _mm_shuffle_epi32(diag2, 0x4e);+        diag1 = _mm_xor_si128(diag1, b2);++        a3    = _mm_add_epi32(a3, diag1);+        a4    = diag3;+        b3    = a3;+        a3    = _mm_slli_epi32(a3, 18);+        b3    = _mm_srli_epi32(b3, 14);+        diag0 = _mm_xor_si128(diag0, a3);+        diag1 = _mm_shuffle_epi32(diag1, 0x39);+        diag0 = _mm_xor_si128(diag0, b3);++        a4    = _mm_add_epi32(a4, diag0);+        a5    = diag0;+        b4    = a4;+        a4    = _mm_slli_epi32(a4, 7);+        b4    = _mm_srli_epi32(b4, 25);+        diag1 = _mm_xor_si128(diag1, a4);++        diag1 = _mm_xor_si128(diag1, b4);++        a5    = _mm_add_epi32(a5, diag1);+        a6    = diag1;+        b5    = a5;+        a5    = _mm_slli_epi32(a5, 9);+        b5    = _mm_srli_epi32(b5, 23);+        diag2 = _mm_xor_si128(diag2, a5);+        diag1 = _mm_shuffle_epi32(diag1, 0x93);+        diag2 = _mm_xor_si128(diag2, b5);++        a6    = _mm_add_epi32(a6, diag2);+        a7    = diag2;+        b6    = a6;+        a6    = _mm_slli_epi32(a6, 13);+        b6    = _mm_srli_epi32(b6, 19);+        diag3 = _mm_xor_si128(diag3, a6);+        diag2 = _mm_shuffle_epi32(diag2, 0x4e);+        diag3 = _mm_xor_si128(diag3, b6);++        a7    = _mm_add_epi32(a7, diag3);+        a0    = diag1;+        b7    = a7;+        a7    = _mm_slli_epi32(a7, 18);+        b7    = _mm_srli_epi32(b7, 14);+        diag0 = _mm_xor_si128(diag0, a7);+        diag3 = _mm_shuffle_epi32(diag3, 0x39);+        diag0 = _mm_xor_si128(diag0, b7);+    }++    diag0 = _mm_add_epi32(diag0, _mm_loadu_si128((const __m128i *) (x + 0)));+    diag1 = _mm_add_epi32(diag1, _mm_loadu_si128((const __m128i *) (x + 4)));+    diag2 = _mm_add_epi32(diag2, _mm_loadu_si128((const __m128i *) (x + 8)));+    diag3 = _mm_add_epi32(diag3, _mm_loadu_si128((const __m128i *) (x + 12)));++#define ONEQUAD_SHUFFLE(A, B, C, D)                                              \+    do {                                                                         \+        uint32_t in##A                         = _mm_cvtsi128_si32(diag0);       \+        uint32_t in##B                         = _mm_cvtsi128_si32(diag1);       \+        uint32_t in##C                         = _mm_cvtsi128_si32(diag2);       \+        uint32_t in##D                         = _mm_cvtsi128_si32(diag3);       \+        diag0                                  = _mm_shuffle_epi32(diag0, 0x39); \+        diag1                                  = _mm_shuffle_epi32(diag1, 0x39); \+        diag2                                  = _mm_shuffle_epi32(diag2, 0x39); \+        diag3                                  = _mm_shuffle_epi32(diag3, 0x39); \+        *(uint32_t *) (partialblock + (A * 4)) = in##A;                          \+        *(uint32_t *) (partialblock + (B * 4)) = in##B;                          \+        *(uint32_t *) (partialblock + (C * 4)) = in##C;                          \+        *(uint32_t *) (partialblock + (D * 4)) = in##D;                          \+    } while (0)++#define ONEQUAD(A, B, C, D) ONEQUAD_SHUFFLE(A, B, C, D)++    ONEQUAD(0, 12, 8, 4);+    ONEQUAD(5, 1, 13, 9);+    ONEQUAD(10, 6, 2, 14);+    ONEQUAD(15, 11, 7, 3);++#undef ONEQUAD+#undef ONEQUAD_SHUFFLE++    for (i = 0; i < bytes; i++) {+        c[i] = m[i] ^ partialblock[i];+    }++    sodium_memzero(partialblock, sizeof partialblock);+}
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6int/u1.h view
@@ -0,0 +1,207 @@+while (bytes >= 64) {+    __m128i diag0 = _mm_loadu_si128((const __m128i *) (x + 0));+    __m128i diag1 = _mm_loadu_si128((const __m128i *) (x + 4));+    __m128i diag2 = _mm_loadu_si128((const __m128i *) (x + 8));+    __m128i diag3 = _mm_loadu_si128((const __m128i *) (x + 12));+    __m128i a0, a1, a2, a3, a4, a5, a6, a7;+    __m128i b0, b1, b2, b3, b4, b5, b6, b7;++    uint32_t in8;+    uint32_t in9;+    int      i;++    a0 = diag1;+    for (i = 0; i < ROUNDS; i += 4) {+        a0    = _mm_add_epi32(a0, diag0);+        a1    = diag0;+        b0    = a0;+        a0    = _mm_slli_epi32(a0, 7);+        b0    = _mm_srli_epi32(b0, 25);+        diag3 = _mm_xor_si128(diag3, a0);++        diag3 = _mm_xor_si128(diag3, b0);++        a1    = _mm_add_epi32(a1, diag3);+        a2    = diag3;+        b1    = a1;+        a1    = _mm_slli_epi32(a1, 9);+        b1    = _mm_srli_epi32(b1, 23);+        diag2 = _mm_xor_si128(diag2, a1);+        diag3 = _mm_shuffle_epi32(diag3, 0x93);+        diag2 = _mm_xor_si128(diag2, b1);++        a2    = _mm_add_epi32(a2, diag2);+        a3    = diag2;+        b2    = a2;+        a2    = _mm_slli_epi32(a2, 13);+        b2    = _mm_srli_epi32(b2, 19);+        diag1 = _mm_xor_si128(diag1, a2);+        diag2 = _mm_shuffle_epi32(diag2, 0x4e);+        diag1 = _mm_xor_si128(diag1, b2);++        a3    = _mm_add_epi32(a3, diag1);+        a4    = diag3;+        b3    = a3;+        a3    = _mm_slli_epi32(a3, 18);+        b3    = _mm_srli_epi32(b3, 14);+        diag0 = _mm_xor_si128(diag0, a3);+        diag1 = _mm_shuffle_epi32(diag1, 0x39);+        diag0 = _mm_xor_si128(diag0, b3);++        a4    = _mm_add_epi32(a4, diag0);+        a5    = diag0;+        b4    = a4;+        a4    = _mm_slli_epi32(a4, 7);+        b4    = _mm_srli_epi32(b4, 25);+        diag1 = _mm_xor_si128(diag1, a4);++        diag1 = _mm_xor_si128(diag1, b4);++        a5    = _mm_add_epi32(a5, diag1);+        a6    = diag1;+        b5    = a5;+        a5    = _mm_slli_epi32(a5, 9);+        b5    = _mm_srli_epi32(b5, 23);+        diag2 = _mm_xor_si128(diag2, a5);+        diag1 = _mm_shuffle_epi32(diag1, 0x93);+        diag2 = _mm_xor_si128(diag2, b5);++        a6    = _mm_add_epi32(a6, diag2);+        a7    = diag2;+        b6    = a6;+        a6    = _mm_slli_epi32(a6, 13);+        b6    = _mm_srli_epi32(b6, 19);+        diag3 = _mm_xor_si128(diag3, a6);+        diag2 = _mm_shuffle_epi32(diag2, 0x4e);+        diag3 = _mm_xor_si128(diag3, b6);++        a7    = _mm_add_epi32(a7, diag3);+        a0    = diag1;+        b7    = a7;+        a7    = _mm_slli_epi32(a7, 18);+        b7    = _mm_srli_epi32(b7, 14);+        diag0 = _mm_xor_si128(diag0, a7);+        diag3 = _mm_shuffle_epi32(diag3, 0x39);+        diag0 = _mm_xor_si128(diag0, b7);++        a0    = _mm_add_epi32(a0, diag0);+        a1    = diag0;+        b0    = a0;+        a0    = _mm_slli_epi32(a0, 7);+        b0    = _mm_srli_epi32(b0, 25);+        diag3 = _mm_xor_si128(diag3, a0);++        diag3 = _mm_xor_si128(diag3, b0);++        a1    = _mm_add_epi32(a1, diag3);+        a2    = diag3;+        b1    = a1;+        a1    = _mm_slli_epi32(a1, 9);+        b1    = _mm_srli_epi32(b1, 23);+        diag2 = _mm_xor_si128(diag2, a1);+        diag3 = _mm_shuffle_epi32(diag3, 0x93);+        diag2 = _mm_xor_si128(diag2, b1);++        a2    = _mm_add_epi32(a2, diag2);+        a3    = diag2;+        b2    = a2;+        a2    = _mm_slli_epi32(a2, 13);+        b2    = _mm_srli_epi32(b2, 19);+        diag1 = _mm_xor_si128(diag1, a2);+        diag2 = _mm_shuffle_epi32(diag2, 0x4e);+        diag1 = _mm_xor_si128(diag1, b2);++        a3    = _mm_add_epi32(a3, diag1);+        a4    = diag3;+        b3    = a3;+        a3    = _mm_slli_epi32(a3, 18);+        b3    = _mm_srli_epi32(b3, 14);+        diag0 = _mm_xor_si128(diag0, a3);+        diag1 = _mm_shuffle_epi32(diag1, 0x39);+        diag0 = _mm_xor_si128(diag0, b3);++        a4    = _mm_add_epi32(a4, diag0);+        a5    = diag0;+        b4    = a4;+        a4    = _mm_slli_epi32(a4, 7);+        b4    = _mm_srli_epi32(b4, 25);+        diag1 = _mm_xor_si128(diag1, a4);++        diag1 = _mm_xor_si128(diag1, b4);++        a5    = _mm_add_epi32(a5, diag1);+        a6    = diag1;+        b5    = a5;+        a5    = _mm_slli_epi32(a5, 9);+        b5    = _mm_srli_epi32(b5, 23);+        diag2 = _mm_xor_si128(diag2, a5);+        diag1 = _mm_shuffle_epi32(diag1, 0x93);+        diag2 = _mm_xor_si128(diag2, b5);++        a6    = _mm_add_epi32(a6, diag2);+        a7    = diag2;+        b6    = a6;+        a6    = _mm_slli_epi32(a6, 13);+        b6    = _mm_srli_epi32(b6, 19);+        diag3 = _mm_xor_si128(diag3, a6);+        diag2 = _mm_shuffle_epi32(diag2, 0x4e);+        diag3 = _mm_xor_si128(diag3, b6);++        a7    = _mm_add_epi32(a7, diag3);+        a0    = diag1;+        b7    = a7;+        a7    = _mm_slli_epi32(a7, 18);+        b7    = _mm_srli_epi32(b7, 14);+        diag0 = _mm_xor_si128(diag0, a7);+        diag3 = _mm_shuffle_epi32(diag3, 0x39);+        diag0 = _mm_xor_si128(diag0, b7);+    }++    diag0 = _mm_add_epi32(diag0, _mm_loadu_si128((const __m128i *) (x + 0)));+    diag1 = _mm_add_epi32(diag1, _mm_loadu_si128((const __m128i *) (x + 4)));+    diag2 = _mm_add_epi32(diag2, _mm_loadu_si128((const __m128i *) (x + 8)));+    diag3 = _mm_add_epi32(diag3, _mm_loadu_si128((const __m128i *) (x + 12)));++#define ONEQUAD_SHUFFLE(A, B, C, D)                      \+    do {                                                 \+        uint32_t in##A = _mm_cvtsi128_si32(diag0);       \+        uint32_t in##B = _mm_cvtsi128_si32(diag1);       \+        uint32_t in##C = _mm_cvtsi128_si32(diag2);       \+        uint32_t in##D = _mm_cvtsi128_si32(diag3);       \+        diag0          = _mm_shuffle_epi32(diag0, 0x39); \+        diag1          = _mm_shuffle_epi32(diag1, 0x39); \+        diag2          = _mm_shuffle_epi32(diag2, 0x39); \+        diag3          = _mm_shuffle_epi32(diag3, 0x39); \+        in##A ^= *(const uint32_t *) (m + (A * 4));      \+        in##B ^= *(const uint32_t *) (m + (B * 4));      \+        in##C ^= *(const uint32_t *) (m + (C * 4));      \+        in##D ^= *(const uint32_t *) (m + (D * 4));      \+        *(uint32_t *) (c + (A * 4)) = in##A;             \+        *(uint32_t *) (c + (B * 4)) = in##B;             \+        *(uint32_t *) (c + (C * 4)) = in##C;             \+        *(uint32_t *) (c + (D * 4)) = in##D;             \+    } while (0)++#define ONEQUAD(A, B, C, D) ONEQUAD_SHUFFLE(A, B, C, D)++    ONEQUAD(0, 12, 8, 4);+    ONEQUAD(5, 1, 13, 9);+    ONEQUAD(10, 6, 2, 14);+    ONEQUAD(15, 11, 7, 3);++#undef ONEQUAD+#undef ONEQUAD_SHUFFLE++    in8 = x[8];+    in9 = x[13];+    in8++;+    if (in8 == 0) {+        in9++;+    }+    x[8]  = in8;+    x[13] = in9;++    c += 64;+    m += 64;+    bytes -= 64;+}
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6int/u4.h view
@@ -0,0 +1,547 @@+if (bytes >= 256) {+    __m128i y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14,+        y15;+    __m128i z0, z1, z2, z3, z4, z5, z6, z7, z8, z9, z10, z11, z12, z13, z14,+        z15;+    __m128i orig0, orig1, orig2, orig3, orig4, orig5, orig6, orig7, orig8,+        orig9, orig10, orig11, orig12, orig13, orig14, orig15;++    uint32_t in8;+    uint32_t in9;+    int      i;++    /* element broadcast immediate for _mm_shuffle_epi32 are in order:+       0x00, 0x55, 0xaa, 0xff */+    z0  = _mm_loadu_si128((const __m128i *) (x + 0));+    z5  = _mm_shuffle_epi32(z0, 0x55);+    z10 = _mm_shuffle_epi32(z0, 0xaa);+    z15 = _mm_shuffle_epi32(z0, 0xff);+    z0  = _mm_shuffle_epi32(z0, 0x00);+    z1  = _mm_loadu_si128((const __m128i *) (x + 4));+    z6  = _mm_shuffle_epi32(z1, 0xaa);+    z11 = _mm_shuffle_epi32(z1, 0xff);+    z12 = _mm_shuffle_epi32(z1, 0x00);+    z1  = _mm_shuffle_epi32(z1, 0x55);+    z2  = _mm_loadu_si128((const __m128i *) (x + 8));+    z7  = _mm_shuffle_epi32(z2, 0xff);+    z13 = _mm_shuffle_epi32(z2, 0x55);+    z2  = _mm_shuffle_epi32(z2, 0xaa);+    /* no z8 -> first half of the nonce, will fill later */+    z3  = _mm_loadu_si128((const __m128i *) (x + 12));+    z4  = _mm_shuffle_epi32(z3, 0x00);+    z14 = _mm_shuffle_epi32(z3, 0xaa);+    z3  = _mm_shuffle_epi32(z3, 0xff);+    /* no z9 -> second half of the nonce, will fill later */+    orig0  = z0;+    orig1  = z1;+    orig2  = z2;+    orig3  = z3;+    orig4  = z4;+    orig5  = z5;+    orig6  = z6;+    orig7  = z7;+    orig10 = z10;+    orig11 = z11;+    orig12 = z12;+    orig13 = z13;+    orig14 = z14;+    orig15 = z15;++    while (bytes >= 256) {+        /* vector implementation for z8 and z9 */+        /* not sure if it helps for only 4 blocks */+        const __m128i addv8 = _mm_set_epi64x(1, 0);+        const __m128i addv9 = _mm_set_epi64x(3, 2);+        __m128i       t8, t9;+        uint64_t      in89;++        in8  = x[8];+        in9  = x[13];+        in89 = ((uint64_t) in8) | (((uint64_t) in9) << 32);+        t8   = _mm_set1_epi64x(in89);+        t9   = _mm_set1_epi64x(in89);++        z8 = _mm_add_epi64(addv8, t8);+        z9 = _mm_add_epi64(addv9, t9);++        t8 = _mm_unpacklo_epi32(z8, z9);+        t9 = _mm_unpackhi_epi32(z8, z9);++        z8 = _mm_unpacklo_epi32(t8, t9);+        z9 = _mm_unpackhi_epi32(t8, t9);++        orig8 = z8;+        orig9 = z9;++        in89 += 4;++        x[8]  = in89 & 0xFFFFFFFF;+        x[13] = (in89 >> 32) & 0xFFFFFFFF;++        z5  = orig5;+        z10 = orig10;+        z15 = orig15;+        z14 = orig14;+        z3  = orig3;+        z6  = orig6;+        z11 = orig11;+        z1  = orig1;++        z7  = orig7;+        z13 = orig13;+        z2  = orig2;+        z9  = orig9;+        z0  = orig0;+        z12 = orig12;+        z4  = orig4;+        z8  = orig8;++        for (i = 0; i < ROUNDS; i += 2) {+            /* the inner loop is a direct translation (regexp search/replace)+             * from the amd64-xmm6 ASM */+            __m128i r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13,+                r14, r15;++            y4 = z12;+            y4 = _mm_add_epi32(y4, z0);+            r4 = y4;+            y4 = _mm_slli_epi32(y4, 7);+            z4 = _mm_xor_si128(z4, y4);+            r4 = _mm_srli_epi32(r4, 25);+            z4 = _mm_xor_si128(z4, r4);++            y9 = z1;+            y9 = _mm_add_epi32(y9, z5);+            r9 = y9;+            y9 = _mm_slli_epi32(y9, 7);+            z9 = _mm_xor_si128(z9, y9);+            r9 = _mm_srli_epi32(r9, 25);+            z9 = _mm_xor_si128(z9, r9);++            y8 = z0;+            y8 = _mm_add_epi32(y8, z4);+            r8 = y8;+            y8 = _mm_slli_epi32(y8, 9);+            z8 = _mm_xor_si128(z8, y8);+            r8 = _mm_srli_epi32(r8, 23);+            z8 = _mm_xor_si128(z8, r8);++            y13 = z5;+            y13 = _mm_add_epi32(y13, z9);+            r13 = y13;+            y13 = _mm_slli_epi32(y13, 9);+            z13 = _mm_xor_si128(z13, y13);+            r13 = _mm_srli_epi32(r13, 23);+            z13 = _mm_xor_si128(z13, r13);++            y12 = z4;+            y12 = _mm_add_epi32(y12, z8);+            r12 = y12;+            y12 = _mm_slli_epi32(y12, 13);+            z12 = _mm_xor_si128(z12, y12);+            r12 = _mm_srli_epi32(r12, 19);+            z12 = _mm_xor_si128(z12, r12);++            y1 = z9;+            y1 = _mm_add_epi32(y1, z13);+            r1 = y1;+            y1 = _mm_slli_epi32(y1, 13);+            z1 = _mm_xor_si128(z1, y1);+            r1 = _mm_srli_epi32(r1, 19);+            z1 = _mm_xor_si128(z1, r1);++            y0 = z8;+            y0 = _mm_add_epi32(y0, z12);+            r0 = y0;+            y0 = _mm_slli_epi32(y0, 18);+            z0 = _mm_xor_si128(z0, y0);+            r0 = _mm_srli_epi32(r0, 14);+            z0 = _mm_xor_si128(z0, r0);++            y5 = z13;+            y5 = _mm_add_epi32(y5, z1);+            r5 = y5;+            y5 = _mm_slli_epi32(y5, 18);+            z5 = _mm_xor_si128(z5, y5);+            r5 = _mm_srli_epi32(r5, 14);+            z5 = _mm_xor_si128(z5, r5);++            y14 = z6;+            y14 = _mm_add_epi32(y14, z10);+            r14 = y14;+            y14 = _mm_slli_epi32(y14, 7);+            z14 = _mm_xor_si128(z14, y14);+            r14 = _mm_srli_epi32(r14, 25);+            z14 = _mm_xor_si128(z14, r14);++            y3 = z11;+            y3 = _mm_add_epi32(y3, z15);+            r3 = y3;+            y3 = _mm_slli_epi32(y3, 7);+            z3 = _mm_xor_si128(z3, y3);+            r3 = _mm_srli_epi32(r3, 25);+            z3 = _mm_xor_si128(z3, r3);++            y2 = z10;+            y2 = _mm_add_epi32(y2, z14);+            r2 = y2;+            y2 = _mm_slli_epi32(y2, 9);+            z2 = _mm_xor_si128(z2, y2);+            r2 = _mm_srli_epi32(r2, 23);+            z2 = _mm_xor_si128(z2, r2);++            y7 = z15;+            y7 = _mm_add_epi32(y7, z3);+            r7 = y7;+            y7 = _mm_slli_epi32(y7, 9);+            z7 = _mm_xor_si128(z7, y7);+            r7 = _mm_srli_epi32(r7, 23);+            z7 = _mm_xor_si128(z7, r7);++            y6 = z14;+            y6 = _mm_add_epi32(y6, z2);+            r6 = y6;+            y6 = _mm_slli_epi32(y6, 13);+            z6 = _mm_xor_si128(z6, y6);+            r6 = _mm_srli_epi32(r6, 19);+            z6 = _mm_xor_si128(z6, r6);++            y11 = z3;+            y11 = _mm_add_epi32(y11, z7);+            r11 = y11;+            y11 = _mm_slli_epi32(y11, 13);+            z11 = _mm_xor_si128(z11, y11);+            r11 = _mm_srli_epi32(r11, 19);+            z11 = _mm_xor_si128(z11, r11);++            y10 = z2;+            y10 = _mm_add_epi32(y10, z6);+            r10 = y10;+            y10 = _mm_slli_epi32(y10, 18);+            z10 = _mm_xor_si128(z10, y10);+            r10 = _mm_srli_epi32(r10, 14);+            z10 = _mm_xor_si128(z10, r10);++            y1 = z3;+            y1 = _mm_add_epi32(y1, z0);+            r1 = y1;+            y1 = _mm_slli_epi32(y1, 7);+            z1 = _mm_xor_si128(z1, y1);+            r1 = _mm_srli_epi32(r1, 25);+            z1 = _mm_xor_si128(z1, r1);++            y15 = z7;+            y15 = _mm_add_epi32(y15, z11);+            r15 = y15;+            y15 = _mm_slli_epi32(y15, 18);+            z15 = _mm_xor_si128(z15, y15);+            r15 = _mm_srli_epi32(r15, 14);+            z15 = _mm_xor_si128(z15, r15);++            y6 = z4;+            y6 = _mm_add_epi32(y6, z5);+            r6 = y6;+            y6 = _mm_slli_epi32(y6, 7);+            z6 = _mm_xor_si128(z6, y6);+            r6 = _mm_srli_epi32(r6, 25);+            z6 = _mm_xor_si128(z6, r6);++            y2 = z0;+            y2 = _mm_add_epi32(y2, z1);+            r2 = y2;+            y2 = _mm_slli_epi32(y2, 9);+            z2 = _mm_xor_si128(z2, y2);+            r2 = _mm_srli_epi32(r2, 23);+            z2 = _mm_xor_si128(z2, r2);++            y7 = z5;+            y7 = _mm_add_epi32(y7, z6);+            r7 = y7;+            y7 = _mm_slli_epi32(y7, 9);+            z7 = _mm_xor_si128(z7, y7);+            r7 = _mm_srli_epi32(r7, 23);+            z7 = _mm_xor_si128(z7, r7);++            y3 = z1;+            y3 = _mm_add_epi32(y3, z2);+            r3 = y3;+            y3 = _mm_slli_epi32(y3, 13);+            z3 = _mm_xor_si128(z3, y3);+            r3 = _mm_srli_epi32(r3, 19);+            z3 = _mm_xor_si128(z3, r3);++            y4 = z6;+            y4 = _mm_add_epi32(y4, z7);+            r4 = y4;+            y4 = _mm_slli_epi32(y4, 13);+            z4 = _mm_xor_si128(z4, y4);+            r4 = _mm_srli_epi32(r4, 19);+            z4 = _mm_xor_si128(z4, r4);++            y0 = z2;+            y0 = _mm_add_epi32(y0, z3);+            r0 = y0;+            y0 = _mm_slli_epi32(y0, 18);+            z0 = _mm_xor_si128(z0, y0);+            r0 = _mm_srli_epi32(r0, 14);+            z0 = _mm_xor_si128(z0, r0);++            y5 = z7;+            y5 = _mm_add_epi32(y5, z4);+            r5 = y5;+            y5 = _mm_slli_epi32(y5, 18);+            z5 = _mm_xor_si128(z5, y5);+            r5 = _mm_srli_epi32(r5, 14);+            z5 = _mm_xor_si128(z5, r5);++            y11 = z9;+            y11 = _mm_add_epi32(y11, z10);+            r11 = y11;+            y11 = _mm_slli_epi32(y11, 7);+            z11 = _mm_xor_si128(z11, y11);+            r11 = _mm_srli_epi32(r11, 25);+            z11 = _mm_xor_si128(z11, r11);++            y12 = z14;+            y12 = _mm_add_epi32(y12, z15);+            r12 = y12;+            y12 = _mm_slli_epi32(y12, 7);+            z12 = _mm_xor_si128(z12, y12);+            r12 = _mm_srli_epi32(r12, 25);+            z12 = _mm_xor_si128(z12, r12);++            y8 = z10;+            y8 = _mm_add_epi32(y8, z11);+            r8 = y8;+            y8 = _mm_slli_epi32(y8, 9);+            z8 = _mm_xor_si128(z8, y8);+            r8 = _mm_srli_epi32(r8, 23);+            z8 = _mm_xor_si128(z8, r8);++            y13 = z15;+            y13 = _mm_add_epi32(y13, z12);+            r13 = y13;+            y13 = _mm_slli_epi32(y13, 9);+            z13 = _mm_xor_si128(z13, y13);+            r13 = _mm_srli_epi32(r13, 23);+            z13 = _mm_xor_si128(z13, r13);++            y9 = z11;+            y9 = _mm_add_epi32(y9, z8);+            r9 = y9;+            y9 = _mm_slli_epi32(y9, 13);+            z9 = _mm_xor_si128(z9, y9);+            r9 = _mm_srli_epi32(r9, 19);+            z9 = _mm_xor_si128(z9, r9);++            y14 = z12;+            y14 = _mm_add_epi32(y14, z13);+            r14 = y14;+            y14 = _mm_slli_epi32(y14, 13);+            z14 = _mm_xor_si128(z14, y14);+            r14 = _mm_srli_epi32(r14, 19);+            z14 = _mm_xor_si128(z14, r14);++            y10 = z8;+            y10 = _mm_add_epi32(y10, z9);+            r10 = y10;+            y10 = _mm_slli_epi32(y10, 18);+            z10 = _mm_xor_si128(z10, y10);+            r10 = _mm_srli_epi32(r10, 14);+            z10 = _mm_xor_si128(z10, r10);++            y15 = z13;+            y15 = _mm_add_epi32(y15, z14);+            r15 = y15;+            y15 = _mm_slli_epi32(y15, 18);+            z15 = _mm_xor_si128(z15, y15);+            r15 = _mm_srli_epi32(r15, 14);+            z15 = _mm_xor_si128(z15, r15);+        }++/* store data ; this macro replicates the original amd64-xmm6 code */+#define ONEQUAD_SHUFFLE(A, B, C, D)        \+    z##A  = _mm_add_epi32(z##A, orig##A);  \+    z##B  = _mm_add_epi32(z##B, orig##B);  \+    z##C  = _mm_add_epi32(z##C, orig##C);  \+    z##D  = _mm_add_epi32(z##D, orig##D);  \+    in##A = _mm_cvtsi128_si32(z##A);       \+    in##B = _mm_cvtsi128_si32(z##B);       \+    in##C = _mm_cvtsi128_si32(z##C);       \+    in##D = _mm_cvtsi128_si32(z##D);       \+    z##A  = _mm_shuffle_epi32(z##A, 0x39); \+    z##B  = _mm_shuffle_epi32(z##B, 0x39); \+    z##C  = _mm_shuffle_epi32(z##C, 0x39); \+    z##D  = _mm_shuffle_epi32(z##D, 0x39); \+                                           \+    in##A ^= *(uint32_t *) (m + 0);        \+    in##B ^= *(uint32_t *) (m + 4);        \+    in##C ^= *(uint32_t *) (m + 8);        \+    in##D ^= *(uint32_t *) (m + 12);       \+                                           \+    *(uint32_t *) (c + 0)  = in##A;        \+    *(uint32_t *) (c + 4)  = in##B;        \+    *(uint32_t *) (c + 8)  = in##C;        \+    *(uint32_t *) (c + 12) = in##D;        \+                                           \+    in##A = _mm_cvtsi128_si32(z##A);       \+    in##B = _mm_cvtsi128_si32(z##B);       \+    in##C = _mm_cvtsi128_si32(z##C);       \+    in##D = _mm_cvtsi128_si32(z##D);       \+    z##A  = _mm_shuffle_epi32(z##A, 0x39); \+    z##B  = _mm_shuffle_epi32(z##B, 0x39); \+    z##C  = _mm_shuffle_epi32(z##C, 0x39); \+    z##D  = _mm_shuffle_epi32(z##D, 0x39); \+                                           \+    in##A ^= *(uint32_t *) (m + 64);       \+    in##B ^= *(uint32_t *) (m + 68);       \+    in##C ^= *(uint32_t *) (m + 72);       \+    in##D ^= *(uint32_t *) (m + 76);       \+    *(uint32_t *) (c + 64) = in##A;        \+    *(uint32_t *) (c + 68) = in##B;        \+    *(uint32_t *) (c + 72) = in##C;        \+    *(uint32_t *) (c + 76) = in##D;        \+                                           \+    in##A = _mm_cvtsi128_si32(z##A);       \+    in##B = _mm_cvtsi128_si32(z##B);       \+    in##C = _mm_cvtsi128_si32(z##C);       \+    in##D = _mm_cvtsi128_si32(z##D);       \+    z##A  = _mm_shuffle_epi32(z##A, 0x39); \+    z##B  = _mm_shuffle_epi32(z##B, 0x39); \+    z##C  = _mm_shuffle_epi32(z##C, 0x39); \+    z##D  = _mm_shuffle_epi32(z##D, 0x39); \+                                           \+    in##A ^= *(uint32_t *) (m + 128);      \+    in##B ^= *(uint32_t *) (m + 132);      \+    in##C ^= *(uint32_t *) (m + 136);      \+    in##D ^= *(uint32_t *) (m + 140);      \+    *(uint32_t *) (c + 128) = in##A;       \+    *(uint32_t *) (c + 132) = in##B;       \+    *(uint32_t *) (c + 136) = in##C;       \+    *(uint32_t *) (c + 140) = in##D;       \+                                           \+    in##A = _mm_cvtsi128_si32(z##A);       \+    in##B = _mm_cvtsi128_si32(z##B);       \+    in##C = _mm_cvtsi128_si32(z##C);       \+    in##D = _mm_cvtsi128_si32(z##D);       \+                                           \+    in##A ^= *(uint32_t *) (m + 192);      \+    in##B ^= *(uint32_t *) (m + 196);      \+    in##C ^= *(uint32_t *) (m + 200);      \+    in##D ^= *(uint32_t *) (m + 204);      \+    *(uint32_t *) (c + 192) = in##A;       \+    *(uint32_t *) (c + 196) = in##B;       \+    *(uint32_t *) (c + 200) = in##C;       \+    *(uint32_t *) (c + 204) = in##D++/* store data ; this macro replaces shuffle+mov by a direct extract; not much+ * difference */+#define ONEQUAD_EXTRACT(A, B, C, D)       \+    z##A  = _mm_add_epi32(z##A, orig##A); \+    z##B  = _mm_add_epi32(z##B, orig##B); \+    z##C  = _mm_add_epi32(z##C, orig##C); \+    z##D  = _mm_add_epi32(z##D, orig##D); \+    in##A = _mm_cvtsi128_si32(z##A);      \+    in##B = _mm_cvtsi128_si32(z##B);      \+    in##C = _mm_cvtsi128_si32(z##C);      \+    in##D = _mm_cvtsi128_si32(z##D);      \+    in##A ^= *(uint32_t *) (m + 0);       \+    in##B ^= *(uint32_t *) (m + 4);       \+    in##C ^= *(uint32_t *) (m + 8);       \+    in##D ^= *(uint32_t *) (m + 12);      \+    *(uint32_t *) (c + 0)  = in##A;       \+    *(uint32_t *) (c + 4)  = in##B;       \+    *(uint32_t *) (c + 8)  = in##C;       \+    *(uint32_t *) (c + 12) = in##D;       \+                                          \+    in##A = _mm_extract_epi32(z##A, 1);   \+    in##B = _mm_extract_epi32(z##B, 1);   \+    in##C = _mm_extract_epi32(z##C, 1);   \+    in##D = _mm_extract_epi32(z##D, 1);   \+                                          \+    in##A ^= *(uint32_t *) (m + 64);      \+    in##B ^= *(uint32_t *) (m + 68);      \+    in##C ^= *(uint32_t *) (m + 72);      \+    in##D ^= *(uint32_t *) (m + 76);      \+    *(uint32_t *) (c + 64) = in##A;       \+    *(uint32_t *) (c + 68) = in##B;       \+    *(uint32_t *) (c + 72) = in##C;       \+    *(uint32_t *) (c + 76) = in##D;       \+                                          \+    in##A = _mm_extract_epi32(z##A, 2);   \+    in##B = _mm_extract_epi32(z##B, 2);   \+    in##C = _mm_extract_epi32(z##C, 2);   \+    in##D = _mm_extract_epi32(z##D, 2);   \+                                          \+    in##A ^= *(uint32_t *) (m + 128);     \+    in##B ^= *(uint32_t *) (m + 132);     \+    in##C ^= *(uint32_t *) (m + 136);     \+    in##D ^= *(uint32_t *) (m + 140);     \+    *(uint32_t *) (c + 128) = in##A;      \+    *(uint32_t *) (c + 132) = in##B;      \+    *(uint32_t *) (c + 136) = in##C;      \+    *(uint32_t *) (c + 140) = in##D;      \+                                          \+    in##A = _mm_extract_epi32(z##A, 3);   \+    in##B = _mm_extract_epi32(z##B, 3);   \+    in##C = _mm_extract_epi32(z##C, 3);   \+    in##D = _mm_extract_epi32(z##D, 3);   \+                                          \+    in##A ^= *(uint32_t *) (m + 192);     \+    in##B ^= *(uint32_t *) (m + 196);     \+    in##C ^= *(uint32_t *) (m + 200);     \+    in##D ^= *(uint32_t *) (m + 204);     \+    *(uint32_t *) (c + 192) = in##A;      \+    *(uint32_t *) (c + 196) = in##B;      \+    *(uint32_t *) (c + 200) = in##C;      \+    *(uint32_t *) (c + 204) = in##D++/* store data ; this macro first transpose data in-registers, and then store+ * them in memory. much faster with icc. */+#define ONEQUAD_TRANSPOSE(A, B, C, D)                                         \+    z##A = _mm_add_epi32(z##A, orig##A);                                      \+    z##B = _mm_add_epi32(z##B, orig##B);                                      \+    z##C = _mm_add_epi32(z##C, orig##C);                                      \+    z##D = _mm_add_epi32(z##D, orig##D);                                      \+    y##A = _mm_unpacklo_epi32(z##A, z##B);                                    \+    y##B = _mm_unpacklo_epi32(z##C, z##D);                                    \+    y##C = _mm_unpackhi_epi32(z##A, z##B);                                    \+    y##D = _mm_unpackhi_epi32(z##C, z##D);                                    \+    z##A = _mm_unpacklo_epi64(y##A, y##B);                                    \+    z##B = _mm_unpackhi_epi64(y##A, y##B);                                    \+    z##C = _mm_unpacklo_epi64(y##C, y##D);                                    \+    z##D = _mm_unpackhi_epi64(y##C, y##D);                                    \+    y##A = _mm_xor_si128(z##A, _mm_loadu_si128((const __m128i *) (m + 0)));   \+    _mm_storeu_si128((__m128i *) (c + 0), y##A);                              \+    y##B = _mm_xor_si128(z##B, _mm_loadu_si128((const __m128i *) (m + 64)));  \+    _mm_storeu_si128((__m128i *) (c + 64), y##B);                             \+    y##C = _mm_xor_si128(z##C, _mm_loadu_si128((const __m128i *) (m + 128))); \+    _mm_storeu_si128((__m128i *) (c + 128), y##C);                            \+    y##D = _mm_xor_si128(z##D, _mm_loadu_si128((const __m128i *) (m + 192))); \+    _mm_storeu_si128((__m128i *) (c + 192), y##D)++#define ONEQUAD(A, B, C, D) ONEQUAD_TRANSPOSE(A, B, C, D)++        ONEQUAD(0, 1, 2, 3);+        m += 16;+        c += 16;+        ONEQUAD(4, 5, 6, 7);+        m += 16;+        c += 16;+        ONEQUAD(8, 9, 10, 11);+        m += 16;+        c += 16;+        ONEQUAD(12, 13, 14, 15);+        m -= 48;+        c -= 48;++#undef ONEQUAD+#undef ONEQUAD_TRANSPOSE+#undef ONEQUAD_EXTRACT+#undef ONEQUAD_SHUFFLE++        bytes -= 256;+        c += 256;+        m += 256;+    }+}
+ vendor/external/libsodium/crypto_stream/salsa20/xmm6int/u8.h view
@@ -0,0 +1,477 @@+if (bytes >= 512) {+    __m256i y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14,+        y15;++    /* the naive way seems as fast (if not a bit faster) than the vector way */+    __m256i z0  = _mm256_set1_epi32(x[0]);+    __m256i z5  = _mm256_set1_epi32(x[1]);+    __m256i z10 = _mm256_set1_epi32(x[2]);+    __m256i z15 = _mm256_set1_epi32(x[3]);+    __m256i z12 = _mm256_set1_epi32(x[4]);+    __m256i z1  = _mm256_set1_epi32(x[5]);+    __m256i z6  = _mm256_set1_epi32(x[6]);+    __m256i z11 = _mm256_set1_epi32(x[7]);+    __m256i z8; /* useless */+    __m256i z13 = _mm256_set1_epi32(x[9]);+    __m256i z2  = _mm256_set1_epi32(x[10]);+    __m256i z7  = _mm256_set1_epi32(x[11]);+    __m256i z4  = _mm256_set1_epi32(x[12]);+    __m256i z9; /* useless */+    __m256i z14 = _mm256_set1_epi32(x[14]);+    __m256i z3  = _mm256_set1_epi32(x[15]);++    __m256i orig0 = z0;+    __m256i orig1 = z1;+    __m256i orig2 = z2;+    __m256i orig3 = z3;+    __m256i orig4 = z4;+    __m256i orig5 = z5;+    __m256i orig6 = z6;+    __m256i orig7 = z7;+    __m256i orig8;+    __m256i orig9;+    __m256i orig10 = z10;+    __m256i orig11 = z11;+    __m256i orig12 = z12;+    __m256i orig13 = z13;+    __m256i orig14 = z14;+    __m256i orig15 = z15;++    uint32_t in8;+    uint32_t in9;+    int      i;++    while (bytes >= 512) {+        /* vector implementation for z8 and z9 */+        /* faster than the naive version for 8 blocks */+        const __m256i addv8   = _mm256_set_epi64x(3, 2, 1, 0);+        const __m256i addv9   = _mm256_set_epi64x(7, 6, 5, 4);+        const __m256i permute = _mm256_set_epi32(7, 6, 3, 2, 5, 4, 1, 0);++        __m256i  t8, t9;+        uint64_t in89;++        in8  = x[8];+        in9  = x[13]; /* see arrays above for the address translation */+        in89 = ((uint64_t) in8) | (((uint64_t) in9) << 32);++        z8 = z9 = _mm256_broadcastq_epi64(_mm_cvtsi64_si128(in89));++        t8 = _mm256_add_epi64(addv8, z8);+        t9 = _mm256_add_epi64(addv9, z9);++        z8 = _mm256_unpacklo_epi32(t8, t9);+        z9 = _mm256_unpackhi_epi32(t8, t9);++        t8 = _mm256_unpacklo_epi32(z8, z9);+        t9 = _mm256_unpackhi_epi32(z8, z9);++        /* required because unpack* are intra-lane */+        z8 = _mm256_permutevar8x32_epi32(t8, permute);+        z9 = _mm256_permutevar8x32_epi32(t9, permute);++        orig8 = z8;+        orig9 = z9;++        in89 += 8;++        x[8]  = in89 & 0xFFFFFFFF;+        x[13] = (in89 >> 32) & 0xFFFFFFFF;++        z5  = orig5;+        z10 = orig10;+        z15 = orig15;+        z14 = orig14;+        z3  = orig3;+        z6  = orig6;+        z11 = orig11;+        z1  = orig1;++        z7  = orig7;+        z13 = orig13;+        z2  = orig2;+        z9  = orig9;+        z0  = orig0;+        z12 = orig12;+        z4  = orig4;+        z8  = orig8;++        for (i = 0; i < ROUNDS; i += 2) {+            /* the inner loop is a direct translation (regexp search/replace)+             * from the amd64-xmm6 ASM */+            __m256i r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13,+                r14, r15;++            y4 = z12;+            y4 = _mm256_add_epi32(y4, z0);+            r4 = y4;+            y4 = _mm256_slli_epi32(y4, 7);+            z4 = _mm256_xor_si256(z4, y4);+            r4 = _mm256_srli_epi32(r4, 25);+            z4 = _mm256_xor_si256(z4, r4);++            y9 = z1;+            y9 = _mm256_add_epi32(y9, z5);+            r9 = y9;+            y9 = _mm256_slli_epi32(y9, 7);+            z9 = _mm256_xor_si256(z9, y9);+            r9 = _mm256_srli_epi32(r9, 25);+            z9 = _mm256_xor_si256(z9, r9);++            y8 = z0;+            y8 = _mm256_add_epi32(y8, z4);+            r8 = y8;+            y8 = _mm256_slli_epi32(y8, 9);+            z8 = _mm256_xor_si256(z8, y8);+            r8 = _mm256_srli_epi32(r8, 23);+            z8 = _mm256_xor_si256(z8, r8);++            y13 = z5;+            y13 = _mm256_add_epi32(y13, z9);+            r13 = y13;+            y13 = _mm256_slli_epi32(y13, 9);+            z13 = _mm256_xor_si256(z13, y13);+            r13 = _mm256_srli_epi32(r13, 23);+            z13 = _mm256_xor_si256(z13, r13);++            y12 = z4;+            y12 = _mm256_add_epi32(y12, z8);+            r12 = y12;+            y12 = _mm256_slli_epi32(y12, 13);+            z12 = _mm256_xor_si256(z12, y12);+            r12 = _mm256_srli_epi32(r12, 19);+            z12 = _mm256_xor_si256(z12, r12);++            y1 = z9;+            y1 = _mm256_add_epi32(y1, z13);+            r1 = y1;+            y1 = _mm256_slli_epi32(y1, 13);+            z1 = _mm256_xor_si256(z1, y1);+            r1 = _mm256_srli_epi32(r1, 19);+            z1 = _mm256_xor_si256(z1, r1);++            y0 = z8;+            y0 = _mm256_add_epi32(y0, z12);+            r0 = y0;+            y0 = _mm256_slli_epi32(y0, 18);+            z0 = _mm256_xor_si256(z0, y0);+            r0 = _mm256_srli_epi32(r0, 14);+            z0 = _mm256_xor_si256(z0, r0);++            y5 = z13;+            y5 = _mm256_add_epi32(y5, z1);+            r5 = y5;+            y5 = _mm256_slli_epi32(y5, 18);+            z5 = _mm256_xor_si256(z5, y5);+            r5 = _mm256_srli_epi32(r5, 14);+            z5 = _mm256_xor_si256(z5, r5);++            y14 = z6;+            y14 = _mm256_add_epi32(y14, z10);+            r14 = y14;+            y14 = _mm256_slli_epi32(y14, 7);+            z14 = _mm256_xor_si256(z14, y14);+            r14 = _mm256_srli_epi32(r14, 25);+            z14 = _mm256_xor_si256(z14, r14);++            y3 = z11;+            y3 = _mm256_add_epi32(y3, z15);+            r3 = y3;+            y3 = _mm256_slli_epi32(y3, 7);+            z3 = _mm256_xor_si256(z3, y3);+            r3 = _mm256_srli_epi32(r3, 25);+            z3 = _mm256_xor_si256(z3, r3);++            y2 = z10;+            y2 = _mm256_add_epi32(y2, z14);+            r2 = y2;+            y2 = _mm256_slli_epi32(y2, 9);+            z2 = _mm256_xor_si256(z2, y2);+            r2 = _mm256_srli_epi32(r2, 23);+            z2 = _mm256_xor_si256(z2, r2);++            y7 = z15;+            y7 = _mm256_add_epi32(y7, z3);+            r7 = y7;+            y7 = _mm256_slli_epi32(y7, 9);+            z7 = _mm256_xor_si256(z7, y7);+            r7 = _mm256_srli_epi32(r7, 23);+            z7 = _mm256_xor_si256(z7, r7);++            y6 = z14;+            y6 = _mm256_add_epi32(y6, z2);+            r6 = y6;+            y6 = _mm256_slli_epi32(y6, 13);+            z6 = _mm256_xor_si256(z6, y6);+            r6 = _mm256_srli_epi32(r6, 19);+            z6 = _mm256_xor_si256(z6, r6);++            y11 = z3;+            y11 = _mm256_add_epi32(y11, z7);+            r11 = y11;+            y11 = _mm256_slli_epi32(y11, 13);+            z11 = _mm256_xor_si256(z11, y11);+            r11 = _mm256_srli_epi32(r11, 19);+            z11 = _mm256_xor_si256(z11, r11);++            y10 = z2;+            y10 = _mm256_add_epi32(y10, z6);+            r10 = y10;+            y10 = _mm256_slli_epi32(y10, 18);+            z10 = _mm256_xor_si256(z10, y10);+            r10 = _mm256_srli_epi32(r10, 14);+            z10 = _mm256_xor_si256(z10, r10);++            y1 = z3;+            y1 = _mm256_add_epi32(y1, z0);+            r1 = y1;+            y1 = _mm256_slli_epi32(y1, 7);+            z1 = _mm256_xor_si256(z1, y1);+            r1 = _mm256_srli_epi32(r1, 25);+            z1 = _mm256_xor_si256(z1, r1);++            y15 = z7;+            y15 = _mm256_add_epi32(y15, z11);+            r15 = y15;+            y15 = _mm256_slli_epi32(y15, 18);+            z15 = _mm256_xor_si256(z15, y15);+            r15 = _mm256_srli_epi32(r15, 14);+            z15 = _mm256_xor_si256(z15, r15);++            y6 = z4;+            y6 = _mm256_add_epi32(y6, z5);+            r6 = y6;+            y6 = _mm256_slli_epi32(y6, 7);+            z6 = _mm256_xor_si256(z6, y6);+            r6 = _mm256_srli_epi32(r6, 25);+            z6 = _mm256_xor_si256(z6, r6);++            y2 = z0;+            y2 = _mm256_add_epi32(y2, z1);+            r2 = y2;+            y2 = _mm256_slli_epi32(y2, 9);+            z2 = _mm256_xor_si256(z2, y2);+            r2 = _mm256_srli_epi32(r2, 23);+            z2 = _mm256_xor_si256(z2, r2);++            y7 = z5;+            y7 = _mm256_add_epi32(y7, z6);+            r7 = y7;+            y7 = _mm256_slli_epi32(y7, 9);+            z7 = _mm256_xor_si256(z7, y7);+            r7 = _mm256_srli_epi32(r7, 23);+            z7 = _mm256_xor_si256(z7, r7);++            y3 = z1;+            y3 = _mm256_add_epi32(y3, z2);+            r3 = y3;+            y3 = _mm256_slli_epi32(y3, 13);+            z3 = _mm256_xor_si256(z3, y3);+            r3 = _mm256_srli_epi32(r3, 19);+            z3 = _mm256_xor_si256(z3, r3);++            y4 = z6;+            y4 = _mm256_add_epi32(y4, z7);+            r4 = y4;+            y4 = _mm256_slli_epi32(y4, 13);+            z4 = _mm256_xor_si256(z4, y4);+            r4 = _mm256_srli_epi32(r4, 19);+            z4 = _mm256_xor_si256(z4, r4);++            y0 = z2;+            y0 = _mm256_add_epi32(y0, z3);+            r0 = y0;+            y0 = _mm256_slli_epi32(y0, 18);+            z0 = _mm256_xor_si256(z0, y0);+            r0 = _mm256_srli_epi32(r0, 14);+            z0 = _mm256_xor_si256(z0, r0);++            y5 = z7;+            y5 = _mm256_add_epi32(y5, z4);+            r5 = y5;+            y5 = _mm256_slli_epi32(y5, 18);+            z5 = _mm256_xor_si256(z5, y5);+            r5 = _mm256_srli_epi32(r5, 14);+            z5 = _mm256_xor_si256(z5, r5);++            y11 = z9;+            y11 = _mm256_add_epi32(y11, z10);+            r11 = y11;+            y11 = _mm256_slli_epi32(y11, 7);+            z11 = _mm256_xor_si256(z11, y11);+            r11 = _mm256_srli_epi32(r11, 25);+            z11 = _mm256_xor_si256(z11, r11);++            y12 = z14;+            y12 = _mm256_add_epi32(y12, z15);+            r12 = y12;+            y12 = _mm256_slli_epi32(y12, 7);+            z12 = _mm256_xor_si256(z12, y12);+            r12 = _mm256_srli_epi32(r12, 25);+            z12 = _mm256_xor_si256(z12, r12);++            y8 = z10;+            y8 = _mm256_add_epi32(y8, z11);+            r8 = y8;+            y8 = _mm256_slli_epi32(y8, 9);+            z8 = _mm256_xor_si256(z8, y8);+            r8 = _mm256_srli_epi32(r8, 23);+            z8 = _mm256_xor_si256(z8, r8);++            y13 = z15;+            y13 = _mm256_add_epi32(y13, z12);+            r13 = y13;+            y13 = _mm256_slli_epi32(y13, 9);+            z13 = _mm256_xor_si256(z13, y13);+            r13 = _mm256_srli_epi32(r13, 23);+            z13 = _mm256_xor_si256(z13, r13);++            y9 = z11;+            y9 = _mm256_add_epi32(y9, z8);+            r9 = y9;+            y9 = _mm256_slli_epi32(y9, 13);+            z9 = _mm256_xor_si256(z9, y9);+            r9 = _mm256_srli_epi32(r9, 19);+            z9 = _mm256_xor_si256(z9, r9);++            y14 = z12;+            y14 = _mm256_add_epi32(y14, z13);+            r14 = y14;+            y14 = _mm256_slli_epi32(y14, 13);+            z14 = _mm256_xor_si256(z14, y14);+            r14 = _mm256_srli_epi32(r14, 19);+            z14 = _mm256_xor_si256(z14, r14);++            y10 = z8;+            y10 = _mm256_add_epi32(y10, z9);+            r10 = y10;+            y10 = _mm256_slli_epi32(y10, 18);+            z10 = _mm256_xor_si256(z10, y10);+            r10 = _mm256_srli_epi32(r10, 14);+            z10 = _mm256_xor_si256(z10, r10);++            y15 = z13;+            y15 = _mm256_add_epi32(y15, z14);+            r15 = y15;+            y15 = _mm256_slli_epi32(y15, 18);+            z15 = _mm256_xor_si256(z15, y15);+            r15 = _mm256_srli_epi32(r15, 14);+            z15 = _mm256_xor_si256(z15, r15);+        }++/* store data ; this macro first transpose data in-registers, and then store+ * them in memory. much faster with icc. */+#define ONEQUAD_TRANSPOSE(A, B, C, D)                                    \+    {                                                                    \+        __m128i t0, t1, t2, t3;                                          \+        z##A = _mm256_add_epi32(z##A, orig##A);                          \+        z##B = _mm256_add_epi32(z##B, orig##B);                          \+        z##C = _mm256_add_epi32(z##C, orig##C);                          \+        z##D = _mm256_add_epi32(z##D, orig##D);                          \+        y##A = _mm256_unpacklo_epi32(z##A, z##B);                        \+        y##B = _mm256_unpacklo_epi32(z##C, z##D);                        \+        y##C = _mm256_unpackhi_epi32(z##A, z##B);                        \+        y##D = _mm256_unpackhi_epi32(z##C, z##D);                        \+        z##A = _mm256_unpacklo_epi64(y##A, y##B);                        \+        z##B = _mm256_unpackhi_epi64(y##A, y##B);                        \+        z##C = _mm256_unpacklo_epi64(y##C, y##D);                        \+        z##D = _mm256_unpackhi_epi64(y##C, y##D);                        \+        t0   = _mm_xor_si128(_mm256_extracti128_si256(z##A, 0),          \+                           _mm_loadu_si128((const __m128i*) (m + 0))); \+        _mm_storeu_si128((__m128i*) (c + 0), t0);                        \+        t1 = _mm_xor_si128(_mm256_extracti128_si256(z##B, 0),            \+                           _mm_loadu_si128((const __m128i*) (m + 64)));  \+        _mm_storeu_si128((__m128i*) (c + 64), t1);                       \+        t2 = _mm_xor_si128(_mm256_extracti128_si256(z##C, 0),            \+                           _mm_loadu_si128((const __m128i*) (m + 128))); \+        _mm_storeu_si128((__m128i*) (c + 128), t2);                      \+        t3 = _mm_xor_si128(_mm256_extracti128_si256(z##D, 0),            \+                           _mm_loadu_si128((const __m128i*) (m + 192))); \+        _mm_storeu_si128((__m128i*) (c + 192), t3);                      \+        t0 = _mm_xor_si128(_mm256_extracti128_si256(z##A, 1),            \+                           _mm_loadu_si128((const __m128i*) (m + 256))); \+        _mm_storeu_si128((__m128i*) (c + 256), t0);                      \+        t1 = _mm_xor_si128(_mm256_extracti128_si256(z##B, 1),            \+                           _mm_loadu_si128((const __m128i*) (m + 320))); \+        _mm_storeu_si128((__m128i*) (c + 320), t1);                      \+        t2 = _mm_xor_si128(_mm256_extracti128_si256(z##C, 1),            \+                           _mm_loadu_si128((const __m128i*) (m + 384))); \+        _mm_storeu_si128((__m128i*) (c + 384), t2);                      \+        t3 = _mm_xor_si128(_mm256_extracti128_si256(z##D, 1),            \+                           _mm_loadu_si128((const __m128i*) (m + 448))); \+        _mm_storeu_si128((__m128i*) (c + 448), t3);                      \+    }++#define ONEQUAD(A, B, C, D) ONEQUAD_TRANSPOSE(A, B, C, D)++#define ONEQUAD_UNPCK(A, B, C, D)                 \+    {                                             \+        z##A = _mm256_add_epi32(z##A, orig##A);   \+        z##B = _mm256_add_epi32(z##B, orig##B);   \+        z##C = _mm256_add_epi32(z##C, orig##C);   \+        z##D = _mm256_add_epi32(z##D, orig##D);   \+        y##A = _mm256_unpacklo_epi32(z##A, z##B); \+        y##B = _mm256_unpacklo_epi32(z##C, z##D); \+        y##C = _mm256_unpackhi_epi32(z##A, z##B); \+        y##D = _mm256_unpackhi_epi32(z##C, z##D); \+        z##A = _mm256_unpacklo_epi64(y##A, y##B); \+        z##B = _mm256_unpackhi_epi64(y##A, y##B); \+        z##C = _mm256_unpacklo_epi64(y##C, y##D); \+        z##D = _mm256_unpackhi_epi64(y##C, y##D); \+    }++#define ONEOCTO(A, B, C, D, A2, B2, C2, D2)                                    \+    {                                                                          \+        ONEQUAD_UNPCK(A, B, C, D);                                             \+        ONEQUAD_UNPCK(A2, B2, C2, D2);                                         \+        y##A  = _mm256_permute2x128_si256(z##A, z##A2, 0x20);                  \+        y##A2 = _mm256_permute2x128_si256(z##A, z##A2, 0x31);                  \+        y##B  = _mm256_permute2x128_si256(z##B, z##B2, 0x20);                  \+        y##B2 = _mm256_permute2x128_si256(z##B, z##B2, 0x31);                  \+        y##C  = _mm256_permute2x128_si256(z##C, z##C2, 0x20);                  \+        y##C2 = _mm256_permute2x128_si256(z##C, z##C2, 0x31);                  \+        y##D  = _mm256_permute2x128_si256(z##D, z##D2, 0x20);                  \+        y##D2 = _mm256_permute2x128_si256(z##D, z##D2, 0x31);                  \+        y##A  = _mm256_xor_si256(y##A,                                         \+                                _mm256_loadu_si256((const __m256i*) (m + 0))); \+        y##B  = _mm256_xor_si256(                                              \+            y##B, _mm256_loadu_si256((const __m256i*) (m + 64)));              \+        y##C = _mm256_xor_si256(                                               \+            y##C, _mm256_loadu_si256((const __m256i*) (m + 128)));             \+        y##D = _mm256_xor_si256(                                               \+            y##D, _mm256_loadu_si256((const __m256i*) (m + 192)));             \+        y##A2 = _mm256_xor_si256(                                              \+            y##A2, _mm256_loadu_si256((const __m256i*) (m + 256)));            \+        y##B2 = _mm256_xor_si256(                                              \+            y##B2, _mm256_loadu_si256((const __m256i*) (m + 320)));            \+        y##C2 = _mm256_xor_si256(                                              \+            y##C2, _mm256_loadu_si256((const __m256i*) (m + 384)));            \+        y##D2 = _mm256_xor_si256(                                              \+            y##D2, _mm256_loadu_si256((const __m256i*) (m + 448)));            \+        _mm256_storeu_si256((__m256i*) (c + 0), y##A);                         \+        _mm256_storeu_si256((__m256i*) (c + 64), y##B);                        \+        _mm256_storeu_si256((__m256i*) (c + 128), y##C);                       \+        _mm256_storeu_si256((__m256i*) (c + 192), y##D);                       \+        _mm256_storeu_si256((__m256i*) (c + 256), y##A2);                      \+        _mm256_storeu_si256((__m256i*) (c + 320), y##B2);                      \+        _mm256_storeu_si256((__m256i*) (c + 384), y##C2);                      \+        _mm256_storeu_si256((__m256i*) (c + 448), y##D2);                      \+    }++        ONEOCTO(0, 1, 2, 3, 4, 5, 6, 7);+        m += 32;+        c += 32;+        ONEOCTO(8, 9, 10, 11, 12, 13, 14, 15);+        m -= 32;+        c -= 32;++#undef ONEQUAD+#undef ONEQUAD_TRANSPOSE+#undef ONEQUAD_UNPCK+#undef ONEOCTO++        bytes -= 512;+        c += 512;+        m += 512;+    }+}
+ vendor/external/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012_ref.c view
@@ -0,0 +1,106 @@+/*+version 20140420+D. J. Bernstein+Public domain.+*/++#include <stdint.h>++#include "crypto_core_salsa2012.h"+#include "crypto_stream_salsa2012.h"+#include "utils.h"++int+crypto_stream_salsa2012(unsigned char *c, unsigned long long clen,+                        const unsigned char *n, const unsigned char *k)+{+    unsigned char in[16];+    unsigned char block[64];+    unsigned char kcopy[32];+    unsigned int  i;+    unsigned int  u;++    if (!clen) {+        return 0;+    }+    for (i = 0; i < 32; ++i) {+        kcopy[i] = k[i];+    }+    for (i = 0; i < 8; ++i) {+        in[i] = n[i];+    }+    for (i = 8; i < 16; ++i) {+        in[i] = 0;+    }+    while (clen >= 64) {+        crypto_core_salsa2012(c, in, kcopy, NULL);+        u = 1;+        for (i = 8; i < 16; ++i) {+            u += (unsigned int)in[i];+            in[i] = u;+            u >>= 8;+        }+        clen -= 64;+        c += 64;+    }+    if (clen) {+        crypto_core_salsa2012(block, in, kcopy, NULL);+        for (i = 0; i < (unsigned int)clen; ++i) {+            c[i] = block[i];+        }+    }+    sodium_memzero(block, sizeof block);+    sodium_memzero(kcopy, sizeof kcopy);++    return 0;+}++int+crypto_stream_salsa2012_xor(unsigned char *c, const unsigned char *m,+                            unsigned long long mlen, const unsigned char *n,+                            const unsigned char *k)+{+    unsigned char in[16];+    unsigned char block[64];+    unsigned char kcopy[32];+    unsigned int  i;+    unsigned int  u;++    if (!mlen) {+        return 0;+    }+    for (i = 0; i < 32; ++i) {+        kcopy[i] = k[i];+    }+    for (i = 0; i < 8; ++i) {+        in[i] = n[i];+    }+    for (i = 8; i < 16; ++i) {+        in[i] = 0;+    }+    while (mlen >= 64) {+        crypto_core_salsa2012(block, in, kcopy, NULL);+        for (i = 0; i < 64; ++i) {+            c[i] = m[i] ^ block[i];+        }+        u = 1;+        for (i = 8; i < 16; ++i) {+            u += (unsigned int)in[i];+            in[i] = u;+            u >>= 8;+        }+        mlen -= 64;+        c += 64;+        m += 64;+    }+    if (mlen) {+        crypto_core_salsa2012(block, in, kcopy, NULL);+        for (i = 0; i < (unsigned int)mlen; ++i) {+            c[i] = m[i] ^ block[i];+        }+    }+    sodium_memzero(block, sizeof block);+    sodium_memzero(kcopy, sizeof kcopy);++    return 0;+}
+ vendor/external/libsodium/crypto_stream/salsa2012/stream_salsa2012.c view
@@ -0,0 +1,26 @@+#include "crypto_stream_salsa2012.h"+#include "randombytes.h"++size_t+crypto_stream_salsa2012_keybytes(void)+{+    return crypto_stream_salsa2012_KEYBYTES;+}++size_t+crypto_stream_salsa2012_noncebytes(void)+{+    return crypto_stream_salsa2012_NONCEBYTES;+}++size_t+crypto_stream_salsa2012_messagebytes_max(void)+{+    return crypto_stream_salsa2012_MESSAGEBYTES_MAX;+}++void+crypto_stream_salsa2012_keygen(unsigned char k[crypto_stream_salsa2012_KEYBYTES])+{+    randombytes_buf(k, crypto_stream_salsa2012_KEYBYTES);+}
+ vendor/external/libsodium/crypto_stream/salsa208/ref/stream_salsa208_ref.c view
@@ -0,0 +1,106 @@+/*+version 20140420+D. J. Bernstein+Public domain.+*/++#include <stdint.h>++#include "crypto_core_salsa208.h"+#include "crypto_stream_salsa208.h"+#include "utils.h"++int+crypto_stream_salsa208(unsigned char *c, unsigned long long clen,+                       const unsigned char *n, const unsigned char *k)+{+    unsigned char in[16];+    unsigned char block[64];+    unsigned char kcopy[32];+    unsigned int  i;+    unsigned int  u;++    if (!clen) {+        return 0;+    }+    for (i = 0; i < 32; ++i) {+        kcopy[i] = k[i];+    }+    for (i = 0; i < 8; ++i) {+        in[i] = n[i];+    }+    for (i = 8; i < 16; ++i) {+        in[i] = 0;+    }+    while (clen >= 64) {+        crypto_core_salsa208(c, in, kcopy, NULL);+        u = 1;+        for (i = 8; i < 16; ++i) {+            u += (unsigned int)in[i];+            in[i] = u;+            u >>= 8;+        }+        clen -= 64;+        c += 64;+    }+    if (clen) {+        crypto_core_salsa208(block, in, kcopy, NULL);+        for (i = 0; i < (unsigned int)clen; ++i) {+            c[i] = block[i];+        }+    }+    sodium_memzero(block, sizeof block);+    sodium_memzero(kcopy, sizeof kcopy);++    return 0;+}++int+crypto_stream_salsa208_xor(unsigned char *c, const unsigned char *m,+                           unsigned long long mlen, const unsigned char *n,+                           const unsigned char *k)+{+    unsigned char in[16];+    unsigned char block[64];+    unsigned char kcopy[32];+    unsigned int  i;+    unsigned int  u;++    if (!mlen) {+        return 0;+    }+    for (i = 0; i < 32; ++i) {+        kcopy[i] = k[i];+    }+    for (i = 0; i < 8; ++i) {+        in[i] = n[i];+    }+    for (i = 8; i < 16; ++i) {+        in[i] = 0;+    }+    while (mlen >= 64) {+        crypto_core_salsa208(block, in, kcopy, NULL);+        for (i = 0; i < 64; ++i) {+            c[i] = m[i] ^ block[i];+        }+        u = 1;+        for (i = 8; i < 16; ++i) {+            u += (unsigned int)in[i];+            in[i] = u;+            u >>= 8;+        }+        mlen -= 64;+        c += 64;+        m += 64;+    }+    if (mlen) {+        crypto_core_salsa208(block, in, kcopy, NULL);+        for (i = 0; i < (unsigned int)mlen; ++i) {+            c[i] = m[i] ^ block[i];+        }+    }+    sodium_memzero(block, sizeof block);+    sodium_memzero(kcopy, sizeof kcopy);++    return 0;+}
+ vendor/external/libsodium/crypto_stream/salsa208/stream_salsa208.c view
@@ -0,0 +1,26 @@+#include "crypto_stream_salsa208.h"+#include "randombytes.h"++size_t+crypto_stream_salsa208_keybytes(void)+{+    return crypto_stream_salsa208_KEYBYTES;+}++size_t+crypto_stream_salsa208_noncebytes(void)+{+    return crypto_stream_salsa208_NONCEBYTES;+}++size_t+crypto_stream_salsa208_messagebytes_max(void)+{+    return crypto_stream_salsa208_MESSAGEBYTES_MAX;+}++void+crypto_stream_salsa208_keygen(unsigned char k[crypto_stream_salsa208_KEYBYTES])+{+    randombytes_buf(k, crypto_stream_salsa208_KEYBYTES);+}
+ vendor/external/libsodium/crypto_stream/xchacha20/stream_xchacha20.c view
@@ -0,0 +1,69 @@++#include <stdlib.h>++#include "crypto_core_hchacha20.h"+#include "crypto_stream_chacha20.h"+#include "crypto_stream_xchacha20.h"+#include "private/common.h"+#include "randombytes.h"++size_t+crypto_stream_xchacha20_keybytes(void)+{+    return crypto_stream_xchacha20_KEYBYTES;+}++size_t+crypto_stream_xchacha20_noncebytes(void)+{+    return crypto_stream_xchacha20_NONCEBYTES;+}++size_t+crypto_stream_xchacha20_messagebytes_max(void)+{+    return crypto_stream_xchacha20_MESSAGEBYTES_MAX;+}++int+crypto_stream_xchacha20(unsigned char *c, unsigned long long clen,+                        const unsigned char *n, const unsigned char *k)+{+    unsigned char k2[crypto_core_hchacha20_OUTPUTBYTES];++    crypto_core_hchacha20(k2, n, k, NULL);+    COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES <= sizeof k2);+    COMPILER_ASSERT(crypto_stream_chacha20_NONCEBYTES ==+                    crypto_stream_xchacha20_NONCEBYTES -+                        crypto_core_hchacha20_INPUTBYTES);++    return crypto_stream_chacha20(c, clen, n + crypto_core_hchacha20_INPUTBYTES,+                                  k2);+}++int+crypto_stream_xchacha20_xor_ic(unsigned char *c, const unsigned char *m,+                               unsigned long long mlen, const unsigned char *n,+                               uint64_t ic, const unsigned char *k)+{+    unsigned char k2[crypto_core_hchacha20_OUTPUTBYTES];++    crypto_core_hchacha20(k2, n, k, NULL);+    return crypto_stream_chacha20_xor_ic(+        c, m, mlen, n + crypto_core_hchacha20_INPUTBYTES, ic, k2);+}++int+crypto_stream_xchacha20_xor(unsigned char *c, const unsigned char *m,+                            unsigned long long mlen, const unsigned char *n,+                            const unsigned char *k)+{+    return crypto_stream_xchacha20_xor_ic(c, m, mlen, n, 0U, k);+}++void+crypto_stream_xchacha20_keygen(+    unsigned char k[crypto_stream_xchacha20_KEYBYTES])+{+    randombytes_buf(k, crypto_stream_xchacha20_KEYBYTES);+}
+ vendor/external/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c view
@@ -0,0 +1,66 @@+#include "crypto_core_hsalsa20.h"+#include "crypto_stream_salsa20.h"+#include "crypto_stream_xsalsa20.h"+#include "randombytes.h"+#include "utils.h"++int+crypto_stream_xsalsa20(unsigned char *c, unsigned long long clen,+                       const unsigned char *n, const unsigned char *k)+{+    unsigned char subkey[32];+    int           ret;++    crypto_core_hsalsa20(subkey, n, k, NULL);+    ret = crypto_stream_salsa20(c, clen, n + 16, subkey);+    sodium_memzero(subkey, sizeof subkey);++    return ret;+}++int+crypto_stream_xsalsa20_xor_ic(unsigned char *c, const unsigned char *m,+                              unsigned long long mlen, const unsigned char *n,+                              uint64_t ic, const unsigned char *k)+{+    unsigned char subkey[32];+    int           ret;++    crypto_core_hsalsa20(subkey, n, k, NULL);+    ret = crypto_stream_salsa20_xor_ic(c, m, mlen, n + 16, ic, subkey);+    sodium_memzero(subkey, sizeof subkey);++    return ret;+}++int+crypto_stream_xsalsa20_xor(unsigned char *c, const unsigned char *m,+                           unsigned long long mlen, const unsigned char *n,+                           const unsigned char *k)+{+    return crypto_stream_xsalsa20_xor_ic(c, m, mlen, n, 0ULL, k);+}++size_t+crypto_stream_xsalsa20_keybytes(void)+{+    return crypto_stream_xsalsa20_KEYBYTES;+}++size_t+crypto_stream_xsalsa20_noncebytes(void)+{+    return crypto_stream_xsalsa20_NONCEBYTES;+}++size_t+crypto_stream_xsalsa20_messagebytes_max(void)+{+    return crypto_stream_xsalsa20_MESSAGEBYTES_MAX;+}++void+crypto_stream_xsalsa20_keygen(unsigned char k[crypto_stream_xsalsa20_KEYBYTES])+{+    randombytes_buf(k, crypto_stream_xsalsa20_KEYBYTES);+}
+ vendor/external/libsodium/crypto_verify/verify.c view
@@ -0,0 +1,98 @@++#include <stddef.h>+#include <stdint.h>++#include "crypto_verify_16.h"+#include "crypto_verify_32.h"+#include "crypto_verify_64.h"++size_t+crypto_verify_16_bytes(void)+{+    return crypto_verify_16_BYTES;+}++size_t+crypto_verify_32_bytes(void)+{+    return crypto_verify_32_BYTES;+}++size_t+crypto_verify_64_bytes(void)+{+    return crypto_verify_64_BYTES;+}++#if defined(HAVE_EMMINTRIN_H) && defined(__SSE2__)++# ifdef __GNUC__+#  pragma GCC target("sse2")+# endif+# include <emmintrin.h>++static inline int+crypto_verify_n(const unsigned char *x_, const unsigned char *y_,+                const int n)+{+    const    __m128i zero = _mm_setzero_si128();+    volatile __m128i v1, v2, z;+    volatile int     m;+    int              i;++    const volatile __m128i *volatile x =+        (const volatile __m128i *volatile) (const void *) x_;+    const volatile __m128i *volatile y =+        (const volatile __m128i *volatile) (const void *) y_;+    v1 = _mm_loadu_si128((const __m128i *) &x[0]);+    v2 = _mm_loadu_si128((const __m128i *) &y[0]);+    z = _mm_xor_si128(v1, v2);+    for (i = 1; i < n / 16; i++) {+        v1 = _mm_loadu_si128((const __m128i *) &x[i]);+        v2 = _mm_loadu_si128((const __m128i *) &y[i]);+        z = _mm_or_si128(z, _mm_xor_si128(v1, v2));+    }+    m = _mm_movemask_epi8(_mm_cmpeq_epi32(z, zero));+    v1 = zero; v2 = zero; z = zero;++    return (int) (((uint32_t) m + 1U) >> 16) - 1;+}++#else++static inline int+crypto_verify_n(const unsigned char *x_, const unsigned char *y_,+                const int n)+{+    const volatile unsigned char *volatile x =+        (const volatile unsigned char *volatile) x_;+    const volatile unsigned char *volatile y =+        (const volatile unsigned char *volatile) y_;+    volatile uint_fast16_t d = 0U;+    int i;++    for (i = 0; i < n; i++) {+        d |= x[i] ^ y[i];+    }+    return (1 & ((d - 1) >> 8)) - 1;+}++#endif++int+crypto_verify_16(const unsigned char *x, const unsigned char *y)+{+    return crypto_verify_n(x, y, crypto_verify_16_BYTES);+}++int+crypto_verify_32(const unsigned char *x, const unsigned char *y)+{+    return crypto_verify_n(x, y, crypto_verify_32_BYTES);+}++int+crypto_verify_64(const unsigned char *x, const unsigned char *y)+{+    return crypto_verify_n(x, y, crypto_verify_64_BYTES);+}
+ vendor/external/libsodium/include/sodium.h view
@@ -0,0 +1,73 @@++#ifndef sodium_H+#define sodium_H++#include "sodium/version.h"++#include "external/libsodium/include/sodium/core.h"+#include "external/libsodium/include/sodium/crypto_aead_aegis128l.h"+#include "external/libsodium/include/sodium/crypto_aead_aegis256.h"+#include "external/libsodium/include/sodium/crypto_aead_aes256gcm.h"+#include "external/libsodium/include/sodium/crypto_aead_chacha20poly1305.h"+#include "external/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h"+#include "external/libsodium/include/sodium/crypto_auth.h"+#include "external/libsodium/include/sodium/crypto_auth_hmacsha256.h"+#include "external/libsodium/include/sodium/crypto_auth_hmacsha512.h"+#include "external/libsodium/include/sodium/crypto_auth_hmacsha512256.h"+#include "external/libsodium/include/sodium/crypto_box.h"+#include "external/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h"+#include "external/libsodium/include/sodium/crypto_core_hchacha20.h"+#include "external/libsodium/include/sodium/crypto_core_hsalsa20.h"+#include "external/libsodium/include/sodium/crypto_core_salsa20.h"+#include "external/libsodium/include/sodium/crypto_core_salsa2012.h"+#include "external/libsodium/include/sodium/crypto_core_salsa208.h"+#include "external/libsodium/include/sodium/crypto_generichash.h"+#include "external/libsodium/include/sodium/crypto_generichash_blake2b.h"+#include "external/libsodium/include/sodium/crypto_hash.h"+#include "external/libsodium/include/sodium/crypto_hash_sha256.h"+#include "external/libsodium/include/sodium/crypto_hash_sha512.h"+#include "external/libsodium/include/sodium/crypto_kdf.h"+#include "external/libsodium/include/sodium/crypto_kdf_blake2b.h"+#include "external/libsodium/include/sodium/crypto_kdf_hkdf_sha256.h"+#include "external/libsodium/include/sodium/crypto_kdf_hkdf_sha512.h"+#include "external/libsodium/include/sodium/crypto_kx.h"+#include "external/libsodium/include/sodium/crypto_onetimeauth.h"+#include "external/libsodium/include/sodium/crypto_onetimeauth_poly1305.h"+#include "external/libsodium/include/sodium/crypto_pwhash.h"+#include "external/libsodium/include/sodium/crypto_pwhash_argon2i.h"+#include "external/libsodium/include/sodium/crypto_scalarmult.h"+#include "external/libsodium/include/sodium/crypto_scalarmult_curve25519.h"+#include "external/libsodium/include/sodium/crypto_secretbox.h"+#include "external/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h"+#include "external/libsodium/include/sodium/crypto_secretstream_xchacha20poly1305.h"+#include "external/libsodium/include/sodium/crypto_shorthash.h"+#include "external/libsodium/include/sodium/crypto_shorthash_siphash24.h"+#include "external/libsodium/include/sodium/crypto_sign.h"+#include "external/libsodium/include/sodium/crypto_sign_ed25519.h"+#include "external/libsodium/include/sodium/crypto_stream.h"+#include "external/libsodium/include/sodium/crypto_stream_chacha20.h"+#include "external/libsodium/include/sodium/crypto_stream_salsa20.h"+#include "external/libsodium/include/sodium/crypto_stream_xsalsa20.h"+#include "external/libsodium/include/sodium/crypto_verify_16.h"+#include "external/libsodium/include/sodium/crypto_verify_32.h"+#include "external/libsodium/include/sodium/crypto_verify_64.h"+#include "external/libsodium/include/sodium/randombytes.h"+#include "external/libsodium/include/sodium/randombytes_internal_random.h"+#include "external/libsodium/include/sodium/randombytes_sysrandom.h"+#include "external/libsodium/include/sodium/runtime.h"+#include "external/libsodium/include/sodium/utils.h"++#ifndef SODIUM_LIBRARY_MINIMAL+#include "external/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h"+#include "external/libsodium/include/sodium/crypto_core_ed25519.h"+#include "external/libsodium/include/sodium/crypto_core_ristretto255.h"+#include "external/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h"+#include "external/libsodium/include/sodium/crypto_scalarmult_ed25519.h"+#include "external/libsodium/include/sodium/crypto_scalarmult_ristretto255.h"+#include "external/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h"+#include "external/libsodium/include/sodium/crypto_stream_salsa2012.h"+#include "external/libsodium/include/sodium/crypto_stream_salsa208.h"+#include "external/libsodium/include/sodium/crypto_stream_xchacha20.h"+#endif++#endif
+ vendor/external/libsodium/include/sodium/core.h view
@@ -0,0 +1,28 @@++#ifndef sodium_core_H+#define sodium_core_H++#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++SODIUM_EXPORT+int sodium_init(void)+            __attribute__ ((warn_unused_result));++/* ---- */++SODIUM_EXPORT+int sodium_set_misuse_handler(void (*handler)(void));++SODIUM_EXPORT+void sodium_misuse(void)+            __attribute__ ((noreturn));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_aead_aegis128l.h view
@@ -0,0 +1,92 @@+#ifndef crypto_aead_aegis128l_H+#define crypto_aead_aegis128l_H++#include <stddef.h>++#include "export.h"++#ifdef __cplusplus+#ifdef __GNUC__+#pragma GCC diagnostic ignored "-Wlong-long"+#endif+extern "C" {+#endif++#define crypto_aead_aegis128l_KEYBYTES 16U+SODIUM_EXPORT+size_t crypto_aead_aegis128l_keybytes(void);++#define crypto_aead_aegis128l_NSECBYTES 0U+SODIUM_EXPORT+size_t crypto_aead_aegis128l_nsecbytes(void);++#define crypto_aead_aegis128l_NPUBBYTES 16U+SODIUM_EXPORT+size_t crypto_aead_aegis128l_npubbytes(void);++#define crypto_aead_aegis128l_ABYTES 32U+SODIUM_EXPORT+size_t crypto_aead_aegis128l_abytes(void);++#define crypto_aead_aegis128l_MESSAGEBYTES_MAX \+    SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_aegis128l_ABYTES, (1ULL << 61) - 1)+SODIUM_EXPORT+size_t crypto_aead_aegis128l_messagebytes_max(void);++SODIUM_EXPORT+int crypto_aead_aegis128l_encrypt(unsigned char       *c,+                                  unsigned long long  *clen_p,+                                  const unsigned char *m,+                                  unsigned long long   mlen,+                                  const unsigned char *ad,+                                  unsigned long long   adlen,+                                  const unsigned char *nsec,+                                  const unsigned char *npub,+                                  const unsigned char *k) __attribute__((nonnull(1, 8, 9)));++SODIUM_EXPORT+int crypto_aead_aegis128l_decrypt(unsigned char       *m,+                                  unsigned long long  *mlen_p,+                                  unsigned char       *nsec,+                                  const unsigned char *c,+                                  unsigned long long   clen,+                                  const unsigned char *ad,+                                  unsigned long long   adlen,+                                  const unsigned char *npub,+                                  const unsigned char *k) __attribute__((warn_unused_result))+__attribute__((nonnull(4, 8, 9)));++SODIUM_EXPORT+int crypto_aead_aegis128l_encrypt_detached(unsigned char       *c,+                                           unsigned char       *mac,+                                           unsigned long long  *maclen_p,+                                           const unsigned char *m,+                                           unsigned long long   mlen,+                                           const unsigned char *ad,+                                           unsigned long long   adlen,+                                           const unsigned char *nsec,+                                           const unsigned char *npub,+                                           const unsigned char *k)+    __attribute__((nonnull(1, 2, 9, 10)));++SODIUM_EXPORT+int crypto_aead_aegis128l_decrypt_detached(unsigned char       *m,+                                           unsigned char       *nsec,+                                           const unsigned char *c,+                                           unsigned long long   clen,+                                           const unsigned char *mac,+                                           const unsigned char *ad,+                                           unsigned long long   adlen,+                                           const unsigned char *npub,+                                           const unsigned char *k)+    __attribute__((warn_unused_result)) __attribute__((nonnull(3, 5, 8, 9)));++SODIUM_EXPORT+void crypto_aead_aegis128l_keygen(unsigned char k[crypto_aead_aegis128l_KEYBYTES])+    __attribute__((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_aead_aegis256.h view
@@ -0,0 +1,92 @@+#ifndef crypto_aead_aegis256_H+#define crypto_aead_aegis256_H++#include <stddef.h>++#include "export.h"++#ifdef __cplusplus+#ifdef __GNUC__+#pragma GCC diagnostic ignored "-Wlong-long"+#endif+extern "C" {+#endif++#define crypto_aead_aegis256_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_aead_aegis256_keybytes(void);++#define crypto_aead_aegis256_NSECBYTES 0U+SODIUM_EXPORT+size_t crypto_aead_aegis256_nsecbytes(void);++#define crypto_aead_aegis256_NPUBBYTES 32U+SODIUM_EXPORT+size_t crypto_aead_aegis256_npubbytes(void);++#define crypto_aead_aegis256_ABYTES 32U+SODIUM_EXPORT+size_t crypto_aead_aegis256_abytes(void);++#define crypto_aead_aegis256_MESSAGEBYTES_MAX \+    SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_aegis256_ABYTES, (1ULL << 61) - 1)+SODIUM_EXPORT+size_t crypto_aead_aegis256_messagebytes_max(void);++SODIUM_EXPORT+int crypto_aead_aegis256_encrypt(unsigned char       *c,+                                 unsigned long long  *clen_p,+                                 const unsigned char *m,+                                 unsigned long long   mlen,+                                 const unsigned char *ad,+                                 unsigned long long   adlen,+                                 const unsigned char *nsec,+                                 const unsigned char *npub,+                                 const unsigned char *k) __attribute__((nonnull(1, 8, 9)));++SODIUM_EXPORT+int crypto_aead_aegis256_decrypt(unsigned char       *m,+                                 unsigned long long  *mlen_p,+                                 unsigned char       *nsec,+                                 const unsigned char *c,+                                 unsigned long long   clen,+                                 const unsigned char *ad,+                                 unsigned long long   adlen,+                                 const unsigned char *npub,+                                 const unsigned char *k) __attribute__((warn_unused_result))+__attribute__((nonnull(4, 8, 9)));++SODIUM_EXPORT+int crypto_aead_aegis256_encrypt_detached(unsigned char       *c,+                                          unsigned char       *mac,+                                          unsigned long long  *maclen_p,+                                          const unsigned char *m,+                                          unsigned long long   mlen,+                                          const unsigned char *ad,+                                          unsigned long long   adlen,+                                          const unsigned char *nsec,+                                          const unsigned char *npub,+                                          const unsigned char *k)+    __attribute__((nonnull(1, 2, 9, 10)));++SODIUM_EXPORT+int crypto_aead_aegis256_decrypt_detached(unsigned char       *m,+                                          unsigned char       *nsec,+                                          const unsigned char *c,+                                          unsigned long long   clen,+                                          const unsigned char *mac,+                                          const unsigned char *ad,+                                          unsigned long long   adlen,+                                          const unsigned char *npub,+                                          const unsigned char *k)+    __attribute__((warn_unused_result)) __attribute__((nonnull(3, 5, 8, 9)));++SODIUM_EXPORT+void crypto_aead_aegis256_keygen(unsigned char k[crypto_aead_aegis256_KEYBYTES])+    __attribute__((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_aead_aes256gcm.h view
@@ -0,0 +1,179 @@+#ifndef crypto_aead_aes256gcm_H+#define crypto_aead_aes256gcm_H++/*+ * WARNING: Despite being the most popular AEAD construction due to its+ * use in TLS, safely using AES-GCM in a different context is tricky.+ *+ * No more than ~ 350 GB of input data should be encrypted with a given key.+ * This is for ~ 16 KB messages -- Actual figures vary according to+ * message sizes.+ *+ * In addition, nonces are short and repeated nonces would totally destroy+ * the security of this scheme.+ *+ * Nonces should thus come from atomic counters, which can be difficult to+ * set up in a distributed environment.+ *+ * Unless you absolutely need AES-GCM, use crypto_aead_xchacha20poly1305_ietf_*()+ * instead. It doesn't have any of these limitations.+ * Or, if you don't need to authenticate additional data, just stick to+ * crypto_secretbox().+ */++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++SODIUM_EXPORT+int crypto_aead_aes256gcm_is_available(void);++#define crypto_aead_aes256gcm_KEYBYTES  32U+SODIUM_EXPORT+size_t crypto_aead_aes256gcm_keybytes(void);++#define crypto_aead_aes256gcm_NSECBYTES 0U+SODIUM_EXPORT+size_t crypto_aead_aes256gcm_nsecbytes(void);++#define crypto_aead_aes256gcm_NPUBBYTES 12U+SODIUM_EXPORT+size_t crypto_aead_aes256gcm_npubbytes(void);++#define crypto_aead_aes256gcm_ABYTES    16U+SODIUM_EXPORT+size_t crypto_aead_aes256gcm_abytes(void);++#define crypto_aead_aes256gcm_MESSAGEBYTES_MAX \+    SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_aes256gcm_ABYTES, \+               (16ULL * ((1ULL << 32) - 2ULL)))+SODIUM_EXPORT+size_t crypto_aead_aes256gcm_messagebytes_max(void);++typedef struct CRYPTO_ALIGN(16) crypto_aead_aes256gcm_state_ {+    unsigned char opaque[512];+} crypto_aead_aes256gcm_state;++SODIUM_EXPORT+size_t crypto_aead_aes256gcm_statebytes(void);++SODIUM_EXPORT+int crypto_aead_aes256gcm_encrypt(unsigned char *c,+                                  unsigned long long *clen_p,+                                  const unsigned char *m,+                                  unsigned long long mlen,+                                  const unsigned char *ad,+                                  unsigned long long adlen,+                                  const unsigned char *nsec,+                                  const unsigned char *npub,+                                  const unsigned char *k)+            __attribute__ ((nonnull(1, 8, 9)));++SODIUM_EXPORT+int crypto_aead_aes256gcm_decrypt(unsigned char *m,+                                  unsigned long long *mlen_p,+                                  unsigned char *nsec,+                                  const unsigned char *c,+                                  unsigned long long clen,+                                  const unsigned char *ad,+                                  unsigned long long adlen,+                                  const unsigned char *npub,+                                  const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));++SODIUM_EXPORT+int crypto_aead_aes256gcm_encrypt_detached(unsigned char *c,+                                           unsigned char *mac,+                                           unsigned long long *maclen_p,+                                           const unsigned char *m,+                                           unsigned long long mlen,+                                           const unsigned char *ad,+                                           unsigned long long adlen,+                                           const unsigned char *nsec,+                                           const unsigned char *npub,+                                           const unsigned char *k)+            __attribute__ ((nonnull(1, 2, 9, 10)));++SODIUM_EXPORT+int crypto_aead_aes256gcm_decrypt_detached(unsigned char *m,+                                           unsigned char *nsec,+                                           const unsigned char *c,+                                           unsigned long long clen,+                                           const unsigned char *mac,+                                           const unsigned char *ad,+                                           unsigned long long adlen,+                                           const unsigned char *npub,+                                           const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));++/* -- Precomputation interface -- */++SODIUM_EXPORT+int crypto_aead_aes256gcm_beforenm(crypto_aead_aes256gcm_state *ctx_,+                                   const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_aead_aes256gcm_encrypt_afternm(unsigned char *c,+                                          unsigned long long *clen_p,+                                          const unsigned char *m,+                                          unsigned long long mlen,+                                          const unsigned char *ad,+                                          unsigned long long adlen,+                                          const unsigned char *nsec,+                                          const unsigned char *npub,+                                          const crypto_aead_aes256gcm_state *ctx_)+            __attribute__ ((nonnull(1, 8, 9)));++SODIUM_EXPORT+int crypto_aead_aes256gcm_decrypt_afternm(unsigned char *m,+                                          unsigned long long *mlen_p,+                                          unsigned char *nsec,+                                          const unsigned char *c,+                                          unsigned long long clen,+                                          const unsigned char *ad,+                                          unsigned long long adlen,+                                          const unsigned char *npub,+                                          const crypto_aead_aes256gcm_state *ctx_)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));++SODIUM_EXPORT+int crypto_aead_aes256gcm_encrypt_detached_afternm(unsigned char *c,+                                                   unsigned char *mac,+                                                   unsigned long long *maclen_p,+                                                   const unsigned char *m,+                                                   unsigned long long mlen,+                                                   const unsigned char *ad,+                                                   unsigned long long adlen,+                                                   const unsigned char *nsec,+                                                   const unsigned char *npub,+                                                   const crypto_aead_aes256gcm_state *ctx_)+            __attribute__ ((nonnull(1, 2, 9, 10)));++SODIUM_EXPORT+int crypto_aead_aes256gcm_decrypt_detached_afternm(unsigned char *m,+                                                   unsigned char *nsec,+                                                   const unsigned char *c,+                                                   unsigned long long clen,+                                                   const unsigned char *mac,+                                                   const unsigned char *ad,+                                                   unsigned long long adlen,+                                                   const unsigned char *npub,+                                                   const crypto_aead_aes256gcm_state *ctx_)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));++SODIUM_EXPORT+void crypto_aead_aes256gcm_keygen(unsigned char k[crypto_aead_aes256gcm_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_aead_chacha20poly1305.h view
@@ -0,0 +1,180 @@+#ifndef crypto_aead_chacha20poly1305_H+#define crypto_aead_chacha20poly1305_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++/* -- IETF ChaCha20-Poly1305 construction with a 96-bit nonce and a 32-bit internal counter -- */++#define crypto_aead_chacha20poly1305_ietf_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_ietf_keybytes(void);++#define crypto_aead_chacha20poly1305_ietf_NSECBYTES 0U+SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_ietf_nsecbytes(void);++#define crypto_aead_chacha20poly1305_ietf_NPUBBYTES 12U++SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_ietf_npubbytes(void);++#define crypto_aead_chacha20poly1305_ietf_ABYTES 16U+SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_ietf_abytes(void);++#define crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX \+    SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_chacha20poly1305_ietf_ABYTES, \+               (64ULL * ((1ULL << 32) - 1ULL)))+SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_ietf_messagebytes_max(void);++SODIUM_EXPORT+int crypto_aead_chacha20poly1305_ietf_encrypt(unsigned char *c,+                                              unsigned long long *clen_p,+                                              const unsigned char *m,+                                              unsigned long long mlen,+                                              const unsigned char *ad,+                                              unsigned long long adlen,+                                              const unsigned char *nsec,+                                              const unsigned char *npub,+                                              const unsigned char *k)+            __attribute__ ((nonnull(1, 8, 9)));++SODIUM_EXPORT+int crypto_aead_chacha20poly1305_ietf_decrypt(unsigned char *m,+                                              unsigned long long *mlen_p,+                                              unsigned char *nsec,+                                              const unsigned char *c,+                                              unsigned long long clen,+                                              const unsigned char *ad,+                                              unsigned long long adlen,+                                              const unsigned char *npub,+                                              const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));++SODIUM_EXPORT+int crypto_aead_chacha20poly1305_ietf_encrypt_detached(unsigned char *c,+                                                       unsigned char *mac,+                                                       unsigned long long *maclen_p,+                                                       const unsigned char *m,+                                                       unsigned long long mlen,+                                                       const unsigned char *ad,+                                                       unsigned long long adlen,+                                                       const unsigned char *nsec,+                                                       const unsigned char *npub,+                                                       const unsigned char *k)+            __attribute__ ((nonnull(1, 2, 9, 10)));++SODIUM_EXPORT+int crypto_aead_chacha20poly1305_ietf_decrypt_detached(unsigned char *m,+                                                       unsigned char *nsec,+                                                       const unsigned char *c,+                                                       unsigned long long clen,+                                                       const unsigned char *mac,+                                                       const unsigned char *ad,+                                                       unsigned long long adlen,+                                                       const unsigned char *npub,+                                                       const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));++SODIUM_EXPORT+void crypto_aead_chacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_chacha20poly1305_ietf_KEYBYTES])+            __attribute__ ((nonnull));++/* -- Original ChaCha20-Poly1305 construction with a 64-bit nonce and a 64-bit internal counter -- */++#define crypto_aead_chacha20poly1305_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_keybytes(void);++#define crypto_aead_chacha20poly1305_NSECBYTES 0U+SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_nsecbytes(void);++#define crypto_aead_chacha20poly1305_NPUBBYTES 8U+SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_npubbytes(void);++#define crypto_aead_chacha20poly1305_ABYTES 16U+SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_abytes(void);++#define crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX \+    (SODIUM_SIZE_MAX - crypto_aead_chacha20poly1305_ABYTES)+SODIUM_EXPORT+size_t crypto_aead_chacha20poly1305_messagebytes_max(void);++SODIUM_EXPORT+int crypto_aead_chacha20poly1305_encrypt(unsigned char *c,+                                         unsigned long long *clen_p,+                                         const unsigned char *m,+                                         unsigned long long mlen,+                                         const unsigned char *ad,+                                         unsigned long long adlen,+                                         const unsigned char *nsec,+                                         const unsigned char *npub,+                                         const unsigned char *k)+            __attribute__ ((nonnull(1, 8, 9)));++SODIUM_EXPORT+int crypto_aead_chacha20poly1305_decrypt(unsigned char *m,+                                         unsigned long long *mlen_p,+                                         unsigned char *nsec,+                                         const unsigned char *c,+                                         unsigned long long clen,+                                         const unsigned char *ad,+                                         unsigned long long adlen,+                                         const unsigned char *npub,+                                         const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));++SODIUM_EXPORT+int crypto_aead_chacha20poly1305_encrypt_detached(unsigned char *c,+                                                  unsigned char *mac,+                                                  unsigned long long *maclen_p,+                                                  const unsigned char *m,+                                                  unsigned long long mlen,+                                                  const unsigned char *ad,+                                                  unsigned long long adlen,+                                                  const unsigned char *nsec,+                                                  const unsigned char *npub,+                                                  const unsigned char *k)+            __attribute__ ((nonnull(1, 2, 9, 10)));++SODIUM_EXPORT+int crypto_aead_chacha20poly1305_decrypt_detached(unsigned char *m,+                                                  unsigned char *nsec,+                                                  const unsigned char *c,+                                                  unsigned long long clen,+                                                  const unsigned char *mac,+                                                  const unsigned char *ad,+                                                  unsigned long long adlen,+                                                  const unsigned char *npub,+                                                  const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));++SODIUM_EXPORT+void crypto_aead_chacha20poly1305_keygen(unsigned char k[crypto_aead_chacha20poly1305_KEYBYTES])+            __attribute__ ((nonnull));++/* Aliases */++#define crypto_aead_chacha20poly1305_IETF_KEYBYTES         crypto_aead_chacha20poly1305_ietf_KEYBYTES+#define crypto_aead_chacha20poly1305_IETF_NSECBYTES        crypto_aead_chacha20poly1305_ietf_NSECBYTES+#define crypto_aead_chacha20poly1305_IETF_NPUBBYTES        crypto_aead_chacha20poly1305_ietf_NPUBBYTES+#define crypto_aead_chacha20poly1305_IETF_ABYTES           crypto_aead_chacha20poly1305_ietf_ABYTES+#define crypto_aead_chacha20poly1305_IETF_MESSAGEBYTES_MAX crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h view
@@ -0,0 +1,100 @@+#ifndef crypto_aead_xchacha20poly1305_H+#define crypto_aead_xchacha20poly1305_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_aead_xchacha20poly1305_ietf_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_aead_xchacha20poly1305_ietf_keybytes(void);++#define crypto_aead_xchacha20poly1305_ietf_NSECBYTES 0U+SODIUM_EXPORT+size_t crypto_aead_xchacha20poly1305_ietf_nsecbytes(void);++#define crypto_aead_xchacha20poly1305_ietf_NPUBBYTES 24U+SODIUM_EXPORT+size_t crypto_aead_xchacha20poly1305_ietf_npubbytes(void);++#define crypto_aead_xchacha20poly1305_ietf_ABYTES 16U+SODIUM_EXPORT+size_t crypto_aead_xchacha20poly1305_ietf_abytes(void);++#define crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX \+    (SODIUM_SIZE_MAX - crypto_aead_xchacha20poly1305_ietf_ABYTES)+SODIUM_EXPORT+size_t crypto_aead_xchacha20poly1305_ietf_messagebytes_max(void);++SODIUM_EXPORT+int crypto_aead_xchacha20poly1305_ietf_encrypt(unsigned char *c,+                                               unsigned long long *clen_p,+                                               const unsigned char *m,+                                               unsigned long long mlen,+                                               const unsigned char *ad,+                                               unsigned long long adlen,+                                               const unsigned char *nsec,+                                               const unsigned char *npub,+                                               const unsigned char *k)+            __attribute__ ((nonnull(1, 8, 9)));++SODIUM_EXPORT+int crypto_aead_xchacha20poly1305_ietf_decrypt(unsigned char *m,+                                               unsigned long long *mlen_p,+                                               unsigned char *nsec,+                                               const unsigned char *c,+                                               unsigned long long clen,+                                               const unsigned char *ad,+                                               unsigned long long adlen,+                                               const unsigned char *npub,+                                               const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));++SODIUM_EXPORT+int crypto_aead_xchacha20poly1305_ietf_encrypt_detached(unsigned char *c,+                                                        unsigned char *mac,+                                                        unsigned long long *maclen_p,+                                                        const unsigned char *m,+                                                        unsigned long long mlen,+                                                        const unsigned char *ad,+                                                        unsigned long long adlen,+                                                        const unsigned char *nsec,+                                                        const unsigned char *npub,+                                                        const unsigned char *k)+            __attribute__ ((nonnull(1, 2, 9, 10)));++SODIUM_EXPORT+int crypto_aead_xchacha20poly1305_ietf_decrypt_detached(unsigned char *m,+                                                        unsigned char *nsec,+                                                        const unsigned char *c,+                                                        unsigned long long clen,+                                                        const unsigned char *mac,+                                                        const unsigned char *ad,+                                                        unsigned long long adlen,+                                                        const unsigned char *npub,+                                                        const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));++SODIUM_EXPORT+void crypto_aead_xchacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES])+            __attribute__ ((nonnull));++/* Aliases */++#define crypto_aead_xchacha20poly1305_IETF_KEYBYTES         crypto_aead_xchacha20poly1305_ietf_KEYBYTES+#define crypto_aead_xchacha20poly1305_IETF_NSECBYTES        crypto_aead_xchacha20poly1305_ietf_NSECBYTES+#define crypto_aead_xchacha20poly1305_IETF_NPUBBYTES        crypto_aead_xchacha20poly1305_ietf_NPUBBYTES+#define crypto_aead_xchacha20poly1305_IETF_ABYTES           crypto_aead_xchacha20poly1305_ietf_ABYTES+#define crypto_aead_xchacha20poly1305_IETF_MESSAGEBYTES_MAX crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_auth.h view
@@ -0,0 +1,46 @@+#ifndef crypto_auth_H+#define crypto_auth_H++#include <stddef.h>++#include "crypto_auth_hmacsha512256.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_auth_BYTES crypto_auth_hmacsha512256_BYTES+SODIUM_EXPORT+size_t  crypto_auth_bytes(void);++#define crypto_auth_KEYBYTES crypto_auth_hmacsha512256_KEYBYTES+SODIUM_EXPORT+size_t  crypto_auth_keybytes(void);++#define crypto_auth_PRIMITIVE "hmacsha512256"+SODIUM_EXPORT+const char *crypto_auth_primitive(void);++SODIUM_EXPORT+int crypto_auth(unsigned char *out, const unsigned char *in,+                unsigned long long inlen, const unsigned char *k)+            __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_auth_verify(const unsigned char *h, const unsigned char *in,+                       unsigned long long inlen, const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_auth_hmacsha256.h view
@@ -0,0 +1,70 @@+#ifndef crypto_auth_hmacsha256_H+#define crypto_auth_hmacsha256_H++#include <stddef.h>+#include "crypto_hash_sha256.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_auth_hmacsha256_BYTES 32U+SODIUM_EXPORT+size_t crypto_auth_hmacsha256_bytes(void);++#define crypto_auth_hmacsha256_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_auth_hmacsha256_keybytes(void);++SODIUM_EXPORT+int crypto_auth_hmacsha256(unsigned char *out,+                           const unsigned char *in,+                           unsigned long long inlen,+                           const unsigned char *k) __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_auth_hmacsha256_verify(const unsigned char *h,+                                  const unsigned char *in,+                                  unsigned long long inlen,+                                  const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));++/* ------------------------------------------------------------------------- */++typedef struct crypto_auth_hmacsha256_state {+    crypto_hash_sha256_state ictx;+    crypto_hash_sha256_state octx;+} crypto_auth_hmacsha256_state;++SODIUM_EXPORT+size_t crypto_auth_hmacsha256_statebytes(void);++SODIUM_EXPORT+int crypto_auth_hmacsha256_init(crypto_auth_hmacsha256_state *state,+                                const unsigned char *key,+                                size_t keylen) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_auth_hmacsha256_update(crypto_auth_hmacsha256_state *state,+                                  const unsigned char *in,+                                  unsigned long long inlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_auth_hmacsha256_final(crypto_auth_hmacsha256_state *state,+                                 unsigned char *out) __attribute__ ((nonnull));+++SODIUM_EXPORT+void crypto_auth_hmacsha256_keygen(unsigned char k[crypto_auth_hmacsha256_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_auth_hmacsha512.h view
@@ -0,0 +1,68 @@+#ifndef crypto_auth_hmacsha512_H+#define crypto_auth_hmacsha512_H++#include <stddef.h>+#include "crypto_hash_sha512.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_auth_hmacsha512_BYTES 64U+SODIUM_EXPORT+size_t crypto_auth_hmacsha512_bytes(void);++#define crypto_auth_hmacsha512_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_auth_hmacsha512_keybytes(void);++SODIUM_EXPORT+int crypto_auth_hmacsha512(unsigned char *out,+                           const unsigned char *in,+                           unsigned long long inlen,+                           const unsigned char *k) __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_auth_hmacsha512_verify(const unsigned char *h,+                                  const unsigned char *in,+                                  unsigned long long inlen,+                                  const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));++/* ------------------------------------------------------------------------- */++typedef struct crypto_auth_hmacsha512_state {+    crypto_hash_sha512_state ictx;+    crypto_hash_sha512_state octx;+} crypto_auth_hmacsha512_state;++SODIUM_EXPORT+size_t crypto_auth_hmacsha512_statebytes(void);++SODIUM_EXPORT+int crypto_auth_hmacsha512_init(crypto_auth_hmacsha512_state *state,+                                const unsigned char *key,+                                size_t keylen) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_auth_hmacsha512_update(crypto_auth_hmacsha512_state *state,+                                  const unsigned char *in,+                                  unsigned long long inlen) __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_auth_hmacsha512_final(crypto_auth_hmacsha512_state *state,+                                 unsigned char *out) __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_auth_hmacsha512_keygen(unsigned char k[crypto_auth_hmacsha512_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_auth_hmacsha512256.h view
@@ -0,0 +1,65 @@+#ifndef crypto_auth_hmacsha512256_H+#define crypto_auth_hmacsha512256_H++#include <stddef.h>+#include "crypto_auth_hmacsha512.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_auth_hmacsha512256_BYTES 32U+SODIUM_EXPORT+size_t crypto_auth_hmacsha512256_bytes(void);++#define crypto_auth_hmacsha512256_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_auth_hmacsha512256_keybytes(void);++SODIUM_EXPORT+int crypto_auth_hmacsha512256(unsigned char *out,+                              const unsigned char *in,+                              unsigned long long inlen,+                              const unsigned char *k) __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_auth_hmacsha512256_verify(const unsigned char *h,+                                     const unsigned char *in,+                                     unsigned long long inlen,+                                     const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));++/* ------------------------------------------------------------------------- */++typedef crypto_auth_hmacsha512_state crypto_auth_hmacsha512256_state;++SODIUM_EXPORT+size_t crypto_auth_hmacsha512256_statebytes(void);++SODIUM_EXPORT+int crypto_auth_hmacsha512256_init(crypto_auth_hmacsha512256_state *state,+                                   const unsigned char *key,+                                   size_t keylen) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_auth_hmacsha512256_update(crypto_auth_hmacsha512256_state *state,+                                     const unsigned char *in,+                                     unsigned long long inlen) __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_auth_hmacsha512256_final(crypto_auth_hmacsha512256_state *state,+                                    unsigned char *out) __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_auth_hmacsha512256_keygen(unsigned char k[crypto_auth_hmacsha512256_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_box.h view
@@ -0,0 +1,177 @@+#ifndef crypto_box_H+#define crypto_box_H++/*+ * THREAD SAFETY: crypto_box_keypair() is thread-safe,+ * provided that sodium_init() was called before.+ *+ * Other functions are always thread-safe.+ */++#include <stddef.h>++#include "crypto_box_curve25519xsalsa20poly1305.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_box_SEEDBYTES crypto_box_curve25519xsalsa20poly1305_SEEDBYTES+SODIUM_EXPORT+size_t  crypto_box_seedbytes(void);++#define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES+SODIUM_EXPORT+size_t  crypto_box_publickeybytes(void);++#define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES+SODIUM_EXPORT+size_t  crypto_box_secretkeybytes(void);++#define crypto_box_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_NONCEBYTES+SODIUM_EXPORT+size_t  crypto_box_noncebytes(void);++#define crypto_box_MACBYTES crypto_box_curve25519xsalsa20poly1305_MACBYTES+SODIUM_EXPORT+size_t  crypto_box_macbytes(void);++#define crypto_box_MESSAGEBYTES_MAX crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX+SODIUM_EXPORT+size_t  crypto_box_messagebytes_max(void);++#define crypto_box_PRIMITIVE "curve25519xsalsa20poly1305"+SODIUM_EXPORT+const char *crypto_box_primitive(void);++SODIUM_EXPORT+int crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk,+                            const unsigned char *seed)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_box_keypair(unsigned char *pk, unsigned char *sk)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_box_easy(unsigned char *c, const unsigned char *m,+                    unsigned long long mlen, const unsigned char *n,+                    const unsigned char *pk, const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));++SODIUM_EXPORT+int crypto_box_open_easy(unsigned char *m, const unsigned char *c,+                         unsigned long long clen, const unsigned char *n,+                         const unsigned char *pk, const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));++SODIUM_EXPORT+int crypto_box_detached(unsigned char *c, unsigned char *mac,+                        const unsigned char *m, unsigned long long mlen,+                        const unsigned char *n, const unsigned char *pk,+                        const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 2, 5, 6, 7)));++SODIUM_EXPORT+int crypto_box_open_detached(unsigned char *m, const unsigned char *c,+                             const unsigned char *mac,+                             unsigned long long clen,+                             const unsigned char *n,+                             const unsigned char *pk,+                             const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6, 7)));++/* -- Precomputation interface -- */++#define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES+SODIUM_EXPORT+size_t  crypto_box_beforenmbytes(void);++SODIUM_EXPORT+int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,+                        const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,+                            unsigned long long mlen, const unsigned char *n,+                            const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));++SODIUM_EXPORT+int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,+                                 unsigned long long clen, const unsigned char *n,+                                 const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++SODIUM_EXPORT+int crypto_box_detached_afternm(unsigned char *c, unsigned char *mac,+                                const unsigned char *m, unsigned long long mlen,+                                const unsigned char *n, const unsigned char *k)+            __attribute__ ((nonnull(1, 2, 5, 6)));++SODIUM_EXPORT+int crypto_box_open_detached_afternm(unsigned char *m, const unsigned char *c,+                                     const unsigned char *mac,+                                     unsigned long long clen, const unsigned char *n,+                                     const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));++/* -- Ephemeral SK interface -- */++#define crypto_box_SEALBYTES (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)+SODIUM_EXPORT+size_t crypto_box_sealbytes(void);++SODIUM_EXPORT+int crypto_box_seal(unsigned char *c, const unsigned char *m,+                    unsigned long long mlen, const unsigned char *pk)+            __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_box_seal_open(unsigned char *m, const unsigned char *c,+                         unsigned long long clen,+                         const unsigned char *pk, const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++/* -- NaCl compatibility interface ; Requires padding -- */++#define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES+SODIUM_EXPORT+size_t  crypto_box_zerobytes(void);++#define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES+SODIUM_EXPORT+size_t  crypto_box_boxzerobytes(void);++SODIUM_EXPORT+int crypto_box(unsigned char *c, const unsigned char *m,+               unsigned long long mlen, const unsigned char *n,+               const unsigned char *pk, const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));++SODIUM_EXPORT+int crypto_box_open(unsigned char *m, const unsigned char *c,+                    unsigned long long clen, const unsigned char *n,+                    const unsigned char *pk, const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));++SODIUM_EXPORT+int crypto_box_afternm(unsigned char *c, const unsigned char *m,+                       unsigned long long mlen, const unsigned char *n,+                       const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));++SODIUM_EXPORT+int crypto_box_open_afternm(unsigned char *m, const unsigned char *c,+                            unsigned long long clen, const unsigned char *n,+                            const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h view
@@ -0,0 +1,164 @@++#ifndef crypto_box_curve25519xchacha20poly1305_H+#define crypto_box_curve25519xchacha20poly1305_H++#include <stddef.h>+#include "crypto_stream_xchacha20.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_box_curve25519xchacha20poly1305_SEEDBYTES 32U+SODIUM_EXPORT+size_t crypto_box_curve25519xchacha20poly1305_seedbytes(void);++#define crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES 32U+SODIUM_EXPORT+size_t crypto_box_curve25519xchacha20poly1305_publickeybytes(void);++#define crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES 32U+SODIUM_EXPORT+size_t crypto_box_curve25519xchacha20poly1305_secretkeybytes(void);++#define crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES 32U+SODIUM_EXPORT+size_t crypto_box_curve25519xchacha20poly1305_beforenmbytes(void);++#define crypto_box_curve25519xchacha20poly1305_NONCEBYTES 24U+SODIUM_EXPORT+size_t crypto_box_curve25519xchacha20poly1305_noncebytes(void);++#define crypto_box_curve25519xchacha20poly1305_MACBYTES 16U+SODIUM_EXPORT+size_t crypto_box_curve25519xchacha20poly1305_macbytes(void);++#define crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX \+    (crypto_stream_xchacha20_MESSAGEBYTES_MAX - crypto_box_curve25519xchacha20poly1305_MACBYTES)+SODIUM_EXPORT+size_t crypto_box_curve25519xchacha20poly1305_messagebytes_max(void);++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_seed_keypair(unsigned char *pk,+                                                        unsigned char *sk,+                                                        const unsigned char *seed)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_keypair(unsigned char *pk,+                                                   unsigned char *sk)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_easy(unsigned char *c,+                                                const unsigned char *m,+                                                unsigned long long mlen,+                                                const unsigned char *n,+                                                const unsigned char *pk,+                                                const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_open_easy(unsigned char *m,+                                                     const unsigned char *c,+                                                     unsigned long long clen,+                                                     const unsigned char *n,+                                                     const unsigned char *pk,+                                                     const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_detached(unsigned char *c,+                                                    unsigned char *mac,+                                                    const unsigned char *m,+                                                    unsigned long long mlen,+                                                    const unsigned char *n,+                                                    const unsigned char *pk,+                                                    const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 2, 5, 6, 7)));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_open_detached(unsigned char *m,+                                                         const unsigned char *c,+                                                         const unsigned char *mac,+                                                         unsigned long long clen,+                                                         const unsigned char *n,+                                                         const unsigned char *pk,+                                                         const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6, 7)));++/* -- Precomputation interface -- */++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_beforenm(unsigned char *k,+                                                    const unsigned char *pk,+                                                    const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_easy_afternm(unsigned char *c,+                                                        const unsigned char *m,+                                                        unsigned long long mlen,+                                                        const unsigned char *n,+                                                        const unsigned char *k)+            __attribute__ ((nonnull(1, 4, 5)));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_open_easy_afternm(unsigned char *m,+                                                             const unsigned char *c,+                                                             unsigned long long clen,+                                                             const unsigned char *n,+                                                             const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_detached_afternm(unsigned char *c,+                                                            unsigned char *mac,+                                                            const unsigned char *m,+                                                            unsigned long long mlen,+                                                            const unsigned char *n,+                                                            const unsigned char *k)+            __attribute__ ((nonnull(1, 2, 5, 6)));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_open_detached_afternm(unsigned char *m,+                                                                 const unsigned char *c,+                                                                 const unsigned char *mac,+                                                                 unsigned long long clen,+                                                                 const unsigned char *n,+                                                                 const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));++/* -- Ephemeral SK interface -- */++#define crypto_box_curve25519xchacha20poly1305_SEALBYTES \+    (crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES + \+     crypto_box_curve25519xchacha20poly1305_MACBYTES)++SODIUM_EXPORT+size_t crypto_box_curve25519xchacha20poly1305_sealbytes(void);++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_seal(unsigned char *c,+                                                const unsigned char *m,+                                                unsigned long long mlen,+                                                const unsigned char *pk)+            __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_box_curve25519xchacha20poly1305_seal_open(unsigned char *m,+                                                     const unsigned char *c,+                                                     unsigned long long clen,+                                                     const unsigned char *pk,+                                                     const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h view
@@ -0,0 +1,112 @@+#ifndef crypto_box_curve25519xsalsa20poly1305_H+#define crypto_box_curve25519xsalsa20poly1305_H++#include <stddef.h>+#include "crypto_stream_xsalsa20.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_box_curve25519xsalsa20poly1305_SEEDBYTES 32U+SODIUM_EXPORT+size_t crypto_box_curve25519xsalsa20poly1305_seedbytes(void);++#define crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES 32U+SODIUM_EXPORT+size_t crypto_box_curve25519xsalsa20poly1305_publickeybytes(void);++#define crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES 32U+SODIUM_EXPORT+size_t crypto_box_curve25519xsalsa20poly1305_secretkeybytes(void);++#define crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES 32U+SODIUM_EXPORT+size_t crypto_box_curve25519xsalsa20poly1305_beforenmbytes(void);++#define crypto_box_curve25519xsalsa20poly1305_NONCEBYTES 24U+SODIUM_EXPORT+size_t crypto_box_curve25519xsalsa20poly1305_noncebytes(void);++#define crypto_box_curve25519xsalsa20poly1305_MACBYTES 16U+SODIUM_EXPORT+size_t crypto_box_curve25519xsalsa20poly1305_macbytes(void);++/* Only for the libsodium API - The NaCl compatibility API would require BOXZEROBYTES extra bytes */+#define crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX \+    (crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_box_curve25519xsalsa20poly1305_MACBYTES)+SODIUM_EXPORT+size_t crypto_box_curve25519xsalsa20poly1305_messagebytes_max(void);++SODIUM_EXPORT+int crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk,+                                                       unsigned char *sk,+                                                       const unsigned char *seed)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk,+                                                  unsigned char *sk)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k,+                                                   const unsigned char *pk,+                                                   const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++/* -- NaCl compatibility interface ; Requires padding -- */++#define crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES 16U+SODIUM_EXPORT+size_t crypto_box_curve25519xsalsa20poly1305_boxzerobytes(void);++#define crypto_box_curve25519xsalsa20poly1305_ZEROBYTES \+    (crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES + \+     crypto_box_curve25519xsalsa20poly1305_MACBYTES)+SODIUM_EXPORT+size_t crypto_box_curve25519xsalsa20poly1305_zerobytes(void);++SODIUM_EXPORT+int crypto_box_curve25519xsalsa20poly1305(unsigned char *c,+                                          const unsigned char *m,+                                          unsigned long long mlen,+                                          const unsigned char *n,+                                          const unsigned char *pk,+                                          const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));++SODIUM_EXPORT+int crypto_box_curve25519xsalsa20poly1305_open(unsigned char *m,+                                               const unsigned char *c,+                                               unsigned long long clen,+                                               const unsigned char *n,+                                               const unsigned char *pk,+                                               const unsigned char *sk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));++SODIUM_EXPORT+int crypto_box_curve25519xsalsa20poly1305_afternm(unsigned char *c,+                                                  const unsigned char *m,+                                                  unsigned long long mlen,+                                                  const unsigned char *n,+                                                  const unsigned char *k)+            __attribute__ ((nonnull(1, 4, 5)));++SODIUM_EXPORT+int crypto_box_curve25519xsalsa20poly1305_open_afternm(unsigned char *m,+                                                       const unsigned char *c,+                                                       unsigned long long clen,+                                                       const unsigned char *n,+                                                       const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_core_ed25519.h view
@@ -0,0 +1,100 @@+#ifndef crypto_core_ed25519_H+#define crypto_core_ed25519_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_core_ed25519_BYTES 32+SODIUM_EXPORT+size_t crypto_core_ed25519_bytes(void);++#define crypto_core_ed25519_UNIFORMBYTES 32+SODIUM_EXPORT+size_t crypto_core_ed25519_uniformbytes(void);++#define crypto_core_ed25519_HASHBYTES 64+SODIUM_EXPORT+size_t crypto_core_ed25519_hashbytes(void);++#define crypto_core_ed25519_SCALARBYTES 32+SODIUM_EXPORT+size_t crypto_core_ed25519_scalarbytes(void);++#define crypto_core_ed25519_NONREDUCEDSCALARBYTES 64+SODIUM_EXPORT+size_t crypto_core_ed25519_nonreducedscalarbytes(void);++SODIUM_EXPORT+int crypto_core_ed25519_is_valid_point(const unsigned char *p)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_core_ed25519_add(unsigned char *r,+                            const unsigned char *p, const unsigned char *q)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_core_ed25519_sub(unsigned char *r,+                            const unsigned char *p, const unsigned char *q)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_core_ed25519_from_uniform(unsigned char *p, const unsigned char *r)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_core_ed25519_from_hash(unsigned char *p, const unsigned char *h)+            __attribute__ ((nonnull)) __attribute__ ((deprecated));++SODIUM_EXPORT+void crypto_core_ed25519_random(unsigned char *p)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ed25519_scalar_random(unsigned char *r)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_core_ed25519_scalar_invert(unsigned char *recip, const unsigned char *s)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ed25519_scalar_negate(unsigned char *neg, const unsigned char *s)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ed25519_scalar_complement(unsigned char *comp, const unsigned char *s)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ed25519_scalar_add(unsigned char *z, const unsigned char *x,+                                    const unsigned char *y)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ed25519_scalar_sub(unsigned char *z, const unsigned char *x,+                                    const unsigned char *y)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ed25519_scalar_mul(unsigned char *z, const unsigned char *x,+                                    const unsigned char *y)+            __attribute__ ((nonnull));++/*+ * The interval `s` is sampled from should be at least 317 bits to ensure almost+ * uniformity of `r` over `L`.+ */+SODIUM_EXPORT+void crypto_core_ed25519_scalar_reduce(unsigned char *r, const unsigned char *s)+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_core_hchacha20.h view
@@ -0,0 +1,36 @@+#ifndef crypto_core_hchacha20_H+#define crypto_core_hchacha20_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_core_hchacha20_OUTPUTBYTES 32U+SODIUM_EXPORT+size_t crypto_core_hchacha20_outputbytes(void);++#define crypto_core_hchacha20_INPUTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_hchacha20_inputbytes(void);++#define crypto_core_hchacha20_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_core_hchacha20_keybytes(void);++#define crypto_core_hchacha20_CONSTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_hchacha20_constbytes(void);++SODIUM_EXPORT+int crypto_core_hchacha20(unsigned char *out, const unsigned char *in,+                          const unsigned char *k, const unsigned char *c)+            __attribute__ ((nonnull(1, 2, 3)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_core_hsalsa20.h view
@@ -0,0 +1,36 @@+#ifndef crypto_core_hsalsa20_H+#define crypto_core_hsalsa20_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_core_hsalsa20_OUTPUTBYTES 32U+SODIUM_EXPORT+size_t crypto_core_hsalsa20_outputbytes(void);++#define crypto_core_hsalsa20_INPUTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_hsalsa20_inputbytes(void);++#define crypto_core_hsalsa20_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_core_hsalsa20_keybytes(void);++#define crypto_core_hsalsa20_CONSTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_hsalsa20_constbytes(void);++SODIUM_EXPORT+int crypto_core_hsalsa20(unsigned char *out, const unsigned char *in,+                         const unsigned char *k, const unsigned char *c)+            __attribute__ ((nonnull(1, 2, 3)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_core_ristretto255.h view
@@ -0,0 +1,100 @@+#ifndef crypto_core_ristretto255_H+#define crypto_core_ristretto255_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_core_ristretto255_BYTES 32+SODIUM_EXPORT+size_t crypto_core_ristretto255_bytes(void);++#define crypto_core_ristretto255_HASHBYTES 64+SODIUM_EXPORT+size_t crypto_core_ristretto255_hashbytes(void);++#define crypto_core_ristretto255_SCALARBYTES 32+SODIUM_EXPORT+size_t crypto_core_ristretto255_scalarbytes(void);++#define crypto_core_ristretto255_NONREDUCEDSCALARBYTES 64+SODIUM_EXPORT+size_t crypto_core_ristretto255_nonreducedscalarbytes(void);++SODIUM_EXPORT+int crypto_core_ristretto255_is_valid_point(const unsigned char *p)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_core_ristretto255_add(unsigned char *r,+                                 const unsigned char *p, const unsigned char *q)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_core_ristretto255_sub(unsigned char *r,+                                 const unsigned char *p, const unsigned char *q)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_core_ristretto255_from_hash(unsigned char *p,+                                       const unsigned char *r)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ristretto255_random(unsigned char *p)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ristretto255_scalar_random(unsigned char *r)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_core_ristretto255_scalar_invert(unsigned char *recip,+                                           const unsigned char *s)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ristretto255_scalar_negate(unsigned char *neg,+                                            const unsigned char *s)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ristretto255_scalar_complement(unsigned char *comp,+                                                const unsigned char *s)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ristretto255_scalar_add(unsigned char *z,+                                         const unsigned char *x,+                                         const unsigned char *y)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ristretto255_scalar_sub(unsigned char *z,+                                         const unsigned char *x,+                                         const unsigned char *y)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_core_ristretto255_scalar_mul(unsigned char *z,+                                         const unsigned char *x,+                                         const unsigned char *y)+            __attribute__ ((nonnull));++/*+ * The interval `s` is sampled from should be at least 317 bits to ensure almost+ * uniformity of `r` over `L`.+ */+SODIUM_EXPORT+void crypto_core_ristretto255_scalar_reduce(unsigned char *r,+                                            const unsigned char *s)+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_core_salsa20.h view
@@ -0,0 +1,36 @@+#ifndef crypto_core_salsa20_H+#define crypto_core_salsa20_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_core_salsa20_OUTPUTBYTES 64U+SODIUM_EXPORT+size_t crypto_core_salsa20_outputbytes(void);++#define crypto_core_salsa20_INPUTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_salsa20_inputbytes(void);++#define crypto_core_salsa20_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_core_salsa20_keybytes(void);++#define crypto_core_salsa20_CONSTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_salsa20_constbytes(void);++SODIUM_EXPORT+int crypto_core_salsa20(unsigned char *out, const unsigned char *in,+                        const unsigned char *k, const unsigned char *c)+            __attribute__ ((nonnull(1, 2, 3)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_core_salsa2012.h view
@@ -0,0 +1,36 @@+#ifndef crypto_core_salsa2012_H+#define crypto_core_salsa2012_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_core_salsa2012_OUTPUTBYTES 64U+SODIUM_EXPORT+size_t crypto_core_salsa2012_outputbytes(void);++#define crypto_core_salsa2012_INPUTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_salsa2012_inputbytes(void);++#define crypto_core_salsa2012_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_core_salsa2012_keybytes(void);++#define crypto_core_salsa2012_CONSTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_salsa2012_constbytes(void);++SODIUM_EXPORT+int crypto_core_salsa2012(unsigned char *out, const unsigned char *in,+                          const unsigned char *k, const unsigned char *c)+            __attribute__ ((nonnull(1, 2, 3)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_core_salsa208.h view
@@ -0,0 +1,40 @@+#ifndef crypto_core_salsa208_H+#define crypto_core_salsa208_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_core_salsa208_OUTPUTBYTES 64U+SODIUM_EXPORT+size_t crypto_core_salsa208_outputbytes(void)+            __attribute__ ((deprecated));++#define crypto_core_salsa208_INPUTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_salsa208_inputbytes(void)+            __attribute__ ((deprecated));++#define crypto_core_salsa208_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_core_salsa208_keybytes(void)+            __attribute__ ((deprecated));++#define crypto_core_salsa208_CONSTBYTES 16U+SODIUM_EXPORT+size_t crypto_core_salsa208_constbytes(void)+            __attribute__ ((deprecated));++SODIUM_EXPORT+int crypto_core_salsa208(unsigned char *out, const unsigned char *in,+                         const unsigned char *k, const unsigned char *c)+            __attribute__ ((nonnull(1, 2, 3)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_generichash.h view
@@ -0,0 +1,84 @@+#ifndef crypto_generichash_H+#define crypto_generichash_H++#include <stddef.h>++#include "crypto_generichash_blake2b.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_generichash_BYTES_MIN crypto_generichash_blake2b_BYTES_MIN+SODIUM_EXPORT+size_t  crypto_generichash_bytes_min(void);++#define crypto_generichash_BYTES_MAX crypto_generichash_blake2b_BYTES_MAX+SODIUM_EXPORT+size_t  crypto_generichash_bytes_max(void);++#define crypto_generichash_BYTES crypto_generichash_blake2b_BYTES+SODIUM_EXPORT+size_t  crypto_generichash_bytes(void);++#define crypto_generichash_KEYBYTES_MIN crypto_generichash_blake2b_KEYBYTES_MIN+SODIUM_EXPORT+size_t  crypto_generichash_keybytes_min(void);++#define crypto_generichash_KEYBYTES_MAX crypto_generichash_blake2b_KEYBYTES_MAX+SODIUM_EXPORT+size_t  crypto_generichash_keybytes_max(void);++#define crypto_generichash_KEYBYTES crypto_generichash_blake2b_KEYBYTES+SODIUM_EXPORT+size_t  crypto_generichash_keybytes(void);++#define crypto_generichash_PRIMITIVE "blake2b"+SODIUM_EXPORT+const char *crypto_generichash_primitive(void);++/*+ * Important when writing bindings for other programming languages:+ * the state address should be 64-bytes aligned.+ */+typedef crypto_generichash_blake2b_state crypto_generichash_state;++SODIUM_EXPORT+size_t  crypto_generichash_statebytes(void);++SODIUM_EXPORT+int crypto_generichash(unsigned char *out, size_t outlen,+                       const unsigned char *in, unsigned long long inlen,+                       const unsigned char *key, size_t keylen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_generichash_init(crypto_generichash_state *state,+                            const unsigned char *key,+                            const size_t keylen, const size_t outlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_generichash_update(crypto_generichash_state *state,+                              const unsigned char *in,+                              unsigned long long inlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_generichash_final(crypto_generichash_state *state,+                             unsigned char *out, const size_t outlen)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_generichash_keygen(unsigned char k[crypto_generichash_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_generichash_blake2b.h view
@@ -0,0 +1,122 @@+#ifndef crypto_generichash_blake2b_H+#define crypto_generichash_blake2b_H++#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>++#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#ifdef __IBMC__+# pragma pack(1)+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)+# pragma pack(1)+#else+# pragma pack(push, 1)+#endif++typedef struct CRYPTO_ALIGN(64) crypto_generichash_blake2b_state {+    unsigned char opaque[384];+} crypto_generichash_blake2b_state;++#ifdef __IBMC__+# pragma pack(pop)+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)+# pragma pack()+#else+# pragma pack(pop)+#endif++#define crypto_generichash_blake2b_BYTES_MIN     16U+SODIUM_EXPORT+size_t crypto_generichash_blake2b_bytes_min(void);++#define crypto_generichash_blake2b_BYTES_MAX     64U+SODIUM_EXPORT+size_t crypto_generichash_blake2b_bytes_max(void);++#define crypto_generichash_blake2b_BYTES         32U+SODIUM_EXPORT+size_t crypto_generichash_blake2b_bytes(void);++#define crypto_generichash_blake2b_KEYBYTES_MIN  16U+SODIUM_EXPORT+size_t crypto_generichash_blake2b_keybytes_min(void);++#define crypto_generichash_blake2b_KEYBYTES_MAX  64U+SODIUM_EXPORT+size_t crypto_generichash_blake2b_keybytes_max(void);++#define crypto_generichash_blake2b_KEYBYTES      32U+SODIUM_EXPORT+size_t crypto_generichash_blake2b_keybytes(void);++#define crypto_generichash_blake2b_SALTBYTES     16U+SODIUM_EXPORT+size_t crypto_generichash_blake2b_saltbytes(void);++#define crypto_generichash_blake2b_PERSONALBYTES 16U+SODIUM_EXPORT+size_t crypto_generichash_blake2b_personalbytes(void);++SODIUM_EXPORT+size_t crypto_generichash_blake2b_statebytes(void);++SODIUM_EXPORT+int crypto_generichash_blake2b(unsigned char *out, size_t outlen,+                               const unsigned char *in,+                               unsigned long long inlen,+                               const unsigned char *key, size_t keylen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_generichash_blake2b_salt_personal(unsigned char *out, size_t outlen,+                                             const unsigned char *in,+                                             unsigned long long inlen,+                                             const unsigned char *key,+                                             size_t keylen,+                                             const unsigned char *salt,+                                             const unsigned char *personal)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state,+                                    const unsigned char *key,+                                    const size_t keylen, const size_t outlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_generichash_blake2b_init_salt_personal(crypto_generichash_blake2b_state *state,+                                                  const unsigned char *key,+                                                  const size_t keylen, const size_t outlen,+                                                  const unsigned char *salt,+                                                  const unsigned char *personal)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_generichash_blake2b_update(crypto_generichash_blake2b_state *state,+                                      const unsigned char *in,+                                      unsigned long long inlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_generichash_blake2b_final(crypto_generichash_blake2b_state *state,+                                     unsigned char *out,+                                     const size_t outlen) __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_generichash_blake2b_keygen(unsigned char k[crypto_generichash_blake2b_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_hash.h view
@@ -0,0 +1,40 @@+#ifndef crypto_hash_H+#define crypto_hash_H++/*+ * WARNING: Unless you absolutely need to use SHA512 for interoperability,+ * purposes, you might want to consider crypto_generichash() instead.+ * Unlike SHA512, crypto_generichash() is not vulnerable to length+ * extension attacks.+ */++#include <stddef.h>++#include "crypto_hash_sha512.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_hash_BYTES crypto_hash_sha512_BYTES+SODIUM_EXPORT+size_t crypto_hash_bytes(void);++SODIUM_EXPORT+int crypto_hash(unsigned char *out, const unsigned char *in,+                unsigned long long inlen) __attribute__ ((nonnull(1)));++#define crypto_hash_PRIMITIVE "sha512"+SODIUM_EXPORT+const char *crypto_hash_primitive(void)+            __attribute__ ((warn_unused_result));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_hash_sha256.h view
@@ -0,0 +1,60 @@+#ifndef crypto_hash_sha256_H+#define crypto_hash_sha256_H++/*+ * WARNING: Unless you absolutely need to use SHA256 for interoperability,+ * purposes, you might want to consider crypto_generichash() instead.+ * Unlike SHA256, crypto_generichash() is not vulnerable to length+ * extension attacks.+ */++#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>++#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++typedef struct crypto_hash_sha256_state {+    uint32_t state[8];+    uint64_t count;+    uint8_t  buf[64];+} crypto_hash_sha256_state;++SODIUM_EXPORT+size_t crypto_hash_sha256_statebytes(void);++#define crypto_hash_sha256_BYTES 32U+SODIUM_EXPORT+size_t crypto_hash_sha256_bytes(void);++SODIUM_EXPORT+int crypto_hash_sha256(unsigned char *out, const unsigned char *in,+                       unsigned long long inlen) __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_hash_sha256_init(crypto_hash_sha256_state *state)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_hash_sha256_update(crypto_hash_sha256_state *state,+                              const unsigned char *in,+                              unsigned long long inlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_hash_sha256_final(crypto_hash_sha256_state *state,+                             unsigned char *out)+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_hash_sha512.h view
@@ -0,0 +1,60 @@+#ifndef crypto_hash_sha512_H+#define crypto_hash_sha512_H++/*+ * WARNING: Unless you absolutely need to use SHA512 for interoperability,+ * purposes, you might want to consider crypto_generichash() instead.+ * Unlike SHA512, crypto_generichash() is not vulnerable to length+ * extension attacks.+ */++#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>++#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++typedef struct crypto_hash_sha512_state {+    uint64_t state[8];+    uint64_t count[2];+    uint8_t  buf[128];+} crypto_hash_sha512_state;++SODIUM_EXPORT+size_t crypto_hash_sha512_statebytes(void);++#define crypto_hash_sha512_BYTES 64U+SODIUM_EXPORT+size_t crypto_hash_sha512_bytes(void);++SODIUM_EXPORT+int crypto_hash_sha512(unsigned char *out, const unsigned char *in,+                       unsigned long long inlen) __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_hash_sha512_init(crypto_hash_sha512_state *state)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_hash_sha512_update(crypto_hash_sha512_state *state,+                              const unsigned char *in,+                              unsigned long long inlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_hash_sha512_final(crypto_hash_sha512_state *state,+                             unsigned char *out)+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_kdf.h view
@@ -0,0 +1,53 @@+#ifndef crypto_kdf_H+#define crypto_kdf_H++#include <stddef.h>+#include <stdint.h>++#include "crypto_kdf_blake2b.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_kdf_BYTES_MIN crypto_kdf_blake2b_BYTES_MIN+SODIUM_EXPORT+size_t crypto_kdf_bytes_min(void);++#define crypto_kdf_BYTES_MAX crypto_kdf_blake2b_BYTES_MAX+SODIUM_EXPORT+size_t crypto_kdf_bytes_max(void);++#define crypto_kdf_CONTEXTBYTES crypto_kdf_blake2b_CONTEXTBYTES+SODIUM_EXPORT+size_t crypto_kdf_contextbytes(void);++#define crypto_kdf_KEYBYTES crypto_kdf_blake2b_KEYBYTES+SODIUM_EXPORT+size_t crypto_kdf_keybytes(void);++#define crypto_kdf_PRIMITIVE "blake2b"+SODIUM_EXPORT+const char *crypto_kdf_primitive(void)+            __attribute__ ((warn_unused_result));++SODIUM_EXPORT+int crypto_kdf_derive_from_key(unsigned char *subkey, size_t subkey_len,+                               uint64_t subkey_id,+                               const char ctx[crypto_kdf_CONTEXTBYTES],+                               const unsigned char key[crypto_kdf_KEYBYTES])+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_kdf_keygen(unsigned char k[crypto_kdf_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_kdf_blake2b.h view
@@ -0,0 +1,44 @@+#ifndef crypto_kdf_blake2b_H+#define crypto_kdf_blake2b_H++#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>++#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_kdf_blake2b_BYTES_MIN 16+SODIUM_EXPORT+size_t crypto_kdf_blake2b_bytes_min(void);++#define crypto_kdf_blake2b_BYTES_MAX 64+SODIUM_EXPORT+size_t crypto_kdf_blake2b_bytes_max(void);++#define crypto_kdf_blake2b_CONTEXTBYTES 8+SODIUM_EXPORT+size_t crypto_kdf_blake2b_contextbytes(void);++#define crypto_kdf_blake2b_KEYBYTES 32+SODIUM_EXPORT+size_t crypto_kdf_blake2b_keybytes(void);++SODIUM_EXPORT+int crypto_kdf_blake2b_derive_from_key(unsigned char *subkey, size_t subkey_len,+                                       uint64_t subkey_id,+                                       const char ctx[crypto_kdf_blake2b_CONTEXTBYTES],+                                       const unsigned char key[crypto_kdf_blake2b_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_kdf_hkdf_sha256.h view
@@ -0,0 +1,74 @@+#ifndef crypto_kdf_hkdf_sha256_H+#define crypto_kdf_hkdf_sha256_H++#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>++#include "crypto_kdf.h"+#include "crypto_auth_hmacsha256.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_kdf_hkdf_sha256_KEYBYTES crypto_auth_hmacsha256_BYTES+SODIUM_EXPORT+size_t crypto_kdf_hkdf_sha256_keybytes(void);++#define crypto_kdf_hkdf_sha256_BYTES_MIN 0U+SODIUM_EXPORT+size_t crypto_kdf_hkdf_sha256_bytes_min(void);++#define crypto_kdf_hkdf_sha256_BYTES_MAX (0xff * crypto_auth_hmacsha256_BYTES)+SODIUM_EXPORT+size_t crypto_kdf_hkdf_sha256_bytes_max(void);++SODIUM_EXPORT+int crypto_kdf_hkdf_sha256_extract(unsigned char prk[crypto_kdf_hkdf_sha256_KEYBYTES],+                                   const unsigned char *salt, size_t salt_len,+                                   const unsigned char *ikm, size_t ikm_len)+            __attribute__ ((nonnull(4)));++SODIUM_EXPORT+void crypto_kdf_hkdf_sha256_keygen(unsigned char prk[crypto_kdf_hkdf_sha256_KEYBYTES]);++SODIUM_EXPORT+int crypto_kdf_hkdf_sha256_expand(unsigned char *out, size_t out_len,+                                  const char *ctx, size_t ctx_len,+                                  const unsigned char prk[crypto_kdf_hkdf_sha256_KEYBYTES])+            __attribute__ ((nonnull(1)));++/* ------------------------------------------------------------------------- */++typedef struct crypto_kdf_hkdf_sha256_state {+    crypto_auth_hmacsha256_state st;+} crypto_kdf_hkdf_sha256_state;++SODIUM_EXPORT+size_t crypto_kdf_hkdf_sha256_statebytes(void);++SODIUM_EXPORT+int crypto_kdf_hkdf_sha256_extract_init(crypto_kdf_hkdf_sha256_state *state,+                                        const unsigned char *salt, size_t salt_len)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_kdf_hkdf_sha256_extract_update(crypto_kdf_hkdf_sha256_state *state,+                                          const unsigned char *ikm, size_t ikm_len)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_kdf_hkdf_sha256_extract_final(crypto_kdf_hkdf_sha256_state *state,+                                         unsigned char prk[crypto_kdf_hkdf_sha256_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_kdf_hkdf_sha512.h view
@@ -0,0 +1,75 @@+#ifndef crypto_kdf_hkdf_sha512_H+#define crypto_kdf_hkdf_sha512_H++#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>++#include "crypto_kdf.h"+#include "crypto_auth_hmacsha512.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_kdf_hkdf_sha512_KEYBYTES crypto_auth_hmacsha512_BYTES+SODIUM_EXPORT+size_t crypto_kdf_hkdf_sha512_keybytes(void);++#define crypto_kdf_hkdf_sha512_BYTES_MIN 0U+SODIUM_EXPORT+size_t crypto_kdf_hkdf_sha512_bytes_min(void);++#define crypto_kdf_hkdf_sha512_BYTES_MAX (0xff * crypto_auth_hmacsha512_BYTES)+SODIUM_EXPORT+size_t crypto_kdf_hkdf_sha512_bytes_max(void);++SODIUM_EXPORT+int crypto_kdf_hkdf_sha512_extract(unsigned char prk[crypto_kdf_hkdf_sha512_KEYBYTES],+                                   const unsigned char *salt, size_t salt_len,+                                   const unsigned char *ikm, size_t ikm_len)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+void crypto_kdf_hkdf_sha512_keygen(unsigned char prk[crypto_kdf_hkdf_sha512_KEYBYTES])+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_kdf_hkdf_sha512_expand(unsigned char *out, size_t out_len,+                                  const char *ctx, size_t ctx_len,+                                  const unsigned char prk[crypto_kdf_hkdf_sha512_KEYBYTES])+            __attribute__ ((nonnull(1)));++/* ------------------------------------------------------------------------- */++typedef struct crypto_kdf_hkdf_sha512_state {+    crypto_auth_hmacsha512_state st;+} crypto_kdf_hkdf_sha512_state;++SODIUM_EXPORT+size_t crypto_kdf_hkdf_sha512_statebytes(void);++SODIUM_EXPORT+int crypto_kdf_hkdf_sha512_extract_init(crypto_kdf_hkdf_sha512_state *state,+                                        const unsigned char *salt, size_t salt_len)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_kdf_hkdf_sha512_extract_update(crypto_kdf_hkdf_sha512_state *state,+                                          const unsigned char *ikm, size_t ikm_len)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_kdf_hkdf_sha512_extract_final(crypto_kdf_hkdf_sha512_state *state,+                                         unsigned char prk[crypto_kdf_hkdf_sha512_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_kx.h view
@@ -0,0 +1,66 @@+#ifndef crypto_kx_H+#define crypto_kx_H++#include <stddef.h>++#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_kx_PUBLICKEYBYTES 32+SODIUM_EXPORT+size_t crypto_kx_publickeybytes(void);++#define crypto_kx_SECRETKEYBYTES 32+SODIUM_EXPORT+size_t crypto_kx_secretkeybytes(void);++#define crypto_kx_SEEDBYTES 32+SODIUM_EXPORT+size_t crypto_kx_seedbytes(void);++#define crypto_kx_SESSIONKEYBYTES 32+SODIUM_EXPORT+size_t crypto_kx_sessionkeybytes(void);++#define crypto_kx_PRIMITIVE "x25519blake2b"+SODIUM_EXPORT+const char *crypto_kx_primitive(void);++SODIUM_EXPORT+int crypto_kx_seed_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES],+                           unsigned char sk[crypto_kx_SECRETKEYBYTES],+                           const unsigned char seed[crypto_kx_SEEDBYTES])+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_kx_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES],+                      unsigned char sk[crypto_kx_SECRETKEYBYTES])+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_kx_client_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES],+                                  unsigned char tx[crypto_kx_SESSIONKEYBYTES],+                                  const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES],+                                  const unsigned char client_sk[crypto_kx_SECRETKEYBYTES],+                                  const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES])+            __attribute__ ((warn_unused_result))  __attribute__ ((nonnull(3, 4, 5)));++SODIUM_EXPORT+int crypto_kx_server_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES],+                                  unsigned char tx[crypto_kx_SESSIONKEYBYTES],+                                  const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES],+                                  const unsigned char server_sk[crypto_kx_SECRETKEYBYTES],+                                  const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES])+            __attribute__ ((warn_unused_result))  __attribute__ ((nonnull(3, 4, 5)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_onetimeauth.h view
@@ -0,0 +1,65 @@+#ifndef crypto_onetimeauth_H+#define crypto_onetimeauth_H++#include <stddef.h>++#include "crypto_onetimeauth_poly1305.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++typedef crypto_onetimeauth_poly1305_state crypto_onetimeauth_state;++SODIUM_EXPORT+size_t  crypto_onetimeauth_statebytes(void);++#define crypto_onetimeauth_BYTES crypto_onetimeauth_poly1305_BYTES+SODIUM_EXPORT+size_t  crypto_onetimeauth_bytes(void);++#define crypto_onetimeauth_KEYBYTES crypto_onetimeauth_poly1305_KEYBYTES+SODIUM_EXPORT+size_t  crypto_onetimeauth_keybytes(void);++#define crypto_onetimeauth_PRIMITIVE "poly1305"+SODIUM_EXPORT+const char *crypto_onetimeauth_primitive(void);++SODIUM_EXPORT+int crypto_onetimeauth(unsigned char *out, const unsigned char *in,+                       unsigned long long inlen, const unsigned char *k)+            __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_onetimeauth_verify(const unsigned char *h, const unsigned char *in,+                              unsigned long long inlen, const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_onetimeauth_init(crypto_onetimeauth_state *state,+                            const unsigned char *key) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_onetimeauth_update(crypto_onetimeauth_state *state,+                              const unsigned char *in,+                              unsigned long long inlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_onetimeauth_final(crypto_onetimeauth_state *state,+                             unsigned char *out) __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_onetimeauth_keygen(unsigned char k[crypto_onetimeauth_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_onetimeauth_poly1305.h view
@@ -0,0 +1,72 @@+#ifndef crypto_onetimeauth_poly1305_H+#define crypto_onetimeauth_poly1305_H++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#include <stdint.h>+#include <stdio.h>+#include <stdlib.h>++#include <sys/types.h>++#include "export.h"++typedef struct CRYPTO_ALIGN(16) crypto_onetimeauth_poly1305_state {+    unsigned char opaque[256];+} crypto_onetimeauth_poly1305_state;++SODIUM_EXPORT+size_t crypto_onetimeauth_poly1305_statebytes(void);++#define crypto_onetimeauth_poly1305_BYTES 16U+SODIUM_EXPORT+size_t crypto_onetimeauth_poly1305_bytes(void);++#define crypto_onetimeauth_poly1305_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_onetimeauth_poly1305_keybytes(void);++SODIUM_EXPORT+int crypto_onetimeauth_poly1305(unsigned char *out,+                                const unsigned char *in,+                                unsigned long long inlen,+                                const unsigned char *k)+            __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_onetimeauth_poly1305_verify(const unsigned char *h,+                                       const unsigned char *in,+                                       unsigned long long inlen,+                                       const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_onetimeauth_poly1305_init(crypto_onetimeauth_poly1305_state *state,+                                     const unsigned char *key)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_onetimeauth_poly1305_update(crypto_onetimeauth_poly1305_state *state,+                                       const unsigned char *in,+                                       unsigned long long inlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_onetimeauth_poly1305_final(crypto_onetimeauth_poly1305_state *state,+                                      unsigned char *out)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_onetimeauth_poly1305_keygen(unsigned char k[crypto_onetimeauth_poly1305_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_pwhash.h view
@@ -0,0 +1,147 @@+#ifndef crypto_pwhash_H+#define crypto_pwhash_H++#include <stddef.h>++#include "crypto_pwhash_argon2i.h"+#include "crypto_pwhash_argon2id.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_pwhash_ALG_ARGON2I13 crypto_pwhash_argon2i_ALG_ARGON2I13+SODIUM_EXPORT+int crypto_pwhash_alg_argon2i13(void);++#define crypto_pwhash_ALG_ARGON2ID13 crypto_pwhash_argon2id_ALG_ARGON2ID13+SODIUM_EXPORT+int crypto_pwhash_alg_argon2id13(void);++#define crypto_pwhash_ALG_DEFAULT crypto_pwhash_ALG_ARGON2ID13+SODIUM_EXPORT+int crypto_pwhash_alg_default(void);++#define crypto_pwhash_BYTES_MIN crypto_pwhash_argon2id_BYTES_MIN+SODIUM_EXPORT+size_t crypto_pwhash_bytes_min(void);++#define crypto_pwhash_BYTES_MAX crypto_pwhash_argon2id_BYTES_MAX+SODIUM_EXPORT+size_t crypto_pwhash_bytes_max(void);++#define crypto_pwhash_PASSWD_MIN crypto_pwhash_argon2id_PASSWD_MIN+SODIUM_EXPORT+size_t crypto_pwhash_passwd_min(void);++#define crypto_pwhash_PASSWD_MAX crypto_pwhash_argon2id_PASSWD_MAX+SODIUM_EXPORT+size_t crypto_pwhash_passwd_max(void);++#define crypto_pwhash_SALTBYTES crypto_pwhash_argon2id_SALTBYTES+SODIUM_EXPORT+size_t crypto_pwhash_saltbytes(void);++#define crypto_pwhash_STRBYTES crypto_pwhash_argon2id_STRBYTES+SODIUM_EXPORT+size_t crypto_pwhash_strbytes(void);++#define crypto_pwhash_STRPREFIX crypto_pwhash_argon2id_STRPREFIX+SODIUM_EXPORT+const char *crypto_pwhash_strprefix(void);++#define crypto_pwhash_OPSLIMIT_MIN crypto_pwhash_argon2id_OPSLIMIT_MIN+SODIUM_EXPORT+size_t crypto_pwhash_opslimit_min(void);++#define crypto_pwhash_OPSLIMIT_MAX crypto_pwhash_argon2id_OPSLIMIT_MAX+SODIUM_EXPORT+size_t crypto_pwhash_opslimit_max(void);++#define crypto_pwhash_MEMLIMIT_MIN crypto_pwhash_argon2id_MEMLIMIT_MIN+SODIUM_EXPORT+size_t crypto_pwhash_memlimit_min(void);++#define crypto_pwhash_MEMLIMIT_MAX crypto_pwhash_argon2id_MEMLIMIT_MAX+SODIUM_EXPORT+size_t crypto_pwhash_memlimit_max(void);++#define crypto_pwhash_OPSLIMIT_INTERACTIVE crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE+SODIUM_EXPORT+size_t crypto_pwhash_opslimit_interactive(void);++#define crypto_pwhash_MEMLIMIT_INTERACTIVE crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE+SODIUM_EXPORT+size_t crypto_pwhash_memlimit_interactive(void);++#define crypto_pwhash_OPSLIMIT_MODERATE crypto_pwhash_argon2id_OPSLIMIT_MODERATE+SODIUM_EXPORT+size_t crypto_pwhash_opslimit_moderate(void);++#define crypto_pwhash_MEMLIMIT_MODERATE crypto_pwhash_argon2id_MEMLIMIT_MODERATE+SODIUM_EXPORT+size_t crypto_pwhash_memlimit_moderate(void);++#define crypto_pwhash_OPSLIMIT_SENSITIVE crypto_pwhash_argon2id_OPSLIMIT_SENSITIVE+SODIUM_EXPORT+size_t crypto_pwhash_opslimit_sensitive(void);++#define crypto_pwhash_MEMLIMIT_SENSITIVE crypto_pwhash_argon2id_MEMLIMIT_SENSITIVE+SODIUM_EXPORT+size_t crypto_pwhash_memlimit_sensitive(void);++/*+ * With this function, do not forget to store all parameters, including the+ * algorithm identifier in order to produce deterministic output.+ * The crypto_pwhash_* definitions, including crypto_pwhash_ALG_DEFAULT,+ * may change.+ */+SODIUM_EXPORT+int crypto_pwhash(unsigned char * const out, unsigned long long outlen,+                  const char * const passwd, unsigned long long passwdlen,+                  const unsigned char * const salt,+                  unsigned long long opslimit, size_t memlimit, int alg)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++/*+ * The output string already includes all the required parameters, including+ * the algorithm identifier. The string is all that has to be stored in+ * order to verify a password.+ */+SODIUM_EXPORT+int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES],+                      const char * const passwd, unsigned long long passwdlen,+                      unsigned long long opslimit, size_t memlimit)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_str_alg(char out[crypto_pwhash_STRBYTES],+                          const char * const passwd, unsigned long long passwdlen,+                          unsigned long long opslimit, size_t memlimit, int alg)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_str_verify(const char *str,+                             const char * const passwd,+                             unsigned long long passwdlen)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_str_needs_rehash(const char *str,+                                   unsigned long long opslimit, size_t memlimit)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++#define crypto_pwhash_PRIMITIVE "argon2i"+SODIUM_EXPORT+const char *crypto_pwhash_primitive(void)+            __attribute__ ((warn_unused_result));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_pwhash_argon2i.h view
@@ -0,0 +1,122 @@+#ifndef crypto_pwhash_argon2i_H+#define crypto_pwhash_argon2i_H++#include <limits.h>+#include <stddef.h>+#include <stdint.h>++#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_pwhash_argon2i_ALG_ARGON2I13 1+SODIUM_EXPORT+int crypto_pwhash_argon2i_alg_argon2i13(void);++#define crypto_pwhash_argon2i_BYTES_MIN 16U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_bytes_min(void);++#define crypto_pwhash_argon2i_BYTES_MAX SODIUM_MIN(SODIUM_SIZE_MAX, 4294967295U)+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_bytes_max(void);++#define crypto_pwhash_argon2i_PASSWD_MIN 0U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_passwd_min(void);++#define crypto_pwhash_argon2i_PASSWD_MAX 4294967295U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_passwd_max(void);++#define crypto_pwhash_argon2i_SALTBYTES 16U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_saltbytes(void);++#define crypto_pwhash_argon2i_STRBYTES 128U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_strbytes(void);++#define crypto_pwhash_argon2i_STRPREFIX "$argon2i$"+SODIUM_EXPORT+const char *crypto_pwhash_argon2i_strprefix(void);++#define crypto_pwhash_argon2i_OPSLIMIT_MIN 3U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_opslimit_min(void);++#define crypto_pwhash_argon2i_OPSLIMIT_MAX 4294967295U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_opslimit_max(void);++#define crypto_pwhash_argon2i_MEMLIMIT_MIN 8192U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_memlimit_min(void);++#define crypto_pwhash_argon2i_MEMLIMIT_MAX \+    ((SIZE_MAX >= 4398046510080U) ? 4398046510080U : (SIZE_MAX >= 2147483648U) ? 2147483648U : 32768U)+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_memlimit_max(void);++#define crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE 4U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_opslimit_interactive(void);++#define crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVE 33554432U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_memlimit_interactive(void);++#define crypto_pwhash_argon2i_OPSLIMIT_MODERATE 6U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_opslimit_moderate(void);++#define crypto_pwhash_argon2i_MEMLIMIT_MODERATE 134217728U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_memlimit_moderate(void);++#define crypto_pwhash_argon2i_OPSLIMIT_SENSITIVE 8U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_opslimit_sensitive(void);++#define crypto_pwhash_argon2i_MEMLIMIT_SENSITIVE 536870912U+SODIUM_EXPORT+size_t crypto_pwhash_argon2i_memlimit_sensitive(void);++SODIUM_EXPORT+int crypto_pwhash_argon2i(unsigned char * const out,+                          unsigned long long outlen,+                          const char * const passwd,+                          unsigned long long passwdlen,+                          const unsigned char * const salt,+                          unsigned long long opslimit, size_t memlimit,+                          int alg)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_argon2i_str(char out[crypto_pwhash_argon2i_STRBYTES],+                              const char * const passwd,+                              unsigned long long passwdlen,+                              unsigned long long opslimit, size_t memlimit)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_argon2i_str_verify(const char * str,+                                     const char * const passwd,+                                     unsigned long long passwdlen)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_argon2i_str_needs_rehash(const char * str,+                                           unsigned long long opslimit, size_t memlimit)+            __attribute__ ((warn_unused_result))  __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_pwhash_argon2id.h view
@@ -0,0 +1,122 @@+#ifndef crypto_pwhash_argon2id_H+#define crypto_pwhash_argon2id_H++#include <limits.h>+#include <stddef.h>+#include <stdint.h>++#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_pwhash_argon2id_ALG_ARGON2ID13 2+SODIUM_EXPORT+int crypto_pwhash_argon2id_alg_argon2id13(void);++#define crypto_pwhash_argon2id_BYTES_MIN 16U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_bytes_min(void);++#define crypto_pwhash_argon2id_BYTES_MAX SODIUM_MIN(SODIUM_SIZE_MAX, 4294967295U)+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_bytes_max(void);++#define crypto_pwhash_argon2id_PASSWD_MIN 0U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_passwd_min(void);++#define crypto_pwhash_argon2id_PASSWD_MAX 4294967295U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_passwd_max(void);++#define crypto_pwhash_argon2id_SALTBYTES 16U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_saltbytes(void);++#define crypto_pwhash_argon2id_STRBYTES 128U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_strbytes(void);++#define crypto_pwhash_argon2id_STRPREFIX "$argon2id$"+SODIUM_EXPORT+const char *crypto_pwhash_argon2id_strprefix(void);++#define crypto_pwhash_argon2id_OPSLIMIT_MIN 1U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_opslimit_min(void);++#define crypto_pwhash_argon2id_OPSLIMIT_MAX 4294967295U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_opslimit_max(void);++#define crypto_pwhash_argon2id_MEMLIMIT_MIN 8192U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_memlimit_min(void);++#define crypto_pwhash_argon2id_MEMLIMIT_MAX \+    ((SIZE_MAX >= 4398046510080U) ? 4398046510080U : (SIZE_MAX >= 2147483648U) ? 2147483648U : 32768U)+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_memlimit_max(void);++#define crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE 2U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_opslimit_interactive(void);++#define crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE 67108864U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_memlimit_interactive(void);++#define crypto_pwhash_argon2id_OPSLIMIT_MODERATE 3U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_opslimit_moderate(void);++#define crypto_pwhash_argon2id_MEMLIMIT_MODERATE 268435456U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_memlimit_moderate(void);++#define crypto_pwhash_argon2id_OPSLIMIT_SENSITIVE 4U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_opslimit_sensitive(void);++#define crypto_pwhash_argon2id_MEMLIMIT_SENSITIVE 1073741824U+SODIUM_EXPORT+size_t crypto_pwhash_argon2id_memlimit_sensitive(void);++SODIUM_EXPORT+int crypto_pwhash_argon2id(unsigned char * const out,+                           unsigned long long outlen,+                           const char * const passwd,+                           unsigned long long passwdlen,+                           const unsigned char * const salt,+                           unsigned long long opslimit, size_t memlimit,+                           int alg)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_argon2id_str(char out[crypto_pwhash_argon2id_STRBYTES],+                               const char * const passwd,+                               unsigned long long passwdlen,+                               unsigned long long opslimit, size_t memlimit)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_argon2id_str_verify(const char * str,+                                      const char * const passwd,+                                      unsigned long long passwdlen)+            __attribute__ ((warn_unused_result))  __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_argon2id_str_needs_rehash(const char * str,+                                            unsigned long long opslimit, size_t memlimit)+            __attribute__ ((warn_unused_result))  __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h view
@@ -0,0 +1,120 @@+#ifndef crypto_pwhash_scryptsalsa208sha256_H+#define crypto_pwhash_scryptsalsa208sha256_H++#include <limits.h>+#include <stddef.h>+#include <stdint.h>++#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_pwhash_scryptsalsa208sha256_BYTES_MIN 16U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_bytes_min(void);++#define crypto_pwhash_scryptsalsa208sha256_BYTES_MAX \+    SODIUM_MIN(SODIUM_SIZE_MAX, 0x1fffffffe0ULL)+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_bytes_max(void);++#define crypto_pwhash_scryptsalsa208sha256_PASSWD_MIN 0U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_passwd_min(void);++#define crypto_pwhash_scryptsalsa208sha256_PASSWD_MAX SODIUM_SIZE_MAX+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_passwd_max(void);++#define crypto_pwhash_scryptsalsa208sha256_SALTBYTES 32U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_saltbytes(void);++#define crypto_pwhash_scryptsalsa208sha256_STRBYTES 102U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_strbytes(void);++#define crypto_pwhash_scryptsalsa208sha256_STRPREFIX "$7$"+SODIUM_EXPORT+const char *crypto_pwhash_scryptsalsa208sha256_strprefix(void);++#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN 32768U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_opslimit_min(void);++#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX 4294967295U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_opslimit_max(void);++#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN 16777216U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_memlimit_min(void);++#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX \+    SODIUM_MIN(SIZE_MAX, 68719476736ULL)+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_memlimit_max(void);++#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE 524288U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_opslimit_interactive(void);++#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE 16777216U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_memlimit_interactive(void);++#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE 33554432U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive(void);++#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE 1073741824U+SODIUM_EXPORT+size_t crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive(void);++SODIUM_EXPORT+int crypto_pwhash_scryptsalsa208sha256(unsigned char * const out,+                                       unsigned long long outlen,+                                       const char * const passwd,+                                       unsigned long long passwdlen,+                                       const unsigned char * const salt,+                                       unsigned long long opslimit,+                                       size_t memlimit)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha256_STRBYTES],+                                           const char * const passwd,+                                           unsigned long long passwdlen,+                                           unsigned long long opslimit,+                                           size_t memlimit)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_scryptsalsa208sha256_str_verify(const char * str,+                                                  const char * const passwd,+                                                  unsigned long long passwdlen)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_scryptsalsa208sha256_ll(const uint8_t * passwd, size_t passwdlen,+                                          const uint8_t * salt, size_t saltlen,+                                          uint64_t N, uint32_t r, uint32_t p,+                                          uint8_t * buf, size_t buflen)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_pwhash_scryptsalsa208sha256_str_needs_rehash(const char * str,+                                                        unsigned long long opslimit,+                                                        size_t memlimit)+            __attribute__ ((warn_unused_result))  __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_scalarmult.h view
@@ -0,0 +1,46 @@+#ifndef crypto_scalarmult_H+#define crypto_scalarmult_H++#include <stddef.h>++#include "crypto_scalarmult_curve25519.h"+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_scalarmult_BYTES crypto_scalarmult_curve25519_BYTES+SODIUM_EXPORT+size_t  crypto_scalarmult_bytes(void);++#define crypto_scalarmult_SCALARBYTES crypto_scalarmult_curve25519_SCALARBYTES+SODIUM_EXPORT+size_t  crypto_scalarmult_scalarbytes(void);++#define crypto_scalarmult_PRIMITIVE "curve25519"+SODIUM_EXPORT+const char *crypto_scalarmult_primitive(void);++SODIUM_EXPORT+int crypto_scalarmult_base(unsigned char *q, const unsigned char *n)+            __attribute__ ((nonnull));++/*+ * NOTE: Do not use the result of this function directly for key exchange.+ *+ * Hash the result with the public keys in order to compute a shared+ * secret key: H(q || client_pk || server_pk)+ *+ * Or unless this is not an option, use the crypto_kx() API instead.+ */+SODIUM_EXPORT+int crypto_scalarmult(unsigned char *q, const unsigned char *n,+                      const unsigned char *p)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_scalarmult_curve25519.h view
@@ -0,0 +1,42 @@+#ifndef crypto_scalarmult_curve25519_H+#define crypto_scalarmult_curve25519_H++#include <stddef.h>++#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_scalarmult_curve25519_BYTES 32U+SODIUM_EXPORT+size_t crypto_scalarmult_curve25519_bytes(void);++#define crypto_scalarmult_curve25519_SCALARBYTES 32U+SODIUM_EXPORT+size_t crypto_scalarmult_curve25519_scalarbytes(void);++/*+ * NOTE: Do not use the result of this function directly for key exchange.+ *+ * Hash the result with the public keys in order to compute a shared+ * secret key: H(q || client_pk || server_pk)+ *+ * Or unless this is not an option, use the crypto_kx() API instead.+ */+SODIUM_EXPORT+int crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n,+                                 const unsigned char *p)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_scalarmult_curve25519_base(unsigned char *q,+                                      const unsigned char *n)+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_scalarmult_ed25519.h view
@@ -0,0 +1,51 @@++#ifndef crypto_scalarmult_ed25519_H+#define crypto_scalarmult_ed25519_H++#include <stddef.h>++#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_scalarmult_ed25519_BYTES 32U+SODIUM_EXPORT+size_t crypto_scalarmult_ed25519_bytes(void);++#define crypto_scalarmult_ed25519_SCALARBYTES 32U+SODIUM_EXPORT+size_t crypto_scalarmult_ed25519_scalarbytes(void);++/*+ * NOTE: Do not use the result of this function directly for key exchange.+ *+ * Hash the result with the public keys in order to compute a shared+ * secret key: H(q || client_pk || server_pk)+ *+ * Or unless this is not an option, use the crypto_kx() API instead.+ */+SODIUM_EXPORT+int crypto_scalarmult_ed25519(unsigned char *q, const unsigned char *n,+                              const unsigned char *p)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_scalarmult_ed25519_noclamp(unsigned char *q, const unsigned char *n,+                                      const unsigned char *p)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_scalarmult_ed25519_base(unsigned char *q, const unsigned char *n)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_scalarmult_ed25519_base_noclamp(unsigned char *q, const unsigned char *n)+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_scalarmult_ristretto255.h view
@@ -0,0 +1,43 @@++#ifndef crypto_scalarmult_ristretto255_H+#define crypto_scalarmult_ristretto255_H++#include <stddef.h>++#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_scalarmult_ristretto255_BYTES 32U+SODIUM_EXPORT+size_t crypto_scalarmult_ristretto255_bytes(void);++#define crypto_scalarmult_ristretto255_SCALARBYTES 32U+SODIUM_EXPORT+size_t crypto_scalarmult_ristretto255_scalarbytes(void);++/*+ * NOTE: Do not use the result of this function directly for key exchange.+ *+ * Hash the result with the public keys in order to compute a shared+ * secret key: H(q || client_pk || server_pk)+ *+ * Or unless this is not an option, use the crypto_kx() API instead.+ */+SODIUM_EXPORT+int crypto_scalarmult_ristretto255(unsigned char *q, const unsigned char *n,+                                   const unsigned char *p)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_scalarmult_ristretto255_base(unsigned char *q,+                                        const unsigned char *n)+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_secretbox.h view
@@ -0,0 +1,93 @@+#ifndef crypto_secretbox_H+#define crypto_secretbox_H++#include <stddef.h>++#include "crypto_secretbox_xsalsa20poly1305.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_secretbox_KEYBYTES crypto_secretbox_xsalsa20poly1305_KEYBYTES+SODIUM_EXPORT+size_t  crypto_secretbox_keybytes(void);++#define crypto_secretbox_NONCEBYTES crypto_secretbox_xsalsa20poly1305_NONCEBYTES+SODIUM_EXPORT+size_t  crypto_secretbox_noncebytes(void);++#define crypto_secretbox_MACBYTES crypto_secretbox_xsalsa20poly1305_MACBYTES+SODIUM_EXPORT+size_t  crypto_secretbox_macbytes(void);++#define crypto_secretbox_PRIMITIVE "xsalsa20poly1305"+SODIUM_EXPORT+const char *crypto_secretbox_primitive(void);++#define crypto_secretbox_MESSAGEBYTES_MAX crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX+SODIUM_EXPORT+size_t crypto_secretbox_messagebytes_max(void);++SODIUM_EXPORT+int crypto_secretbox_easy(unsigned char *c, const unsigned char *m,+                          unsigned long long mlen, const unsigned char *n,+                          const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));++SODIUM_EXPORT+int crypto_secretbox_open_easy(unsigned char *m, const unsigned char *c,+                               unsigned long long clen, const unsigned char *n,+                               const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++SODIUM_EXPORT+int crypto_secretbox_detached(unsigned char *c, unsigned char *mac,+                              const unsigned char *m,+                              unsigned long long mlen,+                              const unsigned char *n,+                              const unsigned char *k)+            __attribute__ ((nonnull(1, 2, 5, 6)));++SODIUM_EXPORT+int crypto_secretbox_open_detached(unsigned char *m,+                                   const unsigned char *c,+                                   const unsigned char *mac,+                                   unsigned long long clen,+                                   const unsigned char *n,+                                   const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));++SODIUM_EXPORT+void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES])+            __attribute__ ((nonnull));++/* -- NaCl compatibility interface ; Requires padding -- */++#define crypto_secretbox_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ZEROBYTES+SODIUM_EXPORT+size_t  crypto_secretbox_zerobytes(void);++#define crypto_secretbox_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES+SODIUM_EXPORT+size_t  crypto_secretbox_boxzerobytes(void);++SODIUM_EXPORT+int crypto_secretbox(unsigned char *c, const unsigned char *m,+                     unsigned long long mlen, const unsigned char *n,+                     const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));++SODIUM_EXPORT+int crypto_secretbox_open(unsigned char *m, const unsigned char *c,+                          unsigned long long clen, const unsigned char *n,+                          const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h view
@@ -0,0 +1,70 @@+#ifndef crypto_secretbox_xchacha20poly1305_H+#define crypto_secretbox_xchacha20poly1305_H++#include <stddef.h>+#include "crypto_stream_xchacha20.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_secretbox_xchacha20poly1305_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_secretbox_xchacha20poly1305_keybytes(void);++#define crypto_secretbox_xchacha20poly1305_NONCEBYTES 24U+SODIUM_EXPORT+size_t crypto_secretbox_xchacha20poly1305_noncebytes(void);++#define crypto_secretbox_xchacha20poly1305_MACBYTES 16U+SODIUM_EXPORT+size_t crypto_secretbox_xchacha20poly1305_macbytes(void);++#define crypto_secretbox_xchacha20poly1305_MESSAGEBYTES_MAX \+    (crypto_stream_xchacha20_MESSAGEBYTES_MAX - crypto_secretbox_xchacha20poly1305_MACBYTES)+SODIUM_EXPORT+size_t crypto_secretbox_xchacha20poly1305_messagebytes_max(void);++SODIUM_EXPORT+int crypto_secretbox_xchacha20poly1305_easy(unsigned char *c,+                                            const unsigned char *m,+                                            unsigned long long mlen,+                                            const unsigned char *n,+                                            const unsigned char *k)+            __attribute__ ((nonnull(1, 4, 5)));++SODIUM_EXPORT+int crypto_secretbox_xchacha20poly1305_open_easy(unsigned char *m,+                                                 const unsigned char *c,+                                                 unsigned long long clen,+                                                 const unsigned char *n,+                                                 const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++SODIUM_EXPORT+int crypto_secretbox_xchacha20poly1305_detached(unsigned char *c,+                                                unsigned char *mac,+                                                const unsigned char *m,+                                                unsigned long long mlen,+                                                const unsigned char *n,+                                                const unsigned char *k)+            __attribute__ ((nonnull(1, 2, 5, 6)));++SODIUM_EXPORT+int crypto_secretbox_xchacha20poly1305_open_detached(unsigned char *m,+                                                     const unsigned char *c,+                                                     const unsigned char *mac,+                                                     unsigned long long clen,+                                                     const unsigned char *n,+                                                     const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h view
@@ -0,0 +1,69 @@+#ifndef crypto_secretbox_xsalsa20poly1305_H+#define crypto_secretbox_xsalsa20poly1305_H++#include <stddef.h>+#include "crypto_stream_xsalsa20.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_secretbox_xsalsa20poly1305_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_secretbox_xsalsa20poly1305_keybytes(void);++#define crypto_secretbox_xsalsa20poly1305_NONCEBYTES 24U+SODIUM_EXPORT+size_t crypto_secretbox_xsalsa20poly1305_noncebytes(void);++#define crypto_secretbox_xsalsa20poly1305_MACBYTES 16U+SODIUM_EXPORT+size_t crypto_secretbox_xsalsa20poly1305_macbytes(void);++/* Only for the libsodium API - The NaCl compatibility API would require BOXZEROBYTES extra bytes */+#define crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX \+    (crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_secretbox_xsalsa20poly1305_MACBYTES)+SODIUM_EXPORT+size_t crypto_secretbox_xsalsa20poly1305_messagebytes_max(void);++SODIUM_EXPORT+int crypto_secretbox_xsalsa20poly1305(unsigned char *c,+                                      const unsigned char *m,+                                      unsigned long long mlen,+                                      const unsigned char *n,+                                      const unsigned char *k)+            __attribute__ ((nonnull(1, 4, 5)));++SODIUM_EXPORT+int crypto_secretbox_xsalsa20poly1305_open(unsigned char *m,+                                           const unsigned char *c,+                                           unsigned long long clen,+                                           const unsigned char *n,+                                           const unsigned char *k)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));++SODIUM_EXPORT+void crypto_secretbox_xsalsa20poly1305_keygen(unsigned char k[crypto_secretbox_xsalsa20poly1305_KEYBYTES])+            __attribute__ ((nonnull));++/* -- NaCl compatibility interface ; Requires padding -- */++#define crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES 16U+SODIUM_EXPORT+size_t crypto_secretbox_xsalsa20poly1305_boxzerobytes(void);++#define crypto_secretbox_xsalsa20poly1305_ZEROBYTES \+    (crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES + \+     crypto_secretbox_xsalsa20poly1305_MACBYTES)+SODIUM_EXPORT+size_t crypto_secretbox_xsalsa20poly1305_zerobytes(void);++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_secretstream_xchacha20poly1305.h view
@@ -0,0 +1,108 @@+#ifndef crypto_secretstream_xchacha20poly1305_H+#define crypto_secretstream_xchacha20poly1305_H++#include <stddef.h>++#include "crypto_aead_xchacha20poly1305.h"+#include "crypto_stream_chacha20.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_secretstream_xchacha20poly1305_ABYTES \+    (1U + crypto_aead_xchacha20poly1305_ietf_ABYTES)+SODIUM_EXPORT+size_t crypto_secretstream_xchacha20poly1305_abytes(void);++#define crypto_secretstream_xchacha20poly1305_HEADERBYTES \+    crypto_aead_xchacha20poly1305_ietf_NPUBBYTES+SODIUM_EXPORT+size_t crypto_secretstream_xchacha20poly1305_headerbytes(void);++#define crypto_secretstream_xchacha20poly1305_KEYBYTES \+    crypto_aead_xchacha20poly1305_ietf_KEYBYTES+SODIUM_EXPORT+size_t crypto_secretstream_xchacha20poly1305_keybytes(void);++#define crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX \+    SODIUM_MIN(SODIUM_SIZE_MAX - crypto_secretstream_xchacha20poly1305_ABYTES, \+              (64ULL * ((1ULL << 32) - 2ULL)))+SODIUM_EXPORT+size_t crypto_secretstream_xchacha20poly1305_messagebytes_max(void);++#define crypto_secretstream_xchacha20poly1305_TAG_MESSAGE 0x00+SODIUM_EXPORT+unsigned char crypto_secretstream_xchacha20poly1305_tag_message(void);++#define crypto_secretstream_xchacha20poly1305_TAG_PUSH    0x01+SODIUM_EXPORT+unsigned char crypto_secretstream_xchacha20poly1305_tag_push(void);++#define crypto_secretstream_xchacha20poly1305_TAG_REKEY   0x02+SODIUM_EXPORT+unsigned char crypto_secretstream_xchacha20poly1305_tag_rekey(void);++#define crypto_secretstream_xchacha20poly1305_TAG_FINAL \+    (crypto_secretstream_xchacha20poly1305_TAG_PUSH | \+     crypto_secretstream_xchacha20poly1305_TAG_REKEY)+SODIUM_EXPORT+unsigned char crypto_secretstream_xchacha20poly1305_tag_final(void);++typedef struct crypto_secretstream_xchacha20poly1305_state {+    unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES];+    unsigned char nonce[crypto_stream_chacha20_ietf_NONCEBYTES];+    unsigned char _pad[8];+} crypto_secretstream_xchacha20poly1305_state;++SODIUM_EXPORT+size_t crypto_secretstream_xchacha20poly1305_statebytes(void);++SODIUM_EXPORT+void crypto_secretstream_xchacha20poly1305_keygen+   (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_secretstream_xchacha20poly1305_init_push+   (crypto_secretstream_xchacha20poly1305_state *state,+    unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],+    const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_secretstream_xchacha20poly1305_push+   (crypto_secretstream_xchacha20poly1305_state *state,+    unsigned char *c, unsigned long long *clen_p,+    const unsigned char *m, unsigned long long mlen,+    const unsigned char *ad, unsigned long long adlen, unsigned char tag)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_secretstream_xchacha20poly1305_init_pull+   (crypto_secretstream_xchacha20poly1305_state *state,+    const unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],+    const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_secretstream_xchacha20poly1305_pull+   (crypto_secretstream_xchacha20poly1305_state *state,+    unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p,+    const unsigned char *c, unsigned long long clen,+    const unsigned char *ad, unsigned long long adlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+void crypto_secretstream_xchacha20poly1305_rekey+    (crypto_secretstream_xchacha20poly1305_state *state);++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_shorthash.h view
@@ -0,0 +1,41 @@+#ifndef crypto_shorthash_H+#define crypto_shorthash_H++#include <stddef.h>++#include "crypto_shorthash_siphash24.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_shorthash_BYTES crypto_shorthash_siphash24_BYTES+SODIUM_EXPORT+size_t  crypto_shorthash_bytes(void);++#define crypto_shorthash_KEYBYTES crypto_shorthash_siphash24_KEYBYTES+SODIUM_EXPORT+size_t  crypto_shorthash_keybytes(void);++#define crypto_shorthash_PRIMITIVE "siphash24"+SODIUM_EXPORT+const char *crypto_shorthash_primitive(void);++SODIUM_EXPORT+int crypto_shorthash(unsigned char *out, const unsigned char *in,+                     unsigned long long inlen, const unsigned char *k)+            __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+void crypto_shorthash_keygen(unsigned char k[crypto_shorthash_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_shorthash_siphash24.h view
@@ -0,0 +1,50 @@+#ifndef crypto_shorthash_siphash24_H+#define crypto_shorthash_siphash24_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++/* -- 64-bit output -- */++#define crypto_shorthash_siphash24_BYTES 8U+SODIUM_EXPORT+size_t crypto_shorthash_siphash24_bytes(void);++#define crypto_shorthash_siphash24_KEYBYTES 16U+SODIUM_EXPORT+size_t crypto_shorthash_siphash24_keybytes(void);++SODIUM_EXPORT+int crypto_shorthash_siphash24(unsigned char *out, const unsigned char *in,+                               unsigned long long inlen, const unsigned char *k)+            __attribute__ ((nonnull(1, 4)));++#ifndef SODIUM_LIBRARY_MINIMAL+/* -- 128-bit output -- */++#define crypto_shorthash_siphashx24_BYTES 16U+SODIUM_EXPORT+size_t crypto_shorthash_siphashx24_bytes(void);++#define crypto_shorthash_siphashx24_KEYBYTES 16U+SODIUM_EXPORT+size_t crypto_shorthash_siphashx24_keybytes(void);++SODIUM_EXPORT+int crypto_shorthash_siphashx24(unsigned char *out, const unsigned char *in,+                                unsigned long long inlen, const unsigned char *k)+            __attribute__ ((nonnull(1, 4)));+#endif++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_sign.h view
@@ -0,0 +1,107 @@+#ifndef crypto_sign_H+#define crypto_sign_H++/*+ * THREAD SAFETY: crypto_sign_keypair() is thread-safe,+ * provided that sodium_init() was called before.+ *+ * Other functions, including crypto_sign_seed_keypair() are always thread-safe.+ */++#include <stddef.h>++#include "crypto_sign_ed25519.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++typedef crypto_sign_ed25519ph_state crypto_sign_state;++SODIUM_EXPORT+size_t  crypto_sign_statebytes(void);++#define crypto_sign_BYTES crypto_sign_ed25519_BYTES+SODIUM_EXPORT+size_t  crypto_sign_bytes(void);++#define crypto_sign_SEEDBYTES crypto_sign_ed25519_SEEDBYTES+SODIUM_EXPORT+size_t  crypto_sign_seedbytes(void);++#define crypto_sign_PUBLICKEYBYTES crypto_sign_ed25519_PUBLICKEYBYTES+SODIUM_EXPORT+size_t  crypto_sign_publickeybytes(void);++#define crypto_sign_SECRETKEYBYTES crypto_sign_ed25519_SECRETKEYBYTES+SODIUM_EXPORT+size_t  crypto_sign_secretkeybytes(void);++#define crypto_sign_MESSAGEBYTES_MAX crypto_sign_ed25519_MESSAGEBYTES_MAX+SODIUM_EXPORT+size_t  crypto_sign_messagebytes_max(void);++#define crypto_sign_PRIMITIVE "ed25519"+SODIUM_EXPORT+const char *crypto_sign_primitive(void);++SODIUM_EXPORT+int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk,+                             const unsigned char *seed)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_sign_keypair(unsigned char *pk, unsigned char *sk)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_sign(unsigned char *sm, unsigned long long *smlen_p,+                const unsigned char *m, unsigned long long mlen,+                const unsigned char *sk) __attribute__ ((nonnull(1, 5)));++SODIUM_EXPORT+int crypto_sign_open(unsigned char *m, unsigned long long *mlen_p,+                     const unsigned char *sm, unsigned long long smlen,+                     const unsigned char *pk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5)));++SODIUM_EXPORT+int crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p,+                         const unsigned char *m, unsigned long long mlen,+                         const unsigned char *sk) __attribute__ ((nonnull(1, 5)));++SODIUM_EXPORT+int crypto_sign_verify_detached(const unsigned char *sig,+                                const unsigned char *m,+                                unsigned long long mlen,+                                const unsigned char *pk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_sign_init(crypto_sign_state *state);++SODIUM_EXPORT+int crypto_sign_update(crypto_sign_state *state,+                       const unsigned char *m, unsigned long long mlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig,+                             unsigned long long *siglen_p,+                             const unsigned char *sk)+            __attribute__ ((nonnull(1, 2, 4)));++SODIUM_EXPORT+int crypto_sign_final_verify(crypto_sign_state *state, const unsigned char *sig,+                             const unsigned char *pk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_sign_ed25519.h view
@@ -0,0 +1,124 @@+#ifndef crypto_sign_ed25519_H+#define crypto_sign_ed25519_H++#include <stddef.h>+#include "crypto_hash_sha512.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++typedef struct crypto_sign_ed25519ph_state {+    crypto_hash_sha512_state hs;+} crypto_sign_ed25519ph_state;++SODIUM_EXPORT+size_t crypto_sign_ed25519ph_statebytes(void);++#define crypto_sign_ed25519_BYTES 64U+SODIUM_EXPORT+size_t crypto_sign_ed25519_bytes(void);++#define crypto_sign_ed25519_SEEDBYTES 32U+SODIUM_EXPORT+size_t crypto_sign_ed25519_seedbytes(void);++#define crypto_sign_ed25519_PUBLICKEYBYTES 32U+SODIUM_EXPORT+size_t crypto_sign_ed25519_publickeybytes(void);++#define crypto_sign_ed25519_SECRETKEYBYTES (32U + 32U)+SODIUM_EXPORT+size_t crypto_sign_ed25519_secretkeybytes(void);++#define crypto_sign_ed25519_MESSAGEBYTES_MAX (SODIUM_SIZE_MAX - crypto_sign_ed25519_BYTES)+SODIUM_EXPORT+size_t crypto_sign_ed25519_messagebytes_max(void);++SODIUM_EXPORT+int crypto_sign_ed25519(unsigned char *sm, unsigned long long *smlen_p,+                        const unsigned char *m, unsigned long long mlen,+                        const unsigned char *sk)+            __attribute__ ((nonnull(1, 5)));++SODIUM_EXPORT+int crypto_sign_ed25519_open(unsigned char *m, unsigned long long *mlen_p,+                             const unsigned char *sm, unsigned long long smlen,+                             const unsigned char *pk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5)));++SODIUM_EXPORT+int crypto_sign_ed25519_detached(unsigned char *sig,+                                 unsigned long long *siglen_p,+                                 const unsigned char *m,+                                 unsigned long long mlen,+                                 const unsigned char *sk)+            __attribute__ ((nonnull(1, 5)));++SODIUM_EXPORT+int crypto_sign_ed25519_verify_detached(const unsigned char *sig,+                                        const unsigned char *m,+                                        unsigned long long mlen,+                                        const unsigned char *pk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4)));++SODIUM_EXPORT+int crypto_sign_ed25519_keypair(unsigned char *pk, unsigned char *sk)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_sign_ed25519_seed_keypair(unsigned char *pk, unsigned char *sk,+                                     const unsigned char *seed)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,+                                         const unsigned char *ed25519_pk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,+                                         const unsigned char *ed25519_sk)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_sign_ed25519_sk_to_seed(unsigned char *seed,+                                   const unsigned char *sk)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_sign_ed25519ph_init(crypto_sign_ed25519ph_state *state)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_sign_ed25519ph_update(crypto_sign_ed25519ph_state *state,+                                 const unsigned char *m,+                                 unsigned long long mlen)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int crypto_sign_ed25519ph_final_create(crypto_sign_ed25519ph_state *state,+                                       unsigned char *sig,+                                       unsigned long long *siglen_p,+                                       const unsigned char *sk)+            __attribute__ ((nonnull(1, 2, 4)));++SODIUM_EXPORT+int crypto_sign_ed25519ph_final_verify(crypto_sign_ed25519ph_state *state,+                                       const unsigned char *sig,+                                       const unsigned char *pk)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h view
@@ -0,0 +1,55 @@+#ifndef crypto_sign_edwards25519sha512batch_H+#define crypto_sign_edwards25519sha512batch_H++/*+ * WARNING: This construction was a prototype, which should not be used+ * any more in new projects.+ *+ * crypto_sign_edwards25519sha512batch is provided for applications+ * initially built with NaCl, but as recommended by the author of this+ * construction, new applications should use ed25519 instead.+ *+ * In Sodium, you should use the high-level crypto_sign_*() functions instead.+ */++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_sign_edwards25519sha512batch_BYTES 64U+#define crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES 32U+#define crypto_sign_edwards25519sha512batch_SECRETKEYBYTES (32U + 32U)+#define crypto_sign_edwards25519sha512batch_MESSAGEBYTES_MAX (SODIUM_SIZE_MAX - crypto_sign_edwards25519sha512batch_BYTES)++SODIUM_EXPORT+int crypto_sign_edwards25519sha512batch(unsigned char *sm,+                                        unsigned long long *smlen_p,+                                        const unsigned char *m,+                                        unsigned long long mlen,+                                        const unsigned char *sk)+            __attribute__ ((deprecated)) __attribute__ ((nonnull(1, 5)));++SODIUM_EXPORT+int crypto_sign_edwards25519sha512batch_open(unsigned char *m,+                                             unsigned long long *mlen_p,+                                             const unsigned char *sm,+                                             unsigned long long smlen,+                                             const unsigned char *pk)+            __attribute__ ((deprecated)) __attribute__ ((nonnull(3, 5)));++SODIUM_EXPORT+int crypto_sign_edwards25519sha512batch_keypair(unsigned char *pk,+                                                unsigned char *sk)+            __attribute__ ((deprecated)) __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_stream.h view
@@ -0,0 +1,59 @@+#ifndef crypto_stream_H+#define crypto_stream_H++/*+ *  WARNING: This is just a stream cipher. It is NOT authenticated encryption.+ *  While it provides some protection against eavesdropping, it does NOT+ *  provide any security against active attacks.+ *  Unless you know what you're doing, what you are looking for is probably+ *  the crypto_box functions.+ */++#include <stddef.h>++#include "crypto_stream_xsalsa20.h"+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_stream_KEYBYTES crypto_stream_xsalsa20_KEYBYTES+SODIUM_EXPORT+size_t  crypto_stream_keybytes(void);++#define crypto_stream_NONCEBYTES crypto_stream_xsalsa20_NONCEBYTES+SODIUM_EXPORT+size_t  crypto_stream_noncebytes(void);++#define crypto_stream_MESSAGEBYTES_MAX crypto_stream_xsalsa20_MESSAGEBYTES_MAX+SODIUM_EXPORT+size_t  crypto_stream_messagebytes_max(void);++#define crypto_stream_PRIMITIVE "xsalsa20"+SODIUM_EXPORT+const char *crypto_stream_primitive(void);++SODIUM_EXPORT+int crypto_stream(unsigned char *c, unsigned long long clen,+                  const unsigned char *n, const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_xor(unsigned char *c, const unsigned char *m,+                      unsigned long long mlen, const unsigned char *n,+                      const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_stream_keygen(unsigned char k[crypto_stream_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_stream_chacha20.h view
@@ -0,0 +1,106 @@+#ifndef crypto_stream_chacha20_H+#define crypto_stream_chacha20_H++/*+ *  WARNING: This is just a stream cipher. It is NOT authenticated encryption.+ *  While it provides some protection against eavesdropping, it does NOT+ *  provide any security against active attacks.+ *  Unless you know what you're doing, what you are looking for is probably+ *  the crypto_box functions.+ */++#include <stddef.h>+#include <stdint.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_stream_chacha20_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_stream_chacha20_keybytes(void);++#define crypto_stream_chacha20_NONCEBYTES 8U+SODIUM_EXPORT+size_t crypto_stream_chacha20_noncebytes(void);++#define crypto_stream_chacha20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX+SODIUM_EXPORT+size_t crypto_stream_chacha20_messagebytes_max(void);++/* ChaCha20 with a 64-bit nonce and a 64-bit counter, as originally designed */++SODIUM_EXPORT+int crypto_stream_chacha20(unsigned char *c, unsigned long long clen,+                           const unsigned char *n, const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m,+                               unsigned long long mlen, const unsigned char *n,+                               const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m,+                                  unsigned long long mlen,+                                  const unsigned char *n, uint64_t ic,+                                  const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES])+            __attribute__ ((nonnull));++/* ChaCha20 with a 96-bit nonce and a 32-bit counter (IETF) */++#define crypto_stream_chacha20_ietf_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_stream_chacha20_ietf_keybytes(void);++#define crypto_stream_chacha20_ietf_NONCEBYTES 12U+SODIUM_EXPORT+size_t crypto_stream_chacha20_ietf_noncebytes(void);++#define crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX \+    SODIUM_MIN(SODIUM_SIZE_MAX, 64ULL * (1ULL << 32))+SODIUM_EXPORT+size_t crypto_stream_chacha20_ietf_messagebytes_max(void);++SODIUM_EXPORT+int crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen,+                                const unsigned char *n, const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m,+                                    unsigned long long mlen, const unsigned char *n,+                                    const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m,+                                       unsigned long long mlen,+                                       const unsigned char *n, uint32_t ic,+                                       const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_stream_chacha20_ietf_keygen(unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES])+            __attribute__ ((nonnull));++/* Aliases */++#define crypto_stream_chacha20_IETF_KEYBYTES crypto_stream_chacha20_ietf_KEYBYTES+#define crypto_stream_chacha20_IETF_NONCEBYTES crypto_stream_chacha20_ietf_NONCEBYTES+#define crypto_stream_chacha20_IETF_MESSAGEBYTES_MAX crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_stream_salsa20.h view
@@ -0,0 +1,61 @@+#ifndef crypto_stream_salsa20_H+#define crypto_stream_salsa20_H++/*+ *  WARNING: This is just a stream cipher. It is NOT authenticated encryption.+ *  While it provides some protection against eavesdropping, it does NOT+ *  provide any security against active attacks.+ *  Unless you know what you're doing, what you are looking for is probably+ *  the crypto_box functions.+ */++#include <stddef.h>+#include <stdint.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_stream_salsa20_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_stream_salsa20_keybytes(void);++#define crypto_stream_salsa20_NONCEBYTES 8U+SODIUM_EXPORT+size_t crypto_stream_salsa20_noncebytes(void);++#define crypto_stream_salsa20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX+SODIUM_EXPORT+size_t crypto_stream_salsa20_messagebytes_max(void);++SODIUM_EXPORT+int crypto_stream_salsa20(unsigned char *c, unsigned long long clen,+                          const unsigned char *n, const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_salsa20_xor(unsigned char *c, const unsigned char *m,+                              unsigned long long mlen, const unsigned char *n,+                              const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_salsa20_xor_ic(unsigned char *c, const unsigned char *m,+                                 unsigned long long mlen,+                                 const unsigned char *n, uint64_t ic,+                                 const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_stream_salsa20_keygen(unsigned char k[crypto_stream_salsa20_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_stream_salsa2012.h view
@@ -0,0 +1,53 @@+#ifndef crypto_stream_salsa2012_H+#define crypto_stream_salsa2012_H++/*+ *  WARNING: This is just a stream cipher. It is NOT authenticated encryption.+ *  While it provides some protection against eavesdropping, it does NOT+ *  provide any security against active attacks.+ *  Unless you know what you're doing, what you are looking for is probably+ *  the crypto_box functions.+ */++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_stream_salsa2012_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_stream_salsa2012_keybytes(void);++#define crypto_stream_salsa2012_NONCEBYTES 8U+SODIUM_EXPORT+size_t crypto_stream_salsa2012_noncebytes(void);++#define crypto_stream_salsa2012_MESSAGEBYTES_MAX SODIUM_SIZE_MAX+SODIUM_EXPORT+size_t crypto_stream_salsa2012_messagebytes_max(void);++SODIUM_EXPORT+int crypto_stream_salsa2012(unsigned char *c, unsigned long long clen,+                            const unsigned char *n, const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_salsa2012_xor(unsigned char *c, const unsigned char *m,+                                unsigned long long mlen, const unsigned char *n,+                                const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_stream_salsa2012_keygen(unsigned char k[crypto_stream_salsa2012_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_stream_salsa208.h view
@@ -0,0 +1,56 @@+#ifndef crypto_stream_salsa208_H+#define crypto_stream_salsa208_H++/*+ *  WARNING: This is just a stream cipher. It is NOT authenticated encryption.+ *  While it provides some protection against eavesdropping, it does NOT+ *  provide any security against active attacks.+ *  Unless you know what you're doing, what you are looking for is probably+ *  the crypto_box functions.+ */++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_stream_salsa208_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_stream_salsa208_keybytes(void)+            __attribute__ ((deprecated));++#define crypto_stream_salsa208_NONCEBYTES 8U+SODIUM_EXPORT+size_t crypto_stream_salsa208_noncebytes(void)+            __attribute__ ((deprecated));++#define crypto_stream_salsa208_MESSAGEBYTES_MAX SODIUM_SIZE_MAX+    SODIUM_EXPORT+size_t crypto_stream_salsa208_messagebytes_max(void)+            __attribute__ ((deprecated));++SODIUM_EXPORT+int crypto_stream_salsa208(unsigned char *c, unsigned long long clen,+                           const unsigned char *n, const unsigned char *k)+            __attribute__ ((deprecated)) __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_salsa208_xor(unsigned char *c, const unsigned char *m,+                               unsigned long long mlen, const unsigned char *n,+                               const unsigned char *k)+            __attribute__ ((deprecated)) __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_stream_salsa208_keygen(unsigned char k[crypto_stream_salsa208_KEYBYTES])+            __attribute__ ((deprecated)) __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_stream_xchacha20.h view
@@ -0,0 +1,61 @@+#ifndef crypto_stream_xchacha20_H+#define crypto_stream_xchacha20_H++/*+ *  WARNING: This is just a stream cipher. It is NOT authenticated encryption.+ *  While it provides some protection against eavesdropping, it does NOT+ *  provide any security against active attacks.+ *  Unless you know what you're doing, what you are looking for is probably+ *  the crypto_box functions.+ */++#include <stddef.h>+#include <stdint.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_stream_xchacha20_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_stream_xchacha20_keybytes(void);++#define crypto_stream_xchacha20_NONCEBYTES 24U+SODIUM_EXPORT+size_t crypto_stream_xchacha20_noncebytes(void);++#define crypto_stream_xchacha20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX+SODIUM_EXPORT+size_t crypto_stream_xchacha20_messagebytes_max(void);++SODIUM_EXPORT+int crypto_stream_xchacha20(unsigned char *c, unsigned long long clen,+                            const unsigned char *n, const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_xchacha20_xor(unsigned char *c, const unsigned char *m,+                                unsigned long long mlen, const unsigned char *n,+                                const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_xchacha20_xor_ic(unsigned char *c, const unsigned char *m,+                                   unsigned long long mlen,+                                   const unsigned char *n, uint64_t ic,+                                   const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_stream_xchacha20_keygen(unsigned char k[crypto_stream_xchacha20_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_stream_xsalsa20.h view
@@ -0,0 +1,61 @@+#ifndef crypto_stream_xsalsa20_H+#define crypto_stream_xsalsa20_H++/*+ *  WARNING: This is just a stream cipher. It is NOT authenticated encryption.+ *  While it provides some protection against eavesdropping, it does NOT+ *  provide any security against active attacks.+ *  Unless you know what you're doing, what you are looking for is probably+ *  the crypto_box functions.+ */++#include <stddef.h>+#include <stdint.h>+#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++#define crypto_stream_xsalsa20_KEYBYTES 32U+SODIUM_EXPORT+size_t crypto_stream_xsalsa20_keybytes(void);++#define crypto_stream_xsalsa20_NONCEBYTES 24U+SODIUM_EXPORT+size_t crypto_stream_xsalsa20_noncebytes(void);++#define crypto_stream_xsalsa20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX+SODIUM_EXPORT+size_t crypto_stream_xsalsa20_messagebytes_max(void);++SODIUM_EXPORT+int crypto_stream_xsalsa20(unsigned char *c, unsigned long long clen,+                           const unsigned char *n, const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_xsalsa20_xor(unsigned char *c, const unsigned char *m,+                               unsigned long long mlen, const unsigned char *n,+                               const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int crypto_stream_xsalsa20_xor_ic(unsigned char *c, const unsigned char *m,+                                  unsigned long long mlen,+                                  const unsigned char *n, uint64_t ic,+                                  const unsigned char *k)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void crypto_stream_xsalsa20_keygen(unsigned char k[crypto_stream_xsalsa20_KEYBYTES])+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_verify_16.h view
@@ -0,0 +1,23 @@+#ifndef crypto_verify_16_H+#define crypto_verify_16_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_verify_16_BYTES 16U+SODIUM_EXPORT+size_t crypto_verify_16_bytes(void);++SODIUM_EXPORT+int crypto_verify_16(const unsigned char *x, const unsigned char *y)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_verify_32.h view
@@ -0,0 +1,23 @@+#ifndef crypto_verify_32_H+#define crypto_verify_32_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_verify_32_BYTES 32U+SODIUM_EXPORT+size_t crypto_verify_32_bytes(void);++SODIUM_EXPORT+int crypto_verify_32(const unsigned char *x, const unsigned char *y)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/crypto_verify_64.h view
@@ -0,0 +1,23 @@+#ifndef crypto_verify_64_H+#define crypto_verify_64_H++#include <stddef.h>+#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#define crypto_verify_64_BYTES 64U+SODIUM_EXPORT+size_t crypto_verify_64_bytes(void);++SODIUM_EXPORT+int crypto_verify_64(const unsigned char *x, const unsigned char *y)+            __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/export.h view
@@ -0,0 +1,57 @@++#ifndef sodium_export_H+#define sodium_export_H++#include <stddef.h>+#include <stdint.h>+#include <limits.h>++#if !defined(__clang__) && !defined(__GNUC__)+# ifdef __attribute__+#  undef __attribute__+# endif+# define __attribute__(a)+#endif++#ifdef SODIUM_STATIC+# define SODIUM_EXPORT+# define SODIUM_EXPORT_WEAK+#else+# if defined(_MSC_VER)+#  ifdef SODIUM_DLL_EXPORT+#   define SODIUM_EXPORT __declspec(dllexport)+#  else+#   define SODIUM_EXPORT __declspec(dllimport)+#  endif+# else+#  if defined(__SUNPRO_C)+#   ifndef __GNU_C__+#    define SODIUM_EXPORT __attribute__ (visibility(__global))+#   else+#    define SODIUM_EXPORT __attribute__ __global+#   endif+#  elif defined(_MSG_VER)+#   define SODIUM_EXPORT extern __declspec(dllexport)+#  else+#   define SODIUM_EXPORT __attribute__ ((visibility ("default")))+#  endif+# endif+# if defined(__ELF__) && !defined(SODIUM_DISABLE_WEAK_FUNCTIONS)+#  define SODIUM_EXPORT_WEAK SODIUM_EXPORT __attribute__((weak))+# else+#  define SODIUM_EXPORT_WEAK SODIUM_EXPORT+# endif+#endif++#ifndef CRYPTO_ALIGN+# if defined(__INTEL_COMPILER) || defined(_MSC_VER)+#  define CRYPTO_ALIGN(x) __declspec(align(x))+# else+#  define CRYPTO_ALIGN(x) __attribute__ ((aligned(x)))+# endif+#endif++#define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B))+#define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX)++#endif
+ vendor/external/libsodium/include/sodium/private/asm_cet.h view
@@ -0,0 +1,11 @@+#ifndef asm_cet_H+#define asm_cet_H 1++#if HAVE_CET_H+# include <cet.h>+#endif+#ifndef _CET_ENDBR+# define _CET_ENDBR+#endif++#endif
+ vendor/external/libsodium/include/sodium/private/chacha20_ietf_ext.h view
@@ -0,0 +1,16 @@+#ifndef chacha20_ietf_ext_H+#define chacha20_ietf_ext_H++#include <stdint.h>++/* The ietf_ext variant allows the internal counter to overflow into the IV */++int crypto_stream_chacha20_ietf_ext(unsigned char *c, unsigned long long clen,+                                    const unsigned char *n, const unsigned char *k);++int crypto_stream_chacha20_ietf_ext_xor_ic(unsigned char *c, const unsigned char *m,+                                           unsigned long long mlen,+                                           const unsigned char *n, uint32_t ic,+                                           const unsigned char *k);+#endif+
+ vendor/external/libsodium/include/sodium/private/common.h view
@@ -0,0 +1,282 @@+#ifndef common_H+#define common_H 1++#if !defined(_MSC_VER) && !defined(DEV_MODE) && 0+# warning *** This is unstable, untested, development code.+# warning It might not compile. It might not work as expected.+# warning It might be totally insecure.+# warning Do not use this except if you are planning to contribute code.+# warning Use releases available at https://download.libsodium.org/libsodium/releases/ instead.+# warning Alternatively, use the "stable" branch in the git repository.+#endif++#if !defined(_MSC_VER) && (!defined(CONFIGURED) || CONFIGURED != 1)+# warning *** The library is being compiled using an undocumented method.+# warning This is not supported. It has not been tested, it might not+# warning work as expected, and performance is likely to be suboptimal.+#endif++#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#define COMPILER_ASSERT(X) (void) sizeof(char[(X) ? 1 : -1])++#ifdef HAVE_TI_MODE+# if defined(__SIZEOF_INT128__)+typedef unsigned __int128 uint128_t;+# else+typedef unsigned uint128_t __attribute__((mode(TI)));+# endif+#endif++#define ROTL32(X, B) rotl32((X), (B))+static inline uint32_t+rotl32(const uint32_t x, const int b)+{+    return (x << b) | (x >> (32 - b));+}++#define ROTL64(X, B) rotl64((X), (B))+static inline uint64_t+rotl64(const uint64_t x, const int b)+{+    return (x << b) | (x >> (64 - b));+}++#define ROTR32(X, B) rotr32((X), (B))+static inline uint32_t+rotr32(const uint32_t x, const int b)+{+    return (x >> b) | (x << (32 - b));+}++#define ROTR64(X, B) rotr64((X), (B))+static inline uint64_t+rotr64(const uint64_t x, const int b)+{+    return (x >> b) | (x << (64 - b));+}++#define LOAD64_LE(SRC) load64_le(SRC)+static inline uint64_t+load64_le(const uint8_t src[8])+{+#ifdef NATIVE_LITTLE_ENDIAN+    uint64_t w;+    memcpy(&w, src, sizeof w);+    return w;+#else+    uint64_t w = (uint64_t) src[0];+    w |= (uint64_t) src[1] <<  8;+    w |= (uint64_t) src[2] << 16;+    w |= (uint64_t) src[3] << 24;+    w |= (uint64_t) src[4] << 32;+    w |= (uint64_t) src[5] << 40;+    w |= (uint64_t) src[6] << 48;+    w |= (uint64_t) src[7] << 56;+    return w;+#endif+}++#define STORE64_LE(DST, W) store64_le((DST), (W))+static inline void+store64_le(uint8_t dst[8], uint64_t w)+{+#ifdef NATIVE_LITTLE_ENDIAN+    memcpy(dst, &w, sizeof w);+#else+    dst[0] = (uint8_t) w; w >>= 8;+    dst[1] = (uint8_t) w; w >>= 8;+    dst[2] = (uint8_t) w; w >>= 8;+    dst[3] = (uint8_t) w; w >>= 8;+    dst[4] = (uint8_t) w; w >>= 8;+    dst[5] = (uint8_t) w; w >>= 8;+    dst[6] = (uint8_t) w; w >>= 8;+    dst[7] = (uint8_t) w;+#endif+}++#define LOAD32_LE(SRC) load32_le(SRC)+static inline uint32_t+load32_le(const uint8_t src[4])+{+#ifdef NATIVE_LITTLE_ENDIAN+    uint32_t w;+    memcpy(&w, src, sizeof w);+    return w;+#else+    uint32_t w = (uint32_t) src[0];+    w |= (uint32_t) src[1] <<  8;+    w |= (uint32_t) src[2] << 16;+    w |= (uint32_t) src[3] << 24;+    return w;+#endif+}++#define STORE32_LE(DST, W) store32_le((DST), (W))+static inline void+store32_le(uint8_t dst[4], uint32_t w)+{+#ifdef NATIVE_LITTLE_ENDIAN+    memcpy(dst, &w, sizeof w);+#else+    dst[0] = (uint8_t) w; w >>= 8;+    dst[1] = (uint8_t) w; w >>= 8;+    dst[2] = (uint8_t) w; w >>= 8;+    dst[3] = (uint8_t) w;+#endif+}++/* ----- */++#define LOAD64_BE(SRC) load64_be(SRC)+static inline uint64_t+load64_be(const uint8_t src[8])+{+#ifdef NATIVE_BIG_ENDIAN+    uint64_t w;+    memcpy(&w, src, sizeof w);+    return w;+#else+    uint64_t w = (uint64_t) src[7];+    w |= (uint64_t) src[6] <<  8;+    w |= (uint64_t) src[5] << 16;+    w |= (uint64_t) src[4] << 24;+    w |= (uint64_t) src[3] << 32;+    w |= (uint64_t) src[2] << 40;+    w |= (uint64_t) src[1] << 48;+    w |= (uint64_t) src[0] << 56;+    return w;+#endif+}++#define STORE64_BE(DST, W) store64_be((DST), (W))+static inline void+store64_be(uint8_t dst[8], uint64_t w)+{+#ifdef NATIVE_BIG_ENDIAN+    memcpy(dst, &w, sizeof w);+#else+    dst[7] = (uint8_t) w; w >>= 8;+    dst[6] = (uint8_t) w; w >>= 8;+    dst[5] = (uint8_t) w; w >>= 8;+    dst[4] = (uint8_t) w; w >>= 8;+    dst[3] = (uint8_t) w; w >>= 8;+    dst[2] = (uint8_t) w; w >>= 8;+    dst[1] = (uint8_t) w; w >>= 8;+    dst[0] = (uint8_t) w;+#endif+}++#define LOAD32_BE(SRC) load32_be(SRC)+static inline uint32_t+load32_be(const uint8_t src[4])+{+#ifdef NATIVE_BIG_ENDIAN+    uint32_t w;+    memcpy(&w, src, sizeof w);+    return w;+#else+    uint32_t w = (uint32_t) src[3];+    w |= (uint32_t) src[2] <<  8;+    w |= (uint32_t) src[1] << 16;+    w |= (uint32_t) src[0] << 24;+    return w;+#endif+}++#define STORE32_BE(DST, W) store32_be((DST), (W))+static inline void+store32_be(uint8_t dst[4], uint32_t w)+{+#ifdef NATIVE_BIG_ENDIAN+    memcpy(dst, &w, sizeof w);+#else+    dst[3] = (uint8_t) w; w >>= 8;+    dst[2] = (uint8_t) w; w >>= 8;+    dst[1] = (uint8_t) w; w >>= 8;+    dst[0] = (uint8_t) w;+#endif+}++#define XOR_BUF(OUT, IN, N) xor_buf((OUT), (IN), (N))+static inline void+xor_buf(unsigned char *out, const unsigned char *in, size_t n)+{+    size_t i;++    for (i = 0; i < n; i++) {+        out[i] ^= in[i];+    }+}++#if !defined(__clang__) && !defined(__GNUC__)+# ifdef __attribute__+#  undef __attribute__+# endif+# define __attribute__(a)+#endif++#ifndef CRYPTO_ALIGN+# if defined(__INTEL_COMPILER) || defined(_MSC_VER)+#  define CRYPTO_ALIGN(x) __declspec(align(x))+# else+#  define CRYPTO_ALIGN(x) __attribute__ ((aligned(x)))+# endif+#endif++#ifdef _MSC_VER++# if defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86)+#  include <intrin.h>++#  define HAVE_INTRIN_H    1+#  define HAVE_MMINTRIN_H  1+#  define HAVE_EMMINTRIN_H 1+#  define HAVE_PMMINTRIN_H 1+#  define HAVE_TMMINTRIN_H 1+#  define HAVE_SMMINTRIN_H 1+#  define HAVE_AVXINTRIN_H 1+#  if _MSC_VER >= 1600+#   define HAVE_WMMINTRIN_H 1+#  endif+#  if _MSC_VER >= 1700 && defined(_M_X64)+#   define HAVE_AVX2INTRIN_H 1+#  endif+#  if _MSC_VER >= 1910 && defined(_M_X64)+#   define HAVE_AVX512FINTRIN_H 1+#  endif++# elif defined(_M_ARM64)++#  ifndef __ARM_NEON+#   define __ARM_NEON 1+#  endif+#  define HAVE_ARMCRYPTO 1++# endif /* _MSC_VER */++#elif defined(HAVE_INTRIN_H)+# include <intrin.h>+#endif++#ifdef HAVE_LIBCTGRIND+extern void ct_poison  (const void *, size_t);+extern void ct_unpoison(const void *, size_t);+# define POISON(X, L)   ct_poison((X), (L))+# define UNPOISON(X, L) ct_unpoison((X), (L))+#else+# define POISON(X, L)   (void) 0+# define UNPOISON(X, L) (void) 0+#endif++#ifdef HAVE_GCC_MEMORY_FENCES+# define ACQUIRE_FENCE __atomic_thread_fence(__ATOMIC_ACQUIRE)+#elif defined(HAVE_C11_MEMORY_FENCES)+# define ACQUIRE_FENCE atomic_thread_fence(memory_order_acquire)+#else+# define ACQUIRE_FENCE (void) 0+#endif++#endif
+ vendor/external/libsodium/include/sodium/private/ed25519_ref10.h view
@@ -0,0 +1,142 @@+#ifndef ed25519_ref10_H+#define ed25519_ref10_H++#include <stddef.h>+#include <stdint.h>++/*+ fe means field element.+ Here the field is \Z/(2^255-19).+ */++#ifdef HAVE_TI_MODE+typedef uint64_t fe25519[5];+#else+typedef int32_t fe25519[10];+#endif++void fe25519_invert(fe25519 out, const fe25519 z);+void fe25519_frombytes(fe25519 h, const unsigned char *s);+void fe25519_tobytes(unsigned char *s, const fe25519 h);++#ifdef HAVE_TI_MODE+# include "ed25519_ref10_fe_51.h"+#else+# include "ed25519_ref10_fe_25_5.h"+#endif+++/*+ ge means group element.++ Here the group is the set of pairs (x,y) of field elements+ satisfying -x^2 + y^2 = 1 + d x^2y^2+ where d = -121665/121666.++ Representations:+ ge25519_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z+ ge25519_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT+ ge25519_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T+ ge25519_precomp (Duif): (y+x,y-x,2dxy)+ */++typedef struct {+    fe25519 X;+    fe25519 Y;+    fe25519 Z;+} ge25519_p2;++typedef struct {+    fe25519 X;+    fe25519 Y;+    fe25519 Z;+    fe25519 T;+} ge25519_p3;++typedef struct {+    fe25519 X;+    fe25519 Y;+    fe25519 Z;+    fe25519 T;+} ge25519_p1p1;++typedef struct {+    fe25519 yplusx;+    fe25519 yminusx;+    fe25519 xy2d;+} ge25519_precomp;++typedef struct {+    fe25519 YplusX;+    fe25519 YminusX;+    fe25519 Z;+    fe25519 T2d;+} ge25519_cached;++void ge25519_tobytes(unsigned char *s, const ge25519_p2 *h);++void ge25519_p3_tobytes(unsigned char *s, const ge25519_p3 *h);++int ge25519_frombytes(ge25519_p3 *h, const unsigned char *s);++int ge25519_frombytes_negate_vartime(ge25519_p3 *h, const unsigned char *s);++void ge25519_p3_to_cached(ge25519_cached *r, const ge25519_p3 *p);++void ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p);++void ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p);++void ge25519_add(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q);++void ge25519_sub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q);++void ge25519_scalarmult_base(ge25519_p3 *h, const unsigned char *a);++void ge25519_double_scalarmult_vartime(ge25519_p2 *r, const unsigned char *a,+                                       const ge25519_p3 *A,+                                       const unsigned char *b);++void ge25519_scalarmult(ge25519_p3 *h, const unsigned char *a,+                        const ge25519_p3 *p);++int ge25519_is_canonical(const unsigned char *s);++int ge25519_is_on_curve(const ge25519_p3 *p);++int ge25519_is_on_main_subgroup(const ge25519_p3 *p);++int ge25519_has_small_order(const unsigned char s[32]);++void ge25519_from_uniform(unsigned char s[32], const unsigned char r[32]);++void ge25519_from_hash(unsigned char s[32], const unsigned char h[64]);++/*+ Ristretto group+ */++int ristretto255_frombytes(ge25519_p3 *h, const unsigned char *s);++void ristretto255_p3_tobytes(unsigned char *s, const ge25519_p3 *h);++void ristretto255_from_hash(unsigned char s[32], const unsigned char h[64]);++/*+ The set of scalars is \Z/l+ where l = 2^252 + 27742317777372353535851937790883648493.+ */++void sc25519_invert(unsigned char recip[32], const unsigned char s[32]);++void sc25519_reduce(unsigned char s[64]);++void sc25519_mul(unsigned char s[32], const unsigned char a[32],+                 const unsigned char b[32]);++void sc25519_muladd(unsigned char s[32], const unsigned char a[32],+                    const unsigned char b[32], const unsigned char c[32]);++int sc25519_is_canonical(const unsigned char s[32]);++#endif
+ vendor/external/libsodium/include/sodium/private/ed25519_ref10_fe_25_5.h view
@@ -0,0 +1,1030 @@+#include <string.h>++#include "private/common.h"+#include "utils.h"++/*+ h = 0+ */++static inline void+fe25519_0(fe25519 h)+{+    memset(&h[0], 0, 10 * sizeof h[0]);+}++/*+ h = 1+ */++static inline void+fe25519_1(fe25519 h)+{+    h[0] = 1;+    h[1] = 0;+    memset(&h[2], 0, 8 * sizeof h[0]);+}++/*+ h = f + g+ Can overlap h with f or g.+ *+ Preconditions:+ |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.+ |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.+ *+ Postconditions:+ |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.+ */++static inline void+fe25519_add(fe25519 h, const fe25519 f, const fe25519 g)+{+    int32_t h0 = f[0] + g[0];+    int32_t h1 = f[1] + g[1];+    int32_t h2 = f[2] + g[2];+    int32_t h3 = f[3] + g[3];+    int32_t h4 = f[4] + g[4];+    int32_t h5 = f[5] + g[5];+    int32_t h6 = f[6] + g[6];+    int32_t h7 = f[7] + g[7];+    int32_t h8 = f[8] + g[8];+    int32_t h9 = f[9] + g[9];++    h[0] = h0;+    h[1] = h1;+    h[2] = h2;+    h[3] = h3;+    h[4] = h4;+    h[5] = h5;+    h[6] = h6;+    h[7] = h7;+    h[8] = h8;+    h[9] = h9;+}++/*+ h = f - g+ Can overlap h with f or g.+ *+ Preconditions:+ |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.+ |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.+ *+ Postconditions:+ |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.+ */++static void+fe25519_sub(fe25519 h, const fe25519 f, const fe25519 g)+{+    int32_t h0 = f[0] - g[0];+    int32_t h1 = f[1] - g[1];+    int32_t h2 = f[2] - g[2];+    int32_t h3 = f[3] - g[3];+    int32_t h4 = f[4] - g[4];+    int32_t h5 = f[5] - g[5];+    int32_t h6 = f[6] - g[6];+    int32_t h7 = f[7] - g[7];+    int32_t h8 = f[8] - g[8];+    int32_t h9 = f[9] - g[9];++    h[0] = h0;+    h[1] = h1;+    h[2] = h2;+    h[3] = h3;+    h[4] = h4;+    h[5] = h5;+    h[6] = h6;+    h[7] = h7;+    h[8] = h8;+    h[9] = h9;+}++/*+ h = -f+ *+ Preconditions:+ |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.+ *+ Postconditions:+ |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.+ */++static inline void+fe25519_neg(fe25519 h, const fe25519 f)+{+    int32_t h0 = -f[0];+    int32_t h1 = -f[1];+    int32_t h2 = -f[2];+    int32_t h3 = -f[3];+    int32_t h4 = -f[4];+    int32_t h5 = -f[5];+    int32_t h6 = -f[6];+    int32_t h7 = -f[7];+    int32_t h8 = -f[8];+    int32_t h9 = -f[9];++    h[0] = h0;+    h[1] = h1;+    h[2] = h2;+    h[3] = h3;+    h[4] = h4;+    h[5] = h5;+    h[6] = h6;+    h[7] = h7;+    h[8] = h8;+    h[9] = h9;+}++/*+ Replace (f,g) with (g,g) if b == 1;+ replace (f,g) with (f,g) if b == 0.+ *+ Preconditions: b in {0,1}.+ */++static void+fe25519_cmov(fe25519 f, const fe25519 g, unsigned int b)+{+    const uint32_t mask = (uint32_t) (-(int32_t) b);++    int32_t f0 = f[0];+    int32_t f1 = f[1];+    int32_t f2 = f[2];+    int32_t f3 = f[3];+    int32_t f4 = f[4];+    int32_t f5 = f[5];+    int32_t f6 = f[6];+    int32_t f7 = f[7];+    int32_t f8 = f[8];+    int32_t f9 = f[9];++    int32_t x0 = f0 ^ g[0];+    int32_t x1 = f1 ^ g[1];+    int32_t x2 = f2 ^ g[2];+    int32_t x3 = f3 ^ g[3];+    int32_t x4 = f4 ^ g[4];+    int32_t x5 = f5 ^ g[5];+    int32_t x6 = f6 ^ g[6];+    int32_t x7 = f7 ^ g[7];+    int32_t x8 = f8 ^ g[8];+    int32_t x9 = f9 ^ g[9];++    x0 &= mask;+    x1 &= mask;+    x2 &= mask;+    x3 &= mask;+    x4 &= mask;+    x5 &= mask;+    x6 &= mask;+    x7 &= mask;+    x8 &= mask;+    x9 &= mask;++    f[0] = f0 ^ x0;+    f[1] = f1 ^ x1;+    f[2] = f2 ^ x2;+    f[3] = f3 ^ x3;+    f[4] = f4 ^ x4;+    f[5] = f5 ^ x5;+    f[6] = f6 ^ x6;+    f[7] = f7 ^ x7;+    f[8] = f8 ^ x8;+    f[9] = f9 ^ x9;+}++static void+fe25519_cswap(fe25519 f, fe25519 g, unsigned int b)+{+    const uint32_t mask = (uint32_t) (-(int64_t) b);++    int32_t f0 = f[0];+    int32_t f1 = f[1];+    int32_t f2 = f[2];+    int32_t f3 = f[3];+    int32_t f4 = f[4];+    int32_t f5 = f[5];+    int32_t f6 = f[6];+    int32_t f7 = f[7];+    int32_t f8 = f[8];+    int32_t f9 = f[9];++    int32_t g0 = g[0];+    int32_t g1 = g[1];+    int32_t g2 = g[2];+    int32_t g3 = g[3];+    int32_t g4 = g[4];+    int32_t g5 = g[5];+    int32_t g6 = g[6];+    int32_t g7 = g[7];+    int32_t g8 = g[8];+    int32_t g9 = g[9];++    int32_t x0 = f0 ^ g0;+    int32_t x1 = f1 ^ g1;+    int32_t x2 = f2 ^ g2;+    int32_t x3 = f3 ^ g3;+    int32_t x4 = f4 ^ g4;+    int32_t x5 = f5 ^ g5;+    int32_t x6 = f6 ^ g6;+    int32_t x7 = f7 ^ g7;+    int32_t x8 = f8 ^ g8;+    int32_t x9 = f9 ^ g9;++    x0 &= mask;+    x1 &= mask;+    x2 &= mask;+    x3 &= mask;+    x4 &= mask;+    x5 &= mask;+    x6 &= mask;+    x7 &= mask;+    x8 &= mask;+    x9 &= mask;++    f[0] = f0 ^ x0;+    f[1] = f1 ^ x1;+    f[2] = f2 ^ x2;+    f[3] = f3 ^ x3;+    f[4] = f4 ^ x4;+    f[5] = f5 ^ x5;+    f[6] = f6 ^ x6;+    f[7] = f7 ^ x7;+    f[8] = f8 ^ x8;+    f[9] = f9 ^ x9;++    g[0] = g0 ^ x0;+    g[1] = g1 ^ x1;+    g[2] = g2 ^ x2;+    g[3] = g3 ^ x3;+    g[4] = g4 ^ x4;+    g[5] = g5 ^ x5;+    g[6] = g6 ^ x6;+    g[7] = g7 ^ x7;+    g[8] = g8 ^ x8;+    g[9] = g9 ^ x9;+}++/*+ h = f+ */++static inline void+fe25519_copy(fe25519 h, const fe25519 f)+{+    memcpy(h, f, 10 * sizeof h[0]);+}++/*+ return 1 if f is in {1,3,5,...,q-2}+ return 0 if f is in {0,2,4,...,q-1}++ Preconditions:+ |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.+ */++static inline int+fe25519_isnegative(const fe25519 f)+{+    unsigned char s[32];++    fe25519_tobytes(s, f);++    return s[0] & 1;+}++/*+ return 1 if f == 0+ return 0 if f != 0++ Preconditions:+ |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.+ */++static inline int+fe25519_iszero(const fe25519 f)+{+    unsigned char s[32];++    fe25519_tobytes(s, f);++    return sodium_is_zero(s, 32);+}++/*+ h = f * g+ Can overlap h with f or g.+ *+ Preconditions:+ |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.+ |g| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.+ *+ Postconditions:+ |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.+ */++/*+ Notes on implementation strategy:+ *+ Using schoolbook multiplication.+ Karatsuba would save a little in some cost models.+ *+ Most multiplications by 2 and 19 are 32-bit precomputations;+ cheaper than 64-bit postcomputations.+ *+ There is one remaining multiplication by 19 in the carry chain;+ one *19 precomputation can be merged into this,+ but the resulting data flow is considerably less clean.+ *+ There are 12 carries below.+ 10 of them are 2-way parallelizable and vectorizable.+ Can get away with 11 carries, but then data flow is much deeper.+ *+ With tighter constraints on inputs can squeeze carries into int32.+ */++static void+fe25519_mul(fe25519 h, const fe25519 f, const fe25519 g)+{+    int32_t f0 = f[0];+    int32_t f1 = f[1];+    int32_t f2 = f[2];+    int32_t f3 = f[3];+    int32_t f4 = f[4];+    int32_t f5 = f[5];+    int32_t f6 = f[6];+    int32_t f7 = f[7];+    int32_t f8 = f[8];+    int32_t f9 = f[9];++    int32_t g0 = g[0];+    int32_t g1 = g[1];+    int32_t g2 = g[2];+    int32_t g3 = g[3];+    int32_t g4 = g[4];+    int32_t g5 = g[5];+    int32_t g6 = g[6];+    int32_t g7 = g[7];+    int32_t g8 = g[8];+    int32_t g9 = g[9];++    int32_t g1_19 = 19 * g1; /* 1.959375*2^29 */+    int32_t g2_19 = 19 * g2; /* 1.959375*2^30; still ok */+    int32_t g3_19 = 19 * g3;+    int32_t g4_19 = 19 * g4;+    int32_t g5_19 = 19 * g5;+    int32_t g6_19 = 19 * g6;+    int32_t g7_19 = 19 * g7;+    int32_t g8_19 = 19 * g8;+    int32_t g9_19 = 19 * g9;+    int32_t f1_2  = 2 * f1;+    int32_t f3_2  = 2 * f3;+    int32_t f5_2  = 2 * f5;+    int32_t f7_2  = 2 * f7;+    int32_t f9_2  = 2 * f9;++    int64_t f0g0    = f0 * (int64_t) g0;+    int64_t f0g1    = f0 * (int64_t) g1;+    int64_t f0g2    = f0 * (int64_t) g2;+    int64_t f0g3    = f0 * (int64_t) g3;+    int64_t f0g4    = f0 * (int64_t) g4;+    int64_t f0g5    = f0 * (int64_t) g5;+    int64_t f0g6    = f0 * (int64_t) g6;+    int64_t f0g7    = f0 * (int64_t) g7;+    int64_t f0g8    = f0 * (int64_t) g8;+    int64_t f0g9    = f0 * (int64_t) g9;+    int64_t f1g0    = f1 * (int64_t) g0;+    int64_t f1g1_2  = f1_2 * (int64_t) g1;+    int64_t f1g2    = f1 * (int64_t) g2;+    int64_t f1g3_2  = f1_2 * (int64_t) g3;+    int64_t f1g4    = f1 * (int64_t) g4;+    int64_t f1g5_2  = f1_2 * (int64_t) g5;+    int64_t f1g6    = f1 * (int64_t) g6;+    int64_t f1g7_2  = f1_2 * (int64_t) g7;+    int64_t f1g8    = f1 * (int64_t) g8;+    int64_t f1g9_38 = f1_2 * (int64_t) g9_19;+    int64_t f2g0    = f2 * (int64_t) g0;+    int64_t f2g1    = f2 * (int64_t) g1;+    int64_t f2g2    = f2 * (int64_t) g2;+    int64_t f2g3    = f2 * (int64_t) g3;+    int64_t f2g4    = f2 * (int64_t) g4;+    int64_t f2g5    = f2 * (int64_t) g5;+    int64_t f2g6    = f2 * (int64_t) g6;+    int64_t f2g7    = f2 * (int64_t) g7;+    int64_t f2g8_19 = f2 * (int64_t) g8_19;+    int64_t f2g9_19 = f2 * (int64_t) g9_19;+    int64_t f3g0    = f3 * (int64_t) g0;+    int64_t f3g1_2  = f3_2 * (int64_t) g1;+    int64_t f3g2    = f3 * (int64_t) g2;+    int64_t f3g3_2  = f3_2 * (int64_t) g3;+    int64_t f3g4    = f3 * (int64_t) g4;+    int64_t f3g5_2  = f3_2 * (int64_t) g5;+    int64_t f3g6    = f3 * (int64_t) g6;+    int64_t f3g7_38 = f3_2 * (int64_t) g7_19;+    int64_t f3g8_19 = f3 * (int64_t) g8_19;+    int64_t f3g9_38 = f3_2 * (int64_t) g9_19;+    int64_t f4g0    = f4 * (int64_t) g0;+    int64_t f4g1    = f4 * (int64_t) g1;+    int64_t f4g2    = f4 * (int64_t) g2;+    int64_t f4g3    = f4 * (int64_t) g3;+    int64_t f4g4    = f4 * (int64_t) g4;+    int64_t f4g5    = f4 * (int64_t) g5;+    int64_t f4g6_19 = f4 * (int64_t) g6_19;+    int64_t f4g7_19 = f4 * (int64_t) g7_19;+    int64_t f4g8_19 = f4 * (int64_t) g8_19;+    int64_t f4g9_19 = f4 * (int64_t) g9_19;+    int64_t f5g0    = f5 * (int64_t) g0;+    int64_t f5g1_2  = f5_2 * (int64_t) g1;+    int64_t f5g2    = f5 * (int64_t) g2;+    int64_t f5g3_2  = f5_2 * (int64_t) g3;+    int64_t f5g4    = f5 * (int64_t) g4;+    int64_t f5g5_38 = f5_2 * (int64_t) g5_19;+    int64_t f5g6_19 = f5 * (int64_t) g6_19;+    int64_t f5g7_38 = f5_2 * (int64_t) g7_19;+    int64_t f5g8_19 = f5 * (int64_t) g8_19;+    int64_t f5g9_38 = f5_2 * (int64_t) g9_19;+    int64_t f6g0    = f6 * (int64_t) g0;+    int64_t f6g1    = f6 * (int64_t) g1;+    int64_t f6g2    = f6 * (int64_t) g2;+    int64_t f6g3    = f6 * (int64_t) g3;+    int64_t f6g4_19 = f6 * (int64_t) g4_19;+    int64_t f6g5_19 = f6 * (int64_t) g5_19;+    int64_t f6g6_19 = f6 * (int64_t) g6_19;+    int64_t f6g7_19 = f6 * (int64_t) g7_19;+    int64_t f6g8_19 = f6 * (int64_t) g8_19;+    int64_t f6g9_19 = f6 * (int64_t) g9_19;+    int64_t f7g0    = f7 * (int64_t) g0;+    int64_t f7g1_2  = f7_2 * (int64_t) g1;+    int64_t f7g2    = f7 * (int64_t) g2;+    int64_t f7g3_38 = f7_2 * (int64_t) g3_19;+    int64_t f7g4_19 = f7 * (int64_t) g4_19;+    int64_t f7g5_38 = f7_2 * (int64_t) g5_19;+    int64_t f7g6_19 = f7 * (int64_t) g6_19;+    int64_t f7g7_38 = f7_2 * (int64_t) g7_19;+    int64_t f7g8_19 = f7 * (int64_t) g8_19;+    int64_t f7g9_38 = f7_2 * (int64_t) g9_19;+    int64_t f8g0    = f8 * (int64_t) g0;+    int64_t f8g1    = f8 * (int64_t) g1;+    int64_t f8g2_19 = f8 * (int64_t) g2_19;+    int64_t f8g3_19 = f8 * (int64_t) g3_19;+    int64_t f8g4_19 = f8 * (int64_t) g4_19;+    int64_t f8g5_19 = f8 * (int64_t) g5_19;+    int64_t f8g6_19 = f8 * (int64_t) g6_19;+    int64_t f8g7_19 = f8 * (int64_t) g7_19;+    int64_t f8g8_19 = f8 * (int64_t) g8_19;+    int64_t f8g9_19 = f8 * (int64_t) g9_19;+    int64_t f9g0    = f9 * (int64_t) g0;+    int64_t f9g1_38 = f9_2 * (int64_t) g1_19;+    int64_t f9g2_19 = f9 * (int64_t) g2_19;+    int64_t f9g3_38 = f9_2 * (int64_t) g3_19;+    int64_t f9g4_19 = f9 * (int64_t) g4_19;+    int64_t f9g5_38 = f9_2 * (int64_t) g5_19;+    int64_t f9g6_19 = f9 * (int64_t) g6_19;+    int64_t f9g7_38 = f9_2 * (int64_t) g7_19;+    int64_t f9g8_19 = f9 * (int64_t) g8_19;+    int64_t f9g9_38 = f9_2 * (int64_t) g9_19;++    int64_t h0 = f0g0 + f1g9_38 + f2g8_19 + f3g7_38 + f4g6_19 + f5g5_38 ++                 f6g4_19 + f7g3_38 + f8g2_19 + f9g1_38;+    int64_t h1 = f0g1 + f1g0 + f2g9_19 + f3g8_19 + f4g7_19 + f5g6_19 + f6g5_19 ++                 f7g4_19 + f8g3_19 + f9g2_19;+    int64_t h2 = f0g2 + f1g1_2 + f2g0 + f3g9_38 + f4g8_19 + f5g7_38 + f6g6_19 ++                 f7g5_38 + f8g4_19 + f9g3_38;+    int64_t h3 = f0g3 + f1g2 + f2g1 + f3g0 + f4g9_19 + f5g8_19 + f6g7_19 ++                 f7g6_19 + f8g5_19 + f9g4_19;+    int64_t h4 = f0g4 + f1g3_2 + f2g2 + f3g1_2 + f4g0 + f5g9_38 + f6g8_19 ++                 f7g7_38 + f8g6_19 + f9g5_38;+    int64_t h5 = f0g5 + f1g4 + f2g3 + f3g2 + f4g1 + f5g0 + f6g9_19 + f7g8_19 ++                 f8g7_19 + f9g6_19;+    int64_t h6 = f0g6 + f1g5_2 + f2g4 + f3g3_2 + f4g2 + f5g1_2 + f6g0 ++                 f7g9_38 + f8g8_19 + f9g7_38;+    int64_t h7 = f0g7 + f1g6 + f2g5 + f3g4 + f4g3 + f5g2 + f6g1 + f7g0 ++                 f8g9_19 + f9g8_19;+    int64_t h8 = f0g8 + f1g7_2 + f2g6 + f3g5_2 + f4g4 + f5g3_2 + f6g2 + f7g1_2 ++                 f8g0 + f9g9_38;+    int64_t h9 =+        f0g9 + f1g8 + f2g7 + f3g6 + f4g5 + f5g4 + f6g3 + f7g2 + f8g1 + f9g0;++    int64_t carry0;+    int64_t carry1;+    int64_t carry2;+    int64_t carry3;+    int64_t carry4;+    int64_t carry5;+    int64_t carry6;+    int64_t carry7;+    int64_t carry8;+    int64_t carry9;++    /*+     |h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38))+     i.e. |h0| <= 1.4*2^60; narrower ranges for h2, h4, h6, h8+     |h1| <= (1.65*1.65*2^51*(1+1+19+19+19+19+19+19+19+19))+     i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9+     */++    carry0 = (h0 + (int64_t)(1L << 25)) >> 26;+    h1 += carry0;+    h0 -= carry0 * ((uint64_t) 1L << 26);+    carry4 = (h4 + (int64_t)(1L << 25)) >> 26;+    h5 += carry4;+    h4 -= carry4 * ((uint64_t) 1L << 26);+    /* |h0| <= 2^25 */+    /* |h4| <= 2^25 */+    /* |h1| <= 1.71*2^59 */+    /* |h5| <= 1.71*2^59 */++    carry1 = (h1 + (int64_t)(1L << 24)) >> 25;+    h2 += carry1;+    h1 -= carry1 * ((uint64_t) 1L << 25);+    carry5 = (h5 + (int64_t)(1L << 24)) >> 25;+    h6 += carry5;+    h5 -= carry5 * ((uint64_t) 1L << 25);+    /* |h1| <= 2^24; from now on fits into int32 */+    /* |h5| <= 2^24; from now on fits into int32 */+    /* |h2| <= 1.41*2^60 */+    /* |h6| <= 1.41*2^60 */++    carry2 = (h2 + (int64_t)(1L << 25)) >> 26;+    h3 += carry2;+    h2 -= carry2 * ((uint64_t) 1L << 26);+    carry6 = (h6 + (int64_t)(1L << 25)) >> 26;+    h7 += carry6;+    h6 -= carry6 * ((uint64_t) 1L << 26);+    /* |h2| <= 2^25; from now on fits into int32 unchanged */+    /* |h6| <= 2^25; from now on fits into int32 unchanged */+    /* |h3| <= 1.71*2^59 */+    /* |h7| <= 1.71*2^59 */++    carry3 = (h3 + (int64_t)(1L << 24)) >> 25;+    h4 += carry3;+    h3 -= carry3 * ((uint64_t) 1L << 25);+    carry7 = (h7 + (int64_t)(1L << 24)) >> 25;+    h8 += carry7;+    h7 -= carry7 * ((uint64_t) 1L << 25);+    /* |h3| <= 2^24; from now on fits into int32 unchanged */+    /* |h7| <= 2^24; from now on fits into int32 unchanged */+    /* |h4| <= 1.72*2^34 */+    /* |h8| <= 1.41*2^60 */++    carry4 = (h4 + (int64_t)(1L << 25)) >> 26;+    h5 += carry4;+    h4 -= carry4 * ((uint64_t) 1L << 26);+    carry8 = (h8 + (int64_t)(1L << 25)) >> 26;+    h9 += carry8;+    h8 -= carry8 * ((uint64_t) 1L << 26);+    /* |h4| <= 2^25; from now on fits into int32 unchanged */+    /* |h8| <= 2^25; from now on fits into int32 unchanged */+    /* |h5| <= 1.01*2^24 */+    /* |h9| <= 1.71*2^59 */++    carry9 = (h9 + (int64_t)(1L << 24)) >> 25;+    h0 += carry9 * 19;+    h9 -= carry9 * ((uint64_t) 1L << 25);+    /* |h9| <= 2^24; from now on fits into int32 unchanged */+    /* |h0| <= 1.1*2^39 */++    carry0 = (h0 + (int64_t)(1L << 25)) >> 26;+    h1 += carry0;+    h0 -= carry0 * ((uint64_t) 1L << 26);+    /* |h0| <= 2^25; from now on fits into int32 unchanged */+    /* |h1| <= 1.01*2^24 */++    h[0] = (int32_t) h0;+    h[1] = (int32_t) h1;+    h[2] = (int32_t) h2;+    h[3] = (int32_t) h3;+    h[4] = (int32_t) h4;+    h[5] = (int32_t) h5;+    h[6] = (int32_t) h6;+    h[7] = (int32_t) h7;+    h[8] = (int32_t) h8;+    h[9] = (int32_t) h9;+}++/*+ h = f * f+ Can overlap h with f.+ *+ Preconditions:+ |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.+ *+ Postconditions:+ |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.+ */++static void+fe25519_sq(fe25519 h, const fe25519 f)+{+    int32_t f0 = f[0];+    int32_t f1 = f[1];+    int32_t f2 = f[2];+    int32_t f3 = f[3];+    int32_t f4 = f[4];+    int32_t f5 = f[5];+    int32_t f6 = f[6];+    int32_t f7 = f[7];+    int32_t f8 = f[8];+    int32_t f9 = f[9];++    int32_t f0_2  = 2 * f0;+    int32_t f1_2  = 2 * f1;+    int32_t f2_2  = 2 * f2;+    int32_t f3_2  = 2 * f3;+    int32_t f4_2  = 2 * f4;+    int32_t f5_2  = 2 * f5;+    int32_t f6_2  = 2 * f6;+    int32_t f7_2  = 2 * f7;+    int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */+    int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */+    int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */+    int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */+    int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */++    int64_t f0f0    = f0 * (int64_t) f0;+    int64_t f0f1_2  = f0_2 * (int64_t) f1;+    int64_t f0f2_2  = f0_2 * (int64_t) f2;+    int64_t f0f3_2  = f0_2 * (int64_t) f3;+    int64_t f0f4_2  = f0_2 * (int64_t) f4;+    int64_t f0f5_2  = f0_2 * (int64_t) f5;+    int64_t f0f6_2  = f0_2 * (int64_t) f6;+    int64_t f0f7_2  = f0_2 * (int64_t) f7;+    int64_t f0f8_2  = f0_2 * (int64_t) f8;+    int64_t f0f9_2  = f0_2 * (int64_t) f9;+    int64_t f1f1_2  = f1_2 * (int64_t) f1;+    int64_t f1f2_2  = f1_2 * (int64_t) f2;+    int64_t f1f3_4  = f1_2 * (int64_t) f3_2;+    int64_t f1f4_2  = f1_2 * (int64_t) f4;+    int64_t f1f5_4  = f1_2 * (int64_t) f5_2;+    int64_t f1f6_2  = f1_2 * (int64_t) f6;+    int64_t f1f7_4  = f1_2 * (int64_t) f7_2;+    int64_t f1f8_2  = f1_2 * (int64_t) f8;+    int64_t f1f9_76 = f1_2 * (int64_t) f9_38;+    int64_t f2f2    = f2 * (int64_t) f2;+    int64_t f2f3_2  = f2_2 * (int64_t) f3;+    int64_t f2f4_2  = f2_2 * (int64_t) f4;+    int64_t f2f5_2  = f2_2 * (int64_t) f5;+    int64_t f2f6_2  = f2_2 * (int64_t) f6;+    int64_t f2f7_2  = f2_2 * (int64_t) f7;+    int64_t f2f8_38 = f2_2 * (int64_t) f8_19;+    int64_t f2f9_38 = f2 * (int64_t) f9_38;+    int64_t f3f3_2  = f3_2 * (int64_t) f3;+    int64_t f3f4_2  = f3_2 * (int64_t) f4;+    int64_t f3f5_4  = f3_2 * (int64_t) f5_2;+    int64_t f3f6_2  = f3_2 * (int64_t) f6;+    int64_t f3f7_76 = f3_2 * (int64_t) f7_38;+    int64_t f3f8_38 = f3_2 * (int64_t) f8_19;+    int64_t f3f9_76 = f3_2 * (int64_t) f9_38;+    int64_t f4f4    = f4 * (int64_t) f4;+    int64_t f4f5_2  = f4_2 * (int64_t) f5;+    int64_t f4f6_38 = f4_2 * (int64_t) f6_19;+    int64_t f4f7_38 = f4 * (int64_t) f7_38;+    int64_t f4f8_38 = f4_2 * (int64_t) f8_19;+    int64_t f4f9_38 = f4 * (int64_t) f9_38;+    int64_t f5f5_38 = f5 * (int64_t) f5_38;+    int64_t f5f6_38 = f5_2 * (int64_t) f6_19;+    int64_t f5f7_76 = f5_2 * (int64_t) f7_38;+    int64_t f5f8_38 = f5_2 * (int64_t) f8_19;+    int64_t f5f9_76 = f5_2 * (int64_t) f9_38;+    int64_t f6f6_19 = f6 * (int64_t) f6_19;+    int64_t f6f7_38 = f6 * (int64_t) f7_38;+    int64_t f6f8_38 = f6_2 * (int64_t) f8_19;+    int64_t f6f9_38 = f6 * (int64_t) f9_38;+    int64_t f7f7_38 = f7 * (int64_t) f7_38;+    int64_t f7f8_38 = f7_2 * (int64_t) f8_19;+    int64_t f7f9_76 = f7_2 * (int64_t) f9_38;+    int64_t f8f8_19 = f8 * (int64_t) f8_19;+    int64_t f8f9_38 = f8 * (int64_t) f9_38;+    int64_t f9f9_38 = f9 * (int64_t) f9_38;++    int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38;+    int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38;+    int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19;+    int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38;+    int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38;+    int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38;+    int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19;+    int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38;+    int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38;+    int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2;++    int64_t carry0;+    int64_t carry1;+    int64_t carry2;+    int64_t carry3;+    int64_t carry4;+    int64_t carry5;+    int64_t carry6;+    int64_t carry7;+    int64_t carry8;+    int64_t carry9;++    carry0 = (h0 + (int64_t)(1L << 25)) >> 26;+    h1 += carry0;+    h0 -= carry0 * ((uint64_t) 1L << 26);+    carry4 = (h4 + (int64_t)(1L << 25)) >> 26;+    h5 += carry4;+    h4 -= carry4 * ((uint64_t) 1L << 26);++    carry1 = (h1 + (int64_t)(1L << 24)) >> 25;+    h2 += carry1;+    h1 -= carry1 * ((uint64_t) 1L << 25);+    carry5 = (h5 + (int64_t)(1L << 24)) >> 25;+    h6 += carry5;+    h5 -= carry5 * ((uint64_t) 1L << 25);++    carry2 = (h2 + (int64_t)(1L << 25)) >> 26;+    h3 += carry2;+    h2 -= carry2 * ((uint64_t) 1L << 26);+    carry6 = (h6 + (int64_t)(1L << 25)) >> 26;+    h7 += carry6;+    h6 -= carry6 * ((uint64_t) 1L << 26);++    carry3 = (h3 + (int64_t)(1L << 24)) >> 25;+    h4 += carry3;+    h3 -= carry3 * ((uint64_t) 1L << 25);+    carry7 = (h7 + (int64_t)(1L << 24)) >> 25;+    h8 += carry7;+    h7 -= carry7 * ((uint64_t) 1L << 25);++    carry4 = (h4 + (int64_t)(1L << 25)) >> 26;+    h5 += carry4;+    h4 -= carry4 * ((uint64_t) 1L << 26);+    carry8 = (h8 + (int64_t)(1L << 25)) >> 26;+    h9 += carry8;+    h8 -= carry8 * ((uint64_t) 1L << 26);++    carry9 = (h9 + (int64_t)(1L << 24)) >> 25;+    h0 += carry9 * 19;+    h9 -= carry9 * ((uint64_t) 1L << 25);++    carry0 = (h0 + (int64_t)(1L << 25)) >> 26;+    h1 += carry0;+    h0 -= carry0 * ((uint64_t) 1L << 26);++    h[0] = (int32_t) h0;+    h[1] = (int32_t) h1;+    h[2] = (int32_t) h2;+    h[3] = (int32_t) h3;+    h[4] = (int32_t) h4;+    h[5] = (int32_t) h5;+    h[6] = (int32_t) h6;+    h[7] = (int32_t) h7;+    h[8] = (int32_t) h8;+    h[9] = (int32_t) h9;+}++/*+ h = 2 * f * f+ Can overlap h with f.+ *+ Preconditions:+ |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.+ *+ Postconditions:+ |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.+ */++static void+fe25519_sq2(fe25519 h, const fe25519 f)+{+    int32_t f0 = f[0];+    int32_t f1 = f[1];+    int32_t f2 = f[2];+    int32_t f3 = f[3];+    int32_t f4 = f[4];+    int32_t f5 = f[5];+    int32_t f6 = f[6];+    int32_t f7 = f[7];+    int32_t f8 = f[8];+    int32_t f9 = f[9];++    int32_t f0_2  = 2 * f0;+    int32_t f1_2  = 2 * f1;+    int32_t f2_2  = 2 * f2;+    int32_t f3_2  = 2 * f3;+    int32_t f4_2  = 2 * f4;+    int32_t f5_2  = 2 * f5;+    int32_t f6_2  = 2 * f6;+    int32_t f7_2  = 2 * f7;+    int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */+    int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */+    int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */+    int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */+    int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */++    int64_t f0f0    = f0 * (int64_t) f0;+    int64_t f0f1_2  = f0_2 * (int64_t) f1;+    int64_t f0f2_2  = f0_2 * (int64_t) f2;+    int64_t f0f3_2  = f0_2 * (int64_t) f3;+    int64_t f0f4_2  = f0_2 * (int64_t) f4;+    int64_t f0f5_2  = f0_2 * (int64_t) f5;+    int64_t f0f6_2  = f0_2 * (int64_t) f6;+    int64_t f0f7_2  = f0_2 * (int64_t) f7;+    int64_t f0f8_2  = f0_2 * (int64_t) f8;+    int64_t f0f9_2  = f0_2 * (int64_t) f9;+    int64_t f1f1_2  = f1_2 * (int64_t) f1;+    int64_t f1f2_2  = f1_2 * (int64_t) f2;+    int64_t f1f3_4  = f1_2 * (int64_t) f3_2;+    int64_t f1f4_2  = f1_2 * (int64_t) f4;+    int64_t f1f5_4  = f1_2 * (int64_t) f5_2;+    int64_t f1f6_2  = f1_2 * (int64_t) f6;+    int64_t f1f7_4  = f1_2 * (int64_t) f7_2;+    int64_t f1f8_2  = f1_2 * (int64_t) f8;+    int64_t f1f9_76 = f1_2 * (int64_t) f9_38;+    int64_t f2f2    = f2 * (int64_t) f2;+    int64_t f2f3_2  = f2_2 * (int64_t) f3;+    int64_t f2f4_2  = f2_2 * (int64_t) f4;+    int64_t f2f5_2  = f2_2 * (int64_t) f5;+    int64_t f2f6_2  = f2_2 * (int64_t) f6;+    int64_t f2f7_2  = f2_2 * (int64_t) f7;+    int64_t f2f8_38 = f2_2 * (int64_t) f8_19;+    int64_t f2f9_38 = f2 * (int64_t) f9_38;+    int64_t f3f3_2  = f3_2 * (int64_t) f3;+    int64_t f3f4_2  = f3_2 * (int64_t) f4;+    int64_t f3f5_4  = f3_2 * (int64_t) f5_2;+    int64_t f3f6_2  = f3_2 * (int64_t) f6;+    int64_t f3f7_76 = f3_2 * (int64_t) f7_38;+    int64_t f3f8_38 = f3_2 * (int64_t) f8_19;+    int64_t f3f9_76 = f3_2 * (int64_t) f9_38;+    int64_t f4f4    = f4 * (int64_t) f4;+    int64_t f4f5_2  = f4_2 * (int64_t) f5;+    int64_t f4f6_38 = f4_2 * (int64_t) f6_19;+    int64_t f4f7_38 = f4 * (int64_t) f7_38;+    int64_t f4f8_38 = f4_2 * (int64_t) f8_19;+    int64_t f4f9_38 = f4 * (int64_t) f9_38;+    int64_t f5f5_38 = f5 * (int64_t) f5_38;+    int64_t f5f6_38 = f5_2 * (int64_t) f6_19;+    int64_t f5f7_76 = f5_2 * (int64_t) f7_38;+    int64_t f5f8_38 = f5_2 * (int64_t) f8_19;+    int64_t f5f9_76 = f5_2 * (int64_t) f9_38;+    int64_t f6f6_19 = f6 * (int64_t) f6_19;+    int64_t f6f7_38 = f6 * (int64_t) f7_38;+    int64_t f6f8_38 = f6_2 * (int64_t) f8_19;+    int64_t f6f9_38 = f6 * (int64_t) f9_38;+    int64_t f7f7_38 = f7 * (int64_t) f7_38;+    int64_t f7f8_38 = f7_2 * (int64_t) f8_19;+    int64_t f7f9_76 = f7_2 * (int64_t) f9_38;+    int64_t f8f8_19 = f8 * (int64_t) f8_19;+    int64_t f8f9_38 = f8 * (int64_t) f9_38;+    int64_t f9f9_38 = f9 * (int64_t) f9_38;++    int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38;+    int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38;+    int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19;+    int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38;+    int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38;+    int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38;+    int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19;+    int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38;+    int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38;+    int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2;++    int64_t carry0;+    int64_t carry1;+    int64_t carry2;+    int64_t carry3;+    int64_t carry4;+    int64_t carry5;+    int64_t carry6;+    int64_t carry7;+    int64_t carry8;+    int64_t carry9;++    h0 += h0;+    h1 += h1;+    h2 += h2;+    h3 += h3;+    h4 += h4;+    h5 += h5;+    h6 += h6;+    h7 += h7;+    h8 += h8;+    h9 += h9;++    carry0 = (h0 + (int64_t)(1L << 25)) >> 26;+    h1 += carry0;+    h0 -= carry0 * ((uint64_t) 1L << 26);+    carry4 = (h4 + (int64_t)(1L << 25)) >> 26;+    h5 += carry4;+    h4 -= carry4 * ((uint64_t) 1L << 26);++    carry1 = (h1 + (int64_t)(1L << 24)) >> 25;+    h2 += carry1;+    h1 -= carry1 * ((uint64_t) 1L << 25);+    carry5 = (h5 + (int64_t)(1L << 24)) >> 25;+    h6 += carry5;+    h5 -= carry5 * ((uint64_t) 1L << 25);++    carry2 = (h2 + (int64_t)(1L << 25)) >> 26;+    h3 += carry2;+    h2 -= carry2 * ((uint64_t) 1L << 26);+    carry6 = (h6 + (int64_t)(1L << 25)) >> 26;+    h7 += carry6;+    h6 -= carry6 * ((uint64_t) 1L << 26);++    carry3 = (h3 + (int64_t)(1L << 24)) >> 25;+    h4 += carry3;+    h3 -= carry3 * ((uint64_t) 1L << 25);+    carry7 = (h7 + (int64_t)(1L << 24)) >> 25;+    h8 += carry7;+    h7 -= carry7 * ((uint64_t) 1L << 25);++    carry4 = (h4 + (int64_t)(1L << 25)) >> 26;+    h5 += carry4;+    h4 -= carry4 * ((uint64_t) 1L << 26);+    carry8 = (h8 + (int64_t)(1L << 25)) >> 26;+    h9 += carry8;+    h8 -= carry8 * ((uint64_t) 1L << 26);++    carry9 = (h9 + (int64_t)(1L << 24)) >> 25;+    h0 += carry9 * 19;+    h9 -= carry9 * ((uint64_t) 1L << 25);++    carry0 = (h0 + (int64_t)(1L << 25)) >> 26;+    h1 += carry0;+    h0 -= carry0 * ((uint64_t) 1L << 26);++    h[0] = (int32_t) h0;+    h[1] = (int32_t) h1;+    h[2] = (int32_t) h2;+    h[3] = (int32_t) h3;+    h[4] = (int32_t) h4;+    h[5] = (int32_t) h5;+    h[6] = (int32_t) h6;+    h[7] = (int32_t) h7;+    h[8] = (int32_t) h8;+    h[9] = (int32_t) h9;+}++static inline void+fe25519_mul32(fe25519 h, const fe25519 f, uint32_t n)+{+    int64_t sn = (int64_t) n;+    int32_t f0 = f[0];+    int32_t f1 = f[1];+    int32_t f2 = f[2];+    int32_t f3 = f[3];+    int32_t f4 = f[4];+    int32_t f5 = f[5];+    int32_t f6 = f[6];+    int32_t f7 = f[7];+    int32_t f8 = f[8];+    int32_t f9 = f[9];+    int64_t h0 = f0 * sn;+    int64_t h1 = f1 * sn;+    int64_t h2 = f2 * sn;+    int64_t h3 = f3 * sn;+    int64_t h4 = f4 * sn;+    int64_t h5 = f5 * sn;+    int64_t h6 = f6 * sn;+    int64_t h7 = f7 * sn;+    int64_t h8 = f8 * sn;+    int64_t h9 = f9 * sn;+    int64_t carry0, carry1, carry2, carry3, carry4, carry5, carry6, carry7,+            carry8, carry9;++    carry9 = (h9 + ((int64_t) 1 << 24)) >> 25;+    h0 += carry9 * 19;+    h9 -= carry9 * ((int64_t) 1 << 25);+    carry1 = (h1 + ((int64_t) 1 << 24)) >> 25;+    h2 += carry1;+    h1 -= carry1 * ((int64_t) 1 << 25);+    carry3 = (h3 + ((int64_t) 1 << 24)) >> 25;+    h4 += carry3;+    h3 -= carry3 * ((int64_t) 1 << 25);+    carry5 = (h5 + ((int64_t) 1 << 24)) >> 25;+    h6 += carry5;+    h5 -= carry5 * ((int64_t) 1 << 25);+    carry7 = (h7 + ((int64_t) 1 << 24)) >> 25;+    h8 += carry7;+    h7 -= carry7 * ((int64_t) 1 << 25);++    carry0 = (h0 + ((int64_t) 1 << 25)) >> 26;+    h1 += carry0;+    h0 -= carry0 * ((int64_t) 1 << 26);+    carry2 = (h2 + ((int64_t) 1 << 25)) >> 26;+    h3 += carry2;+    h2 -= carry2 * ((int64_t) 1 << 26);+    carry4 = (h4 + ((int64_t) 1 << 25)) >> 26;+    h5 += carry4;+    h4 -= carry4 * ((int64_t) 1 << 26);+    carry6 = (h6 + ((int64_t) 1 << 25)) >> 26;+    h7 += carry6;+    h6 -= carry6 * ((int64_t) 1 << 26);+    carry8 = (h8 + ((int64_t) 1 << 25)) >> 26;+    h9 += carry8;+    h8 -= carry8 * ((int64_t) 1 << 26);++    h[0] = (int32_t) h0;+    h[1] = (int32_t) h1;+    h[2] = (int32_t) h2;+    h[3] = (int32_t) h3;+    h[4] = (int32_t) h4;+    h[5] = (int32_t) h5;+    h[6] = (int32_t) h6;+    h[7] = (int32_t) h7;+    h[8] = (int32_t) h8;+    h[9] = (int32_t) h9;+}
+ vendor/external/libsodium/include/sodium/private/ed25519_ref10_fe_51.h view
@@ -0,0 +1,508 @@+#include <string.h>++#include "private/common.h"+#include "utils.h"++/*+ h = 0+ */++static inline void+fe25519_0(fe25519 h)+{+    memset(&h[0], 0, 5 * sizeof h[0]);+}++/*+ h = 1+ */++static inline void+fe25519_1(fe25519 h)+{+    h[0] = 1;+    memset(&h[1], 0, 4 * sizeof h[0]);+}++/*+ h = f + g+ Can overlap h with f or g.+ */++static inline void+fe25519_add(fe25519 h, const fe25519 f, const fe25519 g)+{+    uint64_t h0 = f[0] + g[0];+    uint64_t h1 = f[1] + g[1];+    uint64_t h2 = f[2] + g[2];+    uint64_t h3 = f[3] + g[3];+    uint64_t h4 = f[4] + g[4];++    h[0] = h0;+    h[1] = h1;+    h[2] = h2;+    h[3] = h3;+    h[4] = h4;+}++/*+ h = f - g+ */++static void+fe25519_sub(fe25519 h, const fe25519 f, const fe25519 g)+{+    const uint64_t mask = 0x7ffffffffffffULL;+    uint64_t h0, h1, h2, h3, h4;++    h0 = g[0];+    h1 = g[1];+    h2 = g[2];+    h3 = g[3];+    h4 = g[4];++    h1 += h0 >> 51;+    h0 &= mask;+    h2 += h1 >> 51;+    h1 &= mask;+    h3 += h2 >> 51;+    h2 &= mask;+    h4 += h3 >> 51;+    h3 &= mask;+    h0 += 19ULL * (h4 >> 51);+    h4 &= mask;++    h0 = (f[0] + 0xfffffffffffdaULL) - h0;+    h1 = (f[1] + 0xffffffffffffeULL) - h1;+    h2 = (f[2] + 0xffffffffffffeULL) - h2;+    h3 = (f[3] + 0xffffffffffffeULL) - h3;+    h4 = (f[4] + 0xffffffffffffeULL) - h4;++    h[0] = h0;+    h[1] = h1;+    h[2] = h2;+    h[3] = h3;+    h[4] = h4;+}++/*+ h = -f+ */++static inline void+fe25519_neg(fe25519 h, const fe25519 f)+{+    fe25519 zero;++    fe25519_0(zero);+    fe25519_sub(h, zero, f);+}++/*+ Replace (f,g) with (g,g) if b == 1;+ replace (f,g) with (f,g) if b == 0.+ *+ Preconditions: b in {0,1}.+ */++static void+fe25519_cmov(fe25519 f, const fe25519 g, unsigned int b)+{+    const uint64_t mask = (uint64_t) (-(int64_t) b);++    uint64_t f0 = f[0];+    uint64_t f1 = f[1];+    uint64_t f2 = f[2];+    uint64_t f3 = f[3];+    uint64_t f4 = f[4];++    uint64_t x0 = f0 ^ g[0];+    uint64_t x1 = f1 ^ g[1];+    uint64_t x2 = f2 ^ g[2];+    uint64_t x3 = f3 ^ g[3];+    uint64_t x4 = f4 ^ g[4];++    x0 &= mask;+    x1 &= mask;+    x2 &= mask;+    x3 &= mask;+    x4 &= mask;++    f[0] = f0 ^ x0;+    f[1] = f1 ^ x1;+    f[2] = f2 ^ x2;+    f[3] = f3 ^ x3;+    f[4] = f4 ^ x4;+}++/*+Replace (f,g) with (g,f) if b == 1;+replace (f,g) with (f,g) if b == 0.++Preconditions: b in {0,1}.+*/++static void+fe25519_cswap(fe25519 f, fe25519 g, unsigned int b)+{+    const uint64_t mask = (uint64_t) (-(int64_t) b);++    uint64_t f0 = f[0];+    uint64_t f1 = f[1];+    uint64_t f2 = f[2];+    uint64_t f3 = f[3];+    uint64_t f4 = f[4];++    uint64_t g0 = g[0];+    uint64_t g1 = g[1];+    uint64_t g2 = g[2];+    uint64_t g3 = g[3];+    uint64_t g4 = g[4];++    uint64_t x0 = f0 ^ g0;+    uint64_t x1 = f1 ^ g1;+    uint64_t x2 = f2 ^ g2;+    uint64_t x3 = f3 ^ g3;+    uint64_t x4 = f4 ^ g4;++    x0 &= mask;+    x1 &= mask;+    x2 &= mask;+    x3 &= mask;+    x4 &= mask;++    f[0] = f0 ^ x0;+    f[1] = f1 ^ x1;+    f[2] = f2 ^ x2;+    f[3] = f3 ^ x3;+    f[4] = f4 ^ x4;++    g[0] = g0 ^ x0;+    g[1] = g1 ^ x1;+    g[2] = g2 ^ x2;+    g[3] = g3 ^ x3;+    g[4] = g4 ^ x4;+}++/*+ h = f+ */++static inline void+fe25519_copy(fe25519 h, const fe25519 f)+{+    memcpy(h, f, 5 * sizeof h[0]);+}++/*+ return 1 if f is in {1,3,5,...,q-2}+ return 0 if f is in {0,2,4,...,q-1}+ */++static inline int+fe25519_isnegative(const fe25519 f)+{+    unsigned char s[32];++    fe25519_tobytes(s, f);++    return s[0] & 1;+}++/*+ return 1 if f == 0+ return 0 if f != 0+ */++static inline int+fe25519_iszero(const fe25519 f)+{+    unsigned char s[32];++    fe25519_tobytes(s, f);++    return sodium_is_zero(s, 32);+}++/*+ h = f * g+ Can overlap h with f or g.+ */++static void+fe25519_mul(fe25519 h, const fe25519 f, const fe25519 g)+{+    const uint64_t mask = 0x7ffffffffffffULL;+    uint128_t r0, r1, r2, r3, r4, carry;+    uint64_t  f0, f1, f2, f3, f4;+    uint64_t  f1_19, f2_19, f3_19, f4_19;+    uint64_t  g0, g1, g2, g3, g4;+    uint64_t  r00, r01, r02, r03, r04;++    f0 = f[0];+    f1 = f[1];+    f2 = f[2];+    f3 = f[3];+    f4 = f[4];++    g0 = g[0];+    g1 = g[1];+    g2 = g[2];+    g3 = g[3];+    g4 = g[4];++    f1_19 = 19ULL * f1;+    f2_19 = 19ULL * f2;+    f3_19 = 19ULL * f3;+    f4_19 = 19ULL * f4;++    r0  = ((uint128_t) f0   ) * ((uint128_t) g0);+    r0 += ((uint128_t) f1_19) * ((uint128_t) g4);+    r0 += ((uint128_t) f2_19) * ((uint128_t) g3);+    r0 += ((uint128_t) f3_19) * ((uint128_t) g2);+    r0 += ((uint128_t) f4_19) * ((uint128_t) g1);++    r1  = ((uint128_t) f0   ) * ((uint128_t) g1);+    r1 += ((uint128_t) f1   ) * ((uint128_t) g0);+    r1 += ((uint128_t) f2_19) * ((uint128_t) g4);+    r1 += ((uint128_t) f3_19) * ((uint128_t) g3);+    r1 += ((uint128_t) f4_19) * ((uint128_t) g2);++    r2  = ((uint128_t) f0   ) * ((uint128_t) g2);+    r2 += ((uint128_t) f1   ) * ((uint128_t) g1);+    r2 += ((uint128_t) f2   ) * ((uint128_t) g0);+    r2 += ((uint128_t) f3_19) * ((uint128_t) g4);+    r2 += ((uint128_t) f4_19) * ((uint128_t) g3);++    r3  = ((uint128_t) f0   ) * ((uint128_t) g3);+    r3 += ((uint128_t) f1   ) * ((uint128_t) g2);+    r3 += ((uint128_t) f2   ) * ((uint128_t) g1);+    r3 += ((uint128_t) f3   ) * ((uint128_t) g0);+    r3 += ((uint128_t) f4_19) * ((uint128_t) g4);++    r4  = ((uint128_t) f0   ) * ((uint128_t) g4);+    r4 += ((uint128_t) f1   ) * ((uint128_t) g3);+    r4 += ((uint128_t) f2   ) * ((uint128_t) g2);+    r4 += ((uint128_t) f3   ) * ((uint128_t) g1);+    r4 += ((uint128_t) f4   ) * ((uint128_t) g0);++    r00    = ((uint64_t) r0) & mask;+    carry  = r0 >> 51;+    r1    += carry;+    r01    = ((uint64_t) r1) & mask;+    carry  = r1 >> 51;+    r2    += carry;+    r02    = ((uint64_t) r2) & mask;+    carry  = r2 >> 51;+    r3    += carry;+    r03    = ((uint64_t) r3) & mask;+    carry  = r3 >> 51;+    r4    += carry;+    r04    = ((uint64_t) r4) & mask;+    carry  = r4 >> 51;+    r00   += 19ULL * (uint64_t) carry;+    carry  = r00 >> 51;+    r00   &= mask;+    r01   += (uint64_t) carry;+    carry  = r01 >> 51;+    r01   &= mask;+    r02   += (uint64_t) carry;++    h[0] = r00;+    h[1] = r01;+    h[2] = r02;+    h[3] = r03;+    h[4] = r04;+}++/*+ h = f * f+ Can overlap h with f.+ */++static void+fe25519_sq(fe25519 h, const fe25519 f)+{+    const uint64_t mask = 0x7ffffffffffffULL;+    uint128_t r0, r1, r2, r3, r4, carry;+    uint64_t  f0, f1, f2, f3, f4;+    uint64_t  f0_2, f1_2, f1_38, f2_38, f3_38, f3_19, f4_19;+    uint64_t  r00, r01, r02, r03, r04;++    f0 = f[0];+    f1 = f[1];+    f2 = f[2];+    f3 = f[3];+    f4 = f[4];++    f0_2 = f0 << 1;+    f1_2 = f1 << 1;++    f1_38 = 38ULL * f1;+    f2_38 = 38ULL * f2;+    f3_38 = 38ULL * f3;++    f3_19 = 19ULL * f3;+    f4_19 = 19ULL * f4;++    r0  = ((uint128_t) f0   ) * ((uint128_t) f0);+    r0 += ((uint128_t) f1_38) * ((uint128_t) f4);+    r0 += ((uint128_t) f2_38) * ((uint128_t) f3);++    r1  = ((uint128_t) f0_2 ) * ((uint128_t) f1);+    r1 += ((uint128_t) f2_38) * ((uint128_t) f4);+    r1 += ((uint128_t) f3_19) * ((uint128_t) f3);++    r2  = ((uint128_t) f0_2 ) * ((uint128_t) f2);+    r2 += ((uint128_t) f1   ) * ((uint128_t) f1);+    r2 += ((uint128_t) f3_38) * ((uint128_t) f4);++    r3  = ((uint128_t) f0_2 ) * ((uint128_t) f3);+    r3 += ((uint128_t) f1_2 ) * ((uint128_t) f2);+    r3 += ((uint128_t) f4_19) * ((uint128_t) f4);++    r4  = ((uint128_t) f0_2 ) * ((uint128_t) f4);+    r4 += ((uint128_t) f1_2 ) * ((uint128_t) f3);+    r4 += ((uint128_t) f2   ) * ((uint128_t) f2);++    r00    = ((uint64_t) r0) & mask;+    carry  = r0 >> 51;+    r1    += carry;+    r01    = ((uint64_t) r1) & mask;+    carry  = r1 >> 51;+    r2    += carry;+    r02    = ((uint64_t) r2) & mask;+    carry  = r2 >> 51;+    r3    += carry;+    r03    = ((uint64_t) r3) & mask;+    carry  = r3 >> 51;+    r4    += carry;+    r04    = ((uint64_t) r4) & mask;+    carry  = r4 >> 51;+    r00   += 19ULL * (uint64_t) carry;+    carry  = r00 >> 51;+    r00   &= mask;+    r01   += (uint64_t) carry;+    carry  = r01 >> 51;+    r01   &= mask;+    r02   += (uint64_t) carry;++    h[0] = r00;+    h[1] = r01;+    h[2] = r02;+    h[3] = r03;+    h[4] = r04;+}++/*+ h = 2 * f * f+ Can overlap h with f.+*/++static void+fe25519_sq2(fe25519 h, const fe25519 f)+{+    const uint64_t mask = 0x7ffffffffffffULL;+    uint128_t r0, r1, r2, r3, r4, carry;+    uint64_t  f0, f1, f2, f3, f4;+    uint64_t  f0_2, f1_2, f1_38, f2_38, f3_38, f3_19, f4_19;+    uint64_t  r00, r01, r02, r03, r04;++    f0 = f[0];+    f1 = f[1];+    f2 = f[2];+    f3 = f[3];+    f4 = f[4];++    f0_2 = f0 << 1;+    f1_2 = f1 << 1;++    f1_38 = 38ULL * f1;+    f2_38 = 38ULL * f2;+    f3_38 = 38ULL * f3;++    f3_19 = 19ULL * f3;+    f4_19 = 19ULL * f4;++    r0  = ((uint128_t) f0   ) * ((uint128_t) f0);+    r0 += ((uint128_t) f1_38) * ((uint128_t) f4);+    r0 += ((uint128_t) f2_38) * ((uint128_t) f3);++    r1  = ((uint128_t) f0_2 ) * ((uint128_t) f1);+    r1 += ((uint128_t) f2_38) * ((uint128_t) f4);+    r1 += ((uint128_t) f3_19) * ((uint128_t) f3);++    r2  = ((uint128_t) f0_2 ) * ((uint128_t) f2);+    r2 += ((uint128_t) f1   ) * ((uint128_t) f1);+    r2 += ((uint128_t) f3_38) * ((uint128_t) f4);++    r3  = ((uint128_t) f0_2 ) * ((uint128_t) f3);+    r3 += ((uint128_t) f1_2 ) * ((uint128_t) f2);+    r3 += ((uint128_t) f4_19) * ((uint128_t) f4);++    r4  = ((uint128_t) f0_2 ) * ((uint128_t) f4);+    r4 += ((uint128_t) f1_2 ) * ((uint128_t) f3);+    r4 += ((uint128_t) f2   ) * ((uint128_t) f2);++    r0 <<= 1;+    r1 <<= 1;+    r2 <<= 1;+    r3 <<= 1;+    r4 <<= 1;++    r00    = ((uint64_t) r0) & mask;+    carry  = r0 >> 51;+    r1    += carry;+    r01    = ((uint64_t) r1) & mask;+    carry  = r1 >> 51;+    r2    += carry;+    r02    = ((uint64_t) r2) & mask;+    carry  = r2 >> 51;+    r3    += carry;+    r03    = ((uint64_t) r3) & mask;+    carry  = r3 >> 51;+    r4    += carry;+    r04    = ((uint64_t) r4) & mask;+    carry  = r4 >> 51;+    r00   += 19ULL * (uint64_t) carry;+    carry  = r00 >> 51;+    r00   &= mask;+    r01   += (uint64_t) carry;+    carry  = r01 >> 51;+    r01   &= mask;+    r02   += (uint64_t) carry;++    h[0] = r00;+    h[1] = r01;+    h[2] = r02;+    h[3] = r03;+    h[4] = r04;+}++static inline void+fe25519_mul32(fe25519 h, const fe25519 f, uint32_t n)+{+    const uint64_t mask = 0x7ffffffffffffULL;+    uint128_t a;+    uint128_t sn = (uint128_t) n;+    uint64_t  h0, h1, h2, h3, h4;++    a  = f[0] * sn;+    h0 = ((uint64_t) a) & mask;+    a  = f[1] * sn + ((uint64_t) (a >> 51));+    h1 = ((uint64_t) a) & mask;+    a  = f[2] * sn + ((uint64_t) (a >> 51));+    h2 = ((uint64_t) a) & mask;+    a  = f[3] * sn + ((uint64_t) (a >> 51));+    h3 = ((uint64_t) a) & mask;+    a  = f[4] * sn + ((uint64_t) (a >> 51));+    h4 = ((uint64_t) a) & mask;++    h0 += (a >> 51) * 19ULL;++    h[0] = h0;+    h[1] = h1;+    h[2] = h2;+    h[3] = h3;+    h[4] = h4;+}
+ vendor/external/libsodium/include/sodium/private/implementations.h view
@@ -0,0 +1,13 @@+#ifndef implementations_H+#define implementations_H++int _crypto_generichash_blake2b_pick_best_implementation(void);+int _crypto_onetimeauth_poly1305_pick_best_implementation(void);+int _crypto_pwhash_argon2_pick_best_implementation(void);+int _crypto_scalarmult_curve25519_pick_best_implementation(void);+int _crypto_stream_chacha20_pick_best_implementation(void);+int _crypto_stream_salsa20_pick_best_implementation(void);+int _crypto_aead_aegis128l_pick_best_implementation(void);+int _crypto_aead_aegis256_pick_best_implementation(void);++#endif
+ vendor/external/libsodium/include/sodium/private/mutex.h view
@@ -0,0 +1,7 @@+#ifndef mutex_H+#define mutex_H 1++extern int sodium_crit_enter(void);+extern int sodium_crit_leave(void);++#endif
+ vendor/external/libsodium/include/sodium/private/softaes.h view
@@ -0,0 +1,56 @@+#ifndef softaes_H+#define softaes_H 1++#include <stdint.h>++#include "private/common.h"++typedef struct SoftAesBlock {+    uint32_t w0;+    uint32_t w1;+    uint32_t w2;+    uint32_t w3;+} SoftAesBlock;++SoftAesBlock softaes_block_encrypt(const SoftAesBlock block, const SoftAesBlock rk);++static inline SoftAesBlock+softaes_block_load(const uint8_t in[16])+{+    const SoftAesBlock out = { LOAD32_LE(in + 0), LOAD32_LE(in + 4), LOAD32_LE(in + 8),+                               LOAD32_LE(in + 12) };+    return out;+}++static inline SoftAesBlock+softaes_block_load64x2(const uint64_t a, const uint64_t b)+{+    const SoftAesBlock out = { (uint32_t) b, (uint32_t) (b >> 32), (uint32_t) a,+                               (uint32_t) (a >> 32) };+    return out;+}++static inline void+softaes_block_store(uint8_t out[16], const SoftAesBlock in)+{+    STORE32_LE(out + 0, in.w0);+    STORE32_LE(out + 4, in.w1);+    STORE32_LE(out + 8, in.w2);+    STORE32_LE(out + 12, in.w3);+}++static inline SoftAesBlock+softaes_block_xor(const SoftAesBlock a, const SoftAesBlock b)+{+    const SoftAesBlock out = { a.w0 ^ b.w0, a.w1 ^ b.w1, a.w2 ^ b.w2, a.w3 ^ b.w3 };+    return out;+}++static inline SoftAesBlock+softaes_block_and(const SoftAesBlock a, const SoftAesBlock b)+{+    const SoftAesBlock out = { a.w0 & b.w0, a.w1 & b.w1, a.w2 & b.w2, a.w3 & b.w3 };+    return out;+}++#endif
+ vendor/external/libsodium/include/sodium/private/sse2_64_32.h view
@@ -0,0 +1,50 @@+#ifndef sse2_64_32_H+#define sse2_64_32_H 1++#include "private/common.h"++#ifdef HAVE_INTRIN_H+# include <intrin.h>+#endif++#if defined(HAVE_EMMINTRIN_H) && \+    !(defined(__amd64) || defined(__amd64__) || defined(__x86_64__) || \+      defined(_M_X64) || defined(_M_AMD64))++# include <emmintrin.h>+# include <stdint.h>++# ifndef _mm_set_epi64x+#  define _mm_set_epi64x(Q0, Q1) sodium__mm_set_epi64x((Q0), (Q1))+static inline __m128i+sodium__mm_set_epi64x(int64_t q1, int64_t q0)+{+    union { int64_t as64; int32_t as32[2]; } x0, x1;+    x0.as64 = q0; x1.as64 = q1;+    return _mm_set_epi32(x1.as32[1], x1.as32[0], x0.as32[1], x0.as32[0]);+}+# endif++# ifndef _mm_set1_epi64x+#  define _mm_set1_epi64x(Q) sodium__mm_set1_epi64x(Q)+static inline __m128i+sodium__mm_set1_epi64x(int64_t q)+{+    return _mm_set_epi64x(q, q);+}+# endif++# ifndef _mm_cvtsi64_si128+#  define _mm_cvtsi64_si128(Q) sodium__mm_cvtsi64_si128(Q)+static inline __m128i+sodium__mm_cvtsi64_si128(int64_t q)+{+    union { int64_t as64; int32_t as32[2]; } x;+    x.as64 = q;+    return _mm_setr_epi32(x.as32[0], x.as32[1], 0, 0);+}+# endif++#endif++#endif
+ vendor/external/libsodium/include/sodium/randombytes.h view
@@ -0,0 +1,72 @@++#ifndef randombytes_H+#define randombytes_H++#include <stddef.h>+#include <stdint.h>++#include <sys/types.h>++#include "export.h"++#ifdef __cplusplus+# ifdef __GNUC__+#  pragma GCC diagnostic ignored "-Wlong-long"+# endif+extern "C" {+#endif++typedef struct randombytes_implementation {+    const char *(*implementation_name)(void); /* required */+    uint32_t    (*random)(void);              /* required */+    void        (*stir)(void);                /* optional */+    uint32_t    (*uniform)(const uint32_t upper_bound); /* optional, a default implementation will be used if NULL */+    void        (*buf)(void * const buf, const size_t size); /* required */+    int         (*close)(void);               /* optional */+} randombytes_implementation;++#define randombytes_BYTES_MAX SODIUM_MIN(SODIUM_SIZE_MAX, 0xffffffffUL)++#define randombytes_SEEDBYTES 32U+SODIUM_EXPORT+size_t randombytes_seedbytes(void);++SODIUM_EXPORT+void randombytes_buf(void * const buf, const size_t size)+            __attribute__ ((nonnull));++SODIUM_EXPORT+void randombytes_buf_deterministic(void * const buf, const size_t size,+                                   const unsigned char seed[randombytes_SEEDBYTES])+            __attribute__ ((nonnull));++SODIUM_EXPORT+uint32_t randombytes_random(void);++SODIUM_EXPORT+uint32_t randombytes_uniform(const uint32_t upper_bound);++SODIUM_EXPORT+void randombytes_stir(void);++SODIUM_EXPORT+int randombytes_close(void);++SODIUM_EXPORT+int randombytes_set_implementation(const randombytes_implementation *impl)+            __attribute__ ((nonnull));++SODIUM_EXPORT+const char *randombytes_implementation_name(void);++/* -- NaCl compatibility interface -- */++SODIUM_EXPORT+void randombytes(unsigned char * const buf, const unsigned long long buf_len)+            __attribute__ ((nonnull));++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/randombytes_internal_random.h view
@@ -0,0 +1,22 @@++#ifndef randombytes_internal_random_H+#define randombytes_internal_random_H++#include "export.h"+#include "randombytes.h"++#ifdef __cplusplus+extern "C" {+#endif++SODIUM_EXPORT+extern struct randombytes_implementation randombytes_internal_implementation;++/* Backwards compatibility with libsodium < 1.0.18 */+#define randombytes_salsa20_implementation randombytes_internal_implementation++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/randombytes_sysrandom.h view
@@ -0,0 +1,19 @@++#ifndef randombytes_sysrandom_H+#define randombytes_sysrandom_H++#include "export.h"+#include "randombytes.h"++#ifdef __cplusplus+extern "C" {+#endif++SODIUM_EXPORT+extern struct randombytes_implementation randombytes_sysrandom_implementation;++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/runtime.h view
@@ -0,0 +1,55 @@++#ifndef sodium_runtime_H+#define sodium_runtime_H++#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++SODIUM_EXPORT_WEAK+int sodium_runtime_has_neon(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_armcrypto(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_sse2(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_sse3(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_ssse3(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_sse41(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_avx(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_avx2(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_avx512f(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_pclmul(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_aesni(void);++SODIUM_EXPORT_WEAK+int sodium_runtime_has_rdrand(void);++/* ------------------------------------------------------------------------- */++int _sodium_runtime_get_cpu_features(void);++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/utils.h view
@@ -0,0 +1,179 @@++#ifndef sodium_utils_H+#define sodium_utils_H++#include <stddef.h>++#include "export.h"++#ifdef __cplusplus+extern "C" {+#endif++#ifndef SODIUM_C99+# if defined(__cplusplus) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L+#  define SODIUM_C99(X)+# else+#  define SODIUM_C99(X) X+# endif+#endif++SODIUM_EXPORT+void sodium_memzero(void * const pnt, const size_t len);++SODIUM_EXPORT+void sodium_stackzero(const size_t len);++/*+ * WARNING: sodium_memcmp() must be used to verify if two secret keys+ * are equal, in constant time.+ * It returns 0 if the keys are equal, and -1 if they differ.+ * This function is not designed for lexicographical comparisons.+ */+SODIUM_EXPORT+int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len)+            __attribute__ ((warn_unused_result));++/*+ * sodium_compare() returns -1 if b1_ < b2_, 1 if b1_ > b2_ and 0 if b1_ == b2_+ * It is suitable for lexicographical comparisons, or to compare nonces+ * and counters stored in little-endian format.+ * However, it is slower than sodium_memcmp().+ */+SODIUM_EXPORT+int sodium_compare(const unsigned char *b1_, const unsigned char *b2_,+                   size_t len) __attribute__ ((warn_unused_result));++SODIUM_EXPORT+int sodium_is_zero(const unsigned char *n, const size_t nlen);++SODIUM_EXPORT+void sodium_increment(unsigned char *n, const size_t nlen);++SODIUM_EXPORT+void sodium_add(unsigned char *a, const unsigned char *b, const size_t len);++SODIUM_EXPORT+void sodium_sub(unsigned char *a, const unsigned char *b, const size_t len);++SODIUM_EXPORT+char *sodium_bin2hex(char * const hex, const size_t hex_maxlen,+                     const unsigned char * const bin, const size_t bin_len)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int sodium_hex2bin(unsigned char * const bin, const size_t bin_maxlen,+                   const char * const hex, const size_t hex_len,+                   const char * const ignore, size_t * const bin_len,+                   const char ** const hex_end)+            __attribute__ ((nonnull(1)));++#define sodium_base64_VARIANT_ORIGINAL            1+#define sodium_base64_VARIANT_ORIGINAL_NO_PADDING 3+#define sodium_base64_VARIANT_URLSAFE             5+#define sodium_base64_VARIANT_URLSAFE_NO_PADDING  7++/*+ * Computes the required length to encode BIN_LEN bytes as a base64 string+ * using the given variant. The computed length includes a trailing \0.+ */+#define sodium_base64_ENCODED_LEN(BIN_LEN, VARIANT) \+    (((BIN_LEN) / 3U) * 4U + \+    ((((BIN_LEN) - ((BIN_LEN) / 3U) * 3U) | (((BIN_LEN) - ((BIN_LEN) / 3U) * 3U) >> 1)) & 1U) * \+     (4U - (~((((VARIANT) & 2U) >> 1) - 1U) & (3U - ((BIN_LEN) - ((BIN_LEN) / 3U) * 3U)))) + 1U)++SODIUM_EXPORT+size_t sodium_base64_encoded_len(const size_t bin_len, const int variant);++SODIUM_EXPORT+char *sodium_bin2base64(char * const b64, const size_t b64_maxlen,+                        const unsigned char * const bin, const size_t bin_len,+                        const int variant) __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int sodium_base642bin(unsigned char * const bin, const size_t bin_maxlen,+                      const char * const b64, const size_t b64_len,+                      const char * const ignore, size_t * const bin_len,+                      const char ** const b64_end, const int variant)+            __attribute__ ((nonnull(1)));++SODIUM_EXPORT+int sodium_mlock(void * const addr, const size_t len)+            __attribute__ ((nonnull));++SODIUM_EXPORT+int sodium_munlock(void * const addr, const size_t len)+            __attribute__ ((nonnull));++/* WARNING: sodium_malloc() and sodium_allocarray() are not general-purpose+ * allocation functions.+ *+ * They return a pointer to a region filled with 0xd0 bytes, immediately+ * followed by a guard page.+ * As a result, accessing a single byte after the requested allocation size+ * will intentionally trigger a segmentation fault.+ *+ * A canary and an additional guard page placed before the beginning of the+ * region may also kill the process if a buffer underflow is detected.+ *+ * The memory layout is:+ * [unprotected region size (read only)][guard page (no access)][unprotected pages (read/write)][guard page (no access)]+ * With the layout of the unprotected pages being:+ * [optional padding][16-bytes canary][user region]+ *+ * However:+ * - These functions are significantly slower than standard functions+ * - Each allocation requires 3 or 4 additional pages+ * - The returned address will not be aligned if the allocation size is not+ *   a multiple of the required alignment. For this reason, these functions+ *   are designed to store data, such as secret keys and messages.+ *+ * sodium_malloc() can be used to allocate any libsodium data structure.+ *+ * The crypto_generichash_state structure is packed and its length is+ * either 357 or 361 bytes. For this reason, when using sodium_malloc() to+ * allocate a crypto_generichash_state structure, padding must be added in+ * order to ensure proper alignment. crypto_generichash_statebytes()+ * returns the rounded up structure size, and should be preferred to sizeof():+ * state = sodium_malloc(crypto_generichash_statebytes());+ */++SODIUM_EXPORT+void *sodium_malloc(const size_t size)+            __attribute__ ((malloc));++SODIUM_EXPORT+void *sodium_allocarray(size_t count, size_t size)+            __attribute__ ((malloc));++SODIUM_EXPORT+void sodium_free(void *ptr);++SODIUM_EXPORT+int sodium_mprotect_noaccess(void *ptr) __attribute__ ((nonnull));++SODIUM_EXPORT+int sodium_mprotect_readonly(void *ptr) __attribute__ ((nonnull));++SODIUM_EXPORT+int sodium_mprotect_readwrite(void *ptr) __attribute__ ((nonnull));++SODIUM_EXPORT+int sodium_pad(size_t *padded_buflen_p, unsigned char *buf,+               size_t unpadded_buflen, size_t blocksize, size_t max_buflen)+            __attribute__ ((nonnull(2)));++SODIUM_EXPORT+int sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,+                 size_t padded_buflen, size_t blocksize)+            __attribute__ ((nonnull(2)));++/* -------- */++int _sodium_alloc_init(void);++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/include/sodium/version.h view
@@ -0,0 +1,33 @@++#ifndef sodium_version_H+#define sodium_version_H++#include "export.h"++#define SODIUM_VERSION_STRING "1.0.19"++#define SODIUM_LIBRARY_VERSION_MAJOR 26+#define SODIUM_LIBRARY_VERSION_MINOR 1+++#ifdef __cplusplus+extern "C" {+#endif++SODIUM_EXPORT+const char *sodium_version_string(void);++SODIUM_EXPORT+int         sodium_library_version_major(void);++SODIUM_EXPORT+int         sodium_library_version_minor(void);++SODIUM_EXPORT+int         sodium_library_minimal(void);++#ifdef __cplusplus+}+#endif++#endif
+ vendor/external/libsodium/randombytes/internal/randombytes_internal_random.c view
@@ -0,0 +1,635 @@++#include <assert.h>+#include <errno.h>+#include <fcntl.h>+#include <limits.h>+#include <stdint.h>+#include <stdlib.h>+#include <stdlib.h>+#include <string.h>+#if !defined(_MSC_VER) && !defined(__BORLANDC__)+# include <unistd.h>+#endif++#include <sys/types.h>+#ifndef _WIN32+# include <sys/stat.h>+# include <sys/time.h>+#endif+#ifdef __linux__+# define _LINUX_SOURCE+#endif+#ifdef HAVE_SYS_RANDOM_H+# include <sys/random.h>+#endif+#ifdef __linux__+# ifdef HAVE_GETRANDOM+#  define HAVE_LINUX_COMPATIBLE_GETRANDOM+# else+#  include <sys/syscall.h>+#  if defined(SYS_getrandom) && defined(__NR_getrandom)+#   define getrandom(B, S, F) syscall(SYS_getrandom, (B), (int) (S), (F))+#   define HAVE_LINUX_COMPATIBLE_GETRANDOM+#  endif+# endif+#elif defined(__FreeBSD__)+# include <sys/param.h>+# if defined(__FreeBSD_version) && __FreeBSD_version >= 1200000+#  define HAVE_LINUX_COMPATIBLE_GETRANDOM+# endif+#endif+#if !defined(NO_BLOCKING_RANDOM_POLL) && defined(__linux__)+# define BLOCK_ON_DEV_RANDOM+#endif+#ifdef BLOCK_ON_DEV_RANDOM+# include <poll.h>+#endif+#ifdef HAVE_RDRAND+# pragma GCC target("rdrnd")+# include <immintrin.h>+#endif++#include "core.h"+#include "crypto_core_hchacha20.h"+#include "crypto_stream_chacha20.h"+#include "private/common.h"+#include "randombytes.h"+#include "randombytes_internal_random.h"+#include "runtime.h"+#include "utils.h"++#ifdef _WIN32+# include <windows.h>+# include <sys/timeb.h>+# define RtlGenRandom SystemFunction036+# if defined(__cplusplus)+extern "C"+# endif+BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);+# pragma comment(lib, "advapi32.lib")+# ifdef __BORLANDC__+#  define _ftime ftime+#  define _timeb timeb+# endif+#endif++#define INTERNAL_RANDOM_BLOCK_SIZE crypto_core_hchacha20_OUTPUTBYTES++#if defined(__OpenBSD__) || defined(__CloudABI__) || defined(__wasi__)+# define HAVE_SAFE_ARC4RANDOM 1+#endif+#if defined(__CloudABI__) || defined(__wasm__)+# define NONEXISTENT_DEV_RANDOM 1+#endif++#ifndef SSIZE_MAX+# define SSIZE_MAX (SIZE_MAX / 2 - 1)+#endif+#ifndef S_ISNAM+# ifdef __COMPCERT__+#  define S_ISNAM(X) 1+# else+#  define S_ISNAM(X) 0+# endif+#endif++#if !defined(TLS) && !defined(__STDC_NO_THREADS__) && \+    defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L+# define TLS _Thread_local+#endif+#ifndef TLS+# ifdef _WIN32+#  define TLS __declspec(thread)+# else+#  define TLS+# endif+#endif++typedef struct InternalRandomGlobal_ {+    int           initialized;+    int           random_data_source_fd;+    int           getentropy_available;+    int           getrandom_available;+    int           rdrand_available;+#ifdef HAVE_GETPID+    pid_t         pid;+#endif+} InternalRandomGlobal;++typedef struct InternalRandom_ {+    int           initialized;+    size_t        rnd32_outleft;+    unsigned char key[crypto_stream_chacha20_KEYBYTES];+    unsigned char rnd32[16U * INTERNAL_RANDOM_BLOCK_SIZE];+    uint64_t      nonce;+} InternalRandom;++static InternalRandomGlobal global = {+    SODIUM_C99(.initialized =) 0,+    SODIUM_C99(.random_data_source_fd =) -1+};++static TLS InternalRandom stream = {+    SODIUM_C99(.initialized =) 0,+    SODIUM_C99(.rnd32_outleft =) (size_t) 0U+};+++/*+ * Get a high-resolution timestamp, as a uint64_t value+ */++#ifdef _WIN32+static uint64_t+sodium_hrtime(void)+{+    struct _timeb tb;+# pragma warning(push)+# pragma warning(disable: 4996)+    _ftime(&tb);+# pragma warning(pop)+    return ((uint64_t) tb.time) * 1000000U + ((uint64_t) tb.millitm) * 1000U;+}++#else /* _WIN32 */++static uint64_t+sodium_hrtime(void)+{+    struct timeval tv;++    if (gettimeofday(&tv, NULL) != 0) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+    return ((uint64_t) tv.tv_sec) * 1000000U + (uint64_t) tv.tv_usec;+}+#endif /* _WIN32 */++/*+ * Initialize the entropy source+ */++#ifdef _WIN32++static void+randombytes_internal_random_init(void)+{+    global.rdrand_available = sodium_runtime_has_rdrand();+}++#else /* _WIN32 */++# ifdef HAVE_GETENTROPY+static int+_randombytes_getentropy(void * const buf, const size_t size)+{+    assert(size <= 256U);+    if (getentropy(buf, size) != 0) {+        return -1; /* LCOV_EXCL_LINE */+    }+    return 0;+}++static int+randombytes_getentropy(void * const buf_, size_t size)+{+    unsigned char *buf = (unsigned char *) buf_;+    size_t         chunk_size = 256U;++    do {+        if (size < chunk_size) {+            chunk_size = size;+            assert(chunk_size > (size_t) 0U);+        }+        if (_randombytes_getentropy(buf, chunk_size) != 0) {+            return -1; /* LCOV_EXCL_LINE */+        }+        size -= chunk_size;+        buf += chunk_size;+    } while (size > (size_t) 0U);++    return 0;+}++# elif defined(HAVE_LINUX_COMPATIBLE_GETRANDOM)++static int+_randombytes_linux_getrandom(void * const buf, const size_t size)+{+    int readnb;++    assert(size <= 256U);+    do {+        readnb = getrandom(buf, size, 0);+    } while (readnb < 0 && (errno == EINTR || errno == EAGAIN));++    return (readnb == (int) size) - 1;+}++static int+randombytes_linux_getrandom(void * const buf_, size_t size)+{+    unsigned char *buf = (unsigned char *) buf_;+    size_t         chunk_size = 256U;++    do {+        if (size < chunk_size) {+            chunk_size = size;+            assert(chunk_size > (size_t) 0U);+        }+        if (_randombytes_linux_getrandom(buf, chunk_size) != 0) {+            return -1;+        }+        size -= chunk_size;+        buf += chunk_size;+    } while (size > (size_t) 0U);++    return 0;+}+# endif++# ifndef NONEXISTENT_DEV_RANDOM++#  ifdef BLOCK_ON_DEV_RANDOM+static int+randombytes_block_on_dev_random(void)+{+    struct pollfd pfd;+    int           fd;+    int           pret;++    fd = open("/dev/random", O_RDONLY);+    if (fd == -1) {+        return 0;+    }+    pfd.fd = fd;+    pfd.events = POLLIN;+    pfd.revents = 0;+    do {+        pret = poll(&pfd, 1, -1);+    } while (pret < 0 && (errno == EINTR || errno == EAGAIN));+    if (pret != 1) {+        (void) close(fd);+        errno = EIO;+        return -1;+    }+    return close(fd);+}+#  endif++/* LCOV_EXCL_START */+static int+randombytes_internal_random_random_dev_open(void)+{+    struct stat       st;+    static const char *devices[] = {+#  ifndef USE_BLOCKING_RANDOM+        "/dev/urandom",+#  endif+        "/dev/random", NULL+    };+    const char      **device = devices;+    int               fd;++#  ifdef BLOCK_ON_DEV_RANDOM+    if (randombytes_block_on_dev_random() != 0) {+        return -1;+    }+#  endif+    do {+        fd = open(*device, O_RDONLY);+        if (fd != -1) {+            if (fstat(fd, &st) == 0 && (S_ISNAM(st.st_mode) || S_ISCHR(st.st_mode))) {+#  if defined(F_SETFD) && defined(FD_CLOEXEC)+                (void) fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);+#  endif+                return fd;+            }+            (void) close(fd);+        } else if (errno == EINTR) {+            continue;+        }+        device++;+    } while (*device != NULL);++    errno = EIO;+    return -1;+}+/* LCOV_EXCL_STOP */++static ssize_t+safe_read(const int fd, void * const buf_, size_t size)+{+    unsigned char *buf = (unsigned char *) buf_;+    ssize_t        readnb;++    assert(size > (size_t) 0U);+    assert(size <= SSIZE_MAX);+    do {+        while ((readnb = read(fd, buf, size)) < (ssize_t) 0 &&+               (errno == EINTR || errno == EAGAIN)); /* LCOV_EXCL_LINE */+        if (readnb < (ssize_t) 0) {+            return readnb; /* LCOV_EXCL_LINE */+        }+        if (readnb == (ssize_t) 0) {+            break; /* LCOV_EXCL_LINE */+        }+        size -= (size_t) readnb;+        buf += readnb;+    } while (size > (ssize_t) 0);++    return (ssize_t) (buf - (unsigned char *) buf_);+}++# endif /* !NONEXISTENT_DEV_RANDOM */++static void+randombytes_internal_random_init(void)+{+    const int errno_save = errno;++    global.rdrand_available = sodium_runtime_has_rdrand();+    global.getentropy_available = 0;+    global.getrandom_available = 0;++# ifdef HAVE_GETENTROPY+    {+        unsigned char fodder[16];++        if (randombytes_getentropy(fodder, sizeof fodder) == 0) {+            global.getentropy_available = 1;+            errno = errno_save;+            return;+        }+    }+# elif defined(HAVE_LINUX_COMPATIBLE_GETRANDOM)+    {+        unsigned char fodder[16];++        if (randombytes_linux_getrandom(fodder, sizeof fodder) == 0) {+            global.getrandom_available = 1;+            errno = errno_save;+            return;+        }+    }+# endif+/* LCOV_EXCL_START */+# if !defined(NONEXISTENT_DEV_RANDOM)+    assert((global.getentropy_available | global.getrandom_available) == 0);+    if ((global.random_data_source_fd =+         randombytes_internal_random_random_dev_open()) == -1) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+    errno = errno_save;+    return;+# endif+/* LCOV_EXCL_STOP */+# ifndef HAVE_SAFE_ARC4RANDOM+    sodium_misuse();+# endif+}++#endif /* _WIN32 */++/*+ * (Re)seed the generator using the entropy source+ */++static void+randombytes_internal_random_stir(void)+{+    stream.nonce = sodium_hrtime();+    assert(stream.nonce != (uint64_t) 0U);+    memset(stream.rnd32, 0, sizeof stream.rnd32);+    stream.rnd32_outleft = (size_t) 0U;+    if (global.initialized == 0) {+        randombytes_internal_random_init();+        global.initialized = 1;+    }+#ifdef HAVE_GETPID+    global.pid = getpid();+#endif++#ifndef _WIN32++# ifdef HAVE_GETENTROPY+     if (global.getentropy_available != 0) {+         if (randombytes_getentropy(stream.key, sizeof stream.key) != 0) {+             sodium_misuse(); /* LCOV_EXCL_LINE */+         }+     }+# elif defined(HAVE_LINUX_COMPATIBLE_GETRANDOM)+     if (global.getrandom_available != 0) {+         if (randombytes_linux_getrandom(stream.key, sizeof stream.key) != 0) {+             sodium_misuse(); /* LCOV_EXCL_LINE */+         }+     }+# elif defined(NONEXISTENT_DEV_RANDOM) && defined(HAVE_SAFE_ARC4RANDOM)+    arc4random_buf(stream.key, sizeof stream.key);+# elif !defined(NONEXISTENT_DEV_RANDOM)+    if (global.random_data_source_fd == -1 ||+        safe_read(global.random_data_source_fd, stream.key,+                  sizeof stream.key) != (ssize_t) sizeof stream.key) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+# else+    sodium_misuse();+# endif++#else /* _WIN32 */+    if (! RtlGenRandom((PVOID) stream.key, (ULONG) sizeof stream.key)) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+#endif++    stream.initialized = 1;+}++/*+ * Reseed the generator if it hasn't been initialized yet+ */++static void+randombytes_internal_random_stir_if_needed(void)+{+#ifdef HAVE_GETPID+    if (stream.initialized == 0) {+        randombytes_internal_random_stir();+    } else if (global.pid != getpid()) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+#else+    if (stream.initialized == 0) {+        randombytes_internal_random_stir();+    }+#endif+}++/*+ * Close the stream, free global resources+ */++#ifdef _WIN32+static int+randombytes_internal_random_close(void)+{+    int ret = -1;++    if (global.initialized != 0) {+        global.initialized = 0;+        ret = 0;+    }+    sodium_memzero(&stream, sizeof stream);++    return ret;+}+#else+static int+randombytes_internal_random_close(void)+{+    int ret = -1;++# ifdef HAVE_GETENTROPY+    if (global.getentropy_available != 0) {+        ret = 0;+    }+# elif defined(HAVE_LINUX_COMPATIBLE_GETRANDOM)+    if (global.getrandom_available != 0) {+        ret = 0;+    }+# elif !defined(NONEXISTENT_DEV_RANDOM) && defined(HAVE_SAFE_ARC4RANDOM)+    ret = 0;+# else+    if (global.random_data_source_fd != -1 &&+        close(global.random_data_source_fd) == 0) {+        global.random_data_source_fd = -1;+        global.initialized = 0;+# ifdef HAVE_GETPID+        global.pid = (pid_t) 0;+# endif+        ret = 0;+    }+# endif++    sodium_memzero(&stream, sizeof stream);++    return ret;+}+#endif++/*+ * RDRAND is only used to mitigate prediction if a key is compromised+ */++static void+randombytes_internal_random_xorhwrand(void)+{+/* LCOV_EXCL_START */+#ifdef HAVE_RDRAND+    unsigned int r;++    if (global.rdrand_available == 0) {+        return;+    }+    (void) _rdrand32_step(&r);+    * (uint32_t *) (void *)+        &stream.key[crypto_stream_chacha20_KEYBYTES - 4] ^= (uint32_t) r;+#endif+/* LCOV_EXCL_STOP */+}++/*+ * XOR the key with another same-length secret+ */++static inline void+randombytes_internal_random_xorkey(const unsigned char * const mix)+{+    unsigned char *key = stream.key;+    size_t         i;++    for (i = (size_t) 0U; i < sizeof stream.key; i++) {+        key[i] ^= mix[i];+    }+}++/*+ * Put `size` random bytes into `buf` and overwrite the key+ */++static void+randombytes_internal_random_buf(void * const buf, const size_t size)+{+    size_t i;+    int    ret;++    randombytes_internal_random_stir_if_needed();+    COMPILER_ASSERT(sizeof stream.nonce == crypto_stream_chacha20_NONCEBYTES);+#if defined(ULLONG_MAX) && defined(SIZE_MAX)+# if SIZE_MAX > ULLONG_MAX+    /* coverity[result_independent_of_operands] */+    assert(size <= ULLONG_MAX);+# endif+#endif+    ret = crypto_stream_chacha20((unsigned char *) buf, (unsigned long long) size,+                                 (unsigned char *) &stream.nonce, stream.key);+    assert(ret == 0);+    for (i = 0U; i < sizeof size; i++) {+        stream.key[i] ^= ((const unsigned char *) (const void *) &size)[i];+    }+    randombytes_internal_random_xorhwrand();+    stream.nonce++;+    crypto_stream_chacha20_xor(stream.key, stream.key, sizeof stream.key,+                               (unsigned char *) &stream.nonce, stream.key);+}++/*+ * Pop a 32-bit value from the random pool+ *+ * Overwrite the key after the pool gets refilled.+ */++static uint32_t+randombytes_internal_random(void)+{+    uint32_t val;+    int      ret;++    COMPILER_ASSERT(sizeof stream.rnd32 >= (sizeof stream.key) + (sizeof val));+    COMPILER_ASSERT(((sizeof stream.rnd32) - (sizeof stream.key))+                    % sizeof val == (size_t) 0U);+    if (stream.rnd32_outleft <= (size_t) 0U) {+        randombytes_internal_random_stir_if_needed();+        COMPILER_ASSERT(sizeof stream.nonce == crypto_stream_chacha20_NONCEBYTES);+        ret = crypto_stream_chacha20((unsigned char *) stream.rnd32,+                                     (unsigned long long) sizeof stream.rnd32,+                                     (unsigned char *) &stream.nonce,+                                     stream.key);+        assert(ret == 0);+        stream.rnd32_outleft = (sizeof stream.rnd32) - (sizeof stream.key);+        randombytes_internal_random_xorhwrand();+        randombytes_internal_random_xorkey(&stream.rnd32[stream.rnd32_outleft]);+        memset(&stream.rnd32[stream.rnd32_outleft], 0, sizeof stream.key);+        stream.nonce++;+    }+    stream.rnd32_outleft -= sizeof val;+    memcpy(&val, &stream.rnd32[stream.rnd32_outleft], sizeof val);+    memset(&stream.rnd32[stream.rnd32_outleft], 0, sizeof val);++    return val;+}++static const char *+randombytes_internal_implementation_name(void)+{+    return "internal";+}++struct randombytes_implementation randombytes_internal_implementation = {+    SODIUM_C99(.implementation_name =) randombytes_internal_implementation_name,+    SODIUM_C99(.random =) randombytes_internal_random,+    SODIUM_C99(.stir =) randombytes_internal_random_stir,+    SODIUM_C99(.uniform =) NULL,+    SODIUM_C99(.buf =) randombytes_internal_random_buf,+    SODIUM_C99(.close =) randombytes_internal_random_close+};
+ vendor/external/libsodium/randombytes/randombytes.c view
@@ -0,0 +1,199 @@++#include <assert.h>+#include <limits.h>+#include <stdint.h>+#include <stdlib.h>++#include <sys/types.h>++#ifdef __EMSCRIPTEN__+# include <emscripten.h>+#endif++#include "core.h"+#include "crypto_stream_chacha20.h"+#include "randombytes.h"+#ifndef RANDOMBYTES_CUSTOM_IMPLEMENTATION+# ifdef RANDOMBYTES_DEFAULT_IMPLEMENTATION+#  include "randombytes_internal.h"+# endif+# include "randombytes_sysrandom.h"+#endif+#include "private/common.h"++/* C++Builder defines a "random" macro */+#undef random++static const randombytes_implementation *implementation;++#ifndef RANDOMBYTES_DEFAULT_IMPLEMENTATION+# ifdef __EMSCRIPTEN__+#  define RANDOMBYTES_DEFAULT_IMPLEMENTATION NULL+# else+#  define RANDOMBYTES_DEFAULT_IMPLEMENTATION &randombytes_sysrandom_implementation;+# endif+#endif++static void+randombytes_init_if_needed(void)+{+    if (implementation == NULL) {+        implementation = RANDOMBYTES_DEFAULT_IMPLEMENTATION;+        randombytes_stir();+    }+}++int+randombytes_set_implementation(const randombytes_implementation *impl)+{+    implementation = impl;++    return 0;+}++const char *+randombytes_implementation_name(void)+{+#ifndef __EMSCRIPTEN__+    randombytes_init_if_needed();+    return implementation->implementation_name();+#else+    return "js";+#endif+}++uint32_t+randombytes_random(void)+{+#ifndef __EMSCRIPTEN__+    randombytes_init_if_needed();+    return implementation->random();+#else+    return EM_ASM_INT_V({+        return Module.getRandomValue();+    });+#endif+}++void+randombytes_stir(void)+{+#ifndef __EMSCRIPTEN__+    randombytes_init_if_needed();+    if (implementation->stir != NULL) {+        implementation->stir();+    }+#else+    EM_ASM({+        if (Module.getRandomValue === undefined) {+            try {+                var window_ = 'object' === typeof window ? window : self;+                var crypto_ = typeof window_.crypto !== 'undefined' ? window_.crypto : window_.msCrypto;+                var randomValuesStandard = function() {+                    var buf = new Uint32Array(1);+                    crypto_.getRandomValues(buf);+                    return buf[0] >>> 0;+                };+                randomValuesStandard();+                Module.getRandomValue = randomValuesStandard;+            } catch (e) {+                try {+                    var crypto = require('crypto');+                    var randomValueNodeJS = function() {+                        var buf = crypto['randomBytes'](4);+                        return (buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]) >>> 0;+                    };+                    randomValueNodeJS();+                    Module.getRandomValue = randomValueNodeJS;+                } catch (e) {+                    throw 'No secure random number generator found';+                }+            }+        }+    });+#endif+}++uint32_t+randombytes_uniform(const uint32_t upper_bound)+{+    uint32_t min;+    uint32_t r;++#ifndef __EMSCRIPTEN__+    randombytes_init_if_needed();+    if (implementation->uniform != NULL) {+        return implementation->uniform(upper_bound);+    }+#endif+    if (upper_bound < 2) {+        return 0;+    }+    min = (1U + ~upper_bound) % upper_bound; /* = 2**32 mod upper_bound */+    do {+        r = randombytes_random();+    } while (r < min);+    /* r is now clamped to a set whose size mod upper_bound == 0+     * the worst case (2**31+1) requires ~ 2 attempts */++    return r % upper_bound;+}++void+randombytes_buf(void * const buf, const size_t size)+{+#ifndef __EMSCRIPTEN__+    randombytes_init_if_needed();+    if (size > (size_t) 0U) {+        implementation->buf(buf, size);+    }+#else+    unsigned char *p = (unsigned char *) buf;+    size_t         i;++    for (i = (size_t) 0U; i < size; i++) {+        p[i] = (unsigned char) randombytes_random();+    }+#endif+}++void+randombytes_buf_deterministic(void * const buf, const size_t size,+                              const unsigned char seed[randombytes_SEEDBYTES])+{+    static const unsigned char nonce[crypto_stream_chacha20_ietf_NONCEBYTES] = {+        'L', 'i', 'b', 's', 'o', 'd', 'i', 'u', 'm', 'D', 'R', 'G'+    };++    COMPILER_ASSERT(randombytes_SEEDBYTES == crypto_stream_chacha20_ietf_KEYBYTES);+#if SIZE_MAX > 0x4000000000ULL+    COMPILER_ASSERT(randombytes_BYTES_MAX <= 0x4000000000ULL);+    if (size > 0x4000000000ULL) {+        sodium_misuse();+    }+#endif+    crypto_stream_chacha20_ietf((unsigned char *) buf, (unsigned long long) size,+                                nonce, seed);+}++size_t+randombytes_seedbytes(void)+{+    return randombytes_SEEDBYTES;+}++int+randombytes_close(void)+{+    if (implementation != NULL && implementation->close != NULL) {+        return implementation->close();+    }+    return 0;+}++void+randombytes(unsigned char * const buf, const unsigned long long buf_len)+{+    assert(buf_len <= SIZE_MAX);+    randombytes_buf(buf, (size_t) buf_len);+}
+ vendor/external/libsodium/randombytes/sysrandom/randombytes_sysrandom.c view
@@ -0,0 +1,396 @@+#include <assert.h>+#include <errno.h>+#include <fcntl.h>+#include <limits.h>+#include <stdint.h>+#include <string.h>+#ifndef _WIN32+# include <unistd.h>+#endif+#include <stdlib.h>++#include <sys/types.h>+#ifndef _WIN32+# include <sys/stat.h>+# include <sys/time.h>+#endif+#ifdef __linux__+# define _LINUX_SOURCE+#endif+#ifdef HAVE_SYS_RANDOM_H+# include <sys/random.h>+#endif+#ifdef __linux__+# ifdef HAVE_GETRANDOM+#  define HAVE_LINUX_COMPATIBLE_GETRANDOM+# else+#  include <sys/syscall.h>+#  if defined(SYS_getrandom) && defined(__NR_getrandom)+#   define getrandom(B, S, F) syscall(SYS_getrandom, (B), (int) (S), (F))+#   define HAVE_LINUX_COMPATIBLE_GETRANDOM+#  endif+# endif+#elif defined(__FreeBSD__) || defined(__DragonFly__)+# include <sys/param.h>+# if (defined(__FreeBSD_version) && __FreeBSD_version >= 1200000) || \+     (defined(__DragonFly_version) && __DragonFly_version >= 500700)+#  define HAVE_LINUX_COMPATIBLE_GETRANDOM+# endif+#endif+#if !defined(NO_BLOCKING_RANDOM_POLL) && defined(__linux__)+# define BLOCK_ON_DEV_RANDOM+#endif+#ifdef BLOCK_ON_DEV_RANDOM+# include <poll.h>+#endif++#include "core.h"+#include "private/common.h"+#include "randombytes.h"+#include "randombytes_sysrandom.h"+#include "utils.h"++#ifdef _WIN32+/* `RtlGenRandom` is used over `CryptGenRandom` on Microsoft Windows based systems:+ *  - `CryptGenRandom` requires pulling in `CryptoAPI` which causes unnecessary+ *     memory overhead if this API is not being used for other purposes+ *  - `RtlGenRandom` is thus called directly instead. A detailed explanation+ *     can be found here: https://blogs.msdn.microsoft.com/michael_howard/2005/01/14/cryptographically-secure-random-number-on-windows-without-using-cryptoapi/+ *+ * In spite of the disclaimer on the `RtlGenRandom` documentation page that was+ * written back in the Windows XP days, this function is here to stay. The CRT+ * function `rand_s()` directly depends on it, so touching it would break many+ * applications released since Windows XP.+ *+ * Also note that Rust, Firefox and BoringSSL (thus, Google Chrome and everything+ * based on Chromium) also depend on it, and that libsodium allows the RNG to be+ * replaced without patching nor recompiling the library.+ */+# include <windows.h>+# define RtlGenRandom SystemFunction036+# if defined(__cplusplus)+extern "C"+# endif+BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);+# pragma comment(lib, "advapi32.lib")+#endif++#if defined(__OpenBSD__) || defined(__CloudABI__) || defined(__wasi__)+# define HAVE_SAFE_ARC4RANDOM 1+#endif++#ifndef SSIZE_MAX+# define SSIZE_MAX (SIZE_MAX / 2 - 1)+#endif++#ifdef HAVE_SAFE_ARC4RANDOM++static uint32_t+randombytes_sysrandom(void)+{+    return arc4random();+}++static void+randombytes_sysrandom_stir(void)+{+}++static void+randombytes_sysrandom_buf(void * const buf, const size_t size)+{+    arc4random_buf(buf, size);+}++static int+randombytes_sysrandom_close(void)+{+    return 0;+}++#else /* HAVE_SAFE_ARC4RANDOM */++typedef struct SysRandom_ {+    int random_data_source_fd;+    int initialized;+    int getrandom_available;+} SysRandom;++static SysRandom stream = {+    SODIUM_C99(.random_data_source_fd =) -1,+    SODIUM_C99(.initialized =) 0,+    SODIUM_C99(.getrandom_available =) 0+};++# ifndef _WIN32+static ssize_t+safe_read(const int fd, void * const buf_, size_t size)+{+    unsigned char *buf = (unsigned char *) buf_;+    ssize_t        readnb;++    assert(size > (size_t) 0U);+    assert(size <= SSIZE_MAX);+    do {+        while ((readnb = read(fd, buf, size)) < (ssize_t) 0 &&+               (errno == EINTR || errno == EAGAIN)); /* LCOV_EXCL_LINE */+        if (readnb < (ssize_t) 0) {+            return readnb; /* LCOV_EXCL_LINE */+        }+        if (readnb == (ssize_t) 0) {+            break; /* LCOV_EXCL_LINE */+        }+        size -= (size_t) readnb;+        buf += readnb;+    } while (size > (ssize_t) 0);++    return (ssize_t) (buf - (unsigned char *) buf_);+}++#  ifdef BLOCK_ON_DEV_RANDOM+static int+randombytes_block_on_dev_random(void)+{+    struct pollfd pfd;+    int           fd;+    int           pret;++    fd = open("/dev/random", O_RDONLY);+    if (fd == -1) {+        return 0;+    }+    pfd.fd = fd;+    pfd.events = POLLIN;+    pfd.revents = 0;+    do {+        pret = poll(&pfd, 1, -1);+    } while (pret < 0 && (errno == EINTR || errno == EAGAIN));+    if (pret != 1) {+        (void) close(fd);+        errno = EIO;+        return -1;+    }+    return close(fd);+}+#  endif /* BLOCK_ON_DEV_RANDOM */++static int+randombytes_sysrandom_random_dev_open(void)+{+/* LCOV_EXCL_START */+    struct stat        st;+    static const char *devices[] = {+#  ifndef USE_BLOCKING_RANDOM+        "/dev/urandom",+#  endif+        "/dev/random", NULL+    };+    const char       **device = devices;+    int                fd;++#  ifdef BLOCK_ON_DEV_RANDOM+    if (randombytes_block_on_dev_random() != 0) {+        return -1;+    }+#  endif+    do {+        fd = open(*device, O_RDONLY);+        if (fd != -1) {+            if (fstat(fd, &st) == 0 &&+#  ifdef __COMPCERT__+                1+#  elif defined(S_ISNAM)+                (S_ISNAM(st.st_mode) || S_ISCHR(st.st_mode))+#  else+                S_ISCHR(st.st_mode)+#  endif+               ) {+#  if defined(F_SETFD) && defined(FD_CLOEXEC)+                (void) fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);+#  endif+                return fd;+            }+            (void) close(fd);+        } else if (errno == EINTR) {+            continue;+        }+        device++;+    } while (*device != NULL);++    errno = EIO;+    return -1;+/* LCOV_EXCL_STOP */+}++#  ifdef HAVE_LINUX_COMPATIBLE_GETRANDOM+static int+_randombytes_linux_getrandom(void * const buf, const size_t size)+{+    int readnb;++    assert(size <= 256U);+    do {+        readnb = getrandom(buf, size, 0);+    } while (readnb < 0 && (errno == EINTR || errno == EAGAIN));++    return (readnb == (int) size) - 1;+}++static int+randombytes_linux_getrandom(void * const buf_, size_t size)+{+    unsigned char *buf = (unsigned char *) buf_;+    size_t         chunk_size = 256U;++    do {+        if (size < chunk_size) {+            chunk_size = size;+            assert(chunk_size > (size_t) 0U);+        }+        if (_randombytes_linux_getrandom(buf, chunk_size) != 0) {+            return -1;+        }+        size -= chunk_size;+        buf += chunk_size;+    } while (size > (size_t) 0U);++    return 0;+}+#  endif /* HAVE_LINUX_COMPATIBLE_GETRANDOM */++static void+randombytes_sysrandom_init(void)+{+    const int     errno_save = errno;++#  ifdef HAVE_LINUX_COMPATIBLE_GETRANDOM+    {+        unsigned char fodder[16];++        if (randombytes_linux_getrandom(fodder, sizeof fodder) == 0) {+            stream.getrandom_available = 1;+            errno = errno_save;+            return;+        }+        stream.getrandom_available = 0;+    }+#  endif++    if ((stream.random_data_source_fd =+         randombytes_sysrandom_random_dev_open()) == -1) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+    errno = errno_save;+}++# else /* _WIN32 */++static void+randombytes_sysrandom_init(void)+{+}+# endif /* _WIN32 */++static void+randombytes_sysrandom_stir(void)+{+    if (stream.initialized == 0) {+        randombytes_sysrandom_init();+        stream.initialized = 1;+    }+}++static void+randombytes_sysrandom_stir_if_needed(void)+{+    if (stream.initialized == 0) {+        randombytes_sysrandom_stir();+    }+}++static int+randombytes_sysrandom_close(void)+{+    int ret = -1;++# ifndef _WIN32+    if (stream.random_data_source_fd != -1 &&+        close(stream.random_data_source_fd) == 0) {+        stream.random_data_source_fd = -1;+        stream.initialized = 0;+        ret = 0;+    }+#  ifdef HAVE_LINUX_COMPATIBLE_GETRANDOM+    if (stream.getrandom_available != 0) {+        ret = 0;+    }+#  endif+# else /* _WIN32 */+    if (stream.initialized != 0) {+        stream.initialized = 0;+        ret = 0;+    }+# endif /* _WIN32 */+    return ret;+}++static void+randombytes_sysrandom_buf(void * const buf, const size_t size)+{+    randombytes_sysrandom_stir_if_needed();+# if defined(ULLONG_MAX) && defined(SIZE_MAX)+#  if SIZE_MAX > ULLONG_MAX+    /* coverity[result_independent_of_operands] */+    assert(size <= ULLONG_MAX);+#  endif+# endif+# ifndef _WIN32+#  ifdef HAVE_LINUX_COMPATIBLE_GETRANDOM+    if (stream.getrandom_available != 0) {+        if (randombytes_linux_getrandom(buf, size) != 0) {+            sodium_misuse(); /* LCOV_EXCL_LINE */+        }+        return;+    }+#  endif+    if (stream.random_data_source_fd == -1 ||+        safe_read(stream.random_data_source_fd, buf, size) != (ssize_t) size) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+# else /* _WIN32 */+    COMPILER_ASSERT(randombytes_BYTES_MAX <= 0xffffffffUL);+    if (size > (size_t) 0xffffffffUL) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+    if (! RtlGenRandom((PVOID) buf, (ULONG) size)) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+# endif /* _WIN32 */+}++static uint32_t+randombytes_sysrandom(void)+{+    uint32_t r;++    randombytes_sysrandom_buf(&r, sizeof r);++    return r;+}++#endif /* HAVE_SAFE_ARC4RANDOM */++static const char *+randombytes_sysrandom_implementation_name(void)+{+    return "sysrandom";+}++struct randombytes_implementation randombytes_sysrandom_implementation = {+    SODIUM_C99(.implementation_name =) randombytes_sysrandom_implementation_name,+    SODIUM_C99(.random =) randombytes_sysrandom,+    SODIUM_C99(.stir =) randombytes_sysrandom_stir,+    SODIUM_C99(.uniform =) NULL,+    SODIUM_C99(.buf =) randombytes_sysrandom_buf,+    SODIUM_C99(.close =) randombytes_sysrandom_close+};
+ vendor/external/libsodium/sodium/codecs.c view
@@ -0,0 +1,335 @@+#include <assert.h>+#include <errno.h>+#include <limits.h>+#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#include "core.h"+#include "private/common.h"+#include "utils.h"++/* Derived from original code by CodesInChaos */+char *+sodium_bin2hex(char *const hex, const size_t hex_maxlen,+               const unsigned char *const bin, const size_t bin_len)+{+    size_t       i = (size_t) 0U;+    unsigned int x;+    int          b;+    int          c;++    if (bin_len >= SIZE_MAX / 2 || hex_maxlen <= bin_len * 2U) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+    while (i < bin_len) {+        c = bin[i] & 0xf;+        b = bin[i] >> 4;+        x = (unsigned char) (87U + c + (((c - 10U) >> 8) & ~38U)) << 8 |+            (unsigned char) (87U + b + (((b - 10U) >> 8) & ~38U));+        hex[i * 2U] = (char) x;+        x >>= 8;+        hex[i * 2U + 1U] = (char) x;+        i++;+    }+    hex[i * 2U] = 0U;++    return hex;+}++int+sodium_hex2bin(unsigned char *const bin, const size_t bin_maxlen,+               const char *const hex, const size_t hex_len,+               const char *const ignore, size_t *const bin_len,+               const char **const hex_end)+{+    size_t        bin_pos = (size_t) 0U;+    size_t        hex_pos = (size_t) 0U;+    int           ret     = 0;+    unsigned char c;+    unsigned char c_acc = 0U;+    unsigned char c_alpha0, c_alpha;+    unsigned char c_num0, c_num;+    unsigned char c_val;+    unsigned char state = 0U;++    while (hex_pos < hex_len) {+        c        = (unsigned char) hex[hex_pos];+        c_num    = c ^ 48U;+        c_num0   = (c_num - 10U) >> 8;+        c_alpha  = (c & ~32U) - 55U;+        c_alpha0 = ((c_alpha - 10U) ^ (c_alpha - 16U)) >> 8;+        if ((c_num0 | c_alpha0) == 0U) {+            if (ignore != NULL && state == 0U && strchr(ignore, c) != NULL) {+                hex_pos++;+                continue;+            }+            break;+        }+        c_val = (c_num0 & c_num) | (c_alpha0 & c_alpha);+        if (bin_pos >= bin_maxlen) {+            ret   = -1;+            errno = ERANGE;+            break;+        }+        if (state == 0U) {+            c_acc = c_val * 16U;+        } else {+            bin[bin_pos++] = c_acc | c_val;+        }+        state = ~state;+        hex_pos++;+    }+    if (state != 0U) {+        hex_pos--;+        errno = EINVAL;+        ret = -1;+    }+    if (ret != 0) {+        bin_pos = (size_t) 0U;+    }+    if (hex_end != NULL) {+        *hex_end = &hex[hex_pos];+    } else if (hex_pos != hex_len) {+        errno = EINVAL;+        ret = -1;+    }+    if (bin_len != NULL) {+        *bin_len = bin_pos;+    }+    return ret;+}++/*+ * Some macros for constant-time comparisons. These work over values in+ * the 0..255 range. Returned value is 0x00 on "false", 0xFF on "true".+ *+ * Original code by Thomas Pornin.+ */+#define EQ(x, y) \+    ((((0U - ((unsigned int) (x) ^ (unsigned int) (y))) >> 8) & 0xFF) ^ 0xFF)+#define GT(x, y) ((((unsigned int) (y) - (unsigned int) (x)) >> 8) & 0xFF)+#define GE(x, y) (GT(y, x) ^ 0xFF)+#define LT(x, y) GT(y, x)+#define LE(x, y) GE(y, x)++static int+b64_byte_to_char(unsigned int x)+{+    return (LT(x, 26) & (x + 'A')) |+           (GE(x, 26) & LT(x, 52) & (x + ('a' - 26))) |+           (GE(x, 52) & LT(x, 62) & (x + ('0' - 52))) | (EQ(x, 62) & '+') |+           (EQ(x, 63) & '/');+}++static unsigned int+b64_char_to_byte(int c)+{+    const unsigned int x =+        (GE(c, 'A') & LE(c, 'Z') & (c - 'A')) |+        (GE(c, 'a') & LE(c, 'z') & (c - ('a' - 26))) |+        (GE(c, '0') & LE(c, '9') & (c - ('0' - 52))) | (EQ(c, '+') & 62) |+        (EQ(c, '/') & 63);++    return x | (EQ(x, 0) & (EQ(c, 'A') ^ 0xFF));+}++static int+b64_byte_to_urlsafe_char(unsigned int x)+{+    return (LT(x, 26) & (x + 'A')) |+           (GE(x, 26) & LT(x, 52) & (x + ('a' - 26))) |+           (GE(x, 52) & LT(x, 62) & (x + ('0' - 52))) | (EQ(x, 62) & '-') |+           (EQ(x, 63) & '_');+}++static unsigned int+b64_urlsafe_char_to_byte(int c)+{+    const unsigned x =+        (GE(c, 'A') & LE(c, 'Z') & (c - 'A')) |+        (GE(c, 'a') & LE(c, 'z') & (c - ('a' - 26))) |+        (GE(c, '0') & LE(c, '9') & (c - ('0' - 52))) | (EQ(c, '-') & 62) |+        (EQ(c, '_') & 63);++    return x | (EQ(x, 0) & (EQ(c, 'A') ^ 0xFF));+}+++#define VARIANT_NO_PADDING_MASK 0x2U+#define VARIANT_URLSAFE_MASK    0x4U++static void+sodium_base64_check_variant(const int variant)+{+    if ((((unsigned int) variant) & ~ 0x6U) != 0x1U) {+        sodium_misuse();+    }+}++size_t+sodium_base64_encoded_len(const size_t bin_len, const int variant)+{+    sodium_base64_check_variant(variant);++    return sodium_base64_ENCODED_LEN(bin_len, variant);+}++char *+sodium_bin2base64(char * const b64, const size_t b64_maxlen,+                  const unsigned char * const bin, const size_t bin_len,+                  const int variant)+{+    size_t       acc_len = (size_t) 0;+    size_t       b64_len;+    size_t       b64_pos = (size_t) 0;+    size_t       bin_pos = (size_t) 0;+    size_t       nibbles;+    size_t       remainder;+    unsigned int acc = 0U;++    sodium_base64_check_variant(variant);+    nibbles = bin_len / 3;+    remainder = bin_len - 3 * nibbles;+    b64_len = nibbles * 4;+    if (remainder != 0) {+        if ((((unsigned int) variant) & VARIANT_NO_PADDING_MASK) == 0U) {+            b64_len += 4;+        } else {+            b64_len += 2 + (remainder >> 1);+        }+    }+    if (b64_maxlen <= b64_len) {+        sodium_misuse();+    }+    if ((((unsigned int) variant) & VARIANT_URLSAFE_MASK) != 0U) {+        while (bin_pos < bin_len) {+            acc = (acc << 8) + bin[bin_pos++];+            acc_len += 8;+            while (acc_len >= 6) {+                acc_len -= 6;+                b64[b64_pos++] = (char) b64_byte_to_urlsafe_char((acc >> acc_len) & 0x3F);+            }+        }+        if (acc_len > 0) {+            b64[b64_pos++] = (char) b64_byte_to_urlsafe_char((acc << (6 - acc_len)) & 0x3F);+        }+    } else {+        while (bin_pos < bin_len) {+            acc = (acc << 8) + bin[bin_pos++];+            acc_len += 8;+            while (acc_len >= 6) {+                acc_len -= 6;+                b64[b64_pos++] = (char) b64_byte_to_char((acc >> acc_len) & 0x3F);+            }+        }+        if (acc_len > 0) {+            b64[b64_pos++] = (char) b64_byte_to_char((acc << (6 - acc_len)) & 0x3F);+        }+    }+    assert(b64_pos <= b64_len);+    while (b64_pos < b64_len) {+        b64[b64_pos++] = '=';+    }+    do {+        b64[b64_pos++] = 0U;+    } while (b64_pos < b64_maxlen);++    return b64;+}++static int+_sodium_base642bin_skip_padding(const char * const b64, const size_t b64_len,+                                size_t * const b64_pos_p,+                                const char * const ignore, size_t padding_len)+{+    int c;++    while (padding_len > 0) {+        if (*b64_pos_p >= b64_len) {+            errno = ERANGE;+            return -1;+        }+        ACQUIRE_FENCE;+        c = b64[*b64_pos_p];+        if (c == '=') {+            padding_len--;+        } else if (ignore == NULL || strchr(ignore, c) == NULL) {+            errno = EINVAL;+            return -1;+        }+        (*b64_pos_p)++;+    }+    return 0;+}++int+sodium_base642bin(unsigned char * const bin, const size_t bin_maxlen,+                  const char * const b64, const size_t b64_len,+                  const char * const ignore, size_t * const bin_len,+                  const char ** const b64_end, const int variant)+{+    size_t       acc_len = (size_t) 0;+    size_t       b64_pos = (size_t) 0;+    size_t       bin_pos = (size_t) 0;+    int          is_urlsafe;+    int          ret = 0;+    unsigned int acc = 0U;+    unsigned int d;+    char         c;++    sodium_base64_check_variant(variant);+    is_urlsafe = ((unsigned int) variant) & VARIANT_URLSAFE_MASK;+    while (b64_pos < b64_len) {+        c = b64[b64_pos];+        if (is_urlsafe) {+            d = b64_urlsafe_char_to_byte(c);+        } else {+            d = b64_char_to_byte(c);+        }+        if (d == 0xFF) {+            if (ignore != NULL && strchr(ignore, c) != NULL) {+                b64_pos++;+                continue;+            }+            break;+        }+        acc = (acc << 6) + d;+        acc_len += 6;+        if (acc_len >= 8) {+            acc_len -= 8;+            if (bin_pos >= bin_maxlen) {+                errno = ERANGE;+                ret = -1;+                break;+            }+            bin[bin_pos++] = (acc >> acc_len) & 0xFF;+        }+        b64_pos++;+    }+    if (acc_len > 4U || (acc & ((1U << acc_len) - 1U)) != 0U) {+        ret = -1;+    } else if (ret == 0 &&+               (((unsigned int) variant) & VARIANT_NO_PADDING_MASK) == 0U) {+        ret = _sodium_base642bin_skip_padding(b64, b64_len, &b64_pos, ignore,+                                              acc_len / 2);+    }+    if (ret != 0) {+        bin_pos = (size_t) 0U;+    } else if (ignore != NULL) {+        while (b64_pos < b64_len && strchr(ignore, b64[b64_pos]) != NULL) {+            b64_pos++;+        }+    }+    if (b64_end != NULL) {+        *b64_end = &b64[b64_pos];+    } else if (b64_pos != b64_len) {+        errno = EINVAL;+        ret = -1;+    }+    if (bin_len != NULL) {+        *bin_len = bin_pos;+    }+    return ret;+}
+ vendor/external/libsodium/sodium/core.c view
@@ -0,0 +1,213 @@++#include <assert.h>+#include <stdlib.h>+#include <string.h>+#include <time.h>+#ifdef _WIN32+# include <windows.h>+#elif defined(HAVE_PTHREAD)+# include <pthread.h>+#endif++#include "core.h"+#include "crypto_generichash.h"+#include "crypto_onetimeauth.h"+#include "crypto_scalarmult.h"+#include "crypto_stream_chacha20.h"+#include "crypto_stream_salsa20.h"+#include "randombytes.h"+#include "runtime.h"+#include "utils.h"+#include "private/implementations.h"+#include "private/mutex.h"++static volatile int initialized;+static volatile int locked;++int+sodium_init(void)+{+    if (sodium_crit_enter() != 0) {+        return -1; /* LCOV_EXCL_LINE */+    }+    if (initialized != 0) {+        if (sodium_crit_leave() != 0) {+            return -1; /* LCOV_EXCL_LINE */+        }+        return 1;+    }+    _sodium_runtime_get_cpu_features();+    randombytes_stir();+    _sodium_alloc_init();+    _crypto_generichash_blake2b_pick_best_implementation();+    _crypto_onetimeauth_poly1305_pick_best_implementation();+    _crypto_scalarmult_curve25519_pick_best_implementation();+    _crypto_stream_chacha20_pick_best_implementation();+    initialized = 1;++    if (sodium_crit_leave() != 0) {+        return -1; /* LCOV_EXCL_LINE */+    }+    return 0;+}++#ifdef _WIN32++static CRITICAL_SECTION _sodium_lock;+static volatile LONG    _sodium_lock_initialized;++static int+_sodium_crit_init(void)+{+    LONG status = 0L;++    while ((status = InterlockedCompareExchange(&_sodium_lock_initialized,+                                                1L, 0L)) == 1L) {+        Sleep(0);+    }++    switch (status) {+    case 0L:+        InitializeCriticalSection(&_sodium_lock);+        return InterlockedExchange(&_sodium_lock_initialized, 2L) == 1L ? 0 : -1;+    case 2L:+        return 0;+    default: /* should never be reached */+        return -1;+    }+}++int+sodium_crit_enter(void)+{+    if (_sodium_crit_init() != 0) {+        return -1; /* LCOV_EXCL_LINE */+    }+    EnterCriticalSection(&_sodium_lock);+    assert(locked == 0);+    locked = 1;++    return 0;+}++int+sodium_crit_leave(void)+{+    if (locked == 0) {+# ifdef EPERM+        errno = EPERM;+# endif+        return -1;+    }+    locked = 0;+    LeaveCriticalSection(&_sodium_lock);++    return 0;+}++#elif defined(HAVE_PTHREAD) && !defined(__EMSCRIPTEN__)++static pthread_mutex_t _sodium_lock = PTHREAD_MUTEX_INITIALIZER;++int+sodium_crit_enter(void)+{+    int ret;++    if ((ret = pthread_mutex_lock(&_sodium_lock)) == 0) {+        assert(locked == 0);+        locked = 1;+    }+    return ret;+}++int+sodium_crit_leave(void)+{+    if (locked == 0) {+# ifdef EPERM+        errno = EPERM;+# endif+        return -1;+    }+    locked = 0;++    return pthread_mutex_unlock(&_sodium_lock);+}++#elif defined(HAVE_ATOMIC_OPS) && !defined(__EMSCRIPTEN__)++static volatile int _sodium_lock;++int+sodium_crit_enter(void)+{+# ifdef HAVE_NANOSLEEP+    struct timespec q;+    memset(&q, 0, sizeof q);+# endif+    while (__sync_lock_test_and_set(&_sodium_lock, 1) != 0) {+# ifdef HAVE_NANOSLEEP+        (void) nanosleep(&q, NULL);+# elif defined(__x86_64__) || defined(__i386__)+        __asm__ __volatile__ ("pause");+# endif+    }+    return 0;+}++int+sodium_crit_leave(void)+{+    __sync_lock_release(&_sodium_lock);++    return 0;+}++#else++int+sodium_crit_enter(void)+{+    return 0;+}++int+sodium_crit_leave(void)+{+    return 0;+}++#endif++static void (*_misuse_handler)(void);++void+sodium_misuse(void)+{+    void (*handler)(void);++    (void) sodium_crit_leave();+    if (sodium_crit_enter() == 0) {+        handler = _misuse_handler;+        if (handler != NULL) {+            handler();+        }+    }+/* LCOV_EXCL_START */+    abort();+}+/* LCOV_EXCL_STOP */++int+sodium_set_misuse_handler(void (*handler)(void))+{+    if (sodium_crit_enter() != 0) {+        return -1; /* LCOV_EXCL_LINE */+    }+    _misuse_handler = handler;+    if (sodium_crit_leave() != 0) {+        return -1; /* LCOV_EXCL_LINE */+    }+    return 0;+}
+ vendor/external/libsodium/sodium/runtime.c view
@@ -0,0 +1,392 @@+#include <stddef.h>+#include <stdint.h>+#ifdef HAVE_ANDROID_GETCPUFEATURES+# include <cpu-features.h>+#endif+#ifdef __APPLE__+# include <sys/types.h>+# include <sys/sysctl.h>+# include <mach/machine.h>+#endif+#ifdef HAVE_SYS_AUXV_H+# include <sys/auxv.h>+#endif++#include "private/common.h"+#include "runtime.h"++typedef struct CPUFeatures_ {+    int initialized;+    int has_neon;+    int has_armcrypto;+    int has_sse2;+    int has_sse3;+    int has_ssse3;+    int has_sse41;+    int has_avx;+    int has_avx2;+    int has_avx512f;+    int has_pclmul;+    int has_aesni;+    int has_rdrand;+} CPUFeatures;++static CPUFeatures _cpu_features;++#define CPUID_EBX_AVX2    0x00000020+#define CPUID_EBX_AVX512F 0x00010000++#define CPUID_ECX_SSE3    0x00000001+#define CPUID_ECX_PCLMUL  0x00000002+#define CPUID_ECX_SSSE3   0x00000200+#define CPUID_ECX_SSE41   0x00080000+#define CPUID_ECX_AESNI   0x02000000+#define CPUID_ECX_XSAVE   0x04000000+#define CPUID_ECX_OSXSAVE 0x08000000+#define CPUID_ECX_AVX     0x10000000+#define CPUID_ECX_RDRAND  0x40000000++#define CPUID_EDX_SSE2    0x04000000++#define XCR0_SSE       0x00000002+#define XCR0_AVX       0x00000004+#define XCR0_OPMASK    0x00000020+#define XCR0_ZMM_HI256 0x00000040+#define XCR0_HI16_ZMM  0x00000080++static int+_sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features)+{+    cpu_features->has_neon = 0;+    cpu_features->has_armcrypto = 0;++#ifndef __ARM_ARCH+    return -1; /* LCOV_EXCL_LINE */+#endif++#if defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM64)+    cpu_features->has_neon = 1;+#elif defined(HAVE_ANDROID_GETCPUFEATURES)+    cpu_features->has_neon =+        (android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_ASIMD) != 0x0;+#elif (defined(__aarch64__) || defined(_M_ARM64)) && defined(AT_HWCAP)+# ifdef HAVE_GETAUXVAL+    cpu_features->has_neon = (getauxval(AT_HWCAP) & (1L << 1)) != 0;+# elif defined(HAVE_ELF_AUX_INFO)+    {+        unsigned long buf;+        if (elf_aux_info(AT_HWCAP, (void *) &buf, (int) sizeof buf) == 0) {+            cpu_features->has_neon = (buf & (1L << 1)) != 0;+        }+    }+# endif+#elif defined(__arm__) && defined(AT_HWCAP)+# ifdef HAVE_GETAUXVAL+    cpu_features->has_neon = (getauxval(AT_HWCAP) & (1L << 12)) != 0;+# elif defined(HAVE_ELF_AUX_INFO)+    {+        unsigned long buf;+        if (elf_aux_info(AT_HWCAP, (void *) &buf, (int) sizeof buf) == 0) {+            cpu_features->has_neon = (buf & (1L << 12)) != 0;+        }+    }+# endif+#endif++    if (cpu_features->has_neon == 0) {+        return 0;+    }++#if defined(__ARM_FEATURE_CRYPTO) && defined(__ARM_FEATURE_AES)+    cpu_features->has_armcrypto = 1;+#elif defined(_M_ARM64)+    cpu_features->has_armcrypto = 1; /* assuming all CPUs supported by ARM Windows have the crypto extensions */+#elif defined(__APPLE__) && defined(CPU_TYPE_ARM64) && defined(CPU_SUBTYPE_ARM64E)+    {+        cpu_type_t    cpu_type;+        cpu_subtype_t cpu_subtype;+        size_t        cpu_type_len = sizeof cpu_type;+        size_t        cpu_subtype_len = sizeof cpu_subtype;++        if (sysctlbyname("hw.cputype", &cpu_type, &cpu_type_len,+                         NULL, 0) == 0 && cpu_type == CPU_TYPE_ARM64 &&+            sysctlbyname("hw.cpusubtype", &cpu_subtype, &cpu_subtype_len,+                         NULL, 0) == 0 &&+            (cpu_subtype == CPU_SUBTYPE_ARM64E ||+                cpu_subtype == CPU_SUBTYPE_ARM64_V8)) {+            cpu_features->has_armcrypto = 1;+        }+    }+#elif defined(HAVE_ANDROID_GETCPUFEATURES)+    cpu_features->has_armcrypto =+        (android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_AES) != 0x0;+#elif (defined(__aarch64__) || defined(_M_ARM64)) && defined(AT_HWCAP)+# ifdef HAVE_GETAUXVAL+    cpu_features->has_armcrypto = (getauxval(AT_HWCAP) & (1L << 3)) != 0;+# elif defined(HAVE_ELF_AUX_INFO)+    {+        unsigned long buf;+        if (elf_aux_info(AT_HWCAP, (void *) &buf, (int) sizeof buf) == 0) {+            cpu_features->has_armcrypto = (buf & (1L << 3)) != 0;+        }+    }+# endif+#elif defined(__arm__) && defined(AT_HWCAP2)+# ifdef HAVE_GETAUXVAL+    cpu_features->has_armcrypto = (getauxval(AT_HWCAP2) & (1L << 0)) != 0;+# elif defined(HAVE_ELF_AUX_INFO)+    {+        unsigned long buf;+        if (elf_aux_info(AT_HWCAP2, (void *) &buf, (int) sizeof buf) == 0) {+            cpu_features->has_armcrypto = (buf & (1L << 0)) != 0;+        }+    }+# endif+#endif++    return 0;+}++static void+_cpuid(unsigned int cpu_info[4U], const unsigned int cpu_info_type)+{+#if defined(_MSC_VER) && \+    (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86))+    __cpuid((int *) cpu_info, cpu_info_type);+#elif defined(HAVE_CPUID)+    cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0;+# ifdef __i386__+    __asm__ __volatile__(+        "pushfl; pushfl; "+        "popl %0; "+        "movl %0, %1; xorl %2, %0; "+        "pushl %0; "+        "popfl; pushfl; popl %0; popfl"+        : "=&r"(cpu_info[0]), "=&r"(cpu_info[1])+        : "i"(0x200000));+    if (((cpu_info[0] ^ cpu_info[1]) & 0x200000) == 0x0) {+        return; /* LCOV_EXCL_LINE */+    }+# endif+# ifdef __i386__+    __asm__ __volatile__("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1"+                         : "=a"(cpu_info[0]), "=&r"(cpu_info[1]),+                           "=c"(cpu_info[2]), "=d"(cpu_info[3])+                         : "0"(cpu_info_type), "2"(0U));+# elif defined(__x86_64__)+    __asm__ __volatile__("xchgq %%rbx, %q1; cpuid; xchgq %%rbx, %q1"+                         : "=a"(cpu_info[0]), "=&r"(cpu_info[1]),+                           "=c"(cpu_info[2]), "=d"(cpu_info[3])+                         : "0"(cpu_info_type), "2"(0U));+# else+    __asm__ __volatile__("cpuid"+                         : "=a"(cpu_info[0]), "=b"(cpu_info[1]),+                           "=c"(cpu_info[2]), "=d"(cpu_info[3])+                         : "0"(cpu_info_type), "2"(0U));+# endif+#else+    (void) cpu_info_type;+    cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0;+#endif+}++static int+_sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features)+{+    unsigned int cpu_info[4];+    uint32_t     xcr0 = 0U;++    _cpuid(cpu_info, 0x0);+    if (cpu_info[0] == 0U) {+        return -1; /* LCOV_EXCL_LINE */+    }+    _cpuid(cpu_info, 0x00000001);+#ifdef HAVE_EMMINTRIN_H+    cpu_features->has_sse2 = ((cpu_info[3] & CPUID_EDX_SSE2) != 0x0);+#else+    cpu_features->has_sse2   = 0;+#endif++#ifdef HAVE_PMMINTRIN_H+    cpu_features->has_sse3 = ((cpu_info[2] & CPUID_ECX_SSE3) != 0x0);+#else+    cpu_features->has_sse3   = 0;+#endif++#ifdef HAVE_TMMINTRIN_H+    cpu_features->has_ssse3 = ((cpu_info[2] & CPUID_ECX_SSSE3) != 0x0);+#else+    cpu_features->has_ssse3  = 0;+#endif++#ifdef HAVE_SMMINTRIN_H+    cpu_features->has_sse41 = ((cpu_info[2] & CPUID_ECX_SSE41) != 0x0);+#else+    cpu_features->has_sse41  = 0;+#endif++    cpu_features->has_avx = 0;++    (void) xcr0;+#ifdef HAVE_AVXINTRIN_H+    if ((cpu_info[2] & (CPUID_ECX_AVX | CPUID_ECX_XSAVE | CPUID_ECX_OSXSAVE)) ==+        (CPUID_ECX_AVX | CPUID_ECX_XSAVE | CPUID_ECX_OSXSAVE)) {+        xcr0 = 0U;+# if defined(HAVE__XGETBV) || \+        (defined(_MSC_VER) && defined(_XCR_XFEATURE_ENABLED_MASK) && _MSC_FULL_VER >= 160040219)+        xcr0 = (uint32_t) _xgetbv(0);+# elif defined(_MSC_VER) && defined(_M_IX86)+        /*+         * Visual Studio documentation states that eax/ecx/edx don't need to+         * be preserved in inline assembly code. But that doesn't seem to+         * always hold true on Visual Studio 2010.+         */+        __asm {+            push eax+            push ecx+            push edx+            xor ecx, ecx+            _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0+            mov xcr0, eax+            pop edx+            pop ecx+            pop eax+        }+# elif defined(HAVE_AVX_ASM)+        __asm__ __volatile__(".byte 0x0f, 0x01, 0xd0" /* XGETBV */+                             : "=a"(xcr0)+                             : "c"((uint32_t) 0U)+                             : "%edx");+# endif+        if ((xcr0 & (XCR0_SSE | XCR0_AVX)) == (XCR0_SSE | XCR0_AVX)) {+            cpu_features->has_avx = 1;+        }+    }+#endif++    cpu_features->has_avx2 = 0;+#ifdef HAVE_AVX2INTRIN_H+    if (cpu_features->has_avx) {+        unsigned int cpu_info7[4];++        _cpuid(cpu_info7, 0x00000007);+        cpu_features->has_avx2 = ((cpu_info7[1] & CPUID_EBX_AVX2) != 0x0);+    }+#endif++    cpu_features->has_avx512f = 0;+#ifdef HAVE_AVX512FINTRIN_H+    if (cpu_features->has_avx2) {+        unsigned int cpu_info7[4];++        _cpuid(cpu_info7, 0x00000007);+        /* LCOV_EXCL_START */+        if ((cpu_info7[1] & CPUID_EBX_AVX512F) == CPUID_EBX_AVX512F &&+            (xcr0 & (XCR0_OPMASK | XCR0_ZMM_HI256 | XCR0_HI16_ZMM))+            == (XCR0_OPMASK | XCR0_ZMM_HI256 | XCR0_HI16_ZMM)) {+            cpu_features->has_avx512f = 1;+        }+        /* LCOV_EXCL_STOP */+    }+#endif++#ifdef HAVE_WMMINTRIN_H+    cpu_features->has_pclmul = ((cpu_info[2] & CPUID_ECX_PCLMUL) != 0x0);+    cpu_features->has_aesni  = ((cpu_info[2] & CPUID_ECX_AESNI) != 0x0);+#else+    cpu_features->has_pclmul = 0;+    cpu_features->has_aesni  = 0;+#endif++#ifdef HAVE_RDRAND+    cpu_features->has_rdrand = ((cpu_info[2] & CPUID_ECX_RDRAND) != 0x0);+#else+    cpu_features->has_rdrand = 0;+#endif++    return 0;+}++int+_sodium_runtime_get_cpu_features(void)+{+    int ret = -1;++    ret &= _sodium_runtime_arm_cpu_features(&_cpu_features);+    ret &= _sodium_runtime_intel_cpu_features(&_cpu_features);+    _cpu_features.initialized = 1;++    return ret;+}++int+sodium_runtime_has_neon(void)+{+    return _cpu_features.has_neon;+}++int+sodium_runtime_has_armcrypto(void)+{+    return _cpu_features.has_armcrypto;+}++int+sodium_runtime_has_sse2(void)+{+    return _cpu_features.has_sse2;+}++int+sodium_runtime_has_sse3(void)+{+    return _cpu_features.has_sse3;+}++int+sodium_runtime_has_ssse3(void)+{+    return _cpu_features.has_ssse3;+}++int+sodium_runtime_has_sse41(void)+{+    return _cpu_features.has_sse41;+}++int+sodium_runtime_has_avx(void)+{+    return _cpu_features.has_avx;+}++int+sodium_runtime_has_avx2(void)+{+    return _cpu_features.has_avx2;+}++int+sodium_runtime_has_avx512f(void)+{+    return _cpu_features.has_avx512f;+}++int+sodium_runtime_has_pclmul(void)+{+    return _cpu_features.has_pclmul;+}++int+sodium_runtime_has_aesni(void)+{+    return _cpu_features.has_aesni;+}++int+sodium_runtime_has_rdrand(void)+{+    return _cpu_features.has_rdrand;+}
+ vendor/external/libsodium/sodium/utils.c view
@@ -0,0 +1,809 @@+#ifndef __STDC_WANT_LIB_EXT1__+# define __STDC_WANT_LIB_EXT1__ 1+#endif+#include <assert.h>+#include <errno.h>+#include <limits.h>+#include <stddef.h>+#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#if defined(HAVE_RAISE) && !defined(__wasm__)+# include <signal.h>+#endif++#ifdef HAVE_SYS_MMAN_H+# include <sys/mman.h>+#endif++#ifdef HAVE_SYS_PARAM_H+# include <sys/param.h>+#endif++#ifdef _WIN32+# include <windows.h>+# include <wincrypt.h>+#else+# include <unistd.h>+#endif++#ifndef HAVE_C_VARARRAYS+# ifdef HAVE_ALLOCA_H+#  include <alloca.h>+# elif !defined(alloca)+#  if defined(__clang__) || defined(__GNUC__)+#   define alloca __builtin_alloca+#  elif defined _AIX+#   define alloca __alloca+#  elif defined _MSC_VER+#   include <malloc.h>+#   define alloca _alloca+#  else+#   include <stddef.h>+#   ifdef  __cplusplus+extern "C"+#   endif+void *alloca (size_t);+#  endif+# endif+#endif++#include "core.h"+#include "randombytes.h"+#include "utils.h"++#ifndef ENOSYS+# define ENOSYS ENXIO+#endif++#if defined(_WIN32) && \+    (!defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)+# define WINAPI_DESKTOP+#endif++#define CANARY_SIZE 16U+#define GARBAGE_VALUE 0xdb++#ifndef MAP_NOCORE+# ifdef MAP_CONCEAL+#  define MAP_NOCORE MAP_CONCEAL+# else+#  define MAP_NOCORE 0+# endif+#endif+#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)+# define MAP_ANON MAP_ANONYMOUS+#endif+#if defined(WINAPI_DESKTOP) || (defined(MAP_ANON) && defined(HAVE_MMAP)) || \+    defined(HAVE_POSIX_MEMALIGN)+# define HAVE_ALIGNED_MALLOC+#endif++#if defined(HAVE_MPROTECT) && \+    !(defined(PROT_NONE) && defined(PROT_READ) && defined(PROT_WRITE))+# undef HAVE_MPROTECT+#endif+#if defined(HAVE_ALIGNED_MALLOC) && \+    (defined(WINAPI_DESKTOP) || defined(HAVE_MPROTECT))+# define HAVE_PAGE_PROTECTION+#endif+#if !defined(MADV_DODUMP) && defined(MADV_CORE)+# define MADV_DODUMP   MADV_CORE+# define MADV_DONTDUMP MADV_NOCORE+#endif++#ifndef DEFAULT_PAGE_SIZE+# ifdef PAGE_SIZE+#  define DEFAULT_PAGE_SIZE PAGE_SIZE+# else+#  define DEFAULT_PAGE_SIZE 0x10000+# endif+#endif++static size_t        page_size = DEFAULT_PAGE_SIZE;+static unsigned char canary[CANARY_SIZE];++/* LCOV_EXCL_START */+#ifdef HAVE_WEAK_SYMBOLS+__attribute__((weak)) void+_sodium_dummy_symbol_to_prevent_memzero_lto(void *const  pnt,+                                            const size_t len);+__attribute__((weak)) void+_sodium_dummy_symbol_to_prevent_memzero_lto(void *const  pnt,+                                            const size_t len)+{+    (void) pnt; /* LCOV_EXCL_LINE */+    (void) len; /* LCOV_EXCL_LINE */+}+#endif+/* LCOV_EXCL_STOP */++void+sodium_memzero(void * const pnt, const size_t len)+{+#if defined(_WIN32) && !defined(__CRT_INLINE)+    SecureZeroMemory(pnt, len);+#elif defined(HAVE_MEMSET_S)+    if (len > 0U && memset_s(pnt, (rsize_t) len, 0, (rsize_t) len) != 0) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+#elif defined(HAVE_EXPLICIT_BZERO)+    explicit_bzero(pnt, len);+#elif defined(HAVE_MEMSET_EXPLICIT)+    memset_explicit(pnt, 0, len);+#elif defined(HAVE_EXPLICIT_MEMSET)+    explicit_memset(pnt, 0, len);+#elif HAVE_WEAK_SYMBOLS+    if (len > 0U) {+        memset(pnt, 0, len);+        _sodium_dummy_symbol_to_prevent_memzero_lto(pnt, len);+    }+# ifdef HAVE_INLINE_ASM+    __asm__ __volatile__ ("" : : "r"(pnt) : "memory");+# endif+#else+    volatile unsigned char *volatile pnt_ =+        (volatile unsigned char *volatile) pnt;+    size_t i = (size_t) 0U;++    while (i < len) {+        pnt_[i++] = 0U;+    }+#endif+}++void+sodium_stackzero(const size_t len)+{+#ifdef HAVE_C_VARARRAYS+    unsigned char fodder[len];+    sodium_memzero(fodder, len);+#elif HAVE_ALLOCA+    sodium_memzero(alloca(len), len);+#endif+}++#ifdef HAVE_WEAK_SYMBOLS+__attribute__((weak)) void+_sodium_dummy_symbol_to_prevent_memcmp_lto(const unsigned char *b1,+                                           const unsigned char *b2,+                                           const size_t         len);+__attribute__((weak)) void+_sodium_dummy_symbol_to_prevent_memcmp_lto(const unsigned char *b1,+                                           const unsigned char *b2,+                                           const size_t         len)+{+    (void) b1;+    (void) b2;+    (void) len;+}+#endif++int+sodium_memcmp(const void *const b1_, const void *const b2_, size_t len)+{+#ifdef HAVE_WEAK_SYMBOLS+    const unsigned char *b1 = (const unsigned char *) b1_;+    const unsigned char *b2 = (const unsigned char *) b2_;+#else+    const volatile unsigned char *volatile b1 =+        (const volatile unsigned char *volatile) b1_;+    const volatile unsigned char *volatile b2 =+        (const volatile unsigned char *volatile) b2_;+#endif+    size_t                 i;+    volatile unsigned char d = 0U;++#if HAVE_WEAK_SYMBOLS+    _sodium_dummy_symbol_to_prevent_memcmp_lto(b1, b2, len);+#endif+    for (i = 0U; i < len; i++) {+        d |= b1[i] ^ b2[i];+    }+    return (1 & ((d - 1) >> 8)) - 1;+}++#ifdef HAVE_WEAK_SYMBOLS+__attribute__((weak)) void+_sodium_dummy_symbol_to_prevent_compare_lto(const unsigned char *b1,+                                            const unsigned char *b2,+                                            const size_t         len);+__attribute__((weak)) void+_sodium_dummy_symbol_to_prevent_compare_lto(const unsigned char *b1,+                                            const unsigned char *b2,+                                            const size_t         len)+{+    (void) b1;+    (void) b2;+    (void) len;+}+#endif++int+sodium_compare(const unsigned char *b1_, const unsigned char *b2_, size_t len)+{+#ifdef HAVE_WEAK_SYMBOLS+    const unsigned char *b1 = b1_;+    const unsigned char *b2 = b2_;+#else+    const volatile unsigned char *volatile b1 =+        (const volatile unsigned char *volatile) b1_;+    const volatile unsigned char *volatile b2 =+        (const volatile unsigned char *volatile) b2_;+#endif+    size_t                 i;+    volatile unsigned char gt = 0U;+    volatile unsigned char eq = 1U;+    uint16_t               x1, x2;++#if HAVE_WEAK_SYMBOLS+    _sodium_dummy_symbol_to_prevent_compare_lto(b1, b2, len);+#endif+    i = len;+    while (i != 0U) {+        i--;+        x1 = b1[i];+        x2 = b2[i];+        gt |= (((unsigned int) x2 - (unsigned int) x1) >> 8) & eq;+        eq &= (((unsigned int) (x2 ^ x1)) - 1) >> 8;+    }+    return (int) (gt + gt + eq) - 1;+}++int+sodium_is_zero(const unsigned char *n, const size_t nlen)+{+    size_t                 i;+    volatile unsigned char d = 0U;++    for (i = 0U; i < nlen; i++) {+        d |= n[i];+    }+    return 1 & ((d - 1) >> 8);+}++void+sodium_increment(unsigned char *n, const size_t nlen)+{+    size_t        i = 0U;+    uint_fast16_t c = 1U;++#ifdef HAVE_AMD64_ASM+    uint64_t t64, t64_2;+    uint32_t t32;++    if (nlen == 12U) {+        __asm__ __volatile__(+            "xorq %[t64], %[t64] \n"+            "xorl %[t32], %[t32] \n"+            "stc \n"+            "adcq %[t64], (%[out]) \n"+            "adcl %[t32], 8(%[out]) \n"+            : [t64] "=&r"(t64), [t32] "=&r"(t32)+            : [out] "D"(n)+            : "memory", "flags", "cc");+        return;+    } else if (nlen == 24U) {+        __asm__ __volatile__(+            "movq $1, %[t64] \n"+            "xorq %[t64_2], %[t64_2] \n"+            "addq %[t64], (%[out]) \n"+            "adcq %[t64_2], 8(%[out]) \n"+            "adcq %[t64_2], 16(%[out]) \n"+            : [t64] "=&r"(t64), [t64_2] "=&r"(t64_2)+            : [out] "D"(n)+            : "memory", "flags", "cc");+        return;+    } else if (nlen == 8U) {+        __asm__ __volatile__("incq (%[out]) \n"+                             :+                             : [out] "D"(n)+                             : "memory", "flags", "cc");+        return;+    }+#endif+    for (; i < nlen; i++) {+        c += (uint_fast16_t) n[i];+        n[i] = (unsigned char) c;+        c >>= 8;+    }+}++void+sodium_add(unsigned char *a, const unsigned char *b, const size_t len)+{+    size_t        i;+    uint_fast16_t c = 0U;++#ifdef HAVE_AMD64_ASM+    uint64_t t64, t64_2, t64_3;+    uint32_t t32;++    if (len == 12U) {+        __asm__ __volatile__(+            "movq (%[in]), %[t64] \n"+            "movl 8(%[in]), %[t32] \n"+            "addq %[t64], (%[out]) \n"+            "adcl %[t32], 8(%[out]) \n"+            : [t64] "=&r"(t64), [t32] "=&r"(t32)+            : [in] "S"(b), [out] "D"(a)+            : "memory", "flags", "cc");+        return;+    } else if (len == 24U) {+        __asm__ __volatile__(+            "movq (%[in]), %[t64] \n"+            "movq 8(%[in]), %[t64_2] \n"+            "movq 16(%[in]), %[t64_3] \n"+            "addq %[t64], (%[out]) \n"+            "adcq %[t64_2], 8(%[out]) \n"+            "adcq %[t64_3], 16(%[out]) \n"+            : [t64] "=&r"(t64), [t64_2] "=&r"(t64_2), [t64_3] "=&r"(t64_3)+            : [in] "S"(b), [out] "D"(a)+            : "memory", "flags", "cc");+        return;+    } else if (len == 8U) {+        __asm__ __volatile__(+            "movq (%[in]), %[t64] \n"+            "addq %[t64], (%[out]) \n"+            : [t64] "=&r"(t64)+            : [in] "S"(b), [out] "D"(a)+            : "memory", "flags", "cc");+        return;+    }+#endif+    for (i = 0U; i < len; i++) {+        c += (uint_fast16_t) a[i] + (uint_fast16_t) b[i];+        a[i] = (unsigned char) c;+        c >>= 8;+    }+}++void+sodium_sub(unsigned char *a, const unsigned char *b, const size_t len)+{+    uint_fast16_t c = 0U;+    size_t        i;++#ifdef HAVE_AMD64_ASM+    uint64_t t64_1, t64_2, t64_3, t64_4;+    uint64_t t64_5, t64_6, t64_7, t64_8;+    uint32_t t32;++    if (len == 64U) {+        __asm__ __volatile__(+            "movq   (%[in]), %[t64_1] \n"+            "movq  8(%[in]), %[t64_2] \n"+            "movq 16(%[in]), %[t64_3] \n"+            "movq 24(%[in]), %[t64_4] \n"+            "movq 32(%[in]), %[t64_5] \n"+            "movq 40(%[in]), %[t64_6] \n"+            "movq 48(%[in]), %[t64_7] \n"+            "movq 56(%[in]), %[t64_8] \n"+            "subq %[t64_1],   (%[out]) \n"+            "sbbq %[t64_2],  8(%[out]) \n"+            "sbbq %[t64_3], 16(%[out]) \n"+            "sbbq %[t64_4], 24(%[out]) \n"+            "sbbq %[t64_5], 32(%[out]) \n"+            "sbbq %[t64_6], 40(%[out]) \n"+            "sbbq %[t64_7], 48(%[out]) \n"+            "sbbq %[t64_8], 56(%[out]) \n"+            : [t64_1] "=&r"(t64_1), [t64_2] "=&r"(t64_2), [t64_3] "=&r"(t64_3), [t64_4] "=&r"(t64_4),+              [t64_5] "=&r"(t64_5), [t64_6] "=&r"(t64_6), [t64_7] "=&r"(t64_7), [t64_8] "=&r"(t64_8)+            : [in] "S"(b), [out] "D"(a)+            : "memory", "flags", "cc");+        return;+    }+#endif+    for (i = 0U; i < len; i++) {+        c = (uint_fast16_t) a[i] - (uint_fast16_t) b[i] - c;+        a[i] = (unsigned char) c;+        c = (c >> 8) & 1U;+    }+}++int+_sodium_alloc_init(void)+{+#ifdef HAVE_ALIGNED_MALLOC+# if defined(_SC_PAGESIZE) && defined(HAVE_SYSCONF)+    long page_size_ = sysconf(_SC_PAGESIZE);+    if (page_size_ > 0L) {+        page_size = (size_t) page_size_;+    }+# elif defined(WINAPI_DESKTOP)+    SYSTEM_INFO si;+    GetSystemInfo(&si);+    page_size = (size_t) si.dwPageSize;+# elif !defined(PAGE_SIZE)+#  warning Unknown page size+# endif+    if (page_size < CANARY_SIZE || page_size < sizeof(size_t)) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+#endif+    randombytes_buf(canary, sizeof canary);++    return 0;+}++int+sodium_mlock(void *const addr, const size_t len)+{+#if defined(MADV_DONTDUMP) && defined(HAVE_MADVISE)+    (void) madvise(addr, len, MADV_DONTDUMP);+#endif+#ifdef HAVE_MLOCK+    return mlock(addr, len);+#elif defined(WINAPI_DESKTOP)+    return -(VirtualLock(addr, len) == 0);+#else+    errno = ENOSYS;+    return -1;+#endif+}++int+sodium_munlock(void *const addr, const size_t len)+{+    sodium_memzero(addr, len);+#if defined(MADV_DODUMP) && defined(HAVE_MADVISE)+    (void) madvise(addr, len, MADV_DODUMP);+#endif+#ifdef HAVE_MLOCK+    return munlock(addr, len);+#elif defined(WINAPI_DESKTOP)+    return -(VirtualUnlock(addr, len) == 0);+#else+    errno = ENOSYS;+    return -1;+#endif+}++static int+_mprotect_noaccess(void *ptr, size_t size)+{+#ifdef HAVE_MPROTECT+    return mprotect(ptr, size, PROT_NONE);+#elif defined(WINAPI_DESKTOP)+    DWORD old;+    return -(VirtualProtect(ptr, size, PAGE_NOACCESS, &old) == 0);+#else+    errno = ENOSYS;+    return -1;+#endif+}++static int+_mprotect_readonly(void *ptr, size_t size)+{+#ifdef HAVE_MPROTECT+    return mprotect(ptr, size, PROT_READ);+#elif defined(WINAPI_DESKTOP)+    DWORD old;+    return -(VirtualProtect(ptr, size, PAGE_READONLY, &old) == 0);+#else+    errno = ENOSYS;+    return -1;+#endif+}++static int+_mprotect_readwrite(void *ptr, size_t size)+{+#ifdef HAVE_MPROTECT+    return mprotect(ptr, size, PROT_READ | PROT_WRITE);+#elif defined(WINAPI_DESKTOP)+    DWORD old;+    return -(VirtualProtect(ptr, size, PAGE_READWRITE, &old) == 0);+#else+    errno = ENOSYS;+    return -1;+#endif+}++#ifdef HAVE_ALIGNED_MALLOC++__attribute__((noreturn)) static void+_out_of_bounds(void)+{+# if defined(HAVE_RAISE) && !defined(__wasm__)+#  ifdef SIGPROT+    raise(SIGPROT);+#  elif defined(SIGSEGV)+    raise(SIGSEGV);+#  elif defined(SIGKILL)+    raise(SIGKILL);+#  endif+# endif+    abort(); /* not something we want any higher-level API to catch */+} /* LCOV_EXCL_LINE */++static inline size_t+_page_round(const size_t size)+{+    const size_t page_mask = page_size - 1U;++    return (size + page_mask) & ~page_mask;+}++static __attribute__((malloc)) unsigned char *+_alloc_aligned(const size_t size)+{+    void *ptr;++# if defined(MAP_ANON) && defined(HAVE_MMAP)+    if ((ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,+                    MAP_ANON | MAP_PRIVATE | MAP_NOCORE, -1, 0)) ==+        MAP_FAILED) {+        ptr = NULL; /* LCOV_EXCL_LINE */+    }               /* LCOV_EXCL_LINE */+# elif defined(HAVE_POSIX_MEMALIGN)+    if (posix_memalign(&ptr, page_size, size) != 0) {+        ptr = NULL; /* LCOV_EXCL_LINE */+    }               /* LCOV_EXCL_LINE */+# elif defined(WINAPI_DESKTOP)+    ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);+# else+#  error Bug+# endif+    return (unsigned char *) ptr;+}++static void+_free_aligned(unsigned char *const ptr, const size_t size)+{+# if defined(MAP_ANON) && defined(HAVE_MMAP)+    (void) munmap(ptr, size);+# elif defined(HAVE_POSIX_MEMALIGN)+    free(ptr);+# elif defined(WINAPI_DESKTOP)+    VirtualFree(ptr, 0U, MEM_RELEASE);+# else+#  error Bug+#endif+}++static unsigned char *+_unprotected_ptr_from_user_ptr(void *const ptr)+{+    uintptr_t      unprotected_ptr_u;+    unsigned char *canary_ptr;+    size_t         page_mask;++    canary_ptr = ((unsigned char *) ptr) - sizeof canary;+    page_mask = page_size - 1U;+    unprotected_ptr_u = ((uintptr_t) canary_ptr & (uintptr_t) ~page_mask);+    if (unprotected_ptr_u <= page_size * 2U) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+    return (unsigned char *) unprotected_ptr_u;+}++#endif /* HAVE_ALIGNED_MALLOC */++#ifndef HAVE_ALIGNED_MALLOC+static __attribute__((malloc)) void *+_sodium_malloc(const size_t size)+{+    return malloc(size > (size_t) 0U ? size : (size_t) 1U);+}+#else+static __attribute__((malloc)) void *+_sodium_malloc(const size_t size)+{+    void          *user_ptr;+    unsigned char *base_ptr;+    unsigned char *canary_ptr;+    unsigned char *unprotected_ptr;+    size_t         size_with_canary;+    size_t         total_size;+    size_t         unprotected_size;++    if (size >= (size_t) SIZE_MAX - page_size * 4U) {+        errno = ENOMEM;+        return NULL;+    }+    if (page_size <= sizeof canary || page_size < sizeof unprotected_size) {+        sodium_misuse(); /* LCOV_EXCL_LINE */+    }+    size_with_canary = (sizeof canary) + size;+    unprotected_size = _page_round(size_with_canary);+    total_size       = page_size + page_size + unprotected_size + page_size;+    if ((base_ptr = _alloc_aligned(total_size)) == NULL) {+        return NULL; /* LCOV_EXCL_LINE */+    }+    unprotected_ptr = base_ptr + page_size * 2U;+    _mprotect_noaccess(base_ptr + page_size, page_size);+# ifndef HAVE_PAGE_PROTECTION+    memcpy(unprotected_ptr + unprotected_size, canary, sizeof canary);+# endif+    _mprotect_noaccess(unprotected_ptr + unprotected_size, page_size);+    (void) sodium_mlock(unprotected_ptr, unprotected_size); /* not a hard error in the context of sodium_malloc() */+    canary_ptr =+        unprotected_ptr + _page_round(size_with_canary) - size_with_canary;+    user_ptr = canary_ptr + sizeof canary;+    memcpy(canary_ptr, canary, sizeof canary);+    memcpy(base_ptr, &unprotected_size, sizeof unprotected_size);+    _mprotect_readonly(base_ptr, page_size);+    assert(_unprotected_ptr_from_user_ptr(user_ptr) == unprotected_ptr);++    return user_ptr;+}+#endif /* !HAVE_ALIGNED_MALLOC */++__attribute__((malloc)) void *+sodium_malloc(const size_t size)+{+    void *ptr;++    if ((ptr = _sodium_malloc(size)) == NULL) {+        return NULL;+    }+    memset(ptr, (int) GARBAGE_VALUE, size);++    return ptr;+}++__attribute__((malloc)) void *+sodium_allocarray(size_t count, size_t size)+{+    if (count > (size_t) 0U && size >= (size_t) SIZE_MAX / count) {+        errno = ENOMEM;+        return NULL;+    }+    return sodium_malloc(count * size);+}++#ifndef HAVE_ALIGNED_MALLOC+void+sodium_free(void *ptr)+{+    free(ptr);+}+#else+void+sodium_free(void *ptr)+{+    unsigned char *base_ptr;+    unsigned char *canary_ptr;+    unsigned char *unprotected_ptr;+    size_t         total_size;+    size_t         unprotected_size;++    if (ptr == NULL) {+        return;+    }+    canary_ptr      = ((unsigned char *) ptr) - sizeof canary;+    unprotected_ptr = _unprotected_ptr_from_user_ptr(ptr);+    base_ptr        = unprotected_ptr - page_size * 2U;+    memcpy(&unprotected_size, base_ptr, sizeof unprotected_size);+    total_size = page_size + page_size + unprotected_size + page_size;+    _mprotect_readwrite(base_ptr, total_size);+    if (sodium_memcmp(canary_ptr, canary, sizeof canary) != 0) {+        _out_of_bounds();+    }+# ifndef HAVE_PAGE_PROTECTION+    if (sodium_memcmp(unprotected_ptr + unprotected_size, canary,+                      sizeof canary) != 0) {+        _out_of_bounds();+    }+# endif+    (void) sodium_munlock(unprotected_ptr, unprotected_size);+    _free_aligned(base_ptr, total_size);+}+#endif /* HAVE_ALIGNED_MALLOC */++#ifndef HAVE_PAGE_PROTECTION+static int+_sodium_mprotect(void *ptr, int (*cb)(void *ptr, size_t size))+{+    (void) ptr;+    (void) cb;+    errno = ENOSYS;+    return -1;+}+#else+static int+_sodium_mprotect(void *ptr, int (*cb)(void *ptr, size_t size))+{+    unsigned char *base_ptr;+    unsigned char *unprotected_ptr;+    size_t         unprotected_size;++    unprotected_ptr = _unprotected_ptr_from_user_ptr(ptr);+    base_ptr        = unprotected_ptr - page_size * 2U;+    memcpy(&unprotected_size, base_ptr, sizeof unprotected_size);++    return cb(unprotected_ptr, unprotected_size);+}+#endif++int+sodium_mprotect_noaccess(void *ptr)+{+    return _sodium_mprotect(ptr, _mprotect_noaccess);+}++int+sodium_mprotect_readonly(void *ptr)+{+    return _sodium_mprotect(ptr, _mprotect_readonly);+}++int+sodium_mprotect_readwrite(void *ptr)+{+    return _sodium_mprotect(ptr, _mprotect_readwrite);+}++int+sodium_pad(size_t *padded_buflen_p, unsigned char *buf,+           size_t unpadded_buflen, size_t blocksize, size_t max_buflen)+{+    unsigned char          *tail;+    size_t                  i;+    size_t                  xpadlen;+    size_t                  xpadded_len;+    volatile unsigned char  mask;+    unsigned char           barrier_mask;++    if (blocksize <= 0U) {+        return -1;+    }+    xpadlen = blocksize - 1U;+    if ((blocksize & (blocksize - 1U)) == 0U) {+        xpadlen -= unpadded_buflen & (blocksize - 1U);+    } else {+        xpadlen -= unpadded_buflen % blocksize;+    }+    if ((size_t) SIZE_MAX - unpadded_buflen <= xpadlen) {+        sodium_misuse();+    }+    xpadded_len = unpadded_buflen + xpadlen;+    if (xpadded_len >= max_buflen) {+        return -1;+    }+    tail = &buf[xpadded_len];+    if (padded_buflen_p != NULL) {+        *padded_buflen_p = xpadded_len + 1U;+    }+    mask = 0U;+    for (i = 0; i < blocksize; i++) {+        barrier_mask = (unsigned char) (((i ^ xpadlen) - 1U)+           >> ((sizeof(size_t) - 1) * CHAR_BIT));+        *(tail - i) = ((*(tail - i)) & mask) | (0x80 & barrier_mask);+        mask |= barrier_mask;+    }+    return 0;+}++int+sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,+             size_t padded_buflen, size_t blocksize)+{+    const unsigned char *tail;+    unsigned char        acc = 0U;+    unsigned char        c;+    unsigned char        valid = 0U;+    volatile size_t      pad_len = 0U;+    size_t               i;+    size_t               is_barrier;++    if (padded_buflen < blocksize || blocksize <= 0U) {+        return -1;+    }+    tail = &buf[padded_buflen - 1U];++    for (i = 0U; i < blocksize; i++) {+        c = *(tail - i);+        is_barrier =+            (( (acc - 1U) & (pad_len - 1U) & ((c ^ 0x80) - 1U) ) >> 8) & 1U;+        acc |= c;+        pad_len |= i & (1U + ~is_barrier);+        valid |= (unsigned char) is_barrier;+    }+    *unpadded_buflen_p = padded_buflen - 1U - pad_len;++    return (int) (valid - 1U);+}
+ vendor/external/libsodium/sodium/version.c view
@@ -0,0 +1,30 @@++#include "version.h"++const char *+sodium_version_string(void)+{+    return SODIUM_VERSION_STRING;+}++int+sodium_library_version_major(void)+{+    return SODIUM_LIBRARY_VERSION_MAJOR;+}++int+sodium_library_version_minor(void)+{+    return SODIUM_LIBRARY_VERSION_MINOR;+}++int+sodium_library_minimal(void)+{+#ifdef SODIUM_LIBRARY_MINIMAL+    return 1;+#else+    return 0;+#endif+}
+ vendor/external/ripemd160/LICENSE view
@@ -0,0 +1,30 @@+This RIPEMD-160 implementation is in the public domain.++The full dedication and warranty notices are preserved verbatim at the top of+ripemd160.c. They are reproduced here for convenience:++  adapted by Pieter Wuille in 2012; all changes are in the public domain++  RIPEMD160.c : RIPEMD-160 implementation++  Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>++  ===================================================================+  The contents of this file are dedicated to the public domain.  To+  the extent that dedication to the public domain is not available,+  everyone is granted a worldwide, perpetual, royalty-free,+  non-exclusive license to exercise all rights associated with the+  contents of this file for any purpose whatsoever.+  No rights are reserved.++  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS+  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN+  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN+  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+  SOFTWARE.+  ===================================================================++  Country of origin: Canada
+ vendor/external/ripemd160/VERSION.txt view
@@ -0,0 +1,18 @@+Upstream:  ripemd160.c / ripemd160.h+Origin:    https://github.com/trezor/trezor-firmware (crypto/ripemd160.c, crypto/ripemd160.h)+Lineage:   Written in 2008 by Dwayne C. Litzenberger; public-domain changes by+           Pieter Wuille (2012), via https://github.com/sipa/Coin25519+Commit:    fb471a96f226737ec1c22bbf88078f5b36a572bc (trezor-firmware, path crypto/ripemd160.c)+License:   Public domain (see LICENSE in this directory and the notice at the+           top of ripemd160.c, both preserved verbatim).++Provides:  ripemd160_init / ripemd160_process / ripemd160_done and the+           one-shot ripemd160(), producing a 20-byte RIPEMD-160 digest.++Removed / changed to keep this self-contained (no algorithm or copyright text+altered):+  - Dropped #include "memzero.h" (a trezor-firmware internal header) and+    replaced it with a local "#define memzero(p, n) memset((p), 0, (n))" so+    the pair of files compiles with no external dependency beyond libc.+  - Nothing else from the upstream files was removed; the source is already a+    single self-contained translation unit plus its header.
+ vendor/external/ripemd160/ripemd160.c view
@@ -0,0 +1,361 @@+#include "ripemd160.h"+#include <assert.h>+#include <string.h>++/* cardano-c: upstream pulled memzero() from trezor-firmware/crypto/memzero.h.+ * Vendor it locally as a memset-based shim to keep this a self-contained pair+ * of files. No algorithm or copyright text was changed. */+#define memzero(p, n) memset((p), 0, (n))++// Downlaoded from https://github.com/sipa/Coin25519/blob/master/src/crypto/ripemd160.c++// adapted by Pieter Wuille in 2012; all changes are in the public domain++/*+ *+ *  RIPEMD160.c : RIPEMD-160 implementation+ *+ * Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>+ *+ * ===================================================================+ * The contents of this file are dedicated to the public domain.  To+ * the extent that dedication to the public domain is not available,+ * everyone is granted a worldwide, perpetual, royalty-free,+ * non-exclusive license to exercise all rights associated with the+ * contents of this file for any purpose whatsoever.+ * No rights are reserved.+ *+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+ * SOFTWARE.+ * ===================================================================+ *+ * Country of origin: Canada+ *+ * This implementation (written in C) is based on an implementation the author+ * wrote in Python.+ *+ * This implementation was written with reference to the RIPEMD-160+ * specification, which is available at:+ * http://homes.esat.kuleuven.be/~cosicart/pdf/AB-9601/+ *+ * It is also documented in the _Handbook of Applied Cryptography_, as+ * Algorithm 9.55.  It's on page 30 of the following PDF file:+ * http://www.cacr.math.uwaterloo.ca/hac/about/chap9.pdf+ *+ * The RIPEMD-160 specification doesn't really tell us how to do padding, but+ * since RIPEMD-160 is inspired by MD4, you can use the padding algorithm from+ * RFC 1320.+ *+ * According to http://www.users.zetnet.co.uk/hopwood/crypto/scan/md.html:+ *   "RIPEMD-160 is big-bit-endian, little-byte-endian, and left-justified."+ */++#include <stdint.h>++#include <string.h>++#define RIPEMD160_DIGEST_SIZE RIPEMD160_DIGEST_LENGTH++/* cyclic left-shift the 32-bit word n left by s bits */+#define ROL(s, n) (((n) << (s)) | ((n) >> (32-(s))))++/* Initial values for the chaining variables.+ * This is just 0123456789ABCDEFFEDCBA9876543210F0E1D2C3 in little-endian. */+static const uint32_t initial_h[5] = { 0x67452301u, 0xEFCDAB89u, 0x98BADCFEu, 0x10325476u, 0xC3D2E1F0u };++/* Ordering of message words.  Based on the permutations rho(i) and pi(i), defined as follows:+ *+ *  rho(i) := { 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8 }[i]  0 <= i <= 15+ *+ *  pi(i) := 9*i + 5 (mod 16)+ *+ *  Line  |  Round 1  |  Round 2  |  Round 3  |  Round 4  |  Round 5+ * -------+-----------+-----------+-----------+-----------+-----------+ *  left  |    id     |    rho    |   rho^2   |   rho^3   |   rho^4+ *  right |    pi     |   rho pi  |  rho^2 pi |  rho^3 pi |  rho^4 pi+ */++/* Left line */+static const uint8_t RL[5][16] = {+    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },   /* Round 1: id */+    { 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8 },   /* Round 2: rho */+    { 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12 },   /* Round 3: rho^2 */+    { 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2 },   /* Round 4: rho^3 */+    { 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 }    /* Round 5: rho^4 */+};++/* Right line */+static const uint8_t RR[5][16] = {+    { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12 },   /* Round 1: pi */+    { 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2 },   /* Round 2: rho pi */+    { 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13 },   /* Round 3: rho^2 pi */+    { 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14 },   /* Round 4: rho^3 pi */+    { 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 }    /* Round 5: rho^4 pi */+};++/*+ * Shifts - Since we don't actually re-order the message words according to+ * the permutations above (we could, but it would be slower), these tables+ * come with the permutations pre-applied.+ */++/* Shifts, left line */+static const uint8_t SL[5][16] = {+    { 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8 }, /* Round 1 */+    { 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12 }, /* Round 2 */+    { 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5 }, /* Round 3 */+    { 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12 }, /* Round 4 */+    { 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 }  /* Round 5 */+};++/* Shifts, right line */+static const uint8_t SR[5][16] = {+    { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6 }, /* Round 1 */+    { 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11 }, /* Round 2 */+    { 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5 }, /* Round 3 */+    { 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8 }, /* Round 4 */+    { 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 }  /* Round 5 */+};++/* Boolean functions */++#define F1(x, y, z) ((x) ^ (y) ^ (z))+#define F2(x, y, z) (((x) & (y)) | (~(x) & (z)))+#define F3(x, y, z) (((x) | ~(y)) ^ (z))+#define F4(x, y, z) (((x) & (z)) | ((y) & ~(z)))+#define F5(x, y, z) ((x) ^ ((y) | ~(z)))++/* Round constants, left line */+static const uint32_t KL[5] = {+    0x00000000u,    /* Round 1: 0 */+    0x5A827999u,    /* Round 2: floor(2**30 * sqrt(2)) */+    0x6ED9EBA1u,    /* Round 3: floor(2**30 * sqrt(3)) */+    0x8F1BBCDCu,    /* Round 4: floor(2**30 * sqrt(5)) */+    0xA953FD4Eu     /* Round 5: floor(2**30 * sqrt(7)) */+};++/* Round constants, right line */+static const uint32_t KR[5] = {+    0x50A28BE6u,    /* Round 1: floor(2**30 * cubert(2)) */+    0x5C4DD124u,    /* Round 2: floor(2**30 * cubert(3)) */+    0x6D703EF3u,    /* Round 3: floor(2**30 * cubert(5)) */+    0x7A6D76E9u,    /* Round 4: floor(2**30 * cubert(7)) */+    0x00000000u     /* Round 5: 0 */+};++void ripemd160_init(ripemd160_state *self)+{++    memcpy(self->h, initial_h, RIPEMD160_DIGEST_SIZE);+    memset(&self->buf, 0, sizeof(self->buf));+    self->length = 0;+    self->bufpos = 0;+}++#ifdef PCT_BIG_ENDIAN+static inline void byteswap32(uint32_t *v)+{+    union { uint32_t w; uint8_t b[4]; } x = {0}, y = {0};++    x.w = *v;+    y.b[0] = x.b[3];+    y.b[1] = x.b[2];+    y.b[2] = x.b[1];+    y.b[3] = x.b[0];+    *v = y.w;++    /* Wipe temporary variables */+    x.w = y.w = 0;+}++static inline void byteswap_digest(uint32_t *p)+{+    unsigned int i = 0;++    for (i = 0; i < 4; i++) {+        byteswap32(p++);+        byteswap32(p++);+        byteswap32(p++);+        byteswap32(p++);+    }+}+#endif++/* The RIPEMD160 compression function.  Operates on self->buf */+static void ripemd160_compress(ripemd160_state *self)+{+    uint8_t w = 0, round = 0;+    uint32_t T = 0;+    uint32_t AL = 0, BL = 0, CL = 0, DL = 0, EL = 0;    /* left line */+    uint32_t AR = 0, BR = 0, CR = 0, DR = 0, ER = 0;    /* right line */++    /* Sanity check */+    assert(self->bufpos == 64);++    /* Byte-swap the buffer if we're on a big-endian machine */+#ifdef PCT_BIG_ENDIAN+    byteswap_digest(self->buf.w);+#endif++    /* Load the left and right lines with the initial state */+    AL = AR = self->h[0];+    BL = BR = self->h[1];+    CL = CR = self->h[2];+    DL = DR = self->h[3];+    EL = ER = self->h[4];++    /* Round 1 */+    round = 0;+    for (w = 0; w < 16; w++) { /* left line */+        T = ROL(SL[round][w], AL + F1(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;+        AL = EL; EL = DL; DL = ROL(10, CL); CL = BL; BL = T;+    }+    for (w = 0; w < 16; w++) { /* right line */+        T = ROL(SR[round][w], AR + F5(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;+        AR = ER; ER = DR; DR = ROL(10, CR); CR = BR; BR = T;+    }++    /* Round 2 */+    round++;+    for (w = 0; w < 16; w++) { /* left line */+        T = ROL(SL[round][w], AL + F2(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;+        AL = EL; EL = DL; DL = ROL(10, CL); CL = BL; BL = T;+    }+    for (w = 0; w < 16; w++) { /* right line */+        T = ROL(SR[round][w], AR + F4(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;+        AR = ER; ER = DR; DR = ROL(10, CR); CR = BR; BR = T;+    }++    /* Round 3 */+    round++;+    for (w = 0; w < 16; w++) { /* left line */+        T = ROL(SL[round][w], AL + F3(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;+        AL = EL; EL = DL; DL = ROL(10, CL); CL = BL; BL = T;+    }+    for (w = 0; w < 16; w++) { /* right line */+        T = ROL(SR[round][w], AR + F3(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;+        AR = ER; ER = DR; DR = ROL(10, CR); CR = BR; BR = T;+    }++    /* Round 4 */+    round++;+    for (w = 0; w < 16; w++) { /* left line */+        T = ROL(SL[round][w], AL + F4(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;+        AL = EL; EL = DL; DL = ROL(10, CL); CL = BL; BL = T;+    }+    for (w = 0; w < 16; w++) { /* right line */+        T = ROL(SR[round][w], AR + F2(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;+        AR = ER; ER = DR; DR = ROL(10, CR); CR = BR; BR = T;+    }++    /* Round 5 */+    round++;+    for (w = 0; w < 16; w++) { /* left line */+        T = ROL(SL[round][w], AL + F5(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;+        AL = EL; EL = DL; DL = ROL(10, CL); CL = BL; BL = T;+    }+    for (w = 0; w < 16; w++) { /* right line */+        T = ROL(SR[round][w], AR + F1(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;+        AR = ER; ER = DR; DR = ROL(10, CR); CR = BR; BR = T;+    }++    /* Final mixing stage */+    T = self->h[1] + CL + DR;+    self->h[1] = self->h[2] + DL + ER;+    self->h[2] = self->h[3] + EL + AR;+    self->h[3] = self->h[4] + AL + BR;+    self->h[4] = self->h[0] + BL + CR;+    self->h[0] = T;++    /* Clear the buffer and wipe the temporary variables */+    memzero(&self->buf, sizeof(self->buf));+    memzero(&T, sizeof(T));+    memzero(&AL, sizeof(AL));+    memzero(&BL, sizeof(BL));+    memzero(&CL, sizeof(CL));+    memzero(&DL, sizeof(DL));+    memzero(&EL, sizeof(EL));+    memzero(&AR, sizeof(AR));+    memzero(&BR, sizeof(BR));+    memzero(&CR, sizeof(CR));+    memzero(&DR, sizeof(DR));+    memzero(&ER, sizeof(ER));+    self->bufpos = 0;+}++void ripemd160_process(ripemd160_state * self, const uint8_t *p, size_t length)+{+    unsigned long bytes_needed = 0;++    /* Some assertions */+    assert(p != NULL);++    /* We never leave a full buffer */+    assert(self->bufpos < 64);++    while (length > 0) {+        /* Figure out how many bytes we need to fill the internal buffer. */+        bytes_needed = 64 - self->bufpos;++        if ((unsigned long) length >= bytes_needed) {+            /* We have enough bytes, so copy them into the internal buffer and run+             * the compression function. */+            memcpy(&self->buf.b[self->bufpos], p, bytes_needed);+            self->bufpos += bytes_needed;+            self->length += bytes_needed << 3;    /* length is in bits */+            p += bytes_needed;+            ripemd160_compress(self);+            length -= bytes_needed;+            continue;+        }++        /* We do not have enough bytes to fill the internal buffer.+         * Copy what's there and return. */+        memcpy(&self->buf.b[self->bufpos], p, length);+        self->bufpos += length;+        self->length += length << 3;    /* length is in bits */+        return;+    }+}++void ripemd160_done(ripemd160_state * self, uint8_t out[RIPEMD160_DIGEST_LENGTH])+{+    /* Append the padding */+    self->buf.b[self->bufpos++] = 0x80;++    if (self->bufpos > 56) {+        self->bufpos = 64;+        ripemd160_compress(self);+    }++    /* Append the length */+    self->buf.w[14] = (uint32_t) (self->length & 0xFFFFffffu);+    self->buf.w[15] = (uint32_t) ((self->length >> 32) & 0xFFFFffffu);+#ifdef PCT_BIG_ENDIAN+    byteswap32(&self->buf.w[14]);+    byteswap32(&self->buf.w[15]);+#endif+    self->bufpos = 64;+    ripemd160_compress(self);++    /* Copy the final state into the output buffer */+#ifdef PCT_BIG_ENDIAN+    byteswap_digest(self->h);+#endif+    memcpy(out, &self->h, RIPEMD160_DIGEST_SIZE);+    memzero(self, sizeof(ripemd160_state));+}++void ripemd160(const uint8_t *in, size_t length, uint8_t out[RIPEMD160_DIGEST_LENGTH])+{+  ripemd160_state md = {0};+  ripemd160_init(&md);+  ripemd160_process(&md, in, length);+  ripemd160_done(&md, out);+}
+ vendor/external/ripemd160/ripemd160.h view
@@ -0,0 +1,24 @@+#ifndef __RIPEMD160_H__+#define __RIPEMD160_H__++#include <stdint.h>+#include <stddef.h>++#define RIPEMD160_BLOCK_LENGTH 64+#define RIPEMD160_DIGEST_LENGTH 20++typedef struct {+  uint64_t length;+  union {+    uint32_t w[16];+    uint8_t  b[64];+  } buf;+  uint32_t h[5];+  uint8_t bufpos;+} ripemd160_state;++void ripemd160_init(ripemd160_state * self);+void ripemd160_process(ripemd160_state * self, const uint8_t *in, size_t length);+void ripemd160_done(ripemd160_state * self, uint8_t out[RIPEMD160_DIGEST_LENGTH]);+void ripemd160(const uint8_t *in, size_t length, uint8_t out[RIPEMD160_DIGEST_LENGTH]);+#endif
+ vendor/external/secp256k1/COPYING view
@@ -0,0 +1,19 @@+Copyright (c) 2013 Pieter Wuille++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ vendor/external/secp256k1/VERSION.txt view
@@ -0,0 +1,65 @@+Upstream:  bitcoin-core/secp256k1+Origin:    https://github.com/bitcoin-core/secp256k1+Tag:       v0.6.0+Commit:    0cdc758a56360bf58a851fe91085a327ec97685a+License:   MIT (see COPYING in this directory)++Provides the secp256k1 ECDSA-verify and Schnorr (BIP340) verify primitives for+the Plutus builtins verifyEcdsaSecp256k1Signature and+verifySchnorrSecp256k1Signature. Only the verify path of the core library plus+the extrakeys and schnorrsig modules are compiled.++Build configuration (no autotools, no code generation):+  This release configures purely through preprocessor defines; it does not+  generate a libsecp256k1-config.h and does not need HAVE_CONFIG_H. The build+  defines are set on the isolated CMake OBJECT target (see lib/CMakeLists.txt):+    ENABLE_MODULE_EXTRAKEYS=1   - x-only public keys (schnorr dependency)+    ENABLE_MODULE_SCHNORRSIG=1  - BIP340 Schnorr signatures+    ECMULT_WINDOW_SIZE=8        - small ecmult window: the verify table is 8 KiB+                                  (vs 1 MiB at the upstream default of 15); secp+                                  verify is a rarely-used cold path, so the lean+                                  binary is worth the small verify slowdown+    SECP256K1_STATIC            - consume the API as a static library (no DLL+                                  import/export decoration on Windows)+  The recovery, ECDH, ellswift and musig modules are intentionally not defined+  and therefore not compiled. Wide multiplication, field and scalar backends are+  auto-selected by src/util.h with a portable C fallback; no assembly is forced.++Precomputed tables:+  src/precomputed_ecmult.c and src/precomputed_ecmult_gen.c are the generated+  tables that ship checked in with this release. They are compiled as-is, so no+  precompute/codegen step (precompute_ecmult.c / precompute_ecmult_gen.c) and no+  autotools run is required. Those two generator programs are not vendored.++Vendored files:+  COPYING                          - upstream MIT license, copied verbatim.+  include/secp256k1.h              - core public API.+  include/secp256k1_preallocated.h - included by secp256k1.c.+  include/secp256k1_extrakeys.h    - x-only pubkey public API.+  include/secp256k1_schnorrsig.h   - BIP340 public API.+  src/secp256k1.c                  - the single core translation unit; it pulls+                                     in the enabled module impls by ENABLE_MODULE_*.+  src/precomputed_ecmult.c         - checked-in ecmult table.+  src/precomputed_ecmult_gen.c     - checked-in ecmult-gen table.+  src/*.h                          - the internal headers secp256k1.c includes+                                     (field/group/scalar/ecmult/ecdsa/eckey/hash/+                                     modinv/int128/scratch/hsort/assumptions/+                                     checkmem/selftest/util and the precomputed+                                     table headers).+  src/modules/extrakeys/main_impl.h+  src/modules/schnorrsig/main_impl.h++Removed from the upstream tree to keep this lean (no copyright text altered):+  - Unused modules: src/modules/{ecdh,recovery,ellswift,musig} and their public+    headers include/secp256k1_{ecdh,recovery,ellswift,musig}.h.+  - Tests and benchmarks: src/tests.c, src/tests_exhaustive.c, src/ctime_tests.c,+    src/bench*.c, src/bench.h, the wycheproof test vectors and the per-module+    tests_impl.h / tests_exhaustive_impl.h / bench_impl.h.+  - Test-only internal headers: src/testrand*.h, src/testutil.h, and the+    exhaustive-test scalar backend src/scalar_low.h / src/scalar_low_impl.h+    (only included under EXHAUSTIVE_TEST_ORDER, which is never defined here).+  - The table generators src/precompute_ecmult.c and src/precompute_ecmult_gen.c+    (the checked-in tables above are used instead).+  - Build tooling: configure.ac, Makefile.am, autogen.sh, CMakeLists.txt,+    cmake/, src/CMakeLists.txt, the asm sources under src/asm, the examples/ and+    contrib/ trees, CI and documentation files.
+ vendor/external/secp256k1/include/secp256k1.h view
@@ -0,0 +1,899 @@+#ifndef SECP256K1_H+#define SECP256K1_H++#ifdef __cplusplus+extern "C" {+#endif++#include <stddef.h>++/** Unless explicitly stated all pointer arguments must not be NULL.+ *+ * The following rules specify the order of arguments in API calls:+ *+ * 1. Context pointers go first, followed by output arguments, combined+ *    output/input arguments, and finally input-only arguments.+ * 2. Array lengths always immediately follow the argument whose length+ *    they describe, even if this violates rule 1.+ * 3. Within the OUT/OUTIN/IN groups, pointers to data that is typically generated+ *    later go first. This means: signatures, public nonces, secret nonces,+ *    messages, public keys, secret keys, tweaks.+ * 4. Arguments that are not data pointers go last, from more complex to less+ *    complex: function pointers, algorithm names, messages, void pointers,+ *    counts, flags, booleans.+ * 5. Opaque data pointers follow the function pointer they are to be passed to.+ */++/** Opaque data structure that holds context information+ *+ *  The primary purpose of context objects is to store randomization data for+ *  enhanced protection against side-channel leakage. This protection is only+ *  effective if the context is randomized after its creation. See+ *  secp256k1_context_create for creation of contexts and+ *  secp256k1_context_randomize for randomization.+ *+ *  A secondary purpose of context objects is to store pointers to callback+ *  functions that the library will call when certain error states arise. See+ *  secp256k1_context_set_error_callback as well as+ *  secp256k1_context_set_illegal_callback for details. Future library versions+ *  may use context objects for additional purposes.+ *+ *  A constructed context can safely be used from multiple threads+ *  simultaneously, but API calls that take a non-const pointer to a context+ *  need exclusive access to it. In particular this is the case for+ *  secp256k1_context_destroy, secp256k1_context_preallocated_destroy,+ *  and secp256k1_context_randomize.+ *+ *  Regarding randomization, either do it once at creation time (in which case+ *  you do not need any locking for the other calls), or use a read-write lock.+ */+typedef struct secp256k1_context_struct secp256k1_context;++/** Opaque data structure that holds a parsed and valid public key.+ *+ *  The exact representation of data inside is implementation defined and not+ *  guaranteed to be portable between different platforms or versions. It is+ *  however guaranteed to be 64 bytes in size, and can be safely copied/moved.+ *  If you need to convert to a format suitable for storage or transmission,+ *  use secp256k1_ec_pubkey_serialize and secp256k1_ec_pubkey_parse. To+ *  compare keys, use secp256k1_ec_pubkey_cmp.+ */+typedef struct secp256k1_pubkey {+    unsigned char data[64];+} secp256k1_pubkey;++/** Opaque data structure that holds a parsed ECDSA signature.+ *+ *  The exact representation of data inside is implementation defined and not+ *  guaranteed to be portable between different platforms or versions. It is+ *  however guaranteed to be 64 bytes in size, and can be safely copied/moved.+ *  If you need to convert to a format suitable for storage, transmission, or+ *  comparison, use the secp256k1_ecdsa_signature_serialize_* and+ *  secp256k1_ecdsa_signature_parse_* functions.+ */+typedef struct secp256k1_ecdsa_signature {+    unsigned char data[64];+} secp256k1_ecdsa_signature;++/** A pointer to a function to deterministically generate a nonce.+ *+ * Returns: 1 if a nonce was successfully generated. 0 will cause signing to fail.+ * Out:     nonce32:   pointer to a 32-byte array to be filled by the function.+ * In:      msg32:     the 32-byte message hash being verified (will not be NULL)+ *          key32:     pointer to a 32-byte secret key (will not be NULL)+ *          algo16:    pointer to a 16-byte array describing the signature+ *                     algorithm (will be NULL for ECDSA for compatibility).+ *          data:      Arbitrary data pointer that is passed through.+ *          attempt:   how many iterations we have tried to find a nonce.+ *                     This will almost always be 0, but different attempt values+ *                     are required to result in a different nonce.+ *+ * Except for test cases, this function should compute some cryptographic hash of+ * the message, the algorithm, the key and the attempt.+ */+typedef int (*secp256k1_nonce_function)(+    unsigned char *nonce32,+    const unsigned char *msg32,+    const unsigned char *key32,+    const unsigned char *algo16,+    void *data,+    unsigned int attempt+);++# if !defined(SECP256K1_GNUC_PREREQ)+#  if defined(__GNUC__)&&defined(__GNUC_MINOR__)+#   define SECP256K1_GNUC_PREREQ(_maj,_min) \+ ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))+#  else+#   define SECP256K1_GNUC_PREREQ(_maj,_min) 0+#  endif+# endif++/*  When this header is used at build-time the SECP256K1_BUILD define needs to be set+ *  to correctly setup export attributes and nullness checks.  This is normally done+ *  by secp256k1.c but to guard against this header being included before secp256k1.c+ *  has had a chance to set the define (e.g. via test harnesses that just includes+ *  secp256k1.c) we set SECP256K1_NO_BUILD when this header is processed without the+ *  BUILD define so this condition can be caught.+ */+#ifndef SECP256K1_BUILD+# define SECP256K1_NO_BUILD+#endif++/* Symbol visibility. */+#if defined(_WIN32)+  /* GCC for Windows (e.g., MinGW) accepts the __declspec syntax+   * for MSVC compatibility. A __declspec declaration implies (but is not+   * exactly equivalent to) __attribute__ ((visibility("default"))), and so we+   * actually want __declspec even on GCC, see "Microsoft Windows Function+   * Attributes" in the GCC manual and the recommendations in+   * https://gcc.gnu.org/wiki/Visibility. */+# if defined(SECP256K1_BUILD)+#  if defined(DLL_EXPORT) || defined(SECP256K1_DLL_EXPORT)+    /* Building libsecp256k1 as a DLL.+     * 1. If using Libtool, it defines DLL_EXPORT automatically.+     * 2. In other cases, SECP256K1_DLL_EXPORT must be defined. */+#   define SECP256K1_API extern __declspec (dllexport)+#  else+    /* Building libsecp256k1 as a static library on Windows.+     * No declspec is needed, and so we would want the non-Windows-specific+     * logic below take care of this case. However, this may result in setting+     * __attribute__ ((visibility("default"))), which is supposed to be a noop+     * on Windows but may trigger warnings when compiling with -flto due to a+     * bug in GCC, see+     * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116478 . */+#   define SECP256K1_API extern+#  endif+  /* The user must define SECP256K1_STATIC when consuming libsecp256k1 as a static+   * library on Windows. */+# elif !defined(SECP256K1_STATIC)+   /* Consuming libsecp256k1 as a DLL. */+#  define SECP256K1_API extern __declspec (dllimport)+# endif+#endif+#ifndef SECP256K1_API+/* All cases not captured by the Windows-specific logic. */+# if defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD)+   /* Building libsecp256k1 using GCC or compatible. */+#  define SECP256K1_API extern __attribute__ ((visibility ("default")))+# else+   /* Fall back to standard C's extern. */+#  define SECP256K1_API extern+# endif+#endif++/* Warning attributes+ * NONNULL is not used if SECP256K1_BUILD is set to avoid the compiler optimizing out+ * some paranoid null checks. */+# if defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)+#  define SECP256K1_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))+# else+#  define SECP256K1_WARN_UNUSED_RESULT+# endif+# if !defined(SECP256K1_BUILD) && defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)+#  define SECP256K1_ARG_NONNULL(_x)  __attribute__ ((__nonnull__(_x)))+# else+#  define SECP256K1_ARG_NONNULL(_x)+# endif++/* Attribute for marking functions, types, and variables as deprecated */+#if !defined(SECP256K1_BUILD) && defined(__has_attribute)+# if __has_attribute(__deprecated__)+#  define SECP256K1_DEPRECATED(_msg) __attribute__ ((__deprecated__(_msg)))+# else+#  define SECP256K1_DEPRECATED(_msg)+# endif+#else+# define SECP256K1_DEPRECATED(_msg)+#endif++/* All flags' lower 8 bits indicate what they're for. Do not use directly. */+#define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1)+#define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0)+#define SECP256K1_FLAGS_TYPE_COMPRESSION (1 << 1)+/* The higher bits contain the actual data. Do not use directly. */+#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY (1 << 8)+#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN (1 << 9)+#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY (1 << 10)+#define SECP256K1_FLAGS_BIT_COMPRESSION (1 << 8)++/** Context flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size, and+ *  secp256k1_context_preallocated_create. */+#define SECP256K1_CONTEXT_NONE (SECP256K1_FLAGS_TYPE_CONTEXT)++/** Deprecated context flags. These flags are treated equivalent to SECP256K1_CONTEXT_NONE. */+#define SECP256K1_CONTEXT_VERIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_VERIFY)+#define SECP256K1_CONTEXT_SIGN (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_SIGN)++/* Testing flag. Do not use. */+#define SECP256K1_CONTEXT_DECLASSIFY (SECP256K1_FLAGS_TYPE_CONTEXT | SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY)++/** Flag to pass to secp256k1_ec_pubkey_serialize. */+#define SECP256K1_EC_COMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION | SECP256K1_FLAGS_BIT_COMPRESSION)+#define SECP256K1_EC_UNCOMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION)++/** Prefix byte used to tag various encoded curvepoints for specific purposes */+#define SECP256K1_TAG_PUBKEY_EVEN 0x02+#define SECP256K1_TAG_PUBKEY_ODD 0x03+#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED 0x04+#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 0x06+#define SECP256K1_TAG_PUBKEY_HYBRID_ODD 0x07++/** A built-in constant secp256k1 context object with static storage duration, to be+ *  used in conjunction with secp256k1_selftest.+ *+ *  This context object offers *only limited functionality* , i.e., it cannot be used+ *  for API functions that perform computations involving secret keys, e.g., signing+ *  and public key generation. If this restriction applies to a specific API function,+ *  it is mentioned in its documentation. See secp256k1_context_create if you need a+ *  full context object that supports all functionality offered by the library.+ *+ *  It is highly recommended to call secp256k1_selftest before using this context.+ */+SECP256K1_API const secp256k1_context *secp256k1_context_static;++/** Deprecated alias for secp256k1_context_static. */+SECP256K1_API const secp256k1_context *secp256k1_context_no_precomp+SECP256K1_DEPRECATED("Use secp256k1_context_static instead");++/** Perform basic self tests (to be used in conjunction with secp256k1_context_static)+ *+ *  This function performs self tests that detect some serious usage errors and+ *  similar conditions, e.g., when the library is compiled for the wrong endianness.+ *  This is a last resort measure to be used in production. The performed tests are+ *  very rudimentary and are not intended as a replacement for running the test+ *  binaries.+ *+ *  It is highly recommended to call this before using secp256k1_context_static.+ *  It is not necessary to call this function before using a context created with+ *  secp256k1_context_create (or secp256k1_context_preallocated_create), which will+ *  take care of performing the self tests.+ *+ *  If the tests fail, this function will call the default error handler to abort the+ *  program (see secp256k1_context_set_error_callback).+ */+SECP256K1_API void secp256k1_selftest(void);+++/** Create a secp256k1 context object (in dynamically allocated memory).+ *+ *  This function uses malloc to allocate memory. It is guaranteed that malloc is+ *  called at most once for every call of this function. If you need to avoid dynamic+ *  memory allocation entirely, see secp256k1_context_static and the functions in+ *  secp256k1_preallocated.h.+ *+ *  Returns: pointer to a newly created context object.+ *  In:      flags: Always set to SECP256K1_CONTEXT_NONE (see below).+ *+ *  The only valid non-deprecated flag in recent library versions is+ *  SECP256K1_CONTEXT_NONE, which will create a context sufficient for all functionality+ *  offered by the library. All other (deprecated) flags will be treated as equivalent+ *  to the SECP256K1_CONTEXT_NONE flag. Though the flags parameter primarily exists for+ *  historical reasons, future versions of the library may introduce new flags.+ *+ *  If the context is intended to be used for API functions that perform computations+ *  involving secret keys, e.g., signing and public key generation, then it is highly+ *  recommended to call secp256k1_context_randomize on the context before calling+ *  those API functions. This will provide enhanced protection against side-channel+ *  leakage, see secp256k1_context_randomize for details.+ *+ *  Do not create a new context object for each operation, as construction and+ *  randomization can take non-negligible time.+ */+SECP256K1_API secp256k1_context *secp256k1_context_create(+    unsigned int flags+) SECP256K1_WARN_UNUSED_RESULT;++/** Copy a secp256k1 context object (into dynamically allocated memory).+ *+ *  This function uses malloc to allocate memory. It is guaranteed that malloc is+ *  called at most once for every call of this function. If you need to avoid dynamic+ *  memory allocation entirely, see the functions in secp256k1_preallocated.h.+ *+ *  Cloning secp256k1_context_static is not possible, and should not be emulated by+ *  the caller (e.g., using memcpy). Create a new context instead.+ *+ *  Returns: pointer to a newly created context object.+ *  Args:    ctx: pointer to a context to copy (not secp256k1_context_static).+ */+SECP256K1_API secp256k1_context *secp256k1_context_clone(+    const secp256k1_context *ctx+) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;++/** Destroy a secp256k1 context object (created in dynamically allocated memory).+ *+ *  The context pointer may not be used afterwards.+ *+ *  The context to destroy must have been created using secp256k1_context_create+ *  or secp256k1_context_clone. If the context has instead been created using+ *  secp256k1_context_preallocated_create or secp256k1_context_preallocated_clone, the+ *  behaviour is undefined. In that case, secp256k1_context_preallocated_destroy must+ *  be used instead.+ *+ *  Args:   ctx: pointer to a context to destroy, constructed using+ *               secp256k1_context_create or secp256k1_context_clone+ *               (i.e., not secp256k1_context_static).+ */+SECP256K1_API void secp256k1_context_destroy(+    secp256k1_context *ctx+) SECP256K1_ARG_NONNULL(1);++/** Set a callback function to be called when an illegal argument is passed to+ *  an API call. It will only trigger for violations that are mentioned+ *  explicitly in the header.+ *+ *  The philosophy is that these shouldn't be dealt with through a+ *  specific return value, as calling code should not have branches to deal with+ *  the case that this code itself is broken.+ *+ *  On the other hand, during debug stage, one would want to be informed about+ *  such mistakes, and the default (crashing) may be inadvisable.+ *  When this callback is triggered, the API function called is guaranteed not+ *  to cause a crash, though its return value and output arguments are+ *  undefined.+ *+ *  When this function has not been called (or called with fn==NULL), then the+ *  default handler will be used. The library provides a default handler which+ *  writes the message to stderr and calls abort. This default handler can be+ *  replaced at link time if the preprocessor macro+ *  USE_EXTERNAL_DEFAULT_CALLBACKS is defined, which is the case if the build+ *  has been configured with --enable-external-default-callbacks. Then the+ *  following two symbols must be provided to link against:+ *   - void secp256k1_default_illegal_callback_fn(const char *message, void *data);+ *   - void secp256k1_default_error_callback_fn(const char *message, void *data);+ *  The library can call these default handlers even before a proper callback data+ *  pointer could have been set using secp256k1_context_set_illegal_callback or+ *  secp256k1_context_set_error_callback, e.g., when the creation of a context+ *  fails. In this case, the corresponding default handler will be called with+ *  the data pointer argument set to NULL.+ *+ *  Args: ctx:  pointer to a context object.+ *  In:   fun:  pointer to a function to call when an illegal argument is+ *              passed to the API, taking a message and an opaque pointer.+ *              (NULL restores the default handler.)+ *        data: the opaque pointer to pass to fun above, must be NULL for the default handler.+ *+ *  See also secp256k1_context_set_error_callback.+ */+SECP256K1_API void secp256k1_context_set_illegal_callback(+    secp256k1_context *ctx,+    void (*fun)(const char *message, void *data),+    const void *data+) SECP256K1_ARG_NONNULL(1);++/** Set a callback function to be called when an internal consistency check+ *  fails.+ *+ *  The default callback writes an error message to stderr and calls abort+ *  to abort the program.+ *+ *  This can only trigger in case of a hardware failure, miscompilation,+ *  memory corruption, serious bug in the library, or other error would can+ *  otherwise result in undefined behaviour. It will not trigger due to mere+ *  incorrect usage of the API (see secp256k1_context_set_illegal_callback+ *  for that). After this callback returns, anything may happen, including+ *  crashing.+ *+ *  Args: ctx:  pointer to a context object.+ *  In:   fun:  pointer to a function to call when an internal error occurs,+ *              taking a message and an opaque pointer (NULL restores the+ *              default handler, see secp256k1_context_set_illegal_callback+ *              for details).+ *        data: the opaque pointer to pass to fun above, must be NULL for the default handler.+ *+ *  See also secp256k1_context_set_illegal_callback.+ */+SECP256K1_API void secp256k1_context_set_error_callback(+    secp256k1_context *ctx,+    void (*fun)(const char *message, void *data),+    const void *data+) SECP256K1_ARG_NONNULL(1);++/** Parse a variable-length public key into the pubkey object.+ *+ *  Returns: 1 if the public key was fully valid.+ *           0 if the public key could not be parsed or is invalid.+ *  Args: ctx:      pointer to a context object.+ *  Out:  pubkey:   pointer to a pubkey object. If 1 is returned, it is set to a+ *                  parsed version of input. If not, its value is undefined.+ *  In:   input:    pointer to a serialized public key+ *        inputlen: length of the array pointed to by input+ *+ *  This function supports parsing compressed (33 bytes, header byte 0x02 or+ *  0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header+ *  byte 0x06 or 0x07) format public keys.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(+    const secp256k1_context *ctx,+    secp256k1_pubkey *pubkey,+    const unsigned char *input,+    size_t inputlen+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Serialize a pubkey object into a serialized byte sequence.+ *+ *  Returns: 1 always.+ *  Args:   ctx:        pointer to a context object.+ *  Out:    output:     pointer to a 65-byte (if compressed==0) or 33-byte (if+ *                      compressed==1) byte array to place the serialized key+ *                      in.+ *  In/Out: outputlen:  pointer to an integer which is initially set to the+ *                      size of output, and is overwritten with the written+ *                      size.+ *  In:     pubkey:     pointer to a secp256k1_pubkey containing an+ *                      initialized public key.+ *          flags:      SECP256K1_EC_COMPRESSED if serialization should be in+ *                      compressed format, otherwise SECP256K1_EC_UNCOMPRESSED.+ */+SECP256K1_API int secp256k1_ec_pubkey_serialize(+    const secp256k1_context *ctx,+    unsigned char *output,+    size_t *outputlen,+    const secp256k1_pubkey *pubkey,+    unsigned int flags+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);++/** Compare two public keys using lexicographic (of compressed serialization) order+ *+ *  Returns: <0 if the first public key is less than the second+ *           >0 if the first public key is greater than the second+ *           0 if the two public keys are equal+ *  Args: ctx:      pointer to a context object+ *  In:   pubkey1:  first public key to compare+ *        pubkey2:  second public key to compare+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_cmp(+    const secp256k1_context *ctx,+    const secp256k1_pubkey *pubkey1,+    const secp256k1_pubkey *pubkey2+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Sort public keys using lexicographic (of compressed serialization) order+ *+ *  Returns: 0 if the arguments are invalid. 1 otherwise.+ *+ *  Args:     ctx: pointer to a context object+ *  In:   pubkeys: array of pointers to pubkeys to sort+ *      n_pubkeys: number of elements in the pubkeys array+ */+SECP256K1_API int secp256k1_ec_pubkey_sort(+    const secp256k1_context *ctx,+    const secp256k1_pubkey **pubkeys,+    size_t n_pubkeys+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);++/** Parse an ECDSA signature in compact (64 bytes) format.+ *+ *  Returns: 1 when the signature could be parsed, 0 otherwise.+ *  Args: ctx:      pointer to a context object+ *  Out:  sig:      pointer to a signature object+ *  In:   input64:  pointer to the 64-byte array to parse+ *+ *  The signature must consist of a 32-byte big endian R value, followed by a+ *  32-byte big endian S value. If R or S fall outside of [0..order-1], the+ *  encoding is invalid. R and S with value 0 are allowed in the encoding.+ *+ *  After the call, sig will always be initialized. If parsing failed or R or+ *  S are zero, the resulting sig value is guaranteed to fail verification for+ *  any message and public key.+ */+SECP256K1_API int secp256k1_ecdsa_signature_parse_compact(+    const secp256k1_context *ctx,+    secp256k1_ecdsa_signature *sig,+    const unsigned char *input64+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Parse a DER ECDSA signature.+ *+ *  Returns: 1 when the signature could be parsed, 0 otherwise.+ *  Args: ctx:      pointer to a context object+ *  Out:  sig:      pointer to a signature object+ *  In:   input:    pointer to the signature to be parsed+ *        inputlen: the length of the array pointed to be input+ *+ *  This function will accept any valid DER encoded signature, even if the+ *  encoded numbers are out of range.+ *+ *  After the call, sig will always be initialized. If parsing failed or the+ *  encoded numbers are out of range, signature verification with it is+ *  guaranteed to fail for every message and public key.+ */+SECP256K1_API int secp256k1_ecdsa_signature_parse_der(+    const secp256k1_context *ctx,+    secp256k1_ecdsa_signature *sig,+    const unsigned char *input,+    size_t inputlen+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Serialize an ECDSA signature in DER format.+ *+ *  Returns: 1 if enough space was available to serialize, 0 otherwise+ *  Args:   ctx:       pointer to a context object+ *  Out:    output:    pointer to an array to store the DER serialization+ *  In/Out: outputlen: pointer to a length integer. Initially, this integer+ *                     should be set to the length of output. After the call+ *                     it will be set to the length of the serialization (even+ *                     if 0 was returned).+ *  In:     sig:       pointer to an initialized signature object+ */+SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(+    const secp256k1_context *ctx,+    unsigned char *output,+    size_t *outputlen,+    const secp256k1_ecdsa_signature *sig+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);++/** Serialize an ECDSA signature in compact (64 byte) format.+ *+ *  Returns: 1+ *  Args:   ctx:       pointer to a context object+ *  Out:    output64:  pointer to a 64-byte array to store the compact serialization+ *  In:     sig:       pointer to an initialized signature object+ *+ *  See secp256k1_ecdsa_signature_parse_compact for details about the encoding.+ */+SECP256K1_API int secp256k1_ecdsa_signature_serialize_compact(+    const secp256k1_context *ctx,+    unsigned char *output64,+    const secp256k1_ecdsa_signature *sig+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Verify an ECDSA signature.+ *+ *  Returns: 1: correct signature+ *           0: incorrect or unparseable signature+ *  Args:    ctx:       pointer to a context object+ *  In:      sig:       the signature being verified.+ *           msghash32: the 32-byte message hash being verified.+ *                      The verifier must make sure to apply a cryptographic+ *                      hash function to the message by itself and not accept an+ *                      msghash32 value directly. Otherwise, it would be easy to+ *                      create a "valid" signature without knowledge of the+ *                      secret key. See also+ *                      https://bitcoin.stackexchange.com/a/81116/35586 for more+ *                      background on this topic.+ *           pubkey:    pointer to an initialized public key to verify with.+ *+ * To avoid accepting malleable signatures, only ECDSA signatures in lower-S+ * form are accepted.+ *+ * If you need to accept ECDSA signatures from sources that do not obey this+ * rule, apply secp256k1_ecdsa_signature_normalize to the signature prior to+ * verification, but be aware that doing so results in malleable signatures.+ *+ * For details, see the comments for that function.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(+    const secp256k1_context *ctx,+    const secp256k1_ecdsa_signature *sig,+    const unsigned char *msghash32,+    const secp256k1_pubkey *pubkey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);++/** Convert a signature to a normalized lower-S form.+ *+ *  Returns: 1 if sigin was not normalized, 0 if it already was.+ *  Args: ctx:    pointer to a context object+ *  Out:  sigout: pointer to a signature to fill with the normalized form,+ *                or copy if the input was already normalized. (can be NULL if+ *                you're only interested in whether the input was already+ *                normalized).+ *  In:   sigin:  pointer to a signature to check/normalize (can be identical to sigout)+ *+ *  With ECDSA a third-party can forge a second distinct signature of the same+ *  message, given a single initial signature, but without knowing the key. This+ *  is done by negating the S value modulo the order of the curve, 'flipping'+ *  the sign of the random point R which is not included in the signature.+ *+ *  Forgery of the same message isn't universally problematic, but in systems+ *  where message malleability or uniqueness of signatures is important this can+ *  cause issues. This forgery can be blocked by all verifiers forcing signers+ *  to use a normalized form.+ *+ *  The lower-S form reduces the size of signatures slightly on average when+ *  variable length encodings (such as DER) are used and is cheap to verify,+ *  making it a good choice. Security of always using lower-S is assured because+ *  anyone can trivially modify a signature after the fact to enforce this+ *  property anyway.+ *+ *  The lower S value is always between 0x1 and+ *  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,+ *  inclusive.+ *+ *  No other forms of ECDSA malleability are known and none seem likely, but+ *  there is no formal proof that ECDSA, even with this additional restriction,+ *  is free of other malleability. Commonly used serialization schemes will also+ *  accept various non-unique encodings, so care should be taken when this+ *  property is required for an application.+ *+ *  The secp256k1_ecdsa_sign function will by default create signatures in the+ *  lower-S form, and secp256k1_ecdsa_verify will not accept others. In case+ *  signatures come from a system that cannot enforce this property,+ *  secp256k1_ecdsa_signature_normalize must be called before verification.+ */+SECP256K1_API int secp256k1_ecdsa_signature_normalize(+    const secp256k1_context *ctx,+    secp256k1_ecdsa_signature *sigout,+    const secp256k1_ecdsa_signature *sigin+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3);++/** An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.+ * If a data pointer is passed, it is assumed to be a pointer to 32 bytes of+ * extra entropy.+ */+SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_rfc6979;++/** A default safe nonce generation function (currently equal to secp256k1_nonce_function_rfc6979). */+SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_default;++/** Create an ECDSA signature.+ *+ *  Returns: 1: signature created+ *           0: the nonce generation function failed, or the secret key was invalid.+ *  Args:    ctx:       pointer to a context object (not secp256k1_context_static).+ *  Out:     sig:       pointer to an array where the signature will be placed.+ *  In:      msghash32: the 32-byte message hash being signed.+ *           seckey:    pointer to a 32-byte secret key.+ *           noncefp:   pointer to a nonce generation function. If NULL,+ *                      secp256k1_nonce_function_default is used.+ *           ndata:     pointer to arbitrary data used by the nonce generation function+ *                      (can be NULL). If it is non-NULL and+ *                      secp256k1_nonce_function_default is used, then ndata must be a+ *                      pointer to 32-bytes of additional data.+ *+ * The created signature is always in lower-S form. See+ * secp256k1_ecdsa_signature_normalize for more details.+ */+SECP256K1_API int secp256k1_ecdsa_sign(+    const secp256k1_context *ctx,+    secp256k1_ecdsa_signature *sig,+    const unsigned char *msghash32,+    const unsigned char *seckey,+    secp256k1_nonce_function noncefp,+    const void *ndata+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);++/** Verify an elliptic curve secret key.+ *+ *  A secret key is valid if it is not 0 and less than the secp256k1 curve order+ *  when interpreted as an integer (most significant byte first). The+ *  probability of choosing a 32-byte string uniformly at random which is an+ *  invalid secret key is negligible. However, if it does happen it should+ *  be assumed that the randomness source is severely broken and there should+ *  be no retry.+ *+ *  Returns: 1: secret key is valid+ *           0: secret key is invalid+ *  Args:    ctx: pointer to a context object.+ *  In:      seckey: pointer to a 32-byte secret key.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(+    const secp256k1_context *ctx,+    const unsigned char *seckey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);++/** Compute the public key for a secret key.+ *+ *  Returns: 1: secret was valid, public key stores.+ *           0: secret was invalid, try again.+ *  Args:    ctx:    pointer to a context object (not secp256k1_context_static).+ *  Out:     pubkey: pointer to the created public key.+ *  In:      seckey: pointer to a 32-byte secret key.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(+    const secp256k1_context *ctx,+    secp256k1_pubkey *pubkey,+    const unsigned char *seckey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Negates a secret key in place.+ *+ *  Returns: 0 if the given secret key is invalid according to+ *           secp256k1_ec_seckey_verify. 1 otherwise+ *  Args:   ctx:    pointer to a context object+ *  In/Out: seckey: pointer to the 32-byte secret key to be negated. If the+ *                  secret key is invalid according to+ *                  secp256k1_ec_seckey_verify, this function returns 0 and+ *                  seckey will be set to some unspecified value.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_negate(+    const secp256k1_context *ctx,+    unsigned char *seckey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);++/** Same as secp256k1_ec_seckey_negate, but DEPRECATED. Will be removed in+ *  future versions. */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_negate(+    const secp256k1_context *ctx,+    unsigned char *seckey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)+  SECP256K1_DEPRECATED("Use secp256k1_ec_seckey_negate instead");++/** Negates a public key in place.+ *+ *  Returns: 1 always+ *  Args:   ctx:        pointer to a context object+ *  In/Out: pubkey:     pointer to the public key to be negated.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_negate(+    const secp256k1_context *ctx,+    secp256k1_pubkey *pubkey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);++/** Tweak a secret key by adding tweak to it.+ *+ *  Returns: 0 if the arguments are invalid or the resulting secret key would be+ *           invalid (only when the tweak is the negation of the secret key). 1+ *           otherwise.+ *  Args:    ctx:   pointer to a context object.+ *  In/Out: seckey: pointer to a 32-byte secret key. If the secret key is+ *                  invalid according to secp256k1_ec_seckey_verify, this+ *                  function returns 0. seckey will be set to some unspecified+ *                  value if this function returns 0.+ *  In:    tweak32: pointer to a 32-byte tweak, which must be valid according to+ *                  secp256k1_ec_seckey_verify or 32 zero bytes. For uniformly+ *                  random 32-byte tweaks, the chance of being invalid is+ *                  negligible (around 1 in 2^128).+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_add(+    const secp256k1_context *ctx,+    unsigned char *seckey,+    const unsigned char *tweak32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Same as secp256k1_ec_seckey_tweak_add, but DEPRECATED. Will be removed in+ *  future versions. */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(+    const secp256k1_context *ctx,+    unsigned char *seckey,+    const unsigned char *tweak32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)+  SECP256K1_DEPRECATED("Use secp256k1_ec_seckey_tweak_add instead");++/** Tweak a public key by adding tweak times the generator to it.+ *+ *  Returns: 0 if the arguments are invalid or the resulting public key would be+ *           invalid (only when the tweak is the negation of the corresponding+ *           secret key). 1 otherwise.+ *  Args:    ctx:   pointer to a context object.+ *  In/Out: pubkey: pointer to a public key object. pubkey will be set to an+ *                  invalid value if this function returns 0.+ *  In:    tweak32: pointer to a 32-byte tweak, which must be valid according to+ *                  secp256k1_ec_seckey_verify or 32 zero bytes. For uniformly+ *                  random 32-byte tweaks, the chance of being invalid is+ *                  negligible (around 1 in 2^128).+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(+    const secp256k1_context *ctx,+    secp256k1_pubkey *pubkey,+    const unsigned char *tweak32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Tweak a secret key by multiplying it by a tweak.+ *+ *  Returns: 0 if the arguments are invalid. 1 otherwise.+ *  Args:   ctx:    pointer to a context object.+ *  In/Out: seckey: pointer to a 32-byte secret key. If the secret key is+ *                  invalid according to secp256k1_ec_seckey_verify, this+ *                  function returns 0. seckey will be set to some unspecified+ *                  value if this function returns 0.+ *  In:    tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to+ *                  secp256k1_ec_seckey_verify, this function returns 0. For+ *                  uniformly random 32-byte arrays the chance of being invalid+ *                  is negligible (around 1 in 2^128).+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_mul(+    const secp256k1_context *ctx,+    unsigned char *seckey,+    const unsigned char *tweak32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Same as secp256k1_ec_seckey_tweak_mul, but DEPRECATED. Will be removed in+ *  future versions. */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(+    const secp256k1_context *ctx,+    unsigned char *seckey,+    const unsigned char *tweak32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)+  SECP256K1_DEPRECATED("Use secp256k1_ec_seckey_tweak_mul instead");++/** Tweak a public key by multiplying it by a tweak value.+ *+ *  Returns: 0 if the arguments are invalid. 1 otherwise.+ *  Args:    ctx:   pointer to a context object.+ *  In/Out: pubkey: pointer to a public key object. pubkey will be set to an+ *                  invalid value if this function returns 0.+ *  In:    tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to+ *                  secp256k1_ec_seckey_verify, this function returns 0. For+ *                  uniformly random 32-byte arrays the chance of being invalid+ *                  is negligible (around 1 in 2^128).+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(+    const secp256k1_context *ctx,+    secp256k1_pubkey *pubkey,+    const unsigned char *tweak32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Randomizes the context to provide enhanced protection against side-channel leakage.+ *+ *  Returns: 1: randomization successful+ *           0: error+ *  Args:    ctx:       pointer to a context object (not secp256k1_context_static).+ *  In:      seed32:    pointer to a 32-byte random seed (NULL resets to initial state).+ *+ * While secp256k1 code is written and tested to be constant-time no matter what+ * secret values are, it is possible that a compiler may output code which is not,+ * and also that the CPU may not emit the same radio frequencies or draw the same+ * amount of power for all values. Randomization of the context shields against+ * side-channel observations which aim to exploit secret-dependent behaviour in+ * certain computations which involve secret keys.+ *+ * It is highly recommended to call this function on contexts returned from+ * secp256k1_context_create or secp256k1_context_clone (or from the corresponding+ * functions in secp256k1_preallocated.h) before using these contexts to call API+ * functions that perform computations involving secret keys, e.g., signing and+ * public key generation. It is possible to call this function more than once on+ * the same context, and doing so before every few computations involving secret+ * keys is recommended as a defense-in-depth measure. Randomization of the static+ * context secp256k1_context_static is not supported.+ *+ * Currently, the random seed is mainly used for blinding multiplications of a+ * secret scalar with the elliptic curve base point. Multiplications of this+ * kind are performed by exactly those API functions which are documented to+ * require a context that is not secp256k1_context_static. As a rule of thumb,+ * these are all functions which take a secret key (or a keypair) as an input.+ * A notable exception to that rule is the ECDH module, which relies on a different+ * kind of elliptic curve point multiplication and thus does not benefit from+ * enhanced protection against side-channel leakage currently.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(+    secp256k1_context *ctx,+    const unsigned char *seed32+) SECP256K1_ARG_NONNULL(1);++/** Add a number of public keys together.+ *+ *  Returns: 1: the sum of the public keys is valid.+ *           0: the sum of the public keys is not valid.+ *  Args:   ctx:        pointer to a context object.+ *  Out:    out:        pointer to a public key object for placing the resulting public key.+ *  In:     ins:        pointer to array of pointers to public keys.+ *          n:          the number of public keys to add together (must be at least 1).+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine(+    const secp256k1_context *ctx,+    secp256k1_pubkey *out,+    const secp256k1_pubkey * const *ins,+    size_t n+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Compute a tagged hash as defined in BIP-340.+ *+ *  This is useful for creating a message hash and achieving domain separation+ *  through an application-specific tag. This function returns+ *  SHA256(SHA256(tag)||SHA256(tag)||msg). Therefore, tagged hash+ *  implementations optimized for a specific tag can precompute the SHA256 state+ *  after hashing the tag hashes.+ *+ *  Returns: 1 always.+ *  Args:    ctx: pointer to a context object+ *  Out:  hash32: pointer to a 32-byte array to store the resulting hash+ *  In:      tag: pointer to an array containing the tag+ *        taglen: length of the tag array+ *           msg: pointer to an array containing the message+ *        msglen: length of the message array+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_tagged_sha256(+    const secp256k1_context *ctx,+    unsigned char *hash32,+    const unsigned char *tag,+    size_t taglen,+    const unsigned char *msg,+    size_t msglen+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5);++#ifdef __cplusplus+}+#endif++#endif /* SECP256K1_H */
+ vendor/external/secp256k1/include/secp256k1_extrakeys.h view
@@ -0,0 +1,250 @@+#ifndef SECP256K1_EXTRAKEYS_H+#define SECP256K1_EXTRAKEYS_H++#include "secp256k1.h"++#ifdef __cplusplus+extern "C" {+#endif++/** Opaque data structure that holds a parsed and valid "x-only" public key.+ *  An x-only pubkey encodes a point whose Y coordinate is even. It is+ *  serialized using only its X coordinate (32 bytes). See BIP-340 for more+ *  information about x-only pubkeys.+ *+ *  The exact representation of data inside is implementation defined and not+ *  guaranteed to be portable between different platforms or versions. It is+ *  however guaranteed to be 64 bytes in size, and can be safely copied/moved.+ *  If you need to convert to a format suitable for storage, transmission, use+ *  use secp256k1_xonly_pubkey_serialize and secp256k1_xonly_pubkey_parse. To+ *  compare keys, use secp256k1_xonly_pubkey_cmp.+ */+typedef struct secp256k1_xonly_pubkey {+    unsigned char data[64];+} secp256k1_xonly_pubkey;++/** Opaque data structure that holds a keypair consisting of a secret and a+ *  public key.+ *+ *  The exact representation of data inside is implementation defined and not+ *  guaranteed to be portable between different platforms or versions. It is+ *  however guaranteed to be 96 bytes in size, and can be safely copied/moved.+ */+typedef struct secp256k1_keypair {+    unsigned char data[96];+} secp256k1_keypair;++/** Parse a 32-byte sequence into a xonly_pubkey object.+ *+ *  Returns: 1 if the public key was fully valid.+ *           0 if the public key could not be parsed or is invalid.+ *+ *  Args:   ctx: pointer to a context object.+ *  Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to a+ *               parsed version of input. If not, it's set to an invalid value.+ *  In: input32: pointer to a serialized xonly_pubkey.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_parse(+    const secp256k1_context *ctx,+    secp256k1_xonly_pubkey *pubkey,+    const unsigned char *input32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Serialize an xonly_pubkey object into a 32-byte sequence.+ *+ *  Returns: 1 always.+ *+ *  Args:     ctx: pointer to a context object.+ *  Out: output32: pointer to a 32-byte array to place the serialized key in.+ *  In:    pubkey: pointer to a secp256k1_xonly_pubkey containing an initialized public key.+ */+SECP256K1_API int secp256k1_xonly_pubkey_serialize(+    const secp256k1_context *ctx,+    unsigned char *output32,+    const secp256k1_xonly_pubkey *pubkey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Compare two x-only public keys using lexicographic order+ *+ *  Returns: <0 if the first public key is less than the second+ *           >0 if the first public key is greater than the second+ *           0 if the two public keys are equal+ *  Args: ctx:      pointer to a context object.+ *  In:   pubkey1:  first public key to compare+ *        pubkey2:  second public key to compare+ */+SECP256K1_API int secp256k1_xonly_pubkey_cmp(+    const secp256k1_context *ctx,+    const secp256k1_xonly_pubkey *pk1,+    const secp256k1_xonly_pubkey *pk2+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Converts a secp256k1_pubkey into a secp256k1_xonly_pubkey.+ *+ *  Returns: 1 always.+ *+ *  Args:         ctx: pointer to a context object.+ *  Out: xonly_pubkey: pointer to an x-only public key object for placing the converted public key.+ *          pk_parity: Ignored if NULL. Otherwise, pointer to an integer that+ *                     will be set to 1 if the point encoded by xonly_pubkey is+ *                     the negation of the pubkey and set to 0 otherwise.+ *  In:        pubkey: pointer to a public key that is converted.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_from_pubkey(+    const secp256k1_context *ctx,+    secp256k1_xonly_pubkey *xonly_pubkey,+    int *pk_parity,+    const secp256k1_pubkey *pubkey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4);++/** Tweak an x-only public key by adding the generator multiplied with tweak32+ *  to it.+ *+ *  Note that the resulting point can not in general be represented by an x-only+ *  pubkey because it may have an odd Y coordinate. Instead, the output_pubkey+ *  is a normal secp256k1_pubkey.+ *+ *  Returns: 0 if the arguments are invalid or the resulting public key would be+ *           invalid (only when the tweak is the negation of the corresponding+ *           secret key). 1 otherwise.+ *+ *  Args:           ctx: pointer to a context object.+ *  Out:  output_pubkey: pointer to a public key to store the result. Will be set+ *                       to an invalid value if this function returns 0.+ *  In: internal_pubkey: pointer to an x-only pubkey to apply the tweak to.+ *              tweak32: pointer to a 32-byte tweak, which must be valid+ *                       according to secp256k1_ec_seckey_verify or 32 zero+ *                       bytes. For uniformly random 32-byte tweaks, the chance of+ *                       being invalid is negligible (around 1 in 2^128).+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_tweak_add(+    const secp256k1_context *ctx,+    secp256k1_pubkey *output_pubkey,+    const secp256k1_xonly_pubkey *internal_pubkey,+    const unsigned char *tweak32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);++/** Checks that a tweaked pubkey is the result of calling+ *  secp256k1_xonly_pubkey_tweak_add with internal_pubkey and tweak32.+ *+ *  The tweaked pubkey is represented by its 32-byte x-only serialization and+ *  its pk_parity, which can both be obtained by converting the result of+ *  tweak_add to a secp256k1_xonly_pubkey.+ *+ *  Note that this alone does _not_ verify that the tweaked pubkey is a+ *  commitment. If the tweak is not chosen in a specific way, the tweaked pubkey+ *  can easily be the result of a different internal_pubkey and tweak.+ *+ *  Returns: 0 if the arguments are invalid or the tweaked pubkey is not the+ *           result of tweaking the internal_pubkey with tweak32. 1 otherwise.+ *  Args:            ctx: pointer to a context object.+ *  In: tweaked_pubkey32: pointer to a serialized xonly_pubkey.+ *     tweaked_pk_parity: the parity of the tweaked pubkey (whose serialization+ *                        is passed in as tweaked_pubkey32). This must match the+ *                        pk_parity value that is returned when calling+ *                        secp256k1_xonly_pubkey with the tweaked pubkey, or+ *                        this function will fail.+ *       internal_pubkey: pointer to an x-only public key object to apply the tweak to.+ *               tweak32: pointer to a 32-byte tweak.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_tweak_add_check(+    const secp256k1_context *ctx,+    const unsigned char *tweaked_pubkey32,+    int tweaked_pk_parity,+    const secp256k1_xonly_pubkey *internal_pubkey,+    const unsigned char *tweak32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5);++/** Compute the keypair for a valid secret key.+ *+ *  See the documentation of `secp256k1_ec_seckey_verify` for more information+ *  about the validity of secret keys.+ *+ *  Returns: 1: secret key is valid+ *           0: secret key is invalid+ *  Args:    ctx: pointer to a context object (not secp256k1_context_static).+ *  Out: keypair: pointer to the created keypair.+ *  In:   seckey: pointer to a 32-byte secret key.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_keypair_create(+    const secp256k1_context *ctx,+    secp256k1_keypair *keypair,+    const unsigned char *seckey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Get the secret key from a keypair.+ *+ *  Returns: 1 always.+ *  Args:   ctx: pointer to a context object.+ *  Out: seckey: pointer to a 32-byte buffer for the secret key.+ *  In: keypair: pointer to a keypair.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_keypair_sec(+    const secp256k1_context *ctx,+    unsigned char *seckey,+    const secp256k1_keypair *keypair+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Get the public key from a keypair.+ *+ *  Returns: 1 always.+ *  Args:   ctx: pointer to a context object.+ *  Out: pubkey: pointer to a pubkey object, set to the keypair public key.+ *  In: keypair: pointer to a keypair.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_keypair_pub(+    const secp256k1_context *ctx,+    secp256k1_pubkey *pubkey,+    const secp256k1_keypair *keypair+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++/** Get the x-only public key from a keypair.+ *+ *  This is the same as calling secp256k1_keypair_pub and then+ *  secp256k1_xonly_pubkey_from_pubkey.+ *+ *  Returns: 1 always.+ *  Args:   ctx: pointer to a context object.+ *  Out: pubkey: pointer to an xonly_pubkey object, set to the keypair+ *               public key after converting it to an xonly_pubkey.+ *    pk_parity: Ignored if NULL. Otherwise, pointer to an integer that will be set to the+ *               pk_parity argument of secp256k1_xonly_pubkey_from_pubkey.+ *  In: keypair: pointer to a keypair.+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_keypair_xonly_pub(+    const secp256k1_context *ctx,+    secp256k1_xonly_pubkey *pubkey,+    int *pk_parity,+    const secp256k1_keypair *keypair+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4);++/** Tweak a keypair by adding tweak32 to the secret key and updating the public+ *  key accordingly.+ *+ *  Calling this function and then secp256k1_keypair_pub results in the same+ *  public key as calling secp256k1_keypair_xonly_pub and then+ *  secp256k1_xonly_pubkey_tweak_add.+ *+ *  Returns: 0 if the arguments are invalid or the resulting keypair would be+ *           invalid (only when the tweak is the negation of the keypair's+ *           secret key). 1 otherwise.+ *+ *  Args:       ctx: pointer to a context object.+ *  In/Out: keypair: pointer to a keypair to apply the tweak to. Will be set to+ *                   an invalid value if this function returns 0.+ *  In:     tweak32: pointer to a 32-byte tweak, which must be valid according to+ *                   secp256k1_ec_seckey_verify or 32 zero bytes. For uniformly+ *                   random 32-byte tweaks, the chance of being invalid is+ *                   negligible (around 1 in 2^128).+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_keypair_xonly_tweak_add(+    const secp256k1_context *ctx,+    secp256k1_keypair *keypair,+    const unsigned char *tweak32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);++#ifdef __cplusplus+}+#endif++#endif /* SECP256K1_EXTRAKEYS_H */
+ vendor/external/secp256k1/include/secp256k1_preallocated.h view
@@ -0,0 +1,134 @@+#ifndef SECP256K1_PREALLOCATED_H+#define SECP256K1_PREALLOCATED_H++#include "secp256k1.h"++#ifdef __cplusplus+extern "C" {+#endif++/* The module provided by this header file is intended for settings in which it+ * is not possible or desirable to rely on dynamic memory allocation. It provides+ * functions for creating, cloning, and destroying secp256k1 context objects in a+ * contiguous fixed-size block of memory provided by the caller.+ *+ * Context objects created by functions in this module can be used like contexts+ * objects created by functions in secp256k1.h, i.e., they can be passed to any+ * API function that expects a context object (see secp256k1.h for details). The+ * only exception is that context objects created by functions in this module+ * must be destroyed using secp256k1_context_preallocated_destroy (in this+ * module) instead of secp256k1_context_destroy (in secp256k1.h).+ *+ * It is guaranteed that functions in this module will not call malloc or its+ * friends realloc, calloc, and free.+ */++/** Determine the memory size of a secp256k1 context object to be created in+ *  caller-provided memory.+ *+ *  The purpose of this function is to determine how much memory must be provided+ *  to secp256k1_context_preallocated_create.+ *+ *  Returns: the required size of the caller-provided memory block+ *  In:      flags:    which parts of the context to initialize.+ */+SECP256K1_API size_t secp256k1_context_preallocated_size(+    unsigned int flags+) SECP256K1_WARN_UNUSED_RESULT;++/** Create a secp256k1 context object in caller-provided memory.+ *+ *  The caller must provide a pointer to a rewritable contiguous block of memory+ *  of size at least secp256k1_context_preallocated_size(flags) bytes, suitably+ *  aligned to hold an object of any type.+ *+ *  The block of memory is exclusively owned by the created context object during+ *  the lifetime of this context object, which begins with the call to this+ *  function and ends when a call to secp256k1_context_preallocated_destroy+ *  (which destroys the context object again) returns. During the lifetime of the+ *  context object, the caller is obligated not to access this block of memory,+ *  i.e., the caller may not read or write the memory, e.g., by copying the memory+ *  contents to a different location or trying to create a second context object+ *  in the memory. In simpler words, the prealloc pointer (or any pointer derived+ *  from it) should not be used during the lifetime of the context object.+ *+ *  Returns: pointer to newly created context object.+ *  In:      prealloc: pointer to a rewritable contiguous block of memory of+ *                     size at least secp256k1_context_preallocated_size(flags)+ *                     bytes, as detailed above.+ *           flags:    which parts of the context to initialize.+ *+ *  See secp256k1_context_create (in secp256k1.h) for further details.+ *+ *  See also secp256k1_context_randomize (in secp256k1.h)+ *  and secp256k1_context_preallocated_destroy.+ */+SECP256K1_API secp256k1_context *secp256k1_context_preallocated_create(+    void *prealloc,+    unsigned int flags+) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;++/** Determine the memory size of a secp256k1 context object to be copied into+ *  caller-provided memory.+ *+ *  Returns: the required size of the caller-provided memory block.+ *  In:      ctx: pointer to a context to copy.+ */+SECP256K1_API size_t secp256k1_context_preallocated_clone_size(+    const secp256k1_context *ctx+) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;++/** Copy a secp256k1 context object into caller-provided memory.+ *+ *  The caller must provide a pointer to a rewritable contiguous block of memory+ *  of size at least secp256k1_context_preallocated_size(flags) bytes, suitably+ *  aligned to hold an object of any type.+ *+ *  The block of memory is exclusively owned by the created context object during+ *  the lifetime of this context object, see the description of+ *  secp256k1_context_preallocated_create for details.+ *+ *  Cloning secp256k1_context_static is not possible, and should not be emulated by+ *  the caller (e.g., using memcpy). Create a new context instead.+ *+ *  Returns: pointer to a newly created context object.+ *  Args:    ctx:      pointer to a context to copy (not secp256k1_context_static).+ *  In:      prealloc: pointer to a rewritable contiguous block of memory of+ *                     size at least secp256k1_context_preallocated_size(flags)+ *                     bytes, as detailed above.+ */+SECP256K1_API secp256k1_context *secp256k1_context_preallocated_clone(+    const secp256k1_context *ctx,+    void *prealloc+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_WARN_UNUSED_RESULT;++/** Destroy a secp256k1 context object that has been created in+ *  caller-provided memory.+ *+ *  The context pointer may not be used afterwards.+ *+ *  The context to destroy must have been created using+ *  secp256k1_context_preallocated_create or secp256k1_context_preallocated_clone.+ *  If the context has instead been created using secp256k1_context_create or+ *  secp256k1_context_clone, the behaviour is undefined. In that case,+ *  secp256k1_context_destroy must be used instead.+ *+ *  If required, it is the responsibility of the caller to deallocate the block+ *  of memory properly after this function returns, e.g., by calling free on the+ *  preallocated pointer given to secp256k1_context_preallocated_create or+ *  secp256k1_context_preallocated_clone.+ *+ *  Args:   ctx: pointer to a context to destroy, constructed using+ *               secp256k1_context_preallocated_create or+ *               secp256k1_context_preallocated_clone+ *               (i.e., not secp256k1_context_static).+ */+SECP256K1_API void secp256k1_context_preallocated_destroy(+    secp256k1_context *ctx+) SECP256K1_ARG_NONNULL(1);++#ifdef __cplusplus+}+#endif++#endif /* SECP256K1_PREALLOCATED_H */
+ vendor/external/secp256k1/include/secp256k1_schnorrsig.h view
@@ -0,0 +1,190 @@+#ifndef SECP256K1_SCHNORRSIG_H+#define SECP256K1_SCHNORRSIG_H++#include "secp256k1.h"+#include "secp256k1_extrakeys.h"++#ifdef __cplusplus+extern "C" {+#endif++/** This module implements a variant of Schnorr signatures compliant with+ *  Bitcoin Improvement Proposal 340 "Schnorr Signatures for secp256k1"+ *  (https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).+ */++/** A pointer to a function to deterministically generate a nonce.+ *+ *  Same as secp256k1_nonce function with the exception of accepting an+ *  additional pubkey argument and not requiring an attempt argument. The pubkey+ *  argument can protect signature schemes with key-prefixed challenge hash+ *  inputs against reusing the nonce when signing with the wrong precomputed+ *  pubkey.+ *+ *  Returns: 1 if a nonce was successfully generated. 0 will cause signing to+ *           return an error.+ *  Out:  nonce32: pointer to a 32-byte array to be filled by the function+ *  In:       msg: the message being verified. Is NULL if and only if msglen+ *                 is 0.+ *         msglen: the length of the message+ *          key32: pointer to a 32-byte secret key (will not be NULL)+ *     xonly_pk32: the 32-byte serialized xonly pubkey corresponding to key32+ *                 (will not be NULL)+ *           algo: pointer to an array describing the signature+ *                 algorithm (will not be NULL)+ *        algolen: the length of the algo array+ *           data: arbitrary data pointer that is passed through+ *+ *  Except for test cases, this function should compute some cryptographic hash of+ *  the message, the key, the pubkey, the algorithm description, and data.+ */+typedef int (*secp256k1_nonce_function_hardened)(+    unsigned char *nonce32,+    const unsigned char *msg,+    size_t msglen,+    const unsigned char *key32,+    const unsigned char *xonly_pk32,+    const unsigned char *algo,+    size_t algolen,+    void *data+);++/** An implementation of the nonce generation function as defined in Bitcoin+ *  Improvement Proposal 340 "Schnorr Signatures for secp256k1"+ *  (https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).+ *+ *  If a data pointer is passed, it is assumed to be a pointer to 32 bytes of+ *  auxiliary random data as defined in BIP-340. If the data pointer is NULL,+ *  the nonce derivation procedure follows BIP-340 by setting the auxiliary+ *  random data to zero. The algo argument must be non-NULL, otherwise the+ *  function will fail and return 0. The hash will be tagged with algo.+ *  Therefore, to create BIP-340 compliant signatures, algo must be set to+ *  "BIP0340/nonce" and algolen to 13.+ */+SECP256K1_API const secp256k1_nonce_function_hardened secp256k1_nonce_function_bip340;++/** Data structure that contains additional arguments for schnorrsig_sign_custom.+ *+ *  A schnorrsig_extraparams structure object can be initialized correctly by+ *  setting it to SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT.+ *+ *  Members:+ *      magic: set to SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC at initialization+ *             and has no other function than making sure the object is+ *             initialized.+ *    noncefp: pointer to a nonce generation function. If NULL,+ *             secp256k1_nonce_function_bip340 is used+ *      ndata: pointer to arbitrary data used by the nonce generation function+ *             (can be NULL). If it is non-NULL and+ *             secp256k1_nonce_function_bip340 is used, then ndata must be a+ *             pointer to 32-byte auxiliary randomness as per BIP-340.+ */+typedef struct secp256k1_schnorrsig_extraparams {+    unsigned char magic[4];+    secp256k1_nonce_function_hardened noncefp;+    void *ndata;+} secp256k1_schnorrsig_extraparams;++#define SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC { 0xda, 0x6f, 0xb3, 0x8c }+#define SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT {\+    SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC,\+    NULL,\+    NULL\+}++/** Create a Schnorr signature.+ *+ *  Does _not_ strictly follow BIP-340 because it does not verify the resulting+ *  signature. Instead, you can manually use secp256k1_schnorrsig_verify and+ *  abort if it fails.+ *+ *  This function only signs 32-byte messages. If you have messages of a+ *  different size (or the same size but without a context-specific tag+ *  prefix), it is recommended to create a 32-byte message hash with+ *  secp256k1_tagged_sha256 and then sign the hash. Tagged hashing allows+ *  providing an context-specific tag for domain separation. This prevents+ *  signatures from being valid in multiple contexts by accident.+ *+ *  Returns 1 on success, 0 on failure.+ *  Args:    ctx: pointer to a context object (not secp256k1_context_static).+ *  Out:   sig64: pointer to a 64-byte array to store the serialized signature.+ *  In:    msg32: the 32-byte message being signed.+ *       keypair: pointer to an initialized keypair.+ *    aux_rand32: 32 bytes of fresh randomness. While recommended to provide+ *                this, it is only supplemental to security and can be NULL. A+ *                NULL argument is treated the same as an all-zero one. See+ *                BIP-340 "Default Signing" for a full explanation of this+ *                argument and for guidance if randomness is expensive.+ */+SECP256K1_API int secp256k1_schnorrsig_sign32(+    const secp256k1_context *ctx,+    unsigned char *sig64,+    const unsigned char *msg32,+    const secp256k1_keypair *keypair,+    const unsigned char *aux_rand32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);++/** Same as secp256k1_schnorrsig_sign32, but DEPRECATED. Will be removed in+ *  future versions. */+SECP256K1_API int secp256k1_schnorrsig_sign(+    const secp256k1_context *ctx,+    unsigned char *sig64,+    const unsigned char *msg32,+    const secp256k1_keypair *keypair,+    const unsigned char *aux_rand32+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)+  SECP256K1_DEPRECATED("Use secp256k1_schnorrsig_sign32 instead");++/** Create a Schnorr signature with a more flexible API.+ *+ *  Same arguments as secp256k1_schnorrsig_sign except that it allows signing+ *  variable length messages and accepts a pointer to an extraparams object that+ *  allows customizing signing by passing additional arguments.+ *+ *  Equivalent to secp256k1_schnorrsig_sign32(..., aux_rand32) if msglen is 32+ *  and extraparams is initialized as follows:+ *  ```+ *  secp256k1_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT;+ *  extraparams.ndata = (unsigned char*)aux_rand32;+ *  ```+ *+ *  Returns 1 on success, 0 on failure.+ *  Args:   ctx: pointer to a context object (not secp256k1_context_static).+ *  Out:  sig64: pointer to a 64-byte array to store the serialized signature.+ *  In:     msg: the message being signed. Can only be NULL if msglen is 0.+ *       msglen: length of the message.+ *      keypair: pointer to an initialized keypair.+ *  extraparams: pointer to an extraparams object (can be NULL).+ */+SECP256K1_API int secp256k1_schnorrsig_sign_custom(+    const secp256k1_context *ctx,+    unsigned char *sig64,+    const unsigned char *msg,+    size_t msglen,+    const secp256k1_keypair *keypair,+    secp256k1_schnorrsig_extraparams *extraparams+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(5);++/** Verify a Schnorr signature.+ *+ *  Returns: 1: correct signature+ *           0: incorrect signature+ *  Args:    ctx: pointer to a context object.+ *  In:    sig64: pointer to the 64-byte signature to verify.+ *           msg: the message being verified. Can only be NULL if msglen is 0.+ *        msglen: length of the message+ *        pubkey: pointer to an x-only public key to verify with+ */+SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify(+    const secp256k1_context *ctx,+    const unsigned char *sig64,+    const unsigned char *msg,+    size_t msglen,+    const secp256k1_xonly_pubkey *pubkey+) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(5);++#ifdef __cplusplus+}+#endif++#endif /* SECP256K1_SCHNORRSIG_H */
+ vendor/external/secp256k1/src/assumptions.h view
@@ -0,0 +1,87 @@+/***********************************************************************+ * Copyright (c) 2020 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ASSUMPTIONS_H+#define SECP256K1_ASSUMPTIONS_H++#include <limits.h>++#include "util.h"+#if defined(SECP256K1_INT128_NATIVE)+#include "int128_native.h"+#endif++/* This library, like most software, relies on a number of compiler implementation defined (but not undefined)+   behaviours. Although the behaviours we require are essentially universal we test them specifically here to+   reduce the odds of experiencing an unwelcome surprise.+*/++#if defined(__has_attribute)+# if __has_attribute(__unavailable__)+__attribute__((__unavailable__("Don't call this function. It only exists because STATIC_ASSERT cannot be used outside a function.")))+# endif+#endif+static void secp256k1_assumption_checker(void) {+    /* Bytes are 8 bits. */+    STATIC_ASSERT(CHAR_BIT == 8);++    /* No integer promotion for uint32_t. This ensures that we can multiply uintXX_t values where XX >= 32+       without signed overflow, which would be undefined behaviour. */+    STATIC_ASSERT(UINT_MAX <= UINT32_MAX);++    /* Conversions from unsigned to signed outside of the bounds of the signed type are+       implementation-defined. Verify that they function as reinterpreting the lower+       bits of the input in two's complement notation. Do this for conversions:+       - from uint(N)_t to int(N)_t with negative result+       - from uint(2N)_t to int(N)_t with negative result+       - from int(2N)_t to int(N)_t with negative result+       - from int(2N)_t to int(N)_t with positive result */++    /* To int8_t. */+    STATIC_ASSERT(((int8_t)(uint8_t)0xAB == (int8_t)-(int8_t)0x55));+    STATIC_ASSERT((int8_t)(uint16_t)0xABCD == (int8_t)-(int8_t)0x33);+    STATIC_ASSERT((int8_t)(int16_t)(uint16_t)0xCDEF == (int8_t)(uint8_t)0xEF);+    STATIC_ASSERT((int8_t)(int16_t)(uint16_t)0x9234 == (int8_t)(uint8_t)0x34);++    /* To int16_t. */+    STATIC_ASSERT((int16_t)(uint16_t)0xBCDE == (int16_t)-(int16_t)0x4322);+    STATIC_ASSERT((int16_t)(uint32_t)0xA1B2C3D4 == (int16_t)-(int16_t)0x3C2C);+    STATIC_ASSERT((int16_t)(int32_t)(uint32_t)0xC1D2E3F4 == (int16_t)(uint16_t)0xE3F4);+    STATIC_ASSERT((int16_t)(int32_t)(uint32_t)0x92345678 == (int16_t)(uint16_t)0x5678);++    /* To int32_t. */+    STATIC_ASSERT((int32_t)(uint32_t)0xB2C3D4E5 == (int32_t)-(int32_t)0x4D3C2B1B);+    STATIC_ASSERT((int32_t)(uint64_t)0xA123B456C789D012ULL == (int32_t)-(int32_t)0x38762FEE);+    STATIC_ASSERT((int32_t)(int64_t)(uint64_t)0xC1D2E3F4A5B6C7D8ULL == (int32_t)(uint32_t)0xA5B6C7D8);+    STATIC_ASSERT((int32_t)(int64_t)(uint64_t)0xABCDEF0123456789ULL == (int32_t)(uint32_t)0x23456789);++    /* To int64_t. */+    STATIC_ASSERT((int64_t)(uint64_t)0xB123C456D789E012ULL == (int64_t)-(int64_t)0x4EDC3BA928761FEEULL);+#if defined(SECP256K1_INT128_NATIVE)+    STATIC_ASSERT((int64_t)(((uint128_t)0xA1234567B8901234ULL << 64) + 0xC5678901D2345678ULL) == (int64_t)-(int64_t)0x3A9876FE2DCBA988ULL);+    STATIC_ASSERT(((int64_t)(int128_t)(((uint128_t)0xB1C2D3E4F5A6B7C8ULL << 64) + 0xD9E0F1A2B3C4D5E6ULL)) == (int64_t)(uint64_t)0xD9E0F1A2B3C4D5E6ULL);+    STATIC_ASSERT(((int64_t)(int128_t)(((uint128_t)0xABCDEF0123456789ULL << 64) + 0x0123456789ABCDEFULL)) == (int64_t)(uint64_t)0x0123456789ABCDEFULL);++    /* To int128_t. */+    STATIC_ASSERT((int128_t)(((uint128_t)0xB1234567C8901234ULL << 64) + 0xD5678901E2345678ULL) == (int128_t)(-(int128_t)0x8E1648B3F50E80DCULL * 0x8E1648B3F50E80DDULL + 0x5EA688D5482F9464ULL));+#endif++    /* Right shift on negative signed values is implementation defined. Verify that it+       acts as a right shift in two's complement with sign extension (i.e duplicating+       the top bit into newly added bits). */+    STATIC_ASSERT((((int8_t)0xE8) >> 2) == (int8_t)(uint8_t)0xFA);+    STATIC_ASSERT((((int16_t)0xE9AC) >> 4) == (int16_t)(uint16_t)0xFE9A);+    STATIC_ASSERT((((int32_t)0x937C918A) >> 9) == (int32_t)(uint32_t)0xFFC9BE48);+    STATIC_ASSERT((((int64_t)0xA8B72231DF9CF4B9ULL) >> 19) == (int64_t)(uint64_t)0xFFFFF516E4463BF3ULL);+#if defined(SECP256K1_INT128_NATIVE)+    STATIC_ASSERT((((int128_t)(((uint128_t)0xCD833A65684A0DBCULL << 64) + 0xB349312F71EA7637ULL)) >> 39) == (int128_t)(((uint128_t)0xFFFFFFFFFF9B0674ULL << 64) + 0xCAD0941B79669262ULL));+#endif++    /* This function is not supposed to be called. */+    VERIFY_CHECK(0);+}++#endif /* SECP256K1_ASSUMPTIONS_H */
+ vendor/external/secp256k1/src/checkmem.h view
@@ -0,0 +1,102 @@+/***********************************************************************+ * Copyright (c) 2022 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++/* The code here is inspired by Kris Kwiatkowski's approach in+ * https://github.com/kriskwiatkowski/pqc/blob/main/src/common/ct_check.h+ * to provide a general interface for memory-checking mechanisms, primarily+ * for constant-time checking.+ */++/* These macros are defined by this header file:+ *+ * - SECP256K1_CHECKMEM_ENABLED:+ *   - 1 if memory-checking integration is available, 0 otherwise.+ *     This is just a compile-time macro. Use the next macro to check it is actually+ *     available at runtime.+ * - SECP256K1_CHECKMEM_RUNNING():+ *   - Acts like a function call, returning 1 if memory checking is available+ *     at runtime.+ * - SECP256K1_CHECKMEM_CHECK(p, len):+ *   - Assert or otherwise fail in case the len-byte memory block pointed to by p is+ *     not considered entirely defined.+ * - SECP256K1_CHECKMEM_CHECK_VERIFY(p, len):+ *   - Like SECP256K1_CHECKMEM_CHECK, but only works in VERIFY mode.+ * - SECP256K1_CHECKMEM_UNDEFINE(p, len):+ *   - marks the len-byte memory block pointed to by p as undefined data (secret data,+ *     in the context of constant-time checking).+ * - SECP256K1_CHECKMEM_DEFINE(p, len):+ *   - marks the len-byte memory pointed to by p as defined data (public data, in the+ *     context of constant-time checking).+ * - SECP256K1_CHECKMEM_MSAN_DEFINE(p, len):+ *   - Like SECP256K1_CHECKMEM_DEFINE, but applies only to memory_sanitizer.+ *+ */++#ifndef SECP256K1_CHECKMEM_H+#define SECP256K1_CHECKMEM_H++/* Define a statement-like macro that ignores the arguments. */+#define SECP256K1_CHECKMEM_NOOP(p, len) do { (void)(p); (void)(len); } while(0)++/* If compiling under msan, map the SECP256K1_CHECKMEM_* functionality to msan.+ * Choose this preferentially, even when VALGRIND is defined, as msan-compiled+ * binaries can't be run under valgrind anyway. */+#if defined(__has_feature)+#  if __has_feature(memory_sanitizer)+#    include <sanitizer/msan_interface.h>+#    define SECP256K1_CHECKMEM_ENABLED 1+#    define SECP256K1_CHECKMEM_UNDEFINE(p, len) __msan_allocated_memory((p), (len))+#    define SECP256K1_CHECKMEM_DEFINE(p, len) __msan_unpoison((p), (len))+#    define SECP256K1_CHECKMEM_MSAN_DEFINE(p, len) __msan_unpoison((p), (len))+#    define SECP256K1_CHECKMEM_CHECK(p, len) __msan_check_mem_is_initialized((p), (len))+#    define SECP256K1_CHECKMEM_RUNNING() (1)+#  endif+#endif++#if !defined SECP256K1_CHECKMEM_MSAN_DEFINE+#  define SECP256K1_CHECKMEM_MSAN_DEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))+#endif++/* If valgrind integration is desired (through the VALGRIND define), implement the+ * SECP256K1_CHECKMEM_* macros using valgrind. */+#if !defined SECP256K1_CHECKMEM_ENABLED+#  if defined VALGRIND+#    include <stddef.h>+#  if defined(__clang__) && defined(__APPLE__)+#    pragma clang diagnostic push+#    pragma clang diagnostic ignored "-Wreserved-identifier"+#  endif+#    include <valgrind/memcheck.h>+#  if defined(__clang__) && defined(__APPLE__)+#    pragma clang diagnostic pop+#  endif+#    define SECP256K1_CHECKMEM_ENABLED 1+#    define SECP256K1_CHECKMEM_UNDEFINE(p, len) VALGRIND_MAKE_MEM_UNDEFINED((p), (len))+#    define SECP256K1_CHECKMEM_DEFINE(p, len) VALGRIND_MAKE_MEM_DEFINED((p), (len))+#    define SECP256K1_CHECKMEM_CHECK(p, len) VALGRIND_CHECK_MEM_IS_DEFINED((p), (len))+     /* VALGRIND_MAKE_MEM_DEFINED returns 0 iff not running on memcheck.+      * This is more precise than the RUNNING_ON_VALGRIND macro, which+      * checks for valgrind in general instead of memcheck specifically. */+#    define SECP256K1_CHECKMEM_RUNNING() (VALGRIND_MAKE_MEM_DEFINED(NULL, 0) != 0)+#  endif+#endif++/* As a fall-back, map these macros to dummy statements. */+#if !defined SECP256K1_CHECKMEM_ENABLED+#  define SECP256K1_CHECKMEM_ENABLED 0+#  define SECP256K1_CHECKMEM_UNDEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))+#  define SECP256K1_CHECKMEM_DEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))+#  define SECP256K1_CHECKMEM_CHECK(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))+#  define SECP256K1_CHECKMEM_RUNNING() (0)+#endif++#if defined VERIFY+#define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_CHECK((p), (len))+#else+#define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))+#endif++#endif /* SECP256K1_CHECKMEM_H */
+ vendor/external/secp256k1/src/ecdsa.h view
@@ -0,0 +1,21 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECDSA_H+#define SECP256K1_ECDSA_H++#include <stddef.h>++#include "scalar.h"+#include "group.h"+#include "ecmult.h"++static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size);+static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s);+static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message);+static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid);++#endif /* SECP256K1_ECDSA_H */
+ vendor/external/secp256k1/src/ecdsa_impl.h view
@@ -0,0 +1,304 @@+/***********************************************************************+ * Copyright (c) 2013-2015 Pieter Wuille                               *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/+++#ifndef SECP256K1_ECDSA_IMPL_H+#define SECP256K1_ECDSA_IMPL_H++#include "scalar.h"+#include "field.h"+#include "group.h"+#include "ecmult.h"+#include "ecmult_gen.h"+#include "ecdsa.h"++/** Group order for secp256k1 defined as 'n' in "Standards for Efficient Cryptography" (SEC2) 2.7.1+ *  $ sage -c 'load("secp256k1_params.sage"); print(hex(N))'+ *  0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141+ */+static const secp256k1_fe secp256k1_ecdsa_const_order_as_fe = SECP256K1_FE_CONST(+    0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFEUL,+    0xBAAEDCE6UL, 0xAF48A03BUL, 0xBFD25E8CUL, 0xD0364141UL+);++/** Difference between field and order, values 'p' and 'n' values defined in+ *  "Standards for Efficient Cryptography" (SEC2) 2.7.1.+ *  $ sage -c 'load("secp256k1_params.sage"); print(hex(P-N))'+ *  0x14551231950b75fc4402da1722fc9baee+ */+static const secp256k1_fe secp256k1_ecdsa_const_p_minus_order = SECP256K1_FE_CONST(+    0, 0, 0, 1, 0x45512319UL, 0x50B75FC4UL, 0x402DA172UL, 0x2FC9BAEEUL+);++static int secp256k1_der_read_len(size_t *len, const unsigned char **sigp, const unsigned char *sigend) {+    size_t lenleft;+    unsigned char b1;+    VERIFY_CHECK(len != NULL);+    *len = 0;+    if (*sigp >= sigend) {+        return 0;+    }+    b1 = *((*sigp)++);+    if (b1 == 0xFF) {+        /* X.690-0207 8.1.3.5.c the value 0xFF shall not be used. */+        return 0;+    }+    if ((b1 & 0x80) == 0) {+        /* X.690-0207 8.1.3.4 short form length octets */+        *len = b1;+        return 1;+    }+    if (b1 == 0x80) {+        /* Indefinite length is not allowed in DER. */+        return 0;+    }+    /* X.690-207 8.1.3.5 long form length octets */+    lenleft = b1 & 0x7F; /* lenleft is at least 1 */+    if (lenleft > (size_t)(sigend - *sigp)) {+        return 0;+    }+    if (**sigp == 0) {+        /* Not the shortest possible length encoding. */+        return 0;+    }+    if (lenleft > sizeof(size_t)) {+        /* The resulting length would exceed the range of a size_t, so+         * it is certainly longer than the passed array size. */+        return 0;+    }+    while (lenleft > 0) {+        *len = (*len << 8) | **sigp;+        (*sigp)++;+        lenleft--;+    }+    if (*len > (size_t)(sigend - *sigp)) {+        /* Result exceeds the length of the passed array.+           (Checking this is the responsibility of the caller but it+           can't hurt do it here, too.) */+        return 0;+    }+    if (*len < 128) {+        /* Not the shortest possible length encoding. */+        return 0;+    }+    return 1;+}++static int secp256k1_der_parse_integer(secp256k1_scalar *r, const unsigned char **sig, const unsigned char *sigend) {+    int overflow = 0;+    unsigned char ra[32] = {0};+    size_t rlen;++    if (*sig == sigend || **sig != 0x02) {+        /* Not a primitive integer (X.690-0207 8.3.1). */+        return 0;+    }+    (*sig)++;+    if (secp256k1_der_read_len(&rlen, sig, sigend) == 0) {+        return 0;+    }+    if (rlen == 0 || rlen > (size_t)(sigend - *sig)) {+        /* Exceeds bounds or not at least length 1 (X.690-0207 8.3.1).  */+        return 0;+    }+    if (**sig == 0x00 && rlen > 1 && (((*sig)[1]) & 0x80) == 0x00) {+        /* Excessive 0x00 padding. */+        return 0;+    }+    if (**sig == 0xFF && rlen > 1 && (((*sig)[1]) & 0x80) == 0x80) {+        /* Excessive 0xFF padding. */+        return 0;+    }+    if ((**sig & 0x80) == 0x80) {+        /* Negative. */+        overflow = 1;+    }+    /* There is at most one leading zero byte:+     * if there were two leading zero bytes, we would have failed and returned 0+     * because of excessive 0x00 padding already. */+    if (rlen > 0 && **sig == 0) {+        /* Skip leading zero byte */+        rlen--;+        (*sig)++;+    }+    if (rlen > 32) {+        overflow = 1;+    }+    if (!overflow) {+        if (rlen) memcpy(ra + 32 - rlen, *sig, rlen);+        secp256k1_scalar_set_b32(r, ra, &overflow);+    }+    if (overflow) {+        secp256k1_scalar_set_int(r, 0);+    }+    (*sig) += rlen;+    return 1;+}++static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *rr, secp256k1_scalar *rs, const unsigned char *sig, size_t size) {+    const unsigned char *sigend = sig + size;+    size_t rlen;+    if (sig == sigend || *(sig++) != 0x30) {+        /* The encoding doesn't start with a constructed sequence (X.690-0207 8.9.1). */+        return 0;+    }+    if (secp256k1_der_read_len(&rlen, &sig, sigend) == 0) {+        return 0;+    }+    if (rlen != (size_t)(sigend - sig)) {+        /* Tuple exceeds bounds or garage after tuple. */+        return 0;+    }++    if (!secp256k1_der_parse_integer(rr, &sig, sigend)) {+        return 0;+    }+    if (!secp256k1_der_parse_integer(rs, &sig, sigend)) {+        return 0;+    }++    if (sig != sigend) {+        /* Trailing garbage inside tuple. */+        return 0;+    }++    return 1;+}++static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar* ar, const secp256k1_scalar* as) {+    unsigned char r[33] = {0}, s[33] = {0};+    unsigned char *rp = r, *sp = s;+    size_t lenR = 33, lenS = 33;+    secp256k1_scalar_get_b32(&r[1], ar);+    secp256k1_scalar_get_b32(&s[1], as);+    while (lenR > 1 && rp[0] == 0 && rp[1] < 0x80) { lenR--; rp++; }+    while (lenS > 1 && sp[0] == 0 && sp[1] < 0x80) { lenS--; sp++; }+    if (*size < 6+lenS+lenR) {+        *size = 6 + lenS + lenR;+        return 0;+    }+    *size = 6 + lenS + lenR;+    sig[0] = 0x30;+    sig[1] = 4 + lenS + lenR;+    sig[2] = 0x02;+    sig[3] = lenR;+    memcpy(sig+4, rp, lenR);+    sig[4+lenR] = 0x02;+    sig[5+lenR] = lenS;+    memcpy(sig+lenR+6, sp, lenS);+    return 1;+}++static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar *sigr, const secp256k1_scalar *sigs, const secp256k1_ge *pubkey, const secp256k1_scalar *message) {+    unsigned char c[32];+    secp256k1_scalar sn, u1, u2;+#if !defined(EXHAUSTIVE_TEST_ORDER)+    secp256k1_fe xr;+#endif+    secp256k1_gej pubkeyj;+    secp256k1_gej pr;++    if (secp256k1_scalar_is_zero(sigr) || secp256k1_scalar_is_zero(sigs)) {+        return 0;+    }++    secp256k1_scalar_inverse_var(&sn, sigs);+    secp256k1_scalar_mul(&u1, &sn, message);+    secp256k1_scalar_mul(&u2, &sn, sigr);+    secp256k1_gej_set_ge(&pubkeyj, pubkey);+    secp256k1_ecmult(&pr, &pubkeyj, &u2, &u1);+    if (secp256k1_gej_is_infinity(&pr)) {+        return 0;+    }++#if defined(EXHAUSTIVE_TEST_ORDER)+{+    secp256k1_scalar computed_r;+    secp256k1_ge pr_ge;+    secp256k1_ge_set_gej(&pr_ge, &pr);+    secp256k1_fe_normalize(&pr_ge.x);++    secp256k1_fe_get_b32(c, &pr_ge.x);+    secp256k1_scalar_set_b32(&computed_r, c, NULL);+    return secp256k1_scalar_eq(sigr, &computed_r);+}+#else+    secp256k1_scalar_get_b32(c, sigr);+    /* we can ignore the fe_set_b32_limit return value, because we know the input is in range */+    (void)secp256k1_fe_set_b32_limit(&xr, c);++    /** We now have the recomputed R point in pr, and its claimed x coordinate (modulo n)+     *  in xr. Naively, we would extract the x coordinate from pr (requiring a inversion modulo p),+     *  compute the remainder modulo n, and compare it to xr. However:+     *+     *        xr == X(pr) mod n+     *    <=> exists h. (xr + h * n < p && xr + h * n == X(pr))+     *    [Since 2 * n > p, h can only be 0 or 1]+     *    <=> (xr == X(pr)) || (xr + n < p && xr + n == X(pr))+     *    [In Jacobian coordinates, X(pr) is pr.x / pr.z^2 mod p]+     *    <=> (xr == pr.x / pr.z^2 mod p) || (xr + n < p && xr + n == pr.x / pr.z^2 mod p)+     *    [Multiplying both sides of the equations by pr.z^2 mod p]+     *    <=> (xr * pr.z^2 mod p == pr.x) || (xr + n < p && (xr + n) * pr.z^2 mod p == pr.x)+     *+     *  Thus, we can avoid the inversion, but we have to check both cases separately.+     *  secp256k1_gej_eq_x implements the (xr * pr.z^2 mod p == pr.x) test.+     */+    if (secp256k1_gej_eq_x_var(&xr, &pr)) {+        /* xr * pr.z^2 mod p == pr.x, so the signature is valid. */+        return 1;+    }+    if (secp256k1_fe_cmp_var(&xr, &secp256k1_ecdsa_const_p_minus_order) >= 0) {+        /* xr + n >= p, so we can skip testing the second case. */+        return 0;+    }+    secp256k1_fe_add(&xr, &secp256k1_ecdsa_const_order_as_fe);+    if (secp256k1_gej_eq_x_var(&xr, &pr)) {+        /* (xr + n) * pr.z^2 mod p == pr.x, so the signature is valid. */+        return 1;+    }+    return 0;+#endif+}++static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar *sigr, secp256k1_scalar *sigs, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid) {+    unsigned char b[32];+    secp256k1_gej rp;+    secp256k1_ge r;+    secp256k1_scalar n;+    int overflow = 0;+    int high;++    secp256k1_ecmult_gen(ctx, &rp, nonce);+    secp256k1_ge_set_gej(&r, &rp);+    secp256k1_fe_normalize(&r.x);+    secp256k1_fe_normalize(&r.y);+    secp256k1_fe_get_b32(b, &r.x);+    secp256k1_scalar_set_b32(sigr, b, &overflow);+    if (recid) {+        /* The overflow condition is cryptographically unreachable as hitting it requires finding the discrete log+         * of some P where P.x >= order, and only 1 in about 2^127 points meet this criteria.+         */+        *recid = (overflow << 1) | secp256k1_fe_is_odd(&r.y);+    }+    secp256k1_scalar_mul(&n, sigr, seckey);+    secp256k1_scalar_add(&n, &n, message);+    secp256k1_scalar_inverse(sigs, nonce);+    secp256k1_scalar_mul(sigs, sigs, &n);+    secp256k1_scalar_clear(&n);+    secp256k1_gej_clear(&rp);+    secp256k1_ge_clear(&r);+    high = secp256k1_scalar_is_high(sigs);+    secp256k1_scalar_cond_negate(sigs, high);+    if (recid) {+        *recid ^= high;+    }+    /* P.x = order is on the curve, so technically sig->r could end up being zero, which would be an invalid signature.+     * This is cryptographically unreachable as hitting it requires finding the discrete log of P.x = N.+     */+    return (int)(!secp256k1_scalar_is_zero(sigr)) & (int)(!secp256k1_scalar_is_zero(sigs));+}++#endif /* SECP256K1_ECDSA_IMPL_H */
+ vendor/external/secp256k1/src/eckey.h view
@@ -0,0 +1,25 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECKEY_H+#define SECP256K1_ECKEY_H++#include <stddef.h>++#include "group.h"+#include "scalar.h"+#include "ecmult.h"+#include "ecmult_gen.h"++static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size);+static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed);++static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak);+static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak);+static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak);+static int secp256k1_eckey_pubkey_tweak_mul(secp256k1_ge *key, const secp256k1_scalar *tweak);++#endif /* SECP256K1_ECKEY_H */
+ vendor/external/secp256k1/src/eckey_impl.h view
@@ -0,0 +1,92 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECKEY_IMPL_H+#define SECP256K1_ECKEY_IMPL_H++#include "eckey.h"++#include "scalar.h"+#include "field.h"+#include "group.h"+#include "ecmult_gen.h"++static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size) {+    if (size == 33 && (pub[0] == SECP256K1_TAG_PUBKEY_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_ODD)) {+        secp256k1_fe x;+        return secp256k1_fe_set_b32_limit(&x, pub+1) && secp256k1_ge_set_xo_var(elem, &x, pub[0] == SECP256K1_TAG_PUBKEY_ODD);+    } else if (size == 65 && (pub[0] == SECP256K1_TAG_PUBKEY_UNCOMPRESSED || pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD)) {+        secp256k1_fe x, y;+        if (!secp256k1_fe_set_b32_limit(&x, pub+1) || !secp256k1_fe_set_b32_limit(&y, pub+33)) {+            return 0;+        }+        secp256k1_ge_set_xy(elem, &x, &y);+        if ((pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD) &&+            secp256k1_fe_is_odd(&y) != (pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD)) {+            return 0;+        }+        return secp256k1_ge_is_valid_var(elem);+    } else {+        return 0;+    }+}++static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed) {+    if (secp256k1_ge_is_infinity(elem)) {+        return 0;+    }+    secp256k1_fe_normalize_var(&elem->x);+    secp256k1_fe_normalize_var(&elem->y);+    secp256k1_fe_get_b32(&pub[1], &elem->x);+    if (compressed) {+        *size = 33;+        pub[0] = secp256k1_fe_is_odd(&elem->y) ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN;+    } else {+        *size = 65;+        pub[0] = SECP256K1_TAG_PUBKEY_UNCOMPRESSED;+        secp256k1_fe_get_b32(&pub[33], &elem->y);+    }+    return 1;+}++static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak) {+    secp256k1_scalar_add(key, key, tweak);+    return !secp256k1_scalar_is_zero(key);+}++static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak) {+    secp256k1_gej pt;+    secp256k1_gej_set_ge(&pt, key);+    secp256k1_ecmult(&pt, &pt, &secp256k1_scalar_one, tweak);++    if (secp256k1_gej_is_infinity(&pt)) {+        return 0;+    }+    secp256k1_ge_set_gej(key, &pt);+    return 1;+}++static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak) {+    int ret;+    ret = !secp256k1_scalar_is_zero(tweak);++    secp256k1_scalar_mul(key, key, tweak);+    return ret;+}++static int secp256k1_eckey_pubkey_tweak_mul(secp256k1_ge *key, const secp256k1_scalar *tweak) {+    secp256k1_gej pt;+    if (secp256k1_scalar_is_zero(tweak)) {+        return 0;+    }++    secp256k1_gej_set_ge(&pt, key);+    secp256k1_ecmult(&pt, &pt, tweak, &secp256k1_scalar_zero);+    secp256k1_ge_set_gej(key, &pt);+    return 1;+}++#endif /* SECP256K1_ECKEY_IMPL_H */
+ vendor/external/secp256k1/src/ecmult.h view
@@ -0,0 +1,61 @@+/***********************************************************************+ * Copyright (c) 2013, 2014, 2017 Pieter Wuille, Andrew Poelstra       *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECMULT_H+#define SECP256K1_ECMULT_H++#include "group.h"+#include "scalar.h"+#include "scratch.h"++#ifndef ECMULT_WINDOW_SIZE+#  define ECMULT_WINDOW_SIZE 15+#  ifdef DEBUG_CONFIG+#     pragma message DEBUG_CONFIG_MSG("ECMULT_WINDOW_SIZE undefined, assuming default value")+#  endif+#endif++#ifdef DEBUG_CONFIG+#  pragma message DEBUG_CONFIG_DEF(ECMULT_WINDOW_SIZE)+#endif++/* No one will ever need more than a window size of 24. The code might+ * be correct for larger values of ECMULT_WINDOW_SIZE but this is not+ * tested.+ *+ * The following limitations are known, and there are probably more:+ * If WINDOW_G > 27 and size_t has 32 bits, then the code is incorrect+ * because the size of the memory object that we allocate (in bytes)+ * will not fit in a size_t.+ * If WINDOW_G > 31 and int has 32 bits, then the code is incorrect+ * because certain expressions will overflow.+ */+#if ECMULT_WINDOW_SIZE < 2 || ECMULT_WINDOW_SIZE > 24+#  error Set ECMULT_WINDOW_SIZE to an integer in range [2..24].+#endif++/** The number of entries a table with precomputed multiples needs to have. */+#define ECMULT_TABLE_SIZE(w) (1L << ((w)-2))++/** Double multiply: R = na*A + ng*G */+static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng);++typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data);++/**+ * Multi-multiply: R = inp_g_sc * G + sum_i ni * Ai.+ * Chooses the right algorithm for a given number of points and scratch space+ * size. Resets and overwrites the given scratch space. If the points do not+ * fit in the scratch space the algorithm is repeatedly run with batches of+ * points. If no scratch space is given then a simple algorithm is used that+ * simply multiplies the points with the corresponding scalars and adds them up.+ * Returns: 1 on success (including when inp_g_sc is NULL and n is 0)+ *          0 if there is not enough scratch space for a single point or+ *          callback returns 0+ */+static int secp256k1_ecmult_multi_var(const secp256k1_callback* error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n);++#endif /* SECP256K1_ECMULT_H */
+ vendor/external/secp256k1/src/ecmult_compute_table.h view
@@ -0,0 +1,16 @@+/*****************************************************************************************************+ * Copyright (c) 2013, 2014, 2017, 2021 Pieter Wuille, Andrew Poelstra, Jonas Nick, Russell O'Connor *+ * Distributed under the MIT software license, see the accompanying                                  *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.                              *+ *****************************************************************************************************/++#ifndef SECP256K1_ECMULT_COMPUTE_TABLE_H+#define SECP256K1_ECMULT_COMPUTE_TABLE_H++/* Construct table of all odd multiples of gen in range 1..(2**(window_g-1)-1). */+static void secp256k1_ecmult_compute_table(secp256k1_ge_storage* table, int window_g, const secp256k1_gej* gen);++/* Like secp256k1_ecmult_compute_table, but one for both gen and gen*2^128. */+static void secp256k1_ecmult_compute_two_tables(secp256k1_ge_storage* table, secp256k1_ge_storage* table_128, int window_g, const secp256k1_ge* gen);++#endif /* SECP256K1_ECMULT_COMPUTE_TABLE_H */
+ vendor/external/secp256k1/src/ecmult_compute_table_impl.h view
@@ -0,0 +1,49 @@+/*****************************************************************************************************+ * Copyright (c) 2013, 2014, 2017, 2021 Pieter Wuille, Andrew Poelstra, Jonas Nick, Russell O'Connor *+ * Distributed under the MIT software license, see the accompanying                                  *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.                              *+ *****************************************************************************************************/++#ifndef SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H+#define SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H++#include "ecmult_compute_table.h"+#include "group_impl.h"+#include "field_impl.h"+#include "ecmult.h"+#include "util.h"++static void secp256k1_ecmult_compute_table(secp256k1_ge_storage* table, int window_g, const secp256k1_gej* gen) {+    secp256k1_gej gj;+    secp256k1_ge ge, dgen;+    int j;++    gj = *gen;+    secp256k1_ge_set_gej_var(&ge, &gj);+    secp256k1_ge_to_storage(&table[0], &ge);++    secp256k1_gej_double_var(&gj, gen, NULL);+    secp256k1_ge_set_gej_var(&dgen, &gj);++    for (j = 1; j < ECMULT_TABLE_SIZE(window_g); ++j) {+        secp256k1_gej_set_ge(&gj, &ge);+        secp256k1_gej_add_ge_var(&gj, &gj, &dgen, NULL);+        secp256k1_ge_set_gej_var(&ge, &gj);+        secp256k1_ge_to_storage(&table[j], &ge);+    }+}++/* Like secp256k1_ecmult_compute_table, but one for both gen and gen*2^128. */+static void secp256k1_ecmult_compute_two_tables(secp256k1_ge_storage* table, secp256k1_ge_storage* table_128, int window_g, const secp256k1_ge* gen) {+    secp256k1_gej gj;+    int i;++    secp256k1_gej_set_ge(&gj, gen);+    secp256k1_ecmult_compute_table(table, window_g, &gj);+    for (i = 0; i < 128; ++i) {+        secp256k1_gej_double_var(&gj, &gj, NULL);+    }+    secp256k1_ecmult_compute_table(table_128, window_g, &gj);+}++#endif /* SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H */
+ vendor/external/secp256k1/src/ecmult_const.h view
@@ -0,0 +1,38 @@+/***********************************************************************+ * Copyright (c) 2015 Andrew Poelstra                                  *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECMULT_CONST_H+#define SECP256K1_ECMULT_CONST_H++#include "scalar.h"+#include "group.h"++/**+ * Multiply: R = q*A (in constant-time for q)+ */+static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q);++/**+ * Same as secp256k1_ecmult_const, but takes in an x coordinate of the base point+ * only, specified as fraction n/d (numerator/denominator). Only the x coordinate of the result is+ * returned.+ *+ * If known_on_curve is 0, a verification is performed that n/d is a valid X+ * coordinate, and 0 is returned if not. Otherwise, 1 is returned.+ *+ * d being NULL is interpreted as d=1. If non-NULL, d must not be zero. q must not be zero.+ *+ * Constant time in the value of q, but not any other inputs.+ */+static int secp256k1_ecmult_const_xonly(+    secp256k1_fe *r,+    const secp256k1_fe *n,+    const secp256k1_fe *d,+    const secp256k1_scalar *q,+    int known_on_curve+);++#endif /* SECP256K1_ECMULT_CONST_H */
+ vendor/external/secp256k1/src/ecmult_const_impl.h view
@@ -0,0 +1,399 @@+/***********************************************************************+ * Copyright (c) 2015, 2022 Pieter Wuille, Andrew Poelstra             *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECMULT_CONST_IMPL_H+#define SECP256K1_ECMULT_CONST_IMPL_H++#include "scalar.h"+#include "group.h"+#include "ecmult_const.h"+#include "ecmult_impl.h"++#if defined(EXHAUSTIVE_TEST_ORDER)+/* We need 2^ECMULT_CONST_GROUP_SIZE - 1 to be less than EXHAUSTIVE_TEST_ORDER, because+ * the tables cannot have infinities in them (this breaks the effective-affine technique's+ * z-ratio tracking) */+#  if EXHAUSTIVE_TEST_ORDER == 199+#    define ECMULT_CONST_GROUP_SIZE 4+#  elif EXHAUSTIVE_TEST_ORDER == 13+#    define ECMULT_CONST_GROUP_SIZE 3+#  elif EXHAUSTIVE_TEST_ORDER == 7+#    define ECMULT_CONST_GROUP_SIZE 2+#  else+#    error "Unknown EXHAUSTIVE_TEST_ORDER"+#  endif+#else+/* Group size 4 or 5 appears optimal. */+#  define ECMULT_CONST_GROUP_SIZE 5+#endif++#define ECMULT_CONST_TABLE_SIZE (1L << (ECMULT_CONST_GROUP_SIZE - 1))+#define ECMULT_CONST_GROUPS ((129 + ECMULT_CONST_GROUP_SIZE - 1) / ECMULT_CONST_GROUP_SIZE)+#define ECMULT_CONST_BITS (ECMULT_CONST_GROUPS * ECMULT_CONST_GROUP_SIZE)++/** Fill a table 'pre' with precomputed odd multiples of a.+ *+ *  The resulting point set is brought to a single constant Z denominator, stores the X and Y+ *  coordinates as ge points in pre, and stores the global Z in globalz.+ *+ *  'pre' must be an array of size ECMULT_CONST_TABLE_SIZE.+ */+static void secp256k1_ecmult_const_odd_multiples_table_globalz(secp256k1_ge *pre, secp256k1_fe *globalz, const secp256k1_gej *a) {+    secp256k1_fe zr[ECMULT_CONST_TABLE_SIZE];++    secp256k1_ecmult_odd_multiples_table(ECMULT_CONST_TABLE_SIZE, pre, zr, globalz, a);+    secp256k1_ge_table_set_globalz(ECMULT_CONST_TABLE_SIZE, pre, zr);+}++/* Given a table 'pre' with odd multiples of a point, put in r the signed-bit multiplication of n with that point.+ *+ * For example, if ECMULT_CONST_GROUP_SIZE is 4, then pre is expected to contain 8 entries:+ * [1*P, 3*P, 5*P, 7*P, 9*P, 11*P, 13*P, 15*P]. n is then expected to be a 4-bit integer (range 0-15), and its+ * bits are interpreted as signs of powers of two to look up.+ *+ * For example, if n=4, which is 0100 in binary, which is interpreted as [- + - -], so the looked up value is+ * [ -(2^3) + (2^2) - (2^1) - (2^0) ]*P = -7*P. Every valid n translates to an odd number in range [-15,15],+ * which means we just need to look up one of the precomputed values, and optionally negate it.+ */+#define ECMULT_CONST_TABLE_GET_GE(r,pre,n) do { \+    unsigned int m = 0; \+    /* If the top bit of n is 0, we want the negation. */ \+    volatile unsigned int negative = ((n) >> (ECMULT_CONST_GROUP_SIZE - 1)) ^ 1; \+    /* Let n[i] be the i-th bit of n, then the index is+     *     sum(cnot(n[i]) * 2^i, i=0..l-2)+     * where cnot(b) = b if n[l-1] = 1 and 1 - b otherwise.+     * For example, if n = 4, in binary 0100, the index is 3, in binary 011.+     *+     * Proof:+     *     Let+     *         x = sum((2*n[i] - 1)*2^i, i=0..l-1)+     *           = 2*sum(n[i] * 2^i, i=0..l-1) - 2^l + 1+     *     be the value represented by n.+     *     The index is (x - 1)/2 if x > 0 and -(x + 1)/2 otherwise.+     *     Case x > 0:+     *         n[l-1] = 1+     *         index = sum(n[i] * 2^i, i=0..l-1) - 2^(l-1)+     *               = sum(n[i] * 2^i, i=0..l-2)+     *     Case x <= 0:+     *         n[l-1] = 0+     *          index = -(2*sum(n[i] * 2^i, i=0..l-1) - 2^l + 2)/2+     *                = 2^(l-1) - 1 - sum(n[i] * 2^i, i=0..l-1)+     *                = sum((1 - n[i]) * 2^i, i=0..l-2)+     */ \+    unsigned int index = ((unsigned int)(-negative) ^ n) & ((1U << (ECMULT_CONST_GROUP_SIZE - 1)) - 1U); \+    secp256k1_fe neg_y; \+    VERIFY_CHECK((n) < (1U << ECMULT_CONST_GROUP_SIZE)); \+    VERIFY_CHECK(index < (1U << (ECMULT_CONST_GROUP_SIZE - 1))); \+    /* Unconditionally set r->x = (pre)[m].x. r->y = (pre)[m].y. because it's either the correct one+     * or will get replaced in the later iterations, this is needed to make sure `r` is initialized. */ \+    (r)->x = (pre)[m].x; \+    (r)->y = (pre)[m].y; \+    for (m = 1; m < ECMULT_CONST_TABLE_SIZE; m++) { \+        /* This loop is used to avoid secret data in array indices. See+         * the comment in ecmult_gen_impl.h for rationale. */ \+        secp256k1_fe_cmov(&(r)->x, &(pre)[m].x, m == index); \+        secp256k1_fe_cmov(&(r)->y, &(pre)[m].y, m == index); \+    } \+    (r)->infinity = 0; \+    secp256k1_fe_negate(&neg_y, &(r)->y, 1); \+    secp256k1_fe_cmov(&(r)->y, &neg_y, negative); \+} while(0)++/* For K as defined in the comment of secp256k1_ecmult_const, we have several precomputed+ * formulas/constants.+ * - in exhaustive test mode, we give an explicit expression to compute it at compile time: */+#ifdef EXHAUSTIVE_TEST_ORDER+static const secp256k1_scalar secp256k1_ecmult_const_K = ((SECP256K1_SCALAR_CONST(0, 0, 0, (1U << (ECMULT_CONST_BITS - 128)) - 2U, 0, 0, 0, 0) + EXHAUSTIVE_TEST_ORDER - 1U) * (1U + EXHAUSTIVE_TEST_LAMBDA)) % EXHAUSTIVE_TEST_ORDER;+/* - for the real secp256k1 group we have constants for various ECMULT_CONST_BITS values. */+#elif ECMULT_CONST_BITS == 129+/* For GROUP_SIZE = 1,3. */+static const secp256k1_scalar secp256k1_ecmult_const_K = SECP256K1_SCALAR_CONST(0xac9c52b3ul, 0x3fa3cf1ful, 0x5ad9e3fdul, 0x77ed9ba4ul, 0xa880b9fcul, 0x8ec739c2ul, 0xe0cfc810ul, 0xb51283ceul);+#elif ECMULT_CONST_BITS == 130+/* For GROUP_SIZE = 2,5. */+static const secp256k1_scalar secp256k1_ecmult_const_K = SECP256K1_SCALAR_CONST(0xa4e88a7dul, 0xcb13034eul, 0xc2bdd6bful, 0x7c118d6bul, 0x589ae848ul, 0x26ba29e4ul, 0xb5c2c1dcul, 0xde9798d9ul);+#elif ECMULT_CONST_BITS == 132+/* For GROUP_SIZE = 4,6 */+static const secp256k1_scalar secp256k1_ecmult_const_K = SECP256K1_SCALAR_CONST(0x76b1d93dul, 0x0fae3c6bul, 0x3215874bul, 0x94e93813ul, 0x7937fe0dul, 0xb66bcaaful, 0xb3749ca5ul, 0xd7b6171bul);+#else+#  error "Unknown ECMULT_CONST_BITS"+#endif++static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q) {+    /* The approach below combines the signed-digit logic from Mike Hamburg's+     * "Fast and compact elliptic-curve cryptography" (https://eprint.iacr.org/2012/309)+     * Section 3.3, with the GLV endomorphism.+     *+     * The idea there is to interpret the bits of a scalar as signs (1 = +, 0 = -), and compute a+     * point multiplication in that fashion. Let v be an n-bit non-negative integer (0 <= v < 2^n),+     * and v[i] its i'th bit (so v = sum(v[i] * 2^i, i=0..n-1)). Then define:+     *+     *   C_l(v, A) = sum((2*v[i] - 1) * 2^i*A, i=0..l-1)+     *+     * Then it holds that C_l(v, A) = sum((2*v[i] - 1) * 2^i*A, i=0..l-1)+     *                              = (2*sum(v[i] * 2^i, i=0..l-1) + 1 - 2^l) * A+     *                              = (2*v + 1 - 2^l) * A+     *+     * Thus, one can compute q*A as C_256((q + 2^256 - 1) / 2, A). This is the basis for the+     * paper's signed-digit multi-comb algorithm for multiplication using a precomputed table.+     *+     * It is appealing to try to combine this with the GLV optimization: the idea that a scalar+     * s can be written as s1 + lambda*s2, where lambda is a curve-specific constant such that+     * lambda*A is easy to compute, and where s1 and s2 are small. In particular we have the+     * secp256k1_scalar_split_lambda function which performs such a split with the resulting s1+     * and s2 in range (-2^128, 2^128) mod n. This does work, but is uninteresting:+     *+     *   To compute q*A:+     *   - Let s1, s2 = split_lambda(q)+     *   - Let R1 = C_256((s1 + 2^256 - 1) / 2, A)+     *   - Let R2 = C_256((s2 + 2^256 - 1) / 2, lambda*A)+     *   - Return R1 + R2+     *+     * The issue is that while s1 and s2 are small-range numbers, (s1 + 2^256 - 1) / 2 (mod n)+     * and (s2 + 2^256 - 1) / 2 (mod n) are not, undoing the benefit of the splitting.+     *+     * To make it work, we want to modify the input scalar q first, before splitting, and then only+     * add a 2^128 offset of the split results (so that they end up in the single 129-bit range+     * [0,2^129]). A slightly smaller offset would work due to the bounds on the split, but we pick+     * 2^128 for simplicity. Let s be the scalar fed to split_lambda, and f(q) the function to+     * compute it from q:+     *+     *   To compute q*A:+     *   - Compute s = f(q)+     *   - Let s1, s2 = split_lambda(s)+     *   - Let v1 = s1 + 2^128 (mod n)+     *   - Let v2 = s2 + 2^128 (mod n)+     *   - Let R1 = C_l(v1, A)+     *   - Let R2 = C_l(v2, lambda*A)+     *   - Return R1 + R2+     *+     * l will thus need to be at least 129, but we may overshoot by a few bits (see+     * further), so keep it as a variable.+     *+     * To solve for s, we reason:+     *     q*A  = R1 + R2+     * <=> q*A  = C_l(s1 + 2^128, A) + C_l(s2 + 2^128, lambda*A)+     * <=> q*A  = (2*(s1 + 2^128) + 1 - 2^l) * A + (2*(s2 + 2^128) + 1 - 2^l) * lambda*A+     * <=> q*A  = (2*(s1 + s2*lambda) + (2^129 + 1 - 2^l) * (1 + lambda)) * A+     * <=> q    = 2*(s1 + s2*lambda) + (2^129 + 1 - 2^l) * (1 + lambda) (mod n)+     * <=> q    = 2*s + (2^129 + 1 - 2^l) * (1 + lambda) (mod n)+     * <=> s    = (q + (2^l - 2^129 - 1) * (1 + lambda)) / 2 (mod n)+     * <=> f(q) = (q + K) / 2 (mod n)+     *            where K = (2^l - 2^129 - 1)*(1 + lambda) (mod n)+     *+     * We will process the computation of C_l(v1, A) and C_l(v2, lambda*A) in groups of+     * ECMULT_CONST_GROUP_SIZE, so we set l to the smallest multiple of ECMULT_CONST_GROUP_SIZE+     * that is not less than 129; this equals ECMULT_CONST_BITS.+     */++    /* The offset to add to s1 and s2 to make them non-negative. Equal to 2^128. */+    static const secp256k1_scalar S_OFFSET = SECP256K1_SCALAR_CONST(0, 0, 0, 1, 0, 0, 0, 0);+    secp256k1_scalar s, v1, v2;+    secp256k1_ge pre_a[ECMULT_CONST_TABLE_SIZE];+    secp256k1_ge pre_a_lam[ECMULT_CONST_TABLE_SIZE];+    secp256k1_fe global_z;+    int group, i;++    /* We're allowed to be non-constant time in the point, and the code below (in particular,+     * secp256k1_ecmult_const_odd_multiples_table_globalz) cannot deal with infinity in a+     * constant-time manner anyway. */+    if (secp256k1_ge_is_infinity(a)) {+        secp256k1_gej_set_infinity(r);+        return;+    }++    /* Compute v1 and v2. */+    secp256k1_scalar_add(&s, q, &secp256k1_ecmult_const_K);+    secp256k1_scalar_half(&s, &s);+    secp256k1_scalar_split_lambda(&v1, &v2, &s);+    secp256k1_scalar_add(&v1, &v1, &S_OFFSET);+    secp256k1_scalar_add(&v2, &v2, &S_OFFSET);++#ifdef VERIFY+    /* Verify that v1 and v2 are in range [0, 2^129-1]. */+    for (i = 129; i < 256; ++i) {+        VERIFY_CHECK(secp256k1_scalar_get_bits_limb32(&v1, i, 1) == 0);+        VERIFY_CHECK(secp256k1_scalar_get_bits_limb32(&v2, i, 1) == 0);+    }+#endif++    /* Calculate odd multiples of A and A*lambda.+     * All multiples are brought to the same Z 'denominator', which is stored+     * in global_z. Due to secp256k1' isomorphism we can do all operations pretending+     * that the Z coordinate was 1, use affine addition formulae, and correct+     * the Z coordinate of the result once at the end.+     */+    secp256k1_gej_set_ge(r, a);+    secp256k1_ecmult_const_odd_multiples_table_globalz(pre_a, &global_z, r);+    for (i = 0; i < ECMULT_CONST_TABLE_SIZE; i++) {+        secp256k1_ge_mul_lambda(&pre_a_lam[i], &pre_a[i]);+    }++    /* Next, we compute r = C_l(v1, A) + C_l(v2, lambda*A).+     *+     * We proceed in groups of ECMULT_CONST_GROUP_SIZE bits, operating on that many bits+     * at a time, from high in v1, v2 to low. Call these bits1 (from v1) and bits2 (from v2).+     *+     * Now note that ECMULT_CONST_TABLE_GET_GE(&t, pre_a, bits1) loads into t a point equal+     * to C_{ECMULT_CONST_GROUP_SIZE}(bits1, A), and analogously for pre_lam_a / bits2.+     * This means that all we need to do is add these looked up values together, multiplied+     * by 2^(ECMULT_GROUP_SIZE * group).+     */+    for (group = ECMULT_CONST_GROUPS - 1; group >= 0; --group) {+        /* Using the _var get_bits function is ok here, since it's only variable in offset and count, not in the scalar. */+        unsigned int bits1 = secp256k1_scalar_get_bits_var(&v1, group * ECMULT_CONST_GROUP_SIZE, ECMULT_CONST_GROUP_SIZE);+        unsigned int bits2 = secp256k1_scalar_get_bits_var(&v2, group * ECMULT_CONST_GROUP_SIZE, ECMULT_CONST_GROUP_SIZE);+        secp256k1_ge t;+        int j;++        ECMULT_CONST_TABLE_GET_GE(&t, pre_a, bits1);+        if (group == ECMULT_CONST_GROUPS - 1) {+            /* Directly set r in the first iteration. */+            secp256k1_gej_set_ge(r, &t);+        } else {+            /* Shift the result so far up. */+            for (j = 0; j < ECMULT_CONST_GROUP_SIZE; ++j) {+                secp256k1_gej_double(r, r);+            }+            secp256k1_gej_add_ge(r, r, &t);+        }+        ECMULT_CONST_TABLE_GET_GE(&t, pre_a_lam, bits2);+        secp256k1_gej_add_ge(r, r, &t);+    }++    /* Map the result back to the secp256k1 curve from the isomorphic curve. */+    secp256k1_fe_mul(&r->z, &r->z, &global_z);+}++static int secp256k1_ecmult_const_xonly(secp256k1_fe* r, const secp256k1_fe *n, const secp256k1_fe *d, const secp256k1_scalar *q, int known_on_curve) {++    /* This algorithm is a generalization of Peter Dettman's technique for+     * avoiding the square root in a random-basepoint x-only multiplication+     * on a Weierstrass curve:+     * https://mailarchive.ietf.org/arch/msg/cfrg/7DyYY6gg32wDgHAhgSb6XxMDlJA/+     *+     *+     * === Background: the effective affine technique ===+     *+     * Let phi_u be the isomorphism that maps (x, y) on secp256k1 curve y^2 = x^3 + 7 to+     * x' = u^2*x, y' = u^3*y on curve y'^2 = x'^3 + u^6*7. This new curve has the same order as+     * the original (it is isomorphic), but moreover, has the same addition/doubling formulas, as+     * the curve b=7 coefficient does not appear in those formulas (or at least does not appear in+     * the formulas implemented in this codebase, both affine and Jacobian). See also Example 9.5.2+     * in https://www.math.auckland.ac.nz/~sgal018/crypto-book/ch9.pdf.+     *+     * This means any linear combination of secp256k1 points can be computed by applying phi_u+     * (with non-zero u) on all input points (including the generator, if used), computing the+     * linear combination on the isomorphic curve (using the same group laws), and then applying+     * phi_u^{-1} to get back to secp256k1.+     *+     * Switching to Jacobian coordinates, note that phi_u applied to (X, Y, Z) is simply+     * (X, Y, Z/u). Thus, if we want to compute (X1, Y1, Z) + (X2, Y2, Z), with identical Z+     * coordinates, we can use phi_Z to transform it to (X1, Y1, 1) + (X2, Y2, 1) on an isomorphic+     * curve where the affine addition formula can be used instead.+     * If (X3, Y3, Z3) = (X1, Y1) + (X2, Y2) on that curve, then our answer on secp256k1 is+     * (X3, Y3, Z3*Z).+     *+     * This is the effective affine technique: if we have a linear combination of group elements+     * to compute, and all those group elements have the same Z coordinate, we can simply pretend+     * that all those Z coordinates are 1, perform the computation that way, and then multiply the+     * original Z coordinate back in.+     *+     * The technique works on any a=0 short Weierstrass curve. It is possible to generalize it to+     * other curves too, but there the isomorphic curves will have different 'a' coefficients,+     * which typically does affect the group laws.+     *+     *+     * === Avoiding the square root for x-only point multiplication ===+     *+     * In this function, we want to compute the X coordinate of q*(n/d, y), for+     * y = sqrt((n/d)^3 + 7). Its negation would also be a valid Y coordinate, but by convention+     * we pick whatever sqrt returns (which we assume to be a deterministic function).+     *+     * Let g = y^2*d^3 = n^3 + 7*d^3. This also means y = sqrt(g/d^3).+     * Further let v = sqrt(d*g), which must exist as d*g = y^2*d^4 = (y*d^2)^2.+     *+     * The input point (n/d, y) also has Jacobian coordinates:+     *+     *     (n/d, y, 1)+     *   = (n/d * v^2, y * v^3, v)+     *   = (n/d * d*g, y * sqrt(d^3*g^3), v)+     *   = (n/d * d*g, sqrt(y^2 * d^3*g^3), v)+     *   = (n*g, sqrt(g/d^3 * d^3*g^3), v)+     *   = (n*g, sqrt(g^4), v)+     *   = (n*g, g^2, v)+     *+     * It is easy to verify that both (n*g, g^2, v) and its negation (n*g, -g^2, v) have affine X+     * coordinate n/d, and this holds even when the square root function doesn't have a+     * deterministic sign. We choose the (n*g, g^2, v) version.+     *+     * Now switch to the effective affine curve using phi_v, where the input point has coordinates+     * (n*g, g^2). Compute (X, Y, Z) = q * (n*g, g^2) there.+     *+     * Back on secp256k1, that means q * (n*g, g^2, v) = (X, Y, v*Z). This last point has affine X+     * coordinate X / (v^2*Z^2) = X / (d*g*Z^2). Determining the affine Y coordinate would involve+     * a square root, but as long as we only care about the resulting X coordinate, no square root+     * is needed anywhere in this computation.+     */++    secp256k1_fe g, i;+    secp256k1_ge p;+    secp256k1_gej rj;++    /* Compute g = (n^3 + B*d^3). */+    secp256k1_fe_sqr(&g, n);+    secp256k1_fe_mul(&g, &g, n);+    if (d) {+        secp256k1_fe b;+        VERIFY_CHECK(!secp256k1_fe_normalizes_to_zero(d));+        secp256k1_fe_sqr(&b, d);+        VERIFY_CHECK(SECP256K1_B <= 8); /* magnitude of b will be <= 8 after the next call */+        secp256k1_fe_mul_int(&b, SECP256K1_B);+        secp256k1_fe_mul(&b, &b, d);+        secp256k1_fe_add(&g, &b);+        if (!known_on_curve) {+            /* We need to determine whether (n/d)^3 + 7 is square.+             *+             *     is_square((n/d)^3 + 7)+             * <=> is_square(((n/d)^3 + 7) * d^4)+             * <=> is_square((n^3 + 7*d^3) * d)+             * <=> is_square(g * d)+             */+            secp256k1_fe c;+            secp256k1_fe_mul(&c, &g, d);+            if (!secp256k1_fe_is_square_var(&c)) return 0;+        }+    } else {+        secp256k1_fe_add_int(&g, SECP256K1_B);+        if (!known_on_curve) {+            /* g at this point equals x^3 + 7. Test if it is square. */+            if (!secp256k1_fe_is_square_var(&g)) return 0;+        }+    }++    /* Compute base point P = (n*g, g^2), the effective affine version of (n*g, g^2, v), which has+     * corresponding affine X coordinate n/d. */+    secp256k1_fe_mul(&p.x, &g, n);+    secp256k1_fe_sqr(&p.y, &g);+    p.infinity = 0;++    /* Perform x-only EC multiplication of P with q. */+    VERIFY_CHECK(!secp256k1_scalar_is_zero(q));+    secp256k1_ecmult_const(&rj, &p, q);+    VERIFY_CHECK(!secp256k1_gej_is_infinity(&rj));++    /* The resulting (X, Y, Z) point on the effective-affine isomorphic curve corresponds to+     * (X, Y, Z*v) on the secp256k1 curve. The affine version of that has X coordinate+     * (X / (Z^2*d*g)). */+    secp256k1_fe_sqr(&i, &rj.z);+    secp256k1_fe_mul(&i, &i, &g);+    if (d) secp256k1_fe_mul(&i, &i, d);+    secp256k1_fe_inv(&i, &i);+    secp256k1_fe_mul(r, &rj.x, &i);++    return 1;+}++#endif /* SECP256K1_ECMULT_CONST_IMPL_H */
+ vendor/external/secp256k1/src/ecmult_gen.h view
@@ -0,0 +1,143 @@+/***********************************************************************+ * Copyright (c) Pieter Wuille, Peter Dettman                          *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECMULT_GEN_H+#define SECP256K1_ECMULT_GEN_H++#include "scalar.h"+#include "group.h"+++/* Configuration parameters for the signed-digit multi-comb algorithm:+ *+ * - COMB_BLOCKS is the number of blocks the input is split into. Each+ *   has a corresponding table.+ * - COMB_TEETH is the number of bits simultaneously covered by one table.+ * - COMB_RANGE is the number of bits in supported scalars. For production+ *   purposes, only 256 is reasonable, but smaller numbers are supported for+ *   exhaustive test mode.+ *+ * The comb's spacing (COMB_SPACING), or the distance between the teeth,+ * is defined as ceil(COMB_RANGE / (COMB_BLOCKS * COMB_TEETH)). Each block covers+ * COMB_SPACING * COMB_TEETH consecutive bits in the input.+ *+ * The size of the precomputed table is COMB_BLOCKS * (1 << (COMB_TEETH - 1))+ * secp256k1_ge_storages.+ *+ * The number of point additions equals COMB_BLOCKS * COMB_SPACING. Each point+ * addition involves a cmov from (1 << (COMB_TEETH - 1)) table entries and a+ * conditional negation.+ *+ * The number of point doublings is COMB_SPACING - 1. */++#if defined(EXHAUSTIVE_TEST_ORDER)+/* We need to control these values for exhaustive tests because+ * the table cannot have infinities in them (secp256k1_ge_storage+ * doesn't support infinities) */+#  undef COMB_BLOCKS+#  undef COMB_TEETH+#  if EXHAUSTIVE_TEST_ORDER == 7+#    define COMB_RANGE 3+#    define COMB_BLOCKS 1+#    define COMB_TEETH 2+#  elif EXHAUSTIVE_TEST_ORDER == 13+#    define COMB_RANGE 4+#    define COMB_BLOCKS 1+#    define COMB_TEETH 2+#  elif EXHAUSTIVE_TEST_ORDER == 199+#    define COMB_RANGE 8+#    define COMB_BLOCKS 2+#    define COMB_TEETH 3+#  else+#    error "Unknown exhaustive test order"+#  endif+#  if (COMB_RANGE >= 32) || ((EXHAUSTIVE_TEST_ORDER >> (COMB_RANGE - 1)) != 1)+#    error "COMB_RANGE != ceil(log2(EXHAUSTIVE_TEST_ORDER+1))"+#  endif+#else /* !defined(EXHAUSTIVE_TEST_ORDER) */+#  define COMB_RANGE 256+#endif /* defined(EXHAUSTIVE_TEST_ORDER) */++/* Use (11, 6) as default configuration, which results in a 22 kB table. */+#ifndef COMB_BLOCKS+#  define COMB_BLOCKS 11+#  ifdef DEBUG_CONFIG+#    pragma message DEBUG_CONFIG_MSG("COMB_BLOCKS undefined, assuming default value")+#  endif+#endif+#ifndef COMB_TEETH+#  define COMB_TEETH 6+#  ifdef DEBUG_CONFIG+#    pragma message DEBUG_CONFIG_MSG("COMB_TEETH undefined, assuming default value")+#  endif+#endif+/* Use ceil(COMB_RANGE / (COMB_BLOCKS * COMB_TEETH)) as COMB_SPACING. */+#define COMB_SPACING CEIL_DIV(COMB_RANGE, COMB_BLOCKS * COMB_TEETH)++/* Range checks on the parameters. */++/* The remaining COMB_* parameters are derived values, don't modify these. */+/* - The number of bits covered by all the blocks; must be at least COMB_RANGE. */+#define COMB_BITS (COMB_BLOCKS * COMB_TEETH * COMB_SPACING)+/* - The number of entries per table. */+#define COMB_POINTS (1 << (COMB_TEETH - 1))++/* Sanity checks. */+#if !(1 <= COMB_BLOCKS && COMB_BLOCKS <= 256)+#  error "COMB_BLOCKS must be in the range [1, 256]"+#endif+#if !(1 <= COMB_TEETH && COMB_TEETH <= 8)+#  error "COMB_TEETH must be in the range [1, 8]"+#endif+#if COMB_BITS < COMB_RANGE+#  error "COMB_BLOCKS * COMB_TEETH * COMB_SPACING is too low"+#endif++/* These last 2 checks are not strictly required, but prevent gratuitously inefficient+ * configurations. Note that they compare with 256 rather than COMB_RANGE, so they do+ * permit somewhat excessive values for the exhaustive test case, where testing with+ * suboptimal parameters may be desirable. */+#if (COMB_BLOCKS - 1) * COMB_TEETH * COMB_SPACING >= 256+#  error "COMB_BLOCKS can be reduced"+#endif+#if COMB_BLOCKS * (COMB_TEETH - 1) * COMB_SPACING >= 256+#  error "COMB_TEETH can be reduced"+#endif++#ifdef DEBUG_CONFIG+#  pragma message DEBUG_CONFIG_DEF(COMB_RANGE)+#  pragma message DEBUG_CONFIG_DEF(COMB_BLOCKS)+#  pragma message DEBUG_CONFIG_DEF(COMB_TEETH)+#  pragma message DEBUG_CONFIG_DEF(COMB_SPACING)+#endif++typedef struct {+    /* Whether the context has been built. */+    int built;++    /* Values chosen such that+     *+     *   n*G == comb(n + scalar_offset, G/2) + ge_offset.+     *+     * This expression lets us use scalar blinding and optimize the comb precomputation. See+     * ecmult_gen_impl.h for more details. */+    secp256k1_scalar scalar_offset;+    secp256k1_ge ge_offset;++    /* Factor used for projective blinding. This value is used to rescale the Z+     * coordinate of the first table lookup. */+    secp256k1_fe proj_blind;+} secp256k1_ecmult_gen_context;++static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx);+static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context* ctx);++/** Multiply with the generator: R = a*G */+static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context* ctx, secp256k1_gej *r, const secp256k1_scalar *a);++static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const unsigned char *seed32);++#endif /* SECP256K1_ECMULT_GEN_H */
+ vendor/external/secp256k1/src/ecmult_gen_compute_table.h view
@@ -0,0 +1,14 @@+/***********************************************************************+ * Copyright (c) Pieter Wuille, Gregory Maxwell                        *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H+#define SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H++#include "ecmult_gen.h"++static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, const secp256k1_ge* gen, int blocks, int teeth, int spacing);++#endif /* SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H */
+ vendor/external/secp256k1/src/ecmult_gen_compute_table_impl.h view
@@ -0,0 +1,108 @@+/***********************************************************************+ * Copyright (c) Pieter Wuille, Gregory Maxwell, Peter Dettman         *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECMULT_GEN_COMPUTE_TABLE_IMPL_H+#define SECP256K1_ECMULT_GEN_COMPUTE_TABLE_IMPL_H++#include "ecmult_gen_compute_table.h"+#include "group_impl.h"+#include "field_impl.h"+#include "scalar_impl.h"+#include "ecmult_gen.h"+#include "util.h"++static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, const secp256k1_ge* gen, int blocks, int teeth, int spacing) {+    size_t points = ((size_t)1) << (teeth - 1);+    size_t points_total = points * blocks;+    secp256k1_ge* prec = checked_malloc(&default_error_callback, points_total * sizeof(*prec));+    secp256k1_gej* ds = checked_malloc(&default_error_callback, teeth * sizeof(*ds));+    secp256k1_gej* vs = checked_malloc(&default_error_callback, points_total * sizeof(*vs));+    secp256k1_gej u;+    size_t vs_pos = 0;+    secp256k1_scalar half;+    int block, i;++    VERIFY_CHECK(points_total > 0);++    /* u is the running power of two times gen we're working with, initially gen/2. */+    secp256k1_scalar_half(&half, &secp256k1_scalar_one);+    secp256k1_gej_set_infinity(&u);+    for (i = 255; i >= 0; --i) {+        /* Use a very simple multiplication ladder to avoid dependency on ecmult. */+        secp256k1_gej_double_var(&u, &u, NULL);+        if (secp256k1_scalar_get_bits_limb32(&half, i, 1)) {+            secp256k1_gej_add_ge_var(&u, &u, gen, NULL);+        }+    }+#ifdef VERIFY+    {+        /* Verify that u*2 = gen. */+        secp256k1_gej double_u;+        secp256k1_gej_double_var(&double_u, &u, NULL);+        VERIFY_CHECK(secp256k1_gej_eq_ge_var(&double_u, gen));+    }+#endif++    for (block = 0; block < blocks; ++block) {+        int tooth;+        /* Here u = 2^(block*teeth*spacing) * gen/2. */+        secp256k1_gej sum;+        secp256k1_gej_set_infinity(&sum);+        for (tooth = 0; tooth < teeth; ++tooth) {+            /* Here u = 2^((block*teeth + tooth)*spacing) * gen/2. */+            /* Make sum = sum(2^((block*teeth + t)*spacing), t=0..tooth) * gen/2. */+            secp256k1_gej_add_var(&sum, &sum, &u, NULL);+            /* Make u = 2^((block*teeth + tooth)*spacing + 1) * gen/2. */+            secp256k1_gej_double_var(&u, &u, NULL);+            /* Make ds[tooth] = u = 2^((block*teeth + tooth)*spacing + 1) * gen/2. */+            ds[tooth] = u;+            /* Make u = 2^((block*teeth + tooth + 1)*spacing) * gen/2, unless at the end. */+            if (block + tooth != blocks + teeth - 2) {+                int bit_off;+                for (bit_off = 1; bit_off < spacing; ++bit_off) {+                    secp256k1_gej_double_var(&u, &u, NULL);+                }+            }+        }+        /* Now u = 2^((block*teeth + teeth)*spacing) * gen/2+         *       = 2^((block+1)*teeth*spacing) * gen/2       */++        /* Next, compute the table entries for block number block in Jacobian coordinates.+         * The entries will occupy vs[block*points + i] for i=0..points-1.+         * We start by computing the first (i=0) value corresponding to all summed+         * powers of two times G being negative. */+        secp256k1_gej_neg(&vs[vs_pos++], &sum);+        /* And then teeth-1 times "double" the range of i values for which the table+         * is computed: in each iteration, double the table by taking an existing+         * table entry and adding ds[tooth]. */+        for (tooth = 0; tooth < teeth - 1; ++tooth) {+            size_t stride = ((size_t)1) << tooth;+            size_t index;+            for (index = 0; index < stride; ++index, ++vs_pos) {+                secp256k1_gej_add_var(&vs[vs_pos], &vs[vs_pos - stride], &ds[tooth], NULL);+            }+        }+    }+    VERIFY_CHECK(vs_pos == points_total);++    /* Convert all points simultaneously from secp256k1_gej to secp256k1_ge. */+    secp256k1_ge_set_all_gej_var(prec, vs, points_total);+    /* Convert all points from secp256k1_ge to secp256k1_ge_storage output. */+    for (block = 0; block < blocks; ++block) {+        size_t index;+        for (index = 0; index < points; ++index) {+            VERIFY_CHECK(!secp256k1_ge_is_infinity(&prec[block * points + index]));+            secp256k1_ge_to_storage(&table[block * points + index], &prec[block * points + index]);+        }+    }++    /* Free memory. */+    free(vs);+    free(ds);+    free(prec);+}++#endif /* SECP256K1_ECMULT_GEN_COMPUTE_TABLE_IMPL_H */
+ vendor/external/secp256k1/src/ecmult_gen_impl.h view
@@ -0,0 +1,341 @@+/***********************************************************************+ * Copyright (c) Pieter Wuille, Gregory Maxwell, Peter Dettman         *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_ECMULT_GEN_IMPL_H+#define SECP256K1_ECMULT_GEN_IMPL_H++#include "util.h"+#include "scalar.h"+#include "group.h"+#include "ecmult_gen.h"+#include "hash_impl.h"+#include "precomputed_ecmult_gen.h"++static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ctx) {+    secp256k1_ecmult_gen_blind(ctx, NULL);+    ctx->built = 1;+}++static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context* ctx) {+    return ctx->built;+}++static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx) {+    ctx->built = 0;+    secp256k1_scalar_clear(&ctx->scalar_offset);+    secp256k1_ge_clear(&ctx->ge_offset);+    secp256k1_fe_clear(&ctx->proj_blind);+}++/* Compute the scalar (2^COMB_BITS - 1) / 2, the difference between the gn argument to+ * secp256k1_ecmult_gen, and the scalar whose encoding the table lookup bits are drawn+ * from (before applying blinding). */+static void secp256k1_ecmult_gen_scalar_diff(secp256k1_scalar* diff) {+    int i;++    /* Compute scalar -1/2. */+    secp256k1_scalar neghalf;+    secp256k1_scalar_half(&neghalf, &secp256k1_scalar_one);+    secp256k1_scalar_negate(&neghalf, &neghalf);++    /* Compute offset = 2^(COMB_BITS - 1). */+    *diff = secp256k1_scalar_one;+    for (i = 0; i < COMB_BITS - 1; ++i) {+        secp256k1_scalar_add(diff, diff, diff);+    }++    /* The result is the sum 2^(COMB_BITS - 1) + (-1/2). */+    secp256k1_scalar_add(diff, diff, &neghalf);+}++static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp256k1_gej *r, const secp256k1_scalar *gn) {+    uint32_t comb_off;+    secp256k1_ge add;+    secp256k1_fe neg;+    secp256k1_ge_storage adds;+    secp256k1_scalar d;+    /* Array of uint32_t values large enough to store COMB_BITS bits. Only the bottom+     * 8 are ever nonzero, but having the zero padding at the end if COMB_BITS>256+     * avoids the need to deal with out-of-bounds reads from a scalar. */+    uint32_t recoded[(COMB_BITS + 31) >> 5] = {0};+    int first = 1, i;++    memset(&adds, 0, sizeof(adds));++    /* We want to compute R = gn*G.+     *+     * To blind the scalar used in the computation, we rewrite this to be+     * R = (gn - b)*G + b*G, with a blinding value b determined by the context.+     *+     * The multiplication (gn-b)*G will be performed using a signed-digit multi-comb (see Section+     * 3.3 of "Fast and compact elliptic-curve cryptography" by Mike Hamburg,+     * https://eprint.iacr.org/2012/309).+     *+     * Let comb(s, P) = sum((2*s[i]-1)*2^i*P for i=0..COMB_BITS-1), where s[i] is the i'th bit of+     * the binary representation of scalar s. So the s[i] values determine whether -2^i*P (s[i]=0)+     * or +2^i*P (s[i]=1) are added together. COMB_BITS is at least 256, so all bits of s are+     * covered. By manipulating:+     *+     *     comb(s, P) = sum((2*s[i]-1)*2^i*P for i=0..COMB_BITS-1)+     * <=> comb(s, P) = sum((2*s[i]-1)*2^i for i=0..COMB_BITS-1) * P+     * <=> comb(s, P) = (2*sum(s[i]*2^i for i=0..COMB_BITS-1) - sum(2^i for i=0..COMB_BITS-1)) * P+     * <=> comb(s, P) = (2*s - (2^COMB_BITS - 1)) * P+     *+     * If we wanted to compute (gn-b)*G as comb(s, G), it would need to hold that+     *+     *     (gn - b) * G = (2*s - (2^COMB_BITS - 1)) * G+     * <=> s = (gn - b + (2^COMB_BITS - 1))/2 (mod order)+     *+     * We use an alternative here that avoids the modular division by two: instead we compute+     * (gn-b)*G as comb(d, G/2). For that to hold it must be the case that+     *+     *     (gn - b) * G = (2*d - (2^COMB_BITS - 1)) * (G/2)+     * <=> d = gn - b + (2^COMB_BITS - 1)/2 (mod order)+     *+     * Adding precomputation, our final equations become:+     *+     *     ctx->scalar_offset = (2^COMB_BITS - 1)/2 - b (mod order)+     *     ctx->ge_offset = b*G+     *     d = gn + ctx->scalar_offset (mod order)+     *     R = comb(d, G/2) + ctx->ge_offset+     *+     * comb(d, G/2) function is then computed by summing + or - 2^(i-1)*G, for i=0..COMB_BITS-1,+     * depending on the value of the bits d[i] of the binary representation of scalar d.+     */++    /* Compute the scalar d = (gn + ctx->scalar_offset). */+    secp256k1_scalar_add(&d, &ctx->scalar_offset, gn);+    /* Convert to recoded array. */+    for (i = 0; i < 8 && i < ((COMB_BITS + 31) >> 5); ++i) {+        recoded[i] = secp256k1_scalar_get_bits_limb32(&d, 32 * i, 32);+    }+    secp256k1_scalar_clear(&d);++    /* In secp256k1_ecmult_gen_prec_table we have precomputed sums of the+     * (2*d[i]-1) * 2^(i-1) * G points, for various combinations of i positions.+     * We rewrite our equation in terms of these table entries.+     *+     * Let mask(b) = sum(2^((b*COMB_TEETH + t)*COMB_SPACING) for t=0..COMB_TEETH-1),+     * with b ranging from 0 to COMB_BLOCKS-1. So for example with COMB_BLOCKS=11,+     * COMB_TEETH=6, COMB_SPACING=4, we would have:+     *   mask(0)  = 2^0   + 2^4   + 2^8   + 2^12  + 2^16  + 2^20,+     *   mask(1)  = 2^24  + 2^28  + 2^32  + 2^36  + 2^40  + 2^44,+     *   mask(2)  = 2^48  + 2^52  + 2^56  + 2^60  + 2^64  + 2^68,+     *   ...+     *   mask(10) = 2^240 + 2^244 + 2^248 + 2^252 + 2^256 + 2^260+     *+     * We will split up the bits d[i] using these masks. Specifically, each mask is+     * used COMB_SPACING times, with different shifts:+     *+     * d = (d & mask(0)<<0) + (d & mask(1)<<0) + ... + (d & mask(COMB_BLOCKS-1)<<0) ++     *     (d & mask(0)<<1) + (d & mask(1)<<1) + ... + (d & mask(COMB_BLOCKS-1)<<1) ++     *     ...+     *     (d & mask(0)<<(COMB_SPACING-1)) + ...+     *+     * Now define table(b, m) = (m - mask(b)/2) * G, and we will precompute these values for+     * b=0..COMB_BLOCKS-1, and for all values m which (d & mask(b)) can take (so m can take on+     * 2^COMB_TEETH distinct values).+     *+     * If m=(d & mask(b)), then table(b, m) is the sum of 2^i * (2*d[i]-1) * G/2, with i+     * iterating over the set bits in mask(b). In our example, table(2, 2^48 + 2^56 + 2^68)+     * would equal (2^48 - 2^52 + 2^56 - 2^60 - 2^64 + 2^68) * G/2.+     *+     * With that, we can rewrite comb(d, G/2) as:+     *+     *     2^0 * (table(0, d>>0 & mask(0)) + ... + table(COMB_BLOCKS-1, d>>0 & mask(COMP_BLOCKS-1)))+     *   + 2^1 * (table(0, d>>1 & mask(0)) + ... + table(COMB_BLOCKS-1, d>>1 & mask(COMP_BLOCKS-1)))+     *   + 2^2 * (table(0, d>>2 & mask(0)) + ... + table(COMB_BLOCKS-1, d>>2 & mask(COMP_BLOCKS-1)))+     *   + ...+     *   + 2^(COMB_SPACING-1) * (table(0, d>>(COMB_SPACING-1) & mask(0)) + ...)+     *+     * Or more generically as+     *+     *   sum(2^i * sum(table(b, d>>i & mask(b)), b=0..COMB_BLOCKS-1), i=0..COMB_SPACING-1)+     *+     * This is implemented using an outer loop that runs in reverse order over the lines of this+     * equation, which in each iteration runs an inner loop that adds the terms of that line and+     * then doubles the result before proceeding to the next line.+     *+     * In pseudocode:+     *   c = infinity+     *   for comb_off in range(COMB_SPACING - 1, -1, -1):+     *     for block in range(COMB_BLOCKS):+     *       c += table(block, (d >> comb_off) & mask(block))+     *     if comb_off > 0:+     *       c = 2*c+     *   return c+     *+     * This computes c = comb(d, G/2), and thus finally R = c + ctx->ge_offset. Note that it would+     * be possible to apply an initial offset instead of a final offset (moving ge_offset to take+     * the place of infinity above), but the chosen approach allows using (in a future improvement)+     * an incomplete addition formula for most of the multiplication.+     *+     * The last question is how to implement the table(b, m) function. For any value of b,+     * m=(d & mask(b)) can only take on at most 2^COMB_TEETH possible values (the last one may have+     * fewer as there mask(b) may exceed the curve order). So we could create COMB_BLOCK tables+     * which contain a value for each such m value.+     *+     * Now note that if m=(d & mask(b)), then flipping the relevant bits of m results in negating+     * the result of table(b, m). This is because table(b,m XOR mask(b)) = table(b, mask(b) - m) =+     * (mask(b) - m - mask(b)/2)*G = (-m + mask(b)/2)*G = -(m - mask(b)/2)*G = -table(b, m).+     * Because of this it suffices to only store the first half of the m values for every b. If an+     * entry from the second half is needed, we look up its bit-flipped version instead, and negate+     * it.+     *+     * secp256k1_ecmult_gen_prec_table[b][index] stores the table(b, m) entries. Index+     * is the relevant mask(b) bits of m packed together without gaps. */++    /* Outer loop: iterate over comb_off from COMB_SPACING - 1 down to 0. */+    comb_off = COMB_SPACING - 1;+    while (1) {+        uint32_t block;+        uint32_t bit_pos = comb_off;+        /* Inner loop: for each block, add table entries to the result. */+        for (block = 0; block < COMB_BLOCKS; ++block) {+            /* Gather the mask(block)-selected bits of d into bits. They're packed:+             * bits[tooth] = d[(block*COMB_TEETH + tooth)*COMB_SPACING + comb_off]. */+            uint32_t bits = 0, sign, abs, index, tooth;+            /* Instead of reading individual bits here to construct the bits variable,+             * build up the result by xoring rotated reads together. In every iteration,+             * one additional bit is made correct, starting at the bottom. The bits+             * above that contain junk. This reduces leakage by avoiding computations+             * on variables that can have only a low number of possible values (e.g.,+             * just two values when reading a single bit into a variable.) See:+             * https://www.usenix.org/system/files/conference/usenixsecurity18/sec18-alam.pdf+             */+            for (tooth = 0; tooth < COMB_TEETH; ++tooth) {+                /* Construct bitdata s.t. the bottom bit is the bit we'd like to read.+                 *+                 * We could just set bitdata = recoded[bit_pos >> 5] >> (bit_pos & 0x1f)+                 * but this would simply discard the bits that fall off at the bottom,+                 * and thus, for example, bitdata could still have only two values if we+                 * happen to shift by exactly 31 positions. We use a rotation instead,+                 * which ensures that bitdata doesn't loose entropy. This relies on the+                 * rotation being atomic, i.e., the compiler emitting an actual rot+                 * instruction. */+                uint32_t bitdata = secp256k1_rotr32(recoded[bit_pos >> 5], bit_pos & 0x1f);++                /* Clear the bit at position tooth, but sssh, don't tell clang. */+                uint32_t volatile vmask = ~(1 << tooth);+                bits &= vmask;++                /* Write the bit into position tooth (and junk into higher bits). */+                bits ^= bitdata << tooth;+                bit_pos += COMB_SPACING;+            }++            /* If the top bit of bits is 1, flip them all (corresponding to looking up+             * the negated table value), and remember to negate the result in sign. */+            sign = (bits >> (COMB_TEETH - 1)) & 1;+            abs = (bits ^ -sign) & (COMB_POINTS - 1);+            VERIFY_CHECK(sign == 0 || sign == 1);+            VERIFY_CHECK(abs < COMB_POINTS);++            /** This uses a conditional move to avoid any secret data in array indexes.+             *   _Any_ use of secret indexes has been demonstrated to result in timing+             *   sidechannels, even when the cache-line access patterns are uniform.+             *  See also:+             *   "A word of warning", CHES 2013 Rump Session, by Daniel J. Bernstein and Peter Schwabe+             *    (https://cryptojedi.org/peter/data/chesrump-20130822.pdf) and+             *   "Cache Attacks and Countermeasures: the Case of AES", RSA 2006,+             *    by Dag Arne Osvik, Adi Shamir, and Eran Tromer+             *    (https://www.tau.ac.il/~tromer/papers/cache.pdf)+             */+            for (index = 0; index < COMB_POINTS; ++index) {+                secp256k1_ge_storage_cmov(&adds, &secp256k1_ecmult_gen_prec_table[block][index], index == abs);+            }++            /* Set add=adds or add=-adds, in constant time, based on sign. */+            secp256k1_ge_from_storage(&add, &adds);+            secp256k1_fe_negate(&neg, &add.y, 1);+            secp256k1_fe_cmov(&add.y, &neg, sign);++            /* Add the looked up and conditionally negated value to r. */+            if (EXPECT(first, 0)) {+                /* If this is the first table lookup, we can skip addition. */+                secp256k1_gej_set_ge(r, &add);+                /* Give the entry a random Z coordinate to blind intermediary results. */+                secp256k1_gej_rescale(r, &ctx->proj_blind);+                first = 0;+            } else {+                secp256k1_gej_add_ge(r, r, &add);+            }+        }++        /* Double the result, except in the last iteration. */+        if (comb_off-- == 0) break;+        secp256k1_gej_double(r, r);+    }++    /* Correct for the scalar_offset added at the start (ge_offset = b*G, while b was+     * subtracted from the input scalar gn). */+    secp256k1_gej_add_ge(r, r, &ctx->ge_offset);++    /* Cleanup. */+    secp256k1_fe_clear(&neg);+    secp256k1_ge_clear(&add);+    secp256k1_memclear(&adds, sizeof(adds));+    secp256k1_memclear(&recoded, sizeof(recoded));+}++/* Setup blinding values for secp256k1_ecmult_gen. */+static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const unsigned char *seed32) {+    secp256k1_scalar b;+    secp256k1_scalar diff;+    secp256k1_gej gb;+    secp256k1_fe f;+    unsigned char nonce32[32];+    secp256k1_rfc6979_hmac_sha256 rng;+    unsigned char keydata[64];++    /* Compute the (2^COMB_BITS - 1)/2 term once. */+    secp256k1_ecmult_gen_scalar_diff(&diff);++    if (seed32 == NULL) {+        /* When seed is NULL, reset the final point and blinding value. */+        secp256k1_ge_neg(&ctx->ge_offset, &secp256k1_ge_const_g);+        secp256k1_scalar_add(&ctx->scalar_offset, &secp256k1_scalar_one, &diff);+        ctx->proj_blind = secp256k1_fe_one;+        return;+    }+    /* The prior blinding value (if not reset) is chained forward by including it in the hash. */+    secp256k1_scalar_get_b32(keydata, &ctx->scalar_offset);+    /** Using a CSPRNG allows a failure free interface, avoids needing large amounts of random data,+     *   and guards against weak or adversarial seeds.  This is a simpler and safer interface than+     *   asking the caller for blinding values directly and expecting them to retry on failure.+     */+    VERIFY_CHECK(seed32 != NULL);+    memcpy(keydata + 32, seed32, 32);+    secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, 64);+    secp256k1_memclear(keydata, sizeof(keydata));++    /* Compute projective blinding factor (cannot be 0). */+    secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);+    secp256k1_fe_set_b32_mod(&f, nonce32);+    secp256k1_fe_cmov(&f, &secp256k1_fe_one, secp256k1_fe_normalizes_to_zero(&f));+    ctx->proj_blind = f;++    /* For a random blinding value b, set scalar_offset=diff-b, ge_offset=bG */+    secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);+    secp256k1_scalar_set_b32(&b, nonce32, NULL);+    /* The blinding value cannot be zero, as that would mean ge_offset = infinity,+     * which secp256k1_gej_add_ge cannot handle. */+    secp256k1_scalar_cmov(&b, &secp256k1_scalar_one, secp256k1_scalar_is_zero(&b));+    secp256k1_rfc6979_hmac_sha256_finalize(&rng);+    secp256k1_ecmult_gen(ctx, &gb, &b);+    secp256k1_scalar_negate(&b, &b);+    secp256k1_scalar_add(&ctx->scalar_offset, &b, &diff);+    secp256k1_ge_set_gej(&ctx->ge_offset, &gb);++    /* Clean up. */+    secp256k1_memclear(nonce32, sizeof(nonce32));+    secp256k1_scalar_clear(&b);+    secp256k1_gej_clear(&gb);+    secp256k1_fe_clear(&f);+    secp256k1_rfc6979_hmac_sha256_clear(&rng);+}++#endif /* SECP256K1_ECMULT_GEN_IMPL_H */
+ vendor/external/secp256k1/src/ecmult_impl.h view
@@ -0,0 +1,853 @@+/******************************************************************************+ * Copyright (c) 2013, 2014, 2017 Pieter Wuille, Andrew Poelstra, Jonas Nick  *+ * Distributed under the MIT software license, see the accompanying           *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.       *+ ******************************************************************************/++#ifndef SECP256K1_ECMULT_IMPL_H+#define SECP256K1_ECMULT_IMPL_H++#include <string.h>+#include <stdint.h>++#include "util.h"+#include "group.h"+#include "scalar.h"+#include "ecmult.h"+#include "precomputed_ecmult.h"++#if defined(EXHAUSTIVE_TEST_ORDER)+/* We need to lower these values for exhaustive tests because+ * the tables cannot have infinities in them (this breaks the+ * affine-isomorphism stuff which tracks z-ratios) */+#  if EXHAUSTIVE_TEST_ORDER > 128+#    define WINDOW_A 5+#  elif EXHAUSTIVE_TEST_ORDER > 8+#    define WINDOW_A 4+#  else+#    define WINDOW_A 2+#  endif+#else+/* optimal for 128-bit and 256-bit exponents. */+#  define WINDOW_A 5+/** Larger values for ECMULT_WINDOW_SIZE result in possibly better+ *  performance at the cost of an exponentially larger precomputed+ *  table. The exact table size is+ *      (1 << (WINDOW_G - 2)) * sizeof(secp256k1_ge_storage)  bytes,+ *  where sizeof(secp256k1_ge_storage) is typically 64 bytes but can+ *  be larger due to platform-specific padding and alignment.+ *  Two tables of this size are used (due to the endomorphism+ *  optimization).+ */+#endif++#define WNAF_BITS 128+#define WNAF_SIZE_BITS(bits, w) CEIL_DIV(bits, w)+#define WNAF_SIZE(w) WNAF_SIZE_BITS(WNAF_BITS, w)++/* The number of objects allocated on the scratch space for ecmult_multi algorithms */+#define PIPPENGER_SCRATCH_OBJECTS 6+#define STRAUSS_SCRATCH_OBJECTS 5++#define PIPPENGER_MAX_BUCKET_WINDOW 12++/* Minimum number of points for which pippenger_wnaf is faster than strauss wnaf */+#define ECMULT_PIPPENGER_THRESHOLD 88++#define ECMULT_MAX_POINTS_PER_BATCH 5000000++/** Fill a table 'pre_a' with precomputed odd multiples of a.+ *  pre_a will contain [1*a,3*a,...,(2*n-1)*a], so it needs space for n group elements.+ *  zr needs space for n field elements.+ *+ *  Although pre_a is an array of _ge rather than _gej, it actually represents elements+ *  in Jacobian coordinates with their z coordinates omitted. The omitted z-coordinates+ *  can be recovered using z and zr. Using the notation z(b) to represent the omitted+ *  z coordinate of b:+ *  - z(pre_a[n-1]) = 'z'+ *  - z(pre_a[i-1]) = z(pre_a[i]) / zr[i] for n > i > 0+ *+ *  Lastly the zr[0] value, which isn't used above, is set so that:+ *  - a.z = z(pre_a[0]) / zr[0]+ */+static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_ge *pre_a, secp256k1_fe *zr, secp256k1_fe *z, const secp256k1_gej *a) {+    secp256k1_gej d, ai;+    secp256k1_ge d_ge;+    int i;++    VERIFY_CHECK(!a->infinity);++    secp256k1_gej_double_var(&d, a, NULL);++    /*+     * Perform the additions using an isomorphic curve Y^2 = X^3 + 7*C^6 where C := d.z.+     * The isomorphism, phi, maps a secp256k1 point (x, y) to the point (x*C^2, y*C^3) on the other curve.+     * In Jacobian coordinates phi maps (x, y, z) to (x*C^2, y*C^3, z) or, equivalently to (x, y, z/C).+     *+     *     phi(x, y, z) = (x*C^2, y*C^3, z) = (x, y, z/C)+     *   d_ge := phi(d) = (d.x, d.y, 1)+     *     ai := phi(a) = (a.x*C^2, a.y*C^3, a.z)+     *+     * The group addition functions work correctly on these isomorphic curves.+     * In particular phi(d) is easy to represent in affine coordinates under this isomorphism.+     * This lets us use the faster secp256k1_gej_add_ge_var group addition function that we wouldn't be able to use otherwise.+     */+    secp256k1_ge_set_xy(&d_ge, &d.x, &d.y);+    secp256k1_ge_set_gej_zinv(&pre_a[0], a, &d.z);+    secp256k1_gej_set_ge(&ai, &pre_a[0]);+    ai.z = a->z;++    /* pre_a[0] is the point (a.x*C^2, a.y*C^3, a.z*C) which is equivalent to a.+     * Set zr[0] to C, which is the ratio between the omitted z(pre_a[0]) value and a.z.+     */+    zr[0] = d.z;++    for (i = 1; i < n; i++) {+        secp256k1_gej_add_ge_var(&ai, &ai, &d_ge, &zr[i]);+        secp256k1_ge_set_xy(&pre_a[i], &ai.x, &ai.y);+    }++    /* Multiply the last z-coordinate by C to undo the isomorphism.+     * Since the z-coordinates of the pre_a values are implied by the zr array of z-coordinate ratios,+     * undoing the isomorphism here undoes the isomorphism for all pre_a values.+     */+    secp256k1_fe_mul(z, &ai.z, &d.z);+}++SECP256K1_INLINE static void secp256k1_ecmult_table_verify(int n, int w) {+    (void)n;+    (void)w;+    VERIFY_CHECK(((n) & 1) == 1);+    VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1));+    VERIFY_CHECK((n) <=  ((1 << ((w)-1)) - 1));+}++SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge(secp256k1_ge *r, const secp256k1_ge *pre, int n, int w) {+    secp256k1_ecmult_table_verify(n,w);+    if (n > 0) {+        *r = pre[(n-1)/2];+    } else {+        *r = pre[(-n-1)/2];+        secp256k1_fe_negate(&(r->y), &(r->y), 1);+    }+}++SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_lambda(secp256k1_ge *r, const secp256k1_ge *pre, const secp256k1_fe *x, int n, int w) {+    secp256k1_ecmult_table_verify(n,w);+    if (n > 0) {+        secp256k1_ge_set_xy(r, &x[(n-1)/2], &pre[(n-1)/2].y);+    } else {+        secp256k1_ge_set_xy(r, &x[(-n-1)/2], &pre[(-n-1)/2].y);+        secp256k1_fe_negate(&(r->y), &(r->y), 1);+    }+}++SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_storage(secp256k1_ge *r, const secp256k1_ge_storage *pre, int n, int w) {+    secp256k1_ecmult_table_verify(n,w);+    if (n > 0) {+        secp256k1_ge_from_storage(r, &pre[(n-1)/2]);+    } else {+        secp256k1_ge_from_storage(r, &pre[(-n-1)/2]);+        secp256k1_fe_negate(&(r->y), &(r->y), 1);+    }+}++/** Convert a number to WNAF notation. The number becomes represented by sum(2^i * wnaf[i], i=0..bits),+ *  with the following guarantees:+ *  - each wnaf[i] is either 0, or an odd integer between -(1<<(w-1) - 1) and (1<<(w-1) - 1)+ *  - two non-zero entries in wnaf are separated by at least w-1 zeroes.+ *  - the number of set values in wnaf is returned. This number is at most 256, and at most one more+ *    than the number of bits in the (absolute value) of the input.+ */+static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a, int w) {+    secp256k1_scalar s;+    int last_set_bit = -1;+    int bit = 0;+    int sign = 1;+    int carry = 0;++    VERIFY_CHECK(wnaf != NULL);+    VERIFY_CHECK(0 <= len && len <= 256);+    VERIFY_CHECK(a != NULL);+    VERIFY_CHECK(2 <= w && w <= 31);++    for (bit = 0; bit < len; bit++) {+        wnaf[bit] = 0;+    }++    s = *a;+    if (secp256k1_scalar_get_bits_limb32(&s, 255, 1)) {+        secp256k1_scalar_negate(&s, &s);+        sign = -1;+    }++    bit = 0;+    while (bit < len) {+        int now;+        int word;+        if (secp256k1_scalar_get_bits_limb32(&s, bit, 1) == (unsigned int)carry) {+            bit++;+            continue;+        }++        now = w;+        if (now > len - bit) {+            now = len - bit;+        }++        word = secp256k1_scalar_get_bits_var(&s, bit, now) + carry;++        carry = (word >> (w-1)) & 1;+        word -= carry << w;++        wnaf[bit] = sign * word;+        last_set_bit = bit;++        bit += now;+    }+#ifdef VERIFY+    {+        int verify_bit = bit;++        VERIFY_CHECK(carry == 0);++        while (verify_bit < 256) {+            VERIFY_CHECK(secp256k1_scalar_get_bits_limb32(&s, verify_bit, 1) == 0);+            verify_bit++;+        }+    }+#endif+    return last_set_bit + 1;+}++struct secp256k1_strauss_point_state {+    int wnaf_na_1[129];+    int wnaf_na_lam[129];+    int bits_na_1;+    int bits_na_lam;+};++struct secp256k1_strauss_state {+    /* aux is used to hold z-ratios, and then used to hold pre_a[i].x * BETA values. */+    secp256k1_fe* aux;+    secp256k1_ge* pre_a;+    struct secp256k1_strauss_point_state* ps;+};++static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *state, secp256k1_gej *r, size_t num, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng) {+    secp256k1_ge tmpa;+    secp256k1_fe Z;+    /* Split G factors. */+    secp256k1_scalar ng_1, ng_128;+    int wnaf_ng_1[129];+    int bits_ng_1 = 0;+    int wnaf_ng_128[129];+    int bits_ng_128 = 0;+    int i;+    int bits = 0;+    size_t np;+    size_t no = 0;++    secp256k1_fe_set_int(&Z, 1);+    for (np = 0; np < num; ++np) {+        secp256k1_gej tmp;+        secp256k1_scalar na_1, na_lam;+        if (secp256k1_scalar_is_zero(&na[np]) || secp256k1_gej_is_infinity(&a[np])) {+            continue;+        }+        /* split na into na_1 and na_lam (where na = na_1 + na_lam*lambda, and na_1 and na_lam are ~128 bit) */+        secp256k1_scalar_split_lambda(&na_1, &na_lam, &na[np]);++        /* build wnaf representation for na_1 and na_lam. */+        state->ps[no].bits_na_1   = secp256k1_ecmult_wnaf(state->ps[no].wnaf_na_1,   129, &na_1,   WINDOW_A);+        state->ps[no].bits_na_lam = secp256k1_ecmult_wnaf(state->ps[no].wnaf_na_lam, 129, &na_lam, WINDOW_A);+        VERIFY_CHECK(state->ps[no].bits_na_1 <= 129);+        VERIFY_CHECK(state->ps[no].bits_na_lam <= 129);+        if (state->ps[no].bits_na_1 > bits) {+            bits = state->ps[no].bits_na_1;+        }+        if (state->ps[no].bits_na_lam > bits) {+            bits = state->ps[no].bits_na_lam;+        }++        /* Calculate odd multiples of a.+         * All multiples are brought to the same Z 'denominator', which is stored+         * in Z. Due to secp256k1' isomorphism we can do all operations pretending+         * that the Z coordinate was 1, use affine addition formulae, and correct+         * the Z coordinate of the result once at the end.+         * The exception is the precomputed G table points, which are actually+         * affine. Compared to the base used for other points, they have a Z ratio+         * of 1/Z, so we can use secp256k1_gej_add_zinv_var, which uses the same+         * isomorphism to efficiently add with a known Z inverse.+         */+        tmp = a[np];+        if (no) {+            secp256k1_gej_rescale(&tmp, &Z);+        }+        secp256k1_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), state->pre_a + no * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), &Z, &tmp);+        if (no) secp256k1_fe_mul(state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), &(a[np].z));++        ++no;+    }++    /* Bring them to the same Z denominator. */+    if (no) {+        secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);+    }++    for (np = 0; np < no; ++np) {+        for (i = 0; i < ECMULT_TABLE_SIZE(WINDOW_A); i++) {+            secp256k1_fe_mul(&state->aux[np * ECMULT_TABLE_SIZE(WINDOW_A) + i], &state->pre_a[np * ECMULT_TABLE_SIZE(WINDOW_A) + i].x, &secp256k1_const_beta);+        }+    }++    if (ng) {+        /* split ng into ng_1 and ng_128 (where gn = gn_1 + gn_128*2^128, and gn_1 and gn_128 are ~128 bit) */+        secp256k1_scalar_split_128(&ng_1, &ng_128, ng);++        /* Build wnaf representation for ng_1 and ng_128 */+        bits_ng_1   = secp256k1_ecmult_wnaf(wnaf_ng_1,   129, &ng_1,   WINDOW_G);+        bits_ng_128 = secp256k1_ecmult_wnaf(wnaf_ng_128, 129, &ng_128, WINDOW_G);+        if (bits_ng_1 > bits) {+            bits = bits_ng_1;+        }+        if (bits_ng_128 > bits) {+            bits = bits_ng_128;+        }+    }++    secp256k1_gej_set_infinity(r);++    for (i = bits - 1; i >= 0; i--) {+        int n;+        secp256k1_gej_double_var(r, r, NULL);+        for (np = 0; np < no; ++np) {+            if (i < state->ps[np].bits_na_1 && (n = state->ps[np].wnaf_na_1[i])) {+                secp256k1_ecmult_table_get_ge(&tmpa, state->pre_a + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A);+                secp256k1_gej_add_ge_var(r, r, &tmpa, NULL);+            }+            if (i < state->ps[np].bits_na_lam && (n = state->ps[np].wnaf_na_lam[i])) {+                secp256k1_ecmult_table_get_ge_lambda(&tmpa, state->pre_a + np * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A);+                secp256k1_gej_add_ge_var(r, r, &tmpa, NULL);+            }+        }+        if (i < bits_ng_1 && (n = wnaf_ng_1[i])) {+            secp256k1_ecmult_table_get_ge_storage(&tmpa, secp256k1_pre_g, n, WINDOW_G);+            secp256k1_gej_add_zinv_var(r, r, &tmpa, &Z);+        }+        if (i < bits_ng_128 && (n = wnaf_ng_128[i])) {+            secp256k1_ecmult_table_get_ge_storage(&tmpa, secp256k1_pre_g_128, n, WINDOW_G);+            secp256k1_gej_add_zinv_var(r, r, &tmpa, &Z);+        }+    }++    if (!r->infinity) {+        secp256k1_fe_mul(&r->z, &r->z, &Z);+    }+}++static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng) {+    secp256k1_fe aux[ECMULT_TABLE_SIZE(WINDOW_A)];+    secp256k1_ge pre_a[ECMULT_TABLE_SIZE(WINDOW_A)];+    struct secp256k1_strauss_point_state ps[1];+    struct secp256k1_strauss_state state;++    state.aux = aux;+    state.pre_a = pre_a;+    state.ps = ps;+    secp256k1_ecmult_strauss_wnaf(&state, r, 1, a, na, ng);+}++static size_t secp256k1_strauss_scratch_size(size_t n_points) {+    static const size_t point_size = (sizeof(secp256k1_ge) + sizeof(secp256k1_fe)) * ECMULT_TABLE_SIZE(WINDOW_A) + sizeof(struct secp256k1_strauss_point_state) + sizeof(secp256k1_gej) + sizeof(secp256k1_scalar);+    return n_points*point_size;+}++static int secp256k1_ecmult_strauss_batch(const secp256k1_callback* error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n_points, size_t cb_offset) {+    secp256k1_gej* points;+    secp256k1_scalar* scalars;+    struct secp256k1_strauss_state state;+    size_t i;+    const size_t scratch_checkpoint = secp256k1_scratch_checkpoint(error_callback, scratch);++    secp256k1_gej_set_infinity(r);+    if (inp_g_sc == NULL && n_points == 0) {+        return 1;+    }++    /* We allocate STRAUSS_SCRATCH_OBJECTS objects on the scratch space. If these+     * allocations change, make sure to update the STRAUSS_SCRATCH_OBJECTS+     * constant and strauss_scratch_size accordingly. */+    points = (secp256k1_gej*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(secp256k1_gej));+    scalars = (secp256k1_scalar*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(secp256k1_scalar));+    state.aux = (secp256k1_fe*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_fe));+    state.pre_a = (secp256k1_ge*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_ge));+    state.ps = (struct secp256k1_strauss_point_state*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(struct secp256k1_strauss_point_state));++    if (points == NULL || scalars == NULL || state.aux == NULL || state.pre_a == NULL || state.ps == NULL) {+        secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);+        return 0;+    }++    for (i = 0; i < n_points; i++) {+        secp256k1_ge point;+        if (!cb(&scalars[i], &point, i+cb_offset, cbdata)) {+            secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);+            return 0;+        }+        secp256k1_gej_set_ge(&points[i], &point);+    }+    secp256k1_ecmult_strauss_wnaf(&state, r, n_points, points, scalars, inp_g_sc);+    secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);+    return 1;+}++/* Wrapper for secp256k1_ecmult_multi_func interface */+static int secp256k1_ecmult_strauss_batch_single(const secp256k1_callback* error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n) {+    return secp256k1_ecmult_strauss_batch(error_callback, scratch, r, inp_g_sc, cb, cbdata, n, 0);+}++static size_t secp256k1_strauss_max_points(const secp256k1_callback* error_callback, secp256k1_scratch *scratch) {+    return secp256k1_scratch_max_allocation(error_callback, scratch, STRAUSS_SCRATCH_OBJECTS) / secp256k1_strauss_scratch_size(1);+}++/** Convert a number to WNAF notation.+ *  The number becomes represented by sum(2^{wi} * wnaf[i], i=0..WNAF_SIZE(w)+1) - return_val.+ *  It has the following guarantees:+ *  - each wnaf[i] is either 0 or an odd integer between -(1 << w) and (1 << w)+ *  - the number of words set is always WNAF_SIZE(w)+ *  - the returned skew is 0 or 1+ */+static int secp256k1_wnaf_fixed(int *wnaf, const secp256k1_scalar *s, int w) {+    int skew = 0;+    int pos;+    int max_pos;+    int last_w;+    const secp256k1_scalar *work = s;++    if (secp256k1_scalar_is_zero(s)) {+        for (pos = 0; pos < WNAF_SIZE(w); pos++) {+            wnaf[pos] = 0;+        }+        return 0;+    }++    if (secp256k1_scalar_is_even(s)) {+        skew = 1;+    }++    wnaf[0] = secp256k1_scalar_get_bits_var(work, 0, w) + skew;+    /* Compute last window size. Relevant when window size doesn't divide the+     * number of bits in the scalar */+    last_w = WNAF_BITS - (WNAF_SIZE(w) - 1) * w;++    /* Store the position of the first nonzero word in max_pos to allow+     * skipping leading zeros when calculating the wnaf. */+    for (pos = WNAF_SIZE(w) - 1; pos > 0; pos--) {+        int val = secp256k1_scalar_get_bits_var(work, pos * w, pos == WNAF_SIZE(w)-1 ? last_w : w);+        if(val != 0) {+            break;+        }+        wnaf[pos] = 0;+    }+    max_pos = pos;+    pos = 1;++    while (pos <= max_pos) {+        int val = secp256k1_scalar_get_bits_var(work, pos * w, pos == WNAF_SIZE(w)-1 ? last_w : w);+        if ((val & 1) == 0) {+            wnaf[pos - 1] -= (1 << w);+            wnaf[pos] = (val + 1);+        } else {+            wnaf[pos] = val;+        }+        /* Set a coefficient to zero if it is 1 or -1 and the proceeding digit+         * is strictly negative or strictly positive respectively. Only change+         * coefficients at previous positions because above code assumes that+         * wnaf[pos - 1] is odd.+         */+        if (pos >= 2 && ((wnaf[pos - 1] == 1 && wnaf[pos - 2] < 0) || (wnaf[pos - 1] == -1 && wnaf[pos - 2] > 0))) {+            if (wnaf[pos - 1] == 1) {+                wnaf[pos - 2] += 1 << w;+            } else {+                wnaf[pos - 2] -= 1 << w;+            }+            wnaf[pos - 1] = 0;+        }+        ++pos;+    }++    return skew;+}++struct secp256k1_pippenger_point_state {+    int skew_na;+    size_t input_pos;+};++struct secp256k1_pippenger_state {+    int *wnaf_na;+    struct secp256k1_pippenger_point_state* ps;+};++/*+ * pippenger_wnaf computes the result of a multi-point multiplication as+ * follows: The scalars are brought into wnaf with n_wnaf elements each. Then+ * for every i < n_wnaf, first each point is added to a "bucket" corresponding+ * to the point's wnaf[i]. Second, the buckets are added together such that+ * r += 1*bucket[0] + 3*bucket[1] + 5*bucket[2] + ...+ */+static int secp256k1_ecmult_pippenger_wnaf(secp256k1_gej *buckets, int bucket_window, struct secp256k1_pippenger_state *state, secp256k1_gej *r, const secp256k1_scalar *sc, const secp256k1_ge *pt, size_t num) {+    size_t n_wnaf = WNAF_SIZE(bucket_window+1);+    size_t np;+    size_t no = 0;+    int i;+    int j;++    for (np = 0; np < num; ++np) {+        if (secp256k1_scalar_is_zero(&sc[np]) || secp256k1_ge_is_infinity(&pt[np])) {+            continue;+        }+        state->ps[no].input_pos = np;+        state->ps[no].skew_na = secp256k1_wnaf_fixed(&state->wnaf_na[no*n_wnaf], &sc[np], bucket_window+1);+        no++;+    }+    secp256k1_gej_set_infinity(r);++    if (no == 0) {+        return 1;+    }++    for (i = n_wnaf - 1; i >= 0; i--) {+        secp256k1_gej running_sum;++        for(j = 0; j < ECMULT_TABLE_SIZE(bucket_window+2); j++) {+            secp256k1_gej_set_infinity(&buckets[j]);+        }++        for (np = 0; np < no; ++np) {+            int n = state->wnaf_na[np*n_wnaf + i];+            struct secp256k1_pippenger_point_state point_state = state->ps[np];+            secp256k1_ge tmp;+            int idx;++            if (i == 0) {+                /* correct for wnaf skew */+                int skew = point_state.skew_na;+                if (skew) {+                    secp256k1_ge_neg(&tmp, &pt[point_state.input_pos]);+                    secp256k1_gej_add_ge_var(&buckets[0], &buckets[0], &tmp, NULL);+                }+            }+            if (n > 0) {+                idx = (n - 1)/2;+                secp256k1_gej_add_ge_var(&buckets[idx], &buckets[idx], &pt[point_state.input_pos], NULL);+            } else if (n < 0) {+                idx = -(n + 1)/2;+                secp256k1_ge_neg(&tmp, &pt[point_state.input_pos]);+                secp256k1_gej_add_ge_var(&buckets[idx], &buckets[idx], &tmp, NULL);+            }+        }++        for(j = 0; j < bucket_window; j++) {+            secp256k1_gej_double_var(r, r, NULL);+        }++        secp256k1_gej_set_infinity(&running_sum);+        /* Accumulate the sum: bucket[0] + 3*bucket[1] + 5*bucket[2] + 7*bucket[3] + ...+         *                   = bucket[0] +   bucket[1] +   bucket[2] +   bucket[3] + ...+         *                   +         2 *  (bucket[1] + 2*bucket[2] + 3*bucket[3] + ...)+         * using an intermediate running sum:+         * running_sum = bucket[0] +   bucket[1] +   bucket[2] + ...+         *+         * The doubling is done implicitly by deferring the final window doubling (of 'r').+         */+        for(j = ECMULT_TABLE_SIZE(bucket_window+2) - 1; j > 0; j--) {+            secp256k1_gej_add_var(&running_sum, &running_sum, &buckets[j], NULL);+            secp256k1_gej_add_var(r, r, &running_sum, NULL);+        }++        secp256k1_gej_add_var(&running_sum, &running_sum, &buckets[0], NULL);+        secp256k1_gej_double_var(r, r, NULL);+        secp256k1_gej_add_var(r, r, &running_sum, NULL);+    }+    return 1;+}++/**+ * Returns optimal bucket_window (number of bits of a scalar represented by a+ * set of buckets) for a given number of points.+ */+static int secp256k1_pippenger_bucket_window(size_t n) {+    if (n <= 1) {+        return 1;+    } else if (n <= 4) {+        return 2;+    } else if (n <= 20) {+        return 3;+    } else if (n <= 57) {+        return 4;+    } else if (n <= 136) {+        return 5;+    } else if (n <= 235) {+        return 6;+    } else if (n <= 1260) {+        return 7;+    } else if (n <= 4420) {+        return 9;+    } else if (n <= 7880) {+        return 10;+    } else if (n <= 16050) {+        return 11;+    } else {+        return PIPPENGER_MAX_BUCKET_WINDOW;+    }+}++/**+ * Returns the maximum optimal number of points for a bucket_window.+ */+static size_t secp256k1_pippenger_bucket_window_inv(int bucket_window) {+    switch(bucket_window) {+        case 1: return 1;+        case 2: return 4;+        case 3: return 20;+        case 4: return 57;+        case 5: return 136;+        case 6: return 235;+        case 7: return 1260;+        case 8: return 1260;+        case 9: return 4420;+        case 10: return 7880;+        case 11: return 16050;+        case PIPPENGER_MAX_BUCKET_WINDOW: return SIZE_MAX;+    }+    return 0;+}+++SECP256K1_INLINE static void secp256k1_ecmult_endo_split(secp256k1_scalar *s1, secp256k1_scalar *s2, secp256k1_ge *p1, secp256k1_ge *p2) {+    secp256k1_scalar tmp = *s1;+    secp256k1_scalar_split_lambda(s1, s2, &tmp);+    secp256k1_ge_mul_lambda(p2, p1);++    if (secp256k1_scalar_is_high(s1)) {+        secp256k1_scalar_negate(s1, s1);+        secp256k1_ge_neg(p1, p1);+    }+    if (secp256k1_scalar_is_high(s2)) {+        secp256k1_scalar_negate(s2, s2);+        secp256k1_ge_neg(p2, p2);+    }+}++/**+ * Returns the scratch size required for a given number of points (excluding+ * base point G) without considering alignment.+ */+static size_t secp256k1_pippenger_scratch_size(size_t n_points, int bucket_window) {+    size_t entries = 2*n_points + 2;+    size_t entry_size = sizeof(secp256k1_ge) + sizeof(secp256k1_scalar) + sizeof(struct secp256k1_pippenger_point_state) + (WNAF_SIZE(bucket_window+1)+1)*sizeof(int);+    return (sizeof(secp256k1_gej) << bucket_window) + sizeof(struct secp256k1_pippenger_state) + entries * entry_size;+}++static int secp256k1_ecmult_pippenger_batch(const secp256k1_callback* error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n_points, size_t cb_offset) {+    const size_t scratch_checkpoint = secp256k1_scratch_checkpoint(error_callback, scratch);+    /* Use 2(n+1) with the endomorphism, when calculating batch+     * sizes. The reason for +1 is that we add the G scalar to the list of+     * other scalars. */+    size_t entries = 2*n_points + 2;+    secp256k1_ge *points;+    secp256k1_scalar *scalars;+    secp256k1_gej *buckets;+    struct secp256k1_pippenger_state *state_space;+    size_t idx = 0;+    size_t point_idx = 0;+    int bucket_window;++    secp256k1_gej_set_infinity(r);+    if (inp_g_sc == NULL && n_points == 0) {+        return 1;+    }+    bucket_window = secp256k1_pippenger_bucket_window(n_points);++    /* We allocate PIPPENGER_SCRATCH_OBJECTS objects on the scratch space. If+     * these allocations change, make sure to update the+     * PIPPENGER_SCRATCH_OBJECTS constant and pippenger_scratch_size+     * accordingly. */+    points = (secp256k1_ge *) secp256k1_scratch_alloc(error_callback, scratch, entries * sizeof(*points));+    scalars = (secp256k1_scalar *) secp256k1_scratch_alloc(error_callback, scratch, entries * sizeof(*scalars));+    state_space = (struct secp256k1_pippenger_state *) secp256k1_scratch_alloc(error_callback, scratch, sizeof(*state_space));+    if (points == NULL || scalars == NULL || state_space == NULL) {+        secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);+        return 0;+    }+    state_space->ps = (struct secp256k1_pippenger_point_state *) secp256k1_scratch_alloc(error_callback, scratch, entries * sizeof(*state_space->ps));+    state_space->wnaf_na = (int *) secp256k1_scratch_alloc(error_callback, scratch, entries*(WNAF_SIZE(bucket_window+1)) * sizeof(int));+    buckets = (secp256k1_gej *) secp256k1_scratch_alloc(error_callback, scratch, ((size_t)1 << bucket_window) * sizeof(*buckets));+    if (state_space->ps == NULL || state_space->wnaf_na == NULL || buckets == NULL) {+        secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);+        return 0;+    }++    if (inp_g_sc != NULL) {+        scalars[0] = *inp_g_sc;+        points[0] = secp256k1_ge_const_g;+        idx++;+        secp256k1_ecmult_endo_split(&scalars[0], &scalars[1], &points[0], &points[1]);+        idx++;+    }++    while (point_idx < n_points) {+        if (!cb(&scalars[idx], &points[idx], point_idx + cb_offset, cbdata)) {+            secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);+            return 0;+        }+        idx++;+        secp256k1_ecmult_endo_split(&scalars[idx - 1], &scalars[idx], &points[idx - 1], &points[idx]);+        idx++;+        point_idx++;+    }++    secp256k1_ecmult_pippenger_wnaf(buckets, bucket_window, state_space, r, scalars, points, idx);+    secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);+    return 1;+}++/* Wrapper for secp256k1_ecmult_multi_func interface */+static int secp256k1_ecmult_pippenger_batch_single(const secp256k1_callback* error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n) {+    return secp256k1_ecmult_pippenger_batch(error_callback, scratch, r, inp_g_sc, cb, cbdata, n, 0);+}++/**+ * Returns the maximum number of points in addition to G that can be used with+ * a given scratch space. The function ensures that fewer points may also be+ * used.+ */+static size_t secp256k1_pippenger_max_points(const secp256k1_callback* error_callback, secp256k1_scratch *scratch) {+    size_t max_alloc = secp256k1_scratch_max_allocation(error_callback, scratch, PIPPENGER_SCRATCH_OBJECTS);+    int bucket_window;+    size_t res = 0;++    for (bucket_window = 1; bucket_window <= PIPPENGER_MAX_BUCKET_WINDOW; bucket_window++) {+        size_t n_points;+        size_t max_points = secp256k1_pippenger_bucket_window_inv(bucket_window);+        size_t space_for_points;+        size_t space_overhead;+        size_t entry_size = sizeof(secp256k1_ge) + sizeof(secp256k1_scalar) + sizeof(struct secp256k1_pippenger_point_state) + (WNAF_SIZE(bucket_window+1)+1)*sizeof(int);++        entry_size = 2*entry_size;+        space_overhead = (sizeof(secp256k1_gej) << bucket_window) + entry_size + sizeof(struct secp256k1_pippenger_state);+        if (space_overhead > max_alloc) {+            break;+        }+        space_for_points = max_alloc - space_overhead;++        n_points = space_for_points/entry_size;+        n_points = n_points > max_points ? max_points : n_points;+        if (n_points > res) {+            res = n_points;+        }+        if (n_points < max_points) {+            /* A larger bucket_window may support even more points. But if we+             * would choose that then the caller couldn't safely use any number+             * smaller than what this function returns */+            break;+        }+    }+    return res;+}++/* Computes ecmult_multi by simply multiplying and adding each point. Does not+ * require a scratch space */+static int secp256k1_ecmult_multi_simple_var(secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n_points) {+    size_t point_idx;+    secp256k1_gej tmpj;++    secp256k1_gej_set_infinity(r);+    secp256k1_gej_set_infinity(&tmpj);+    /* r = inp_g_sc*G */+    secp256k1_ecmult(r, &tmpj, &secp256k1_scalar_zero, inp_g_sc);+    for (point_idx = 0; point_idx < n_points; point_idx++) {+        secp256k1_ge point;+        secp256k1_gej pointj;+        secp256k1_scalar scalar;+        if (!cb(&scalar, &point, point_idx, cbdata)) {+            return 0;+        }+        /* r += scalar*point */+        secp256k1_gej_set_ge(&pointj, &point);+        secp256k1_ecmult(&tmpj, &pointj, &scalar, NULL);+        secp256k1_gej_add_var(r, r, &tmpj, NULL);+    }+    return 1;+}++/* Compute the number of batches and the batch size given the maximum batch size and the+ * total number of points */+static int secp256k1_ecmult_multi_batch_size_helper(size_t *n_batches, size_t *n_batch_points, size_t max_n_batch_points, size_t n) {+    if (max_n_batch_points == 0) {+        return 0;+    }+    if (max_n_batch_points > ECMULT_MAX_POINTS_PER_BATCH) {+        max_n_batch_points = ECMULT_MAX_POINTS_PER_BATCH;+    }+    if (n == 0) {+        *n_batches = 0;+        *n_batch_points = 0;+        return 1;+    }+    /* Compute ceil(n/max_n_batch_points) and ceil(n/n_batches) */+    *n_batches = CEIL_DIV(n, max_n_batch_points);+    *n_batch_points = CEIL_DIV(n, *n_batches);+    return 1;+}++typedef int (*secp256k1_ecmult_multi_func)(const secp256k1_callback* error_callback, secp256k1_scratch*, secp256k1_gej*, const secp256k1_scalar*, secp256k1_ecmult_multi_callback cb, void*, size_t);+static int secp256k1_ecmult_multi_var(const secp256k1_callback* error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n) {+    size_t i;++    int (*f)(const secp256k1_callback* error_callback, secp256k1_scratch*, secp256k1_gej*, const secp256k1_scalar*, secp256k1_ecmult_multi_callback cb, void*, size_t, size_t);+    size_t n_batches;+    size_t n_batch_points;++    secp256k1_gej_set_infinity(r);+    if (inp_g_sc == NULL && n == 0) {+        return 1;+    } else if (n == 0) {+        secp256k1_ecmult(r, r, &secp256k1_scalar_zero, inp_g_sc);+        return 1;+    }+    if (scratch == NULL) {+        return secp256k1_ecmult_multi_simple_var(r, inp_g_sc, cb, cbdata, n);+    }++    /* Compute the batch sizes for Pippenger's algorithm given a scratch space. If it's greater than+     * a threshold use Pippenger's algorithm. Otherwise use Strauss' algorithm.+     * As a first step check if there's enough space for Pippenger's algo (which requires less space+     * than Strauss' algo) and if not, use the simple algorithm. */+    if (!secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, secp256k1_pippenger_max_points(error_callback, scratch), n)) {+        return secp256k1_ecmult_multi_simple_var(r, inp_g_sc, cb, cbdata, n);+    }+    if (n_batch_points >= ECMULT_PIPPENGER_THRESHOLD) {+        f = secp256k1_ecmult_pippenger_batch;+    } else {+        if (!secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, secp256k1_strauss_max_points(error_callback, scratch), n)) {+            return secp256k1_ecmult_multi_simple_var(r, inp_g_sc, cb, cbdata, n);+        }+        f = secp256k1_ecmult_strauss_batch;+    }+    for(i = 0; i < n_batches; i++) {+        size_t nbp = n < n_batch_points ? n : n_batch_points;+        size_t offset = n_batch_points*i;+        secp256k1_gej tmp;+        if (!f(error_callback, scratch, &tmp, i == 0 ? inp_g_sc : NULL, cb, cbdata, nbp, offset)) {+            return 0;+        }+        secp256k1_gej_add_var(r, r, &tmp, NULL);+        n -= nbp;+    }+    return 1;+}++#endif /* SECP256K1_ECMULT_IMPL_H */
+ vendor/external/secp256k1/src/field.h view
@@ -0,0 +1,350 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_FIELD_H+#define SECP256K1_FIELD_H++#include "util.h"++/* This file defines the generic interface for working with secp256k1_fe+ * objects, which represent field elements (integers modulo 2^256 - 2^32 - 977).+ *+ * The actual definition of the secp256k1_fe type depends on the chosen field+ * implementation; see the field_5x52.h and field_10x26.h files for details.+ *+ * All secp256k1_fe objects have implicit properties that determine what+ * operations are permitted on it. These are purely a function of what+ * secp256k1_fe_ operations are applied on it, generally (implicitly) fixed at+ * compile time, and do not depend on the chosen field implementation. Despite+ * that, what these properties actually entail for the field representation+ * values depends on the chosen field implementation. These properties are:+ * - magnitude: an integer in [0,32]+ * - normalized: 0 or 1; normalized=1 implies magnitude <= 1.+ *+ * In VERIFY mode, they are materialized explicitly as fields in the struct,+ * allowing run-time verification of these properties. In that case, the field+ * implementation also provides a secp256k1_fe_verify routine to verify that+ * these fields match the run-time value and perform internal consistency+ * checks. */+#ifdef VERIFY+#  define SECP256K1_FE_VERIFY_FIELDS \+    int magnitude; \+    int normalized;+#else+#  define SECP256K1_FE_VERIFY_FIELDS+#endif++#if defined(SECP256K1_WIDEMUL_INT128)+#include "field_5x52.h"+#elif defined(SECP256K1_WIDEMUL_INT64)+#include "field_10x26.h"+#else+#error "Please select wide multiplication implementation"+#endif++#ifdef VERIFY+/* Magnitude and normalized value for constants. */+#define SECP256K1_FE_VERIFY_CONST(d7, d6, d5, d4, d3, d2, d1, d0) \+    /* Magnitude is 0 for constant 0; 1 otherwise. */ \+    , (((d7) | (d6) | (d5) | (d4) | (d3) | (d2) | (d1) | (d0)) != 0) \+    /* Normalized is 1 unless sum(d_i<<(32*i) for i=0..7) exceeds field modulus. */ \+    , (!(((d7) & (d6) & (d5) & (d4) & (d3) & (d2)) == 0xfffffffful && ((d1) == 0xfffffffful || ((d1) == 0xfffffffe && (d0 >= 0xfffffc2f)))))+#else+#define SECP256K1_FE_VERIFY_CONST(d7, d6, d5, d4, d3, d2, d1, d0)+#endif++/** This expands to an initializer for a secp256k1_fe valued sum((i*32) * d_i, i=0..7) mod p.+ *+ * It has magnitude 1, unless d_i are all 0, in which case the magnitude is 0.+ * It is normalized, unless sum(2^(i*32) * d_i, i=0..7) >= p.+ *+ * SECP256K1_FE_CONST_INNER is provided by the implementation.+ */+#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)) SECP256K1_FE_VERIFY_CONST((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)) }++static const secp256k1_fe secp256k1_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1);+static const secp256k1_fe secp256k1_const_beta = SECP256K1_FE_CONST(+    0x7ae96a2bul, 0x657c0710ul, 0x6e64479eul, 0xac3434e9ul,+    0x9cf04975ul, 0x12f58995ul, 0xc1396c28ul, 0x719501eeul+);++#ifndef VERIFY+/* In non-VERIFY mode, we #define the fe operations to be identical to their+ * internal field implementation, to avoid the potential overhead of a+ * function call (even though presumably inlinable). */+#  define secp256k1_fe_normalize secp256k1_fe_impl_normalize+#  define secp256k1_fe_normalize_weak secp256k1_fe_impl_normalize_weak+#  define secp256k1_fe_normalize_var secp256k1_fe_impl_normalize_var+#  define secp256k1_fe_normalizes_to_zero secp256k1_fe_impl_normalizes_to_zero+#  define secp256k1_fe_normalizes_to_zero_var secp256k1_fe_impl_normalizes_to_zero_var+#  define secp256k1_fe_set_int secp256k1_fe_impl_set_int+#  define secp256k1_fe_is_zero secp256k1_fe_impl_is_zero+#  define secp256k1_fe_is_odd secp256k1_fe_impl_is_odd+#  define secp256k1_fe_cmp_var secp256k1_fe_impl_cmp_var+#  define secp256k1_fe_set_b32_mod secp256k1_fe_impl_set_b32_mod+#  define secp256k1_fe_set_b32_limit secp256k1_fe_impl_set_b32_limit+#  define secp256k1_fe_get_b32 secp256k1_fe_impl_get_b32+#  define secp256k1_fe_negate_unchecked secp256k1_fe_impl_negate_unchecked+#  define secp256k1_fe_mul_int_unchecked secp256k1_fe_impl_mul_int_unchecked+#  define secp256k1_fe_add secp256k1_fe_impl_add+#  define secp256k1_fe_mul secp256k1_fe_impl_mul+#  define secp256k1_fe_sqr secp256k1_fe_impl_sqr+#  define secp256k1_fe_cmov secp256k1_fe_impl_cmov+#  define secp256k1_fe_to_storage secp256k1_fe_impl_to_storage+#  define secp256k1_fe_from_storage secp256k1_fe_impl_from_storage+#  define secp256k1_fe_inv secp256k1_fe_impl_inv+#  define secp256k1_fe_inv_var secp256k1_fe_impl_inv_var+#  define secp256k1_fe_get_bounds secp256k1_fe_impl_get_bounds+#  define secp256k1_fe_half secp256k1_fe_impl_half+#  define secp256k1_fe_add_int secp256k1_fe_impl_add_int+#  define secp256k1_fe_is_square_var secp256k1_fe_impl_is_square_var+#endif /* !defined(VERIFY) */++/** Normalize a field element.+ *+ * On input, r must be a valid field element.+ * On output, r represents the same value but has normalized=1 and magnitude=1.+ */+static void secp256k1_fe_normalize(secp256k1_fe *r);++/** Give a field element magnitude 1.+ *+ * On input, r must be a valid field element.+ * On output, r represents the same value but has magnitude=1. Normalized is unchanged.+ */+static void secp256k1_fe_normalize_weak(secp256k1_fe *r);++/** Normalize a field element, without constant-time guarantee.+ *+ * Identical in behavior to secp256k1_fe_normalize, but not constant time in r.+ */+static void secp256k1_fe_normalize_var(secp256k1_fe *r);++/** Determine whether r represents field element 0.+ *+ * On input, r must be a valid field element.+ * Returns whether r = 0 (mod p).+ */+static int secp256k1_fe_normalizes_to_zero(const secp256k1_fe *r);++/** Determine whether r represents field element 0, without constant-time guarantee.+ *+ * Identical in behavior to secp256k1_normalizes_to_zero, but not constant time in r.+ */+static int secp256k1_fe_normalizes_to_zero_var(const secp256k1_fe *r);++/** Set a field element to an integer in range [0,0x7FFF].+ *+ * On input, r does not need to be initialized, a must be in [0,0x7FFF].+ * On output, r represents value a, is normalized and has magnitude (a!=0).+ */+static void secp256k1_fe_set_int(secp256k1_fe *r, int a);++/** Clear a field element to prevent leaking sensitive information. */+static void secp256k1_fe_clear(secp256k1_fe *a);++/** Determine whether a represents field element 0.+ *+ * On input, a must be a valid normalized field element.+ * Returns whether a = 0 (mod p).+ *+ * This behaves identical to secp256k1_normalizes_to_zero{,_var}, but requires+ * normalized input (and is much faster).+ */+static int secp256k1_fe_is_zero(const secp256k1_fe *a);++/** Determine whether a (mod p) is odd.+ *+ * On input, a must be a valid normalized field element.+ * Returns (int(a) mod p) & 1.+ */+static int secp256k1_fe_is_odd(const secp256k1_fe *a);++/** Determine whether two field elements are equal.+ *+ * On input, a and b must be valid field elements with magnitudes not exceeding+ * 1 and 31, respectively.+ * Returns a = b (mod p).+ */+static int secp256k1_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b);++/** Compare the values represented by 2 field elements, without constant-time guarantee.+ *+ * On input, a and b must be valid normalized field elements.+ * Returns 1 if a > b, -1 if a < b, and 0 if a = b (comparisons are done as integers+ * in range 0..p-1).+ */+static int secp256k1_fe_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b);++/** Set a field element equal to the element represented by a provided 32-byte big endian value+ * interpreted modulo p.+ *+ * On input, r does not need to be initialized. a must be a pointer to an initialized 32-byte array.+ * On output, r = a (mod p). It will have magnitude 1, and not be normalized.+ */+static void secp256k1_fe_set_b32_mod(secp256k1_fe *r, const unsigned char *a);++/** Set a field element equal to a provided 32-byte big endian value, checking for overflow.+ *+ * On input, r does not need to be initialized. a must be a pointer to an initialized 32-byte array.+ * On output, r = a if (a < p), it will be normalized with magnitude 1, and 1 is returned.+ * If a >= p, 0 is returned, and r will be made invalid (and must not be used without overwriting).+ */+static int secp256k1_fe_set_b32_limit(secp256k1_fe *r, const unsigned char *a);++/** Convert a field element to 32-byte big endian byte array.+ * On input, a must be a valid normalized field element, and r a pointer to a 32-byte array.+ * On output, r = a (mod p).+ */+static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a);++/** Negate a field element.+ *+ * On input, r does not need to be initialized. a must be a valid field element with+ * magnitude not exceeding m. m must be an integer constant expression in [0,31].+ * Performs {r = -a}.+ * On output, r will not be normalized, and will have magnitude m+1.+ */+#define secp256k1_fe_negate(r, a, m) ASSERT_INT_CONST_AND_DO(m, secp256k1_fe_negate_unchecked(r, a, m))++/** Like secp256k1_fe_negate_unchecked but m is not checked to be an integer constant expression.+ *+ * Should not be called directly outside of tests.+ */+static void secp256k1_fe_negate_unchecked(secp256k1_fe *r, const secp256k1_fe *a, int m);++/** Add a small integer to a field element.+ *+ * Performs {r += a}. The magnitude of r increases by 1, and normalized is cleared.+ * a must be in range [0,0x7FFF].+ */+static void secp256k1_fe_add_int(secp256k1_fe *r, int a);++/** Multiply a field element with a small integer.+ *+ * On input, r must be a valid field element. a must be an integer constant expression in [0,32].+ * The magnitude of r times a must not exceed 32.+ * Performs {r *= a}.+ * On output, r's magnitude is multiplied by a, and r will not be normalized.+ */+#define secp256k1_fe_mul_int(r, a) ASSERT_INT_CONST_AND_DO(a, secp256k1_fe_mul_int_unchecked(r, a))++/** Like secp256k1_fe_mul_int but a is not checked to be an integer constant expression.+ * + * Should not be called directly outside of tests.+ */+static void secp256k1_fe_mul_int_unchecked(secp256k1_fe *r, int a);++/** Increment a field element by another.+ *+ * On input, r and a must be valid field elements, not necessarily normalized.+ * The sum of their magnitudes must not exceed 32.+ * Performs {r += a}.+ * On output, r will not be normalized, and will have magnitude incremented by a's.+ */+static void secp256k1_fe_add(secp256k1_fe *r, const secp256k1_fe *a);++/** Multiply two field elements.+ *+ * On input, a and b must be valid field elements; r does not need to be initialized.+ * r and a may point to the same object, but neither may point to the object pointed+ * to by b. The magnitudes of a and b must not exceed 8.+ * Performs {r = a * b}+ * On output, r will have magnitude 1, but won't be normalized.+ */+static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe * SECP256K1_RESTRICT b);++/** Square a field element.+ *+ * On input, a must be a valid field element; r does not need to be initialized. The magnitude+ * of a must not exceed 8.+ * Performs {r = a**2}+ * On output, r will have magnitude 1, but won't be normalized.+ */+static void secp256k1_fe_sqr(secp256k1_fe *r, const secp256k1_fe *a);++/** Compute a square root of a field element.+ *+ * On input, a must be a valid field element with magnitude<=8; r need not be initialized.+ * If sqrt(a) exists, performs {r = sqrt(a)} and returns 1.+ * Otherwise, sqrt(-a) exists. The function performs {r = sqrt(-a)} and returns 0.+ * The resulting value represented by r will be a square itself.+ * Variables r and a must not point to the same object.+ * On output, r will have magnitude 1 but will not be normalized.+ */+static int secp256k1_fe_sqrt(secp256k1_fe * SECP256K1_RESTRICT r, const secp256k1_fe * SECP256K1_RESTRICT a);++/** Compute the modular inverse of a field element.+ *+ * On input, a must be a valid field element; r need not be initialized.+ * Performs {r = a**(p-2)} (which maps 0 to 0, and every other element to its+ * inverse).+ * On output, r will have magnitude (a.magnitude != 0) and be normalized.+ */+static void secp256k1_fe_inv(secp256k1_fe *r, const secp256k1_fe *a);++/** Compute the modular inverse of a field element, without constant-time guarantee.+ *+ * Behaves identically to secp256k1_fe_inv, but is not constant-time in a.+ */+static void secp256k1_fe_inv_var(secp256k1_fe *r, const secp256k1_fe *a);++/** Convert a field element to secp256k1_fe_storage.+ *+ * On input, a must be a valid normalized field element.+ * Performs {r = a}.+ */+static void secp256k1_fe_to_storage(secp256k1_fe_storage *r, const secp256k1_fe *a);++/** Convert a field element back from secp256k1_fe_storage.+ *+ * On input, r need not be initialized.+ * Performs {r = a}.+ * On output, r will be normalized and will have magnitude 1.+ */+static void secp256k1_fe_from_storage(secp256k1_fe *r, const secp256k1_fe_storage *a);++/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time.  Both *r and *a must be initialized.*/+static void secp256k1_fe_storage_cmov(secp256k1_fe_storage *r, const secp256k1_fe_storage *a, int flag);++/** Conditionally move a field element in constant time.+ *+ * On input, both r and a must be valid field elements. Flag must be 0 or 1.+ * Performs {r = flag ? a : r}.+ *+ * On output, r's magnitude will be the maximum of both input magnitudes.+ * It will be normalized if and only if both inputs were normalized.+ */+static void secp256k1_fe_cmov(secp256k1_fe *r, const secp256k1_fe *a, int flag);++/** Halve the value of a field element modulo the field prime in constant-time.+ *+ * On input, r must be a valid field element.+ * On output, r will be normalized and have magnitude floor(m/2) + 1 where m is+ * the magnitude of r on input.+ */+static void secp256k1_fe_half(secp256k1_fe *r);++/** Sets r to a field element with magnitude m, normalized if (and only if) m==0.+ *  The value is chosen so that it is likely to trigger edge cases related to+ *  internal overflows. */+static void secp256k1_fe_get_bounds(secp256k1_fe *r, int m);++/** Determine whether a is a square (modulo p).+ *+ * On input, a must be a valid field element.+ */+static int secp256k1_fe_is_square_var(const secp256k1_fe *a);++/** Check invariants on a field element (no-op unless VERIFY is enabled). */+static void secp256k1_fe_verify(const secp256k1_fe *a);+#define SECP256K1_FE_VERIFY(a) secp256k1_fe_verify(a)++/** Check that magnitude of a is at most m (no-op unless VERIFY is enabled). */+static void secp256k1_fe_verify_magnitude(const secp256k1_fe *a, int m);+#define SECP256K1_FE_VERIFY_MAGNITUDE(a, m) secp256k1_fe_verify_magnitude(a, m)++#endif /* SECP256K1_FIELD_H */
+ vendor/external/secp256k1/src/field_10x26.h view
@@ -0,0 +1,57 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_FIELD_REPR_H+#define SECP256K1_FIELD_REPR_H++#include <stdint.h>++/** This field implementation represents the value as 10 uint32_t limbs in base+ *  2^26. */+typedef struct {+   /* A field element f represents the sum(i=0..9, f.n[i] << (i*26)) mod p,+    * where p is the field modulus, 2^256 - 2^32 - 977.+    *+    * The individual limbs f.n[i] can exceed 2^26; the field's magnitude roughly+    * corresponds to how much excess is allowed. The value+    * sum(i=0..9, f.n[i] << (i*26)) may exceed p, unless the field element is+    * normalized. */+    uint32_t n[10];+    /*+     * Magnitude m requires:+     *     n[i] <= 2 * m * (2^26 - 1) for i=0..8+     *     n[9] <= 2 * m * (2^22 - 1)+     *+     * Normalized requires:+     *     n[i] <= (2^26 - 1) for i=0..8+     *     sum(i=0..9, n[i] << (i*26)) < p+     *     (together these imply n[9] <= 2^22 - 1)+     */+    SECP256K1_FE_VERIFY_FIELDS+} secp256k1_fe;++/* Unpacks a constant into a overlapping multi-limbed FE element. */+#define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \+    (d0) & 0x3FFFFFFUL, \+    (((uint32_t)d0) >> 26) | (((uint32_t)(d1) & 0xFFFFFUL) << 6), \+    (((uint32_t)d1) >> 20) | (((uint32_t)(d2) & 0x3FFFUL) << 12), \+    (((uint32_t)d2) >> 14) | (((uint32_t)(d3) & 0xFFUL) << 18), \+    (((uint32_t)d3) >> 8) | (((uint32_t)(d4) & 0x3UL) << 24), \+    (((uint32_t)d4) >> 2) & 0x3FFFFFFUL, \+    (((uint32_t)d4) >> 28) | (((uint32_t)(d5) & 0x3FFFFFUL) << 4), \+    (((uint32_t)d5) >> 22) | (((uint32_t)(d6) & 0xFFFFUL) << 10), \+    (((uint32_t)d6) >> 16) | (((uint32_t)(d7) & 0x3FFUL) << 16), \+    (((uint32_t)d7) >> 10) \+}++typedef struct {+    uint32_t n[8];+} secp256k1_fe_storage;++#define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }}+#define SECP256K1_FE_STORAGE_CONST_GET(d) d.n[7], d.n[6], d.n[5], d.n[4],d.n[3], d.n[2], d.n[1], d.n[0]++#endif /* SECP256K1_FIELD_REPR_H */
+ vendor/external/secp256k1/src/field_10x26_impl.h view
@@ -0,0 +1,1232 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_FIELD_REPR_IMPL_H+#define SECP256K1_FIELD_REPR_IMPL_H++#include "checkmem.h"+#include "util.h"+#include "field.h"+#include "modinv32_impl.h"++#ifdef VERIFY+static void secp256k1_fe_impl_verify(const secp256k1_fe *a) {+    const uint32_t *d = a->n;+    int m = a->normalized ? 1 : 2 * a->magnitude;+    VERIFY_CHECK(d[0] <= 0x3FFFFFFUL * m);+    VERIFY_CHECK(d[1] <= 0x3FFFFFFUL * m);+    VERIFY_CHECK(d[2] <= 0x3FFFFFFUL * m);+    VERIFY_CHECK(d[3] <= 0x3FFFFFFUL * m);+    VERIFY_CHECK(d[4] <= 0x3FFFFFFUL * m);+    VERIFY_CHECK(d[5] <= 0x3FFFFFFUL * m);+    VERIFY_CHECK(d[6] <= 0x3FFFFFFUL * m);+    VERIFY_CHECK(d[7] <= 0x3FFFFFFUL * m);+    VERIFY_CHECK(d[8] <= 0x3FFFFFFUL * m);+    VERIFY_CHECK(d[9] <= 0x03FFFFFUL * m);+    if (a->normalized) {+        if (d[9] == 0x03FFFFFUL) {+            uint32_t mid = d[8] & d[7] & d[6] & d[5] & d[4] & d[3] & d[2];+            if (mid == 0x3FFFFFFUL) {+                VERIFY_CHECK((d[1] + 0x40UL + ((d[0] + 0x3D1UL) >> 26)) <= 0x3FFFFFFUL);+            }+        }+    }+}+#endif++static void secp256k1_fe_impl_get_bounds(secp256k1_fe *r, int m) {+    r->n[0] = 0x3FFFFFFUL * 2 * m;+    r->n[1] = 0x3FFFFFFUL * 2 * m;+    r->n[2] = 0x3FFFFFFUL * 2 * m;+    r->n[3] = 0x3FFFFFFUL * 2 * m;+    r->n[4] = 0x3FFFFFFUL * 2 * m;+    r->n[5] = 0x3FFFFFFUL * 2 * m;+    r->n[6] = 0x3FFFFFFUL * 2 * m;+    r->n[7] = 0x3FFFFFFUL * 2 * m;+    r->n[8] = 0x3FFFFFFUL * 2 * m;+    r->n[9] = 0x03FFFFFUL * 2 * m;+}++static void secp256k1_fe_impl_normalize(secp256k1_fe *r) {+    uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4],+             t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9];++    /* Reduce t9 at the start so there will be at most a single carry from the first pass */+    uint32_t m;+    uint32_t x = t9 >> 22; t9 &= 0x03FFFFFUL;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x3D1UL; t1 += (x << 6);+    t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;+    t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;+    t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL; m = t2;+    t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL; m &= t3;+    t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL; m &= t4;+    t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL; m &= t5;+    t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL; m &= t6;+    t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL; m &= t7;+    t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL; m &= t8;++    /* ... except for a possible carry at bit 22 of t9 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t9 >> 23 == 0);++    /* At most a single final reduction is needed; check if the value is >= the field characteristic */+    x = (t9 >> 22) | ((t9 == 0x03FFFFFUL) & (m == 0x3FFFFFFUL)+        & ((t1 + 0x40UL + ((t0 + 0x3D1UL) >> 26)) > 0x3FFFFFFUL));++    /* Apply the final reduction (for constant-time behaviour, we do it always) */+    t0 += x * 0x3D1UL; t1 += (x << 6);+    t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;+    t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;+    t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL;+    t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL;+    t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL;+    t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL;+    t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL;+    t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL;+    t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL;++    /* If t9 didn't carry to bit 22 already, then it should have after any final reduction */+    VERIFY_CHECK(t9 >> 22 == x);++    /* Mask off the possible multiple of 2^256 from the final reduction */+    t9 &= 0x03FFFFFUL;++    r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4;+    r->n[5] = t5; r->n[6] = t6; r->n[7] = t7; r->n[8] = t8; r->n[9] = t9;+}++static void secp256k1_fe_impl_normalize_weak(secp256k1_fe *r) {+    uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4],+             t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9];++    /* Reduce t9 at the start so there will be at most a single carry from the first pass */+    uint32_t x = t9 >> 22; t9 &= 0x03FFFFFUL;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x3D1UL; t1 += (x << 6);+    t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;+    t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;+    t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL;+    t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL;+    t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL;+    t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL;+    t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL;+    t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL;+    t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL;++    /* ... except for a possible carry at bit 22 of t9 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t9 >> 23 == 0);++    r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4;+    r->n[5] = t5; r->n[6] = t6; r->n[7] = t7; r->n[8] = t8; r->n[9] = t9;+}++static void secp256k1_fe_impl_normalize_var(secp256k1_fe *r) {+    uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4],+             t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9];++    /* Reduce t9 at the start so there will be at most a single carry from the first pass */+    uint32_t m;+    uint32_t x = t9 >> 22; t9 &= 0x03FFFFFUL;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x3D1UL; t1 += (x << 6);+    t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;+    t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;+    t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL; m = t2;+    t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL; m &= t3;+    t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL; m &= t4;+    t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL; m &= t5;+    t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL; m &= t6;+    t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL; m &= t7;+    t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL; m &= t8;++    /* ... except for a possible carry at bit 22 of t9 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t9 >> 23 == 0);++    /* At most a single final reduction is needed; check if the value is >= the field characteristic */+    x = (t9 >> 22) | ((t9 == 0x03FFFFFUL) & (m == 0x3FFFFFFUL)+        & ((t1 + 0x40UL + ((t0 + 0x3D1UL) >> 26)) > 0x3FFFFFFUL));++    if (x) {+        t0 += 0x3D1UL; t1 += (x << 6);+        t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL;+        t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL;+        t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL;+        t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL;+        t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL;+        t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL;+        t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL;+        t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL;+        t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL;++        /* If t9 didn't carry to bit 22 already, then it should have after any final reduction */+        VERIFY_CHECK(t9 >> 22 == x);++        /* Mask off the possible multiple of 2^256 from the final reduction */+        t9 &= 0x03FFFFFUL;+    }++    r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4;+    r->n[5] = t5; r->n[6] = t6; r->n[7] = t7; r->n[8] = t8; r->n[9] = t9;+}++static int secp256k1_fe_impl_normalizes_to_zero(const secp256k1_fe *r) {+    uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4],+             t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9];++    /* z0 tracks a possible raw value of 0, z1 tracks a possible raw value of P */+    uint32_t z0, z1;++    /* Reduce t9 at the start so there will be at most a single carry from the first pass */+    uint32_t x = t9 >> 22; t9 &= 0x03FFFFFUL;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x3D1UL; t1 += (x << 6);+    t1 += (t0 >> 26); t0 &= 0x3FFFFFFUL; z0  = t0; z1  = t0 ^ 0x3D0UL;+    t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL; z0 |= t1; z1 &= t1 ^ 0x40UL;+    t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL; z0 |= t2; z1 &= t2;+    t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL; z0 |= t3; z1 &= t3;+    t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL; z0 |= t4; z1 &= t4;+    t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL; z0 |= t5; z1 &= t5;+    t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL; z0 |= t6; z1 &= t6;+    t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL; z0 |= t7; z1 &= t7;+    t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL; z0 |= t8; z1 &= t8;+                                         z0 |= t9; z1 &= t9 ^ 0x3C00000UL;++    /* ... except for a possible carry at bit 22 of t9 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t9 >> 23 == 0);++    return (z0 == 0) | (z1 == 0x3FFFFFFUL);+}++static int secp256k1_fe_impl_normalizes_to_zero_var(const secp256k1_fe *r) {+    uint32_t t0, t1, t2, t3, t4, t5, t6, t7, t8, t9;+    uint32_t z0, z1;+    uint32_t x;++    t0 = r->n[0];+    t9 = r->n[9];++    /* Reduce t9 at the start so there will be at most a single carry from the first pass */+    x = t9 >> 22;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x3D1UL;++    /* z0 tracks a possible raw value of 0, z1 tracks a possible raw value of P */+    z0 = t0 & 0x3FFFFFFUL;+    z1 = z0 ^ 0x3D0UL;++    /* Fast return path should catch the majority of cases */+    if ((z0 != 0UL) & (z1 != 0x3FFFFFFUL)) {+        return 0;+    }++    t1 = r->n[1];+    t2 = r->n[2];+    t3 = r->n[3];+    t4 = r->n[4];+    t5 = r->n[5];+    t6 = r->n[6];+    t7 = r->n[7];+    t8 = r->n[8];++    t9 &= 0x03FFFFFUL;+    t1 += (x << 6);++    t1 += (t0 >> 26);+    t2 += (t1 >> 26); t1 &= 0x3FFFFFFUL; z0 |= t1; z1 &= t1 ^ 0x40UL;+    t3 += (t2 >> 26); t2 &= 0x3FFFFFFUL; z0 |= t2; z1 &= t2;+    t4 += (t3 >> 26); t3 &= 0x3FFFFFFUL; z0 |= t3; z1 &= t3;+    t5 += (t4 >> 26); t4 &= 0x3FFFFFFUL; z0 |= t4; z1 &= t4;+    t6 += (t5 >> 26); t5 &= 0x3FFFFFFUL; z0 |= t5; z1 &= t5;+    t7 += (t6 >> 26); t6 &= 0x3FFFFFFUL; z0 |= t6; z1 &= t6;+    t8 += (t7 >> 26); t7 &= 0x3FFFFFFUL; z0 |= t7; z1 &= t7;+    t9 += (t8 >> 26); t8 &= 0x3FFFFFFUL; z0 |= t8; z1 &= t8;+                                         z0 |= t9; z1 &= t9 ^ 0x3C00000UL;++    /* ... except for a possible carry at bit 22 of t9 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t9 >> 23 == 0);++    return (z0 == 0) | (z1 == 0x3FFFFFFUL);+}++SECP256K1_INLINE static void secp256k1_fe_impl_set_int(secp256k1_fe *r, int a) {+    r->n[0] = a;+    r->n[1] = r->n[2] = r->n[3] = r->n[4] = r->n[5] = r->n[6] = r->n[7] = r->n[8] = r->n[9] = 0;+}++SECP256K1_INLINE static int secp256k1_fe_impl_is_zero(const secp256k1_fe *a) {+    const uint32_t *t = a->n;+    return (t[0] | t[1] | t[2] | t[3] | t[4] | t[5] | t[6] | t[7] | t[8] | t[9]) == 0;+}++SECP256K1_INLINE static int secp256k1_fe_impl_is_odd(const secp256k1_fe *a) {+    return a->n[0] & 1;+}++static int secp256k1_fe_impl_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b) {+    int i;+    for (i = 9; i >= 0; i--) {+        if (a->n[i] > b->n[i]) {+            return 1;+        }+        if (a->n[i] < b->n[i]) {+            return -1;+        }+    }+    return 0;+}++static void secp256k1_fe_impl_set_b32_mod(secp256k1_fe *r, const unsigned char *a) {+    r->n[0] = (uint32_t)a[31] | ((uint32_t)a[30] << 8) | ((uint32_t)a[29] << 16) | ((uint32_t)(a[28] & 0x3) << 24);+    r->n[1] = (uint32_t)((a[28] >> 2) & 0x3f) | ((uint32_t)a[27] << 6) | ((uint32_t)a[26] << 14) | ((uint32_t)(a[25] & 0xf) << 22);+    r->n[2] = (uint32_t)((a[25] >> 4) & 0xf) | ((uint32_t)a[24] << 4) | ((uint32_t)a[23] << 12) | ((uint32_t)(a[22] & 0x3f) << 20);+    r->n[3] = (uint32_t)((a[22] >> 6) & 0x3) | ((uint32_t)a[21] << 2) | ((uint32_t)a[20] << 10) | ((uint32_t)a[19] << 18);+    r->n[4] = (uint32_t)a[18] | ((uint32_t)a[17] << 8) | ((uint32_t)a[16] << 16) | ((uint32_t)(a[15] & 0x3) << 24);+    r->n[5] = (uint32_t)((a[15] >> 2) & 0x3f) | ((uint32_t)a[14] << 6) | ((uint32_t)a[13] << 14) | ((uint32_t)(a[12] & 0xf) << 22);+    r->n[6] = (uint32_t)((a[12] >> 4) & 0xf) | ((uint32_t)a[11] << 4) | ((uint32_t)a[10] << 12) | ((uint32_t)(a[9] & 0x3f) << 20);+    r->n[7] = (uint32_t)((a[9] >> 6) & 0x3) | ((uint32_t)a[8] << 2) | ((uint32_t)a[7] << 10) | ((uint32_t)a[6] << 18);+    r->n[8] = (uint32_t)a[5] | ((uint32_t)a[4] << 8) | ((uint32_t)a[3] << 16) | ((uint32_t)(a[2] & 0x3) << 24);+    r->n[9] = (uint32_t)((a[2] >> 2) & 0x3f) | ((uint32_t)a[1] << 6) | ((uint32_t)a[0] << 14);+}++static int secp256k1_fe_impl_set_b32_limit(secp256k1_fe *r, const unsigned char *a) {+    secp256k1_fe_impl_set_b32_mod(r, a);+    return !((r->n[9] == 0x3FFFFFUL) & ((r->n[8] & r->n[7] & r->n[6] & r->n[5] & r->n[4] & r->n[3] & r->n[2]) == 0x3FFFFFFUL) & ((r->n[1] + 0x40UL + ((r->n[0] + 0x3D1UL) >> 26)) > 0x3FFFFFFUL));+}++/** Convert a field element to a 32-byte big endian value. Requires the input to be normalized */+static void secp256k1_fe_impl_get_b32(unsigned char *r, const secp256k1_fe *a) {+    r[0] = (a->n[9] >> 14) & 0xff;+    r[1] = (a->n[9] >> 6) & 0xff;+    r[2] = ((a->n[9] & 0x3F) << 2) | ((a->n[8] >> 24) & 0x3);+    r[3] = (a->n[8] >> 16) & 0xff;+    r[4] = (a->n[8] >> 8) & 0xff;+    r[5] = a->n[8] & 0xff;+    r[6] = (a->n[7] >> 18) & 0xff;+    r[7] = (a->n[7] >> 10) & 0xff;+    r[8] = (a->n[7] >> 2) & 0xff;+    r[9] = ((a->n[7] & 0x3) << 6) | ((a->n[6] >> 20) & 0x3f);+    r[10] = (a->n[6] >> 12) & 0xff;+    r[11] = (a->n[6] >> 4) & 0xff;+    r[12] = ((a->n[6] & 0xf) << 4) | ((a->n[5] >> 22) & 0xf);+    r[13] = (a->n[5] >> 14) & 0xff;+    r[14] = (a->n[5] >> 6) & 0xff;+    r[15] = ((a->n[5] & 0x3f) << 2) | ((a->n[4] >> 24) & 0x3);+    r[16] = (a->n[4] >> 16) & 0xff;+    r[17] = (a->n[4] >> 8) & 0xff;+    r[18] = a->n[4] & 0xff;+    r[19] = (a->n[3] >> 18) & 0xff;+    r[20] = (a->n[3] >> 10) & 0xff;+    r[21] = (a->n[3] >> 2) & 0xff;+    r[22] = ((a->n[3] & 0x3) << 6) | ((a->n[2] >> 20) & 0x3f);+    r[23] = (a->n[2] >> 12) & 0xff;+    r[24] = (a->n[2] >> 4) & 0xff;+    r[25] = ((a->n[2] & 0xf) << 4) | ((a->n[1] >> 22) & 0xf);+    r[26] = (a->n[1] >> 14) & 0xff;+    r[27] = (a->n[1] >> 6) & 0xff;+    r[28] = ((a->n[1] & 0x3f) << 2) | ((a->n[0] >> 24) & 0x3);+    r[29] = (a->n[0] >> 16) & 0xff;+    r[30] = (a->n[0] >> 8) & 0xff;+    r[31] = a->n[0] & 0xff;+}++SECP256K1_INLINE static void secp256k1_fe_impl_negate_unchecked(secp256k1_fe *r, const secp256k1_fe *a, int m) {+    /* For all legal values of m (0..31), the following properties hold: */+    VERIFY_CHECK(0x3FFFC2FUL * 2 * (m + 1) >= 0x3FFFFFFUL * 2 * m);+    VERIFY_CHECK(0x3FFFFBFUL * 2 * (m + 1) >= 0x3FFFFFFUL * 2 * m);+    VERIFY_CHECK(0x3FFFFFFUL * 2 * (m + 1) >= 0x3FFFFFFUL * 2 * m);+    VERIFY_CHECK(0x03FFFFFUL * 2 * (m + 1) >= 0x03FFFFFUL * 2 * m);++    /* Due to the properties above, the left hand in the subtractions below is never less than+     * the right hand. */+    r->n[0] = 0x3FFFC2FUL * 2 * (m + 1) - a->n[0];+    r->n[1] = 0x3FFFFBFUL * 2 * (m + 1) - a->n[1];+    r->n[2] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[2];+    r->n[3] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[3];+    r->n[4] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[4];+    r->n[5] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[5];+    r->n[6] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[6];+    r->n[7] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[7];+    r->n[8] = 0x3FFFFFFUL * 2 * (m + 1) - a->n[8];+    r->n[9] = 0x03FFFFFUL * 2 * (m + 1) - a->n[9];+}++SECP256K1_INLINE static void secp256k1_fe_impl_mul_int_unchecked(secp256k1_fe *r, int a) {+    r->n[0] *= a;+    r->n[1] *= a;+    r->n[2] *= a;+    r->n[3] *= a;+    r->n[4] *= a;+    r->n[5] *= a;+    r->n[6] *= a;+    r->n[7] *= a;+    r->n[8] *= a;+    r->n[9] *= a;+}++SECP256K1_INLINE static void secp256k1_fe_impl_add(secp256k1_fe *r, const secp256k1_fe *a) {+    r->n[0] += a->n[0];+    r->n[1] += a->n[1];+    r->n[2] += a->n[2];+    r->n[3] += a->n[3];+    r->n[4] += a->n[4];+    r->n[5] += a->n[5];+    r->n[6] += a->n[6];+    r->n[7] += a->n[7];+    r->n[8] += a->n[8];+    r->n[9] += a->n[9];+}++SECP256K1_INLINE static void secp256k1_fe_impl_add_int(secp256k1_fe *r, int a) {+    r->n[0] += a;+}++#if defined(USE_EXTERNAL_ASM)++/* External assembler implementation */+void secp256k1_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t * SECP256K1_RESTRICT b);+void secp256k1_fe_sqr_inner(uint32_t *r, const uint32_t *a);++#else++#define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0)++SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t * SECP256K1_RESTRICT b) {+    uint64_t c, d;+    uint64_t u0, u1, u2, u3, u4, u5, u6, u7, u8;+    uint32_t t9, t1, t0, t2, t3, t4, t5, t6, t7;+    const uint32_t M = 0x3FFFFFFUL, R0 = 0x3D10UL, R1 = 0x400UL;++    VERIFY_BITS(a[0], 30);+    VERIFY_BITS(a[1], 30);+    VERIFY_BITS(a[2], 30);+    VERIFY_BITS(a[3], 30);+    VERIFY_BITS(a[4], 30);+    VERIFY_BITS(a[5], 30);+    VERIFY_BITS(a[6], 30);+    VERIFY_BITS(a[7], 30);+    VERIFY_BITS(a[8], 30);+    VERIFY_BITS(a[9], 26);+    VERIFY_BITS(b[0], 30);+    VERIFY_BITS(b[1], 30);+    VERIFY_BITS(b[2], 30);+    VERIFY_BITS(b[3], 30);+    VERIFY_BITS(b[4], 30);+    VERIFY_BITS(b[5], 30);+    VERIFY_BITS(b[6], 30);+    VERIFY_BITS(b[7], 30);+    VERIFY_BITS(b[8], 30);+    VERIFY_BITS(b[9], 26);++    /** [... a b c] is a shorthand for ... + a<<52 + b<<26 + c<<0 mod n.+     *  for 0 <= x <= 9, px is a shorthand for sum(a[i]*b[x-i], i=0..x).+     *  for 9 <= x <= 18, px is a shorthand for sum(a[i]*b[x-i], i=(x-9)..9)+     *  Note that [x 0 0 0 0 0 0 0 0 0 0] = [x*R1 x*R0].+     */++    d  = (uint64_t)a[0] * b[9]+       + (uint64_t)a[1] * b[8]+       + (uint64_t)a[2] * b[7]+       + (uint64_t)a[3] * b[6]+       + (uint64_t)a[4] * b[5]+       + (uint64_t)a[5] * b[4]+       + (uint64_t)a[6] * b[3]+       + (uint64_t)a[7] * b[2]+       + (uint64_t)a[8] * b[1]+       + (uint64_t)a[9] * b[0];+    /* VERIFY_BITS(d, 64); */+    /* [d 0 0 0 0 0 0 0 0 0] = [p9 0 0 0 0 0 0 0 0 0] */+    t9 = d & M; d >>= 26;+    VERIFY_BITS(t9, 26);+    VERIFY_BITS(d, 38);+    /* [d t9 0 0 0 0 0 0 0 0 0] = [p9 0 0 0 0 0 0 0 0 0] */++    c  = (uint64_t)a[0] * b[0];+    VERIFY_BITS(c, 60);+    /* [d t9 0 0 0 0 0 0 0 0 c] = [p9 0 0 0 0 0 0 0 0 p0] */+    d += (uint64_t)a[1] * b[9]+       + (uint64_t)a[2] * b[8]+       + (uint64_t)a[3] * b[7]+       + (uint64_t)a[4] * b[6]+       + (uint64_t)a[5] * b[5]+       + (uint64_t)a[6] * b[4]+       + (uint64_t)a[7] * b[3]+       + (uint64_t)a[8] * b[2]+       + (uint64_t)a[9] * b[1];+    VERIFY_BITS(d, 63);+    /* [d t9 0 0 0 0 0 0 0 0 c] = [p10 p9 0 0 0 0 0 0 0 0 p0] */+    u0 = d & M; d >>= 26; c += u0 * R0;+    VERIFY_BITS(u0, 26);+    VERIFY_BITS(d, 37);+    VERIFY_BITS(c, 61);+    /* [d u0 t9 0 0 0 0 0 0 0 0 c-u0*R0] = [p10 p9 0 0 0 0 0 0 0 0 p0] */+    t0 = c & M; c >>= 26; c += u0 * R1;+    VERIFY_BITS(t0, 26);+    VERIFY_BITS(c, 37);+    /* [d u0 t9 0 0 0 0 0 0 0 c-u0*R1 t0-u0*R0] = [p10 p9 0 0 0 0 0 0 0 0 p0] */+    /* [d 0 t9 0 0 0 0 0 0 0 c t0] = [p10 p9 0 0 0 0 0 0 0 0 p0] */++    c += (uint64_t)a[0] * b[1]+       + (uint64_t)a[1] * b[0];+    VERIFY_BITS(c, 62);+    /* [d 0 t9 0 0 0 0 0 0 0 c t0] = [p10 p9 0 0 0 0 0 0 0 p1 p0] */+    d += (uint64_t)a[2] * b[9]+       + (uint64_t)a[3] * b[8]+       + (uint64_t)a[4] * b[7]+       + (uint64_t)a[5] * b[6]+       + (uint64_t)a[6] * b[5]+       + (uint64_t)a[7] * b[4]+       + (uint64_t)a[8] * b[3]+       + (uint64_t)a[9] * b[2];+    VERIFY_BITS(d, 63);+    /* [d 0 t9 0 0 0 0 0 0 0 c t0] = [p11 p10 p9 0 0 0 0 0 0 0 p1 p0] */+    u1 = d & M; d >>= 26; c += u1 * R0;+    VERIFY_BITS(u1, 26);+    VERIFY_BITS(d, 37);+    VERIFY_BITS(c, 63);+    /* [d u1 0 t9 0 0 0 0 0 0 0 c-u1*R0 t0] = [p11 p10 p9 0 0 0 0 0 0 0 p1 p0] */+    t1 = c & M; c >>= 26; c += u1 * R1;+    VERIFY_BITS(t1, 26);+    VERIFY_BITS(c, 38);+    /* [d u1 0 t9 0 0 0 0 0 0 c-u1*R1 t1-u1*R0 t0] = [p11 p10 p9 0 0 0 0 0 0 0 p1 p0] */+    /* [d 0 0 t9 0 0 0 0 0 0 c t1 t0] = [p11 p10 p9 0 0 0 0 0 0 0 p1 p0] */++    c += (uint64_t)a[0] * b[2]+       + (uint64_t)a[1] * b[1]+       + (uint64_t)a[2] * b[0];+    VERIFY_BITS(c, 62);+    /* [d 0 0 t9 0 0 0 0 0 0 c t1 t0] = [p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */+    d += (uint64_t)a[3] * b[9]+       + (uint64_t)a[4] * b[8]+       + (uint64_t)a[5] * b[7]+       + (uint64_t)a[6] * b[6]+       + (uint64_t)a[7] * b[5]+       + (uint64_t)a[8] * b[4]+       + (uint64_t)a[9] * b[3];+    VERIFY_BITS(d, 63);+    /* [d 0 0 t9 0 0 0 0 0 0 c t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */+    u2 = d & M; d >>= 26; c += u2 * R0;+    VERIFY_BITS(u2, 26);+    VERIFY_BITS(d, 37);+    VERIFY_BITS(c, 63);+    /* [d u2 0 0 t9 0 0 0 0 0 0 c-u2*R0 t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */+    t2 = c & M; c >>= 26; c += u2 * R1;+    VERIFY_BITS(t2, 26);+    VERIFY_BITS(c, 38);+    /* [d u2 0 0 t9 0 0 0 0 0 c-u2*R1 t2-u2*R0 t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */+    /* [d 0 0 0 t9 0 0 0 0 0 c t2 t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */++    c += (uint64_t)a[0] * b[3]+       + (uint64_t)a[1] * b[2]+       + (uint64_t)a[2] * b[1]+       + (uint64_t)a[3] * b[0];+    VERIFY_BITS(c, 63);+    /* [d 0 0 0 t9 0 0 0 0 0 c t2 t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */+    d += (uint64_t)a[4] * b[9]+       + (uint64_t)a[5] * b[8]+       + (uint64_t)a[6] * b[7]+       + (uint64_t)a[7] * b[6]+       + (uint64_t)a[8] * b[5]+       + (uint64_t)a[9] * b[4];+    VERIFY_BITS(d, 63);+    /* [d 0 0 0 t9 0 0 0 0 0 c t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */+    u3 = d & M; d >>= 26; c += u3 * R0;+    VERIFY_BITS(u3, 26);+    VERIFY_BITS(d, 37);+    /* VERIFY_BITS(c, 64); */+    /* [d u3 0 0 0 t9 0 0 0 0 0 c-u3*R0 t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */+    t3 = c & M; c >>= 26; c += u3 * R1;+    VERIFY_BITS(t3, 26);+    VERIFY_BITS(c, 39);+    /* [d u3 0 0 0 t9 0 0 0 0 c-u3*R1 t3-u3*R0 t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */+    /* [d 0 0 0 0 t9 0 0 0 0 c t3 t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */++    c += (uint64_t)a[0] * b[4]+       + (uint64_t)a[1] * b[3]+       + (uint64_t)a[2] * b[2]+       + (uint64_t)a[3] * b[1]+       + (uint64_t)a[4] * b[0];+    VERIFY_BITS(c, 63);+    /* [d 0 0 0 0 t9 0 0 0 0 c t3 t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */+    d += (uint64_t)a[5] * b[9]+       + (uint64_t)a[6] * b[8]+       + (uint64_t)a[7] * b[7]+       + (uint64_t)a[8] * b[6]+       + (uint64_t)a[9] * b[5];+    VERIFY_BITS(d, 62);+    /* [d 0 0 0 0 t9 0 0 0 0 c t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */+    u4 = d & M; d >>= 26; c += u4 * R0;+    VERIFY_BITS(u4, 26);+    VERIFY_BITS(d, 36);+    /* VERIFY_BITS(c, 64); */+    /* [d u4 0 0 0 0 t9 0 0 0 0 c-u4*R0 t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */+    t4 = c & M; c >>= 26; c += u4 * R1;+    VERIFY_BITS(t4, 26);+    VERIFY_BITS(c, 39);+    /* [d u4 0 0 0 0 t9 0 0 0 c-u4*R1 t4-u4*R0 t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 t9 0 0 0 c t4 t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */++    c += (uint64_t)a[0] * b[5]+       + (uint64_t)a[1] * b[4]+       + (uint64_t)a[2] * b[3]+       + (uint64_t)a[3] * b[2]+       + (uint64_t)a[4] * b[1]+       + (uint64_t)a[5] * b[0];+    VERIFY_BITS(c, 63);+    /* [d 0 0 0 0 0 t9 0 0 0 c t4 t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */+    d += (uint64_t)a[6] * b[9]+       + (uint64_t)a[7] * b[8]+       + (uint64_t)a[8] * b[7]+       + (uint64_t)a[9] * b[6];+    VERIFY_BITS(d, 62);+    /* [d 0 0 0 0 0 t9 0 0 0 c t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */+    u5 = d & M; d >>= 26; c += u5 * R0;+    VERIFY_BITS(u5, 26);+    VERIFY_BITS(d, 36);+    /* VERIFY_BITS(c, 64); */+    /* [d u5 0 0 0 0 0 t9 0 0 0 c-u5*R0 t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */+    t5 = c & M; c >>= 26; c += u5 * R1;+    VERIFY_BITS(t5, 26);+    VERIFY_BITS(c, 39);+    /* [d u5 0 0 0 0 0 t9 0 0 c-u5*R1 t5-u5*R0 t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 t9 0 0 c t5 t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */++    c += (uint64_t)a[0] * b[6]+       + (uint64_t)a[1] * b[5]+       + (uint64_t)a[2] * b[4]+       + (uint64_t)a[3] * b[3]+       + (uint64_t)a[4] * b[2]+       + (uint64_t)a[5] * b[1]+       + (uint64_t)a[6] * b[0];+    VERIFY_BITS(c, 63);+    /* [d 0 0 0 0 0 0 t9 0 0 c t5 t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */+    d += (uint64_t)a[7] * b[9]+       + (uint64_t)a[8] * b[8]+       + (uint64_t)a[9] * b[7];+    VERIFY_BITS(d, 61);+    /* [d 0 0 0 0 0 0 t9 0 0 c t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */+    u6 = d & M; d >>= 26; c += u6 * R0;+    VERIFY_BITS(u6, 26);+    VERIFY_BITS(d, 35);+    /* VERIFY_BITS(c, 64); */+    /* [d u6 0 0 0 0 0 0 t9 0 0 c-u6*R0 t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */+    t6 = c & M; c >>= 26; c += u6 * R1;+    VERIFY_BITS(t6, 26);+    VERIFY_BITS(c, 39);+    /* [d u6 0 0 0 0 0 0 t9 0 c-u6*R1 t6-u6*R0 t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 0 t9 0 c t6 t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */++    c += (uint64_t)a[0] * b[7]+       + (uint64_t)a[1] * b[6]+       + (uint64_t)a[2] * b[5]+       + (uint64_t)a[3] * b[4]+       + (uint64_t)a[4] * b[3]+       + (uint64_t)a[5] * b[2]+       + (uint64_t)a[6] * b[1]+       + (uint64_t)a[7] * b[0];+    /* VERIFY_BITS(c, 64); */+    VERIFY_CHECK(c <= 0x8000007C00000007ULL);+    /* [d 0 0 0 0 0 0 0 t9 0 c t6 t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */+    d += (uint64_t)a[8] * b[9]+       + (uint64_t)a[9] * b[8];+    VERIFY_BITS(d, 58);+    /* [d 0 0 0 0 0 0 0 t9 0 c t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */+    u7 = d & M; d >>= 26; c += u7 * R0;+    VERIFY_BITS(u7, 26);+    VERIFY_BITS(d, 32);+    /* VERIFY_BITS(c, 64); */+    VERIFY_CHECK(c <= 0x800001703FFFC2F7ULL);+    /* [d u7 0 0 0 0 0 0 0 t9 0 c-u7*R0 t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */+    t7 = c & M; c >>= 26; c += u7 * R1;+    VERIFY_BITS(t7, 26);+    VERIFY_BITS(c, 38);+    /* [d u7 0 0 0 0 0 0 0 t9 c-u7*R1 t7-u7*R0 t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 0 0 t9 c t7 t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */++    c += (uint64_t)a[0] * b[8]+       + (uint64_t)a[1] * b[7]+       + (uint64_t)a[2] * b[6]+       + (uint64_t)a[3] * b[5]+       + (uint64_t)a[4] * b[4]+       + (uint64_t)a[5] * b[3]+       + (uint64_t)a[6] * b[2]+       + (uint64_t)a[7] * b[1]+       + (uint64_t)a[8] * b[0];+    /* VERIFY_BITS(c, 64); */+    VERIFY_CHECK(c <= 0x9000007B80000008ULL);+    /* [d 0 0 0 0 0 0 0 0 t9 c t7 t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    d += (uint64_t)a[9] * b[9];+    VERIFY_BITS(d, 57);+    /* [d 0 0 0 0 0 0 0 0 t9 c t7 t6 t5 t4 t3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    u8 = d & M; d >>= 26; c += u8 * R0;+    VERIFY_BITS(u8, 26);+    VERIFY_BITS(d, 31);+    /* VERIFY_BITS(c, 64); */+    VERIFY_CHECK(c <= 0x9000016FBFFFC2F8ULL);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 t6 t5 t4 t3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */++    r[3] = t3;+    VERIFY_BITS(r[3], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 t6 t5 t4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[4] = t4;+    VERIFY_BITS(r[4], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 t6 t5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[5] = t5;+    VERIFY_BITS(r[5], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 t6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[6] = t6;+    VERIFY_BITS(r[6], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[7] = t7;+    VERIFY_BITS(r[7], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */++    r[8] = c & M; c >>= 26; c += u8 * R1;+    VERIFY_BITS(r[8], 26);+    VERIFY_BITS(c, 39);+    /* [d u8 0 0 0 0 0 0 0 0 t9+c-u8*R1 r8-u8*R0 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 0 0 0 t9+c r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    c   += d * R0 + t9;+    VERIFY_BITS(c, 45);+    /* [d 0 0 0 0 0 0 0 0 0 c-d*R0 r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[9] = c & (M >> 4); c >>= 22; c += d * (R1 << 4);+    VERIFY_BITS(r[9], 22);+    VERIFY_BITS(c, 46);+    /* [d 0 0 0 0 0 0 0 0 r9+((c-d*R1<<4)<<22)-d*R0 r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 0 -d*R1 r9+(c<<22)-d*R0 r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */++    d    = c * (R0 >> 4) + t0;+    VERIFY_BITS(d, 56);+    /* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1 d-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[0] = d & M; d >>= 26;+    VERIFY_BITS(r[0], 26);+    VERIFY_BITS(d, 30);+    /* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1+d r0-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    d   += c * (R1 >> 4) + t1;+    VERIFY_BITS(d, 53);+    VERIFY_CHECK(d <= 0x10000003FFFFBFULL);+    /* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 d-c*R1>>4 r0-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [r9 r8 r7 r6 r5 r4 r3 t2 d r0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[1] = d & M; d >>= 26;+    VERIFY_BITS(r[1], 26);+    VERIFY_BITS(d, 27);+    VERIFY_CHECK(d <= 0x4000000ULL);+    /* [r9 r8 r7 r6 r5 r4 r3 t2+d r1 r0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    d   += t2;+    VERIFY_BITS(d, 27);+    /* [r9 r8 r7 r6 r5 r4 r3 d r1 r0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[2] = d;+    VERIFY_BITS(r[2], 27);+    /* [r9 r8 r7 r6 r5 r4 r3 r2 r1 r0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+}++SECP256K1_INLINE static void secp256k1_fe_sqr_inner(uint32_t *r, const uint32_t *a) {+    uint64_t c, d;+    uint64_t u0, u1, u2, u3, u4, u5, u6, u7, u8;+    uint32_t t9, t0, t1, t2, t3, t4, t5, t6, t7;+    const uint32_t M = 0x3FFFFFFUL, R0 = 0x3D10UL, R1 = 0x400UL;++    VERIFY_BITS(a[0], 30);+    VERIFY_BITS(a[1], 30);+    VERIFY_BITS(a[2], 30);+    VERIFY_BITS(a[3], 30);+    VERIFY_BITS(a[4], 30);+    VERIFY_BITS(a[5], 30);+    VERIFY_BITS(a[6], 30);+    VERIFY_BITS(a[7], 30);+    VERIFY_BITS(a[8], 30);+    VERIFY_BITS(a[9], 26);++    /** [... a b c] is a shorthand for ... + a<<52 + b<<26 + c<<0 mod n.+     *  px is a shorthand for sum(a[i]*a[x-i], i=0..x).+     *  Note that [x 0 0 0 0 0 0 0 0 0 0] = [x*R1 x*R0].+     */++    d  = (uint64_t)(a[0]*2) * a[9]+       + (uint64_t)(a[1]*2) * a[8]+       + (uint64_t)(a[2]*2) * a[7]+       + (uint64_t)(a[3]*2) * a[6]+       + (uint64_t)(a[4]*2) * a[5];+    /* VERIFY_BITS(d, 64); */+    /* [d 0 0 0 0 0 0 0 0 0] = [p9 0 0 0 0 0 0 0 0 0] */+    t9 = d & M; d >>= 26;+    VERIFY_BITS(t9, 26);+    VERIFY_BITS(d, 38);+    /* [d t9 0 0 0 0 0 0 0 0 0] = [p9 0 0 0 0 0 0 0 0 0] */++    c  = (uint64_t)a[0] * a[0];+    VERIFY_BITS(c, 60);+    /* [d t9 0 0 0 0 0 0 0 0 c] = [p9 0 0 0 0 0 0 0 0 p0] */+    d += (uint64_t)(a[1]*2) * a[9]+       + (uint64_t)(a[2]*2) * a[8]+       + (uint64_t)(a[3]*2) * a[7]+       + (uint64_t)(a[4]*2) * a[6]+       + (uint64_t)a[5] * a[5];+    VERIFY_BITS(d, 63);+    /* [d t9 0 0 0 0 0 0 0 0 c] = [p10 p9 0 0 0 0 0 0 0 0 p0] */+    u0 = d & M; d >>= 26; c += u0 * R0;+    VERIFY_BITS(u0, 26);+    VERIFY_BITS(d, 37);+    VERIFY_BITS(c, 61);+    /* [d u0 t9 0 0 0 0 0 0 0 0 c-u0*R0] = [p10 p9 0 0 0 0 0 0 0 0 p0] */+    t0 = c & M; c >>= 26; c += u0 * R1;+    VERIFY_BITS(t0, 26);+    VERIFY_BITS(c, 37);+    /* [d u0 t9 0 0 0 0 0 0 0 c-u0*R1 t0-u0*R0] = [p10 p9 0 0 0 0 0 0 0 0 p0] */+    /* [d 0 t9 0 0 0 0 0 0 0 c t0] = [p10 p9 0 0 0 0 0 0 0 0 p0] */++    c += (uint64_t)(a[0]*2) * a[1];+    VERIFY_BITS(c, 62);+    /* [d 0 t9 0 0 0 0 0 0 0 c t0] = [p10 p9 0 0 0 0 0 0 0 p1 p0] */+    d += (uint64_t)(a[2]*2) * a[9]+       + (uint64_t)(a[3]*2) * a[8]+       + (uint64_t)(a[4]*2) * a[7]+       + (uint64_t)(a[5]*2) * a[6];+    VERIFY_BITS(d, 63);+    /* [d 0 t9 0 0 0 0 0 0 0 c t0] = [p11 p10 p9 0 0 0 0 0 0 0 p1 p0] */+    u1 = d & M; d >>= 26; c += u1 * R0;+    VERIFY_BITS(u1, 26);+    VERIFY_BITS(d, 37);+    VERIFY_BITS(c, 63);+    /* [d u1 0 t9 0 0 0 0 0 0 0 c-u1*R0 t0] = [p11 p10 p9 0 0 0 0 0 0 0 p1 p0] */+    t1 = c & M; c >>= 26; c += u1 * R1;+    VERIFY_BITS(t1, 26);+    VERIFY_BITS(c, 38);+    /* [d u1 0 t9 0 0 0 0 0 0 c-u1*R1 t1-u1*R0 t0] = [p11 p10 p9 0 0 0 0 0 0 0 p1 p0] */+    /* [d 0 0 t9 0 0 0 0 0 0 c t1 t0] = [p11 p10 p9 0 0 0 0 0 0 0 p1 p0] */++    c += (uint64_t)(a[0]*2) * a[2]+       + (uint64_t)a[1] * a[1];+    VERIFY_BITS(c, 62);+    /* [d 0 0 t9 0 0 0 0 0 0 c t1 t0] = [p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */+    d += (uint64_t)(a[3]*2) * a[9]+       + (uint64_t)(a[4]*2) * a[8]+       + (uint64_t)(a[5]*2) * a[7]+       + (uint64_t)a[6] * a[6];+    VERIFY_BITS(d, 63);+    /* [d 0 0 t9 0 0 0 0 0 0 c t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */+    u2 = d & M; d >>= 26; c += u2 * R0;+    VERIFY_BITS(u2, 26);+    VERIFY_BITS(d, 37);+    VERIFY_BITS(c, 63);+    /* [d u2 0 0 t9 0 0 0 0 0 0 c-u2*R0 t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */+    t2 = c & M; c >>= 26; c += u2 * R1;+    VERIFY_BITS(t2, 26);+    VERIFY_BITS(c, 38);+    /* [d u2 0 0 t9 0 0 0 0 0 c-u2*R1 t2-u2*R0 t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */+    /* [d 0 0 0 t9 0 0 0 0 0 c t2 t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 0 p2 p1 p0] */++    c += (uint64_t)(a[0]*2) * a[3]+       + (uint64_t)(a[1]*2) * a[2];+    VERIFY_BITS(c, 63);+    /* [d 0 0 0 t9 0 0 0 0 0 c t2 t1 t0] = [p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */+    d += (uint64_t)(a[4]*2) * a[9]+       + (uint64_t)(a[5]*2) * a[8]+       + (uint64_t)(a[6]*2) * a[7];+    VERIFY_BITS(d, 63);+    /* [d 0 0 0 t9 0 0 0 0 0 c t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */+    u3 = d & M; d >>= 26; c += u3 * R0;+    VERIFY_BITS(u3, 26);+    VERIFY_BITS(d, 37);+    /* VERIFY_BITS(c, 64); */+    /* [d u3 0 0 0 t9 0 0 0 0 0 c-u3*R0 t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */+    t3 = c & M; c >>= 26; c += u3 * R1;+    VERIFY_BITS(t3, 26);+    VERIFY_BITS(c, 39);+    /* [d u3 0 0 0 t9 0 0 0 0 c-u3*R1 t3-u3*R0 t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */+    /* [d 0 0 0 0 t9 0 0 0 0 c t3 t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 0 p3 p2 p1 p0] */++    c += (uint64_t)(a[0]*2) * a[4]+       + (uint64_t)(a[1]*2) * a[3]+       + (uint64_t)a[2] * a[2];+    VERIFY_BITS(c, 63);+    /* [d 0 0 0 0 t9 0 0 0 0 c t3 t2 t1 t0] = [p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */+    d += (uint64_t)(a[5]*2) * a[9]+       + (uint64_t)(a[6]*2) * a[8]+       + (uint64_t)a[7] * a[7];+    VERIFY_BITS(d, 62);+    /* [d 0 0 0 0 t9 0 0 0 0 c t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */+    u4 = d & M; d >>= 26; c += u4 * R0;+    VERIFY_BITS(u4, 26);+    VERIFY_BITS(d, 36);+    /* VERIFY_BITS(c, 64); */+    /* [d u4 0 0 0 0 t9 0 0 0 0 c-u4*R0 t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */+    t4 = c & M; c >>= 26; c += u4 * R1;+    VERIFY_BITS(t4, 26);+    VERIFY_BITS(c, 39);+    /* [d u4 0 0 0 0 t9 0 0 0 c-u4*R1 t4-u4*R0 t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 t9 0 0 0 c t4 t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 0 p4 p3 p2 p1 p0] */++    c += (uint64_t)(a[0]*2) * a[5]+       + (uint64_t)(a[1]*2) * a[4]+       + (uint64_t)(a[2]*2) * a[3];+    VERIFY_BITS(c, 63);+    /* [d 0 0 0 0 0 t9 0 0 0 c t4 t3 t2 t1 t0] = [p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */+    d += (uint64_t)(a[6]*2) * a[9]+       + (uint64_t)(a[7]*2) * a[8];+    VERIFY_BITS(d, 62);+    /* [d 0 0 0 0 0 t9 0 0 0 c t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */+    u5 = d & M; d >>= 26; c += u5 * R0;+    VERIFY_BITS(u5, 26);+    VERIFY_BITS(d, 36);+    /* VERIFY_BITS(c, 64); */+    /* [d u5 0 0 0 0 0 t9 0 0 0 c-u5*R0 t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */+    t5 = c & M; c >>= 26; c += u5 * R1;+    VERIFY_BITS(t5, 26);+    VERIFY_BITS(c, 39);+    /* [d u5 0 0 0 0 0 t9 0 0 c-u5*R1 t5-u5*R0 t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 t9 0 0 c t5 t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 0 p5 p4 p3 p2 p1 p0] */++    c += (uint64_t)(a[0]*2) * a[6]+       + (uint64_t)(a[1]*2) * a[5]+       + (uint64_t)(a[2]*2) * a[4]+       + (uint64_t)a[3] * a[3];+    VERIFY_BITS(c, 63);+    /* [d 0 0 0 0 0 0 t9 0 0 c t5 t4 t3 t2 t1 t0] = [p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */+    d += (uint64_t)(a[7]*2) * a[9]+       + (uint64_t)a[8] * a[8];+    VERIFY_BITS(d, 61);+    /* [d 0 0 0 0 0 0 t9 0 0 c t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */+    u6 = d & M; d >>= 26; c += u6 * R0;+    VERIFY_BITS(u6, 26);+    VERIFY_BITS(d, 35);+    /* VERIFY_BITS(c, 64); */+    /* [d u6 0 0 0 0 0 0 t9 0 0 c-u6*R0 t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */+    t6 = c & M; c >>= 26; c += u6 * R1;+    VERIFY_BITS(t6, 26);+    VERIFY_BITS(c, 39);+    /* [d u6 0 0 0 0 0 0 t9 0 c-u6*R1 t6-u6*R0 t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 0 t9 0 c t6 t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 0 p6 p5 p4 p3 p2 p1 p0] */++    c += (uint64_t)(a[0]*2) * a[7]+       + (uint64_t)(a[1]*2) * a[6]+       + (uint64_t)(a[2]*2) * a[5]+       + (uint64_t)(a[3]*2) * a[4];+    /* VERIFY_BITS(c, 64); */+    VERIFY_CHECK(c <= 0x8000007C00000007ULL);+    /* [d 0 0 0 0 0 0 0 t9 0 c t6 t5 t4 t3 t2 t1 t0] = [p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */+    d += (uint64_t)(a[8]*2) * a[9];+    VERIFY_BITS(d, 58);+    /* [d 0 0 0 0 0 0 0 t9 0 c t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */+    u7 = d & M; d >>= 26; c += u7 * R0;+    VERIFY_BITS(u7, 26);+    VERIFY_BITS(d, 32);+    /* VERIFY_BITS(c, 64); */+    VERIFY_CHECK(c <= 0x800001703FFFC2F7ULL);+    /* [d u7 0 0 0 0 0 0 0 t9 0 c-u7*R0 t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */+    t7 = c & M; c >>= 26; c += u7 * R1;+    VERIFY_BITS(t7, 26);+    VERIFY_BITS(c, 38);+    /* [d u7 0 0 0 0 0 0 0 t9 c-u7*R1 t7-u7*R0 t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 0 0 t9 c t7 t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 0 p7 p6 p5 p4 p3 p2 p1 p0] */++    c += (uint64_t)(a[0]*2) * a[8]+       + (uint64_t)(a[1]*2) * a[7]+       + (uint64_t)(a[2]*2) * a[6]+       + (uint64_t)(a[3]*2) * a[5]+       + (uint64_t)a[4] * a[4];+    /* VERIFY_BITS(c, 64); */+    VERIFY_CHECK(c <= 0x9000007B80000008ULL);+    /* [d 0 0 0 0 0 0 0 0 t9 c t7 t6 t5 t4 t3 t2 t1 t0] = [p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    d += (uint64_t)a[9] * a[9];+    VERIFY_BITS(d, 57);+    /* [d 0 0 0 0 0 0 0 0 t9 c t7 t6 t5 t4 t3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    u8 = d & M; d >>= 26; c += u8 * R0;+    VERIFY_BITS(u8, 26);+    VERIFY_BITS(d, 31);+    /* VERIFY_BITS(c, 64); */+    VERIFY_CHECK(c <= 0x9000016FBFFFC2F8ULL);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 t6 t5 t4 t3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */++    r[3] = t3;+    VERIFY_BITS(r[3], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 t6 t5 t4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[4] = t4;+    VERIFY_BITS(r[4], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 t6 t5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[5] = t5;+    VERIFY_BITS(r[5], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 t6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[6] = t6;+    VERIFY_BITS(r[6], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 t7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[7] = t7;+    VERIFY_BITS(r[7], 26);+    /* [d u8 0 0 0 0 0 0 0 0 t9 c-u8*R0 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */++    r[8] = c & M; c >>= 26; c += u8 * R1;+    VERIFY_BITS(r[8], 26);+    VERIFY_BITS(c, 39);+    /* [d u8 0 0 0 0 0 0 0 0 t9+c-u8*R1 r8-u8*R0 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 0 0 0 t9+c r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    c   += d * R0 + t9;+    VERIFY_BITS(c, 45);+    /* [d 0 0 0 0 0 0 0 0 0 c-d*R0 r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[9] = c & (M >> 4); c >>= 22; c += d * (R1 << 4);+    VERIFY_BITS(r[9], 22);+    VERIFY_BITS(c, 46);+    /* [d 0 0 0 0 0 0 0 0 r9+((c-d*R1<<4)<<22)-d*R0 r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [d 0 0 0 0 0 0 0 -d*R1 r9+(c<<22)-d*R0 r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */++    d    = c * (R0 >> 4) + t0;+    VERIFY_BITS(d, 56);+    /* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1 d-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[0] = d & M; d >>= 26;+    VERIFY_BITS(r[0], 26);+    VERIFY_BITS(d, 30);+    /* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1+d r0-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    d   += c * (R1 >> 4) + t1;+    VERIFY_BITS(d, 53);+    VERIFY_CHECK(d <= 0x10000003FFFFBFULL);+    /* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 d-c*R1>>4 r0-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    /* [r9 r8 r7 r6 r5 r4 r3 t2 d r0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[1] = d & M; d >>= 26;+    VERIFY_BITS(r[1], 26);+    VERIFY_BITS(d, 27);+    VERIFY_CHECK(d <= 0x4000000ULL);+    /* [r9 r8 r7 r6 r5 r4 r3 t2+d r1 r0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    d   += t2;+    VERIFY_BITS(d, 27);+    /* [r9 r8 r7 r6 r5 r4 r3 d r1 r0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[2] = d;+    VERIFY_BITS(r[2], 27);+    /* [r9 r8 r7 r6 r5 r4 r3 r2 r1 r0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */+}+#endif++SECP256K1_INLINE static void secp256k1_fe_impl_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe * SECP256K1_RESTRICT b) {+    secp256k1_fe_mul_inner(r->n, a->n, b->n);+}++SECP256K1_INLINE static void secp256k1_fe_impl_sqr(secp256k1_fe *r, const secp256k1_fe *a) {+    secp256k1_fe_sqr_inner(r->n, a->n);+}++SECP256K1_INLINE static void secp256k1_fe_impl_cmov(secp256k1_fe *r, const secp256k1_fe *a, int flag) {+    uint32_t mask0, mask1;+    volatile int vflag = flag;+    SECP256K1_CHECKMEM_CHECK_VERIFY(r->n, sizeof(r->n));+    mask0 = vflag + ~((uint32_t)0);+    mask1 = ~mask0;+    r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);+    r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1);+    r->n[2] = (r->n[2] & mask0) | (a->n[2] & mask1);+    r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1);+    r->n[4] = (r->n[4] & mask0) | (a->n[4] & mask1);+    r->n[5] = (r->n[5] & mask0) | (a->n[5] & mask1);+    r->n[6] = (r->n[6] & mask0) | (a->n[6] & mask1);+    r->n[7] = (r->n[7] & mask0) | (a->n[7] & mask1);+    r->n[8] = (r->n[8] & mask0) | (a->n[8] & mask1);+    r->n[9] = (r->n[9] & mask0) | (a->n[9] & mask1);+}++static SECP256K1_INLINE void secp256k1_fe_impl_half(secp256k1_fe *r) {+    uint32_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4],+             t5 = r->n[5], t6 = r->n[6], t7 = r->n[7], t8 = r->n[8], t9 = r->n[9];+    uint32_t one = (uint32_t)1;+    uint32_t mask = -(t0 & one) >> 6;++    /* Bounds analysis (over the rationals).+     *+     * Let m = r->magnitude+     *     C = 0x3FFFFFFUL * 2+     *     D = 0x03FFFFFUL * 2+     *+     * Initial bounds: t0..t8 <= C * m+     *                     t9 <= D * m+     */++    t0 += 0x3FFFC2FUL & mask;+    t1 += 0x3FFFFBFUL & mask;+    t2 += mask;+    t3 += mask;+    t4 += mask;+    t5 += mask;+    t6 += mask;+    t7 += mask;+    t8 += mask;+    t9 += mask >> 4;++    VERIFY_CHECK((t0 & one) == 0);++    /* t0..t8: added <= C/2+     *     t9: added <= D/2+     *+     * Current bounds: t0..t8 <= C * (m + 1/2)+     *                     t9 <= D * (m + 1/2)+     */++    r->n[0] = (t0 >> 1) + ((t1 & one) << 25);+    r->n[1] = (t1 >> 1) + ((t2 & one) << 25);+    r->n[2] = (t2 >> 1) + ((t3 & one) << 25);+    r->n[3] = (t3 >> 1) + ((t4 & one) << 25);+    r->n[4] = (t4 >> 1) + ((t5 & one) << 25);+    r->n[5] = (t5 >> 1) + ((t6 & one) << 25);+    r->n[6] = (t6 >> 1) + ((t7 & one) << 25);+    r->n[7] = (t7 >> 1) + ((t8 & one) << 25);+    r->n[8] = (t8 >> 1) + ((t9 & one) << 25);+    r->n[9] = (t9 >> 1);++    /* t0..t8: shifted right and added <= C/4 + 1/2+     *     t9: shifted right+     *+     * Current bounds: t0..t8 <= C * (m/2 + 1/2)+     *                     t9 <= D * (m/2 + 1/4)+     *+     * Therefore the output magnitude (M) has to be set such that:+     *     t0..t8: C * M >= C * (m/2 + 1/2)+     *         t9: D * M >= D * (m/2 + 1/4)+     *+     * It suffices for all limbs that, for any input magnitude m:+     *     M >= m/2 + 1/2+     *+     * and since we want the smallest such integer value for M:+     *     M == floor(m/2) + 1+     */+}++static SECP256K1_INLINE void secp256k1_fe_storage_cmov(secp256k1_fe_storage *r, const secp256k1_fe_storage *a, int flag) {+    uint32_t mask0, mask1;+    volatile int vflag = flag;+    SECP256K1_CHECKMEM_CHECK_VERIFY(r->n, sizeof(r->n));+    mask0 = vflag + ~((uint32_t)0);+    mask1 = ~mask0;+    r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);+    r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1);+    r->n[2] = (r->n[2] & mask0) | (a->n[2] & mask1);+    r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1);+    r->n[4] = (r->n[4] & mask0) | (a->n[4] & mask1);+    r->n[5] = (r->n[5] & mask0) | (a->n[5] & mask1);+    r->n[6] = (r->n[6] & mask0) | (a->n[6] & mask1);+    r->n[7] = (r->n[7] & mask0) | (a->n[7] & mask1);+}++static void secp256k1_fe_impl_to_storage(secp256k1_fe_storage *r, const secp256k1_fe *a) {+    r->n[0] = a->n[0] | a->n[1] << 26;+    r->n[1] = a->n[1] >> 6 | a->n[2] << 20;+    r->n[2] = a->n[2] >> 12 | a->n[3] << 14;+    r->n[3] = a->n[3] >> 18 | a->n[4] << 8;+    r->n[4] = a->n[4] >> 24 | a->n[5] << 2 | a->n[6] << 28;+    r->n[5] = a->n[6] >> 4 | a->n[7] << 22;+    r->n[6] = a->n[7] >> 10 | a->n[8] << 16;+    r->n[7] = a->n[8] >> 16 | a->n[9] << 10;+}++static SECP256K1_INLINE void secp256k1_fe_impl_from_storage(secp256k1_fe *r, const secp256k1_fe_storage *a) {+    r->n[0] = a->n[0] & 0x3FFFFFFUL;+    r->n[1] = a->n[0] >> 26 | ((a->n[1] << 6) & 0x3FFFFFFUL);+    r->n[2] = a->n[1] >> 20 | ((a->n[2] << 12) & 0x3FFFFFFUL);+    r->n[3] = a->n[2] >> 14 | ((a->n[3] << 18) & 0x3FFFFFFUL);+    r->n[4] = a->n[3] >> 8 | ((a->n[4] << 24) & 0x3FFFFFFUL);+    r->n[5] = (a->n[4] >> 2) & 0x3FFFFFFUL;+    r->n[6] = a->n[4] >> 28 | ((a->n[5] << 4) & 0x3FFFFFFUL);+    r->n[7] = a->n[5] >> 22 | ((a->n[6] << 10) & 0x3FFFFFFUL);+    r->n[8] = a->n[6] >> 16 | ((a->n[7] << 16) & 0x3FFFFFFUL);+    r->n[9] = a->n[7] >> 10;+}++static void secp256k1_fe_from_signed30(secp256k1_fe *r, const secp256k1_modinv32_signed30 *a) {+    const uint32_t M26 = UINT32_MAX >> 6;+    const uint32_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4],+                   a5 = a->v[5], a6 = a->v[6], a7 = a->v[7], a8 = a->v[8];++    /* The output from secp256k1_modinv32{_var} should be normalized to range [0,modulus), and+     * have limbs in [0,2^30). The modulus is < 2^256, so the top limb must be below 2^(256-30*8).+     */+    VERIFY_CHECK(a0 >> 30 == 0);+    VERIFY_CHECK(a1 >> 30 == 0);+    VERIFY_CHECK(a2 >> 30 == 0);+    VERIFY_CHECK(a3 >> 30 == 0);+    VERIFY_CHECK(a4 >> 30 == 0);+    VERIFY_CHECK(a5 >> 30 == 0);+    VERIFY_CHECK(a6 >> 30 == 0);+    VERIFY_CHECK(a7 >> 30 == 0);+    VERIFY_CHECK(a8 >> 16 == 0);++    r->n[0] =  a0                   & M26;+    r->n[1] = (a0 >> 26 | a1 <<  4) & M26;+    r->n[2] = (a1 >> 22 | a2 <<  8) & M26;+    r->n[3] = (a2 >> 18 | a3 << 12) & M26;+    r->n[4] = (a3 >> 14 | a4 << 16) & M26;+    r->n[5] = (a4 >> 10 | a5 << 20) & M26;+    r->n[6] = (a5 >>  6 | a6 << 24) & M26;+    r->n[7] = (a6 >>  2           ) & M26;+    r->n[8] = (a6 >> 28 | a7 <<  2) & M26;+    r->n[9] = (a7 >> 24 | a8 <<  6);+}++static void secp256k1_fe_to_signed30(secp256k1_modinv32_signed30 *r, const secp256k1_fe *a) {+    const uint32_t M30 = UINT32_MAX >> 2;+    const uint64_t a0 = a->n[0], a1 = a->n[1], a2 = a->n[2], a3 = a->n[3], a4 = a->n[4],+                   a5 = a->n[5], a6 = a->n[6], a7 = a->n[7], a8 = a->n[8], a9 = a->n[9];++    r->v[0] = (a0       | a1 << 26) & M30;+    r->v[1] = (a1 >>  4 | a2 << 22) & M30;+    r->v[2] = (a2 >>  8 | a3 << 18) & M30;+    r->v[3] = (a3 >> 12 | a4 << 14) & M30;+    r->v[4] = (a4 >> 16 | a5 << 10) & M30;+    r->v[5] = (a5 >> 20 | a6 <<  6) & M30;+    r->v[6] = (a6 >> 24 | a7 <<  2+                        | a8 << 28) & M30;+    r->v[7] = (a8 >>  2 | a9 << 24) & M30;+    r->v[8] =  a9 >>  6;+}++static const secp256k1_modinv32_modinfo secp256k1_const_modinfo_fe = {+    {{-0x3D1, -4, 0, 0, 0, 0, 0, 0, 65536}},+    0x2DDACACFL+};++static void secp256k1_fe_impl_inv(secp256k1_fe *r, const secp256k1_fe *x) {+    secp256k1_fe tmp = *x;+    secp256k1_modinv32_signed30 s;++    secp256k1_fe_normalize(&tmp);+    secp256k1_fe_to_signed30(&s, &tmp);+    secp256k1_modinv32(&s, &secp256k1_const_modinfo_fe);+    secp256k1_fe_from_signed30(r, &s);+}++static void secp256k1_fe_impl_inv_var(secp256k1_fe *r, const secp256k1_fe *x) {+    secp256k1_fe tmp = *x;+    secp256k1_modinv32_signed30 s;++    secp256k1_fe_normalize_var(&tmp);+    secp256k1_fe_to_signed30(&s, &tmp);+    secp256k1_modinv32_var(&s, &secp256k1_const_modinfo_fe);+    secp256k1_fe_from_signed30(r, &s);+}++static int secp256k1_fe_impl_is_square_var(const secp256k1_fe *x) {+    secp256k1_fe tmp;+    secp256k1_modinv32_signed30 s;+    int jac, ret;++    tmp = *x;+    secp256k1_fe_normalize_var(&tmp);+    /* secp256k1_jacobi32_maybe_var cannot deal with input 0. */+    if (secp256k1_fe_is_zero(&tmp)) return 1;+    secp256k1_fe_to_signed30(&s, &tmp);+    jac = secp256k1_jacobi32_maybe_var(&s, &secp256k1_const_modinfo_fe);+    if (jac == 0) {+        /* secp256k1_jacobi32_maybe_var failed to compute the Jacobi symbol. Fall back+         * to computing a square root. This should be extremely rare with random+         * input (except in VERIFY mode, where a lower iteration count is used). */+        secp256k1_fe dummy;+        ret = secp256k1_fe_sqrt(&dummy, &tmp);+    } else {+        ret = jac >= 0;+    }+    return ret;+}++#endif /* SECP256K1_FIELD_REPR_IMPL_H */
+ vendor/external/secp256k1/src/field_5x52.h view
@@ -0,0 +1,62 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_FIELD_REPR_H+#define SECP256K1_FIELD_REPR_H++#include <stdint.h>++/** This field implementation represents the value as 5 uint64_t limbs in base+ *  2^52. */+typedef struct {+   /* A field element f represents the sum(i=0..4, f.n[i] << (i*52)) mod p,+    * where p is the field modulus, 2^256 - 2^32 - 977.+    *+    * The individual limbs f.n[i] can exceed 2^52; the field's magnitude roughly+    * corresponds to how much excess is allowed. The value+    * sum(i=0..4, f.n[i] << (i*52)) may exceed p, unless the field element is+    * normalized. */+    uint64_t n[5];+    /*+     * Magnitude m requires:+     *     n[i] <= 2 * m * (2^52 - 1) for i=0..3+     *     n[4] <= 2 * m * (2^48 - 1)+     *+     * Normalized requires:+     *     n[i] <= (2^52 - 1) for i=0..3+     *     sum(i=0..4, n[i] << (i*52)) < p+     *     (together these imply n[4] <= 2^48 - 1)+     */+    SECP256K1_FE_VERIFY_FIELDS+} secp256k1_fe;++/* Unpacks a constant into a overlapping multi-limbed FE element. */+#define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \+    (d0) | (((uint64_t)(d1) & 0xFFFFFUL) << 32), \+    ((uint64_t)(d1) >> 20) | (((uint64_t)(d2)) << 12) | (((uint64_t)(d3) & 0xFFUL) << 44), \+    ((uint64_t)(d3) >> 8) | (((uint64_t)(d4) & 0xFFFFFFFUL) << 24), \+    ((uint64_t)(d4) >> 28) | (((uint64_t)(d5)) << 4) | (((uint64_t)(d6) & 0xFFFFUL) << 36), \+    ((uint64_t)(d6) >> 16) | (((uint64_t)(d7)) << 16) \+}++typedef struct {+    uint64_t n[4];+} secp256k1_fe_storage;++#define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ \+    (d0) | (((uint64_t)(d1)) << 32), \+    (d2) | (((uint64_t)(d3)) << 32), \+    (d4) | (((uint64_t)(d5)) << 32), \+    (d6) | (((uint64_t)(d7)) << 32) \+}}++#define SECP256K1_FE_STORAGE_CONST_GET(d) \+    (uint32_t)(d.n[3] >> 32), (uint32_t)d.n[3], \+    (uint32_t)(d.n[2] >> 32), (uint32_t)d.n[2], \+    (uint32_t)(d.n[1] >> 32), (uint32_t)d.n[1], \+    (uint32_t)(d.n[0] >> 32), (uint32_t)d.n[0]++#endif /* SECP256K1_FIELD_REPR_H */
+ vendor/external/secp256k1/src/field_5x52_impl.h view
@@ -0,0 +1,522 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_FIELD_REPR_IMPL_H+#define SECP256K1_FIELD_REPR_IMPL_H++#include "checkmem.h"+#include "util.h"+#include "field.h"+#include "modinv64_impl.h"++#include "field_5x52_int128_impl.h"++#ifdef VERIFY+static void secp256k1_fe_impl_verify(const secp256k1_fe *a) {+    const uint64_t *d = a->n;+    int m = a->normalized ? 1 : 2 * a->magnitude;+   /* secp256k1 'p' value defined in "Standards for Efficient Cryptography" (SEC2) 2.7.1. */+    VERIFY_CHECK(d[0] <= 0xFFFFFFFFFFFFFULL * m);+    VERIFY_CHECK(d[1] <= 0xFFFFFFFFFFFFFULL * m);+    VERIFY_CHECK(d[2] <= 0xFFFFFFFFFFFFFULL * m);+    VERIFY_CHECK(d[3] <= 0xFFFFFFFFFFFFFULL * m);+    VERIFY_CHECK(d[4] <= 0x0FFFFFFFFFFFFULL * m);+    if (a->normalized) {+        if ((d[4] == 0x0FFFFFFFFFFFFULL) && ((d[3] & d[2] & d[1]) == 0xFFFFFFFFFFFFFULL)) {+            VERIFY_CHECK(d[0] < 0xFFFFEFFFFFC2FULL);+        }+    }+}+#endif++static void secp256k1_fe_impl_get_bounds(secp256k1_fe *r, int m) {+    r->n[0] = 0xFFFFFFFFFFFFFULL * 2 * m;+    r->n[1] = 0xFFFFFFFFFFFFFULL * 2 * m;+    r->n[2] = 0xFFFFFFFFFFFFFULL * 2 * m;+    r->n[3] = 0xFFFFFFFFFFFFFULL * 2 * m;+    r->n[4] = 0x0FFFFFFFFFFFFULL * 2 * m;+}++static void secp256k1_fe_impl_normalize(secp256k1_fe *r) {+    uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4];++    /* Reduce t4 at the start so there will be at most a single carry from the first pass */+    uint64_t m;+    uint64_t x = t4 >> 48; t4 &= 0x0FFFFFFFFFFFFULL;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x1000003D1ULL;+    t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;+    t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL; m = t1;+    t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL; m &= t2;+    t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL; m &= t3;++    /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t4 >> 49 == 0);++    /* At most a single final reduction is needed; check if the value is >= the field characteristic */+    x = (t4 >> 48) | ((t4 == 0x0FFFFFFFFFFFFULL) & (m == 0xFFFFFFFFFFFFFULL)+        & (t0 >= 0xFFFFEFFFFFC2FULL));++    /* Apply the final reduction (for constant-time behaviour, we do it always) */+    t0 += x * 0x1000003D1ULL;+    t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;+    t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL;+    t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL;+    t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL;++    /* If t4 didn't carry to bit 48 already, then it should have after any final reduction */+    VERIFY_CHECK(t4 >> 48 == x);++    /* Mask off the possible multiple of 2^256 from the final reduction */+    t4 &= 0x0FFFFFFFFFFFFULL;++    r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4;+}++static void secp256k1_fe_impl_normalize_weak(secp256k1_fe *r) {+    uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4];++    /* Reduce t4 at the start so there will be at most a single carry from the first pass */+    uint64_t x = t4 >> 48; t4 &= 0x0FFFFFFFFFFFFULL;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x1000003D1ULL;+    t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;+    t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL;+    t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL;+    t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL;++    /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t4 >> 49 == 0);++    r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4;+}++static void secp256k1_fe_impl_normalize_var(secp256k1_fe *r) {+    uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4];++    /* Reduce t4 at the start so there will be at most a single carry from the first pass */+    uint64_t m;+    uint64_t x = t4 >> 48; t4 &= 0x0FFFFFFFFFFFFULL;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x1000003D1ULL;+    t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;+    t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL; m = t1;+    t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL; m &= t2;+    t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL; m &= t3;++    /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t4 >> 49 == 0);++    /* At most a single final reduction is needed; check if the value is >= the field characteristic */+    x = (t4 >> 48) | ((t4 == 0x0FFFFFFFFFFFFULL) & (m == 0xFFFFFFFFFFFFFULL)+        & (t0 >= 0xFFFFEFFFFFC2FULL));++    if (x) {+        t0 += 0x1000003D1ULL;+        t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL;+        t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL;+        t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL;+        t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL;++        /* If t4 didn't carry to bit 48 already, then it should have after any final reduction */+        VERIFY_CHECK(t4 >> 48 == x);++        /* Mask off the possible multiple of 2^256 from the final reduction */+        t4 &= 0x0FFFFFFFFFFFFULL;+    }++    r->n[0] = t0; r->n[1] = t1; r->n[2] = t2; r->n[3] = t3; r->n[4] = t4;+}++static int secp256k1_fe_impl_normalizes_to_zero(const secp256k1_fe *r) {+    uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4];++    /* z0 tracks a possible raw value of 0, z1 tracks a possible raw value of P */+    uint64_t z0, z1;++    /* Reduce t4 at the start so there will be at most a single carry from the first pass */+    uint64_t x = t4 >> 48; t4 &= 0x0FFFFFFFFFFFFULL;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x1000003D1ULL;+    t1 += (t0 >> 52); t0 &= 0xFFFFFFFFFFFFFULL; z0  = t0; z1  = t0 ^ 0x1000003D0ULL;+    t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL; z0 |= t1; z1 &= t1;+    t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL; z0 |= t2; z1 &= t2;+    t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL; z0 |= t3; z1 &= t3;+                                                z0 |= t4; z1 &= t4 ^ 0xF000000000000ULL;++    /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t4 >> 49 == 0);++    return (z0 == 0) | (z1 == 0xFFFFFFFFFFFFFULL);+}++static int secp256k1_fe_impl_normalizes_to_zero_var(const secp256k1_fe *r) {+    uint64_t t0, t1, t2, t3, t4;+    uint64_t z0, z1;+    uint64_t x;++    t0 = r->n[0];+    t4 = r->n[4];++    /* Reduce t4 at the start so there will be at most a single carry from the first pass */+    x = t4 >> 48;++    /* The first pass ensures the magnitude is 1, ... */+    t0 += x * 0x1000003D1ULL;++    /* z0 tracks a possible raw value of 0, z1 tracks a possible raw value of P */+    z0 = t0 & 0xFFFFFFFFFFFFFULL;+    z1 = z0 ^ 0x1000003D0ULL;++    /* Fast return path should catch the majority of cases */+    if ((z0 != 0ULL) & (z1 != 0xFFFFFFFFFFFFFULL)) {+        return 0;+    }++    t1 = r->n[1];+    t2 = r->n[2];+    t3 = r->n[3];++    t4 &= 0x0FFFFFFFFFFFFULL;++    t1 += (t0 >> 52);+    t2 += (t1 >> 52); t1 &= 0xFFFFFFFFFFFFFULL; z0 |= t1; z1 &= t1;+    t3 += (t2 >> 52); t2 &= 0xFFFFFFFFFFFFFULL; z0 |= t2; z1 &= t2;+    t4 += (t3 >> 52); t3 &= 0xFFFFFFFFFFFFFULL; z0 |= t3; z1 &= t3;+                                                z0 |= t4; z1 &= t4 ^ 0xF000000000000ULL;++    /* ... except for a possible carry at bit 48 of t4 (i.e. bit 256 of the field element) */+    VERIFY_CHECK(t4 >> 49 == 0);++    return (z0 == 0) | (z1 == 0xFFFFFFFFFFFFFULL);+}++SECP256K1_INLINE static void secp256k1_fe_impl_set_int(secp256k1_fe *r, int a) {+    r->n[0] = a;+    r->n[1] = r->n[2] = r->n[3] = r->n[4] = 0;+}++SECP256K1_INLINE static int secp256k1_fe_impl_is_zero(const secp256k1_fe *a) {+    const uint64_t *t = a->n;+    return (t[0] | t[1] | t[2] | t[3] | t[4]) == 0;+}++SECP256K1_INLINE static int secp256k1_fe_impl_is_odd(const secp256k1_fe *a) {+    return a->n[0] & 1;+}++static int secp256k1_fe_impl_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b) {+    int i;+    for (i = 4; i >= 0; i--) {+        if (a->n[i] > b->n[i]) {+            return 1;+        }+        if (a->n[i] < b->n[i]) {+            return -1;+        }+    }+    return 0;+}++static void secp256k1_fe_impl_set_b32_mod(secp256k1_fe *r, const unsigned char *a) {+    r->n[0] = (uint64_t)a[31]+            | ((uint64_t)a[30] << 8)+            | ((uint64_t)a[29] << 16)+            | ((uint64_t)a[28] << 24)+            | ((uint64_t)a[27] << 32)+            | ((uint64_t)a[26] << 40)+            | ((uint64_t)(a[25] & 0xF)  << 48);+    r->n[1] = (uint64_t)((a[25] >> 4) & 0xF)+            | ((uint64_t)a[24] << 4)+            | ((uint64_t)a[23] << 12)+            | ((uint64_t)a[22] << 20)+            | ((uint64_t)a[21] << 28)+            | ((uint64_t)a[20] << 36)+            | ((uint64_t)a[19] << 44);+    r->n[2] = (uint64_t)a[18]+            | ((uint64_t)a[17] << 8)+            | ((uint64_t)a[16] << 16)+            | ((uint64_t)a[15] << 24)+            | ((uint64_t)a[14] << 32)+            | ((uint64_t)a[13] << 40)+            | ((uint64_t)(a[12] & 0xF) << 48);+    r->n[3] = (uint64_t)((a[12] >> 4) & 0xF)+            | ((uint64_t)a[11] << 4)+            | ((uint64_t)a[10] << 12)+            | ((uint64_t)a[9]  << 20)+            | ((uint64_t)a[8]  << 28)+            | ((uint64_t)a[7]  << 36)+            | ((uint64_t)a[6]  << 44);+    r->n[4] = (uint64_t)a[5]+            | ((uint64_t)a[4] << 8)+            | ((uint64_t)a[3] << 16)+            | ((uint64_t)a[2] << 24)+            | ((uint64_t)a[1] << 32)+            | ((uint64_t)a[0] << 40);+}++static int secp256k1_fe_impl_set_b32_limit(secp256k1_fe *r, const unsigned char *a) {+    secp256k1_fe_impl_set_b32_mod(r, a);+    return !((r->n[4] == 0x0FFFFFFFFFFFFULL) & ((r->n[3] & r->n[2] & r->n[1]) == 0xFFFFFFFFFFFFFULL) & (r->n[0] >= 0xFFFFEFFFFFC2FULL));+}++/** Convert a field element to a 32-byte big endian value. Requires the input to be normalized */+static void secp256k1_fe_impl_get_b32(unsigned char *r, const secp256k1_fe *a) {+    r[0] = (a->n[4] >> 40) & 0xFF;+    r[1] = (a->n[4] >> 32) & 0xFF;+    r[2] = (a->n[4] >> 24) & 0xFF;+    r[3] = (a->n[4] >> 16) & 0xFF;+    r[4] = (a->n[4] >> 8) & 0xFF;+    r[5] = a->n[4] & 0xFF;+    r[6] = (a->n[3] >> 44) & 0xFF;+    r[7] = (a->n[3] >> 36) & 0xFF;+    r[8] = (a->n[3] >> 28) & 0xFF;+    r[9] = (a->n[3] >> 20) & 0xFF;+    r[10] = (a->n[3] >> 12) & 0xFF;+    r[11] = (a->n[3] >> 4) & 0xFF;+    r[12] = ((a->n[2] >> 48) & 0xF) | ((a->n[3] & 0xF) << 4);+    r[13] = (a->n[2] >> 40) & 0xFF;+    r[14] = (a->n[2] >> 32) & 0xFF;+    r[15] = (a->n[2] >> 24) & 0xFF;+    r[16] = (a->n[2] >> 16) & 0xFF;+    r[17] = (a->n[2] >> 8) & 0xFF;+    r[18] = a->n[2] & 0xFF;+    r[19] = (a->n[1] >> 44) & 0xFF;+    r[20] = (a->n[1] >> 36) & 0xFF;+    r[21] = (a->n[1] >> 28) & 0xFF;+    r[22] = (a->n[1] >> 20) & 0xFF;+    r[23] = (a->n[1] >> 12) & 0xFF;+    r[24] = (a->n[1] >> 4) & 0xFF;+    r[25] = ((a->n[0] >> 48) & 0xF) | ((a->n[1] & 0xF) << 4);+    r[26] = (a->n[0] >> 40) & 0xFF;+    r[27] = (a->n[0] >> 32) & 0xFF;+    r[28] = (a->n[0] >> 24) & 0xFF;+    r[29] = (a->n[0] >> 16) & 0xFF;+    r[30] = (a->n[0] >> 8) & 0xFF;+    r[31] = a->n[0] & 0xFF;+}++SECP256K1_INLINE static void secp256k1_fe_impl_negate_unchecked(secp256k1_fe *r, const secp256k1_fe *a, int m) {+    /* For all legal values of m (0..31), the following properties hold: */+    VERIFY_CHECK(0xFFFFEFFFFFC2FULL * 2 * (m + 1) >= 0xFFFFFFFFFFFFFULL * 2 * m);+    VERIFY_CHECK(0xFFFFFFFFFFFFFULL * 2 * (m + 1) >= 0xFFFFFFFFFFFFFULL * 2 * m);+    VERIFY_CHECK(0x0FFFFFFFFFFFFULL * 2 * (m + 1) >= 0x0FFFFFFFFFFFFULL * 2 * m);++    /* Due to the properties above, the left hand in the subtractions below is never less than+     * the right hand. */+    r->n[0] = 0xFFFFEFFFFFC2FULL * 2 * (m + 1) - a->n[0];+    r->n[1] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[1];+    r->n[2] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[2];+    r->n[3] = 0xFFFFFFFFFFFFFULL * 2 * (m + 1) - a->n[3];+    r->n[4] = 0x0FFFFFFFFFFFFULL * 2 * (m + 1) - a->n[4];+}++SECP256K1_INLINE static void secp256k1_fe_impl_mul_int_unchecked(secp256k1_fe *r, int a) {+    r->n[0] *= a;+    r->n[1] *= a;+    r->n[2] *= a;+    r->n[3] *= a;+    r->n[4] *= a;+}++SECP256K1_INLINE static void secp256k1_fe_impl_add_int(secp256k1_fe *r, int a) {+    r->n[0] += a;+}++SECP256K1_INLINE static void secp256k1_fe_impl_add(secp256k1_fe *r, const secp256k1_fe *a) {+    r->n[0] += a->n[0];+    r->n[1] += a->n[1];+    r->n[2] += a->n[2];+    r->n[3] += a->n[3];+    r->n[4] += a->n[4];+}++SECP256K1_INLINE static void secp256k1_fe_impl_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe * SECP256K1_RESTRICT b) {+    secp256k1_fe_mul_inner(r->n, a->n, b->n);+}++SECP256K1_INLINE static void secp256k1_fe_impl_sqr(secp256k1_fe *r, const secp256k1_fe *a) {+    secp256k1_fe_sqr_inner(r->n, a->n);+}++SECP256K1_INLINE static void secp256k1_fe_impl_cmov(secp256k1_fe *r, const secp256k1_fe *a, int flag) {+    uint64_t mask0, mask1;+    volatile int vflag = flag;+    SECP256K1_CHECKMEM_CHECK_VERIFY(r->n, sizeof(r->n));+    mask0 = vflag + ~((uint64_t)0);+    mask1 = ~mask0;+    r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);+    r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1);+    r->n[2] = (r->n[2] & mask0) | (a->n[2] & mask1);+    r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1);+    r->n[4] = (r->n[4] & mask0) | (a->n[4] & mask1);+}++static SECP256K1_INLINE void secp256k1_fe_impl_half(secp256k1_fe *r) {+    uint64_t t0 = r->n[0], t1 = r->n[1], t2 = r->n[2], t3 = r->n[3], t4 = r->n[4];+    uint64_t one = (uint64_t)1;+    uint64_t mask = -(t0 & one) >> 12;++    /* Bounds analysis (over the rationals).+     *+     * Let m = r->magnitude+     *     C = 0xFFFFFFFFFFFFFULL * 2+     *     D = 0x0FFFFFFFFFFFFULL * 2+     *+     * Initial bounds: t0..t3 <= C * m+     *                     t4 <= D * m+     */++    t0 += 0xFFFFEFFFFFC2FULL & mask;+    t1 += mask;+    t2 += mask;+    t3 += mask;+    t4 += mask >> 4;++    VERIFY_CHECK((t0 & one) == 0);++    /* t0..t3: added <= C/2+     *     t4: added <= D/2+     *+     * Current bounds: t0..t3 <= C * (m + 1/2)+     *                     t4 <= D * (m + 1/2)+     */++    r->n[0] = (t0 >> 1) + ((t1 & one) << 51);+    r->n[1] = (t1 >> 1) + ((t2 & one) << 51);+    r->n[2] = (t2 >> 1) + ((t3 & one) << 51);+    r->n[3] = (t3 >> 1) + ((t4 & one) << 51);+    r->n[4] = (t4 >> 1);++    /* t0..t3: shifted right and added <= C/4 + 1/2+     *     t4: shifted right+     *+     * Current bounds: t0..t3 <= C * (m/2 + 1/2)+     *                     t4 <= D * (m/2 + 1/4)+     *+     * Therefore the output magnitude (M) has to be set such that:+     *     t0..t3: C * M >= C * (m/2 + 1/2)+     *         t4: D * M >= D * (m/2 + 1/4)+     *+     * It suffices for all limbs that, for any input magnitude m:+     *     M >= m/2 + 1/2+     *+     * and since we want the smallest such integer value for M:+     *     M == floor(m/2) + 1+     */+}++static SECP256K1_INLINE void secp256k1_fe_storage_cmov(secp256k1_fe_storage *r, const secp256k1_fe_storage *a, int flag) {+    uint64_t mask0, mask1;+    volatile int vflag = flag;+    SECP256K1_CHECKMEM_CHECK_VERIFY(r->n, sizeof(r->n));+    mask0 = vflag + ~((uint64_t)0);+    mask1 = ~mask0;+    r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);+    r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1);+    r->n[2] = (r->n[2] & mask0) | (a->n[2] & mask1);+    r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1);+}++static void secp256k1_fe_impl_to_storage(secp256k1_fe_storage *r, const secp256k1_fe *a) {+    r->n[0] = a->n[0] | a->n[1] << 52;+    r->n[1] = a->n[1] >> 12 | a->n[2] << 40;+    r->n[2] = a->n[2] >> 24 | a->n[3] << 28;+    r->n[3] = a->n[3] >> 36 | a->n[4] << 16;+}++static SECP256K1_INLINE void secp256k1_fe_impl_from_storage(secp256k1_fe *r, const secp256k1_fe_storage *a) {+    r->n[0] = a->n[0] & 0xFFFFFFFFFFFFFULL;+    r->n[1] = a->n[0] >> 52 | ((a->n[1] << 12) & 0xFFFFFFFFFFFFFULL);+    r->n[2] = a->n[1] >> 40 | ((a->n[2] << 24) & 0xFFFFFFFFFFFFFULL);+    r->n[3] = a->n[2] >> 28 | ((a->n[3] << 36) & 0xFFFFFFFFFFFFFULL);+    r->n[4] = a->n[3] >> 16;+}++static void secp256k1_fe_from_signed62(secp256k1_fe *r, const secp256k1_modinv64_signed62 *a) {+    const uint64_t M52 = UINT64_MAX >> 12;+    const uint64_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4];++    /* The output from secp256k1_modinv64{_var} should be normalized to range [0,modulus), and+     * have limbs in [0,2^62). The modulus is < 2^256, so the top limb must be below 2^(256-62*4).+     */+    VERIFY_CHECK(a0 >> 62 == 0);+    VERIFY_CHECK(a1 >> 62 == 0);+    VERIFY_CHECK(a2 >> 62 == 0);+    VERIFY_CHECK(a3 >> 62 == 0);+    VERIFY_CHECK(a4 >> 8 == 0);++    r->n[0] =  a0                   & M52;+    r->n[1] = (a0 >> 52 | a1 << 10) & M52;+    r->n[2] = (a1 >> 42 | a2 << 20) & M52;+    r->n[3] = (a2 >> 32 | a3 << 30) & M52;+    r->n[4] = (a3 >> 22 | a4 << 40);+}++static void secp256k1_fe_to_signed62(secp256k1_modinv64_signed62 *r, const secp256k1_fe *a) {+    const uint64_t M62 = UINT64_MAX >> 2;+    const uint64_t a0 = a->n[0], a1 = a->n[1], a2 = a->n[2], a3 = a->n[3], a4 = a->n[4];++    r->v[0] = (a0       | a1 << 52) & M62;+    r->v[1] = (a1 >> 10 | a2 << 42) & M62;+    r->v[2] = (a2 >> 20 | a3 << 32) & M62;+    r->v[3] = (a3 >> 30 | a4 << 22) & M62;+    r->v[4] =  a4 >> 40;+}++static const secp256k1_modinv64_modinfo secp256k1_const_modinfo_fe = {+    {{-0x1000003D1LL, 0, 0, 0, 256}},+    0x27C7F6E22DDACACFLL+};++static void secp256k1_fe_impl_inv(secp256k1_fe *r, const secp256k1_fe *x) {+    secp256k1_fe tmp = *x;+    secp256k1_modinv64_signed62 s;++    secp256k1_fe_normalize(&tmp);+    secp256k1_fe_to_signed62(&s, &tmp);+    secp256k1_modinv64(&s, &secp256k1_const_modinfo_fe);+    secp256k1_fe_from_signed62(r, &s);+}++static void secp256k1_fe_impl_inv_var(secp256k1_fe *r, const secp256k1_fe *x) {+    secp256k1_fe tmp = *x;+    secp256k1_modinv64_signed62 s;++    secp256k1_fe_normalize_var(&tmp);+    secp256k1_fe_to_signed62(&s, &tmp);+    secp256k1_modinv64_var(&s, &secp256k1_const_modinfo_fe);+    secp256k1_fe_from_signed62(r, &s);+}++static int secp256k1_fe_impl_is_square_var(const secp256k1_fe *x) {+    secp256k1_fe tmp;+    secp256k1_modinv64_signed62 s;+    int jac, ret;++    tmp = *x;+    secp256k1_fe_normalize_var(&tmp);+    /* secp256k1_jacobi64_maybe_var cannot deal with input 0. */+    if (secp256k1_fe_is_zero(&tmp)) return 1;+    secp256k1_fe_to_signed62(&s, &tmp);+    jac = secp256k1_jacobi64_maybe_var(&s, &secp256k1_const_modinfo_fe);+    if (jac == 0) {+        /* secp256k1_jacobi64_maybe_var failed to compute the Jacobi symbol. Fall back+         * to computing a square root. This should be extremely rare with random+         * input (except in VERIFY mode, where a lower iteration count is used). */+        secp256k1_fe dummy;+        ret = secp256k1_fe_sqrt(&dummy, &tmp);+    } else {+        ret = jac >= 0;+    }+    return ret;+}++#endif /* SECP256K1_FIELD_REPR_IMPL_H */
+ vendor/external/secp256k1/src/field_5x52_int128_impl.h view
@@ -0,0 +1,274 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_FIELD_INNER5X52_IMPL_H+#define SECP256K1_FIELD_INNER5X52_IMPL_H++#include <stdint.h>++#include "int128.h"+#include "util.h"++#define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0)+#define VERIFY_BITS_128(x, n) VERIFY_CHECK(secp256k1_u128_check_bits((x), (n)))++SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint64_t *r, const uint64_t *a, const uint64_t * SECP256K1_RESTRICT b) {+    secp256k1_uint128 c, d;+    uint64_t t3, t4, tx, u0;+    uint64_t a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4];+    const uint64_t M = 0xFFFFFFFFFFFFFULL, R = 0x1000003D10ULL;++    VERIFY_BITS(a[0], 56);+    VERIFY_BITS(a[1], 56);+    VERIFY_BITS(a[2], 56);+    VERIFY_BITS(a[3], 56);+    VERIFY_BITS(a[4], 52);+    VERIFY_BITS(b[0], 56);+    VERIFY_BITS(b[1], 56);+    VERIFY_BITS(b[2], 56);+    VERIFY_BITS(b[3], 56);+    VERIFY_BITS(b[4], 52);+    VERIFY_CHECK(r != b);+    VERIFY_CHECK(a != b);++    /*  [... a b c] is a shorthand for ... + a<<104 + b<<52 + c<<0 mod n.+     *  for 0 <= x <= 4, px is a shorthand for sum(a[i]*b[x-i], i=0..x).+     *  for 4 <= x <= 8, px is a shorthand for sum(a[i]*b[x-i], i=(x-4)..4)+     *  Note that [x 0 0 0 0 0] = [x*R].+     */++    secp256k1_u128_mul(&d, a0, b[3]);+    secp256k1_u128_accum_mul(&d, a1, b[2]);+    secp256k1_u128_accum_mul(&d, a2, b[1]);+    secp256k1_u128_accum_mul(&d, a3, b[0]);+    VERIFY_BITS_128(&d, 114);+    /* [d 0 0 0] = [p3 0 0 0] */+    secp256k1_u128_mul(&c, a4, b[4]);+    VERIFY_BITS_128(&c, 112);+    /* [c 0 0 0 0 d 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */+    secp256k1_u128_accum_mul(&d, R, secp256k1_u128_to_u64(&c)); secp256k1_u128_rshift(&c, 64);+    VERIFY_BITS_128(&d, 115);+    VERIFY_BITS_128(&c, 48);+    /* [(c<<12) 0 0 0 0 0 d 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */+    t3 = secp256k1_u128_to_u64(&d) & M; secp256k1_u128_rshift(&d, 52);+    VERIFY_BITS(t3, 52);+    VERIFY_BITS_128(&d, 63);+    /* [(c<<12) 0 0 0 0 d t3 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */++    secp256k1_u128_accum_mul(&d, a0, b[4]);+    secp256k1_u128_accum_mul(&d, a1, b[3]);+    secp256k1_u128_accum_mul(&d, a2, b[2]);+    secp256k1_u128_accum_mul(&d, a3, b[1]);+    secp256k1_u128_accum_mul(&d, a4, b[0]);+    VERIFY_BITS_128(&d, 115);+    /* [(c<<12) 0 0 0 0 d t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */+    secp256k1_u128_accum_mul(&d, R << 12, secp256k1_u128_to_u64(&c));+    VERIFY_BITS_128(&d, 116);+    /* [d t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */+    t4 = secp256k1_u128_to_u64(&d) & M; secp256k1_u128_rshift(&d, 52);+    VERIFY_BITS(t4, 52);+    VERIFY_BITS_128(&d, 64);+    /* [d t4 t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */+    tx = (t4 >> 48); t4 &= (M >> 4);+    VERIFY_BITS(tx, 4);+    VERIFY_BITS(t4, 48);+    /* [d t4+(tx<<48) t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */++    secp256k1_u128_mul(&c, a0, b[0]);+    VERIFY_BITS_128(&c, 112);+    /* [d t4+(tx<<48) t3 0 0 c] = [p8 0 0 0 p4 p3 0 0 p0] */+    secp256k1_u128_accum_mul(&d, a1, b[4]);+    secp256k1_u128_accum_mul(&d, a2, b[3]);+    secp256k1_u128_accum_mul(&d, a3, b[2]);+    secp256k1_u128_accum_mul(&d, a4, b[1]);+    VERIFY_BITS_128(&d, 114);+    /* [d t4+(tx<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    u0 = secp256k1_u128_to_u64(&d) & M; secp256k1_u128_rshift(&d, 52);+    VERIFY_BITS(u0, 52);+    VERIFY_BITS_128(&d, 62);+    /* [d u0 t4+(tx<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    /* [d 0 t4+(tx<<48)+(u0<<52) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    u0 = (u0 << 4) | tx;+    VERIFY_BITS(u0, 56);+    /* [d 0 t4+(u0<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    secp256k1_u128_accum_mul(&c, u0, R >> 4);+    VERIFY_BITS_128(&c, 113);+    /* [d 0 t4 t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    r[0] = secp256k1_u128_to_u64(&c) & M; secp256k1_u128_rshift(&c, 52);+    VERIFY_BITS(r[0], 52);+    VERIFY_BITS_128(&c, 61);+    /* [d 0 t4 t3 0 c r0] = [p8 0 0 p5 p4 p3 0 0 p0] */++    secp256k1_u128_accum_mul(&c, a0, b[1]);+    secp256k1_u128_accum_mul(&c, a1, b[0]);+    VERIFY_BITS_128(&c, 114);+    /* [d 0 t4 t3 0 c r0] = [p8 0 0 p5 p4 p3 0 p1 p0] */+    secp256k1_u128_accum_mul(&d, a2, b[4]);+    secp256k1_u128_accum_mul(&d, a3, b[3]);+    secp256k1_u128_accum_mul(&d, a4, b[2]);+    VERIFY_BITS_128(&d, 114);+    /* [d 0 t4 t3 0 c r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */+    secp256k1_u128_accum_mul(&c, secp256k1_u128_to_u64(&d) & M, R); secp256k1_u128_rshift(&d, 52);+    VERIFY_BITS_128(&c, 115);+    VERIFY_BITS_128(&d, 62);+    /* [d 0 0 t4 t3 0 c r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */+    r[1] = secp256k1_u128_to_u64(&c) & M; secp256k1_u128_rshift(&c, 52);+    VERIFY_BITS(r[1], 52);+    VERIFY_BITS_128(&c, 63);+    /* [d 0 0 t4 t3 c r1 r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */++    secp256k1_u128_accum_mul(&c, a0, b[2]);+    secp256k1_u128_accum_mul(&c, a1, b[1]);+    secp256k1_u128_accum_mul(&c, a2, b[0]);+    VERIFY_BITS_128(&c, 114);+    /* [d 0 0 t4 t3 c r1 r0] = [p8 0 p6 p5 p4 p3 p2 p1 p0] */+    secp256k1_u128_accum_mul(&d, a3, b[4]);+    secp256k1_u128_accum_mul(&d, a4, b[3]);+    VERIFY_BITS_128(&d, 114);+    /* [d 0 0 t4 t3 c t1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    secp256k1_u128_accum_mul(&c, R, secp256k1_u128_to_u64(&d)); secp256k1_u128_rshift(&d, 64);+    VERIFY_BITS_128(&c, 115);+    VERIFY_BITS_128(&d, 50);+    /* [(d<<12) 0 0 0 t4 t3 c r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */++    r[2] = secp256k1_u128_to_u64(&c) & M; secp256k1_u128_rshift(&c, 52);+    VERIFY_BITS(r[2], 52);+    VERIFY_BITS_128(&c, 63);+    /* [(d<<12) 0 0 0 t4 t3+c r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    secp256k1_u128_accum_mul(&c, R << 12, secp256k1_u128_to_u64(&d));+    secp256k1_u128_accum_u64(&c, t3);+    VERIFY_BITS_128(&c, 100);+    /* [t4 c r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[3] = secp256k1_u128_to_u64(&c) & M; secp256k1_u128_rshift(&c, 52);+    VERIFY_BITS(r[3], 52);+    VERIFY_BITS_128(&c, 48);+    /* [t4+c r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[4] = secp256k1_u128_to_u64(&c) + t4;+    VERIFY_BITS(r[4], 49);+    /* [r4 r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+}++SECP256K1_INLINE static void secp256k1_fe_sqr_inner(uint64_t *r, const uint64_t *a) {+    secp256k1_uint128 c, d;+    uint64_t a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4];+    uint64_t t3, t4, tx, u0;+    const uint64_t M = 0xFFFFFFFFFFFFFULL, R = 0x1000003D10ULL;++    VERIFY_BITS(a[0], 56);+    VERIFY_BITS(a[1], 56);+    VERIFY_BITS(a[2], 56);+    VERIFY_BITS(a[3], 56);+    VERIFY_BITS(a[4], 52);++    /**  [... a b c] is a shorthand for ... + a<<104 + b<<52 + c<<0 mod n.+     *  px is a shorthand for sum(a[i]*a[x-i], i=0..x).+     *  Note that [x 0 0 0 0 0] = [x*R].+     */++    secp256k1_u128_mul(&d, a0*2, a3);+    secp256k1_u128_accum_mul(&d, a1*2, a2);+    VERIFY_BITS_128(&d, 114);+    /* [d 0 0 0] = [p3 0 0 0] */+    secp256k1_u128_mul(&c, a4, a4);+    VERIFY_BITS_128(&c, 112);+    /* [c 0 0 0 0 d 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */+    secp256k1_u128_accum_mul(&d, R, secp256k1_u128_to_u64(&c)); secp256k1_u128_rshift(&c, 64);+    VERIFY_BITS_128(&d, 115);+    VERIFY_BITS_128(&c, 48);+    /* [(c<<12) 0 0 0 0 0 d 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */+    t3 = secp256k1_u128_to_u64(&d) & M; secp256k1_u128_rshift(&d, 52);+    VERIFY_BITS(t3, 52);+    VERIFY_BITS_128(&d, 63);+    /* [(c<<12) 0 0 0 0 d t3 0 0 0] = [p8 0 0 0 0 p3 0 0 0] */++    a4 *= 2;+    secp256k1_u128_accum_mul(&d, a0, a4);+    secp256k1_u128_accum_mul(&d, a1*2, a3);+    secp256k1_u128_accum_mul(&d, a2, a2);+    VERIFY_BITS_128(&d, 115);+    /* [(c<<12) 0 0 0 0 d t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */+    secp256k1_u128_accum_mul(&d, R << 12, secp256k1_u128_to_u64(&c));+    VERIFY_BITS_128(&d, 116);+    /* [d t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */+    t4 = secp256k1_u128_to_u64(&d) & M; secp256k1_u128_rshift(&d, 52);+    VERIFY_BITS(t4, 52);+    VERIFY_BITS_128(&d, 64);+    /* [d t4 t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */+    tx = (t4 >> 48); t4 &= (M >> 4);+    VERIFY_BITS(tx, 4);+    VERIFY_BITS(t4, 48);+    /* [d t4+(tx<<48) t3 0 0 0] = [p8 0 0 0 p4 p3 0 0 0] */++    secp256k1_u128_mul(&c, a0, a0);+    VERIFY_BITS_128(&c, 112);+    /* [d t4+(tx<<48) t3 0 0 c] = [p8 0 0 0 p4 p3 0 0 p0] */+    secp256k1_u128_accum_mul(&d, a1, a4);+    secp256k1_u128_accum_mul(&d, a2*2, a3);+    VERIFY_BITS_128(&d, 114);+    /* [d t4+(tx<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    u0 = secp256k1_u128_to_u64(&d) & M; secp256k1_u128_rshift(&d, 52);+    VERIFY_BITS(u0, 52);+    VERIFY_BITS_128(&d, 62);+    /* [d u0 t4+(tx<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    /* [d 0 t4+(tx<<48)+(u0<<52) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    u0 = (u0 << 4) | tx;+    VERIFY_BITS(u0, 56);+    /* [d 0 t4+(u0<<48) t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    secp256k1_u128_accum_mul(&c, u0, R >> 4);+    VERIFY_BITS_128(&c, 113);+    /* [d 0 t4 t3 0 0 c] = [p8 0 0 p5 p4 p3 0 0 p0] */+    r[0] = secp256k1_u128_to_u64(&c) & M; secp256k1_u128_rshift(&c, 52);+    VERIFY_BITS(r[0], 52);+    VERIFY_BITS_128(&c, 61);+    /* [d 0 t4 t3 0 c r0] = [p8 0 0 p5 p4 p3 0 0 p0] */++    a0 *= 2;+    secp256k1_u128_accum_mul(&c, a0, a1);+    VERIFY_BITS_128(&c, 114);+    /* [d 0 t4 t3 0 c r0] = [p8 0 0 p5 p4 p3 0 p1 p0] */+    secp256k1_u128_accum_mul(&d, a2, a4);+    secp256k1_u128_accum_mul(&d, a3, a3);+    VERIFY_BITS_128(&d, 114);+    /* [d 0 t4 t3 0 c r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */+    secp256k1_u128_accum_mul(&c, secp256k1_u128_to_u64(&d) & M, R); secp256k1_u128_rshift(&d, 52);+    VERIFY_BITS_128(&c, 115);+    VERIFY_BITS_128(&d, 62);+    /* [d 0 0 t4 t3 0 c r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */+    r[1] = secp256k1_u128_to_u64(&c) & M; secp256k1_u128_rshift(&c, 52);+    VERIFY_BITS(r[1], 52);+    VERIFY_BITS_128(&c, 63);+    /* [d 0 0 t4 t3 c r1 r0] = [p8 0 p6 p5 p4 p3 0 p1 p0] */++    secp256k1_u128_accum_mul(&c, a0, a2);+    secp256k1_u128_accum_mul(&c, a1, a1);+    VERIFY_BITS_128(&c, 114);+    /* [d 0 0 t4 t3 c r1 r0] = [p8 0 p6 p5 p4 p3 p2 p1 p0] */+    secp256k1_u128_accum_mul(&d, a3, a4);+    VERIFY_BITS_128(&d, 114);+    /* [d 0 0 t4 t3 c r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    secp256k1_u128_accum_mul(&c, R, secp256k1_u128_to_u64(&d)); secp256k1_u128_rshift(&d, 64);+    VERIFY_BITS_128(&c, 115);+    VERIFY_BITS_128(&d, 50);+    /* [(d<<12) 0 0 0 t4 t3 c r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[2] = secp256k1_u128_to_u64(&c) & M; secp256k1_u128_rshift(&c, 52);+    VERIFY_BITS(r[2], 52);+    VERIFY_BITS_128(&c, 63);+    /* [(d<<12) 0 0 0 t4 t3+c r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */++    secp256k1_u128_accum_mul(&c, R << 12, secp256k1_u128_to_u64(&d));+    secp256k1_u128_accum_u64(&c, t3);+    VERIFY_BITS_128(&c, 100);+    /* [t4 c r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[3] = secp256k1_u128_to_u64(&c) & M; secp256k1_u128_rshift(&c, 52);+    VERIFY_BITS(r[3], 52);+    VERIFY_BITS_128(&c, 48);+    /* [t4+c r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+    r[4] = secp256k1_u128_to_u64(&c) + t4;+    VERIFY_BITS(r[4], 49);+    /* [r4 r3 r2 r1 r0] = [p8 p7 p6 p5 p4 p3 p2 p1 p0] */+}++#endif /* SECP256K1_FIELD_INNER5X52_IMPL_H */
+ vendor/external/secp256k1/src/field_impl.h view
@@ -0,0 +1,457 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_FIELD_IMPL_H+#define SECP256K1_FIELD_IMPL_H++#include "field.h"+#include "util.h"++#if defined(SECP256K1_WIDEMUL_INT128)+#include "field_5x52_impl.h"+#elif defined(SECP256K1_WIDEMUL_INT64)+#include "field_10x26_impl.h"+#else+#error "Please select wide multiplication implementation"+#endif++SECP256K1_INLINE static void secp256k1_fe_clear(secp256k1_fe *a) {+    secp256k1_memclear(a, sizeof(secp256k1_fe));+}++SECP256K1_INLINE static int secp256k1_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b) {+    secp256k1_fe na;+    SECP256K1_FE_VERIFY(a);+    SECP256K1_FE_VERIFY(b);+    SECP256K1_FE_VERIFY_MAGNITUDE(a, 1);+    SECP256K1_FE_VERIFY_MAGNITUDE(b, 31);++    secp256k1_fe_negate(&na, a, 1);+    secp256k1_fe_add(&na, b);+    return secp256k1_fe_normalizes_to_zero(&na);+}++static int secp256k1_fe_sqrt(secp256k1_fe * SECP256K1_RESTRICT r, const secp256k1_fe * SECP256K1_RESTRICT a) {+    /** Given that p is congruent to 3 mod 4, we can compute the square root of+     *  a mod p as the (p+1)/4'th power of a.+     *+     *  As (p+1)/4 is an even number, it will have the same result for a and for+     *  (-a). Only one of these two numbers actually has a square root however,+     *  so we test at the end by squaring and comparing to the input.+     *  Also because (p+1)/4 is an even number, the computed square root is+     *  itself always a square (a ** ((p+1)/4) is the square of a ** ((p+1)/8)).+     */+    secp256k1_fe x2, x3, x6, x9, x11, x22, x44, x88, x176, x220, x223, t1;+    int j, ret;++    VERIFY_CHECK(r != a);+    SECP256K1_FE_VERIFY(a);+    SECP256K1_FE_VERIFY_MAGNITUDE(a, 8);++    /** The binary representation of (p + 1)/4 has 3 blocks of 1s, with lengths in+     *  { 2, 22, 223 }. Use an addition chain to calculate 2^n - 1 for each block:+     *  1, [2], 3, 6, 9, 11, [22], 44, 88, 176, 220, [223]+     */++    secp256k1_fe_sqr(&x2, a);+    secp256k1_fe_mul(&x2, &x2, a);++    secp256k1_fe_sqr(&x3, &x2);+    secp256k1_fe_mul(&x3, &x3, a);++    x6 = x3;+    for (j=0; j<3; j++) {+        secp256k1_fe_sqr(&x6, &x6);+    }+    secp256k1_fe_mul(&x6, &x6, &x3);++    x9 = x6;+    for (j=0; j<3; j++) {+        secp256k1_fe_sqr(&x9, &x9);+    }+    secp256k1_fe_mul(&x9, &x9, &x3);++    x11 = x9;+    for (j=0; j<2; j++) {+        secp256k1_fe_sqr(&x11, &x11);+    }+    secp256k1_fe_mul(&x11, &x11, &x2);++    x22 = x11;+    for (j=0; j<11; j++) {+        secp256k1_fe_sqr(&x22, &x22);+    }+    secp256k1_fe_mul(&x22, &x22, &x11);++    x44 = x22;+    for (j=0; j<22; j++) {+        secp256k1_fe_sqr(&x44, &x44);+    }+    secp256k1_fe_mul(&x44, &x44, &x22);++    x88 = x44;+    for (j=0; j<44; j++) {+        secp256k1_fe_sqr(&x88, &x88);+    }+    secp256k1_fe_mul(&x88, &x88, &x44);++    x176 = x88;+    for (j=0; j<88; j++) {+        secp256k1_fe_sqr(&x176, &x176);+    }+    secp256k1_fe_mul(&x176, &x176, &x88);++    x220 = x176;+    for (j=0; j<44; j++) {+        secp256k1_fe_sqr(&x220, &x220);+    }+    secp256k1_fe_mul(&x220, &x220, &x44);++    x223 = x220;+    for (j=0; j<3; j++) {+        secp256k1_fe_sqr(&x223, &x223);+    }+    secp256k1_fe_mul(&x223, &x223, &x3);++    /* The final result is then assembled using a sliding window over the blocks. */++    t1 = x223;+    for (j=0; j<23; j++) {+        secp256k1_fe_sqr(&t1, &t1);+    }+    secp256k1_fe_mul(&t1, &t1, &x22);+    for (j=0; j<6; j++) {+        secp256k1_fe_sqr(&t1, &t1);+    }+    secp256k1_fe_mul(&t1, &t1, &x2);+    secp256k1_fe_sqr(&t1, &t1);+    secp256k1_fe_sqr(r, &t1);++    /* Check that a square root was actually calculated */++    secp256k1_fe_sqr(&t1, r);+    ret = secp256k1_fe_equal(&t1, a);++#ifdef VERIFY+    if (!ret) {+        secp256k1_fe_negate(&t1, &t1, 1);+        secp256k1_fe_normalize_var(&t1);+        VERIFY_CHECK(secp256k1_fe_equal(&t1, a));+    }+#endif+    return ret;+}++#ifndef VERIFY+static void secp256k1_fe_verify(const secp256k1_fe *a) { (void)a; }+static void secp256k1_fe_verify_magnitude(const secp256k1_fe *a, int m) { (void)a; (void)m; }+#else+static void secp256k1_fe_impl_verify(const secp256k1_fe *a);+static void secp256k1_fe_verify(const secp256k1_fe *a) {+    /* Magnitude between 0 and 32. */+    SECP256K1_FE_VERIFY_MAGNITUDE(a, 32);+    /* Normalized is 0 or 1. */+    VERIFY_CHECK((a->normalized == 0) || (a->normalized == 1));+    /* If normalized, magnitude must be 0 or 1. */+    if (a->normalized) SECP256K1_FE_VERIFY_MAGNITUDE(a, 1);+    /* Invoke implementation-specific checks. */+    secp256k1_fe_impl_verify(a);+}++static void secp256k1_fe_verify_magnitude(const secp256k1_fe *a, int m) {+    VERIFY_CHECK(m >= 0);+    VERIFY_CHECK(m <= 32);+    VERIFY_CHECK(a->magnitude <= m);+}++static void secp256k1_fe_impl_normalize(secp256k1_fe *r);+SECP256K1_INLINE static void secp256k1_fe_normalize(secp256k1_fe *r) {+    SECP256K1_FE_VERIFY(r);++    secp256k1_fe_impl_normalize(r);+    r->magnitude = 1;+    r->normalized = 1;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_normalize_weak(secp256k1_fe *r);+SECP256K1_INLINE static void secp256k1_fe_normalize_weak(secp256k1_fe *r) {+    SECP256K1_FE_VERIFY(r);++    secp256k1_fe_impl_normalize_weak(r);+    r->magnitude = 1;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_normalize_var(secp256k1_fe *r);+SECP256K1_INLINE static void secp256k1_fe_normalize_var(secp256k1_fe *r) {+    SECP256K1_FE_VERIFY(r);++    secp256k1_fe_impl_normalize_var(r);+    r->magnitude = 1;+    r->normalized = 1;++    SECP256K1_FE_VERIFY(r);+}++static int secp256k1_fe_impl_normalizes_to_zero(const secp256k1_fe *r);+SECP256K1_INLINE static int secp256k1_fe_normalizes_to_zero(const secp256k1_fe *r) {+    SECP256K1_FE_VERIFY(r);++    return secp256k1_fe_impl_normalizes_to_zero(r);+}++static int secp256k1_fe_impl_normalizes_to_zero_var(const secp256k1_fe *r);+SECP256K1_INLINE static int secp256k1_fe_normalizes_to_zero_var(const secp256k1_fe *r) {+    SECP256K1_FE_VERIFY(r);++    return secp256k1_fe_impl_normalizes_to_zero_var(r);+}++static void secp256k1_fe_impl_set_int(secp256k1_fe *r, int a);+SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {+    VERIFY_CHECK(0 <= a && a <= 0x7FFF);++    secp256k1_fe_impl_set_int(r, a);+    r->magnitude = (a != 0);+    r->normalized = 1;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_add_int(secp256k1_fe *r, int a);+SECP256K1_INLINE static void secp256k1_fe_add_int(secp256k1_fe *r, int a) {+    VERIFY_CHECK(0 <= a && a <= 0x7FFF);+    SECP256K1_FE_VERIFY(r);++    secp256k1_fe_impl_add_int(r, a);+    r->magnitude += 1;+    r->normalized = 0;++    SECP256K1_FE_VERIFY(r);+}++static int secp256k1_fe_impl_is_zero(const secp256k1_fe *a);+SECP256K1_INLINE static int secp256k1_fe_is_zero(const secp256k1_fe *a) {+    SECP256K1_FE_VERIFY(a);+    VERIFY_CHECK(a->normalized);++    return secp256k1_fe_impl_is_zero(a);+}++static int secp256k1_fe_impl_is_odd(const secp256k1_fe *a);+SECP256K1_INLINE static int secp256k1_fe_is_odd(const secp256k1_fe *a) {+    SECP256K1_FE_VERIFY(a);+    VERIFY_CHECK(a->normalized);++    return secp256k1_fe_impl_is_odd(a);+}++static int secp256k1_fe_impl_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b);+SECP256K1_INLINE static int secp256k1_fe_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b) {+    SECP256K1_FE_VERIFY(a);+    SECP256K1_FE_VERIFY(b);+    VERIFY_CHECK(a->normalized);+    VERIFY_CHECK(b->normalized);++    return secp256k1_fe_impl_cmp_var(a, b);+}++static void secp256k1_fe_impl_set_b32_mod(secp256k1_fe *r, const unsigned char *a);+SECP256K1_INLINE static void secp256k1_fe_set_b32_mod(secp256k1_fe *r, const unsigned char *a) {+    secp256k1_fe_impl_set_b32_mod(r, a);+    r->magnitude = 1;+    r->normalized = 0;++    SECP256K1_FE_VERIFY(r);+}++static int secp256k1_fe_impl_set_b32_limit(secp256k1_fe *r, const unsigned char *a);+SECP256K1_INLINE static int secp256k1_fe_set_b32_limit(secp256k1_fe *r, const unsigned char *a) {+    if (secp256k1_fe_impl_set_b32_limit(r, a)) {+        r->magnitude = 1;+        r->normalized = 1;+        SECP256K1_FE_VERIFY(r);+        return 1;+    } else {+        /* Mark the output field element as invalid. */+        r->magnitude = -1;+        return 0;+    }+}++static void secp256k1_fe_impl_get_b32(unsigned char *r, const secp256k1_fe *a);+SECP256K1_INLINE static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a) {+    SECP256K1_FE_VERIFY(a);+    VERIFY_CHECK(a->normalized);++    secp256k1_fe_impl_get_b32(r, a);+}++static void secp256k1_fe_impl_negate_unchecked(secp256k1_fe *r, const secp256k1_fe *a, int m);+SECP256K1_INLINE static void secp256k1_fe_negate_unchecked(secp256k1_fe *r, const secp256k1_fe *a, int m) {+    SECP256K1_FE_VERIFY(a);+    VERIFY_CHECK(m >= 0 && m <= 31);+    SECP256K1_FE_VERIFY_MAGNITUDE(a, m);++    secp256k1_fe_impl_negate_unchecked(r, a, m);+    r->magnitude = m + 1;+    r->normalized = 0;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_mul_int_unchecked(secp256k1_fe *r, int a);+SECP256K1_INLINE static void secp256k1_fe_mul_int_unchecked(secp256k1_fe *r, int a) {+    SECP256K1_FE_VERIFY(r);++    VERIFY_CHECK(a >= 0 && a <= 32);+    VERIFY_CHECK(a*r->magnitude <= 32);+    secp256k1_fe_impl_mul_int_unchecked(r, a);+    r->magnitude *= a;+    r->normalized = 0;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_add(secp256k1_fe *r, const secp256k1_fe *a);+SECP256K1_INLINE static void secp256k1_fe_add(secp256k1_fe *r, const secp256k1_fe *a) {+    SECP256K1_FE_VERIFY(r);+    SECP256K1_FE_VERIFY(a);+    VERIFY_CHECK(r->magnitude + a->magnitude <= 32);++    secp256k1_fe_impl_add(r, a);+    r->magnitude += a->magnitude;+    r->normalized = 0;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe * SECP256K1_RESTRICT b);+SECP256K1_INLINE static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe * SECP256K1_RESTRICT b) {+    SECP256K1_FE_VERIFY(a);+    SECP256K1_FE_VERIFY(b);+    SECP256K1_FE_VERIFY_MAGNITUDE(a, 8);+    SECP256K1_FE_VERIFY_MAGNITUDE(b, 8);+    VERIFY_CHECK(r != b);+    VERIFY_CHECK(a != b);++    secp256k1_fe_impl_mul(r, a, b);+    r->magnitude = 1;+    r->normalized = 0;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_sqr(secp256k1_fe *r, const secp256k1_fe *a);+SECP256K1_INLINE static void secp256k1_fe_sqr(secp256k1_fe *r, const secp256k1_fe *a) {+    SECP256K1_FE_VERIFY(a);+    SECP256K1_FE_VERIFY_MAGNITUDE(a, 8);++    secp256k1_fe_impl_sqr(r, a);+    r->magnitude = 1;+    r->normalized = 0;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_cmov(secp256k1_fe *r, const secp256k1_fe *a, int flag);+SECP256K1_INLINE static void secp256k1_fe_cmov(secp256k1_fe *r, const secp256k1_fe *a, int flag) {+    VERIFY_CHECK(flag == 0 || flag == 1);+    SECP256K1_FE_VERIFY(a);+    SECP256K1_FE_VERIFY(r);++    secp256k1_fe_impl_cmov(r, a, flag);+    if (a->magnitude > r->magnitude) r->magnitude = a->magnitude;+    if (!a->normalized) r->normalized = 0;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_to_storage(secp256k1_fe_storage *r, const secp256k1_fe *a);+SECP256K1_INLINE static void secp256k1_fe_to_storage(secp256k1_fe_storage *r, const secp256k1_fe *a) {+    SECP256K1_FE_VERIFY(a);+    VERIFY_CHECK(a->normalized);++    secp256k1_fe_impl_to_storage(r, a);+}++static void secp256k1_fe_impl_from_storage(secp256k1_fe *r, const secp256k1_fe_storage *a);+SECP256K1_INLINE static void secp256k1_fe_from_storage(secp256k1_fe *r, const secp256k1_fe_storage *a) {+    secp256k1_fe_impl_from_storage(r, a);+    r->magnitude = 1;+    r->normalized = 1;++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_inv(secp256k1_fe *r, const secp256k1_fe *x);+SECP256K1_INLINE static void secp256k1_fe_inv(secp256k1_fe *r, const secp256k1_fe *x) {+    int input_is_zero = secp256k1_fe_normalizes_to_zero(x);+    SECP256K1_FE_VERIFY(x);++    secp256k1_fe_impl_inv(r, x);+    r->magnitude = x->magnitude > 0;+    r->normalized = 1;++    VERIFY_CHECK(secp256k1_fe_normalizes_to_zero(r) == input_is_zero);+    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_inv_var(secp256k1_fe *r, const secp256k1_fe *x);+SECP256K1_INLINE static void secp256k1_fe_inv_var(secp256k1_fe *r, const secp256k1_fe *x) {+    int input_is_zero = secp256k1_fe_normalizes_to_zero(x);+    SECP256K1_FE_VERIFY(x);++    secp256k1_fe_impl_inv_var(r, x);+    r->magnitude = x->magnitude > 0;+    r->normalized = 1;++    VERIFY_CHECK(secp256k1_fe_normalizes_to_zero(r) == input_is_zero);+    SECP256K1_FE_VERIFY(r);+}++static int secp256k1_fe_impl_is_square_var(const secp256k1_fe *x);+SECP256K1_INLINE static int secp256k1_fe_is_square_var(const secp256k1_fe *x) {+    int ret;+    secp256k1_fe tmp = *x, sqrt;+    SECP256K1_FE_VERIFY(x);++    ret = secp256k1_fe_impl_is_square_var(x);+    secp256k1_fe_normalize_weak(&tmp);+    VERIFY_CHECK(ret == secp256k1_fe_sqrt(&sqrt, &tmp));+    return ret;+}++static void secp256k1_fe_impl_get_bounds(secp256k1_fe* r, int m);+SECP256K1_INLINE static void secp256k1_fe_get_bounds(secp256k1_fe* r, int m) {+    VERIFY_CHECK(m >= 0);+    VERIFY_CHECK(m <= 32);++    secp256k1_fe_impl_get_bounds(r, m);+    r->magnitude = m;+    r->normalized = (m == 0);++    SECP256K1_FE_VERIFY(r);+}++static void secp256k1_fe_impl_half(secp256k1_fe *r);+SECP256K1_INLINE static void secp256k1_fe_half(secp256k1_fe *r) {+    SECP256K1_FE_VERIFY(r);+    SECP256K1_FE_VERIFY_MAGNITUDE(r, 31);++    secp256k1_fe_impl_half(r);+    r->magnitude = (r->magnitude >> 1) + 1;+    r->normalized = 0;++    SECP256K1_FE_VERIFY(r);+}++#endif /* defined(VERIFY) */++#endif /* SECP256K1_FIELD_IMPL_H */
+ vendor/external/secp256k1/src/group.h view
@@ -0,0 +1,212 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_GROUP_H+#define SECP256K1_GROUP_H++#include "field.h"++/** A group element in affine coordinates on the secp256k1 curve,+ *  or occasionally on an isomorphic curve of the form y^2 = x^3 + 7*t^6.+ *  Note: For exhaustive test mode, secp256k1 is replaced by a small subgroup of a different curve.+ */+typedef struct {+    secp256k1_fe x;+    secp256k1_fe y;+    int infinity; /* whether this represents the point at infinity */+} secp256k1_ge;++#define SECP256K1_GE_CONST(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {SECP256K1_FE_CONST((a),(b),(c),(d),(e),(f),(g),(h)), SECP256K1_FE_CONST((i),(j),(k),(l),(m),(n),(o),(p)), 0}+#define SECP256K1_GE_CONST_INFINITY {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), 1}++/** A group element of the secp256k1 curve, in jacobian coordinates.+ *  Note: For exhastive test mode, secp256k1 is replaced by a small subgroup of a different curve.+ */+typedef struct {+    secp256k1_fe x; /* actual X: x/z^2 */+    secp256k1_fe y; /* actual Y: y/z^3 */+    secp256k1_fe z;+    int infinity; /* whether this represents the point at infinity */+} secp256k1_gej;++#define SECP256K1_GEJ_CONST(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {SECP256K1_FE_CONST((a),(b),(c),(d),(e),(f),(g),(h)), SECP256K1_FE_CONST((i),(j),(k),(l),(m),(n),(o),(p)), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1), 0}+#define SECP256K1_GEJ_CONST_INFINITY {SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 0), 1}++typedef struct {+    secp256k1_fe_storage x;+    secp256k1_fe_storage y;+} secp256k1_ge_storage;++#define SECP256K1_GE_STORAGE_CONST(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) {SECP256K1_FE_STORAGE_CONST((a),(b),(c),(d),(e),(f),(g),(h)), SECP256K1_FE_STORAGE_CONST((i),(j),(k),(l),(m),(n),(o),(p))}++#define SECP256K1_GE_STORAGE_CONST_GET(t) SECP256K1_FE_STORAGE_CONST_GET(t.x), SECP256K1_FE_STORAGE_CONST_GET(t.y)++/** Maximum allowed magnitudes for group element coordinates+ *  in affine (x, y) and jacobian (x, y, z) representation. */+#define SECP256K1_GE_X_MAGNITUDE_MAX  4+#define SECP256K1_GE_Y_MAGNITUDE_MAX  3+#define SECP256K1_GEJ_X_MAGNITUDE_MAX 4+#define SECP256K1_GEJ_Y_MAGNITUDE_MAX 4+#define SECP256K1_GEJ_Z_MAGNITUDE_MAX 1++/** Set a group element equal to the point with given X and Y coordinates */+static void secp256k1_ge_set_xy(secp256k1_ge *r, const secp256k1_fe *x, const secp256k1_fe *y);++/** Set a group element (affine) equal to the point with the given X coordinate, and given oddness+ *  for Y. Return value indicates whether the result is valid. */+static int secp256k1_ge_set_xo_var(secp256k1_ge *r, const secp256k1_fe *x, int odd);++/** Determine whether x is a valid X coordinate on the curve. */+static int secp256k1_ge_x_on_curve_var(const secp256k1_fe *x);++/** Determine whether fraction xn/xd is a valid X coordinate on the curve (xd != 0). */+static int secp256k1_ge_x_frac_on_curve_var(const secp256k1_fe *xn, const secp256k1_fe *xd);++/** Check whether a group element is the point at infinity. */+static int secp256k1_ge_is_infinity(const secp256k1_ge *a);++/** Check whether a group element is valid (i.e., on the curve). */+static int secp256k1_ge_is_valid_var(const secp256k1_ge *a);++/** Set r equal to the inverse of a (i.e., mirrored around the X axis) */+static void secp256k1_ge_neg(secp256k1_ge *r, const secp256k1_ge *a);++/** Set a group element equal to another which is given in jacobian coordinates. Constant time. */+static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a);++/** Set a group element equal to another which is given in jacobian coordinates. */+static void secp256k1_ge_set_gej_var(secp256k1_ge *r, secp256k1_gej *a);++/** Set a batch of group elements equal to the inputs given in jacobian coordinates */+static void secp256k1_ge_set_all_gej_var(secp256k1_ge *r, const secp256k1_gej *a, size_t len);++/** Bring a batch of inputs to the same global z "denominator", based on ratios between+ *  (omitted) z coordinates of adjacent elements.+ *+ *  Although the elements a[i] are _ge rather than _gej, they actually represent elements+ *  in Jacobian coordinates with their z coordinates omitted.+ *+ *  Using the notation z(b) to represent the omitted z coordinate of b, the array zr of+ *  z coordinate ratios must satisfy zr[i] == z(a[i]) / z(a[i-1]) for 0 < 'i' < len.+ *  The zr[0] value is unused.+ *+ *  This function adjusts the coordinates of 'a' in place so that for all 'i', z(a[i]) == z(a[len-1]).+ *  In other words, the initial value of z(a[len-1]) becomes the global z "denominator". Only the+ *  a[i].x and a[i].y coordinates are explicitly modified; the adjustment of the omitted z coordinate is+ *  implicit.+ *+ *  The coordinates of the final element a[len-1] are not changed.+ */+static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const secp256k1_fe *zr);++/** Check two group elements (affine) for equality in variable time. */+static int secp256k1_ge_eq_var(const secp256k1_ge *a, const secp256k1_ge *b);++/** Set a group element (affine) equal to the point at infinity. */+static void secp256k1_ge_set_infinity(secp256k1_ge *r);++/** Set a group element (jacobian) equal to the point at infinity. */+static void secp256k1_gej_set_infinity(secp256k1_gej *r);++/** Set a group element (jacobian) equal to another which is given in affine coordinates. */+static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a);++/** Check two group elements (jacobian) for equality in variable time. */+static int secp256k1_gej_eq_var(const secp256k1_gej *a, const secp256k1_gej *b);++/** Check two group elements (jacobian and affine) for equality in variable time. */+static int secp256k1_gej_eq_ge_var(const secp256k1_gej *a, const secp256k1_ge *b);++/** Compare the X coordinate of a group element (jacobian).+  * The magnitude of the group element's X coordinate must not exceed 31. */+static int secp256k1_gej_eq_x_var(const secp256k1_fe *x, const secp256k1_gej *a);++/** Set r equal to the inverse of a (i.e., mirrored around the X axis) */+static void secp256k1_gej_neg(secp256k1_gej *r, const secp256k1_gej *a);++/** Check whether a group element is the point at infinity. */+static int secp256k1_gej_is_infinity(const secp256k1_gej *a);++/** Set r equal to the double of a. Constant time. */+static void secp256k1_gej_double(secp256k1_gej *r, const secp256k1_gej *a);++/** Set r equal to the double of a. If rzr is not-NULL this sets *rzr such that r->z == a->z * *rzr (where infinity means an implicit z = 0). */+static void secp256k1_gej_double_var(secp256k1_gej *r, const secp256k1_gej *a, secp256k1_fe *rzr);++/** Set r equal to the sum of a and b. If rzr is non-NULL this sets *rzr such that r->z == a->z * *rzr (a cannot be infinity in that case). */+static void secp256k1_gej_add_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_gej *b, secp256k1_fe *rzr);++/** Set r equal to the sum of a and b (with b given in affine coordinates, and not infinity). */+static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b);++/** Set r equal to the sum of a and b (with b given in affine coordinates). This is more efficient+    than secp256k1_gej_add_var. It is identical to secp256k1_gej_add_ge but without constant-time+    guarantee, and b is allowed to be infinity. If rzr is non-NULL this sets *rzr such that r->z == a->z * *rzr (a cannot be infinity in that case). */+static void secp256k1_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, secp256k1_fe *rzr);++/** Set r equal to the sum of a and b (with the inverse of b's Z coordinate passed as bzinv). */+static void secp256k1_gej_add_zinv_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, const secp256k1_fe *bzinv);++/** Set r to be equal to lambda times a, where lambda is chosen in a way such that this is very fast. */+static void secp256k1_ge_mul_lambda(secp256k1_ge *r, const secp256k1_ge *a);++/** Clear a secp256k1_gej to prevent leaking sensitive information. */+static void secp256k1_gej_clear(secp256k1_gej *r);++/** Clear a secp256k1_ge to prevent leaking sensitive information. */+static void secp256k1_ge_clear(secp256k1_ge *r);++/** Convert a group element to the storage type. */+static void secp256k1_ge_to_storage(secp256k1_ge_storage *r, const secp256k1_ge *a);++/** Convert a group element back from the storage type. */+static void secp256k1_ge_from_storage(secp256k1_ge *r, const secp256k1_ge_storage *a);++/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time.  Both *r and *a must be initialized.*/+static void secp256k1_gej_cmov(secp256k1_gej *r, const secp256k1_gej *a, int flag);++/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time.  Both *r and *a must be initialized.*/+static void secp256k1_ge_storage_cmov(secp256k1_ge_storage *r, const secp256k1_ge_storage *a, int flag);++/** Rescale a jacobian point by b which must be non-zero. Constant-time. */+static void secp256k1_gej_rescale(secp256k1_gej *r, const secp256k1_fe *b);++/** Convert a group element that is not infinity to a 64-byte array. The output+ *  array is platform-dependent. */+static void secp256k1_ge_to_bytes(unsigned char *buf, const secp256k1_ge *a);++/** Convert a 64-byte array into group element. This function assumes that the+ *  provided buffer correctly encodes a group element. */+static void secp256k1_ge_from_bytes(secp256k1_ge *r, const unsigned char *buf);++/** Convert a group element (that is allowed to be infinity) to a 64-byte+ *  array. The output array is platform-dependent. */+static void secp256k1_ge_to_bytes_ext(unsigned char *data, const secp256k1_ge *ge);++/** Convert a 64-byte array into a group element. This function assumes that the+ *  provided buffer is the output of secp256k1_ge_to_bytes_ext. */+static void secp256k1_ge_from_bytes_ext(secp256k1_ge *ge, const unsigned char *data);++/** Determine if a point (which is assumed to be on the curve) is in the correct (sub)group of the curve.+ *+ * In normal mode, the used group is secp256k1, which has cofactor=1 meaning that every point on the curve is in the+ * group, and this function returns always true.+ *+ * When compiling in exhaustive test mode, a slightly different curve equation is used, leading to a group with a+ * (very) small subgroup, and that subgroup is what is used for all cryptographic operations. In that mode, this+ * function checks whether a point that is on the curve is in fact also in that subgroup.+ */+static int secp256k1_ge_is_in_correct_subgroup(const secp256k1_ge* ge);++/** Check invariants on an affine group element (no-op unless VERIFY is enabled). */+static void secp256k1_ge_verify(const secp256k1_ge *a);+#define SECP256K1_GE_VERIFY(a) secp256k1_ge_verify(a)++/** Check invariants on a Jacobian group element (no-op unless VERIFY is enabled). */+static void secp256k1_gej_verify(const secp256k1_gej *a);+#define SECP256K1_GEJ_VERIFY(a) secp256k1_gej_verify(a)++#endif /* SECP256K1_GROUP_H */
+ vendor/external/secp256k1/src/group_impl.h view
@@ -0,0 +1,974 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_GROUP_IMPL_H+#define SECP256K1_GROUP_IMPL_H++#include <string.h>++#include "field.h"+#include "group.h"+#include "util.h"++/* Begin of section generated by sage/gen_exhaustive_groups.sage. */+#define SECP256K1_G_ORDER_7 SECP256K1_GE_CONST(\+    0x66625d13, 0x317ffe44, 0x63d32cff, 0x1ca02b9b,\+    0xe5c6d070, 0x50b4b05e, 0x81cc30db, 0xf5166f0a,\+    0x1e60e897, 0xa7c00c7c, 0x2df53eb6, 0x98274ff4,\+    0x64252f42, 0x8ca44e17, 0x3b25418c, 0xff4ab0cf\+)+#define SECP256K1_G_ORDER_13 SECP256K1_GE_CONST(\+    0xa2482ff8, 0x4bf34edf, 0xa51262fd, 0xe57921db,\+    0xe0dd2cb7, 0xa5914790, 0xbc71631f, 0xc09704fb,\+    0x942536cb, 0xa3e49492, 0x3a701cc3, 0xee3e443f,\+    0xdf182aa9, 0x15b8aa6a, 0x166d3b19, 0xba84b045\+)+#define SECP256K1_G_ORDER_199 SECP256K1_GE_CONST(\+    0x7fb07b5c, 0xd07c3bda, 0x553902e2, 0x7a87ea2c,\+    0x35108a7f, 0x051f41e5, 0xb76abad5, 0x1f2703ad,\+    0x0a251539, 0x5b4c4438, 0x952a634f, 0xac10dd4d,\+    0x6d6f4745, 0x98990c27, 0x3a4f3116, 0xd32ff969\+)+/** Generator for secp256k1, value 'g' defined in+ *  "Standards for Efficient Cryptography" (SEC2) 2.7.1.+ */+#define SECP256K1_G SECP256K1_GE_CONST(\+    0x79be667e, 0xf9dcbbac, 0x55a06295, 0xce870b07,\+    0x029bfcdb, 0x2dce28d9, 0x59f2815b, 0x16f81798,\+    0x483ada77, 0x26a3c465, 0x5da4fbfc, 0x0e1108a8,\+    0xfd17b448, 0xa6855419, 0x9c47d08f, 0xfb10d4b8\+)+/* These exhaustive group test orders and generators are chosen such that:+ * - The field size is equal to that of secp256k1, so field code is the same.+ * - The curve equation is of the form y^2=x^3+B for some small constant B.+ * - The subgroup has a generator 2*P, where P.x is as small as possible.+ * - The subgroup has size less than 1000 to permit exhaustive testing.+ * - The subgroup admits an endomorphism of the form lambda*(x,y) == (beta*x,y).+ */+#if defined(EXHAUSTIVE_TEST_ORDER)+#  if EXHAUSTIVE_TEST_ORDER == 7++static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_7;+#define SECP256K1_B 6++#  elif EXHAUSTIVE_TEST_ORDER == 13++static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_13;+#define SECP256K1_B 2++#  elif EXHAUSTIVE_TEST_ORDER == 199++static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_199;+#define SECP256K1_B 4++#  else+#    error No known generator for the specified exhaustive test group order.+#  endif+#else++static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G;+#define SECP256K1_B 7++#endif+/* End of section generated by sage/gen_exhaustive_groups.sage. */++static void secp256k1_ge_verify(const secp256k1_ge *a) {+    SECP256K1_FE_VERIFY(&a->x);+    SECP256K1_FE_VERIFY(&a->y);+    SECP256K1_FE_VERIFY_MAGNITUDE(&a->x, SECP256K1_GE_X_MAGNITUDE_MAX);+    SECP256K1_FE_VERIFY_MAGNITUDE(&a->y, SECP256K1_GE_Y_MAGNITUDE_MAX);+    VERIFY_CHECK(a->infinity == 0 || a->infinity == 1);+    (void)a;+}++static void secp256k1_gej_verify(const secp256k1_gej *a) {+    SECP256K1_FE_VERIFY(&a->x);+    SECP256K1_FE_VERIFY(&a->y);+    SECP256K1_FE_VERIFY(&a->z);+    SECP256K1_FE_VERIFY_MAGNITUDE(&a->x, SECP256K1_GEJ_X_MAGNITUDE_MAX);+    SECP256K1_FE_VERIFY_MAGNITUDE(&a->y, SECP256K1_GEJ_Y_MAGNITUDE_MAX);+    SECP256K1_FE_VERIFY_MAGNITUDE(&a->z, SECP256K1_GEJ_Z_MAGNITUDE_MAX);+    VERIFY_CHECK(a->infinity == 0 || a->infinity == 1);+    (void)a;+}++/* Set r to the affine coordinates of Jacobian point (a.x, a.y, 1/zi). */+static void secp256k1_ge_set_gej_zinv(secp256k1_ge *r, const secp256k1_gej *a, const secp256k1_fe *zi) {+    secp256k1_fe zi2;+    secp256k1_fe zi3;+    SECP256K1_GEJ_VERIFY(a);+    SECP256K1_FE_VERIFY(zi);+    VERIFY_CHECK(!a->infinity);++    secp256k1_fe_sqr(&zi2, zi);+    secp256k1_fe_mul(&zi3, &zi2, zi);+    secp256k1_fe_mul(&r->x, &a->x, &zi2);+    secp256k1_fe_mul(&r->y, &a->y, &zi3);+    r->infinity = a->infinity;++    SECP256K1_GE_VERIFY(r);+}++/* Set r to the affine coordinates of Jacobian point (a.x, a.y, 1/zi). */+static void secp256k1_ge_set_ge_zinv(secp256k1_ge *r, const secp256k1_ge *a, const secp256k1_fe *zi) {+    secp256k1_fe zi2;+    secp256k1_fe zi3;+    SECP256K1_GE_VERIFY(a);+    SECP256K1_FE_VERIFY(zi);+    VERIFY_CHECK(!a->infinity);++    secp256k1_fe_sqr(&zi2, zi);+    secp256k1_fe_mul(&zi3, &zi2, zi);+    secp256k1_fe_mul(&r->x, &a->x, &zi2);+    secp256k1_fe_mul(&r->y, &a->y, &zi3);+    r->infinity = a->infinity;++    SECP256K1_GE_VERIFY(r);+}++static void secp256k1_ge_set_xy(secp256k1_ge *r, const secp256k1_fe *x, const secp256k1_fe *y) {+    SECP256K1_FE_VERIFY(x);+    SECP256K1_FE_VERIFY(y);++    r->infinity = 0;+    r->x = *x;+    r->y = *y;++    SECP256K1_GE_VERIFY(r);+}++static int secp256k1_ge_is_infinity(const secp256k1_ge *a) {+    SECP256K1_GE_VERIFY(a);++    return a->infinity;+}++static void secp256k1_ge_neg(secp256k1_ge *r, const secp256k1_ge *a) {+    SECP256K1_GE_VERIFY(a);++    *r = *a;+    secp256k1_fe_normalize_weak(&r->y);+    secp256k1_fe_negate(&r->y, &r->y, 1);++    SECP256K1_GE_VERIFY(r);+}++static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a) {+    secp256k1_fe z2, z3;+    SECP256K1_GEJ_VERIFY(a);++    r->infinity = a->infinity;+    secp256k1_fe_inv(&a->z, &a->z);+    secp256k1_fe_sqr(&z2, &a->z);+    secp256k1_fe_mul(&z3, &a->z, &z2);+    secp256k1_fe_mul(&a->x, &a->x, &z2);+    secp256k1_fe_mul(&a->y, &a->y, &z3);+    secp256k1_fe_set_int(&a->z, 1);+    r->x = a->x;+    r->y = a->y;++    SECP256K1_GEJ_VERIFY(a);+    SECP256K1_GE_VERIFY(r);+}++static void secp256k1_ge_set_gej_var(secp256k1_ge *r, secp256k1_gej *a) {+    secp256k1_fe z2, z3;+    SECP256K1_GEJ_VERIFY(a);++    if (secp256k1_gej_is_infinity(a)) {+        secp256k1_ge_set_infinity(r);+        return;+    }+    r->infinity = 0;+    secp256k1_fe_inv_var(&a->z, &a->z);+    secp256k1_fe_sqr(&z2, &a->z);+    secp256k1_fe_mul(&z3, &a->z, &z2);+    secp256k1_fe_mul(&a->x, &a->x, &z2);+    secp256k1_fe_mul(&a->y, &a->y, &z3);+    secp256k1_fe_set_int(&a->z, 1);+    secp256k1_ge_set_xy(r, &a->x, &a->y);++    SECP256K1_GEJ_VERIFY(a);+    SECP256K1_GE_VERIFY(r);+}++static void secp256k1_ge_set_all_gej_var(secp256k1_ge *r, const secp256k1_gej *a, size_t len) {+    secp256k1_fe u;+    size_t i;+    size_t last_i = SIZE_MAX;+#ifdef VERIFY+    for (i = 0; i < len; i++) {+        SECP256K1_GEJ_VERIFY(&a[i]);+    }+#endif++    for (i = 0; i < len; i++) {+        if (a[i].infinity) {+            secp256k1_ge_set_infinity(&r[i]);+        } else {+            /* Use destination's x coordinates as scratch space */+            if (last_i == SIZE_MAX) {+                r[i].x = a[i].z;+            } else {+                secp256k1_fe_mul(&r[i].x, &r[last_i].x, &a[i].z);+            }+            last_i = i;+        }+    }+    if (last_i == SIZE_MAX) {+        return;+    }+    secp256k1_fe_inv_var(&u, &r[last_i].x);++    i = last_i;+    while (i > 0) {+        i--;+        if (!a[i].infinity) {+            secp256k1_fe_mul(&r[last_i].x, &r[i].x, &u);+            secp256k1_fe_mul(&u, &u, &a[last_i].z);+            last_i = i;+        }+    }+    VERIFY_CHECK(!a[last_i].infinity);+    r[last_i].x = u;++    for (i = 0; i < len; i++) {+        if (!a[i].infinity) {+            secp256k1_ge_set_gej_zinv(&r[i], &a[i], &r[i].x);+        }+    }++#ifdef VERIFY+    for (i = 0; i < len; i++) {+        SECP256K1_GE_VERIFY(&r[i]);+    }+#endif+}++static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const secp256k1_fe *zr) {+    size_t i;+    secp256k1_fe zs;+#ifdef VERIFY+    for (i = 0; i < len; i++) {+        SECP256K1_GE_VERIFY(&a[i]);+        SECP256K1_FE_VERIFY(&zr[i]);+    }+#endif++    if (len > 0) {+        i = len - 1;+        /* Ensure all y values are in weak normal form for fast negation of points */+        secp256k1_fe_normalize_weak(&a[i].y);+        zs = zr[i];++        /* Work our way backwards, using the z-ratios to scale the x/y values. */+        while (i > 0) {+            if (i != len - 1) {+                secp256k1_fe_mul(&zs, &zs, &zr[i]);+            }+            i--;+            secp256k1_ge_set_ge_zinv(&a[i], &a[i], &zs);+        }+    }++#ifdef VERIFY+    for (i = 0; i < len; i++) {+        SECP256K1_GE_VERIFY(&a[i]);+    }+#endif+}++static void secp256k1_gej_set_infinity(secp256k1_gej *r) {+    r->infinity = 1;+    secp256k1_fe_set_int(&r->x, 0);+    secp256k1_fe_set_int(&r->y, 0);+    secp256k1_fe_set_int(&r->z, 0);++    SECP256K1_GEJ_VERIFY(r);+}++static void secp256k1_ge_set_infinity(secp256k1_ge *r) {+    r->infinity = 1;+    secp256k1_fe_set_int(&r->x, 0);+    secp256k1_fe_set_int(&r->y, 0);++    SECP256K1_GE_VERIFY(r);+}++static void secp256k1_gej_clear(secp256k1_gej *r) {+    secp256k1_memclear(r, sizeof(secp256k1_gej));+}++static void secp256k1_ge_clear(secp256k1_ge *r) {+    secp256k1_memclear(r, sizeof(secp256k1_ge));+}++static int secp256k1_ge_set_xo_var(secp256k1_ge *r, const secp256k1_fe *x, int odd) {+    secp256k1_fe x2, x3;+    int ret;+    SECP256K1_FE_VERIFY(x);++    r->x = *x;+    secp256k1_fe_sqr(&x2, x);+    secp256k1_fe_mul(&x3, x, &x2);+    r->infinity = 0;+    secp256k1_fe_add_int(&x3, SECP256K1_B);+    ret = secp256k1_fe_sqrt(&r->y, &x3);+    secp256k1_fe_normalize_var(&r->y);+    if (secp256k1_fe_is_odd(&r->y) != odd) {+        secp256k1_fe_negate(&r->y, &r->y, 1);+    }++    SECP256K1_GE_VERIFY(r);+    return ret;+}++static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a) {+   SECP256K1_GE_VERIFY(a);++   r->infinity = a->infinity;+   r->x = a->x;+   r->y = a->y;+   secp256k1_fe_set_int(&r->z, 1);++   SECP256K1_GEJ_VERIFY(r);+}++static int secp256k1_gej_eq_var(const secp256k1_gej *a, const secp256k1_gej *b) {+    secp256k1_gej tmp;+    SECP256K1_GEJ_VERIFY(b);+    SECP256K1_GEJ_VERIFY(a);++    secp256k1_gej_neg(&tmp, a);+    secp256k1_gej_add_var(&tmp, &tmp, b, NULL);+    return secp256k1_gej_is_infinity(&tmp);+}++static int secp256k1_gej_eq_ge_var(const secp256k1_gej *a, const secp256k1_ge *b) {+    secp256k1_gej tmp;+    SECP256K1_GEJ_VERIFY(a);+    SECP256K1_GE_VERIFY(b);++    secp256k1_gej_neg(&tmp, a);+    secp256k1_gej_add_ge_var(&tmp, &tmp, b, NULL);+    return secp256k1_gej_is_infinity(&tmp);+}++static int secp256k1_ge_eq_var(const secp256k1_ge *a, const secp256k1_ge *b) {+    secp256k1_fe tmp;+    SECP256K1_GE_VERIFY(a);+    SECP256K1_GE_VERIFY(b);++    if (a->infinity != b->infinity) return 0;+    if (a->infinity) return 1;++    tmp = a->x;+    secp256k1_fe_normalize_weak(&tmp);+    if (!secp256k1_fe_equal(&tmp, &b->x)) return 0;++    tmp = a->y;+    secp256k1_fe_normalize_weak(&tmp);+    if (!secp256k1_fe_equal(&tmp, &b->y)) return 0;++    return 1;+}++static int secp256k1_gej_eq_x_var(const secp256k1_fe *x, const secp256k1_gej *a) {+    secp256k1_fe r;+    SECP256K1_FE_VERIFY(x);+    SECP256K1_GEJ_VERIFY(a);+    VERIFY_CHECK(!a->infinity);++    secp256k1_fe_sqr(&r, &a->z); secp256k1_fe_mul(&r, &r, x);+    return secp256k1_fe_equal(&r, &a->x);+}++static void secp256k1_gej_neg(secp256k1_gej *r, const secp256k1_gej *a) {+    SECP256K1_GEJ_VERIFY(a);++    r->infinity = a->infinity;+    r->x = a->x;+    r->y = a->y;+    r->z = a->z;+    secp256k1_fe_normalize_weak(&r->y);+    secp256k1_fe_negate(&r->y, &r->y, 1);++    SECP256K1_GEJ_VERIFY(r);+}++static int secp256k1_gej_is_infinity(const secp256k1_gej *a) {+    SECP256K1_GEJ_VERIFY(a);++    return a->infinity;+}++static int secp256k1_ge_is_valid_var(const secp256k1_ge *a) {+    secp256k1_fe y2, x3;+    SECP256K1_GE_VERIFY(a);++    if (a->infinity) {+        return 0;+    }+    /* y^2 = x^3 + 7 */+    secp256k1_fe_sqr(&y2, &a->y);+    secp256k1_fe_sqr(&x3, &a->x); secp256k1_fe_mul(&x3, &x3, &a->x);+    secp256k1_fe_add_int(&x3, SECP256K1_B);+    return secp256k1_fe_equal(&y2, &x3);+}++static SECP256K1_INLINE void secp256k1_gej_double(secp256k1_gej *r, const secp256k1_gej *a) {+    /* Operations: 3 mul, 4 sqr, 8 add/half/mul_int/negate */+    secp256k1_fe l, s, t;+    SECP256K1_GEJ_VERIFY(a);++    r->infinity = a->infinity;++    /* Formula used:+     * L = (3/2) * X1^2+     * S = Y1^2+     * T = -X1*S+     * X3 = L^2 + 2*T+     * Y3 = -(L*(X3 + T) + S^2)+     * Z3 = Y1*Z1+     */++    secp256k1_fe_mul(&r->z, &a->z, &a->y); /* Z3 = Y1*Z1 (1) */+    secp256k1_fe_sqr(&s, &a->y);           /* S = Y1^2 (1) */+    secp256k1_fe_sqr(&l, &a->x);           /* L = X1^2 (1) */+    secp256k1_fe_mul_int(&l, 3);           /* L = 3*X1^2 (3) */+    secp256k1_fe_half(&l);                 /* L = 3/2*X1^2 (2) */+    secp256k1_fe_negate(&t, &s, 1);        /* T = -S (2) */+    secp256k1_fe_mul(&t, &t, &a->x);       /* T = -X1*S (1) */+    secp256k1_fe_sqr(&r->x, &l);           /* X3 = L^2 (1) */+    secp256k1_fe_add(&r->x, &t);           /* X3 = L^2 + T (2) */+    secp256k1_fe_add(&r->x, &t);           /* X3 = L^2 + 2*T (3) */+    secp256k1_fe_sqr(&s, &s);              /* S' = S^2 (1) */+    secp256k1_fe_add(&t, &r->x);           /* T' = X3 + T (4) */+    secp256k1_fe_mul(&r->y, &t, &l);       /* Y3 = L*(X3 + T) (1) */+    secp256k1_fe_add(&r->y, &s);           /* Y3 = L*(X3 + T) + S^2 (2) */+    secp256k1_fe_negate(&r->y, &r->y, 2);  /* Y3 = -(L*(X3 + T) + S^2) (3) */++    SECP256K1_GEJ_VERIFY(r);+}++static void secp256k1_gej_double_var(secp256k1_gej *r, const secp256k1_gej *a, secp256k1_fe *rzr) {+    SECP256K1_GEJ_VERIFY(a);++    /** For secp256k1, 2Q is infinity if and only if Q is infinity. This is because if 2Q = infinity,+     *  Q must equal -Q, or that Q.y == -(Q.y), or Q.y is 0. For a point on y^2 = x^3 + 7 to have+     *  y=0, x^3 must be -7 mod p. However, -7 has no cube root mod p.+     *+     *  Having said this, if this function receives a point on a sextic twist, e.g. by+     *  a fault attack, it is possible for y to be 0. This happens for y^2 = x^3 + 6,+     *  since -6 does have a cube root mod p. For this point, this function will not set+     *  the infinity flag even though the point doubles to infinity, and the result+     *  point will be gibberish (z = 0 but infinity = 0).+     */+    if (a->infinity) {+        secp256k1_gej_set_infinity(r);+        if (rzr != NULL) {+            secp256k1_fe_set_int(rzr, 1);+        }+        return;+    }++    if (rzr != NULL) {+        *rzr = a->y;+        secp256k1_fe_normalize_weak(rzr);+    }++    secp256k1_gej_double(r, a);++    SECP256K1_GEJ_VERIFY(r);+}++static void secp256k1_gej_add_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_gej *b, secp256k1_fe *rzr) {+    /* 12 mul, 4 sqr, 11 add/negate/normalizes_to_zero (ignoring special cases) */+    secp256k1_fe z22, z12, u1, u2, s1, s2, h, i, h2, h3, t;+    SECP256K1_GEJ_VERIFY(a);+    SECP256K1_GEJ_VERIFY(b);++    if (a->infinity) {+        VERIFY_CHECK(rzr == NULL);+        *r = *b;+        return;+    }+    if (b->infinity) {+        if (rzr != NULL) {+            secp256k1_fe_set_int(rzr, 1);+        }+        *r = *a;+        return;+    }++    secp256k1_fe_sqr(&z22, &b->z);+    secp256k1_fe_sqr(&z12, &a->z);+    secp256k1_fe_mul(&u1, &a->x, &z22);+    secp256k1_fe_mul(&u2, &b->x, &z12);+    secp256k1_fe_mul(&s1, &a->y, &z22); secp256k1_fe_mul(&s1, &s1, &b->z);+    secp256k1_fe_mul(&s2, &b->y, &z12); secp256k1_fe_mul(&s2, &s2, &a->z);+    secp256k1_fe_negate(&h, &u1, 1); secp256k1_fe_add(&h, &u2);+    secp256k1_fe_negate(&i, &s2, 1); secp256k1_fe_add(&i, &s1);+    if (secp256k1_fe_normalizes_to_zero_var(&h)) {+        if (secp256k1_fe_normalizes_to_zero_var(&i)) {+            secp256k1_gej_double_var(r, a, rzr);+        } else {+            if (rzr != NULL) {+                secp256k1_fe_set_int(rzr, 0);+            }+            secp256k1_gej_set_infinity(r);+        }+        return;+    }++    r->infinity = 0;+    secp256k1_fe_mul(&t, &h, &b->z);+    if (rzr != NULL) {+        *rzr = t;+    }+    secp256k1_fe_mul(&r->z, &a->z, &t);++    secp256k1_fe_sqr(&h2, &h);+    secp256k1_fe_negate(&h2, &h2, 1);+    secp256k1_fe_mul(&h3, &h2, &h);+    secp256k1_fe_mul(&t, &u1, &h2);++    secp256k1_fe_sqr(&r->x, &i);+    secp256k1_fe_add(&r->x, &h3);+    secp256k1_fe_add(&r->x, &t);+    secp256k1_fe_add(&r->x, &t);++    secp256k1_fe_add(&t, &r->x);+    secp256k1_fe_mul(&r->y, &t, &i);+    secp256k1_fe_mul(&h3, &h3, &s1);+    secp256k1_fe_add(&r->y, &h3);++    SECP256K1_GEJ_VERIFY(r);+}++static void secp256k1_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, secp256k1_fe *rzr) {+    /* Operations: 8 mul, 3 sqr, 11 add/negate/normalizes_to_zero (ignoring special cases) */+    secp256k1_fe z12, u1, u2, s1, s2, h, i, h2, h3, t;+    SECP256K1_GEJ_VERIFY(a);+    SECP256K1_GE_VERIFY(b);++    if (a->infinity) {+        VERIFY_CHECK(rzr == NULL);+        secp256k1_gej_set_ge(r, b);+        return;+    }+    if (b->infinity) {+        if (rzr != NULL) {+            secp256k1_fe_set_int(rzr, 1);+        }+        *r = *a;+        return;+    }++    secp256k1_fe_sqr(&z12, &a->z);+    u1 = a->x;+    secp256k1_fe_mul(&u2, &b->x, &z12);+    s1 = a->y;+    secp256k1_fe_mul(&s2, &b->y, &z12); secp256k1_fe_mul(&s2, &s2, &a->z);+    secp256k1_fe_negate(&h, &u1, SECP256K1_GEJ_X_MAGNITUDE_MAX); secp256k1_fe_add(&h, &u2);+    secp256k1_fe_negate(&i, &s2, 1); secp256k1_fe_add(&i, &s1);+    if (secp256k1_fe_normalizes_to_zero_var(&h)) {+        if (secp256k1_fe_normalizes_to_zero_var(&i)) {+            secp256k1_gej_double_var(r, a, rzr);+        } else {+            if (rzr != NULL) {+                secp256k1_fe_set_int(rzr, 0);+            }+            secp256k1_gej_set_infinity(r);+        }+        return;+    }++    r->infinity = 0;+    if (rzr != NULL) {+        *rzr = h;+    }+    secp256k1_fe_mul(&r->z, &a->z, &h);++    secp256k1_fe_sqr(&h2, &h);+    secp256k1_fe_negate(&h2, &h2, 1);+    secp256k1_fe_mul(&h3, &h2, &h);+    secp256k1_fe_mul(&t, &u1, &h2);++    secp256k1_fe_sqr(&r->x, &i);+    secp256k1_fe_add(&r->x, &h3);+    secp256k1_fe_add(&r->x, &t);+    secp256k1_fe_add(&r->x, &t);++    secp256k1_fe_add(&t, &r->x);+    secp256k1_fe_mul(&r->y, &t, &i);+    secp256k1_fe_mul(&h3, &h3, &s1);+    secp256k1_fe_add(&r->y, &h3);++    SECP256K1_GEJ_VERIFY(r);+    if (rzr != NULL) SECP256K1_FE_VERIFY(rzr);+}++static void secp256k1_gej_add_zinv_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, const secp256k1_fe *bzinv) {+    /* Operations: 9 mul, 3 sqr, 11 add/negate/normalizes_to_zero (ignoring special cases) */+    secp256k1_fe az, z12, u1, u2, s1, s2, h, i, h2, h3, t;+    SECP256K1_GEJ_VERIFY(a);+    SECP256K1_GE_VERIFY(b);+    SECP256K1_FE_VERIFY(bzinv);++    if (a->infinity) {+        secp256k1_fe bzinv2, bzinv3;+        r->infinity = b->infinity;+        secp256k1_fe_sqr(&bzinv2, bzinv);+        secp256k1_fe_mul(&bzinv3, &bzinv2, bzinv);+        secp256k1_fe_mul(&r->x, &b->x, &bzinv2);+        secp256k1_fe_mul(&r->y, &b->y, &bzinv3);+        secp256k1_fe_set_int(&r->z, 1);+        SECP256K1_GEJ_VERIFY(r);+        return;+    }+    if (b->infinity) {+        *r = *a;+        return;+    }++    /** We need to calculate (rx,ry,rz) = (ax,ay,az) + (bx,by,1/bzinv). Due to+     *  secp256k1's isomorphism we can multiply the Z coordinates on both sides+     *  by bzinv, and get: (rx,ry,rz*bzinv) = (ax,ay,az*bzinv) + (bx,by,1).+     *  This means that (rx,ry,rz) can be calculated as+     *  (ax,ay,az*bzinv) + (bx,by,1), when not applying the bzinv factor to rz.+     *  The variable az below holds the modified Z coordinate for a, which is used+     *  for the computation of rx and ry, but not for rz.+     */+    secp256k1_fe_mul(&az, &a->z, bzinv);++    secp256k1_fe_sqr(&z12, &az);+    u1 = a->x;+    secp256k1_fe_mul(&u2, &b->x, &z12);+    s1 = a->y;+    secp256k1_fe_mul(&s2, &b->y, &z12); secp256k1_fe_mul(&s2, &s2, &az);+    secp256k1_fe_negate(&h, &u1, SECP256K1_GEJ_X_MAGNITUDE_MAX); secp256k1_fe_add(&h, &u2);+    secp256k1_fe_negate(&i, &s2, 1); secp256k1_fe_add(&i, &s1);+    if (secp256k1_fe_normalizes_to_zero_var(&h)) {+        if (secp256k1_fe_normalizes_to_zero_var(&i)) {+            secp256k1_gej_double_var(r, a, NULL);+        } else {+            secp256k1_gej_set_infinity(r);+        }+        return;+    }++    r->infinity = 0;+    secp256k1_fe_mul(&r->z, &a->z, &h);++    secp256k1_fe_sqr(&h2, &h);+    secp256k1_fe_negate(&h2, &h2, 1);+    secp256k1_fe_mul(&h3, &h2, &h);+    secp256k1_fe_mul(&t, &u1, &h2);++    secp256k1_fe_sqr(&r->x, &i);+    secp256k1_fe_add(&r->x, &h3);+    secp256k1_fe_add(&r->x, &t);+    secp256k1_fe_add(&r->x, &t);++    secp256k1_fe_add(&t, &r->x);+    secp256k1_fe_mul(&r->y, &t, &i);+    secp256k1_fe_mul(&h3, &h3, &s1);+    secp256k1_fe_add(&r->y, &h3);++    SECP256K1_GEJ_VERIFY(r);+}+++static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b) {+    /* Operations: 7 mul, 5 sqr, 21 add/cmov/half/mul_int/negate/normalizes_to_zero */+    secp256k1_fe zz, u1, u2, s1, s2, t, tt, m, n, q, rr;+    secp256k1_fe m_alt, rr_alt;+    int degenerate;+    SECP256K1_GEJ_VERIFY(a);+    SECP256K1_GE_VERIFY(b);+    VERIFY_CHECK(!b->infinity);++    /*  In:+     *    Eric Brier and Marc Joye, Weierstrass Elliptic Curves and Side-Channel Attacks.+     *    In D. Naccache and P. Paillier, Eds., Public Key Cryptography, vol. 2274 of Lecture Notes in Computer Science, pages 335-345. Springer-Verlag, 2002.+     *  we find as solution for a unified addition/doubling formula:+     *    lambda = ((x1 + x2)^2 - x1 * x2 + a) / (y1 + y2), with a = 0 for secp256k1's curve equation.+     *    x3 = lambda^2 - (x1 + x2)+     *    2*y3 = lambda * (x1 + x2 - 2 * x3) - (y1 + y2).+     *+     *  Substituting x_i = Xi / Zi^2 and yi = Yi / Zi^3, for i=1,2,3, gives:+     *    U1 = X1*Z2^2, U2 = X2*Z1^2+     *    S1 = Y1*Z2^3, S2 = Y2*Z1^3+     *    Z = Z1*Z2+     *    T = U1+U2+     *    M = S1+S2+     *    Q = -T*M^2+     *    R = T^2-U1*U2+     *    X3 = R^2+Q+     *    Y3 = -(R*(2*X3+Q)+M^4)/2+     *    Z3 = M*Z+     *  (Note that the paper uses xi = Xi / Zi and yi = Yi / Zi instead.)+     *+     *  This formula has the benefit of being the same for both addition+     *  of distinct points and doubling. However, it breaks down in the+     *  case that either point is infinity, or that y1 = -y2. We handle+     *  these cases in the following ways:+     *+     *    - If b is infinity we simply bail by means of a VERIFY_CHECK.+     *+     *    - If a is infinity, we detect this, and at the end of the+     *      computation replace the result (which will be meaningless,+     *      but we compute to be constant-time) with b.x : b.y : 1.+     *+     *    - If a = -b, we have y1 = -y2, which is a degenerate case.+     *      But here the answer is infinity, so we simply set the+     *      infinity flag of the result, overriding the computed values+     *      without even needing to cmov.+     *+     *    - If y1 = -y2 but x1 != x2, which does occur thanks to certain+     *      properties of our curve (specifically, 1 has nontrivial cube+     *      roots in our field, and the curve equation has no x coefficient)+     *      then the answer is not infinity but also not given by the above+     *      equation. In this case, we cmov in place an alternate expression+     *      for lambda. Specifically (y1 - y2)/(x1 - x2). Where both these+     *      expressions for lambda are defined, they are equal, and can be+     *      obtained from each other by multiplication by (y1 + y2)/(y1 + y2)+     *      then substitution of x^3 + 7 for y^2 (using the curve equation).+     *      For all pairs of nonzero points (a, b) at least one is defined,+     *      so this covers everything.+     */++    secp256k1_fe_sqr(&zz, &a->z);                       /* z = Z1^2 */+    u1 = a->x;                                          /* u1 = U1 = X1*Z2^2 (GEJ_X_M) */+    secp256k1_fe_mul(&u2, &b->x, &zz);                  /* u2 = U2 = X2*Z1^2 (1) */+    s1 = a->y;                                          /* s1 = S1 = Y1*Z2^3 (GEJ_Y_M) */+    secp256k1_fe_mul(&s2, &b->y, &zz);                  /* s2 = Y2*Z1^2 (1) */+    secp256k1_fe_mul(&s2, &s2, &a->z);                  /* s2 = S2 = Y2*Z1^3 (1) */+    t = u1; secp256k1_fe_add(&t, &u2);                  /* t = T = U1+U2 (GEJ_X_M+1) */+    m = s1; secp256k1_fe_add(&m, &s2);                  /* m = M = S1+S2 (GEJ_Y_M+1) */+    secp256k1_fe_sqr(&rr, &t);                          /* rr = T^2 (1) */+    secp256k1_fe_negate(&m_alt, &u2, 1);                /* Malt = -X2*Z1^2 (2) */+    secp256k1_fe_mul(&tt, &u1, &m_alt);                 /* tt = -U1*U2 (1) */+    secp256k1_fe_add(&rr, &tt);                         /* rr = R = T^2-U1*U2 (2) */+    /* If lambda = R/M = R/0 we have a problem (except in the "trivial"+     * case that Z = z1z2 = 0, and this is special-cased later on). */+    degenerate = secp256k1_fe_normalizes_to_zero(&m);+    /* This only occurs when y1 == -y2 and x1^3 == x2^3, but x1 != x2.+     * This means either x1 == beta*x2 or beta*x1 == x2, where beta is+     * a nontrivial cube root of one. In either case, an alternate+     * non-indeterminate expression for lambda is (y1 - y2)/(x1 - x2),+     * so we set R/M equal to this. */+    rr_alt = s1;+    secp256k1_fe_mul_int(&rr_alt, 2);       /* rr_alt = Y1*Z2^3 - Y2*Z1^3 (GEJ_Y_M*2) */+    secp256k1_fe_add(&m_alt, &u1);          /* Malt = X1*Z2^2 - X2*Z1^2 (GEJ_X_M+2) */++    secp256k1_fe_cmov(&rr_alt, &rr, !degenerate);       /* rr_alt (GEJ_Y_M*2) */+    secp256k1_fe_cmov(&m_alt, &m, !degenerate);         /* m_alt (GEJ_X_M+2) */+    /* Now Ralt / Malt = lambda and is guaranteed not to be Ralt / 0.+     * From here on out Ralt and Malt represent the numerator+     * and denominator of lambda; R and M represent the explicit+     * expressions x1^2 + x2^2 + x1x2 and y1 + y2. */+    secp256k1_fe_sqr(&n, &m_alt);                       /* n = Malt^2 (1) */+    secp256k1_fe_negate(&q, &t,+        SECP256K1_GEJ_X_MAGNITUDE_MAX + 1);             /* q = -T (GEJ_X_M+2) */+    secp256k1_fe_mul(&q, &q, &n);                       /* q = Q = -T*Malt^2 (1) */+    /* These two lines use the observation that either M == Malt or M == 0,+     * so M^3 * Malt is either Malt^4 (which is computed by squaring), or+     * zero (which is "computed" by cmov). So the cost is one squaring+     * versus two multiplications. */+    secp256k1_fe_sqr(&n, &n);                           /* n = Malt^4 (1) */+    secp256k1_fe_cmov(&n, &m, degenerate);              /* n = M^3 * Malt (GEJ_Y_M+1) */+    secp256k1_fe_sqr(&t, &rr_alt);                      /* t = Ralt^2 (1) */+    secp256k1_fe_mul(&r->z, &a->z, &m_alt);             /* r->z = Z3 = Malt*Z (1) */+    secp256k1_fe_add(&t, &q);                           /* t = Ralt^2 + Q (2) */+    r->x = t;                                           /* r->x = X3 = Ralt^2 + Q (2) */+    secp256k1_fe_mul_int(&t, 2);                        /* t = 2*X3 (4) */+    secp256k1_fe_add(&t, &q);                           /* t = 2*X3 + Q (5) */+    secp256k1_fe_mul(&t, &t, &rr_alt);                  /* t = Ralt*(2*X3 + Q) (1) */+    secp256k1_fe_add(&t, &n);                           /* t = Ralt*(2*X3 + Q) + M^3*Malt (GEJ_Y_M+2) */+    secp256k1_fe_negate(&r->y, &t,+        SECP256K1_GEJ_Y_MAGNITUDE_MAX + 2);             /* r->y = -(Ralt*(2*X3 + Q) + M^3*Malt) (GEJ_Y_M+3) */+    secp256k1_fe_half(&r->y);                           /* r->y = Y3 = -(Ralt*(2*X3 + Q) + M^3*Malt)/2 ((GEJ_Y_M+3)/2 + 1) */++    /* In case a->infinity == 1, replace r with (b->x, b->y, 1). */+    secp256k1_fe_cmov(&r->x, &b->x, a->infinity);+    secp256k1_fe_cmov(&r->y, &b->y, a->infinity);+    secp256k1_fe_cmov(&r->z, &secp256k1_fe_one, a->infinity);++    /* Set r->infinity if r->z is 0.+     *+     * If a->infinity is set, then r->infinity = (r->z == 0) = (1 == 0) = false,+     * which is correct because the function assumes that b is not infinity.+     *+     * Now assume !a->infinity. This implies Z = Z1 != 0.+     *+     * Case y1 = -y2:+     * In this case we could have a = -b, namely if x1 = x2.+     * We have degenerate = true, r->z = (x1 - x2) * Z.+     * Then r->infinity = ((x1 - x2)Z == 0) = (x1 == x2) = (a == -b).+     *+     * Case y1 != -y2:+     * In this case, we can't have a = -b.+     * We have degenerate = false, r->z = (y1 + y2) * Z.+     * Then r->infinity = ((y1 + y2)Z == 0) = (y1 == -y2) = false. */+    r->infinity = secp256k1_fe_normalizes_to_zero(&r->z);++    SECP256K1_GEJ_VERIFY(r);+}++static void secp256k1_gej_rescale(secp256k1_gej *r, const secp256k1_fe *s) {+    /* Operations: 4 mul, 1 sqr */+    secp256k1_fe zz;+    SECP256K1_GEJ_VERIFY(r);+    SECP256K1_FE_VERIFY(s);+    VERIFY_CHECK(!secp256k1_fe_normalizes_to_zero_var(s));++    secp256k1_fe_sqr(&zz, s);+    secp256k1_fe_mul(&r->x, &r->x, &zz);                /* r->x *= s^2 */+    secp256k1_fe_mul(&r->y, &r->y, &zz);+    secp256k1_fe_mul(&r->y, &r->y, s);                  /* r->y *= s^3 */+    secp256k1_fe_mul(&r->z, &r->z, s);                  /* r->z *= s   */++    SECP256K1_GEJ_VERIFY(r);+}++static void secp256k1_ge_to_storage(secp256k1_ge_storage *r, const secp256k1_ge *a) {+    secp256k1_fe x, y;+    SECP256K1_GE_VERIFY(a);+    VERIFY_CHECK(!a->infinity);++    x = a->x;+    secp256k1_fe_normalize(&x);+    y = a->y;+    secp256k1_fe_normalize(&y);+    secp256k1_fe_to_storage(&r->x, &x);+    secp256k1_fe_to_storage(&r->y, &y);+}++static void secp256k1_ge_from_storage(secp256k1_ge *r, const secp256k1_ge_storage *a) {+    secp256k1_fe_from_storage(&r->x, &a->x);+    secp256k1_fe_from_storage(&r->y, &a->y);+    r->infinity = 0;++    SECP256K1_GE_VERIFY(r);+}++static SECP256K1_INLINE void secp256k1_gej_cmov(secp256k1_gej *r, const secp256k1_gej *a, int flag) {+    SECP256K1_GEJ_VERIFY(r);+    SECP256K1_GEJ_VERIFY(a);++    secp256k1_fe_cmov(&r->x, &a->x, flag);+    secp256k1_fe_cmov(&r->y, &a->y, flag);+    secp256k1_fe_cmov(&r->z, &a->z, flag);+    r->infinity ^= (r->infinity ^ a->infinity) & flag;++    SECP256K1_GEJ_VERIFY(r);+}++static SECP256K1_INLINE void secp256k1_ge_storage_cmov(secp256k1_ge_storage *r, const secp256k1_ge_storage *a, int flag) {+    secp256k1_fe_storage_cmov(&r->x, &a->x, flag);+    secp256k1_fe_storage_cmov(&r->y, &a->y, flag);+}++static void secp256k1_ge_mul_lambda(secp256k1_ge *r, const secp256k1_ge *a) {+    SECP256K1_GE_VERIFY(a);++    *r = *a;+    secp256k1_fe_mul(&r->x, &r->x, &secp256k1_const_beta);++    SECP256K1_GE_VERIFY(r);+}++static int secp256k1_ge_is_in_correct_subgroup(const secp256k1_ge* ge) {+#ifdef EXHAUSTIVE_TEST_ORDER+    secp256k1_gej out;+    int i;+    SECP256K1_GE_VERIFY(ge);++    /* A very simple EC multiplication ladder that avoids a dependency on ecmult. */+    secp256k1_gej_set_infinity(&out);+    for (i = 0; i < 32; ++i) {+        secp256k1_gej_double_var(&out, &out, NULL);+        if ((((uint32_t)EXHAUSTIVE_TEST_ORDER) >> (31 - i)) & 1) {+            secp256k1_gej_add_ge_var(&out, &out, ge, NULL);+        }+    }+    return secp256k1_gej_is_infinity(&out);+#else+    SECP256K1_GE_VERIFY(ge);++    (void)ge;+    /* The real secp256k1 group has cofactor 1, so the subgroup is the entire curve. */+    return 1;+#endif+}++static int secp256k1_ge_x_on_curve_var(const secp256k1_fe *x) {+    secp256k1_fe c;+    secp256k1_fe_sqr(&c, x);+    secp256k1_fe_mul(&c, &c, x);+    secp256k1_fe_add_int(&c, SECP256K1_B);+    return secp256k1_fe_is_square_var(&c);+}++static int secp256k1_ge_x_frac_on_curve_var(const secp256k1_fe *xn, const secp256k1_fe *xd) {+    /* We want to determine whether (xn/xd) is on the curve.+     *+     * (xn/xd)^3 + 7 is square <=> xd*xn^3 + 7*xd^4 is square (multiplying by xd^4, a square).+     */+     secp256k1_fe r, t;+     VERIFY_CHECK(!secp256k1_fe_normalizes_to_zero_var(xd));++     secp256k1_fe_mul(&r, xd, xn); /* r = xd*xn */+     secp256k1_fe_sqr(&t, xn); /* t = xn^2 */+     secp256k1_fe_mul(&r, &r, &t); /* r = xd*xn^3 */+     secp256k1_fe_sqr(&t, xd); /* t = xd^2 */+     secp256k1_fe_sqr(&t, &t); /* t = xd^4 */+     VERIFY_CHECK(SECP256K1_B <= 31);+     secp256k1_fe_mul_int(&t, SECP256K1_B); /* t = 7*xd^4 */+     secp256k1_fe_add(&r, &t); /* r = xd*xn^3 + 7*xd^4 */+     return secp256k1_fe_is_square_var(&r);+}++static void secp256k1_ge_to_bytes(unsigned char *buf, const secp256k1_ge *a) {+    secp256k1_ge_storage s;++    /* We require that the secp256k1_ge_storage type is exactly 64 bytes.+     * This is formally not guaranteed by the C standard, but should hold on any+     * sane compiler in the real world. */+    STATIC_ASSERT(sizeof(secp256k1_ge_storage) == 64);+    VERIFY_CHECK(!secp256k1_ge_is_infinity(a));+    secp256k1_ge_to_storage(&s, a);+    memcpy(buf, &s, 64);+}++static void secp256k1_ge_from_bytes(secp256k1_ge *r, const unsigned char *buf) {+    secp256k1_ge_storage s;++    STATIC_ASSERT(sizeof(secp256k1_ge_storage) == 64);+    memcpy(&s, buf, 64);+    secp256k1_ge_from_storage(r, &s);+}++static void secp256k1_ge_to_bytes_ext(unsigned char *data, const secp256k1_ge *ge) {+    if (secp256k1_ge_is_infinity(ge)) {+        memset(data, 0, 64);+    } else {+        secp256k1_ge_to_bytes(data, ge);+    }+}++static void secp256k1_ge_from_bytes_ext(secp256k1_ge *ge, const unsigned char *data) {+    static const unsigned char zeros[64] = { 0 };+    if (secp256k1_memcmp_var(data, zeros, sizeof(zeros)) == 0) {+        secp256k1_ge_set_infinity(ge);+    } else {+        secp256k1_ge_from_bytes(ge, data);+    }+}++#endif /* SECP256K1_GROUP_IMPL_H */
+ vendor/external/secp256k1/src/hash.h view
@@ -0,0 +1,44 @@+/***********************************************************************+ * Copyright (c) 2014 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_HASH_H+#define SECP256K1_HASH_H++#include <stdlib.h>+#include <stdint.h>++typedef struct {+    uint32_t s[8];+    unsigned char buf[64];+    uint64_t bytes;+} secp256k1_sha256;++static void secp256k1_sha256_initialize(secp256k1_sha256 *hash);+static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size);+static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32);+static void secp256k1_sha256_clear(secp256k1_sha256 *hash);++typedef struct {+    secp256k1_sha256 inner, outer;+} secp256k1_hmac_sha256;++static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256 *hash, const unsigned char *key, size_t size);+static void secp256k1_hmac_sha256_write(secp256k1_hmac_sha256 *hash, const unsigned char *data, size_t size);+static void secp256k1_hmac_sha256_finalize(secp256k1_hmac_sha256 *hash, unsigned char *out32);+static void secp256k1_hmac_sha256_clear(secp256k1_hmac_sha256 *hash);++typedef struct {+    unsigned char v[32];+    unsigned char k[32];+    int retry;+} secp256k1_rfc6979_hmac_sha256;++static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen);+static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen);+static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256 *rng);+static void secp256k1_rfc6979_hmac_sha256_clear(secp256k1_rfc6979_hmac_sha256 *rng);++#endif /* SECP256K1_HASH_H */
+ vendor/external/secp256k1/src/hash_impl.h view
@@ -0,0 +1,299 @@+/***********************************************************************+ * Copyright (c) 2014 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_HASH_IMPL_H+#define SECP256K1_HASH_IMPL_H++#include "hash.h"+#include "util.h"++#include <stdlib.h>+#include <stdint.h>+#include <string.h>++#define Ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))+#define Maj(x,y,z) (((x) & (y)) | ((z) & ((x) | (y))))+#define Sigma0(x) (((x) >> 2 | (x) << 30) ^ ((x) >> 13 | (x) << 19) ^ ((x) >> 22 | (x) << 10))+#define Sigma1(x) (((x) >> 6 | (x) << 26) ^ ((x) >> 11 | (x) << 21) ^ ((x) >> 25 | (x) << 7))+#define sigma0(x) (((x) >> 7 | (x) << 25) ^ ((x) >> 18 | (x) << 14) ^ ((x) >> 3))+#define sigma1(x) (((x) >> 17 | (x) << 15) ^ ((x) >> 19 | (x) << 13) ^ ((x) >> 10))++#define Round(a,b,c,d,e,f,g,h,k,w) do { \+    uint32_t t1 = (h) + Sigma1(e) + Ch((e), (f), (g)) + (k) + (w); \+    uint32_t t2 = Sigma0(a) + Maj((a), (b), (c)); \+    (d) += t1; \+    (h) = t1 + t2; \+} while(0)++static void secp256k1_sha256_initialize(secp256k1_sha256 *hash) {+    hash->s[0] = 0x6a09e667ul;+    hash->s[1] = 0xbb67ae85ul;+    hash->s[2] = 0x3c6ef372ul;+    hash->s[3] = 0xa54ff53aul;+    hash->s[4] = 0x510e527ful;+    hash->s[5] = 0x9b05688cul;+    hash->s[6] = 0x1f83d9abul;+    hash->s[7] = 0x5be0cd19ul;+    hash->bytes = 0;+}++/** Perform one SHA-256 transformation, processing 16 big endian 32-bit words. */+static void secp256k1_sha256_transform(uint32_t* s, const unsigned char* buf) {+    uint32_t a = s[0], b = s[1], c = s[2], d = s[3], e = s[4], f = s[5], g = s[6], h = s[7];+    uint32_t w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15;++    Round(a, b, c, d, e, f, g, h, 0x428a2f98,  w0 = secp256k1_read_be32(&buf[0]));+    Round(h, a, b, c, d, e, f, g, 0x71374491,  w1 = secp256k1_read_be32(&buf[4]));+    Round(g, h, a, b, c, d, e, f, 0xb5c0fbcf,  w2 = secp256k1_read_be32(&buf[8]));+    Round(f, g, h, a, b, c, d, e, 0xe9b5dba5,  w3 = secp256k1_read_be32(&buf[12]));+    Round(e, f, g, h, a, b, c, d, 0x3956c25b,  w4 = secp256k1_read_be32(&buf[16]));+    Round(d, e, f, g, h, a, b, c, 0x59f111f1,  w5 = secp256k1_read_be32(&buf[20]));+    Round(c, d, e, f, g, h, a, b, 0x923f82a4,  w6 = secp256k1_read_be32(&buf[24]));+    Round(b, c, d, e, f, g, h, a, 0xab1c5ed5,  w7 = secp256k1_read_be32(&buf[28]));+    Round(a, b, c, d, e, f, g, h, 0xd807aa98,  w8 = secp256k1_read_be32(&buf[32]));+    Round(h, a, b, c, d, e, f, g, 0x12835b01,  w9 = secp256k1_read_be32(&buf[36]));+    Round(g, h, a, b, c, d, e, f, 0x243185be, w10 = secp256k1_read_be32(&buf[40]));+    Round(f, g, h, a, b, c, d, e, 0x550c7dc3, w11 = secp256k1_read_be32(&buf[44]));+    Round(e, f, g, h, a, b, c, d, 0x72be5d74, w12 = secp256k1_read_be32(&buf[48]));+    Round(d, e, f, g, h, a, b, c, 0x80deb1fe, w13 = secp256k1_read_be32(&buf[52]));+    Round(c, d, e, f, g, h, a, b, 0x9bdc06a7, w14 = secp256k1_read_be32(&buf[56]));+    Round(b, c, d, e, f, g, h, a, 0xc19bf174, w15 = secp256k1_read_be32(&buf[60]));++    Round(a, b, c, d, e, f, g, h, 0xe49b69c1, w0 += sigma1(w14) + w9 + sigma0(w1));+    Round(h, a, b, c, d, e, f, g, 0xefbe4786, w1 += sigma1(w15) + w10 + sigma0(w2));+    Round(g, h, a, b, c, d, e, f, 0x0fc19dc6, w2 += sigma1(w0) + w11 + sigma0(w3));+    Round(f, g, h, a, b, c, d, e, 0x240ca1cc, w3 += sigma1(w1) + w12 + sigma0(w4));+    Round(e, f, g, h, a, b, c, d, 0x2de92c6f, w4 += sigma1(w2) + w13 + sigma0(w5));+    Round(d, e, f, g, h, a, b, c, 0x4a7484aa, w5 += sigma1(w3) + w14 + sigma0(w6));+    Round(c, d, e, f, g, h, a, b, 0x5cb0a9dc, w6 += sigma1(w4) + w15 + sigma0(w7));+    Round(b, c, d, e, f, g, h, a, 0x76f988da, w7 += sigma1(w5) + w0 + sigma0(w8));+    Round(a, b, c, d, e, f, g, h, 0x983e5152, w8 += sigma1(w6) + w1 + sigma0(w9));+    Round(h, a, b, c, d, e, f, g, 0xa831c66d, w9 += sigma1(w7) + w2 + sigma0(w10));+    Round(g, h, a, b, c, d, e, f, 0xb00327c8, w10 += sigma1(w8) + w3 + sigma0(w11));+    Round(f, g, h, a, b, c, d, e, 0xbf597fc7, w11 += sigma1(w9) + w4 + sigma0(w12));+    Round(e, f, g, h, a, b, c, d, 0xc6e00bf3, w12 += sigma1(w10) + w5 + sigma0(w13));+    Round(d, e, f, g, h, a, b, c, 0xd5a79147, w13 += sigma1(w11) + w6 + sigma0(w14));+    Round(c, d, e, f, g, h, a, b, 0x06ca6351, w14 += sigma1(w12) + w7 + sigma0(w15));+    Round(b, c, d, e, f, g, h, a, 0x14292967, w15 += sigma1(w13) + w8 + sigma0(w0));++    Round(a, b, c, d, e, f, g, h, 0x27b70a85, w0 += sigma1(w14) + w9 + sigma0(w1));+    Round(h, a, b, c, d, e, f, g, 0x2e1b2138, w1 += sigma1(w15) + w10 + sigma0(w2));+    Round(g, h, a, b, c, d, e, f, 0x4d2c6dfc, w2 += sigma1(w0) + w11 + sigma0(w3));+    Round(f, g, h, a, b, c, d, e, 0x53380d13, w3 += sigma1(w1) + w12 + sigma0(w4));+    Round(e, f, g, h, a, b, c, d, 0x650a7354, w4 += sigma1(w2) + w13 + sigma0(w5));+    Round(d, e, f, g, h, a, b, c, 0x766a0abb, w5 += sigma1(w3) + w14 + sigma0(w6));+    Round(c, d, e, f, g, h, a, b, 0x81c2c92e, w6 += sigma1(w4) + w15 + sigma0(w7));+    Round(b, c, d, e, f, g, h, a, 0x92722c85, w7 += sigma1(w5) + w0 + sigma0(w8));+    Round(a, b, c, d, e, f, g, h, 0xa2bfe8a1, w8 += sigma1(w6) + w1 + sigma0(w9));+    Round(h, a, b, c, d, e, f, g, 0xa81a664b, w9 += sigma1(w7) + w2 + sigma0(w10));+    Round(g, h, a, b, c, d, e, f, 0xc24b8b70, w10 += sigma1(w8) + w3 + sigma0(w11));+    Round(f, g, h, a, b, c, d, e, 0xc76c51a3, w11 += sigma1(w9) + w4 + sigma0(w12));+    Round(e, f, g, h, a, b, c, d, 0xd192e819, w12 += sigma1(w10) + w5 + sigma0(w13));+    Round(d, e, f, g, h, a, b, c, 0xd6990624, w13 += sigma1(w11) + w6 + sigma0(w14));+    Round(c, d, e, f, g, h, a, b, 0xf40e3585, w14 += sigma1(w12) + w7 + sigma0(w15));+    Round(b, c, d, e, f, g, h, a, 0x106aa070, w15 += sigma1(w13) + w8 + sigma0(w0));++    Round(a, b, c, d, e, f, g, h, 0x19a4c116, w0 += sigma1(w14) + w9 + sigma0(w1));+    Round(h, a, b, c, d, e, f, g, 0x1e376c08, w1 += sigma1(w15) + w10 + sigma0(w2));+    Round(g, h, a, b, c, d, e, f, 0x2748774c, w2 += sigma1(w0) + w11 + sigma0(w3));+    Round(f, g, h, a, b, c, d, e, 0x34b0bcb5, w3 += sigma1(w1) + w12 + sigma0(w4));+    Round(e, f, g, h, a, b, c, d, 0x391c0cb3, w4 += sigma1(w2) + w13 + sigma0(w5));+    Round(d, e, f, g, h, a, b, c, 0x4ed8aa4a, w5 += sigma1(w3) + w14 + sigma0(w6));+    Round(c, d, e, f, g, h, a, b, 0x5b9cca4f, w6 += sigma1(w4) + w15 + sigma0(w7));+    Round(b, c, d, e, f, g, h, a, 0x682e6ff3, w7 += sigma1(w5) + w0 + sigma0(w8));+    Round(a, b, c, d, e, f, g, h, 0x748f82ee, w8 += sigma1(w6) + w1 + sigma0(w9));+    Round(h, a, b, c, d, e, f, g, 0x78a5636f, w9 += sigma1(w7) + w2 + sigma0(w10));+    Round(g, h, a, b, c, d, e, f, 0x84c87814, w10 += sigma1(w8) + w3 + sigma0(w11));+    Round(f, g, h, a, b, c, d, e, 0x8cc70208, w11 += sigma1(w9) + w4 + sigma0(w12));+    Round(e, f, g, h, a, b, c, d, 0x90befffa, w12 += sigma1(w10) + w5 + sigma0(w13));+    Round(d, e, f, g, h, a, b, c, 0xa4506ceb, w13 += sigma1(w11) + w6 + sigma0(w14));+    Round(c, d, e, f, g, h, a, b, 0xbef9a3f7, w14 + sigma1(w12) + w7 + sigma0(w15));+    Round(b, c, d, e, f, g, h, a, 0xc67178f2, w15 + sigma1(w13) + w8 + sigma0(w0));++    s[0] += a;+    s[1] += b;+    s[2] += c;+    s[3] += d;+    s[4] += e;+    s[5] += f;+    s[6] += g;+    s[7] += h;+}++static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t len) {+    size_t bufsize = hash->bytes & 0x3F;+    hash->bytes += len;+    VERIFY_CHECK(hash->bytes >= len);+    while (len >= 64 - bufsize) {+        /* Fill the buffer, and process it. */+        size_t chunk_len = 64 - bufsize;+        memcpy(hash->buf + bufsize, data, chunk_len);+        data += chunk_len;+        len -= chunk_len;+        secp256k1_sha256_transform(hash->s, hash->buf);+        bufsize = 0;+    }+    if (len) {+        /* Fill the buffer with what remains. */+        memcpy(hash->buf + bufsize, data, len);+    }+}++static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32) {+    static const unsigned char pad[64] = {0x80};+    unsigned char sizedesc[8];+    int i;+    /* The maximum message size of SHA256 is 2^64-1 bits. */+    VERIFY_CHECK(hash->bytes < ((uint64_t)1 << 61));+    secp256k1_write_be32(&sizedesc[0], hash->bytes >> 29);+    secp256k1_write_be32(&sizedesc[4], hash->bytes << 3);+    secp256k1_sha256_write(hash, pad, 1 + ((119 - (hash->bytes % 64)) % 64));+    secp256k1_sha256_write(hash, sizedesc, 8);+    for (i = 0; i < 8; i++) {+        secp256k1_write_be32(&out32[4*i], hash->s[i]);+        hash->s[i] = 0;+    }+}++/* Initializes a sha256 struct and writes the 64 byte string+ * SHA256(tag)||SHA256(tag) into it. */+static void secp256k1_sha256_initialize_tagged(secp256k1_sha256 *hash, const unsigned char *tag, size_t taglen) {+    unsigned char buf[32];+    secp256k1_sha256_initialize(hash);+    secp256k1_sha256_write(hash, tag, taglen);+    secp256k1_sha256_finalize(hash, buf);++    secp256k1_sha256_initialize(hash);+    secp256k1_sha256_write(hash, buf, 32);+    secp256k1_sha256_write(hash, buf, 32);+}++static void secp256k1_sha256_clear(secp256k1_sha256 *hash) {+    secp256k1_memclear(hash, sizeof(*hash));+}++static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256 *hash, const unsigned char *key, size_t keylen) {+    size_t n;+    unsigned char rkey[64];+    if (keylen <= sizeof(rkey)) {+        memcpy(rkey, key, keylen);+        memset(rkey + keylen, 0, sizeof(rkey) - keylen);+    } else {+        secp256k1_sha256 sha256;+        secp256k1_sha256_initialize(&sha256);+        secp256k1_sha256_write(&sha256, key, keylen);+        secp256k1_sha256_finalize(&sha256, rkey);+        memset(rkey + 32, 0, 32);+    }++    secp256k1_sha256_initialize(&hash->outer);+    for (n = 0; n < sizeof(rkey); n++) {+        rkey[n] ^= 0x5c;+    }+    secp256k1_sha256_write(&hash->outer, rkey, sizeof(rkey));++    secp256k1_sha256_initialize(&hash->inner);+    for (n = 0; n < sizeof(rkey); n++) {+        rkey[n] ^= 0x5c ^ 0x36;+    }+    secp256k1_sha256_write(&hash->inner, rkey, sizeof(rkey));+    secp256k1_memclear(rkey, sizeof(rkey));+}++static void secp256k1_hmac_sha256_write(secp256k1_hmac_sha256 *hash, const unsigned char *data, size_t size) {+    secp256k1_sha256_write(&hash->inner, data, size);+}++static void secp256k1_hmac_sha256_finalize(secp256k1_hmac_sha256 *hash, unsigned char *out32) {+    unsigned char temp[32];+    secp256k1_sha256_finalize(&hash->inner, temp);+    secp256k1_sha256_write(&hash->outer, temp, 32);+    secp256k1_memclear(temp, sizeof(temp));+    secp256k1_sha256_finalize(&hash->outer, out32);+}++static void secp256k1_hmac_sha256_clear(secp256k1_hmac_sha256 *hash) {+    secp256k1_memclear(hash, sizeof(*hash));+}++static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen) {+    secp256k1_hmac_sha256 hmac;+    static const unsigned char zero[1] = {0x00};+    static const unsigned char one[1] = {0x01};++    memset(rng->v, 0x01, 32); /* RFC6979 3.2.b. */+    memset(rng->k, 0x00, 32); /* RFC6979 3.2.c. */++    /* RFC6979 3.2.d. */+    secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);+    secp256k1_hmac_sha256_write(&hmac, rng->v, 32);+    secp256k1_hmac_sha256_write(&hmac, zero, 1);+    secp256k1_hmac_sha256_write(&hmac, key, keylen);+    secp256k1_hmac_sha256_finalize(&hmac, rng->k);+    secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);+    secp256k1_hmac_sha256_write(&hmac, rng->v, 32);+    secp256k1_hmac_sha256_finalize(&hmac, rng->v);++    /* RFC6979 3.2.f. */+    secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);+    secp256k1_hmac_sha256_write(&hmac, rng->v, 32);+    secp256k1_hmac_sha256_write(&hmac, one, 1);+    secp256k1_hmac_sha256_write(&hmac, key, keylen);+    secp256k1_hmac_sha256_finalize(&hmac, rng->k);+    secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);+    secp256k1_hmac_sha256_write(&hmac, rng->v, 32);+    secp256k1_hmac_sha256_finalize(&hmac, rng->v);+    rng->retry = 0;+}++static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen) {+    /* RFC6979 3.2.h. */+    static const unsigned char zero[1] = {0x00};+    if (rng->retry) {+        secp256k1_hmac_sha256 hmac;+        secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);+        secp256k1_hmac_sha256_write(&hmac, rng->v, 32);+        secp256k1_hmac_sha256_write(&hmac, zero, 1);+        secp256k1_hmac_sha256_finalize(&hmac, rng->k);+        secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);+        secp256k1_hmac_sha256_write(&hmac, rng->v, 32);+        secp256k1_hmac_sha256_finalize(&hmac, rng->v);+    }++    while (outlen > 0) {+        secp256k1_hmac_sha256 hmac;+        int now = outlen;+        secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);+        secp256k1_hmac_sha256_write(&hmac, rng->v, 32);+        secp256k1_hmac_sha256_finalize(&hmac, rng->v);+        if (now > 32) {+            now = 32;+        }+        memcpy(out, rng->v, now);+        out += now;+        outlen -= now;+    }++    rng->retry = 1;+}++static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256 *rng) {+    (void) rng;+}++static void secp256k1_rfc6979_hmac_sha256_clear(secp256k1_rfc6979_hmac_sha256 *rng) {+    secp256k1_memclear(rng, sizeof(*rng));+}++#undef Round+#undef sigma1+#undef sigma0+#undef Sigma1+#undef Sigma0+#undef Maj+#undef Ch++#endif /* SECP256K1_HASH_IMPL_H */
+ vendor/external/secp256k1/src/hsort.h view
@@ -0,0 +1,33 @@+/***********************************************************************+ * Copyright (c) 2021 Russell O'Connor, Jonas Nick                     *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_HSORT_H+#define SECP256K1_HSORT_H++#include <stddef.h>+#include <string.h>++/* In-place, iterative heapsort with an interface matching glibc's qsort_r. This+ * is preferred over standard library implementations because they generally+ * make no guarantee about being fast for malicious inputs.+ * Remember that heapsort is unstable.+ *+ * In/Out: ptr: pointer to the array to sort. The contents of the array are+ *              sorted in ascending order according to the comparison function.+ * In:   count: number of elements in the array.+ *        size: size in bytes of each element.+ *         cmp: pointer to a comparison function that is called with two+ *              arguments that point to the objects being compared. The cmp_data+ *              argument of secp256k1_hsort is passed as third argument. The+ *              function must return an integer less than, equal to, or greater+ *              than zero if the first argument is considered to be respectively+ *              less than, equal to, or greater than the second.+ *    cmp_data: pointer passed as third argument to cmp.+ */+static void secp256k1_hsort(void *ptr, size_t count, size_t size,+                            int (*cmp)(const void *, const void *, void *),+                            void *cmp_data);+#endif
+ vendor/external/secp256k1/src/hsort_impl.h view
@@ -0,0 +1,125 @@+/***********************************************************************+ * Copyright (c) 2021 Russell O'Connor, Jonas Nick                     *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_HSORT_IMPL_H+#define SECP256K1_HSORT_IMPL_H++#include "hsort.h"++/* An array is a heap when, for all non-zero indexes i, the element at index i+ * compares as less than or equal to the element at index parent(i) = (i-1)/2.+ */++static SECP256K1_INLINE size_t secp256k1_heap_child1(size_t i) {+    VERIFY_CHECK(i <= (SIZE_MAX - 1)/2);+    return 2*i + 1;+}++static SECP256K1_INLINE size_t secp256k1_heap_child2(size_t i) {+    VERIFY_CHECK(i <= SIZE_MAX/2 - 1);+    return secp256k1_heap_child1(i)+1;+}++static SECP256K1_INLINE void secp256k1_heap_swap64(unsigned char *a, unsigned char *b, size_t len) {+    unsigned char tmp[64];+    VERIFY_CHECK(len <= 64);+    memcpy(tmp, a, len);+    memmove(a, b, len);+    memcpy(b, tmp, len);+}++static SECP256K1_INLINE void secp256k1_heap_swap(unsigned char *arr, size_t i, size_t j, size_t stride) {+    unsigned char *a = arr + i*stride;+    unsigned char *b = arr + j*stride;+    size_t len = stride;+    while (64 < len) {+        secp256k1_heap_swap64(a + (len - 64), b + (len - 64), 64);+        len -= 64;+    }+    secp256k1_heap_swap64(a, b, len);+}++/* This function accepts an array arr containing heap_size elements, each of+ * size stride. The elements in the array at indices >i satisfy the max-heap+ * property, i.e., for any element at index j (where j > i), all of its children+ * are smaller than the element itself. The purpose of the function is to update+ * the array so that all elements at indices >=i satisfy the max-heap+ * property. */+static SECP256K1_INLINE void secp256k1_heap_down(unsigned char *arr, size_t i, size_t heap_size, size_t stride,+                            int (*cmp)(const void *, const void *, void *), void *cmp_data) {+    while (i < heap_size/2) {+        VERIFY_CHECK(i <= SIZE_MAX/2 - 1);+        /* Proof:+         * i < heap_size/2+         * i + 1 <= heap_size/2+         * 2*i + 2 <= heap_size <= SIZE_MAX+         * 2*i <= SIZE_MAX - 2+         */++        VERIFY_CHECK(secp256k1_heap_child1(i) < heap_size);+        /* Proof:+         * i < heap_size/2+         * i + 1 <= heap_size/2+         * 2*i + 2 <= heap_size+         * 2*i + 1 < heap_size+         * child1(i) < heap_size+         */++        /* Let [x] be notation for the contents at arr[x*stride].+         *+         * If [child1(i)] > [i] and [child2(i)] > [i],+         *   swap [i] with the larger child to ensure the new parent is larger+         *   than both children. When [child1(i)] == [child2(i)], swap [i] with+         *   [child2(i)].+         * Else if [child1(i)] > [i], swap [i] with [child1(i)].+         * Else if [child2(i)] > [i], swap [i] with [child2(i)].+         */+        if (secp256k1_heap_child2(i) < heap_size+                && 0 <= cmp(arr + secp256k1_heap_child2(i)*stride, arr + secp256k1_heap_child1(i)*stride, cmp_data)) {+            if (0 < cmp(arr + secp256k1_heap_child2(i)*stride, arr + i*stride, cmp_data)) {+                secp256k1_heap_swap(arr, i, secp256k1_heap_child2(i), stride);+                i = secp256k1_heap_child2(i);+            } else {+                /* At this point we have [child2(i)] >= [child1(i)] and we have+                 * [child2(i)] <= [i], and thus [child1(i)] <= [i] which means+                 * that the next comparison can be skipped. */+                return;+            }+        } else if (0 < cmp(arr + secp256k1_heap_child1(i)*stride, arr +         i*stride, cmp_data)) {+            secp256k1_heap_swap(arr, i, secp256k1_heap_child1(i), stride);+            i = secp256k1_heap_child1(i);+        } else {+            return;+        }+    }+    /* heap_size/2 <= i+     * heap_size/2 < i + 1+     * heap_size < 2*i + 2+     * heap_size <= 2*i + 1+     * heap_size <= child1(i)+     * Thus child1(i) and child2(i) are now out of bounds and we are at a leaf.+     */+}++/* In-place heap sort. */+static void secp256k1_hsort(void *ptr, size_t count, size_t size,+                            int (*cmp)(const void *, const void *, void *),+                            void *cmp_data) {+    size_t i;++    for (i = count/2; 0 < i; --i) {+        secp256k1_heap_down(ptr, i-1, count, size, cmp, cmp_data);+    }+    for (i = count; 1 < i; --i) {+        /* Extract the largest value from the heap */+        secp256k1_heap_swap(ptr, 0, i-1, size);++        /* Repair the heap condition */+        secp256k1_heap_down(ptr, 0, i-1, size, cmp, cmp_data);+    }+}++#endif
+ vendor/external/secp256k1/src/int128.h view
@@ -0,0 +1,90 @@+#ifndef SECP256K1_INT128_H+#define SECP256K1_INT128_H++#include "util.h"++#if defined(SECP256K1_WIDEMUL_INT128)+#  if defined(SECP256K1_INT128_NATIVE)+#    include "int128_native.h"+#  elif defined(SECP256K1_INT128_STRUCT)+#    include "int128_struct.h"+#  else+#    error "Please select int128 implementation"+#  endif++/* Construct an unsigned 128-bit value from a high and a low 64-bit value. */+static SECP256K1_INLINE void secp256k1_u128_load(secp256k1_uint128 *r, uint64_t hi, uint64_t lo);++/* Multiply two unsigned 64-bit values a and b and write the result to r. */+static SECP256K1_INLINE void secp256k1_u128_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b);++/* Multiply two unsigned 64-bit values a and b and add the result to r.+ * The final result is taken modulo 2^128.+ */+static SECP256K1_INLINE void secp256k1_u128_accum_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b);++/* Add an unsigned 64-bit value a to r.+ * The final result is taken modulo 2^128.+ */+static SECP256K1_INLINE void secp256k1_u128_accum_u64(secp256k1_uint128 *r, uint64_t a);++/* Unsigned (logical) right shift.+ * Non-constant time in n.+ */+static SECP256K1_INLINE void secp256k1_u128_rshift(secp256k1_uint128 *r, unsigned int n);++/* Return the low 64-bits of a 128-bit value as an unsigned 64-bit value. */+static SECP256K1_INLINE uint64_t secp256k1_u128_to_u64(const secp256k1_uint128 *a);++/* Return the high 64-bits of a 128-bit value as an unsigned 64-bit value. */+static SECP256K1_INLINE uint64_t secp256k1_u128_hi_u64(const secp256k1_uint128 *a);++/* Write an unsigned 64-bit value to r. */+static SECP256K1_INLINE void secp256k1_u128_from_u64(secp256k1_uint128 *r, uint64_t a);++/* Tests if r is strictly less than to 2^n.+ * n must be strictly less than 128.+ */+static SECP256K1_INLINE int secp256k1_u128_check_bits(const secp256k1_uint128 *r, unsigned int n);++/* Construct an signed 128-bit value from a high and a low 64-bit value. */+static SECP256K1_INLINE void secp256k1_i128_load(secp256k1_int128 *r, int64_t hi, uint64_t lo);++/* Multiply two signed 64-bit values a and b and write the result to r. */+static SECP256K1_INLINE void secp256k1_i128_mul(secp256k1_int128 *r, int64_t a, int64_t b);++/* Multiply two signed 64-bit values a and b and add the result to r.+ * Overflow or underflow from the addition is undefined behaviour.+ */+static SECP256K1_INLINE void secp256k1_i128_accum_mul(secp256k1_int128 *r, int64_t a, int64_t b);++/* Compute a*d - b*c from signed 64-bit values and write the result to r. */+static SECP256K1_INLINE void secp256k1_i128_det(secp256k1_int128 *r, int64_t a, int64_t b, int64_t c, int64_t d);++/* Signed (arithmetic) right shift.+ * Non-constant time in b.+ */+static SECP256K1_INLINE void secp256k1_i128_rshift(secp256k1_int128 *r, unsigned int b);++/* Return the input value modulo 2^64. */+static SECP256K1_INLINE uint64_t secp256k1_i128_to_u64(const secp256k1_int128 *a);++/* Return the value as a signed 64-bit value.+ * Requires the input to be between INT64_MIN and INT64_MAX.+ */+static SECP256K1_INLINE int64_t secp256k1_i128_to_i64(const secp256k1_int128 *a);++/* Write a signed 64-bit value to r. */+static SECP256K1_INLINE void secp256k1_i128_from_i64(secp256k1_int128 *r, int64_t a);++/* Compare two 128-bit values for equality. */+static SECP256K1_INLINE int secp256k1_i128_eq_var(const secp256k1_int128 *a, const secp256k1_int128 *b);++/* Tests if r is equal to sign*2^n (sign must be 1 or -1).+ * n must be strictly less than 127.+ */+static SECP256K1_INLINE int secp256k1_i128_check_pow2(const secp256k1_int128 *r, unsigned int n, int sign);++#endif++#endif
+ vendor/external/secp256k1/src/int128_impl.h view
@@ -0,0 +1,18 @@+#ifndef SECP256K1_INT128_IMPL_H+#define SECP256K1_INT128_IMPL_H++#include "util.h"++#include "int128.h"++#if defined(SECP256K1_WIDEMUL_INT128)+#  if defined(SECP256K1_INT128_NATIVE)+#    include "int128_native_impl.h"+#  elif defined(SECP256K1_INT128_STRUCT)+#    include "int128_struct_impl.h"+#  else+#    error "Please select int128 implementation"+#  endif+#endif++#endif
+ vendor/external/secp256k1/src/int128_native.h view
@@ -0,0 +1,19 @@+#ifndef SECP256K1_INT128_NATIVE_H+#define SECP256K1_INT128_NATIVE_H++#include <stdint.h>+#include "util.h"++#if !defined(UINT128_MAX) && defined(__SIZEOF_INT128__)+SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t;+SECP256K1_GNUC_EXT typedef __int128 int128_t;+# define UINT128_MAX ((uint128_t)(-1))+# define INT128_MAX ((int128_t)(UINT128_MAX >> 1))+# define INT128_MIN (-INT128_MAX - 1)+/* No (U)INT128_C macros because compilers providing __int128 do not support 128-bit literals.  */+#endif++typedef uint128_t secp256k1_uint128;+typedef int128_t secp256k1_int128;++#endif
+ vendor/external/secp256k1/src/int128_native_impl.h view
@@ -0,0 +1,94 @@+#ifndef SECP256K1_INT128_NATIVE_IMPL_H+#define SECP256K1_INT128_NATIVE_IMPL_H++#include "int128.h"+#include "util.h"++static SECP256K1_INLINE void secp256k1_u128_load(secp256k1_uint128 *r, uint64_t hi, uint64_t lo) {+    *r = (((uint128_t)hi) << 64) + lo;+}++static SECP256K1_INLINE void secp256k1_u128_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b) {+   *r = (uint128_t)a * b;+}++static SECP256K1_INLINE void secp256k1_u128_accum_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b) {+   *r += (uint128_t)a * b;+}++static SECP256K1_INLINE void secp256k1_u128_accum_u64(secp256k1_uint128 *r, uint64_t a) {+   *r += a;+}++static SECP256K1_INLINE void secp256k1_u128_rshift(secp256k1_uint128 *r, unsigned int n) {+   VERIFY_CHECK(n < 128);+   *r >>= n;+}++static SECP256K1_INLINE uint64_t secp256k1_u128_to_u64(const secp256k1_uint128 *a) {+   return (uint64_t)(*a);+}++static SECP256K1_INLINE uint64_t secp256k1_u128_hi_u64(const secp256k1_uint128 *a) {+   return (uint64_t)(*a >> 64);+}++static SECP256K1_INLINE void secp256k1_u128_from_u64(secp256k1_uint128 *r, uint64_t a) {+   *r = a;+}++static SECP256K1_INLINE int secp256k1_u128_check_bits(const secp256k1_uint128 *r, unsigned int n) {+   VERIFY_CHECK(n < 128);+   return (*r >> n == 0);+}++static SECP256K1_INLINE void secp256k1_i128_load(secp256k1_int128 *r, int64_t hi, uint64_t lo) {+    *r = (((uint128_t)(uint64_t)hi) << 64) + lo;+}++static SECP256K1_INLINE void secp256k1_i128_mul(secp256k1_int128 *r, int64_t a, int64_t b) {+   *r = (int128_t)a * b;+}++static SECP256K1_INLINE void secp256k1_i128_accum_mul(secp256k1_int128 *r, int64_t a, int64_t b) {+   int128_t ab = (int128_t)a * b;+   VERIFY_CHECK(0 <= ab ? *r <= INT128_MAX - ab : INT128_MIN - ab <= *r);+   *r += ab;+}++static SECP256K1_INLINE void secp256k1_i128_det(secp256k1_int128 *r, int64_t a, int64_t b, int64_t c, int64_t d) {+   int128_t ad = (int128_t)a * d;+   int128_t bc = (int128_t)b * c;+   VERIFY_CHECK(0 <= bc ? INT128_MIN + bc <= ad : ad <= INT128_MAX + bc);+   *r = ad - bc;+}++static SECP256K1_INLINE void secp256k1_i128_rshift(secp256k1_int128 *r, unsigned int n) {+   VERIFY_CHECK(n < 128);+   *r >>= n;+}++static SECP256K1_INLINE uint64_t secp256k1_i128_to_u64(const secp256k1_int128 *a) {+   return (uint64_t)*a;+}++static SECP256K1_INLINE int64_t secp256k1_i128_to_i64(const secp256k1_int128 *a) {+   VERIFY_CHECK(INT64_MIN <= *a && *a <= INT64_MAX);+   return *a;+}++static SECP256K1_INLINE void secp256k1_i128_from_i64(secp256k1_int128 *r, int64_t a) {+   *r = a;+}++static SECP256K1_INLINE int secp256k1_i128_eq_var(const secp256k1_int128 *a, const secp256k1_int128 *b) {+   return *a == *b;+}++static SECP256K1_INLINE int secp256k1_i128_check_pow2(const secp256k1_int128 *r, unsigned int n, int sign) {+   VERIFY_CHECK(n < 127);+   VERIFY_CHECK(sign == 1 || sign == -1);+   return (*r == (int128_t)((uint128_t)sign << n));+}++#endif
+ vendor/external/secp256k1/src/int128_struct.h view
@@ -0,0 +1,14 @@+#ifndef SECP256K1_INT128_STRUCT_H+#define SECP256K1_INT128_STRUCT_H++#include <stdint.h>+#include "util.h"++typedef struct {+  uint64_t lo;+  uint64_t hi;+} secp256k1_uint128;++typedef secp256k1_uint128 secp256k1_int128;++#endif
+ vendor/external/secp256k1/src/int128_struct_impl.h view
@@ -0,0 +1,205 @@+#ifndef SECP256K1_INT128_STRUCT_IMPL_H+#define SECP256K1_INT128_STRUCT_IMPL_H++#include "int128.h"+#include "util.h"++#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64)) /* MSVC */+#    include <intrin.h>+#    if defined(_M_ARM64) || defined(SECP256K1_MSVC_MULH_TEST_OVERRIDE)+/* On ARM64 MSVC, use __(u)mulh for the upper half of 64x64 multiplications.+   (Define SECP256K1_MSVC_MULH_TEST_OVERRIDE to test this code path on X64,+   which supports both __(u)mulh and _umul128.) */+#        if defined(SECP256K1_MSVC_MULH_TEST_OVERRIDE)+#            pragma message(__FILE__ ": SECP256K1_MSVC_MULH_TEST_OVERRIDE is defined, forcing use of __(u)mulh.")+#        endif+static SECP256K1_INLINE uint64_t secp256k1_umul128(uint64_t a, uint64_t b, uint64_t* hi) {+    *hi = __umulh(a, b);+    return a * b;+}++static SECP256K1_INLINE int64_t secp256k1_mul128(int64_t a, int64_t b, int64_t* hi) {+    *hi = __mulh(a, b);+    return (uint64_t)a * (uint64_t)b;+}+#    else+/* On x84_64 MSVC, use native _(u)mul128 for 64x64->128 multiplications. */+#        define secp256k1_umul128 _umul128+#        define secp256k1_mul128 _mul128+#    endif+#else+/* On other systems, emulate 64x64->128 multiplications using 32x32->64 multiplications. */+static SECP256K1_INLINE uint64_t secp256k1_umul128(uint64_t a, uint64_t b, uint64_t* hi) {+    uint64_t ll = (uint64_t)(uint32_t)a * (uint32_t)b;+    uint64_t lh = (uint32_t)a * (b >> 32);+    uint64_t hl = (a >> 32) * (uint32_t)b;+    uint64_t hh = (a >> 32) * (b >> 32);+    uint64_t mid34 = (ll >> 32) + (uint32_t)lh + (uint32_t)hl;+    *hi = hh + (lh >> 32) + (hl >> 32) + (mid34 >> 32);+    return (mid34 << 32) + (uint32_t)ll;+}++static SECP256K1_INLINE int64_t secp256k1_mul128(int64_t a, int64_t b, int64_t* hi) {+    uint64_t ll = (uint64_t)(uint32_t)a * (uint32_t)b;+    int64_t lh = (uint32_t)a * (b >> 32);+    int64_t hl = (a >> 32) * (uint32_t)b;+    int64_t hh = (a >> 32) * (b >> 32);+    uint64_t mid34 = (ll >> 32) + (uint32_t)lh + (uint32_t)hl;+    *hi = hh + (lh >> 32) + (hl >> 32) + (mid34 >> 32);+    return (mid34 << 32) + (uint32_t)ll;+}+#endif++static SECP256K1_INLINE void secp256k1_u128_load(secp256k1_uint128 *r, uint64_t hi, uint64_t lo) {+    r->hi = hi;+    r->lo = lo;+}++static SECP256K1_INLINE void secp256k1_u128_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b) {+   r->lo = secp256k1_umul128(a, b, &r->hi);+}++static SECP256K1_INLINE void secp256k1_u128_accum_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b) {+   uint64_t lo, hi;+   lo = secp256k1_umul128(a, b, &hi);+   r->lo += lo;+   r->hi += hi + (r->lo < lo);+}++static SECP256K1_INLINE void secp256k1_u128_accum_u64(secp256k1_uint128 *r, uint64_t a) {+   r->lo += a;+   r->hi += r->lo < a;+}++/* Unsigned (logical) right shift.+ * Non-constant time in n.+ */+static SECP256K1_INLINE void secp256k1_u128_rshift(secp256k1_uint128 *r, unsigned int n) {+   VERIFY_CHECK(n < 128);+   if (n >= 64) {+     r->lo = r->hi >> (n-64);+     r->hi = 0;+   } else if (n > 0) {+#if defined(_MSC_VER) && defined(_M_X64)+     VERIFY_CHECK(n < 64);+     r->lo = __shiftright128(r->lo, r->hi, n);+#else+     r->lo = ((1U * r->hi) << (64-n)) | r->lo >> n;+#endif+     r->hi >>= n;+   }+}++static SECP256K1_INLINE uint64_t secp256k1_u128_to_u64(const secp256k1_uint128 *a) {+   return a->lo;+}++static SECP256K1_INLINE uint64_t secp256k1_u128_hi_u64(const secp256k1_uint128 *a) {+   return a->hi;+}++static SECP256K1_INLINE void secp256k1_u128_from_u64(secp256k1_uint128 *r, uint64_t a) {+   r->hi = 0;+   r->lo = a;+}++static SECP256K1_INLINE int secp256k1_u128_check_bits(const secp256k1_uint128 *r, unsigned int n) {+   VERIFY_CHECK(n < 128);+   return n >= 64 ? r->hi >> (n - 64) == 0+                  : r->hi == 0 && r->lo >> n == 0;+}++static SECP256K1_INLINE void secp256k1_i128_load(secp256k1_int128 *r, int64_t hi, uint64_t lo) {+    r->hi = hi;+    r->lo = lo;+}++static SECP256K1_INLINE void secp256k1_i128_mul(secp256k1_int128 *r, int64_t a, int64_t b) {+   int64_t hi;+   r->lo = (uint64_t)secp256k1_mul128(a, b, &hi);+   r->hi = (uint64_t)hi;+}++static SECP256K1_INLINE void secp256k1_i128_accum_mul(secp256k1_int128 *r, int64_t a, int64_t b) {+   int64_t hi;+   uint64_t lo = (uint64_t)secp256k1_mul128(a, b, &hi);+   r->lo += lo;+   hi += r->lo < lo;+   /* Verify no overflow.+    * If r represents a positive value (the sign bit is not set) and the value we are adding is a positive value (the sign bit is not set),+    * then we require that the resulting value also be positive (the sign bit is not set).+    * Note that (X <= Y) means (X implies Y) when X and Y are boolean values (i.e. 0 or 1).+    */+   VERIFY_CHECK((r->hi <= 0x7fffffffffffffffu && (uint64_t)hi <= 0x7fffffffffffffffu) <= (r->hi + (uint64_t)hi <= 0x7fffffffffffffffu));+   /* Verify no underflow.+    * If r represents a negative value (the sign bit is set) and the value we are adding is a negative value (the sign bit is set),+    * then we require that the resulting value also be negative (the sign bit is set).+    */+   VERIFY_CHECK((r->hi > 0x7fffffffffffffffu && (uint64_t)hi > 0x7fffffffffffffffu) <= (r->hi + (uint64_t)hi > 0x7fffffffffffffffu));+   r->hi += hi;+}++static SECP256K1_INLINE void secp256k1_i128_dissip_mul(secp256k1_int128 *r, int64_t a, int64_t b) {+   int64_t hi;+   uint64_t lo = (uint64_t)secp256k1_mul128(a, b, &hi);+   hi += r->lo < lo;+   /* Verify no overflow.+    * If r represents a positive value (the sign bit is not set) and the value we are subtracting is a negative value (the sign bit is set),+    * then we require that the resulting value also be positive (the sign bit is not set).+    */+   VERIFY_CHECK((r->hi <= 0x7fffffffffffffffu && (uint64_t)hi > 0x7fffffffffffffffu) <= (r->hi - (uint64_t)hi <= 0x7fffffffffffffffu));+   /* Verify no underflow.+    * If r represents a negative value (the sign bit is set) and the value we are subtracting is a positive value (the sign sign bit is not set),+    * then we require that the resulting value also be negative (the sign bit is set).+    */+   VERIFY_CHECK((r->hi > 0x7fffffffffffffffu && (uint64_t)hi <= 0x7fffffffffffffffu) <= (r->hi - (uint64_t)hi > 0x7fffffffffffffffu));+   r->hi -= hi;+   r->lo -= lo;+}++static SECP256K1_INLINE void secp256k1_i128_det(secp256k1_int128 *r, int64_t a, int64_t b, int64_t c, int64_t d) {+   secp256k1_i128_mul(r, a, d);+   secp256k1_i128_dissip_mul(r, b, c);+}++/* Signed (arithmetic) right shift.+ * Non-constant time in n.+ */+static SECP256K1_INLINE void secp256k1_i128_rshift(secp256k1_int128 *r, unsigned int n) {+   VERIFY_CHECK(n < 128);+   if (n >= 64) {+     r->lo = (uint64_t)((int64_t)(r->hi) >> (n-64));+     r->hi = (uint64_t)((int64_t)(r->hi) >> 63);+   } else if (n > 0) {+     r->lo = ((1U * r->hi) << (64-n)) | r->lo >> n;+     r->hi = (uint64_t)((int64_t)(r->hi) >> n);+   }+}++static SECP256K1_INLINE uint64_t secp256k1_i128_to_u64(const secp256k1_int128 *a) {+   return a->lo;+}++static SECP256K1_INLINE int64_t secp256k1_i128_to_i64(const secp256k1_int128 *a) {+   /* Verify that a represents a 64 bit signed value by checking that the high bits are a sign extension of the low bits. */+   VERIFY_CHECK(a->hi == -(a->lo >> 63));+   return (int64_t)secp256k1_i128_to_u64(a);+}++static SECP256K1_INLINE void secp256k1_i128_from_i64(secp256k1_int128 *r, int64_t a) {+   r->hi = (uint64_t)(a >> 63);+   r->lo = (uint64_t)a;+}++static SECP256K1_INLINE int secp256k1_i128_eq_var(const secp256k1_int128 *a, const secp256k1_int128 *b) {+   return a->hi == b->hi && a->lo == b->lo;+}++static SECP256K1_INLINE int secp256k1_i128_check_pow2(const secp256k1_int128 *r, unsigned int n, int sign) {+    VERIFY_CHECK(n < 127);+    VERIFY_CHECK(sign == 1 || sign == -1);+    return n >= 64 ? r->hi == (uint64_t)sign << (n - 64) && r->lo == 0+                   : r->hi == (uint64_t)(sign >> 1) && r->lo == (uint64_t)sign << n;+}++#endif
+ vendor/external/secp256k1/src/modinv32.h view
@@ -0,0 +1,43 @@+/***********************************************************************+ * Copyright (c) 2020 Peter Dettman                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ **********************************************************************/++#ifndef SECP256K1_MODINV32_H+#define SECP256K1_MODINV32_H++#include "util.h"++/* A signed 30-bit limb representation of integers.+ *+ * Its value is sum(v[i] * 2^(30*i), i=0..8). */+typedef struct {+    int32_t v[9];+} secp256k1_modinv32_signed30;++typedef struct {+    /* The modulus in signed30 notation, must be odd and in [3, 2^256]. */+    secp256k1_modinv32_signed30 modulus;++    /* modulus^{-1} mod 2^30 */+    uint32_t modulus_inv30;+} secp256k1_modinv32_modinfo;++/* Replace x with its modular inverse mod modinfo->modulus. x must be in range [0, modulus).+ * If x is zero, the result will be zero as well. If not, the inverse must exist (i.e., the gcd of+ * x and modulus must be 1). These rules are automatically satisfied if the modulus is prime.+ *+ * On output, all of x's limbs will be in [0, 2^30).+ */+static void secp256k1_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo);++/* Same as secp256k1_modinv32_var, but constant time in x (not in the modulus). */+static void secp256k1_modinv32(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo);++/* Compute the Jacobi symbol for (x | modinfo->modulus). x must be coprime with modulus (and thus+ * cannot be 0, as modulus >= 3). All limbs of x must be non-negative. Returns 0 if the result+ * cannot be computed. */+static int secp256k1_jacobi32_maybe_var(const secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo);++#endif /* SECP256K1_MODINV32_H */
+ vendor/external/secp256k1/src/modinv32_impl.h view
@@ -0,0 +1,725 @@+/***********************************************************************+ * Copyright (c) 2020 Peter Dettman                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ **********************************************************************/++#ifndef SECP256K1_MODINV32_IMPL_H+#define SECP256K1_MODINV32_IMPL_H++#include "modinv32.h"++#include "util.h"++#include <stdlib.h>++/* This file implements modular inversion based on the paper "Fast constant-time gcd computation and+ * modular inversion" by Daniel J. Bernstein and Bo-Yin Yang.+ *+ * For an explanation of the algorithm, see doc/safegcd_implementation.md. This file contains an+ * implementation for N=30, using 30-bit signed limbs represented as int32_t.+ */++#ifdef VERIFY+static const secp256k1_modinv32_signed30 SECP256K1_SIGNED30_ONE = {{1}};++/* Compute a*factor and put it in r. All but the top limb in r will be in range [0,2^30). */+static void secp256k1_modinv32_mul_30(secp256k1_modinv32_signed30 *r, const secp256k1_modinv32_signed30 *a, int alen, int32_t factor) {+    const int32_t M30 = (int32_t)(UINT32_MAX >> 2);+    int64_t c = 0;+    int i;+    for (i = 0; i < 8; ++i) {+        if (i < alen) c += (int64_t)a->v[i] * factor;+        r->v[i] = (int32_t)c & M30; c >>= 30;+    }+    if (8 < alen) c += (int64_t)a->v[8] * factor;+    VERIFY_CHECK(c == (int32_t)c);+    r->v[8] = (int32_t)c;+}++/* Return -1 for a<b*factor, 0 for a==b*factor, 1 for a>b*factor. A consists of alen limbs; b has 9. */+static int secp256k1_modinv32_mul_cmp_30(const secp256k1_modinv32_signed30 *a, int alen, const secp256k1_modinv32_signed30 *b, int32_t factor) {+    int i;+    secp256k1_modinv32_signed30 am, bm;+    secp256k1_modinv32_mul_30(&am, a, alen, 1); /* Normalize all but the top limb of a. */+    secp256k1_modinv32_mul_30(&bm, b, 9, factor);+    for (i = 0; i < 8; ++i) {+        /* Verify that all but the top limb of a and b are normalized. */+        VERIFY_CHECK(am.v[i] >> 30 == 0);+        VERIFY_CHECK(bm.v[i] >> 30 == 0);+    }+    for (i = 8; i >= 0; --i) {+        if (am.v[i] < bm.v[i]) return -1;+        if (am.v[i] > bm.v[i]) return 1;+    }+    return 0;+}+#endif++/* Take as input a signed30 number in range (-2*modulus,modulus), and add a multiple of the modulus+ * to it to bring it to range [0,modulus). If sign < 0, the input will also be negated in the+ * process. The input must have limbs in range (-2^30,2^30). The output will have limbs in range+ * [0,2^30). */+static void secp256k1_modinv32_normalize_30(secp256k1_modinv32_signed30 *r, int32_t sign, const secp256k1_modinv32_modinfo *modinfo) {+    const int32_t M30 = (int32_t)(UINT32_MAX >> 2);+    int32_t r0 = r->v[0], r1 = r->v[1], r2 = r->v[2], r3 = r->v[3], r4 = r->v[4],+            r5 = r->v[5], r6 = r->v[6], r7 = r->v[7], r8 = r->v[8];+    volatile int32_t cond_add, cond_negate;++#ifdef VERIFY+    /* Verify that all limbs are in range (-2^30,2^30). */+    int i;+    for (i = 0; i < 9; ++i) {+        VERIFY_CHECK(r->v[i] >= -M30);+        VERIFY_CHECK(r->v[i] <= M30);+    }+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, -2) > 0); /* r > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 1) < 0); /* r < modulus */+#endif++    /* In a first step, add the modulus if the input is negative, and then negate if requested.+     * This brings r from range (-2*modulus,modulus) to range (-modulus,modulus). As all input+     * limbs are in range (-2^30,2^30), this cannot overflow an int32_t. Note that the right+     * shifts below are signed sign-extending shifts (see assumptions.h for tests that that is+     * indeed the behavior of the right shift operator). */+    cond_add = r8 >> 31;+    r0 += modinfo->modulus.v[0] & cond_add;+    r1 += modinfo->modulus.v[1] & cond_add;+    r2 += modinfo->modulus.v[2] & cond_add;+    r3 += modinfo->modulus.v[3] & cond_add;+    r4 += modinfo->modulus.v[4] & cond_add;+    r5 += modinfo->modulus.v[5] & cond_add;+    r6 += modinfo->modulus.v[6] & cond_add;+    r7 += modinfo->modulus.v[7] & cond_add;+    r8 += modinfo->modulus.v[8] & cond_add;+    cond_negate = sign >> 31;+    r0 = (r0 ^ cond_negate) - cond_negate;+    r1 = (r1 ^ cond_negate) - cond_negate;+    r2 = (r2 ^ cond_negate) - cond_negate;+    r3 = (r3 ^ cond_negate) - cond_negate;+    r4 = (r4 ^ cond_negate) - cond_negate;+    r5 = (r5 ^ cond_negate) - cond_negate;+    r6 = (r6 ^ cond_negate) - cond_negate;+    r7 = (r7 ^ cond_negate) - cond_negate;+    r8 = (r8 ^ cond_negate) - cond_negate;+    /* Propagate the top bits, to bring limbs back to range (-2^30,2^30). */+    r1 += r0 >> 30; r0 &= M30;+    r2 += r1 >> 30; r1 &= M30;+    r3 += r2 >> 30; r2 &= M30;+    r4 += r3 >> 30; r3 &= M30;+    r5 += r4 >> 30; r4 &= M30;+    r6 += r5 >> 30; r5 &= M30;+    r7 += r6 >> 30; r6 &= M30;+    r8 += r7 >> 30; r7 &= M30;++    /* In a second step add the modulus again if the result is still negative, bringing r to range+     * [0,modulus). */+    cond_add = r8 >> 31;+    r0 += modinfo->modulus.v[0] & cond_add;+    r1 += modinfo->modulus.v[1] & cond_add;+    r2 += modinfo->modulus.v[2] & cond_add;+    r3 += modinfo->modulus.v[3] & cond_add;+    r4 += modinfo->modulus.v[4] & cond_add;+    r5 += modinfo->modulus.v[5] & cond_add;+    r6 += modinfo->modulus.v[6] & cond_add;+    r7 += modinfo->modulus.v[7] & cond_add;+    r8 += modinfo->modulus.v[8] & cond_add;+    /* And propagate again. */+    r1 += r0 >> 30; r0 &= M30;+    r2 += r1 >> 30; r1 &= M30;+    r3 += r2 >> 30; r2 &= M30;+    r4 += r3 >> 30; r3 &= M30;+    r5 += r4 >> 30; r4 &= M30;+    r6 += r5 >> 30; r5 &= M30;+    r7 += r6 >> 30; r6 &= M30;+    r8 += r7 >> 30; r7 &= M30;++    r->v[0] = r0;+    r->v[1] = r1;+    r->v[2] = r2;+    r->v[3] = r3;+    r->v[4] = r4;+    r->v[5] = r5;+    r->v[6] = r6;+    r->v[7] = r7;+    r->v[8] = r8;++    VERIFY_CHECK(r0 >> 30 == 0);+    VERIFY_CHECK(r1 >> 30 == 0);+    VERIFY_CHECK(r2 >> 30 == 0);+    VERIFY_CHECK(r3 >> 30 == 0);+    VERIFY_CHECK(r4 >> 30 == 0);+    VERIFY_CHECK(r5 >> 30 == 0);+    VERIFY_CHECK(r6 >> 30 == 0);+    VERIFY_CHECK(r7 >> 30 == 0);+    VERIFY_CHECK(r8 >> 30 == 0);+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 0) >= 0); /* r >= 0 */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(r, 9, &modinfo->modulus, 1) < 0); /* r < modulus */+}++/* Data type for transition matrices (see section 3 of explanation).+ *+ * t = [ u  v ]+ *     [ q  r ]+ */+typedef struct {+    int32_t u, v, q, r;+} secp256k1_modinv32_trans2x2;++/* Compute the transition matrix and zeta for 30 divsteps.+ *+ * Input:  zeta: initial zeta+ *         f0:   bottom limb of initial f+ *         g0:   bottom limb of initial g+ * Output: t: transition matrix+ * Return: final zeta+ *+ * Implements the divsteps_n_matrix function from the explanation.+ */+static int32_t secp256k1_modinv32_divsteps_30(int32_t zeta, uint32_t f0, uint32_t g0, secp256k1_modinv32_trans2x2 *t) {+    /* u,v,q,r are the elements of the transformation matrix being built up,+     * starting with the identity matrix. Semantically they are signed integers+     * in range [-2^30,2^30], but here represented as unsigned mod 2^32. This+     * permits left shifting (which is UB for negative numbers). The range+     * being inside [-2^31,2^31) means that casting to signed works correctly.+     */+    uint32_t u = 1, v = 0, q = 0, r = 1;+    volatile uint32_t c1, c2;+    uint32_t mask1, mask2, f = f0, g = g0, x, y, z;+    int i;++    for (i = 0; i < 30; ++i) {+        VERIFY_CHECK((f & 1) == 1); /* f must always be odd */+        VERIFY_CHECK((u * f0 + v * g0) == f << i);+        VERIFY_CHECK((q * f0 + r * g0) == g << i);+        /* Compute conditional masks for (zeta < 0) and for (g & 1). */+        c1 = zeta >> 31;+        mask1 = c1;+        c2 = g & 1;+        mask2 = -c2;+        /* Compute x,y,z, conditionally negated versions of f,u,v. */+        x = (f ^ mask1) - mask1;+        y = (u ^ mask1) - mask1;+        z = (v ^ mask1) - mask1;+        /* Conditionally add x,y,z to g,q,r. */+        g += x & mask2;+        q += y & mask2;+        r += z & mask2;+        /* In what follows, mask1 is a condition mask for (zeta < 0) and (g & 1). */+        mask1 &= mask2;+        /* Conditionally change zeta into -zeta-2 or zeta-1. */+        zeta = (zeta ^ mask1) - 1;+        /* Conditionally add g,q,r to f,u,v. */+        f += g & mask1;+        u += q & mask1;+        v += r & mask1;+        /* Shifts */+        g >>= 1;+        u <<= 1;+        v <<= 1;+        /* Bounds on zeta that follow from the bounds on iteration count (max 20*30 divsteps). */+        VERIFY_CHECK(zeta >= -601 && zeta <= 601);+    }+    /* Return data in t and return value. */+    t->u = (int32_t)u;+    t->v = (int32_t)v;+    t->q = (int32_t)q;+    t->r = (int32_t)r;+    /* The determinant of t must be a power of two. This guarantees that multiplication with t+     * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which+     * will be divided out again). As each divstep's individual matrix has determinant 2, the+     * aggregate of 30 of them will have determinant 2^30. */+    VERIFY_CHECK((int64_t)t->u * t->r - (int64_t)t->v * t->q == ((int64_t)1) << 30);+    return zeta;+}++/* secp256k1_modinv32_inv256[i] = -(2*i+1)^-1 (mod 256) */+static const uint8_t secp256k1_modinv32_inv256[128] = {+    0xFF, 0x55, 0x33, 0x49, 0xC7, 0x5D, 0x3B, 0x11, 0x0F, 0xE5, 0xC3, 0x59,+    0xD7, 0xED, 0xCB, 0x21, 0x1F, 0x75, 0x53, 0x69, 0xE7, 0x7D, 0x5B, 0x31,+    0x2F, 0x05, 0xE3, 0x79, 0xF7, 0x0D, 0xEB, 0x41, 0x3F, 0x95, 0x73, 0x89,+    0x07, 0x9D, 0x7B, 0x51, 0x4F, 0x25, 0x03, 0x99, 0x17, 0x2D, 0x0B, 0x61,+    0x5F, 0xB5, 0x93, 0xA9, 0x27, 0xBD, 0x9B, 0x71, 0x6F, 0x45, 0x23, 0xB9,+    0x37, 0x4D, 0x2B, 0x81, 0x7F, 0xD5, 0xB3, 0xC9, 0x47, 0xDD, 0xBB, 0x91,+    0x8F, 0x65, 0x43, 0xD9, 0x57, 0x6D, 0x4B, 0xA1, 0x9F, 0xF5, 0xD3, 0xE9,+    0x67, 0xFD, 0xDB, 0xB1, 0xAF, 0x85, 0x63, 0xF9, 0x77, 0x8D, 0x6B, 0xC1,+    0xBF, 0x15, 0xF3, 0x09, 0x87, 0x1D, 0xFB, 0xD1, 0xCF, 0xA5, 0x83, 0x19,+    0x97, 0xAD, 0x8B, 0xE1, 0xDF, 0x35, 0x13, 0x29, 0xA7, 0x3D, 0x1B, 0xF1,+    0xEF, 0xC5, 0xA3, 0x39, 0xB7, 0xCD, 0xAB, 0x01+};++/* Compute the transition matrix and eta for 30 divsteps (variable time).+ *+ * Input:  eta: initial eta+ *         f0:  bottom limb of initial f+ *         g0:  bottom limb of initial g+ * Output: t: transition matrix+ * Return: final eta+ *+ * Implements the divsteps_n_matrix_var function from the explanation.+ */+static int32_t secp256k1_modinv32_divsteps_30_var(int32_t eta, uint32_t f0, uint32_t g0, secp256k1_modinv32_trans2x2 *t) {+    /* Transformation matrix; see comments in secp256k1_modinv32_divsteps_30. */+    uint32_t u = 1, v = 0, q = 0, r = 1;+    uint32_t f = f0, g = g0, m;+    uint16_t w;+    int i = 30, limit, zeros;++    for (;;) {+        /* Use a sentinel bit to count zeros only up to i. */+        zeros = secp256k1_ctz32_var(g | (UINT32_MAX << i));+        /* Perform zeros divsteps at once; they all just divide g by two. */+        g >>= zeros;+        u <<= zeros;+        v <<= zeros;+        eta -= zeros;+        i -= zeros;+         /* We're done once we've done 30 divsteps. */+        if (i == 0) break;+        VERIFY_CHECK((f & 1) == 1);+        VERIFY_CHECK((g & 1) == 1);+        VERIFY_CHECK((u * f0 + v * g0) == f << (30 - i));+        VERIFY_CHECK((q * f0 + r * g0) == g << (30 - i));+        /* Bounds on eta that follow from the bounds on iteration count (max 25*30 divsteps). */+        VERIFY_CHECK(eta >= -751 && eta <= 751);+        /* If eta is negative, negate it and replace f,g with g,-f. */+        if (eta < 0) {+            uint32_t tmp;+            eta = -eta;+            tmp = f; f = g; g = -tmp;+            tmp = u; u = q; q = -tmp;+            tmp = v; v = r; r = -tmp;+        }+        /* eta is now >= 0. In what follows we're going to cancel out the bottom bits of g. No more+         * than i can be cancelled out (as we'd be done before that point), and no more than eta+1+         * can be done as its sign will flip once that happens. */+        limit = ((int)eta + 1) > i ? i : ((int)eta + 1);+        /* m is a mask for the bottom min(limit, 8) bits (our table only supports 8 bits). */+        VERIFY_CHECK(limit > 0 && limit <= 30);+        m = (UINT32_MAX >> (32 - limit)) & 255U;+        /* Find what multiple of f must be added to g to cancel its bottom min(limit, 8) bits. */+        w = (g * secp256k1_modinv32_inv256[(f >> 1) & 127]) & m;+        /* Do so. */+        g += f * w;+        q += u * w;+        r += v * w;+        VERIFY_CHECK((g & m) == 0);+    }+    /* Return data in t and return value. */+    t->u = (int32_t)u;+    t->v = (int32_t)v;+    t->q = (int32_t)q;+    t->r = (int32_t)r;+    /* The determinant of t must be a power of two. This guarantees that multiplication with t+     * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which+     * will be divided out again). As each divstep's individual matrix has determinant 2, the+     * aggregate of 30 of them will have determinant 2^30. */+    VERIFY_CHECK((int64_t)t->u * t->r - (int64_t)t->v * t->q == ((int64_t)1) << 30);+    return eta;+}++/* Compute the transition matrix and eta for 30 posdivsteps (variable time, eta=-delta), and keeps track+ * of the Jacobi symbol along the way. f0 and g0 must be f and g mod 2^32 rather than 2^30, because+ * Jacobi tracking requires knowing (f mod 8) rather than just (f mod 2).+ *+ * Input:        eta: initial eta+ *               f0:  bottom limb of initial f+ *               g0:  bottom limb of initial g+ * Output:       t: transition matrix+ * Input/Output: (*jacp & 1) is bitflipped if and only if the Jacobi symbol of (f | g) changes sign+ *               by applying the returned transformation matrix to it. The other bits of *jacp may+ *               change, but are meaningless.+ * Return: final eta+ */+static int32_t secp256k1_modinv32_posdivsteps_30_var(int32_t eta, uint32_t f0, uint32_t g0, secp256k1_modinv32_trans2x2 *t, int *jacp) {+    /* Transformation matrix. */+    uint32_t u = 1, v = 0, q = 0, r = 1;+    uint32_t f = f0, g = g0, m;+    uint16_t w;+    int i = 30, limit, zeros;+    int jac = *jacp;++    for (;;) {+        /* Use a sentinel bit to count zeros only up to i. */+        zeros = secp256k1_ctz32_var(g | (UINT32_MAX << i));+        /* Perform zeros divsteps at once; they all just divide g by two. */+        g >>= zeros;+        u <<= zeros;+        v <<= zeros;+        eta -= zeros;+        i -= zeros;+        /* Update the bottom bit of jac: when dividing g by an odd power of 2,+         * if (f mod 8) is 3 or 5, the Jacobi symbol changes sign. */+        jac ^= (zeros & ((f >> 1) ^ (f >> 2)));+        /* We're done once we've done 30 posdivsteps. */+        if (i == 0) break;+        VERIFY_CHECK((f & 1) == 1);+        VERIFY_CHECK((g & 1) == 1);+        VERIFY_CHECK((u * f0 + v * g0) == f << (30 - i));+        VERIFY_CHECK((q * f0 + r * g0) == g << (30 - i));+        /* If eta is negative, negate it and replace f,g with g,f. */+        if (eta < 0) {+            uint32_t tmp;+            eta = -eta;+            /* Update bottom bit of jac: when swapping f and g, the Jacobi symbol changes sign+             * if both f and g are 3 mod 4. */+            jac ^= ((f & g) >> 1);+            tmp = f; f = g; g = tmp;+            tmp = u; u = q; q = tmp;+            tmp = v; v = r; r = tmp;+        }+        /* eta is now >= 0. In what follows we're going to cancel out the bottom bits of g. No more+         * than i can be cancelled out (as we'd be done before that point), and no more than eta+1+         * can be done as its sign will flip once that happens. */+        limit = ((int)eta + 1) > i ? i : ((int)eta + 1);+        /* m is a mask for the bottom min(limit, 8) bits (our table only supports 8 bits). */+        VERIFY_CHECK(limit > 0 && limit <= 30);+        m = (UINT32_MAX >> (32 - limit)) & 255U;+        /* Find what multiple of f must be added to g to cancel its bottom min(limit, 8) bits. */+        w = (g * secp256k1_modinv32_inv256[(f >> 1) & 127]) & m;+        /* Do so. */+        g += f * w;+        q += u * w;+        r += v * w;+        VERIFY_CHECK((g & m) == 0);+    }+    /* Return data in t and return value. */+    t->u = (int32_t)u;+    t->v = (int32_t)v;+    t->q = (int32_t)q;+    t->r = (int32_t)r;+    /* The determinant of t must be a power of two. This guarantees that multiplication with t+     * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which+     * will be divided out again). As each divstep's individual matrix has determinant 2 or -2,+     * the aggregate of 30 of them will have determinant 2^30 or -2^30. */+    VERIFY_CHECK((int64_t)t->u * t->r - (int64_t)t->v * t->q == ((int64_t)1) << 30 ||+                 (int64_t)t->u * t->r - (int64_t)t->v * t->q == -(((int64_t)1) << 30));+    *jacp = jac;+    return eta;+}++/* Compute (t/2^30) * [d, e] mod modulus, where t is a transition matrix for 30 divsteps.+ *+ * On input and output, d and e are in range (-2*modulus,modulus). All output limbs will be in range+ * (-2^30,2^30).+ *+ * This implements the update_de function from the explanation.+ */+static void secp256k1_modinv32_update_de_30(secp256k1_modinv32_signed30 *d, secp256k1_modinv32_signed30 *e, const secp256k1_modinv32_trans2x2 *t, const secp256k1_modinv32_modinfo* modinfo) {+    const int32_t M30 = (int32_t)(UINT32_MAX >> 2);+    const int32_t u = t->u, v = t->v, q = t->q, r = t->r;+    int32_t di, ei, md, me, sd, se;+    int64_t cd, ce;+    int i;+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, -2) > 0); /* d > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, 1) < 0);  /* d <    modulus */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, -2) > 0); /* e > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, 1) < 0);  /* e <    modulus */+    VERIFY_CHECK(labs(u) <= (M30 + 1 - labs(v))); /* |u|+|v| <= 2^30 */+    VERIFY_CHECK(labs(q) <= (M30 + 1 - labs(r))); /* |q|+|r| <= 2^30 */++    /* [md,me] start as zero; plus [u,q] if d is negative; plus [v,r] if e is negative. */+    sd = d->v[8] >> 31;+    se = e->v[8] >> 31;+    md = (u & sd) + (v & se);+    me = (q & sd) + (r & se);+    /* Begin computing t*[d,e]. */+    di = d->v[0];+    ei = e->v[0];+    cd = (int64_t)u * di + (int64_t)v * ei;+    ce = (int64_t)q * di + (int64_t)r * ei;+    /* Correct md,me so that t*[d,e]+modulus*[md,me] has 30 zero bottom bits. */+    md -= (modinfo->modulus_inv30 * (uint32_t)cd + md) & M30;+    me -= (modinfo->modulus_inv30 * (uint32_t)ce + me) & M30;+    /* Update the beginning of computation for t*[d,e]+modulus*[md,me] now md,me are known. */+    cd += (int64_t)modinfo->modulus.v[0] * md;+    ce += (int64_t)modinfo->modulus.v[0] * me;+    /* Verify that the low 30 bits of the computation are indeed zero, and then throw them away. */+    VERIFY_CHECK(((int32_t)cd & M30) == 0); cd >>= 30;+    VERIFY_CHECK(((int32_t)ce & M30) == 0); ce >>= 30;+    /* Now iteratively compute limb i=1..8 of t*[d,e]+modulus*[md,me], and store them in output+     * limb i-1 (shifting down by 30 bits). */+    for (i = 1; i < 9; ++i) {+        di = d->v[i];+        ei = e->v[i];+        cd += (int64_t)u * di + (int64_t)v * ei;+        ce += (int64_t)q * di + (int64_t)r * ei;+        cd += (int64_t)modinfo->modulus.v[i] * md;+        ce += (int64_t)modinfo->modulus.v[i] * me;+        d->v[i - 1] = (int32_t)cd & M30; cd >>= 30;+        e->v[i - 1] = (int32_t)ce & M30; ce >>= 30;+    }+    /* What remains is limb 9 of t*[d,e]+modulus*[md,me]; store it as output limb 8. */+    d->v[8] = (int32_t)cd;+    e->v[8] = (int32_t)ce;++    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, -2) > 0); /* d > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(d, 9, &modinfo->modulus, 1) < 0);  /* d <    modulus */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, -2) > 0); /* e > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(e, 9, &modinfo->modulus, 1) < 0);  /* e <    modulus */+}++/* Compute (t/2^30) * [f, g], where t is a transition matrix for 30 divsteps.+ *+ * This implements the update_fg function from the explanation.+ */+static void secp256k1_modinv32_update_fg_30(secp256k1_modinv32_signed30 *f, secp256k1_modinv32_signed30 *g, const secp256k1_modinv32_trans2x2 *t) {+    const int32_t M30 = (int32_t)(UINT32_MAX >> 2);+    const int32_t u = t->u, v = t->v, q = t->q, r = t->r;+    int32_t fi, gi;+    int64_t cf, cg;+    int i;+    /* Start computing t*[f,g]. */+    fi = f->v[0];+    gi = g->v[0];+    cf = (int64_t)u * fi + (int64_t)v * gi;+    cg = (int64_t)q * fi + (int64_t)r * gi;+    /* Verify that the bottom 30 bits of the result are zero, and then throw them away. */+    VERIFY_CHECK(((int32_t)cf & M30) == 0); cf >>= 30;+    VERIFY_CHECK(((int32_t)cg & M30) == 0); cg >>= 30;+    /* Now iteratively compute limb i=1..8 of t*[f,g], and store them in output limb i-1 (shifting+     * down by 30 bits). */+    for (i = 1; i < 9; ++i) {+        fi = f->v[i];+        gi = g->v[i];+        cf += (int64_t)u * fi + (int64_t)v * gi;+        cg += (int64_t)q * fi + (int64_t)r * gi;+        f->v[i - 1] = (int32_t)cf & M30; cf >>= 30;+        g->v[i - 1] = (int32_t)cg & M30; cg >>= 30;+    }+    /* What remains is limb 9 of t*[f,g]; store it as output limb 8. */+    f->v[8] = (int32_t)cf;+    g->v[8] = (int32_t)cg;+}++/* Compute (t/2^30) * [f, g], where t is a transition matrix for 30 divsteps.+ *+ * Version that operates on a variable number of limbs in f and g.+ *+ * This implements the update_fg function from the explanation in modinv64_impl.h.+ */+static void secp256k1_modinv32_update_fg_30_var(int len, secp256k1_modinv32_signed30 *f, secp256k1_modinv32_signed30 *g, const secp256k1_modinv32_trans2x2 *t) {+    const int32_t M30 = (int32_t)(UINT32_MAX >> 2);+    const int32_t u = t->u, v = t->v, q = t->q, r = t->r;+    int32_t fi, gi;+    int64_t cf, cg;+    int i;+    VERIFY_CHECK(len > 0);+    /* Start computing t*[f,g]. */+    fi = f->v[0];+    gi = g->v[0];+    cf = (int64_t)u * fi + (int64_t)v * gi;+    cg = (int64_t)q * fi + (int64_t)r * gi;+    /* Verify that the bottom 62 bits of the result are zero, and then throw them away. */+    VERIFY_CHECK(((int32_t)cf & M30) == 0); cf >>= 30;+    VERIFY_CHECK(((int32_t)cg & M30) == 0); cg >>= 30;+    /* Now iteratively compute limb i=1..len of t*[f,g], and store them in output limb i-1 (shifting+     * down by 30 bits). */+    for (i = 1; i < len; ++i) {+        fi = f->v[i];+        gi = g->v[i];+        cf += (int64_t)u * fi + (int64_t)v * gi;+        cg += (int64_t)q * fi + (int64_t)r * gi;+        f->v[i - 1] = (int32_t)cf & M30; cf >>= 30;+        g->v[i - 1] = (int32_t)cg & M30; cg >>= 30;+    }+    /* What remains is limb (len) of t*[f,g]; store it as output limb (len-1). */+    f->v[len - 1] = (int32_t)cf;+    g->v[len - 1] = (int32_t)cg;+}++/* Compute the inverse of x modulo modinfo->modulus, and replace x with it (constant time in x). */+static void secp256k1_modinv32(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo) {+    /* Start with d=0, e=1, f=modulus, g=x, zeta=-1. */+    secp256k1_modinv32_signed30 d = {{0}};+    secp256k1_modinv32_signed30 e = {{1}};+    secp256k1_modinv32_signed30 f = modinfo->modulus;+    secp256k1_modinv32_signed30 g = *x;+    int i;+    int32_t zeta = -1; /* zeta = -(delta+1/2); delta is initially 1/2. */++    /* Do 20 iterations of 30 divsteps each = 600 divsteps. 590 suffices for 256-bit inputs. */+    for (i = 0; i < 20; ++i) {+        /* Compute transition matrix and new zeta after 30 divsteps. */+        secp256k1_modinv32_trans2x2 t;+        zeta = secp256k1_modinv32_divsteps_30(zeta, f.v[0], g.v[0], &t);+        /* Update d,e using that transition matrix. */+        secp256k1_modinv32_update_de_30(&d, &e, &t, modinfo);+        /* Update f,g using that transition matrix. */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) > 0); /* f > -modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, -1) > 0); /* g > -modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, 1) < 0);  /* g <  modulus */++        secp256k1_modinv32_update_fg_30(&f, &g, &t);++        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, -1) > 0); /* f > -modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, -1) > 0); /* g > -modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &modinfo->modulus, 1) < 0);  /* g <  modulus */+    }++    /* At this point sufficient iterations have been performed that g must have reached 0+     * and (if g was not originally 0) f must now equal +/- GCD of the initial f, g+     * values i.e. +/- 1, and d now contains +/- the modular inverse. */++    /* g == 0 */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, 9, &SECP256K1_SIGNED30_ONE, 0) == 0);+    /* |f| == 1, or (x == 0 and d == 0 and f == modulus) */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, 9, &SECP256K1_SIGNED30_ONE, -1) == 0 ||+                 secp256k1_modinv32_mul_cmp_30(&f, 9, &SECP256K1_SIGNED30_ONE, 1) == 0 ||+                 (secp256k1_modinv32_mul_cmp_30(x, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 &&+                  secp256k1_modinv32_mul_cmp_30(&d, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 &&+                  secp256k1_modinv32_mul_cmp_30(&f, 9, &modinfo->modulus, 1) == 0));++    /* Optionally negate d, normalize to [0,modulus), and return it. */+    secp256k1_modinv32_normalize_30(&d, f.v[8], modinfo);+    *x = d;+}++/* Compute the inverse of x modulo modinfo->modulus, and replace x with it (variable time). */+static void secp256k1_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo) {+    /* Start with d=0, e=1, f=modulus, g=x, eta=-1. */+    secp256k1_modinv32_signed30 d = {{0, 0, 0, 0, 0, 0, 0, 0, 0}};+    secp256k1_modinv32_signed30 e = {{1, 0, 0, 0, 0, 0, 0, 0, 0}};+    secp256k1_modinv32_signed30 f = modinfo->modulus;+    secp256k1_modinv32_signed30 g = *x;+#ifdef VERIFY+    int i = 0;+#endif+    int j, len = 9;+    int32_t eta = -1; /* eta = -delta; delta is initially 1 (faster for the variable-time code) */+    int32_t cond, fn, gn;++    /* Do iterations of 30 divsteps each until g=0. */+    while (1) {+        /* Compute transition matrix and new eta after 30 divsteps. */+        secp256k1_modinv32_trans2x2 t;+        eta = secp256k1_modinv32_divsteps_30_var(eta, f.v[0], g.v[0], &t);+        /* Update d,e using that transition matrix. */+        secp256k1_modinv32_update_de_30(&d, &e, &t, modinfo);+        /* Update f,g using that transition matrix. */++        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0);  /* g <  modulus */++        secp256k1_modinv32_update_fg_30_var(len, &f, &g, &t);+        /* If the bottom limb of g is 0, there is a chance g=0. */+        if (g.v[0] == 0) {+            cond = 0;+            /* Check if all other limbs are also 0. */+            for (j = 1; j < len; ++j) {+                cond |= g.v[j];+            }+            /* If so, we're done. */+            if (cond == 0) break;+        }++        /* Determine if len>1 and limb (len-1) of both f and g is 0 or -1. */+        fn = f.v[len - 1];+        gn = g.v[len - 1];+        cond = ((int32_t)len - 2) >> 31;+        cond |= fn ^ (fn >> 31);+        cond |= gn ^ (gn >> 31);+        /* If so, reduce length, propagating the sign of f and g's top limb into the one below. */+        if (cond == 0) {+            f.v[len - 2] |= (uint32_t)fn << 30;+            g.v[len - 2] |= (uint32_t)gn << 30;+            --len;+        }++        VERIFY_CHECK(++i < 25); /* We should never need more than 25*30 = 750 divsteps */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0);  /* g <  modulus */+    }++    /* At this point g is 0 and (if g was not originally 0) f must now equal +/- GCD of+     * the initial f, g values i.e. +/- 1, and d now contains +/- the modular inverse. */++    /* g == 0 */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &SECP256K1_SIGNED30_ONE, 0) == 0);+    /* |f| == 1, or (x == 0 and d == 0 and f == modulus) */+    VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &SECP256K1_SIGNED30_ONE, -1) == 0 ||+                 secp256k1_modinv32_mul_cmp_30(&f, len, &SECP256K1_SIGNED30_ONE, 1) == 0 ||+                 (secp256k1_modinv32_mul_cmp_30(x, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 &&+                  secp256k1_modinv32_mul_cmp_30(&d, 9, &SECP256K1_SIGNED30_ONE, 0) == 0 &&+                  secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) == 0));++    /* Optionally negate d, normalize to [0,modulus), and return it. */+    secp256k1_modinv32_normalize_30(&d, f.v[len - 1], modinfo);+    *x = d;+}++/* Do up to 50 iterations of 30 posdivsteps (up to 1500 steps; more is extremely rare) each until f=1.+ * In VERIFY mode use a lower number of iterations (750, close to the median 756), so failure actually occurs. */+#ifdef VERIFY+#define JACOBI32_ITERATIONS 25+#else+#define JACOBI32_ITERATIONS 50+#endif++/* Compute the Jacobi symbol of x modulo modinfo->modulus (variable time). gcd(x,modulus) must be 1. */+static int secp256k1_jacobi32_maybe_var(const secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo) {+    /* Start with f=modulus, g=x, eta=-1. */+    secp256k1_modinv32_signed30 f = modinfo->modulus;+    secp256k1_modinv32_signed30 g = *x;+    int j, len = 9;+    int32_t eta = -1; /* eta = -delta; delta is initially 1 */+    int32_t cond, fn, gn;+    int jac = 0;+    int count;++    /* The input limbs must all be non-negative. */+    VERIFY_CHECK(g.v[0] >= 0 && g.v[1] >= 0 && g.v[2] >= 0 && g.v[3] >= 0 && g.v[4] >= 0 && g.v[5] >= 0 && g.v[6] >= 0 && g.v[7] >= 0 && g.v[8] >= 0);++    /* If x > 0, then if the loop below converges, it converges to f=g=gcd(x,modulus). Since we+     * require that gcd(x,modulus)=1 and modulus>=3, x cannot be 0. Thus, we must reach f=1 (or+     * time out). */+    VERIFY_CHECK((g.v[0] | g.v[1] | g.v[2] | g.v[3] | g.v[4] | g.v[5] | g.v[6] | g.v[7] | g.v[8]) != 0);++    for (count = 0; count < JACOBI32_ITERATIONS; ++count) {+        /* Compute transition matrix and new eta after 30 posdivsteps. */+        secp256k1_modinv32_trans2x2 t;+        eta = secp256k1_modinv32_posdivsteps_30_var(eta, f.v[0] | ((uint32_t)f.v[1] << 30), g.v[0] | ((uint32_t)g.v[1] << 30), &t, &jac);+        /* Update f,g using that transition matrix. */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0);  /* g < modulus */++        secp256k1_modinv32_update_fg_30_var(len, &f, &g, &t);+        /* If the bottom limb of f is 1, there is a chance that f=1. */+        if (f.v[0] == 1) {+            cond = 0;+            /* Check if the other limbs are also 0. */+            for (j = 1; j < len; ++j) {+                cond |= f.v[j];+            }+            /* If so, we're done. If f=1, the Jacobi symbol (g | f)=1. */+            if (cond == 0) return 1 - 2*(jac & 1);+        }++        /* Determine if len>1 and limb (len-1) of both f and g is 0. */+        fn = f.v[len - 1];+        gn = g.v[len - 1];+        cond = ((int32_t)len - 2) >> 31;+        cond |= fn;+        cond |= gn;+        /* If so, reduce length. */+        if (cond == 0) --len;++        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */+        VERIFY_CHECK(secp256k1_modinv32_mul_cmp_30(&g, len, &modinfo->modulus, 1) < 0);  /* g < modulus */+    }++    /* The loop failed to converge to f=g after 1500 iterations. Return 0, indicating unknown result. */+    return 0;+}++#endif /* SECP256K1_MODINV32_IMPL_H */
+ vendor/external/secp256k1/src/modinv64.h view
@@ -0,0 +1,47 @@+/***********************************************************************+ * Copyright (c) 2020 Peter Dettman                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ **********************************************************************/++#ifndef SECP256K1_MODINV64_H+#define SECP256K1_MODINV64_H++#include "util.h"++#ifndef SECP256K1_WIDEMUL_INT128+#error "modinv64 requires 128-bit wide multiplication support"+#endif++/* A signed 62-bit limb representation of integers.+ *+ * Its value is sum(v[i] * 2^(62*i), i=0..4). */+typedef struct {+    int64_t v[5];+} secp256k1_modinv64_signed62;++typedef struct {+    /* The modulus in signed62 notation, must be odd and in [3, 2^256]. */+    secp256k1_modinv64_signed62 modulus;++    /* modulus^{-1} mod 2^62 */+    uint64_t modulus_inv62;+} secp256k1_modinv64_modinfo;++/* Replace x with its modular inverse mod modinfo->modulus. x must be in range [0, modulus).+ * If x is zero, the result will be zero as well. If not, the inverse must exist (i.e., the gcd of+ * x and modulus must be 1). These rules are automatically satisfied if the modulus is prime.+ *+ * On output, all of x's limbs will be in [0, 2^62).+ */+static void secp256k1_modinv64_var(secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo);++/* Same as secp256k1_modinv64_var, but constant time in x (not in the modulus). */+static void secp256k1_modinv64(secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo);++/* Compute the Jacobi symbol for (x | modinfo->modulus). x must be coprime with modulus (and thus+ * cannot be 0, as modulus >= 3). All limbs of x must be non-negative. Returns 0 if the result+ * cannot be computed. */+static int secp256k1_jacobi64_maybe_var(const secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo);++#endif /* SECP256K1_MODINV64_H */
+ vendor/external/secp256k1/src/modinv64_impl.h view
@@ -0,0 +1,780 @@+/***********************************************************************+ * Copyright (c) 2020 Peter Dettman                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ **********************************************************************/++#ifndef SECP256K1_MODINV64_IMPL_H+#define SECP256K1_MODINV64_IMPL_H++#include "int128.h"+#include "modinv64.h"++/* This file implements modular inversion based on the paper "Fast constant-time gcd computation and+ * modular inversion" by Daniel J. Bernstein and Bo-Yin Yang.+ *+ * For an explanation of the algorithm, see doc/safegcd_implementation.md. This file contains an+ * implementation for N=62, using 62-bit signed limbs represented as int64_t.+ */++/* Data type for transition matrices (see section 3 of explanation).+ *+ * t = [ u  v ]+ *     [ q  r ]+ */+typedef struct {+    int64_t u, v, q, r;+} secp256k1_modinv64_trans2x2;++#ifdef VERIFY+/* Helper function to compute the absolute value of an int64_t.+ * (we don't use abs/labs/llabs as it depends on the int sizes). */+static int64_t secp256k1_modinv64_abs(int64_t v) {+    VERIFY_CHECK(v > INT64_MIN);+    if (v < 0) return -v;+    return v;+}++static const secp256k1_modinv64_signed62 SECP256K1_SIGNED62_ONE = {{1}};++/* Compute a*factor and put it in r. All but the top limb in r will be in range [0,2^62). */+static void secp256k1_modinv64_mul_62(secp256k1_modinv64_signed62 *r, const secp256k1_modinv64_signed62 *a, int alen, int64_t factor) {+    const uint64_t M62 = UINT64_MAX >> 2;+    secp256k1_int128 c, d;+    int i;+    secp256k1_i128_from_i64(&c, 0);+    for (i = 0; i < 4; ++i) {+        if (i < alen) secp256k1_i128_accum_mul(&c, a->v[i], factor);+        r->v[i] = secp256k1_i128_to_u64(&c) & M62; secp256k1_i128_rshift(&c, 62);+    }+    if (4 < alen) secp256k1_i128_accum_mul(&c, a->v[4], factor);+    secp256k1_i128_from_i64(&d, secp256k1_i128_to_i64(&c));+    VERIFY_CHECK(secp256k1_i128_eq_var(&c, &d));+    r->v[4] = secp256k1_i128_to_i64(&c);+}++/* Return -1 for a<b*factor, 0 for a==b*factor, 1 for a>b*factor. A has alen limbs; b has 5. */+static int secp256k1_modinv64_mul_cmp_62(const secp256k1_modinv64_signed62 *a, int alen, const secp256k1_modinv64_signed62 *b, int64_t factor) {+    int i;+    secp256k1_modinv64_signed62 am, bm;+    secp256k1_modinv64_mul_62(&am, a, alen, 1); /* Normalize all but the top limb of a. */+    secp256k1_modinv64_mul_62(&bm, b, 5, factor);+    for (i = 0; i < 4; ++i) {+        /* Verify that all but the top limb of a and b are normalized. */+        VERIFY_CHECK(am.v[i] >> 62 == 0);+        VERIFY_CHECK(bm.v[i] >> 62 == 0);+    }+    for (i = 4; i >= 0; --i) {+        if (am.v[i] < bm.v[i]) return -1;+        if (am.v[i] > bm.v[i]) return 1;+    }+    return 0;+}++/* Check if the determinant of t is equal to 1 << n. If abs, check if |det t| == 1 << n. */+static int secp256k1_modinv64_det_check_pow2(const secp256k1_modinv64_trans2x2 *t, unsigned int n, int abs) {+    secp256k1_int128 a;+    secp256k1_i128_det(&a, t->u, t->v, t->q, t->r);+    if (secp256k1_i128_check_pow2(&a, n, 1)) return 1;+    if (abs && secp256k1_i128_check_pow2(&a, n, -1)) return 1;+    return 0;+}+#endif++/* Take as input a signed62 number in range (-2*modulus,modulus), and add a multiple of the modulus+ * to it to bring it to range [0,modulus). If sign < 0, the input will also be negated in the+ * process. The input must have limbs in range (-2^62,2^62). The output will have limbs in range+ * [0,2^62). */+static void secp256k1_modinv64_normalize_62(secp256k1_modinv64_signed62 *r, int64_t sign, const secp256k1_modinv64_modinfo *modinfo) {+    const int64_t M62 = (int64_t)(UINT64_MAX >> 2);+    int64_t r0 = r->v[0], r1 = r->v[1], r2 = r->v[2], r3 = r->v[3], r4 = r->v[4];+    volatile int64_t cond_add, cond_negate;++#ifdef VERIFY+    /* Verify that all limbs are in range (-2^62,2^62). */+    int i;+    for (i = 0; i < 5; ++i) {+        VERIFY_CHECK(r->v[i] >= -M62);+        VERIFY_CHECK(r->v[i] <= M62);+    }+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, -2) > 0); /* r > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, 1) < 0); /* r < modulus */+#endif++    /* In a first step, add the modulus if the input is negative, and then negate if requested.+     * This brings r from range (-2*modulus,modulus) to range (-modulus,modulus). As all input+     * limbs are in range (-2^62,2^62), this cannot overflow an int64_t. Note that the right+     * shifts below are signed sign-extending shifts (see assumptions.h for tests that that is+     * indeed the behavior of the right shift operator). */+    cond_add = r4 >> 63;+    r0 += modinfo->modulus.v[0] & cond_add;+    r1 += modinfo->modulus.v[1] & cond_add;+    r2 += modinfo->modulus.v[2] & cond_add;+    r3 += modinfo->modulus.v[3] & cond_add;+    r4 += modinfo->modulus.v[4] & cond_add;+    cond_negate = sign >> 63;+    r0 = (r0 ^ cond_negate) - cond_negate;+    r1 = (r1 ^ cond_negate) - cond_negate;+    r2 = (r2 ^ cond_negate) - cond_negate;+    r3 = (r3 ^ cond_negate) - cond_negate;+    r4 = (r4 ^ cond_negate) - cond_negate;+    /* Propagate the top bits, to bring limbs back to range (-2^62,2^62). */+    r1 += r0 >> 62; r0 &= M62;+    r2 += r1 >> 62; r1 &= M62;+    r3 += r2 >> 62; r2 &= M62;+    r4 += r3 >> 62; r3 &= M62;++    /* In a second step add the modulus again if the result is still negative, bringing+     * r to range [0,modulus). */+    cond_add = r4 >> 63;+    r0 += modinfo->modulus.v[0] & cond_add;+    r1 += modinfo->modulus.v[1] & cond_add;+    r2 += modinfo->modulus.v[2] & cond_add;+    r3 += modinfo->modulus.v[3] & cond_add;+    r4 += modinfo->modulus.v[4] & cond_add;+    /* And propagate again. */+    r1 += r0 >> 62; r0 &= M62;+    r2 += r1 >> 62; r1 &= M62;+    r3 += r2 >> 62; r2 &= M62;+    r4 += r3 >> 62; r3 &= M62;++    r->v[0] = r0;+    r->v[1] = r1;+    r->v[2] = r2;+    r->v[3] = r3;+    r->v[4] = r4;++    VERIFY_CHECK(r0 >> 62 == 0);+    VERIFY_CHECK(r1 >> 62 == 0);+    VERIFY_CHECK(r2 >> 62 == 0);+    VERIFY_CHECK(r3 >> 62 == 0);+    VERIFY_CHECK(r4 >> 62 == 0);+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, 0) >= 0); /* r >= 0 */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(r, 5, &modinfo->modulus, 1) < 0); /* r < modulus */+}++/* Compute the transition matrix and eta for 59 divsteps (where zeta=-(delta+1/2)).+ * Note that the transformation matrix is scaled by 2^62 and not 2^59.+ *+ * Input:  zeta: initial zeta+ *         f0:   bottom limb of initial f+ *         g0:   bottom limb of initial g+ * Output: t: transition matrix+ * Return: final zeta+ *+ * Implements the divsteps_n_matrix function from the explanation.+ */+static int64_t secp256k1_modinv64_divsteps_59(int64_t zeta, uint64_t f0, uint64_t g0, secp256k1_modinv64_trans2x2 *t) {+    /* u,v,q,r are the elements of the transformation matrix being built up,+     * starting with the identity matrix times 8 (because the caller expects+     * a result scaled by 2^62). Semantically they are signed integers+     * in range [-2^62,2^62], but here represented as unsigned mod 2^64. This+     * permits left shifting (which is UB for negative numbers). The range+     * being inside [-2^63,2^63) means that casting to signed works correctly.+     */+    uint64_t u = 8, v = 0, q = 0, r = 8;+    volatile uint64_t c1, c2;+    uint64_t mask1, mask2, f = f0, g = g0, x, y, z;+    int i;++    for (i = 3; i < 62; ++i) {+        VERIFY_CHECK((f & 1) == 1); /* f must always be odd */+        VERIFY_CHECK((u * f0 + v * g0) == f << i);+        VERIFY_CHECK((q * f0 + r * g0) == g << i);+        /* Compute conditional masks for (zeta < 0) and for (g & 1). */+        c1 = zeta >> 63;+        mask1 = c1;+        c2 = g & 1;+        mask2 = -c2;+        /* Compute x,y,z, conditionally negated versions of f,u,v. */+        x = (f ^ mask1) - mask1;+        y = (u ^ mask1) - mask1;+        z = (v ^ mask1) - mask1;+        /* Conditionally add x,y,z to g,q,r. */+        g += x & mask2;+        q += y & mask2;+        r += z & mask2;+        /* In what follows, c1 is a condition mask for (zeta < 0) and (g & 1). */+        mask1 &= mask2;+        /* Conditionally change zeta into -zeta-2 or zeta-1. */+        zeta = (zeta ^ mask1) - 1;+        /* Conditionally add g,q,r to f,u,v. */+        f += g & mask1;+        u += q & mask1;+        v += r & mask1;+        /* Shifts */+        g >>= 1;+        u <<= 1;+        v <<= 1;+        /* Bounds on zeta that follow from the bounds on iteration count (max 10*59 divsteps). */+        VERIFY_CHECK(zeta >= -591 && zeta <= 591);+    }+    /* Return data in t and return value. */+    t->u = (int64_t)u;+    t->v = (int64_t)v;+    t->q = (int64_t)q;+    t->r = (int64_t)r;++    /* The determinant of t must be a power of two. This guarantees that multiplication with t+     * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which+     * will be divided out again). As each divstep's individual matrix has determinant 2, the+     * aggregate of 59 of them will have determinant 2^59. Multiplying with the initial+     * 8*identity (which has determinant 2^6) means the overall outputs has determinant+     * 2^65. */+    VERIFY_CHECK(secp256k1_modinv64_det_check_pow2(t, 65, 0));++    return zeta;+}++/* Compute the transition matrix and eta for 62 divsteps (variable time, eta=-delta).+ *+ * Input:  eta: initial eta+ *         f0:  bottom limb of initial f+ *         g0:  bottom limb of initial g+ * Output: t: transition matrix+ * Return: final eta+ *+ * Implements the divsteps_n_matrix_var function from the explanation.+ */+static int64_t secp256k1_modinv64_divsteps_62_var(int64_t eta, uint64_t f0, uint64_t g0, secp256k1_modinv64_trans2x2 *t) {+    /* Transformation matrix; see comments in secp256k1_modinv64_divsteps_62. */+    uint64_t u = 1, v = 0, q = 0, r = 1;+    uint64_t f = f0, g = g0, m;+    uint32_t w;+    int i = 62, limit, zeros;++    for (;;) {+        /* Use a sentinel bit to count zeros only up to i. */+        zeros = secp256k1_ctz64_var(g | (UINT64_MAX << i));+        /* Perform zeros divsteps at once; they all just divide g by two. */+        g >>= zeros;+        u <<= zeros;+        v <<= zeros;+        eta -= zeros;+        i -= zeros;+        /* We're done once we've done 62 divsteps. */+        if (i == 0) break;+        VERIFY_CHECK((f & 1) == 1);+        VERIFY_CHECK((g & 1) == 1);+        VERIFY_CHECK((u * f0 + v * g0) == f << (62 - i));+        VERIFY_CHECK((q * f0 + r * g0) == g << (62 - i));+        /* Bounds on eta that follow from the bounds on iteration count (max 12*62 divsteps). */+        VERIFY_CHECK(eta >= -745 && eta <= 745);+        /* If eta is negative, negate it and replace f,g with g,-f. */+        if (eta < 0) {+            uint64_t tmp;+            eta = -eta;+            tmp = f; f = g; g = -tmp;+            tmp = u; u = q; q = -tmp;+            tmp = v; v = r; r = -tmp;+            /* Use a formula to cancel out up to 6 bits of g. Also, no more than i can be cancelled+             * out (as we'd be done before that point), and no more than eta+1 can be done as its+             * sign will flip again once that happens. */+            limit = ((int)eta + 1) > i ? i : ((int)eta + 1);+            VERIFY_CHECK(limit > 0 && limit <= 62);+            /* m is a mask for the bottom min(limit, 6) bits. */+            m = (UINT64_MAX >> (64 - limit)) & 63U;+            /* Find what multiple of f must be added to g to cancel its bottom min(limit, 6)+             * bits. */+            w = (f * g * (f * f - 2)) & m;+        } else {+            /* In this branch, use a simpler formula that only lets us cancel up to 4 bits of g, as+             * eta tends to be smaller here. */+            limit = ((int)eta + 1) > i ? i : ((int)eta + 1);+            VERIFY_CHECK(limit > 0 && limit <= 62);+            /* m is a mask for the bottom min(limit, 4) bits. */+            m = (UINT64_MAX >> (64 - limit)) & 15U;+            /* Find what multiple of f must be added to g to cancel its bottom min(limit, 4)+             * bits. */+            w = f + (((f + 1) & 4) << 1);+            w = (-w * g) & m;+        }+        g += f * w;+        q += u * w;+        r += v * w;+        VERIFY_CHECK((g & m) == 0);+    }+    /* Return data in t and return value. */+    t->u = (int64_t)u;+    t->v = (int64_t)v;+    t->q = (int64_t)q;+    t->r = (int64_t)r;++    /* The determinant of t must be a power of two. This guarantees that multiplication with t+     * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which+     * will be divided out again). As each divstep's individual matrix has determinant 2, the+     * aggregate of 62 of them will have determinant 2^62. */+    VERIFY_CHECK(secp256k1_modinv64_det_check_pow2(t, 62, 0));++    return eta;+}++/* Compute the transition matrix and eta for 62 posdivsteps (variable time, eta=-delta), and keeps track+ * of the Jacobi symbol along the way. f0 and g0 must be f and g mod 2^64 rather than 2^62, because+ * Jacobi tracking requires knowing (f mod 8) rather than just (f mod 2).+ *+ * Input:        eta: initial eta+ *               f0:  bottom limb of initial f+ *               g0:  bottom limb of initial g+ * Output:       t: transition matrix+ * Input/Output: (*jacp & 1) is bitflipped if and only if the Jacobi symbol of (f | g) changes sign+ *               by applying the returned transformation matrix to it. The other bits of *jacp may+ *               change, but are meaningless.+ * Return:       final eta+ */+static int64_t secp256k1_modinv64_posdivsteps_62_var(int64_t eta, uint64_t f0, uint64_t g0, secp256k1_modinv64_trans2x2 *t, int *jacp) {+    /* Transformation matrix; see comments in secp256k1_modinv64_divsteps_62. */+    uint64_t u = 1, v = 0, q = 0, r = 1;+    uint64_t f = f0, g = g0, m;+    uint32_t w;+    int i = 62, limit, zeros;+    int jac = *jacp;++    for (;;) {+        /* Use a sentinel bit to count zeros only up to i. */+        zeros = secp256k1_ctz64_var(g | (UINT64_MAX << i));+        /* Perform zeros divsteps at once; they all just divide g by two. */+        g >>= zeros;+        u <<= zeros;+        v <<= zeros;+        eta -= zeros;+        i -= zeros;+        /* Update the bottom bit of jac: when dividing g by an odd power of 2,+         * if (f mod 8) is 3 or 5, the Jacobi symbol changes sign. */+        jac ^= (zeros & ((f >> 1) ^ (f >> 2)));+        /* We're done once we've done 62 posdivsteps. */+        if (i == 0) break;+        VERIFY_CHECK((f & 1) == 1);+        VERIFY_CHECK((g & 1) == 1);+        VERIFY_CHECK((u * f0 + v * g0) == f << (62 - i));+        VERIFY_CHECK((q * f0 + r * g0) == g << (62 - i));+        /* If eta is negative, negate it and replace f,g with g,f. */+        if (eta < 0) {+            uint64_t tmp;+            eta = -eta;+            tmp = f; f = g; g = tmp;+            tmp = u; u = q; q = tmp;+            tmp = v; v = r; r = tmp;+            /* Update bottom bit of jac: when swapping f and g, the Jacobi symbol changes sign+             * if both f and g are 3 mod 4. */+            jac ^= ((f & g) >> 1);+            /* Use a formula to cancel out up to 6 bits of g. Also, no more than i can be cancelled+             * out (as we'd be done before that point), and no more than eta+1 can be done as its+             * sign will flip again once that happens. */+            limit = ((int)eta + 1) > i ? i : ((int)eta + 1);+            VERIFY_CHECK(limit > 0 && limit <= 62);+            /* m is a mask for the bottom min(limit, 6) bits. */+            m = (UINT64_MAX >> (64 - limit)) & 63U;+            /* Find what multiple of f must be added to g to cancel its bottom min(limit, 6)+             * bits. */+            w = (f * g * (f * f - 2)) & m;+        } else {+            /* In this branch, use a simpler formula that only lets us cancel up to 4 bits of g, as+             * eta tends to be smaller here. */+            limit = ((int)eta + 1) > i ? i : ((int)eta + 1);+            VERIFY_CHECK(limit > 0 && limit <= 62);+            /* m is a mask for the bottom min(limit, 4) bits. */+            m = (UINT64_MAX >> (64 - limit)) & 15U;+            /* Find what multiple of f must be added to g to cancel its bottom min(limit, 4)+             * bits. */+            w = f + (((f + 1) & 4) << 1);+            w = (-w * g) & m;+        }+        g += f * w;+        q += u * w;+        r += v * w;+        VERIFY_CHECK((g & m) == 0);+    }+    /* Return data in t and return value. */+    t->u = (int64_t)u;+    t->v = (int64_t)v;+    t->q = (int64_t)q;+    t->r = (int64_t)r;++    /* The determinant of t must be a power of two. This guarantees that multiplication with t+     * does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which+     * will be divided out again). As each divstep's individual matrix has determinant 2 or -2,+     * the aggregate of 62 of them will have determinant 2^62 or -2^62. */+    VERIFY_CHECK(secp256k1_modinv64_det_check_pow2(t, 62, 1));++    *jacp = jac;+    return eta;+}++/* Compute (t/2^62) * [d, e] mod modulus, where t is a transition matrix scaled by 2^62.+ *+ * On input and output, d and e are in range (-2*modulus,modulus). All output limbs will be in range+ * (-2^62,2^62).+ *+ * This implements the update_de function from the explanation.+ */+static void secp256k1_modinv64_update_de_62(secp256k1_modinv64_signed62 *d, secp256k1_modinv64_signed62 *e, const secp256k1_modinv64_trans2x2 *t, const secp256k1_modinv64_modinfo* modinfo) {+    const uint64_t M62 = UINT64_MAX >> 2;+    const int64_t d0 = d->v[0], d1 = d->v[1], d2 = d->v[2], d3 = d->v[3], d4 = d->v[4];+    const int64_t e0 = e->v[0], e1 = e->v[1], e2 = e->v[2], e3 = e->v[3], e4 = e->v[4];+    const int64_t u = t->u, v = t->v, q = t->q, r = t->r;+    int64_t md, me, sd, se;+    secp256k1_int128 cd, ce;+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, -2) > 0); /* d > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, 1) < 0);  /* d <    modulus */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, -2) > 0); /* e > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, 1) < 0);  /* e <    modulus */+    VERIFY_CHECK(secp256k1_modinv64_abs(u) <= (((int64_t)1 << 62) - secp256k1_modinv64_abs(v))); /* |u|+|v| <= 2^62 */+    VERIFY_CHECK(secp256k1_modinv64_abs(q) <= (((int64_t)1 << 62) - secp256k1_modinv64_abs(r))); /* |q|+|r| <= 2^62 */++    /* [md,me] start as zero; plus [u,q] if d is negative; plus [v,r] if e is negative. */+    sd = d4 >> 63;+    se = e4 >> 63;+    md = (u & sd) + (v & se);+    me = (q & sd) + (r & se);+    /* Begin computing t*[d,e]. */+    secp256k1_i128_mul(&cd, u, d0);+    secp256k1_i128_accum_mul(&cd, v, e0);+    secp256k1_i128_mul(&ce, q, d0);+    secp256k1_i128_accum_mul(&ce, r, e0);+    /* Correct md,me so that t*[d,e]+modulus*[md,me] has 62 zero bottom bits. */+    md -= (modinfo->modulus_inv62 * secp256k1_i128_to_u64(&cd) + md) & M62;+    me -= (modinfo->modulus_inv62 * secp256k1_i128_to_u64(&ce) + me) & M62;+    /* Update the beginning of computation for t*[d,e]+modulus*[md,me] now md,me are known. */+    secp256k1_i128_accum_mul(&cd, modinfo->modulus.v[0], md);+    secp256k1_i128_accum_mul(&ce, modinfo->modulus.v[0], me);+    /* Verify that the low 62 bits of the computation are indeed zero, and then throw them away. */+    VERIFY_CHECK((secp256k1_i128_to_u64(&cd) & M62) == 0); secp256k1_i128_rshift(&cd, 62);+    VERIFY_CHECK((secp256k1_i128_to_u64(&ce) & M62) == 0); secp256k1_i128_rshift(&ce, 62);+    /* Compute limb 1 of t*[d,e]+modulus*[md,me], and store it as output limb 0 (= down shift). */+    secp256k1_i128_accum_mul(&cd, u, d1);+    secp256k1_i128_accum_mul(&cd, v, e1);+    secp256k1_i128_accum_mul(&ce, q, d1);+    secp256k1_i128_accum_mul(&ce, r, e1);+    if (modinfo->modulus.v[1]) { /* Optimize for the case where limb of modulus is zero. */+        secp256k1_i128_accum_mul(&cd, modinfo->modulus.v[1], md);+        secp256k1_i128_accum_mul(&ce, modinfo->modulus.v[1], me);+    }+    d->v[0] = secp256k1_i128_to_u64(&cd) & M62; secp256k1_i128_rshift(&cd, 62);+    e->v[0] = secp256k1_i128_to_u64(&ce) & M62; secp256k1_i128_rshift(&ce, 62);+    /* Compute limb 2 of t*[d,e]+modulus*[md,me], and store it as output limb 1. */+    secp256k1_i128_accum_mul(&cd, u, d2);+    secp256k1_i128_accum_mul(&cd, v, e2);+    secp256k1_i128_accum_mul(&ce, q, d2);+    secp256k1_i128_accum_mul(&ce, r, e2);+    if (modinfo->modulus.v[2]) { /* Optimize for the case where limb of modulus is zero. */+        secp256k1_i128_accum_mul(&cd, modinfo->modulus.v[2], md);+        secp256k1_i128_accum_mul(&ce, modinfo->modulus.v[2], me);+    }+    d->v[1] = secp256k1_i128_to_u64(&cd) & M62; secp256k1_i128_rshift(&cd, 62);+    e->v[1] = secp256k1_i128_to_u64(&ce) & M62; secp256k1_i128_rshift(&ce, 62);+    /* Compute limb 3 of t*[d,e]+modulus*[md,me], and store it as output limb 2. */+    secp256k1_i128_accum_mul(&cd, u, d3);+    secp256k1_i128_accum_mul(&cd, v, e3);+    secp256k1_i128_accum_mul(&ce, q, d3);+    secp256k1_i128_accum_mul(&ce, r, e3);+    if (modinfo->modulus.v[3]) { /* Optimize for the case where limb of modulus is zero. */+        secp256k1_i128_accum_mul(&cd, modinfo->modulus.v[3], md);+        secp256k1_i128_accum_mul(&ce, modinfo->modulus.v[3], me);+    }+    d->v[2] = secp256k1_i128_to_u64(&cd) & M62; secp256k1_i128_rshift(&cd, 62);+    e->v[2] = secp256k1_i128_to_u64(&ce) & M62; secp256k1_i128_rshift(&ce, 62);+    /* Compute limb 4 of t*[d,e]+modulus*[md,me], and store it as output limb 3. */+    secp256k1_i128_accum_mul(&cd, u, d4);+    secp256k1_i128_accum_mul(&cd, v, e4);+    secp256k1_i128_accum_mul(&ce, q, d4);+    secp256k1_i128_accum_mul(&ce, r, e4);+    secp256k1_i128_accum_mul(&cd, modinfo->modulus.v[4], md);+    secp256k1_i128_accum_mul(&ce, modinfo->modulus.v[4], me);+    d->v[3] = secp256k1_i128_to_u64(&cd) & M62; secp256k1_i128_rshift(&cd, 62);+    e->v[3] = secp256k1_i128_to_u64(&ce) & M62; secp256k1_i128_rshift(&ce, 62);+    /* What remains is limb 5 of t*[d,e]+modulus*[md,me]; store it as output limb 4. */+    d->v[4] = secp256k1_i128_to_i64(&cd);+    e->v[4] = secp256k1_i128_to_i64(&ce);++    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, -2) > 0); /* d > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(d, 5, &modinfo->modulus, 1) < 0);  /* d <    modulus */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, -2) > 0); /* e > -2*modulus */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(e, 5, &modinfo->modulus, 1) < 0);  /* e <    modulus */+}++/* Compute (t/2^62) * [f, g], where t is a transition matrix scaled by 2^62.+ *+ * This implements the update_fg function from the explanation.+ */+static void secp256k1_modinv64_update_fg_62(secp256k1_modinv64_signed62 *f, secp256k1_modinv64_signed62 *g, const secp256k1_modinv64_trans2x2 *t) {+    const uint64_t M62 = UINT64_MAX >> 2;+    const int64_t f0 = f->v[0], f1 = f->v[1], f2 = f->v[2], f3 = f->v[3], f4 = f->v[4];+    const int64_t g0 = g->v[0], g1 = g->v[1], g2 = g->v[2], g3 = g->v[3], g4 = g->v[4];+    const int64_t u = t->u, v = t->v, q = t->q, r = t->r;+    secp256k1_int128 cf, cg;+    /* Start computing t*[f,g]. */+    secp256k1_i128_mul(&cf, u, f0);+    secp256k1_i128_accum_mul(&cf, v, g0);+    secp256k1_i128_mul(&cg, q, f0);+    secp256k1_i128_accum_mul(&cg, r, g0);+    /* Verify that the bottom 62 bits of the result are zero, and then throw them away. */+    VERIFY_CHECK((secp256k1_i128_to_u64(&cf) & M62) == 0); secp256k1_i128_rshift(&cf, 62);+    VERIFY_CHECK((secp256k1_i128_to_u64(&cg) & M62) == 0); secp256k1_i128_rshift(&cg, 62);+    /* Compute limb 1 of t*[f,g], and store it as output limb 0 (= down shift). */+    secp256k1_i128_accum_mul(&cf, u, f1);+    secp256k1_i128_accum_mul(&cf, v, g1);+    secp256k1_i128_accum_mul(&cg, q, f1);+    secp256k1_i128_accum_mul(&cg, r, g1);+    f->v[0] = secp256k1_i128_to_u64(&cf) & M62; secp256k1_i128_rshift(&cf, 62);+    g->v[0] = secp256k1_i128_to_u64(&cg) & M62; secp256k1_i128_rshift(&cg, 62);+    /* Compute limb 2 of t*[f,g], and store it as output limb 1. */+    secp256k1_i128_accum_mul(&cf, u, f2);+    secp256k1_i128_accum_mul(&cf, v, g2);+    secp256k1_i128_accum_mul(&cg, q, f2);+    secp256k1_i128_accum_mul(&cg, r, g2);+    f->v[1] = secp256k1_i128_to_u64(&cf) & M62; secp256k1_i128_rshift(&cf, 62);+    g->v[1] = secp256k1_i128_to_u64(&cg) & M62; secp256k1_i128_rshift(&cg, 62);+    /* Compute limb 3 of t*[f,g], and store it as output limb 2. */+    secp256k1_i128_accum_mul(&cf, u, f3);+    secp256k1_i128_accum_mul(&cf, v, g3);+    secp256k1_i128_accum_mul(&cg, q, f3);+    secp256k1_i128_accum_mul(&cg, r, g3);+    f->v[2] = secp256k1_i128_to_u64(&cf) & M62; secp256k1_i128_rshift(&cf, 62);+    g->v[2] = secp256k1_i128_to_u64(&cg) & M62; secp256k1_i128_rshift(&cg, 62);+    /* Compute limb 4 of t*[f,g], and store it as output limb 3. */+    secp256k1_i128_accum_mul(&cf, u, f4);+    secp256k1_i128_accum_mul(&cf, v, g4);+    secp256k1_i128_accum_mul(&cg, q, f4);+    secp256k1_i128_accum_mul(&cg, r, g4);+    f->v[3] = secp256k1_i128_to_u64(&cf) & M62; secp256k1_i128_rshift(&cf, 62);+    g->v[3] = secp256k1_i128_to_u64(&cg) & M62; secp256k1_i128_rshift(&cg, 62);+    /* What remains is limb 5 of t*[f,g]; store it as output limb 4. */+    f->v[4] = secp256k1_i128_to_i64(&cf);+    g->v[4] = secp256k1_i128_to_i64(&cg);+}++/* Compute (t/2^62) * [f, g], where t is a transition matrix for 62 divsteps.+ *+ * Version that operates on a variable number of limbs in f and g.+ *+ * This implements the update_fg function from the explanation.+ */+static void secp256k1_modinv64_update_fg_62_var(int len, secp256k1_modinv64_signed62 *f, secp256k1_modinv64_signed62 *g, const secp256k1_modinv64_trans2x2 *t) {+    const uint64_t M62 = UINT64_MAX >> 2;+    const int64_t u = t->u, v = t->v, q = t->q, r = t->r;+    int64_t fi, gi;+    secp256k1_int128 cf, cg;+    int i;+    VERIFY_CHECK(len > 0);+    /* Start computing t*[f,g]. */+    fi = f->v[0];+    gi = g->v[0];+    secp256k1_i128_mul(&cf, u, fi);+    secp256k1_i128_accum_mul(&cf, v, gi);+    secp256k1_i128_mul(&cg, q, fi);+    secp256k1_i128_accum_mul(&cg, r, gi);+    /* Verify that the bottom 62 bits of the result are zero, and then throw them away. */+    VERIFY_CHECK((secp256k1_i128_to_u64(&cf) & M62) == 0); secp256k1_i128_rshift(&cf, 62);+    VERIFY_CHECK((secp256k1_i128_to_u64(&cg) & M62) == 0); secp256k1_i128_rshift(&cg, 62);+    /* Now iteratively compute limb i=1..len of t*[f,g], and store them in output limb i-1 (shifting+     * down by 62 bits). */+    for (i = 1; i < len; ++i) {+        fi = f->v[i];+        gi = g->v[i];+        secp256k1_i128_accum_mul(&cf, u, fi);+        secp256k1_i128_accum_mul(&cf, v, gi);+        secp256k1_i128_accum_mul(&cg, q, fi);+        secp256k1_i128_accum_mul(&cg, r, gi);+        f->v[i - 1] = secp256k1_i128_to_u64(&cf) & M62; secp256k1_i128_rshift(&cf, 62);+        g->v[i - 1] = secp256k1_i128_to_u64(&cg) & M62; secp256k1_i128_rshift(&cg, 62);+    }+    /* What remains is limb (len) of t*[f,g]; store it as output limb (len-1). */+    f->v[len - 1] = secp256k1_i128_to_i64(&cf);+    g->v[len - 1] = secp256k1_i128_to_i64(&cg);+}++/* Compute the inverse of x modulo modinfo->modulus, and replace x with it (constant time in x). */+static void secp256k1_modinv64(secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo) {+    /* Start with d=0, e=1, f=modulus, g=x, zeta=-1. */+    secp256k1_modinv64_signed62 d = {{0, 0, 0, 0, 0}};+    secp256k1_modinv64_signed62 e = {{1, 0, 0, 0, 0}};+    secp256k1_modinv64_signed62 f = modinfo->modulus;+    secp256k1_modinv64_signed62 g = *x;+    int i;+    int64_t zeta = -1; /* zeta = -(delta+1/2); delta starts at 1/2. */++    /* Do 10 iterations of 59 divsteps each = 590 divsteps. This suffices for 256-bit inputs. */+    for (i = 0; i < 10; ++i) {+        /* Compute transition matrix and new zeta after 59 divsteps. */+        secp256k1_modinv64_trans2x2 t;+        zeta = secp256k1_modinv64_divsteps_59(zeta, f.v[0], g.v[0], &t);+        /* Update d,e using that transition matrix. */+        secp256k1_modinv64_update_de_62(&d, &e, &t, modinfo);+        /* Update f,g using that transition matrix. */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, -1) > 0); /* f > -modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, -1) > 0); /* g > -modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, 1) < 0);  /* g <  modulus */++        secp256k1_modinv64_update_fg_62(&f, &g, &t);++        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, -1) > 0); /* f > -modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, -1) > 0); /* g > -modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, 5, &modinfo->modulus, 1) < 0);  /* g <  modulus */+    }++    /* At this point sufficient iterations have been performed that g must have reached 0+     * and (if g was not originally 0) f must now equal +/- GCD of the initial f, g+     * values i.e. +/- 1, and d now contains +/- the modular inverse. */++    /* g == 0 */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, 5, &SECP256K1_SIGNED62_ONE, 0) == 0);+    /* |f| == 1, or (x == 0 and d == 0 and f == modulus) */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, 5, &SECP256K1_SIGNED62_ONE, -1) == 0 ||+                 secp256k1_modinv64_mul_cmp_62(&f, 5, &SECP256K1_SIGNED62_ONE, 1) == 0 ||+                 (secp256k1_modinv64_mul_cmp_62(x, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 &&+                  secp256k1_modinv64_mul_cmp_62(&d, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 &&+                  secp256k1_modinv64_mul_cmp_62(&f, 5, &modinfo->modulus, 1) == 0));++    /* Optionally negate d, normalize to [0,modulus), and return it. */+    secp256k1_modinv64_normalize_62(&d, f.v[4], modinfo);+    *x = d;+}++/* Compute the inverse of x modulo modinfo->modulus, and replace x with it (variable time). */+static void secp256k1_modinv64_var(secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo) {+    /* Start with d=0, e=1, f=modulus, g=x, eta=-1. */+    secp256k1_modinv64_signed62 d = {{0, 0, 0, 0, 0}};+    secp256k1_modinv64_signed62 e = {{1, 0, 0, 0, 0}};+    secp256k1_modinv64_signed62 f = modinfo->modulus;+    secp256k1_modinv64_signed62 g = *x;+#ifdef VERIFY+    int i = 0;+#endif+    int j, len = 5;+    int64_t eta = -1; /* eta = -delta; delta is initially 1 */+    int64_t cond, fn, gn;++    /* Do iterations of 62 divsteps each until g=0. */+    while (1) {+        /* Compute transition matrix and new eta after 62 divsteps. */+        secp256k1_modinv64_trans2x2 t;+        eta = secp256k1_modinv64_divsteps_62_var(eta, f.v[0], g.v[0], &t);+        /* Update d,e using that transition matrix. */+        secp256k1_modinv64_update_de_62(&d, &e, &t, modinfo);+        /* Update f,g using that transition matrix. */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0);  /* g <  modulus */++        secp256k1_modinv64_update_fg_62_var(len, &f, &g, &t);+        /* If the bottom limb of g is zero, there is a chance that g=0. */+        if (g.v[0] == 0) {+            cond = 0;+            /* Check if the other limbs are also 0. */+            for (j = 1; j < len; ++j) {+                cond |= g.v[j];+            }+            /* If so, we're done. */+            if (cond == 0) break;+        }++        /* Determine if len>1 and limb (len-1) of both f and g is 0 or -1. */+        fn = f.v[len - 1];+        gn = g.v[len - 1];+        cond = ((int64_t)len - 2) >> 63;+        cond |= fn ^ (fn >> 63);+        cond |= gn ^ (gn >> 63);+        /* If so, reduce length, propagating the sign of f and g's top limb into the one below. */+        if (cond == 0) {+            f.v[len - 2] |= (uint64_t)fn << 62;+            g.v[len - 2] |= (uint64_t)gn << 62;+            --len;+        }++        VERIFY_CHECK(++i < 12); /* We should never need more than 12*62 = 744 divsteps */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, -1) > 0); /* f > -modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, -1) > 0); /* g > -modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0);  /* g <  modulus */+    }++    /* At this point g is 0 and (if g was not originally 0) f must now equal +/- GCD of+     * the initial f, g values i.e. +/- 1, and d now contains +/- the modular inverse. */++    /* g == 0 */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, len, &SECP256K1_SIGNED62_ONE, 0) == 0);+    /* |f| == 1, or (x == 0 and d == 0 and f == modulus) */+    VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, len, &SECP256K1_SIGNED62_ONE, -1) == 0 ||+                 secp256k1_modinv64_mul_cmp_62(&f, len, &SECP256K1_SIGNED62_ONE, 1) == 0 ||+                 (secp256k1_modinv64_mul_cmp_62(x, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 &&+                  secp256k1_modinv64_mul_cmp_62(&d, 5, &SECP256K1_SIGNED62_ONE, 0) == 0 &&+                  secp256k1_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) == 0));++    /* Optionally negate d, normalize to [0,modulus), and return it. */+    secp256k1_modinv64_normalize_62(&d, f.v[len - 1], modinfo);+    *x = d;+}++/* Do up to 25 iterations of 62 posdivsteps (up to 1550 steps; more is extremely rare) each until f=1.+ * In VERIFY mode use a lower number of iterations (744, close to the median 756), so failure actually occurs. */+#ifdef VERIFY+#define JACOBI64_ITERATIONS 12+#else+#define JACOBI64_ITERATIONS 25+#endif++/* Compute the Jacobi symbol of x modulo modinfo->modulus (variable time). gcd(x,modulus) must be 1. */+static int secp256k1_jacobi64_maybe_var(const secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo) {+    /* Start with f=modulus, g=x, eta=-1. */+    secp256k1_modinv64_signed62 f = modinfo->modulus;+    secp256k1_modinv64_signed62 g = *x;+    int j, len = 5;+    int64_t eta = -1; /* eta = -delta; delta is initially 1 */+    int64_t cond, fn, gn;+    int jac = 0;+    int count;++    /* The input limbs must all be non-negative. */+    VERIFY_CHECK(g.v[0] >= 0 && g.v[1] >= 0 && g.v[2] >= 0 && g.v[3] >= 0 && g.v[4] >= 0);++    /* If x > 0, then if the loop below converges, it converges to f=g=gcd(x,modulus). Since we+     * require that gcd(x,modulus)=1 and modulus>=3, x cannot be 0. Thus, we must reach f=1 (or+     * time out). */+    VERIFY_CHECK((g.v[0] | g.v[1] | g.v[2] | g.v[3] | g.v[4]) != 0);++    for (count = 0; count < JACOBI64_ITERATIONS; ++count) {+        /* Compute transition matrix and new eta after 62 posdivsteps. */+        secp256k1_modinv64_trans2x2 t;+        eta = secp256k1_modinv64_posdivsteps_62_var(eta, f.v[0] | ((uint64_t)f.v[1] << 62), g.v[0] | ((uint64_t)g.v[1] << 62), &t, &jac);+        /* Update f,g using that transition matrix. */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0);  /* g < modulus */++        secp256k1_modinv64_update_fg_62_var(len, &f, &g, &t);+        /* If the bottom limb of f is 1, there is a chance that f=1. */+        if (f.v[0] == 1) {+            cond = 0;+            /* Check if the other limbs are also 0. */+            for (j = 1; j < len; ++j) {+                cond |= f.v[j];+            }+            /* If so, we're done. When f=1, the Jacobi symbol (g | f)=1. */+            if (cond == 0) return 1 - 2*(jac & 1);+        }++        /* Determine if len>1 and limb (len-1) of both f and g is 0. */+        fn = f.v[len - 1];+        gn = g.v[len - 1];+        cond = ((int64_t)len - 2) >> 63;+        cond |= fn;+        cond |= gn;+        /* If so, reduce length. */+        if (cond == 0) --len;++        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 0) > 0); /* f > 0 */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&f, len, &modinfo->modulus, 1) <= 0); /* f <= modulus */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 0) > 0); /* g > 0 */+        VERIFY_CHECK(secp256k1_modinv64_mul_cmp_62(&g, len, &modinfo->modulus, 1) < 0);  /* g < modulus */+    }++    /* The loop failed to converge to f=g after 1550 iterations. Return 0, indicating unknown result. */+    return 0;+}++#endif /* SECP256K1_MODINV64_IMPL_H */
+ vendor/external/secp256k1/src/modules/extrakeys/main_impl.h view
@@ -0,0 +1,285 @@+/***********************************************************************+ * Copyright (c) 2020 Jonas Nick                                       *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_MODULE_EXTRAKEYS_MAIN_H+#define SECP256K1_MODULE_EXTRAKEYS_MAIN_H++#include "../../../include/secp256k1.h"+#include "../../../include/secp256k1_extrakeys.h"+#include "../../util.h"++static SECP256K1_INLINE int secp256k1_xonly_pubkey_load(const secp256k1_context* ctx, secp256k1_ge *ge, const secp256k1_xonly_pubkey *pubkey) {+    return secp256k1_pubkey_load(ctx, ge, (const secp256k1_pubkey *) pubkey);+}++static SECP256K1_INLINE void secp256k1_xonly_pubkey_save(secp256k1_xonly_pubkey *pubkey, secp256k1_ge *ge) {+    secp256k1_pubkey_save((secp256k1_pubkey *) pubkey, ge);+}++int secp256k1_xonly_pubkey_parse(const secp256k1_context* ctx, secp256k1_xonly_pubkey *pubkey, const unsigned char *input32) {+    secp256k1_ge pk;+    secp256k1_fe x;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubkey != NULL);+    memset(pubkey, 0, sizeof(*pubkey));+    ARG_CHECK(input32 != NULL);++    if (!secp256k1_fe_set_b32_limit(&x, input32)) {+        return 0;+    }+    if (!secp256k1_ge_set_xo_var(&pk, &x, 0)) {+        return 0;+    }+    if (!secp256k1_ge_is_in_correct_subgroup(&pk)) {+        return 0;+    }+    secp256k1_xonly_pubkey_save(pubkey, &pk);+    return 1;+}++int secp256k1_xonly_pubkey_serialize(const secp256k1_context* ctx, unsigned char *output32, const secp256k1_xonly_pubkey *pubkey) {+    secp256k1_ge pk;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(output32 != NULL);+    memset(output32, 0, 32);+    ARG_CHECK(pubkey != NULL);++    if (!secp256k1_xonly_pubkey_load(ctx, &pk, pubkey)) {+        return 0;+    }+    secp256k1_fe_get_b32(output32, &pk.x);+    return 1;+}++int secp256k1_xonly_pubkey_cmp(const secp256k1_context* ctx, const secp256k1_xonly_pubkey* pk0, const secp256k1_xonly_pubkey* pk1) {+    unsigned char out[2][32];+    const secp256k1_xonly_pubkey* pk[2];+    int i;++    VERIFY_CHECK(ctx != NULL);+    pk[0] = pk0; pk[1] = pk1;+    for (i = 0; i < 2; i++) {+        /* If the public key is NULL or invalid, xonly_pubkey_serialize will+         * call the illegal_callback and return 0. In that case we will+         * serialize the key as all zeros which is less than any valid public+         * key. This results in consistent comparisons even if NULL or invalid+         * pubkeys are involved and prevents edge cases such as sorting+         * algorithms that use this function and do not terminate as a+         * result. */+        if (!secp256k1_xonly_pubkey_serialize(ctx, out[i], pk[i])) {+            /* Note that xonly_pubkey_serialize should already set the output to+             * zero in that case, but it's not guaranteed by the API, we can't+             * test it and writing a VERIFY_CHECK is more complex than+             * explicitly memsetting (again). */+            memset(out[i], 0, sizeof(out[i]));+        }+    }+    return secp256k1_memcmp_var(out[0], out[1], sizeof(out[1]));+}++/** Keeps a group element as is if it has an even Y and otherwise negates it.+ *  y_parity is set to 0 in the former case and to 1 in the latter case.+ *  Requires that the coordinates of r are normalized. */+static int secp256k1_extrakeys_ge_even_y(secp256k1_ge *r) {+    int y_parity = 0;+    VERIFY_CHECK(!secp256k1_ge_is_infinity(r));++    if (secp256k1_fe_is_odd(&r->y)) {+        secp256k1_fe_negate(&r->y, &r->y, 1);+        y_parity = 1;+    }+    return y_parity;+}++int secp256k1_xonly_pubkey_from_pubkey(const secp256k1_context* ctx, secp256k1_xonly_pubkey *xonly_pubkey, int *pk_parity, const secp256k1_pubkey *pubkey) {+    secp256k1_ge pk;+    int tmp;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(xonly_pubkey != NULL);+    ARG_CHECK(pubkey != NULL);++    if (!secp256k1_pubkey_load(ctx, &pk, pubkey)) {+        return 0;+    }+    tmp = secp256k1_extrakeys_ge_even_y(&pk);+    if (pk_parity != NULL) {+        *pk_parity = tmp;+    }+    secp256k1_xonly_pubkey_save(xonly_pubkey, &pk);+    return 1;+}++int secp256k1_xonly_pubkey_tweak_add(const secp256k1_context* ctx, secp256k1_pubkey *output_pubkey, const secp256k1_xonly_pubkey *internal_pubkey, const unsigned char *tweak32) {+    secp256k1_ge pk;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(output_pubkey != NULL);+    memset(output_pubkey, 0, sizeof(*output_pubkey));+    ARG_CHECK(internal_pubkey != NULL);+    ARG_CHECK(tweak32 != NULL);++    if (!secp256k1_xonly_pubkey_load(ctx, &pk, internal_pubkey)+        || !secp256k1_ec_pubkey_tweak_add_helper(&pk, tweak32)) {+        return 0;+    }+    secp256k1_pubkey_save(output_pubkey, &pk);+    return 1;+}++int secp256k1_xonly_pubkey_tweak_add_check(const secp256k1_context* ctx, const unsigned char *tweaked_pubkey32, int tweaked_pk_parity, const secp256k1_xonly_pubkey *internal_pubkey, const unsigned char *tweak32) {+    secp256k1_ge pk;+    unsigned char pk_expected32[32];++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(internal_pubkey != NULL);+    ARG_CHECK(tweaked_pubkey32 != NULL);+    ARG_CHECK(tweak32 != NULL);++    if (!secp256k1_xonly_pubkey_load(ctx, &pk, internal_pubkey)+        || !secp256k1_ec_pubkey_tweak_add_helper(&pk, tweak32)) {+        return 0;+    }+    secp256k1_fe_normalize_var(&pk.x);+    secp256k1_fe_normalize_var(&pk.y);+    secp256k1_fe_get_b32(pk_expected32, &pk.x);++    return secp256k1_memcmp_var(&pk_expected32, tweaked_pubkey32, 32) == 0+            && secp256k1_fe_is_odd(&pk.y) == tweaked_pk_parity;+}++static void secp256k1_keypair_save(secp256k1_keypair *keypair, const secp256k1_scalar *sk, secp256k1_ge *pk) {+    secp256k1_scalar_get_b32(&keypair->data[0], sk);+    secp256k1_pubkey_save((secp256k1_pubkey *)&keypair->data[32], pk);+}+++static int secp256k1_keypair_seckey_load(const secp256k1_context* ctx, secp256k1_scalar *sk, const secp256k1_keypair *keypair) {+    int ret;++    ret = secp256k1_scalar_set_b32_seckey(sk, &keypair->data[0]);+    /* We can declassify ret here because sk is only zero if a keypair function+     * failed (which zeroes the keypair) and its return value is ignored. */+    secp256k1_declassify(ctx, &ret, sizeof(ret));+    ARG_CHECK(ret);+    return ret;+}++/* Load a keypair into pk and sk (if non-NULL). This function declassifies pk+ * and ARG_CHECKs that the keypair is not invalid. It always initializes sk and+ * pk with dummy values. */+static int secp256k1_keypair_load(const secp256k1_context* ctx, secp256k1_scalar *sk, secp256k1_ge *pk, const secp256k1_keypair *keypair) {+    int ret;+    const secp256k1_pubkey *pubkey = (const secp256k1_pubkey *)&keypair->data[32];++    /* Need to declassify the pubkey because pubkey_load ARG_CHECKs if it's+     * invalid. */+    secp256k1_declassify(ctx, pubkey, sizeof(*pubkey));+    ret = secp256k1_pubkey_load(ctx, pk, pubkey);+    if (sk != NULL) {+        ret = ret && secp256k1_keypair_seckey_load(ctx, sk, keypair);+    }+    if (!ret) {+        *pk = secp256k1_ge_const_g;+        if (sk != NULL) {+            *sk = secp256k1_scalar_one;+        }+    }+    return ret;+}++int secp256k1_keypair_create(const secp256k1_context* ctx, secp256k1_keypair *keypair, const unsigned char *seckey32) {+    secp256k1_scalar sk;+    secp256k1_ge pk;+    int ret = 0;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(keypair != NULL);+    memset(keypair, 0, sizeof(*keypair));+    ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));+    ARG_CHECK(seckey32 != NULL);++    ret = secp256k1_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &sk, &pk, seckey32);+    secp256k1_keypair_save(keypair, &sk, &pk);+    secp256k1_memczero(keypair, sizeof(*keypair), !ret);++    secp256k1_scalar_clear(&sk);+    return ret;+}++int secp256k1_keypair_sec(const secp256k1_context* ctx, unsigned char *seckey, const secp256k1_keypair *keypair) {+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(seckey != NULL);+    memset(seckey, 0, 32);+    ARG_CHECK(keypair != NULL);++    memcpy(seckey, &keypair->data[0], 32);+    return 1;+}++int secp256k1_keypair_pub(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const secp256k1_keypair *keypair) {+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubkey != NULL);+    memset(pubkey, 0, sizeof(*pubkey));+    ARG_CHECK(keypair != NULL);++    memcpy(pubkey->data, &keypair->data[32], sizeof(*pubkey));+    return 1;+}++int secp256k1_keypair_xonly_pub(const secp256k1_context* ctx, secp256k1_xonly_pubkey *pubkey, int *pk_parity, const secp256k1_keypair *keypair) {+    secp256k1_ge pk;+    int tmp;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubkey != NULL);+    memset(pubkey, 0, sizeof(*pubkey));+    ARG_CHECK(keypair != NULL);++    if (!secp256k1_keypair_load(ctx, NULL, &pk, keypair)) {+        return 0;+    }+    tmp = secp256k1_extrakeys_ge_even_y(&pk);+    if (pk_parity != NULL) {+        *pk_parity = tmp;+    }+    secp256k1_xonly_pubkey_save(pubkey, &pk);++    return 1;+}++int secp256k1_keypair_xonly_tweak_add(const secp256k1_context* ctx, secp256k1_keypair *keypair, const unsigned char *tweak32) {+    secp256k1_ge pk;+    secp256k1_scalar sk;+    int y_parity;+    int ret;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(keypair != NULL);+    ARG_CHECK(tweak32 != NULL);++    ret = secp256k1_keypair_load(ctx, &sk, &pk, keypair);+    memset(keypair, 0, sizeof(*keypair));++    y_parity = secp256k1_extrakeys_ge_even_y(&pk);+    if (y_parity == 1) {+        secp256k1_scalar_negate(&sk, &sk);+    }++    ret &= secp256k1_ec_seckey_tweak_add_helper(&sk, tweak32);+    ret &= secp256k1_ec_pubkey_tweak_add_helper(&pk, tweak32);++    secp256k1_declassify(ctx, &ret, sizeof(ret));+    if (ret) {+        secp256k1_keypair_save(keypair, &sk, &pk);+    }++    secp256k1_scalar_clear(&sk);+    return ret;+}++#endif
+ vendor/external/secp256k1/src/modules/schnorrsig/main_impl.h view
@@ -0,0 +1,269 @@+/***********************************************************************+ * Copyright (c) 2018-2020 Andrew Poelstra, Jonas Nick                 *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_MODULE_SCHNORRSIG_MAIN_H+#define SECP256K1_MODULE_SCHNORRSIG_MAIN_H++#include "../../../include/secp256k1.h"+#include "../../../include/secp256k1_schnorrsig.h"+#include "../../hash.h"++/* Initializes SHA256 with fixed midstate. This midstate was computed by applying+ * SHA256 to SHA256("BIP0340/nonce")||SHA256("BIP0340/nonce"). */+static void secp256k1_nonce_function_bip340_sha256_tagged(secp256k1_sha256 *sha) {+    secp256k1_sha256_initialize(sha);+    sha->s[0] = 0x46615b35ul;+    sha->s[1] = 0xf4bfbff7ul;+    sha->s[2] = 0x9f8dc671ul;+    sha->s[3] = 0x83627ab3ul;+    sha->s[4] = 0x60217180ul;+    sha->s[5] = 0x57358661ul;+    sha->s[6] = 0x21a29e54ul;+    sha->s[7] = 0x68b07b4cul;++    sha->bytes = 64;+}++/* Initializes SHA256 with fixed midstate. This midstate was computed by applying+ * SHA256 to SHA256("BIP0340/aux")||SHA256("BIP0340/aux"). */+static void secp256k1_nonce_function_bip340_sha256_tagged_aux(secp256k1_sha256 *sha) {+    secp256k1_sha256_initialize(sha);+    sha->s[0] = 0x24dd3219ul;+    sha->s[1] = 0x4eba7e70ul;+    sha->s[2] = 0xca0fabb9ul;+    sha->s[3] = 0x0fa3166dul;+    sha->s[4] = 0x3afbe4b1ul;+    sha->s[5] = 0x4c44df97ul;+    sha->s[6] = 0x4aac2739ul;+    sha->s[7] = 0x249e850aul;++    sha->bytes = 64;+}++/* algo argument for nonce_function_bip340 to derive the nonce exactly as stated in BIP-340+ * by using the correct tagged hash function. */+static const unsigned char bip340_algo[] = {'B', 'I', 'P', '0', '3', '4', '0', '/', 'n', 'o', 'n', 'c', 'e'};++static const unsigned char schnorrsig_extraparams_magic[4] = SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC;++static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *msg, size_t msglen, const unsigned char *key32, const unsigned char *xonly_pk32, const unsigned char *algo, size_t algolen, void *data) {+    secp256k1_sha256 sha;+    unsigned char masked_key[32];+    int i;++    if (algo == NULL) {+        return 0;+    }++    if (data != NULL) {+        secp256k1_nonce_function_bip340_sha256_tagged_aux(&sha);+        secp256k1_sha256_write(&sha, data, 32);+        secp256k1_sha256_finalize(&sha, masked_key);+        for (i = 0; i < 32; i++) {+            masked_key[i] ^= key32[i];+        }+    } else {+        /* Precomputed TaggedHash("BIP0340/aux", 0x0000...00); */+        static const unsigned char ZERO_MASK[32] = {+              84, 241, 105, 207, 201, 226, 229, 114,+             116, 128,  68,  31, 144, 186,  37, 196,+             136, 244,  97, 199,  11,  94, 165, 220,+             170, 247, 175, 105, 39,  10, 165,  20+        };+        for (i = 0; i < 32; i++) {+            masked_key[i] = key32[i] ^ ZERO_MASK[i];+        }+    }++    /* Tag the hash with algo which is important to avoid nonce reuse across+     * algorithms. If this nonce function is used in BIP-340 signing as defined+     * in the spec, an optimized tagging implementation is used. */+    if (algolen == sizeof(bip340_algo)+            && secp256k1_memcmp_var(algo, bip340_algo, algolen) == 0) {+        secp256k1_nonce_function_bip340_sha256_tagged(&sha);+    } else {+        secp256k1_sha256_initialize_tagged(&sha, algo, algolen);+    }++    /* Hash masked-key||pk||msg using the tagged hash as per the spec */+    secp256k1_sha256_write(&sha, masked_key, 32);+    secp256k1_sha256_write(&sha, xonly_pk32, 32);+    secp256k1_sha256_write(&sha, msg, msglen);+    secp256k1_sha256_finalize(&sha, nonce32);+    secp256k1_sha256_clear(&sha);+    return 1;+}++const secp256k1_nonce_function_hardened secp256k1_nonce_function_bip340 = nonce_function_bip340;++/* Initializes SHA256 with fixed midstate. This midstate was computed by applying+ * SHA256 to SHA256("BIP0340/challenge")||SHA256("BIP0340/challenge"). */+static void secp256k1_schnorrsig_sha256_tagged(secp256k1_sha256 *sha) {+    secp256k1_sha256_initialize(sha);+    sha->s[0] = 0x9cecba11ul;+    sha->s[1] = 0x23925381ul;+    sha->s[2] = 0x11679112ul;+    sha->s[3] = 0xd1627e0ful;+    sha->s[4] = 0x97c87550ul;+    sha->s[5] = 0x003cc765ul;+    sha->s[6] = 0x90f61164ul;+    sha->s[7] = 0x33e9b66aul;+    sha->bytes = 64;+}++static void secp256k1_schnorrsig_challenge(secp256k1_scalar* e, const unsigned char *r32, const unsigned char *msg, size_t msglen, const unsigned char *pubkey32)+{+    unsigned char buf[32];+    secp256k1_sha256 sha;++    /* tagged hash(r.x, pk.x, msg) */+    secp256k1_schnorrsig_sha256_tagged(&sha);+    secp256k1_sha256_write(&sha, r32, 32);+    secp256k1_sha256_write(&sha, pubkey32, 32);+    secp256k1_sha256_write(&sha, msg, msglen);+    secp256k1_sha256_finalize(&sha, buf);+    /* Set scalar e to the challenge hash modulo the curve order as per+     * BIP340. */+    secp256k1_scalar_set_b32(e, buf, NULL);+}++static int secp256k1_schnorrsig_sign_internal(const secp256k1_context* ctx, unsigned char *sig64, const unsigned char *msg, size_t msglen, const secp256k1_keypair *keypair, secp256k1_nonce_function_hardened noncefp, void *ndata) {+    secp256k1_scalar sk;+    secp256k1_scalar e;+    secp256k1_scalar k;+    secp256k1_gej rj;+    secp256k1_ge pk;+    secp256k1_ge r;+    unsigned char buf[32] = { 0 };+    unsigned char pk_buf[32];+    unsigned char seckey[32];+    int ret = 1;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));+    ARG_CHECK(sig64 != NULL);+    ARG_CHECK(msg != NULL || msglen == 0);+    ARG_CHECK(keypair != NULL);++    if (noncefp == NULL) {+        noncefp = secp256k1_nonce_function_bip340;+    }++    ret &= secp256k1_keypair_load(ctx, &sk, &pk, keypair);+    /* Because we are signing for a x-only pubkey, the secret key is negated+     * before signing if the point corresponding to the secret key does not+     * have an even Y. */+    if (secp256k1_fe_is_odd(&pk.y)) {+        secp256k1_scalar_negate(&sk, &sk);+    }++    secp256k1_scalar_get_b32(seckey, &sk);+    secp256k1_fe_get_b32(pk_buf, &pk.x);+    ret &= !!noncefp(buf, msg, msglen, seckey, pk_buf, bip340_algo, sizeof(bip340_algo), ndata);+    secp256k1_scalar_set_b32(&k, buf, NULL);+    ret &= !secp256k1_scalar_is_zero(&k);+    secp256k1_scalar_cmov(&k, &secp256k1_scalar_one, !ret);++    secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &rj, &k);+    secp256k1_ge_set_gej(&r, &rj);++    /* We declassify r to allow using it as a branch point. This is fine+     * because r is not a secret. */+    secp256k1_declassify(ctx, &r, sizeof(r));+    secp256k1_fe_normalize_var(&r.y);+    if (secp256k1_fe_is_odd(&r.y)) {+        secp256k1_scalar_negate(&k, &k);+    }+    secp256k1_fe_normalize_var(&r.x);+    secp256k1_fe_get_b32(&sig64[0], &r.x);++    secp256k1_schnorrsig_challenge(&e, &sig64[0], msg, msglen, pk_buf);+    secp256k1_scalar_mul(&e, &e, &sk);+    secp256k1_scalar_add(&e, &e, &k);+    secp256k1_scalar_get_b32(&sig64[32], &e);++    secp256k1_memczero(sig64, 64, !ret);+    secp256k1_scalar_clear(&k);+    secp256k1_scalar_clear(&sk);+    secp256k1_memclear(seckey, sizeof(seckey));+    secp256k1_gej_clear(&rj);++    return ret;+}++int secp256k1_schnorrsig_sign32(const secp256k1_context* ctx, unsigned char *sig64, const unsigned char *msg32, const secp256k1_keypair *keypair, const unsigned char *aux_rand32) {+    /* We cast away const from the passed aux_rand32 argument since we know the default nonce function does not modify it. */+    return secp256k1_schnorrsig_sign_internal(ctx, sig64, msg32, 32, keypair, secp256k1_nonce_function_bip340, (unsigned char*)aux_rand32);+}++int secp256k1_schnorrsig_sign(const secp256k1_context* ctx, unsigned char *sig64, const unsigned char *msg32, const secp256k1_keypair *keypair, const unsigned char *aux_rand32) {+    return secp256k1_schnorrsig_sign32(ctx, sig64, msg32, keypair, aux_rand32);+}++int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char *sig64, const unsigned char *msg, size_t msglen, const secp256k1_keypair *keypair, secp256k1_schnorrsig_extraparams *extraparams) {+    secp256k1_nonce_function_hardened noncefp = NULL;+    void *ndata = NULL;+    VERIFY_CHECK(ctx != NULL);++    if (extraparams != NULL) {+        ARG_CHECK(secp256k1_memcmp_var(extraparams->magic,+                                       schnorrsig_extraparams_magic,+                                       sizeof(extraparams->magic)) == 0);+        noncefp = extraparams->noncefp;+        ndata = extraparams->ndata;+    }+    return secp256k1_schnorrsig_sign_internal(ctx, sig64, msg, msglen, keypair, noncefp, ndata);+}++int secp256k1_schnorrsig_verify(const secp256k1_context* ctx, const unsigned char *sig64, const unsigned char *msg, size_t msglen, const secp256k1_xonly_pubkey *pubkey) {+    secp256k1_scalar s;+    secp256k1_scalar e;+    secp256k1_gej rj;+    secp256k1_ge pk;+    secp256k1_gej pkj;+    secp256k1_fe rx;+    secp256k1_ge r;+    unsigned char buf[32];+    int overflow;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(sig64 != NULL);+    ARG_CHECK(msg != NULL || msglen == 0);+    ARG_CHECK(pubkey != NULL);++    if (!secp256k1_fe_set_b32_limit(&rx, &sig64[0])) {+        return 0;+    }++    secp256k1_scalar_set_b32(&s, &sig64[32], &overflow);+    if (overflow) {+        return 0;+    }++    if (!secp256k1_xonly_pubkey_load(ctx, &pk, pubkey)) {+        return 0;+    }++    /* Compute e. */+    secp256k1_fe_get_b32(buf, &pk.x);+    secp256k1_schnorrsig_challenge(&e, &sig64[0], msg, msglen, buf);++    /* Compute rj =  s*G + (-e)*pkj */+    secp256k1_scalar_negate(&e, &e);+    secp256k1_gej_set_ge(&pkj, &pk);+    secp256k1_ecmult(&rj, &pkj, &e, &s);++    secp256k1_ge_set_gej_var(&r, &rj);+    if (secp256k1_ge_is_infinity(&r)) {+        return 0;+    }++    secp256k1_fe_normalize_var(&r.y);+    return !secp256k1_fe_is_odd(&r.y) &&+           secp256k1_fe_equal(&rx, &r.x);+}++#endif
+ vendor/external/secp256k1/src/precomputed_ecmult.c view

file too large to diff

+ vendor/external/secp256k1/src/precomputed_ecmult.h view
@@ -0,0 +1,38 @@+/*****************************************************************************************************+ * Copyright (c) 2013, 2014, 2017, 2021 Pieter Wuille, Andrew Poelstra, Jonas Nick, Russell O'Connor *+ * Distributed under the MIT software license, see the accompanying                                  *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.                              *+ *****************************************************************************************************/++#ifndef SECP256K1_PRECOMPUTED_ECMULT_H+#define SECP256K1_PRECOMPUTED_ECMULT_H++#ifdef __cplusplus+extern "C" {+#endif++#include "ecmult.h"+#include "group.h"+#if defined(EXHAUSTIVE_TEST_ORDER)+#    if EXHAUSTIVE_TEST_ORDER == 7+#        define WINDOW_G 3+#    elif EXHAUSTIVE_TEST_ORDER == 13+#        define WINDOW_G 4+#    elif EXHAUSTIVE_TEST_ORDER == 199+#        define WINDOW_G 8+#    else+#        error No known generator for the specified exhaustive test group order.+#    endif+static secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)];+static secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)];+#else /* !defined(EXHAUSTIVE_TEST_ORDER) */+#    define WINDOW_G ECMULT_WINDOW_SIZE+extern const secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)];+extern const secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)];+#endif /* defined(EXHAUSTIVE_TEST_ORDER) */++#ifdef __cplusplus+}+#endif++#endif /* SECP256K1_PRECOMPUTED_ECMULT_H */
+ vendor/external/secp256k1/src/precomputed_ecmult_gen.c view
@@ -0,0 +1,1779 @@+/* This file was automatically generated by precompute_ecmult_gen. */+/* See ecmult_gen_impl.h for details about the contents of this file. */+#include "group.h"+#include "ecmult_gen.h"+#include "precomputed_ecmult_gen.h"+#ifdef EXHAUSTIVE_TEST_ORDER+#    error Cannot compile precomputed_ecmult_gen.c in exhaustive test mode+#endif /* EXHAUSTIVE_TEST_ORDER */+#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)+const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS] = {+#if 0+#elif (COMB_BLOCKS == 2) && (COMB_TEETH == 5) && (COMB_SPACING == 26)+{S(7081b567,8cb87d01,99c9c76e,d1e0a5e0,1d784be9,27f6b135,161e0fd0,3f39b473,ad5222ac,f062cb39,21b234a7,15b626ae,f780b307,9b5122d1,53210f42,d9369242),+S(228af17e,df90d1cc,a40173e9,478fa445,9780dacd,c3f15b90,fda5d00e,1faa1b51,8ff47c4d,a4ba636a,f656da9,12a81f79,6252496d,1e519886,b2c2b073,25be2b4a),+S(b515ebe0,f48fb34e,9e01824c,d90553af,db116579,96667847,5ebaa700,242fd722,4cf08191,510fbf0,51f9e19a,198f11f6,ea31268c,2a6d384c,60557250,f0553c50),+S(c37581f1,35446ff3,e80cde04,ec987f08,5af3af9f,71d87494,99b03ba,dcb8f78c,9e46324a,8d8754fe,fbda7c34,2446cf72,b7472708,25cfb92f,a22a4e73,4f1e9bc7),+S(768392e3,b2ccbbc,21792f2d,6f43c63d,efcc249,bcd549cb,96abd8ef,4ae59e90,5d061a40,ac3f93d1,82f0f7a9,914fff5d,90bbacb9,1965882c,591e89bf,c49da994),+S(a9db5de9,2d96c715,8ce5ee00,3d186cf1,976f6a76,f1be0714,726594fb,6c1ba564,743df2a8,ee73fb4a,47b3d0f,2f2b8cab,5af5227,f232946a,82676e4e,8bb70c8b),+S(58921d8d,3712f640,657e762a,737ccd0a,cece1459,a2ba8323,20b43903,d4953f93,78c26959,7e422c02,c01fcbef,484a9d44,9f635c82,849bc2a3,2a9bf6ef,3e6f1e7e),+S(bae41760,ade541bb,60028015,f6906b78,aa41515a,d995dc40,afa091da,77ae8b9a,716ff74d,ad6dc24c,77ebe31f,abe19792,41d18b0f,43ff7598,c6ea04c6,6899219f),+S(e836ff6c,6f9e02e2,4e6f6bcc,2f2460b4,9de88730,6d69241f,b22fa574,7e100f80,77c41df1,4d87b6d3,de74deca,ad426635,f85daca0,ab966a4,5a26a972,32105c5),+S(c7f17d19,fbbf28e2,543fceb2,4268ff6f,1b85e189,79b09991,7457fca0,9ba1b5a4,23a6d4aa,83ee15bf,f1655575,3e4162c5,8acedadb,4c4abfc2,54b7018,f477514b),+S(79c337ad,8835046e,572eea35,df76276b,84e99172,7bbc68a6,8c0b743,28619a,af6cf2b3,9c6b51c9,f1f92e42,6598dcbe,39da6196,2abae0da,d5fc8d0a,aa16a875),+S(1e77739b,12d20887,2bfe200b,d202972a,544804f5,2b0969c5,c22fbe1c,b8b23837,880c7490,c0455322,a0f1e67d,34b3fd1e,33c1e7da,83b9b047,5aef7bc1,332ccee5),+S(b1d314c1,74d493f6,c36a893a,830d90b,f1e86d0c,6deceee0,edb77ff4,31e9607f,8a4ba010,ec3e47cb,29d8f056,e056eb73,3b6b35f6,4c742d06,9ab832f4,68bcd3be),+S(2498aea6,471f748a,f14e50e6,bc17e0a3,ee09514d,fccbd174,f8a21d02,dd0fae48,55a3949f,2e4188e2,b3d344ce,6f0276b5,99b121bc,358e8fe6,bc4f03f5,a8219d08),+S(42d0778e,27e87710,dd19285e,d531af1e,7064386d,11b1b3c9,fb788bf2,b0c112dc,37888909,d943825a,9610e37a,362549f,547b7c7d,ae64a27e,c34290f0,b4fc5fcc),+S(af09a9f8,3a21b2fd,69ce14c5,495c680e,df18e426,c1ca5a1c,af56246f,d6ea5bbd,8eae43ca,8e591017,62c4cb02,9e5cacd2,58f0fdb1,ddbef7e2,c5765208,107c96af)},+{S(4a7f72ed,ebd8df1f,13db15be,3ab296a8,d67edee4,37965f03,eb501205,3518ddea,1f8c4dc1,2d0e59e7,7d30a326,fd4ecbf8,aacd5fb6,7dc7169,898a9708,ac46b972),+S(c4d4f8d4,949d1ff6,559925db,f4d34972,af16062b,d59493b8,b1e0d546,c2870874,cd7f93e6,c0ee3fdc,4267625a,a6620540,4f6d80c3,d0f7210a,ce6b52e,c350706e),+S(773627f7,dcc56184,7eabafa3,42fffade,325b8ee2,a96f2f77,cbe675a6,2942277d,fb0ad731,9bff4c9c,270d93d1,89a4c380,218ec9df,1f564228,641ab35c,46526bd6),+S(ff443101,befd0bd9,e1914864,3eceea06,b9cf711b,1405e3d5,3883a29f,906063ed,aa1b7d9f,59cbddf7,bc1ad03c,44c4295e,efb406ca,7960c683,eca508d1,b2a9a2dd),+S(cbfb6813,a6874b65,9234e866,c2875f70,e45f9f76,3d634752,3f86040c,880a2e56,ed85d1a,6620c1a4,85ba3038,d2ee6590,4e27206b,eaa531ec,1eb5b886,8232cbca),+S(4e85c77b,27788563,aaeba139,975f7125,f3c933b4,8d67ba6a,2e964243,bdd7bb51,200a9d9b,3400c87b,1fb98422,3200aeb8,e6a5af1d,58c061f0,d059c0b8,d431c08a),+S(d58178ed,f0ce32e3,39a524f7,ad389f7d,8817f41f,ed782612,45218816,2a67d4f0,4840df81,5dab9596,93f9284c,54bdee72,f4861d39,3944c648,ecd76ec5,6dd3225e),+S(670f8f7,9b66496d,13692558,d56d4cd7,a1eeb0d6,9e5133ab,4f0a064b,7152fce4,1a72206,6f530586,927c2e39,370d11f3,e251bd9e,eee10303,406b7592,716333d6),+S(10b41abd,ed4de2fe,b7a40050,e61e5982,89a8cf3,6eaa608c,f2a82c63,5788f1d0,532d168d,680e9c74,4d5111da,6aab902a,9a0f5283,7836b9d9,585dbc8b,1a407de4),+S(76abd21b,103aea9a,f04b4040,297894ce,a501474d,9d38d30,8ed02cc7,137bc7c9,b5a432ad,9e92935f,7040897e,3b04152f,693c5f2,cc1e1d53,2c33f70d,185318e1),+S(4335e10d,5e4f02e6,f1b58a0d,ffb473ec,15f735a3,bf96c140,50bae78c,37061db2,1301143b,1f29f122,afcd0230,d46b6b38,b154e589,92b7eeb4,16088968,a7d57485),+S(2b3966f0,7e37e771,ac4c68ad,b8eef3c0,977cb895,2f47676b,e658aa86,76057f67,5382a6c5,bcdd1a01,6d79d817,80faf650,c0a486bc,ea8fb592,1cd3492c,42c91c3e),+S(f7738800,b7fdf237,dc7f03fc,43724011,8b53aea4,4d7953d4,276f3b4d,bf5c0ff8,c1de7924,ef8dfeed,c4fb409,f1a15d4c,5e8ab42c,90ea9c92,867b5b5c,f2921605),+S(5cb07874,ac4ffb86,2da619be,4c8fa38b,e8b261ec,3ec73a12,cd4cf8fc,4f8d5dae,549d1896,4931dabf,ba4553a2,461f2660,87733454,ea8eec6b,f671e3de,60c70340),+S(5cc85d41,7b2ae9ac,dedb1b44,ce78d8a7,8f56b878,1a4b3af6,635a55c1,fead3be7,66a48c79,301e57d4,54cc8644,d2e778a8,45d85762,2c10eb98,d77eb873,e58bbeca),+S(f27211c9,a067b01c,7fe7fbf7,7b5d9b0,eb0f2475,9d541457,6eb24ba4,19fd3db8,e26d28eb,89f7b518,e9ae0b88,fadbfb9b,641d3a44,c59c6f93,ec28a541,486e041e)}+#elif (COMB_BLOCKS == 11) && (COMB_TEETH == 6) && (COMB_SPACING == 4)+{S(629bee58,a391595f,eb20c534,4933937a,cdb2eba1,86d49f8b,845c1b5f,4ca87182,8dae4162,73c6c068,2e2aede4,76efa86b,7612c07e,f72070d0,dc4486f1,47e95085),+S(6fd5e13c,a94b874b,28cd574b,726efdbf,143ab108,1089b846,7b5b2ebe,6c6a3c8f,4a4db306,52c9772a,868b2859,57c5a005,d83f6afa,6e65d87c,700da998,ce651396),+S(609b6576,191514f4,83f5b428,500cfbaf,96871b8b,3348fe5c,1a131768,bb266b6f,90abb9c1,1bf184d2,8dbc424a,bbf74eb8,de4e0582,2ea5dd93,7d1e8b30,e5f695e7),+S(b5ec0263,27cfd922,23a46abf,a755e6fc,547806ea,333666cf,a43865a3,f4ae647,143353c,cc733d02,617f7764,7dc29c65,67a2e245,aed27120,e5fc11b3,95ffb9c9),+S(ac1fff6,cd869ed5,ca920544,1ceb990c,ce304998,10e27587,6536dcd8,1d4cd15,67a7a012,3e5ea292,85dedf0a,9f138b80,58a1d23c,2a233c5d,783bec39,b6482126),+S(c1807552,644130a3,f9b8aea0,29fdccdd,59e03e27,ff2cb1f9,9d13cf0d,42da7b13,85e99587,f77a25b0,bc64b882,bd279fa3,5be0262e,c2f5253c,70a43261,bd1fe361),+S(42919187,2b3c6877,c3b91266,79266e49,9fa37a8d,74d094a8,8c4a3638,89c2717c,1e4bd2df,a9757d42,285cca1d,856b49b0,ad481ad,828d826e,8921f744,7e04d6ad),+S(d4b10124,283afe03,4b278e5a,91daf61b,be608417,fc845e1f,9b9f52a5,43659f2,fd070859,75e2bad6,b34e0396,47b81a87,cab9fb,fdba802f,6ae3cc8b,67cc98cb),+S(ec4c2c4c,722a54ae,edc37acd,cb6ac490,3077bdf6,3f2c145c,7eb25e74,87c046aa,327bfe37,d745283b,a385dfd0,8e30b61e,2b4e5499,4432be41,fd3f0d31,c00e9ed7),+S(559e40a7,e151eeeb,46442b86,aaf4922c,12030adf,7279bb2,2bca24c6,67566a05,5483756f,60d26b97,82033592,cec21681,c5b5496a,c47f600,2013e5e5,f2ea82df),+S(c1d2e92,19c0138a,9f0a34fd,acc92f4,eafe13cf,1c004b6a,3175133d,6cc7bf12,8fa653f2,a20c1262,be59c7db,20f12579,b2adb1ff,54d84ebc,e5ad4116,3d2ebc23),+S(1becc6c0,e4861825,576624e4,fa622c01,139d9cb0,50c12062,9b87ae6b,9622245,d8516472,656ea10f,5b23839d,43f64e,85fc727b,faafcb6c,fc9c6e89,bf9c038d),+S(c483c2b3,8ceefd35,a9fa9e7a,da242c,d618cd6c,8b3bcb62,e39d68e,c1effab2,71964aca,9101863a,d7c865f2,41e814ef,3c20face,f46246b6,4a742026,471b2495),+S(3487162e,40c7efa6,92bc827f,9af9121e,af5ac549,b4ab6585,6353d699,a94a3783,f5b29042,28833bd6,e3ce0deb,dc0396ca,42701752,f930f437,d042cab2,8f135c1a),+S(eb3b21fa,f733f15a,b94ee0e4,3378e9b6,47571aff,d69292ad,a1b107c8,ad511d5f,cd95b4ad,b8768858,cb750cbb,4fa64523,6b6fde59,ceb71dd4,73a7fe48,9e5a2304),+S(21c8dd7c,34d3f333,758d1d1b,72748fe0,8695af46,3d0bd9ad,e4a6498d,1d01e9df,634d8671,7b885f36,a54b6691,35c3c026,667f3cb6,f2577701,beb0d3bb,84f07940),+S(608e33b8,14998177,5d78e286,d5c6436f,99623417,4e887da0,a95274a0,d120b57d,5d094ca1,181f8dca,87d1e043,f798bfaa,f1004edf,a470fce0,7ff8b124,328397a5),+S(f77710b4,dbc5f7fb,ac6b015e,956ed26a,6bbfb540,6a931a30,d4215aed,de610c7,7508a762,a7333ca8,ac244d6,47e47647,c62c82d,387d8df6,175fb563,1de83d54),+S(f37040aa,b0347fe,976d5980,cbd83db5,4d8cb90e,7f2d2118,85159911,af769d61,df228dd7,67fa0d5c,d44c3f6d,b09e662b,99faa5c6,688b088d,949ddab1,6f11e42),+S(7bf929f3,25374a1b,a0cbaa50,db47fea2,a5d1e3f9,3c34bddc,ea5c2250,d8252071,8fe2d2bf,b23a6755,50f16760,a6511ae8,4e4d316c,45d7cd62,4411ad3f,c72805c),+S(261bc0f3,a69d636a,b82248,6132bf91,2ab7ca95,e9a4925,b3f68bb4,745ee63a,68f52f7,df1ec349,77856c74,7b280907,cb3d456f,988ff7a7,225c4ace,8457a804),+S(60ef138d,e7086d09,711defff,68dad211,88d7f878,d616efb6,dbd3d498,5b730243,ca7c3297,3c56b178,b0cfb8a,da98748a,c3d06cc0,7fe050d7,3a6a9695,52500f8e),+S(8bfef3d6,4be90cac,8b83bf20,906b4277,75a6d982,23d5141f,b74e3851,50bc5eec,ea8b6b4c,c7c8d9ba,809ca811,3621c72c,b82006d7,81ff5f25,32010fc9,57858324),+S(9ca85f3d,4ba47ab0,e9fc0a28,74cd10a4,a8ba9aeb,ff319405,6140fea9,6e395ff3,41182ce8,96554f45,93768fc3,a656981e,69719f05,5469f9e4,ba79de22,bcfe8a8e),+S(38cd0c79,437b1299,9567999a,f54d4f8e,82a6354c,8a93a5ef,56ca2ff5,8a1ce180,c96f5ed,d78de5,9f560716,82b60b13,f06de5f9,49206258,80544bfc,73dfa76a),+S(be37e05b,9369b159,6b390290,3eb8fa0f,f221f599,1270c5f0,47edf62e,a1d0e6e2,4fc860a7,1fa69a27,fbefd8c0,906fc68f,4713fa2a,b37aaa2a,7edd3c8c,d100963c),+S(aa640e99,b091512f,85faed73,a3ac8ede,ee120513,b661f812,9a046a74,d624aaaf,dfb48ad1,a01fd508,e5652406,b681cc9e,13d0d600,68411dae,72d68061,6f6b94ff),+S(d08bb931,f008a1a7,38a16200,9fbf1ab3,d3d455dd,47f45cd6,617e81,8b8e0245,18d92218,21c9a2ed,bcaa5d26,2b7aba18,1f7f1e,7f2007a9,ec6f7d18,f038d723),+S(4e6ed1f6,c39c894f,eaa53e1c,e115fda,75fecf8a,55794628,d9a2202a,9dd5c719,1bb97d73,2e0e137c,e9c94d4c,763f9a6d,e1496548,904460d,df1c3a2f,73b66c1e),+S(867e83ae,610a24bf,401119d,8e1af6dd,414a7161,52b2ffdc,50f71f77,2fa8409c,d5d21ad5,ef365994,b3ad0533,92df82a5,6f677cb3,8500781b,a769dd50,1f6d235),+S(6031361c,6dffc505,dc7e1887,bc75c1d9,5a9db023,8b7240e4,c254f855,b35686fa,b9a9a979,c6b8c576,11eeb783,8b4ac2ae,66506bb0,a203fdf6,3efa9b59,98c7643d),+S(8502d0f,34684503,68784822,f4510c5c,562ad30f,be29a792,f0667e83,b6f95773,cd0e6511,763674b5,57fac9f1,bb62f9e2,3163a0a4,cf08cd52,a6d10064,d8b02ade)},+{S(840e41bf,13203a96,f41ea041,1ec034fd,db0dac3d,53b6bbc9,4f8a3a78,d0371235,71b51550,a79af319,56c9b3de,fcb167d0,c3e318eb,a852eedc,78490dc5,fdaaca85),+S(5678a034,a24a1607,d78036b2,23eaa3c3,845c9f9e,7293f656,7390354,2f714d5f,57f624be,ff5d1774,c6962dd4,d14cc565,acae170c,7aaf8c6d,b0552daf,e3bdf48c),+S(722012a5,57ed9c9f,9d737a87,39954469,ca12ab29,9dedbaca,507c1259,7a27c6f1,6c28881e,a0e62453,80d73a7f,499f05a4,d9a9c04f,c2ba11e6,9fdd0b6,7c5d5ee4),+S(70c638d9,3eeab892,8bccf1e4,82368eac,a03ca8f1,b30f7b2d,34258539,8c95c014,f8635082,3dc2a200,67dfb293,891929cf,18a810f2,5c85c169,159a4b44,b190a029),+S(2ce4a530,b5f6c77d,c0c4d891,6e89b24b,c25c04c2,723842d4,29300f82,5e260458,6f306154,4d1195ea,98b972e,91a962e2,95a2a4eb,9be03949,a789b01c,f61dd705),+S(89e71182,851bb441,c0af4e31,cad89dc7,3947369b,fef12eb6,b1dfa71a,72498c51,20b7ffd5,878718c2,2b5bfdc,ac422794,63aac0da,4bcdec2a,8f3b538e,3a9f574d),+S(f01f06b8,da0ba34c,e1045e83,adb95fbe,b76f134b,35235539,6b07f8de,9dd25869,afa0fb5b,45ad1f24,73460f17,5ff4bfd8,f162262,65c423fd,ebd92bc1,72f3aa7b),+S(f0c217c8,1dda2201,1f46648a,e096906d,71fba006,1b4dfdb9,85dfe59c,9d8f1894,d5ddd6b7,bdf2a6f6,cba166ae,4c01c60,b012c9ee,ad954a46,6f631f9f,928b3fc),+S(bd9acff2,87cc2a2b,396aef61,b0937a49,c43a2366,a2c3c461,c1283987,a7b6f53,828de0ad,b9067b2d,8f8fefe6,ce3a5c94,e7d63ea1,7c891d2c,5f266e8c,a5fac116),+S(ee314d97,2b9c10a4,fec9f8d,ccab0015,d4923e52,d915eae8,b319911c,7a8fe379,82057aef,ff05c496,ba8b4753,c4e57832,aba9a724,adf70a9f,1b3765ef,952ab52),+S(d39fa7b,9b87ee2a,aa32454a,13470406,c8024c39,cf387143,3364de62,cb94c103,5cf1309,530f9e09,c9b38ad9,3a778ec5,533f60f6,4a42e31,1cd97c2f,c984b9cc),+S(5ab1a07e,5f6aff68,16780e5a,23c9faff,b29cd7d7,5bfb8984,4834fb6b,c6b34a14,deac47fd,6567023e,b5ec7a94,a0133bbf,158c0425,c0a6d288,23558986,314d54bd),+S(b1a4ecc6,94bb5212,98e80464,cffacd32,331ebc7c,4d545141,a129b522,a4818830,9772044f,3722ec57,d76a049b,2afce2b6,319f0bbc,b17c7f06,175a288f,3ce3534d),+S(56015e42,81aed744,a0859e29,eb913a7c,b44ebd39,2ed8c0b7,1eb42f9c,9c93c8ba,8f973650,45f7d8a9,24a276ac,20056895,fb2b0aaa,4b35468a,a51f41f,722b9d33),+S(7d99a5c5,21543229,c8f9c7b,50dbaa64,b200bf86,47c71b35,a0105dde,2b3a8e0c,eae09ef,3ffdec8b,9a30291c,244c0a72,6466c26d,fe2c8d30,174f57fd,ec6aba60),+S(ab7d21f9,1e7dac68,afd6e4e4,794551d5,55a9f42,59825109,5b25652e,946ebdae,8805a806,710ed7b0,fb99ff30,130c074c,6a0be3d2,abe6e155,f9c07496,f8b92454),+S(b31a5f85,d65e5200,8f5261cd,fd6d36f6,4b2a1f3a,6f08d7b8,defc7e84,21d0f7db,2e6d46c3,3733b3b5,597a133f,7459ee2b,570ba333,4d1e7648,1980dda,1aa8d2d3),+S(30af789e,850c8ef8,9eeb226b,27786679,442a9a0c,35cb7337,98345400,29220fc5,f6651170,c83e24e1,eb6e8da,ffa0b0bb,a6c53676,72558d44,c5b77176,3d9b5d7f),+S(8d87f808,98fb8007,ffd5093a,bc6bad2d,23e09e90,e6967031,48d5418,4c60e0ae,3d14332c,21df527f,a2e98243,d3ed4bd0,6634d799,9f62efd,e8d6c919,8ed716a3),+S(a961c219,eb9ea127,205af30d,909ef732,8cc599a,b2080966,f615796e,1126dd98,3e235ae0,37b10074,32e5cee5,56778856,1d552e3e,bf40bb82,5b527cac,8e1e5b9c),+S(b9c2de21,40cea728,2aec5293,bb77dc7b,550a72c8,84389c05,310651bc,7570f2ea,74171cd9,4a5683b7,5bc7c5d9,b4c8fc10,1fecc3b1,b7349ce,840b6ca4,877fed21),+S(cd041ff2,e8191946,8fd7ef0,c33021d2,9533cd75,64772252,c686f718,7e33166b,3f54a9af,e8597bb,faccbbd2,9280e60,93d31bc5,b366aff2,2c95e21b,fbca6041),+S(adfce0b5,8a9cef85,e690b84a,c7ccc6,8f5aa4de,ada5e265,3720412b,e1f19ae,8ae2dcdb,c6ce83be,825593d6,87f9afbe,a88af079,564c60d5,c9b88898,897515ea),+S(833a50c2,cb5507c6,60bd450e,cde341c9,64f2809a,e400215,c52dfaa0,9825df96,de85e216,493cdb4c,4541f720,201f4c67,1472b6a,d61cf8ea,3cf54ccd,a4584b77),+S(3475027a,628ea423,2d689d70,d45e975d,39d62303,282b16b,1f94a427,3d7ea746,97c3052d,9270df78,6efbd2e7,beaa58cd,f864e28,905e3ab5,507cb9aa,e3c69160),+S(cbda2707,e61d9e40,124668ef,7ed83973,dd293dfd,221396a8,d27e7aa1,392edcb3,fd5023a8,af8eff08,f0e3c8b9,b6a22a99,b3ec3aeb,7e0104dc,1f8409cc,d83d8a02),+S(963722ec,aced2105,2bf447fe,619a8532,dc78816e,2e17a111,3ffc601d,9bec0381,f31feba,259f7d0e,3c326c69,53aae60c,1e0479da,5ca839ea,77c6f1a4,9419172c),+S(fc531e1d,49d2a984,83c861b2,b299b8fd,b26831e0,3bced6da,5c4449b0,18363be7,9f9cc9b0,8d72ced1,998c6329,a17695d9,c94cfc76,ba9f6943,1c5dab83,60f2942),+S(dab255f5,b47d96d8,ec5272b,5cde4ca4,33070920,84aa4866,d53b674a,330aea2,feeda13b,a544f090,b790514a,42064cea,509bb3f3,9dbd4567,6bd75414,37579d7c),+S(ac5b161c,fcc42998,71b49d1f,8cf35bd4,dd6bf98e,5f84f2f6,420bc363,b9cac257,4511d4d3,1fa26d7f,e56f671d,7467bbd0,41358b36,b60775f8,65f7d491,3d17b685),+S(b62fbfcc,2aca0706,b0fe67f4,ed5d96b,4a65b048,f73e8f4c,9782e1ee,36189e31,6549e8c2,f77bc824,4e1a90b4,e42ca64a,5ade1768,a0996d69,8d7b047,7bfbf862),+S(56938443,5e509000,5cf3dd18,ea629078,e15097e9,da7bb5c5,737cfa0a,a40e8818,f86a1815,4f379054,11016994,9b2eba6b,477c32b8,b68091a4,4b14990a,5e8eaf92)},+{S(7c028bd1,75367939,74871a6b,cc957d95,3813331c,87ae606c,17aecbdf,a704ebb4,4fea040b,a0ef0319,91ff9b8b,7829c0c3,93895439,d506c5c3,1a1a3fd9,e32e7e59),+S(24e966d0,bf1227ca,11eb8fd7,8dc5369d,2bb9b681,927990b6,dd02b948,fc18a169,72b7fa7c,f929a6b1,c556a372,4149a279,8d57f504,4b50a1a7,922cfddc,17308ca7),+S(a2b7db3a,265b30aa,94823577,6d5ea839,c4fe564b,97a5e3da,313f7fc4,5de617c5,5e895546,a2778162,4a91ea4e,c104c911,85f3e954,f8378fc2,bea41a3,f1cc9e15),+S(e365c695,449c9976,cb67ede3,325d9229,ee526349,e6b255f7,f4e72184,6722580b,eff99cdf,a0920505,ac37e46,b812d47b,31a29113,e491208,a19e3edb,557ac2e),+S(c3d90905,297c3a65,2c6c3d5d,915cd9c2,d741f472,4a47c8cf,35e5cf3,cac9dd11,8e9ebbd,34a7dd02,24fa6e33,193cdd72,4906dc81,a5aa41ee,4a34d3d0,4b2ee5b3),+S(6e4e23cd,ee4388d6,e8b61f8a,af7678d1,a62b3e1a,3385d278,895a02a,de4c9f00,f69b843b,ae39cf41,11fe9b99,a0287057,5695421e,e1ea690e,2e76d937,e7e32c01),+S(92eb38a6,3743088a,39b58cad,4eb4a27e,a8b08c27,444d704,6d2aa5f4,89713217,22af8d6c,d3567a6d,cf7403ef,e0afea02,48ea4266,1577005a,9afb5f2a,19611864),+S(b3c84323,e2d022fd,d2a80d07,203f4a26,f5d32dae,62842072,9663a994,3a829d08,9a899de,82329d94,83b88e1e,1bce53ed,8714cad4,c68cd491,1b71bc0a,e3839821),+S(daae5199,57a6002,8958b22e,6dbbee20,c4bbd8e1,7ed589e,b8528f35,7a4dbb40,afec8a03,321586ec,ac38e941,7fa8e342,f0542193,59decf5e,56479a39,c32f92af),+S(7afb9a56,89fd1344,cdbc5c72,62dff7b,718c2e47,a6e19ec,665af795,86ed0161,d1c2c9cb,60a191a9,a3db7e20,2ebc2eff,444bbaa8,d81ba086,6f8825f3,8c765f53),+S(8d0c4a2a,e72b54c6,236d997d,61a2a24f,ddbd39c7,ee16f1e7,d7c45b22,b4bfdac8,15a58f4f,fdad9e3f,b4d33c7e,170747cc,6a5abfdd,bfbe5814,ef0c3611,6a0a9e91),+S(24d8c0ca,53400126,347e67f3,72f19298,595b6d33,76ba2f19,2fba6dd1,7b57bda1,7c01404f,bd316814,f10734a1,559049ca,d6f20e90,d6b13ed5,f9542630,db77f9ec),+S(4c2b7a58,87a49df4,f98cfc72,22fdd832,362b8cc4,c5f4fff4,d0a20674,c9749bde,c2a1cfcd,e8636288,31a5c450,fb5cf552,c76e581f,9274e5d9,888a3a68,c37ca349),+S(2028e381,f42cc2f7,a8829308,bb72881e,94e5b54e,3331d848,898ccabc,bf971cb,16debea0,203f0709,d9b55b0d,2b8651b5,cb085d8c,8f56708d,c1fe4d33,a616dfab),+S(d11e0753,f72b7c4e,641ed50f,84dfa24d,a0baea77,98fcf062,8b2696ba,a7ec2529,55af37fe,88324646,777387e5,a9b18059,ace20e9,becd7488,5e43fee5,fa6809e2),+S(72309865,b8a1a6f3,9d6d561f,43ddf5b7,f2d022ed,95df130b,2563eaff,9008a95,f3fca0be,3ce7d9eb,e1648964,58eba87e,934d000b,a535f223,868dae11,dd5230e),+S(adca4785,cbf38a0f,28de7b36,daccc761,89b8b918,f3fafa7b,abbbd9b1,4ed5485f,880d76a6,fbcce864,657edb9b,349f124d,1b22c7af,2b0ff833,40d7a0c4,84b49de0),+S(bb43e0c0,93d58c6f,3946e58e,4727d7e2,d223c84d,513c4e2,222406bc,aafb03c2,c00f7dc8,fcbd55b3,6a95f2f4,a3a07b7f,9599736f,af099a69,e2fc2630,a2aef1d5),+S(179eb588,d1c7aa5a,24e51f5e,6d86e4ed,2e6f0f98,bf956b71,ec1caca1,b7f775cf,42f461c8,a784f643,d5a8682a,6ec9b470,455f0ab9,f269140,b1ad2376,95f64afd),+S(9144fc75,b00f8608,714f027,16b30575,be19dc01,d3689e8d,2665d967,6a077d11,b168c324,7dc6c31e,8302b6df,a2e7c053,dd849538,f9d45b87,14d889ec,cc789704),+S(d6cd2a7a,b7253b86,34231eb3,2793f062,bdf103b2,4fade912,6206e745,a3b429a7,9903e507,dc5e3a61,d73fc83c,5c4ba476,6ae92655,9b208369,bee55948,4bfe444a),+S(264845ed,623bd3f3,808ca51e,517def45,1fbc237b,e47e3ded,70c3769b,391a9f83,cb5022fe,3d535f4d,192e73d8,5d9ede23,78e0824c,e560a97,d53aabdd,f8717377),+S(2df9621c,cf3e67da,54c47ddf,81e3ba7e,7b50e713,cc7d08ac,d64f47e9,85c4f334,8058f6e8,139d8e87,cce4a389,c470e3d8,45da3537,ccead4f3,abbccf42,a5fcc49f),+S(ccfd6c4,c5966144,32d2efc4,1ccfa0eb,3e0b44ed,a4558128,c3e4d68d,949a5cac,bc77b87b,5f50d3a9,6b28d5cf,fb371b4a,36cc1360,15c548b3,f98d661a,beda8acf),+S(4e2e6052,cd35d585,6531fcf1,73bf124d,3c569bf6,6cc54ed6,9a520d42,cb836296,6381d100,e5d9ae50,f1821122,b8e91a5e,f365edee,556fee1c,2fdb6d17,3fd29c65),+S(6603d715,ed0f8725,7d9c3f29,cf86ad4c,aa0500ca,fa16a708,3168e265,b87d0255,9d2eda4a,6195e2c4,a4576e4d,5d02383,a3a01b2c,f94ab8fd,fef2f338,15807d31),+S(f09ef30d,fade81df,2fcafe31,387ed34,5a8029cb,e93fec3b,eaaeb8ac,8adc9803,f9f3039e,5b73c7cc,cf841eb8,1c15203f,ba192e,9eb39aeb,36f56c29,44b286bb),+S(ebf4611f,cb3a44a9,f9d5b00a,c559dbb5,394840c8,41a06496,bbd2011a,2508cc34,1e183324,9a610584,5d62ef4b,685152e5,c75c7525,c703f81,51bdd87c,6fda0d43),+S(31fc3226,c19aea7b,4845ff2a,ddeca6a9,36505a49,92102cb3,499d66f8,a6e1a3b5,49babd41,b1e8a6c,a728f971,d8d8cb76,47cdb94b,89767a67,fd975ac6,93f144d1),+S(be1e37d9,dadc4b4b,7a5ba74d,fb7eb55c,2b0a4fdd,81564f8d,51038afe,f716e3d2,de6f0c3d,b6efc974,975a7d6d,3c6e9d44,a712879e,4e95c612,164273bc,5de1f4b),+S(f8034e14,2425cdce,31e82b49,cde33ba8,3630d1ae,283b8b47,73960539,c67f1652,a302e3b1,860252a5,e7114568,748746ad,1e02c2e4,280bc913,dd4b4d2f,92a561af),+S(21e709bf,369cdb2d,b7f51b10,f0ff56c1,2c1938d6,18419d00,34e57d94,7b83d5e2,d7e09ab1,2e7d04f5,aab3a75f,8cf75876,ddc3cf0d,cb4b9526,ea7f755a,dfe1e495)},+{S(638b6618,c1498946,75a1a943,8755a68,30d7dd3c,9d8a9f20,d65a7161,9c8b477f,e4e66035,e947c73a,c34a48b,b43a3762,d1038e6,893dee23,cf658a12,190d2a56),+S(4b6ce93a,acd4954e,cf0febd1,fc9a965e,ae7fbc1e,e24a12d3,a4b86573,62eb255d,8cea4838,1bdf4e5d,79e25ed0,1aab94b3,5f00267b,3ec7eeb6,63833507,583407b3),+S(e2a42110,3e8e2a80,a6451f71,b348434d,7d508023,beeed16a,d87417b8,5c7b7913,5fc15b62,124014e7,fa8f95cf,78ce8415,d46a1f97,d88be55a,76431786,8de3d605),+S(6949956,91582c2c,2e14576f,5ec0dd37,65133237,a4e43369,633edf69,933d1f75,5ca8c2a6,329882f5,2daf48e2,e291c48d,febbbd29,9ccc9ff,3ad54ed,33ccef43),+S(55d836af,2dd4b8a5,7f20eb57,6886790e,a3ccfcf9,2a2940b3,646f263d,685f62cd,7cc1ffe6,37781c72,d3cc26dd,9d4147c2,183c8e0a,95b87742,52ac47ac,19db266),+S(442a3090,46bbf3ef,503a138,b60ddfa0,ea4a5901,ae801003,f3f18ad9,9703a44e,129d9913,eff78c49,16e67c4c,cb658784,fa47da35,92ea1c98,4054b371,a275639b),+S(76981efa,29944c2d,9463fc94,67a92e1f,9403c287,dd595292,4860aee4,b78626ca,c87cb5c9,ce93ff3c,23189404,cabf8e09,996c4cde,e67935d5,874c705d,6a7f95ae),+S(42ad08fc,2a1eafc3,d793f04e,304831e,c1bae89,c7d00b24,7785d870,904bef5c,c3913fd3,6b8c08c2,553b9c48,5b90221e,ecdc8d02,6d558bc2,5fdd6ba3,df78ed63),+S(4d70ffbe,efc6254d,cee74a89,70244bd3,384b3af5,8510ca61,258fcbf8,f0c82575,ba3e19d,b022a75b,c75cbaea,84ff912b,867124d,a20e0d28,a007fb74,9a9d1c7b),+S(4ec8dca8,7079487c,adfd516,da2df139,5477b524,df4aa6d6,4db5e206,cfb14b9f,e88e5bad,c8654d60,fe1f8f6a,73328209,63bb10cd,31aae381,ea1b4d9c,eaf9cb27),+S(2e5a47c9,a47cbbb5,ef701784,34798a6c,48244df9,dab1e5d8,83c7f732,b89c7d79,7c8202dd,cf7fb6ec,471856d5,830d59e6,99c04377,c553d835,f64cb333,cc405c35),+S(3ca98150,bc5f116a,e7034a07,628d698f,67cbb8d3,74869ab1,534464f5,5e8ed24f,fad702ec,c6b738de,5b653f78,f51c98d2,1e4bad57,4db97730,58324d1e,12b89f9),+S(f414495d,9093ad22,11e001f8,b07b38bd,f5430a11,72899bcc,2c553b55,a9d4a225,bc130e93,998db229,6aef128a,5b8e5b9,9cf67eb7,713aa7d9,9fc4c902,af660f4b),+S(44e794c9,5a28ee80,f9b64193,9c626a78,4a851a4f,84f28887,9eaec508,1b60e508,b219e000,1b07a275,f63dfb3b,e977a40a,f505be1e,d3eb8194,b919b9ea,70d7198a),+S(35024622,bc17bec1,9c352280,297ddf7f,41654c08,61c3744b,13c74ed5,6673b98,64aece4c,3ec0b19c,cdbc06b7,4eb15704,50ff689e,6c5bafb7,6ae99396,12f4cca0),+S(45c4f36c,ac4c4738,ab216363,e12b2475,50b8ef09,7a986ce1,60b0462f,f8725a58,fb944806,dee59834,7d256885,3761e3a,9ae666b,9b0ee095,fea33ec7,bbce9a5f),+S(20a0b4f7,cfb58bd8,d09d008d,70e7f807,b4fa61ff,65f2e15,f00bddeb,55df1124,7961d1de,e98ca40f,4d09e5fc,52ae4916,cafdd6e,2bdb9f9d,2776239c,a3480157),+S(fa10af8c,eb2de4c9,3c0c2cb0,95f95911,755b19d9,90f17e33,69930d6,6002fcd3,68a3bfb4,533bb5f0,54fbf91c,b771b08e,e388a61a,9727bb7f,a3a1f67e,60b2eba7),+S(d417d7dd,30ebe9f1,7d52edd6,c82d91f9,25d5987f,a6f53b0e,d769a34f,e557c11e,ea89c810,619e32f2,369258ae,8ad8a456,cc36d87e,b45a42d3,83956039,62e437c8),+S(349b002d,ecee0e4,1788a3c0,cabb9ff7,c17848e2,78ef8905,63924c55,52d59853,47583a2e,7ff61b9,6fa168b5,1191b363,efa3e0a1,ce825a3c,5bb04e5b,e403b4b0),+S(4b8efc8d,7eeb3554,b5128e8d,ce20c29,697f79cb,29f61b4e,a2f7ac28,57910bb,e3cef657,7b5c0d2f,dee52c96,b6353073,b099fc9c,65688969,24cd744b,981c5ff0),+S(f356e8cf,5785b05e,e99a2b4,d202b64,2b1e98c2,57741e60,7241fb9f,d3f5ea2f,9079fd65,59d5a93f,91370d16,20ba487a,a8c6ad3d,e67f2c83,a1c335,fb5398a2),+S(bfb74aa2,15e5ce36,97cb6156,c2666ef7,1b579a50,56ff60ba,d3d5e10a,7eb2d31f,3def8a80,ddc3f407,e30d11fb,232f0e31,191bba1,d51a7eaf,b86d7f97,45d78dce),+S(658748bc,bbc75ba,30c969fa,371fc1d7,76c32a5c,7e632201,264deb36,b296ad2a,c173fe4b,14ead07c,2c6574c,8887500b,53f6c02e,dbd4048b,e69aab41,9267ef9f),+S(f51a5ca6,fd6dde25,447fa46f,c0984d26,66004c02,8d402624,8886d0d4,604f6ad8,fd4290e1,7b2928aa,f2e03b98,97252b82,d481c4c5,ad4edda6,16dc1cd8,e7ee83b2),+S(20ef1ab3,491b8d0d,a1565e2,8dd92dff,efcb88f,e88c6c2f,6b100b30,b58249b6,6814d32,7b5b94c4,12fb770e,2fc4077f,fa9a336c,9e7db2a4,bc7dffa4,286eee0),+S(d98785a,82dfe5de,343bea0,d91cd8c4,93344b86,7fffe1e6,efd7758a,90cdd899,37ad7f7c,5783d262,5204bac3,4405c207,972b7fb4,cccc3585,ee152f0a,48ee16c4),+S(3885e910,18a66e64,2d3f0c76,bca6dc82,a6916cb,1e46a858,7aff5ea2,d9390689,20765590,83ba89c2,14be9178,46e40553,ea195c49,de203c9,d175296e,a4430819),+S(c88cf650,3b50f5eb,7bac15fe,2097ff76,9c57b983,1b5d05c9,fbd8dc58,d4a9a746,b6443b76,64984192,e7056478,e9f372cb,21a0c7c0,cfcb0e84,850443a0,25ff42b6),+S(2831fddb,2ba2d301,2dedd58,a3f47434,3450985e,80e4e4c1,646745cb,1abc69d4,1b04e1b7,db84b6c4,882f264c,7bba91d5,2256dc97,fdd22e58,483dec32,5020a257),+S(5e492bf,c9d19dcb,c3bcb9a8,b7bec84c,23c359de,a78aa0a1,e0522232,df037abc,614fe5b7,cffedd76,35d371b5,2d89baf0,55af687d,e6c12d80,b221d0b3,9d03d0ac),+S(bbc64d06,681957e9,685c9864,c5f9bfda,34b4dd02,6b749399,a12bd8de,87f311e7,3c525096,dd6b7d11,26c6ca50,5064da63,f7f6a203,87594f4f,e4ae0403,fb4d66b6)},+{S(2b00c7db,16887372,753ab219,17092563,8c603992,f501b07c,9d8442b3,721addf9,8e7c5f66,4c2493ec,77cc74ef,d9221235,f26bd3bd,6f505347,39f0fe19,c41b9fad),+S(56b9a3eb,d9360224,56267f52,21ade9f9,674863ee,4bacb7c9,ef0155ca,b36b336e,2e2b1a4d,f6c150c8,6dcfe9d2,e2836579,f82ac4d4,2f8fa4d5,d814b952,e92da69e),+S(ff52bbc2,83bd15ad,523e6d08,873a8896,9449a1c1,c5ec8570,ed532000,5a92aa3f,dd9c534b,e59d3845,a1943435,1a20513d,1a829424,e65ed8ad,60342b38,6578b21),+S(84f79356,86b0d45a,13a1ce22,7e7c925e,d80be5d9,9fd7e671,270c4c35,7254e9ce,3dfe2058,1e91dc25,12c16951,c667fbe6,83192bf3,3fc0bdec,c760dff6,730f82be),+S(db14da0a,86bcd275,71cb9348,36268bb,85c306c8,9ee1b78b,83c247a1,71c7355d,66ba535e,81e877b4,71b0b75a,6545970d,6e33cbe0,ff011e3f,d653d026,f4fff395),+S(28bfbd9e,44554371,74a4c24a,cc65ef45,5fd4d39e,b466e94,358cef4b,b0eeaa5,5f5ce6de,2925acc9,e503d731,d46601aa,7e668001,669819cf,fa54b3e3,dbb98f32),+S(a7b21a3f,a07b4049,7f9f5087,c763b431,d5f04cd0,e7b7e0dc,f9c6c664,df7c6ac7,daf23f35,b903ecc,af4f50cf,459deac9,85d0d008,3b5afa73,7131a61d,8591bf9c),+S(12fac42a,40935aa,e881894d,245b9691,cd1f6ad0,e0481e1f,444e0ccb,6ee88781,c519e0b9,e3c19fc8,f67c07e4,f357f43d,589ec23c,7714f7a0,4347be96,4ca572fb),+S(5c2e28bc,94f8639e,50133dba,9b6c8a35,348eefdd,2fdbc18f,2abb792,eb8807dd,c546b3c2,5f2809e2,7977a8e2,3a1c3ddf,36229f31,434c90e9,1386ee84,b64e8fdb),+S(e8e73382,fbe8b94e,58bef90b,aeb28305,d27ea48d,9c5f6e08,ef47e4dd,5fad6b78,d3529a2e,86240f06,a63ba03b,ce419c05,24d22622,fab9107d,aaf3016c,6ff7fe3e),+S(26b93629,ebe68d1e,878e94b7,5babd663,6fe1f6f8,659b155a,e10801eb,c2cc51d9,f4630056,b3e532f7,32238911,555c0ffd,f4951c9a,b2f45119,cb12e774,aaa2666),+S(57b3b642,431f793f,24862328,dbd271ae,19d343eb,c3b0ca7c,affe4fcb,319d8d94,1d7ed35a,5abc7e39,1858a9fd,b90f907e,6a065648,c00f94a7,75f06d2b,1cacef1a),+S(c2123794,d98f0311,c1327522,1767236a,6f45cb14,8fcd65d7,e0be8d13,2a650953,d5a382f,fcc2ffba,3917763d,ebe0549d,66f358b,d727c281,288551f8,4ecd193b),+S(16789662,9208b510,7528efd1,36036980,994d6c3e,5b34c69f,ef3b86a4,3db9e8f2,217105f8,39b0ae0e,932b5207,e8e7c190,3ea463c5,40c043aa,e4f8b106,97ccc84b),+S(3a0b8ffc,83a1702e,214adfc3,79bec5a9,753274ef,9e3271ca,8ec5b067,a5f3b6cf,2c3de01b,f27dd574,4496c2a4,75a07e60,71ee60ef,7eaf1c94,c257418b,744d1338),+S(482e5ac2,6477feb7,6c848d58,40173d87,1687c5b7,3b2970ec,b8dd69e9,3393f923,dfb3995a,ca5b54a3,b48e1dc,107023d4,dbd7a918,6adf2af0,61f92160,76e7f78c),+S(3869373d,638a30cb,63177204,bfb194f0,2c6ff503,3cb4ef1f,b146741a,f3b495ed,f2ac9f3a,ca159c7,c2ce9f48,e895c543,d3f19066,74f335b9,efdc4b47,4ccc23c3),+S(98c16ec8,54b34ea2,f08aa4fd,3ce1877d,4a36f2a6,4e673191,17f74e5d,86e57f4e,3448646f,c9aaab0f,4d9ec298,8f7c07ef,448888e7,6318e0ac,552d7cc,b59820a3),+S(1b3a4ebc,8ad1c200,2847e182,de7c9eba,f0f7a408,e2aa172d,484bb9d3,ab897b73,b93decef,69cf2da4,5c3a2373,ac2abd77,311fc1f9,21e7df8,5f5b3504,a5ecbdb4),+S(57b5b2d2,87bec103,e4aa7b96,16129718,64780441,fb5ef847,19f16d,a1c909fe,2c2d983c,d8c37a7d,653716e6,15756121,9e5ad5ab,25664967,67a0fbd8,e8180c71),+S(cd7e277b,ae1498a1,8e7bc00c,2c299a49,69f6862b,bf96e6d9,f5143db8,7b582115,f9548ddf,c27108bb,38f80025,6ffdc25e,28621c17,c370a40e,5009b968,d40660bc),+S(80615f12,82ed7a8f,bdd70890,77c24f18,c03fa395,3cbea7bd,32a26c7c,260102e7,8d54a3a2,83383d6c,a633d17d,e2f4f756,3bcc3826,10cc1012,3f2f192b,e654c2cb),+S(9b16f5dd,c8c8c8d,53786b49,e2d025a6,838f6322,700fe105,7de6d78e,92281a9e,a36aa3c2,f2034285,76f5c570,63bb1bd7,e6e0410,2e1cd2dd,f100a54e,431ca08f),+S(f1d04075,35ffd40f,2a0b59f9,14ecf368,67700c5,b33e15c5,153fa9b1,c724d36c,22a8b48e,4db1d3d1,28cc735f,99db74d9,ba7457cc,67b8fb39,7b38fcbb,153f7c0a),+S(c252ae6b,cb711704,659c37a6,f425b215,1ac8a4c6,63420eba,899127e8,1d8df3b7,8e9a75ab,c5a2cd8c,d44331ea,b07e5d97,a30c6619,8e382261,642c0e10,8f6d46b3),+S(59f6fadb,4a8a3389,999b93d4,cdf1f8f0,4735b397,9fa5397e,64df420b,85876ed5,c6e8baae,fdeb7019,23a68b71,9c88596f,60742a38,db04d7e5,76bd1b8d,1ae25a6b),+S(3c2e03c9,3f610ffd,db519c7,80c201ce,b58ffed8,ee10e21f,d1610e99,33fd08c7,d339d979,38e1c5de,7492e7d2,d64fe34d,ed889d48,54670345,1c51432f,ec6c829),+S(59d16070,f9147ce5,5bac599e,aaace0ef,24c02ea6,85249cc6,ccfbeecb,a4bba83f,8105bf41,47f22f7b,18c73941,3a85ef06,40bf6805,51c68a10,e16be920,193977f),+S(3aca1182,3f31b2b,a12e628b,604b1010,62c45fce,22e15dd0,8b9b5ef9,a53dc02,bdca8ab2,d2dcab6e,3a98e7f8,7e192c19,cae60952,fc6f54bb,d46acb49,60d51c0a),+S(261e9b93,3648c7d8,d5255219,fd0634eb,112e1dd3,fcce0a04,135b2784,e67b5e32,e0eb5ec4,30b1f9ef,2bd10916,b21f4fe1,4cfc80c,2bc179e0,fceb8678,ff933068),+S(75918e0c,a0f03b34,40cd6239,c108bb72,f293a881,a1f2e9a,73c604b8,8c451c39,7f02a925,80e50aa2,5b786d10,422f1d80,2c42cb37,27f09ff1,1f5e0dd9,bf6a6c1c),+S(42025e76,3c05c64c,311a275d,d6f1fb3f,2da2108a,39ed24be,3de83123,b1c1d1e9,dba2eec,7405b67c,a1915b13,45702062,7bfeebb8,6b90dbd4,87849e5a,756921c6)},+{S(ef2c5fa8,b23285e3,50d7f05d,bd8c96bc,6e662824,5b10e1cb,4b659bc5,ded5836f,1b37679e,1177b653,8975790a,4d5d2abe,3626d636,1d863e0e,1db5881e,8e0c54a8),+S(a1d5a92c,93df3c75,a06f9c2b,a604789d,fd487513,62d957be,68c033e8,3e202fe7,64c1c00a,3964fd5,b35fb52,b423b285,77c8d269,bb1ffd16,325c5e0f,7be08bdb),+S(ef13ec66,d46813ce,68038fcd,541e5e8,bdbc970d,337d7b5b,9099d0e4,3fa4288,7ad7f4f0,c8345229,96341248,b1455ebb,89aaeb6e,1ae9db25,1b86930c,9f779fd9),+S(aea7cf4c,afc1079e,e61396b6,2df9bac3,bf334745,54af4678,8621e337,4c7486c7,c0538605,5911c893,459b98b0,4be449f1,2e9f98cf,ef4cc292,9975d42a,f460d65),+S(8f082b3b,6476b4e9,ffb317e6,1fec0cbe,8e389041,1fdc87d6,8d4d26f5,44c2e6e3,eafc2bd0,d6570a7a,cf8bb5d1,6cdc1020,456473c9,e7fec1b7,fc6217cd,89d0a2a1),+S(e0d6310d,e5e664b3,164faddf,39c93676,4ddd3f0d,f5e007ef,5293ee35,980ae0cc,de093cfa,ca1033bf,47e88723,4978758a,74b93cc5,2cef48a3,daf4dda9,adc79ccb),+S(2518110d,5d064422,5ead0e2a,5ac8b8b6,b1fb7fe1,55e351c5,1d39673d,dab0f6a7,84f0d6e4,b497043a,95b6af9d,e72cd502,a7b6a68d,ecaa01b0,9e0d8ff9,9d8a16c9),+S(6dc820b8,5db42353,c97453eb,d7d768cc,af9732d7,c261bc6f,8399caab,34cf5b93,30b168c0,2509e2f7,2035f60,8be8b89d,577b6e72,540f521,934fe980,7412459c),+S(bddc1c75,5bca9911,3c9ae05d,c14441e,2c707fe5,8a329f8d,feaa36ff,12771376,8c0087ca,b7688dcf,5a3cf1a3,3c27c7b9,cee36007,3aeb9b9f,d7088623,af20f62a),+S(b6e5ef5a,a84c6d2c,a209d50e,8fa8e1d7,93c61ed9,bfbc22d5,2ecf293c,9489ac13,f76e3adc,a89cb983,b6b670f9,5a7e774a,c015de5,1ba56417,40ac1f68,e3df377a),+S(26699dfe,93788eb8,d91cb601,cae628e5,75e8468e,73f6cefe,588755b8,c396071c,e5f9e00f,bcf6f1cc,cd39ab13,41cd06b0,ef2e789a,17d761f6,6a7a83b1,c036791f),+S(72f7e16f,77f0a4f7,92db2cd0,354382af,34282dc0,7b8cb290,a89a5d60,894e8090,54d32ecc,2cd022c6,c03f1379,657450b0,db9f08e9,6e2be5ab,5233dd84,62733cf),+S(f84ae7f8,a03b60,af9cc359,36f0ae78,96935b2c,534f852,8ad159bb,6c0b44e7,68f4dfc6,20a354d9,d6904bae,67792622,337e3180,ab340828,80bf04fd,f47cc23b),+S(5dea33b1,b5207880,6debbcbf,83ca17db,4617488c,ac5c6997,ad4092a9,8a7bff7b,99976fe5,ae88d36f,597e16bc,6dbbd4b4,547f4dcd,7e85786c,d10af30e,1d81bbaa),+S(31be76bd,4f946e41,7de73037,ceaa0dd7,c6eccedd,74399e14,2ae6fb2f,d2b59def,54ad8748,ef129085,dc3172aa,904cc376,e203fa69,38783007,2af33889,52cc6549),+S(b6124d0b,f603a00a,22662897,8dd0da87,fcaca5c4,fb04ebaa,81a7d13b,39f2e307,34ce08c7,4463b06c,afb03c02,583288eb,7bfa6f2d,3eedfed4,91e31781,dcff10da),+S(6aa4bd60,90bee70a,295c451c,c8af72bd,3665680f,545f46c0,bf5af990,aab5f43d,9c2364d8,25406b76,94ec9db,a0ea2f9d,bb36fb2c,5bda62a2,bec941c6,874e68f7),+S(f72faef0,e268a7b0,a9b00a57,3674d846,c1f0dcab,c9a586da,be318b1c,d2874d8b,16b3cfda,65db0f3d,1b5274cd,20b1329e,61ea0404,1f702e71,cd98708e,28c9307),+S(1d26df15,98a6b9a8,7c0a6171,767539e1,86d51d1d,cef130da,1001226f,87872c5c,f227cd82,becf5493,e2fc7635,6a37bb48,3e681a19,ab4d9dc7,92edb114,3a7b072e),+S(28690cb1,db697840,13e9eec4,d9388723,4c28451c,cf9dd51a,746d1274,b13b4610,d9bc39ef,19228981,a1ead1f8,94deb254,162fed5d,cbb58a76,6d361e04,3d8f62ea),+S(4b0b5258,22dbc31b,1966b004,4d39c5de,f2e16d5,1e032045,f9973b1e,fe83ca12,2db33ff4,3631fdc3,b3608b40,7dd494f6,ae730212,9619ae35,f6ea08eb,51aded12),+S(a5b4e205,462ae419,8fffc1e7,393d366f,c5a9eea4,e98c67ee,1684d63f,cc09aa64,d3c11017,de4ad175,17cd076f,cf6c0ce0,4d3108ed,60eabdf0,935499f9,4226078b),+S(d4f1af69,2a3e9fee,1f92d892,b14eef6a,a0ec1f4e,d4d455f3,c70bcb19,52fa9837,115c7ee,73b90adf,f142191b,eca0be01,7d5a651f,93e2e90,5a36646e,21790294),+S(c275c715,9d6e9757,d2adef47,2ee53856,dcf067db,bd4f380e,892c9832,708d46b6,70da1cdd,853a0dc8,a6a9043,3c319371,25590c9,5807284c,ae168f65,62e4465e),+S(d2e38b27,83156e2a,a8e4eac0,149bf2bd,bc2918af,1cfa2a23,d1c7136e,15dca7b,738a0fe,751ecfa3,459e005f,72b7461f,a4b5e1ed,736420d2,22c5428e,2ec1348c),+S(f8f5b3d,b3659174,e0149fc6,fa747c22,9607c434,8f9eab60,900bfe92,b23f9a4d,d89eff33,94a093fb,549fece1,4e11028a,614cdce2,21d5ac26,1bc25f32,dca3919c),+S(5e266403,e49fb860,e6ed0928,45bc0811,a214a0e,dcd6174b,290ecca9,3539d862,ab300acf,5d8b8a14,2fc9e93f,ea995d2c,d7a2bdb8,6a146f65,2b8bd49c,4e8dac1e),+S(8ff869a7,60230ba6,aa5adf91,1ba61702,17cbfdc,5ffa4018,b8a09b9e,4088d634,db5a5aae,bdb946db,80e4c207,22ce38c9,4921bf41,47eea510,70e5aac5,c592f32a),+S(f3d39b65,95bd5ab9,aeedc43f,f49bdb20,73a211f4,5ec2c1b7,72226a97,a31c059b,ea41abf,9322d733,bb5971ac,194da6a0,a6d41c6c,a0d0acaf,a53e17bd,dabcdc68),+S(18ba0c34,10169914,7f7589f9,179b94f9,daed92c9,287f3468,d283bdcc,d71cc637,b3512d25,c199d2a4,c115bd11,eb53d6a1,6ef16c3d,97be6291,5ff76b76,890ba675),+S(2cf3354d,7f96c58f,3c6336a0,6fa30c83,8da767af,48f89fc5,5ced5b40,e0b86cee,403ac306,f6c3ad55,be1ee5bc,29cdd46e,2e3d83ac,71050909,5f117d21,7ef015cf),+S(5d31d140,f754d6c,5943deb7,6aa4d867,cac81abd,9911618b,82327795,da8d085f,c25f99d0,5bc5d583,a3a72b41,4e5eac5f,c14ced01,98247ded,79ba482c,882bec49)},+{S(e0ad91c6,6ca95326,d440f44,df91c1cd,cd3ec344,e906d0ef,51fd4a48,31ce293d,3559f3c,e349f7b3,cf66c17b,2c3fe7e6,8ba3804e,438c0816,b68ecfe2,30da18d),+S(d8b8c50c,ae9f285f,d6d9282c,373607d8,5fda59dc,71ba0066,148b378b,37440076,ef83dd08,ddc115cc,24948009,f9eb4afe,dcd65c64,b6ef2194,bb4ddd0f,ece180e6),+S(881fbbf1,a9627bd,369abbc2,edda8026,a61b10f,4161e442,530a5e36,447a0290,6a63cb8f,7e5094d3,c8beba5a,2a1d7b54,bc33005c,efdd5a1b,20d51f74,d00c2fcc),+S(36bc0df,fd1441be,1a4efd6a,43ab9d83,243d44bc,a6e108dc,fa9a79fe,23106f0e,eeec58b7,dc37eedb,4432dcff,4de7f88b,2a0e0721,da2c0a72,eadac4dd,71037ed9),+S(7652c155,c2ca8a23,7680f015,a62c7c31,31682752,a99c4329,77ccfb9d,cb58b03e,5339a51b,36ad4548,197d3018,4bde4428,b38ed983,d624bd18,a5f8c4e7,21871c5),+S(904774bb,fb8b0c12,e2b3f91a,e5a2a0c1,a92971f9,86e29fda,9edc609e,e85b222d,ee843f1,8039e251,9c7b23b3,725ca099,114b4f0,26970111,35ded92b,94445e2d),+S(1c7c82cb,fc14b9b2,cdb3c12c,32df33b6,a08e7af9,df62f310,79fa0710,f28f5f95,93471b5a,17c84eea,a45948df,80c0f56,d8684f35,1aa2ce73,ab84b3c,1b8250a4),+S(bb060f5d,971ce062,427a5630,8f114532,40ec54fe,6479d5e7,9ce81444,27f07927,fcbeaa69,8278eff3,d4dad904,836c0233,40a866b2,d8f66774,70d1159e,201501dd),+S(287c5b8b,8dc168ea,197200ea,97c4f63d,db0b620c,7f30d623,7934f856,a558438a,260630e6,ce310eb0,366acd78,bb58f4ef,27fe4836,edc8ff0f,5d5ff987,b659bd20),+S(7d4c5c6a,d6bb0f0a,47b45a35,1264f4e6,a81ee0b1,65a7e665,4b226c95,feb59dbb,e89691f3,ceb4c57f,5aabc1b7,4acd9aef,41531851,b41ec1c6,608f16a2,2243ab5e),+S(ff806f2b,9eaea4f6,47d85077,d8aa5052,9d4b96d2,1e0b31e0,7c86b14b,73b7ab4f,9acc2f77,a994997c,7a2b1aa0,79c0b5d4,c84f6715,e4a50e33,628b871f,8885ef9),+S(3ce795ba,1d91a9bc,b0260654,3450ced8,c94184dc,8a41ac5,e1b84856,e88927de,3492e696,cd1ab2dd,587d4707,ae34fd67,3ab7902c,d0c0972f,ef419795,1ad88a1),+S(299ad528,afa3f36b,c80a757f,f081a8d,c4a6ddc2,d2b57fbe,1e3d361b,ee5a5d8c,9fe823da,74eda2f,266a8e9b,331d511b,623dcd32,ef9ab7a7,f1d1cb4a,7e6fa65c),+S(bc4b0549,16177aa9,b52b29b7,cb91673c,9ffce4c,7d0066b,e4249383,4467e3b9,55bc6436,7db68687,e699cf6c,f2db9dd8,c2b9a438,8202fef5,11acdce0,ab06f969),+S(a8e8b02c,ff5de02a,9e6652cc,6fbe41cf,6e87ae0a,abb14ac5,a178b3d9,e697d0a1,285d4af9,405b03da,c57c993e,4b40df8e,82c6979,f8de57ce,4543b7ef,3381e0a8),+S(e50aa8b6,d7dcc055,4f406959,b056dac5,21a7842c,ffaf09a1,ac24a3d9,8aef5228,46656395,ee84d061,a9f5788a,cb05975d,5ffa5fae,edced564,1f81b5cd,2491c23f),+S(cb516899,98a214c3,c31e4f2,692cd7d,fad6f1aa,eb8afd1f,b29c23ce,429c224b,2292b8a4,5a89eb80,167238ef,2027f975,98a2aea9,a4460c5,3646d088,82403c63),+S(ded04c06,74c6eb16,557b5bed,4b6703d2,cc37c6aa,bae466e,ee7b5665,6693c3c9,4f3ea70f,8e75b02b,76934cc3,645d2af,eee8e9d0,8d100117,40e8a16c,dbf01113),+S(f3d0a253,edb74436,897e6cc6,621c74e1,30457b41,e0690b6f,7b2a203e,8ccf8ac8,89cb07e0,97495bdf,403490fa,d58eefe3,e79ffa33,1deb5cfd,2c548ec0,8771be67),+S(d4c66267,aa73ed55,bd68fee3,2a166a4a,4ec660fc,4cb13e18,fb6ab0fb,19a5f330,7c2efa2e,4509b221,97589483,40b6c74a,8ee2b5b6,5fbb794,7f838c47,ee03e2f0),+S(dbe9a638,f262f9a4,b3a8955f,22293feb,50ef4b32,20df0184,f363a373,d7110981,4c563e83,5e957756,5e6a8996,97510c67,9561972e,5601c1cb,2f2f789a,c1e0b5dc),+S(70c7c07,1b1e6fd0,a97b55cc,5ee34297,166f4d02,417a796b,eadcfd43,96e1b338,b5c49a6e,2ab03e55,f4755f37,e5211d4b,e23339d9,d464fd28,6781bb29,56db23bb),+S(aabc501c,6d52961a,a613fe66,96f0bacf,fad74fcf,8386cbf8,b18704bc,a1392ffc,cb72ba86,70bc3f7c,85a00d3d,76b11596,6cfa0fc7,44b31e01,9129da9,a5b04b77),+S(47f72ec6,e7820788,f0f7814f,aefd6e2e,af5d90f3,f877677d,ae72569f,c6a2e8f5,6709731b,ef2dd880,4696a6,a0661d13,fe579704,5e0a9bc0,e5fdc0af,789c5830),+S(20026251,d9413e42,47a5884c,209b144c,98e36f7d,8ef3f56a,68efd475,8a2ba8c6,9c5531b6,94ba0d24,a943d0c0,94bb623,75c798ca,c9716181,a9d659af,2acb978c),+S(8dfc6293,9b300c9b,fb617d23,6885f652,424b4f12,d04f8bf1,151d1ccf,935e445d,9a519433,18e94107,5472aa9d,6ec3390,59bd3bcb,bbbf6937,c9290e48,9da25f8f),+S(afef3520,3b558495,6fde0eff,5cfab48d,8fb08806,3c1d7cbe,d7e352c2,9d49176f,a764e6e7,bd0c8fa0,8a6f7f30,aa38d7de,fe71773,fb7ea484,68b3fd9a,8adfd650),+S(354c0a98,1628dfff,8be8ede,ed809db4,bc39c686,39a26828,ff28dd47,90801c46,8ff40299,d607036b,acd7c0ab,66a102ab,38f8d3a8,a271e2a5,20b43cbb,687cce6e),+S(da2e7eb1,1a1e66d9,5001ec4,f7b66c1e,d9f7d0ba,ea3bb326,672b9069,5cf4bebb,cbc1c7da,b9bf7e0c,dea9297c,5f45ad0b,9c4fb093,318b55f6,1e4a8951,726c4021),+S(6f780994,d0662667,8fa74156,4232bafb,b3a7f54b,a5b66507,9df32545,c192c3fb,5f11f0f3,af1a763e,4c9fdcb1,1e5e57a5,6dfe0d0f,f27535b4,4343a312,90e375e3),+S(8e28948c,729c1438,5bd09316,31ed3eb8,7acfc5f4,2a9eb4f8,afa50362,33591cec,2c09fa1c,bf0044eb,a78ae81f,bdbd4271,2a89ffdc,f7d476af,881d29fa,2627f250),+S(4011cf05,a85ef14f,1875cf3f,4f78a51,a52a89bd,a8930a4b,8e13802d,b85f319f,35045b10,45c4f71c,c762fa78,5b8d4daf,aa2a1c07,ba37d82d,ee0592ae,ad807810)},+{S(9089bcb7,1c1559bf,e17f6c0b,91fc098,c63785fa,18a42d69,798b063f,a0930175,de229175,5e4ebf17,1047f79a,37d81b9f,9004a7cf,df747589,7365e174,ae367969),+S(4d1caeb3,41f25459,3b06f715,9e9418df,e29ee076,76c26e6a,51d8add2,5c70a5d1,bf773e4e,4151d17,650aa7ed,1d6a5505,2d622264,75c50f31,3261aea2,cf68dc37),+S(b0760330,517c0d66,2571cfae,830da7fc,a7e0d86c,1ca7f75f,5150f625,db50ad2,d8d10ef3,9c84bc13,32c2cc01,4d4df0fb,45e5c546,1849fb1b,81b7fdd0,7484d35b),+S(3db731e4,273e5b20,2de984c9,74b4112a,d0feebe3,7bb0d2c7,db38c7a,21bd8c67,b425c1d3,46b6a61f,2893a3aa,a243d60f,5563cba2,40018cca,3f80925f,71f4f1b1),+S(3a74a50d,cfbf2ff2,5c99c4d0,1a13a917,9f510c2d,eca1d5a,7ac8fb69,7eb9795,d2b468b6,714681f4,57bc586f,40585c01,e1dc14a1,a42ce887,9ce044d9,ddb92d82),+S(b9139ad5,4f44fed8,4917ad55,c49c23c7,8d62aadc,e83c9ebd,9efde865,cb1eb298,18068856,c80abc3e,2a02a441,bb7a7609,aae8d2d7,8abf4e2e,378fa3d0,a27aa900),+S(bcf5cf94,5887f183,e58a0128,4ed9a4f9,fcf918dd,4e68d70c,5a54eeff,166cb44c,8235f63b,bb06a1a6,d9ad2ae8,47aeb2b3,4838c962,9608943a,93294c6d,e21a3ab9),+S(4b598ce3,a77680c4,c5f66e90,1b76627a,27f35301,9641520f,53ea3894,dcbbd187,357af043,f77cb9fe,c04ce1f4,dd9b610f,9151d15b,3b7383e4,ecc5384a,8ff7c5cd),+S(b588aec9,2dc045e9,a95abd7e,da929837,28b5a7dc,d637001,ce7f0917,1283b16e,e682f53b,5e94fd84,914b7bed,5afc28a,30ae6f53,e12d948b,3c0d88fd,adc5d0e6),+S(eb8f5080,218ac5c3,cd792042,b59e80ed,e3857a75,a81d67e0,7c2221de,d3b7a677,c5f272cc,3734e0f4,6a5cf40,626973ae,1aa76839,1953f211,eb52693d,254a7fc3),+S(87d119ee,65a60dd9,aac3e784,22049cfb,4123d262,ac9e7473,4c9cc418,fb7ce4f0,5185ac,7bcaee8f,f1334eeb,cdf2c39e,83b8b665,1ef9d8f5,48a029c6,464242da),+S(cfd0438b,186d0f5,c64b5f38,a190baf7,35b67512,a439f486,fb79d501,90294683,985edeea,243e9c6b,d9c57cb5,c7372202,7492156f,e10bd2e5,67edd14,8603daf6),+S(52abfb67,5fa8b12f,1b0cf0d,8e85f402,47696662,64c7252f,69562590,839ce4f8,8483ab43,2d4851d7,4f432c0a,8e3863b9,783cff58,3d4c390a,9865d7f7,d1aed67f),+S(52926df,cf12eebd,3008459d,3c91dc1,73532f1d,ce3c5d0a,874ea4c,67331787,18b48fe6,1bd74ac6,4b34f2d0,e7de8920,2c875625,bcad84bd,cb3c81dc,cc86dd87),+S(695e09db,8c4479cf,4c305005,b5737ca0,63f89d02,aced2010,5600d65f,58e26401,32123a91,8bb23fd8,79715cc7,488184b7,53e0eb00,6dbbc95a,ef9d815f,3833c08d),+S(97c35716,e5aac70c,45dcdd45,a5ca0155,5962f09a,cc22c16b,c79ec272,ce1c12d3,93869464,6470f8e3,c0db18b6,2e4378e6,5caa7203,c4d6a079,a10c8182,b8eaec3a),+S(35197cbb,8da9188a,fc60faf9,71cf08fe,73372e15,f857b93b,6afd77e6,bf4db7ed,4e0efeb5,2db601dc,a539c777,14f4aede,c5ff121d,77dbdeee,7f16fb0c,4cfc19af),+S(afb2f842,e0818237,46c294b5,9ae8afd2,279e834f,100f7d1a,58a9551a,98408d49,5bf5ac43,a3609b4f,f058d6dc,6ae09fec,19a19864,6d12096b,6bd3e06d,95d15ae8),+S(a37f6113,882459,b1dc6335,26253a8d,287c9285,b7862721,f9bee74a,d2c4c09b,9ed3252a,303c6d,e01c9985,c5b3edce,1074d478,db56b961,d91fdaf5,1b1d07cd),+S(4579a503,cb12a345,182b28f6,9a3fb98c,4a80579b,2ff592d1,ab18b32d,212098d8,8c61c503,df79dcf2,6083f15b,c3ee1f99,9e1e0960,8bf6af9f,b3175699,cb0e32d5),+S(545031f7,883a2c8e,bd56a405,52719096,4aa1d40d,b22a1730,242f3064,530ce326,ecb024e8,e762b456,f62072e,5f471180,bbc817e7,54e830ee,7757ed7b,df5c9300),+S(b127fb32,bb3e193c,99d232e,d50dcad0,3b45c072,e0d521dd,de72daa9,e20e97b4,b198428,12a344b9,2e8a8d26,f7964c66,82cb3652,66ab3e28,2ba56197,a159f1a),+S(28cb3582,d312cfcc,75ab637d,66c646f7,5157dc74,7a464e9b,933c0820,2326b6cd,a87042b8,510ef9b3,ecf918d,916128e5,f946f43,6f18fd5f,ad62c46c,5882a23c),+S(8a46cb3,27efbeb6,850e3861,c4845ab1,21414f12,9fb27387,4560826d,c9116886,ab09eda1,9156f1f7,194b7b17,fce15268,ba041c96,24765ce,fd964ede,d1f05b3e),+S(b73af914,10ad56f7,d490dc37,1a2584bb,633de0f5,3f00cd0f,6b8a6019,53c7ef16,3dbf4e52,753e5d33,3fd23cc1,c839f278,38eacb3d,5980cba5,bf1be426,b27641a4),+S(b38c1896,427a0108,3f24a917,2a64314c,d9dc1759,60971135,1b2db6f7,d66ab745,d3a71a74,f80d6919,b65629f9,80c7757a,cc49c2aa,78dc67d3,d6f76d06,91a90d85),+S(6f6ac108,aa819a27,6dae862e,276b3ebd,8ed5a3ad,9b0296e0,4f8b65a7,f6a5ac1a,e3048583,7aa2140e,de381363,788d6d95,25a7ee33,9e3a3ed1,2518619b,30d9f71),+S(72f5809c,7c282ab3,4dd81851,33070d85,53999a6f,14fd753f,2ed8deec,ed7adc5b,112bf5fc,8cfd71e1,84ca1967,d05da765,801f12b4,c852768f,60afa7f1,e9576534),+S(4c348833,10f7dd6f,b385ce25,e2d6eef9,8556a59b,5e79a084,ec83425b,37150085,9c4c97e1,be47b073,5209ecf1,5f05cd8a,58ece74c,1b35a92d,96a70287,11d95add),+S(f16e4513,2291b577,ab360b42,c1babcdd,ac61e623,da85819,e9c4c73d,463204b2,5556d7d3,a2d45955,28781d15,16b59aad,941ea356,1b5c88ec,94d09314,555ea64b),+S(3580d3f7,896fb70e,d48d40f8,1b31a72b,51405574,2c2b4369,e3e7dcb,aca4ca22,e38da3af,f409e459,82098305,87aa0eb3,b2339959,75af2e33,501115ce,648360ee),+S(407e63d2,c0cd6d37,84c27734,f7e517fb,4bdf7847,296dc7c,a8714fab,16199828,2dbe5da7,4b29bcc,fe9adabb,69157830,987ac51f,389c6001,2577f298,710025f1)},+{S(f61f644b,e2414c07,66c6caf7,5d32683d,efafb133,cb4d341d,7eb565e8,9f6e4158,2848548f,15a6e7d7,2b2eefc1,1b76e318,15ebb4b2,1e3bb938,e0c2e9d4,5ad4f7d1),+S(5b891f8,ec902550,429a5ea8,33fc29c0,bfdddf6b,a6f62c19,87a14050,a9689a9e,77901539,1ef92985,6d3e3b35,4e4ba2db,3bad967c,dedf331a,c0bff08e,f25f2e99),+S(d8c5a617,62655ffa,c943ba35,3b595b46,88012282,af068e52,d918bbec,46bec87b,9263db7f,6f74aa,df0dbdaa,7e7ccd76,cb3a498b,44de2bd5,f9b23029,2ebc6009),+S(2e940645,cd189edd,2d6cc2f4,f9b49e4d,305cfe8a,46f2a596,fbb55200,89fa5b21,4c197028,e89ef8a5,b5b6cbb1,3733e90,408877fe,7425d58,1f4bd063,ce286fb2),+S(396c3bd0,9c6af07d,123a8441,c9f79ab3,a783b8f3,fdd69dba,ba61c7ec,f65e3098,534c8657,aeb8cdc6,ea34b372,68f1c70,70881797,46b8e335,477c8525,cd17aa8b),+S(c34e6be,b079f3e8,d1355754,4246d2b7,a82d551b,740b4b59,b9220bbb,768796fe,57806a7,653ff7f9,3d7cb6,b3acf68e,aed049c5,75988fa5,f03b1ab5,1103aee8),+S(5d2d6aa5,252fc9b2,55d89773,e920891e,7021f233,5f7d0ff8,c6bde5eb,b65c5149,1fdbd2c5,6b8bd095,2d16c304,8d9c588b,2a26379a,17f748d,f1345695,1c5959c4),+S(dec812f5,745fcbed,fc36c635,76874bc5,96dde8ef,68a8724c,201b6af3,be7c6e2c,1715328a,f75f9661,d58c667e,5c5514d4,c99dc881,8cfbe702,e0c3c8cf,662e6906),+S(32499061,83487250,f65684b9,9434489d,3a83ec93,61531dfe,48086b2e,b2bd18fa,53217af1,2a25fc6f,45555d93,98fe46df,4247d38d,7b162e34,945f8928,bfe148ba),+S(d3e9381d,83f31116,ee161490,c9b5d1e5,7e086c6c,1552160,2c913315,af033ddb,97ae863d,34271b26,a4d6577a,32028c12,f092a54,8a18ae1b,a83de384,3b8fb84),+S(1347dca6,d097faa5,7c6583c1,c292c6b3,ed87b31e,9f7afe8f,d0d151ee,50ebdeb0,570a9be,e4806ee3,e30696c9,71b5d905,65d09ee6,8b4fa8e2,8acc54c0,7fabb492),+S(691f9995,af2bccbb,f556f624,b28a1da0,67854c15,4f014e92,a56a8cdd,9a43c25c,81babe0,ae44984c,bfdfa958,4dc5c677,881d1b0f,63993075,a3fc462d,e986866a),+S(cbfb62c0,b91cedb2,5a9d4b3,ada43cac,7839dd18,33174711,24688ca5,5f162cb,77c12161,e8199410,b040dd57,4d90c39c,2f1b499e,6b7c17c7,fb21438d,aff4e674),+S(53627516,8de62d6,2c792f64,f87996af,3ed8ec88,653532a8,ad60942e,cae4a339,d8449a0c,c6ae32ff,45a11652,97b3d3a0,57e67c64,42d3bdb1,ea2cbcbc,cf0655cc),+S(2a81679,7505601c,763e6f6d,f7ed5c0c,14ee7fbf,d75b8755,7bd57f3b,e2d3c7c,99f26af2,10540397,b8423da2,c4809942,63734d99,f0d642d8,96b5f216,767b759e),+S(54b2c03b,7a7ea964,220a255b,bb688767,99ff1b83,f0934e4f,fd03c2bb,51490e22,b3cc56a9,ada9240a,a3730828,26733090,ace3d7e3,91200d08,2cbfacfc,bcdb9c08),+S(aac88c8b,7c96e629,6f023e5e,8f260324,9f4e645,bd701705,8f38e9f3,a034eb57,da03ca87,b98ab6fb,e4869756,7c2db04b,7f9948d9,ea65d93f,d222d52f,6d48c552),+S(bfdd8394,fb49f93d,630f6b8d,469da38b,105529d6,70b9a1ab,e3196816,d2a13978,39a97919,4249f78e,c336b00e,475722e8,7ca734d4,3d1e97d4,d2aed074,abfacbe9),+S(5b5dc3d8,66ba3647,d2aab2ac,3338abbe,4d1ca08c,6cc6fb26,4335f40d,4dfb2331,3432ba31,46a0f15a,beca45e4,1ded8729,e6a0a49e,70315745,bfcb3388,4e1b9e64),+S(77057b28,a1d139a1,91e05ad,a8d72f3a,c7bbd198,7647070a,b6a21355,7bc0c73c,46f32321,4519afd2,f830cf7d,567aacc9,47ae6b8f,8c841adf,988e39ad,e7b9757b),+S(f6c8d1da,e28a3d23,2a388998,1b638b23,f381618f,18dc81ed,67bfa696,4cf1626f,2ad8c92d,43378941,8d298dc8,2cbf288e,86d21467,ac73c0e3,383ef3e0,a03142fe),+S(b75b5cc3,77a55310,a3b97067,34f1929,fc0db732,3265e6da,71405f37,729d5a90,be077940,4dc94ea3,3cff505c,e1aef457,bc120359,521eae05,1de1963d,b1948053),+S(a66d54d4,4b4d06ea,f141307e,27e1c225,41274eef,5c0b1743,e6398b22,fbaa4068,51b6b8a8,48e1c27f,107f82cd,d0554643,b9e16611,fa93b789,a2199b3e,3bdce296),+S(56b2f9,ab707dde,3479d0ea,baeb62a7,6cb9bf03,66278eed,559e027e,a1ea6b3b,27c47e9d,646684dd,2a54db0f,c245fcdd,721416f7,22ed568b,736e3e1b,f195b379),+S(a9642a49,83b19c3f,f5f63ea2,9e76afbf,a25dd0c0,221b32b7,6e67373,36e7f5db,8ada3766,9207c6b6,a6b6006b,5240a4d6,cdb8b807,c0c16a56,91289b7d,62b3a051),+S(18eef8d,f9e64c1c,548db40,ad77d92b,11f3ac43,60c63792,5f7d598d,7d8d5155,806db24,eefc3a64,c84da338,937811e1,20c6d0e6,9cde79ee,9957a4fe,c53d0e12),+S(d11359fe,61861a36,8b3809cc,c727320e,42905036,774d0e83,98453ac0,68d404b9,d4182ce7,2500637c,8e14b977,34fcad09,f061838d,57c555fa,420fbd50,9abf6b81),+S(7ea072e8,f60ff273,9cad1d8f,c560f208,b54149a2,5748900b,50830e3f,738b2db2,af09e54b,d44feb44,b39956af,fdca6894,91c7c6fd,f029e71b,e780f8f6,77a48a0f),+S(f53406ab,9fb1317,b038dc28,f0165abc,115b37fa,77d23bc9,e51993a7,8a15ba00,a293f429,f7fb281,9cb60b53,b2e6f07,afb6537a,39a18be,a5ad4cfa,55aea13a),+S(b1674e5f,9f194a16,94fd12d1,4b64ac8,bba69432,241aefd9,9a1c49d,23287635,83cb0060,1f5c33be,9436d946,22c3b3ce,68d20733,ee1e2392,8c3d6c14,a7cde085),+S(22b72e08,66b96344,ee53b898,ea725f7a,b5832c12,7c0881ce,862ea945,5eafee85,b886e8e9,cba29b15,be5c22d6,ada99b02,1098be69,d1c500fe,6fd2ef8b,f1ecae25),+S(9b7151af,698a85d,2246c88e,8ffb14a0,c762c2e2,64ab70b7,e30e2434,9b8370b7,fd9c3d89,46ee9d90,e7fb6d26,796062eb,4cb6c160,76df4834,eecd2748,c8a7bb4b)},+{S(5ba26c2d,53b04b63,d260c6cf,392786d9,41a1a7c,b88331c1,149cd3b9,9c207f5c,9c7f6303,bd72850e,d4da618,3427e7f3,eee078,6f67cf9,85d483ef,79c2eab7),+S(f7d26944,6d29f81e,39a44a88,49f12184,b9f42eef,16c5d88f,60c96a28,cf0c3e48,e7ec965e,d0a966a7,45087e09,a058421b,852c8a7c,3790a3ef,7abc6ccc,e17c6084),+S(98590b7d,36bd2ef9,37ce788b,22cab951,d921724b,87c3ad83,8263416f,b5a67dc9,b711c21e,5af72a36,5cc1b220,7ed09ebe,be918555,55e9239a,e9b03d75,c0261d5c),+S(92e1cc4e,5f57514e,9ed13535,5f3e2cda,b0b22f8,8f56a972,a657dba4,7263463d,14d296bd,452f2faa,7d6f42e1,550fe35b,3c47eb2e,fe7636c6,2eef90b2,e7822da8),+S(33de9b1b,e153bdd6,efaf9d1a,30aa9b3d,faf26a32,4486b6aa,ecb1f958,f11c4673,7ef29223,4d3a565b,c0f0e295,deffa3c9,a86a6bf1,933a084f,9334b790,51eb0270),+S(f9fad0b7,e1dfd4b2,47cd2cbe,bd863e1,95b3be25,6cf7a707,5d422b9b,f5631ca6,fd5262f9,e6ca0cee,e1c7e531,83d9f3c0,7ac518b,c024681b,56c06a1d,1826f5ef),+S(455ec5ea,f34c02c6,961469ed,27bc7883,c07c9a18,663e22ca,83830a66,569b2b36,4dbf1b57,a7de2fdd,7c0380c2,b38fa5d3,697a5995,8ca0c0f7,6405244d,bff4c9),+S(940fa05,d96fb400,bac8fa39,e696c536,71a490d7,c98b3851,ef76ed35,c62bac19,b6de17b4,1a045978,5755497f,1c2a953f,17554b4,20f2ccaa,9fcfedf3,5afb9b46),+S(16012402,4ded6478,72374af4,6daf9c2d,a9000841,9a7d4672,98b627c2,420981b,7c2607e0,a4b86f7a,d5df7371,60987d21,35d2ce2d,bc422ab9,b643d080,26f84323),+S(caf887e3,339046ff,42c629ff,c954873,2c629ecf,319c44be,6701a9f7,c81bf842,d253a688,3b3d51c5,a914ffb7,46e7ab68,70c2b1ab,5b7e46c1,7a5119e8,4ab6c878),+S(41a5b720,595bfc66,18406547,d59ec09b,4efba0ec,5bbd3191,9e9256ce,f40a7afb,87ee1be5,2233ba8c,82dc06a3,6fd0a1b,4ee8d7d3,ce89cb56,1dc96c19,dad79613),+S(8bdcbe80,fe8533a,174045a8,3cf9d89a,ca438ef0,8f6393cf,6e24d923,edb02586,8d21379f,c053e8dc,c628f0cb,83a7782c,b4e946e3,ca88d467,36232762,fc6f8fdf),+S(409a4482,6b6f0ff6,36178d65,aedd64cd,2d28b39f,3e9cd93d,a0afe712,b75fcd19,25a3bec4,74216dae,d686825b,bee6aac,487a6d07,606e5aed,7c3032df,f4911eba),+S(b7f414a8,4c0af927,64ed5b52,e96dad38,6995771c,2cd90af1,1986bdc3,cbeb61c0,702b0a68,4e93f0a6,26b807d8,8049db6a,3e65001a,d75a476c,e4be230,89574e8e),+S(58b0cdd7,bed4f327,bcecd493,d835c0f0,e45f6fa4,3687d1d2,f19de285,5bcb5c11,21b0a478,2c1d14db,9c67817d,7b23db21,a96e456e,62a85c3f,2a02c76d,78dcad10),+S(c75cbf00,893447ba,5b3f8462,9d6897ff,64be841a,9a6bb714,54adb849,8df03900,15f68903,ae20ae4b,9b3fc7c4,f8135936,c09de15,18317dde,bcf66190,2db79f72),+S(e6258fd4,b63be23f,38361a16,cf3f81cf,f2d7343e,515b2d0c,ea0bfe38,6d4400a9,aedca212,9b73e49b,9757cd7d,a39a1e92,f885b267,a188521b,32089ae7,6d351eb0),+S(7c61b66d,d76f759f,be92708,8b075147,2ba10db2,eee4f0a4,2eac1ad0,d2dac3a6,c2b79de,70372e1a,6c9449af,2612e34a,8e101cc2,81ef378b,97cd77aa,bff004af),+S(29c71194,bbe41f4e,b2f58bf5,799616c3,7b247283,c993bce4,630929d7,55f7c8c4,c0fb083f,d68f63d3,599c2da,9d0c1f03,b6903545,a47581ff,3caecbf4,359e0235),+S(f1cd983,5bd3eb61,f8207495,48da075b,ff4191ff,d5b1521a,a1f4413f,2173a68e,beac8102,13b643a9,4658cdbc,71713894,39b72abc,f8644697,2fe6310b,4ff0233f),+S(94f2137a,ae170855,3af3dd45,8f8fc9d3,c1bf07e4,35a62798,25d5b93a,37380144,e952d6af,b27f9b2b,80ccbe89,59fb8b15,5fe1b2db,f3ffbf14,cf9c1fe9,b8e8209d),+S(f4f0cd2,e28cb8a1,9b469b18,90033912,4a40a39e,67ae1642,a3a677b9,fa1a9a3c,75412f04,5c41770d,73d7cd77,bce0da96,1e6fc69,cfc6cb9,8f691d43,dce1e548),+S(15ba2fd,b652ea98,f2b326ee,e5e1629b,ec8f8e7a,36078d7,cb8a80c8,c943e98a,db416844,cf757376,cfcd5a9a,9a318b51,184f8c89,fcda3d97,e735c120,43d47c35),+S(5754903c,ffa8cb6a,3ffe3488,e484c498,69163b77,7c07183e,8d2da037,78b8da34,508312e,6c2fd008,fac12bd,afdf8e50,1940a81b,d05efd38,5277a85c,ccf125da),+S(3bc76f6b,8abc155a,dbba76a1,9c0fef85,373bb1bc,9775f431,1b3ccb12,9c7fb29c,48036702,aea467ec,daa8b809,97c41c07,9e38c414,f798bdc3,a531b08b,fb4ae303),+S(2992c410,306d3d40,313ef69c,a2e3383,88f592d4,a9c2bd36,ebd9f51e,883aa33,cdecc5df,41cd193a,ecb26700,baa42486,a0506372,d56de3e2,2fa09156,7b525519),+S(baa7d83d,6d70a528,e6392adb,b2af797c,72772b92,ace96a25,90d65c37,b0ff1bc,9943b555,4e44b480,28815d8b,e50189d3,6617e9b6,c8f07393,8309e04c,9978fad7),+S(935488ea,4c88c2e3,cda6c0ab,5b42d519,e7fabe09,fdd3e36a,7c78c9bd,730612fe,705c8f8b,228be0c5,539eae13,1f4f4bdc,2fecf6ce,6cc567c4,dc692af9,7c1d506d),+S(8edeb68d,e63c35e2,5e36bc8,61445a63,8b0637ab,d14557bc,f0b0648b,db43f86a,d20bd0ec,14ef4f35,68954130,6577ef85,baeeeed1,c1004130,80687a5a,94a9e9a3),+S(9a39617a,27c2ff2d,9869acff,b22fad1e,a7d04271,be154547,43234f54,7f21924b,917bf9f3,fe0563a9,8daacf90,dfdcd8eb,e657f023,3fb15711,79bc5ce6,e6f5dd56),+S(41dcb02d,21137ea3,a179b469,199f9ed7,9b831923,68719a4e,5c727ce0,d42e95d,4669d53,82147266,8327cd6b,31c21b80,d3394bf7,fa29a43c,2ed7441,d866f5e1),+S(d4e3e3cc,387e0364,6688a62d,9390d585,a69ff43e,1060811,431dea8,d868355e,3309af2c,b3d7ca6,55334f2e,c53de6aa,debf5d57,1618ecc2,9dc9830f,ec46144a)},+{S(90edfd0,61871350,b7f1f029,c4114190,b050065b,2030a400,9a8a7a6f,4b92aae8,872d4f07,5f60ae2d,dcec2f12,98a22da2,53d54de4,fde85560,690dde89,1628db56),+S(27e3ce53,b4258f97,a499f408,ecab24f0,60aabae1,dafe992e,5a34952d,5e6e486,d393fad2,9be684f4,7ecec306,332ad969,75b79d29,b5863d98,5f959c4c,b8ffb442),+S(420f1078,27c75c95,d5bc657b,a46cbe2b,415a7d42,ad62cdf1,6c84ee89,22215379,8b257a28,e0b15fcc,ae0b555a,cdadf4a,be93bbb3,a208ee45,77710a9e,d58da7fa),+S(28859abc,b60a95e6,b26c0996,566bf798,60c1a194,2d3342f7,9655f286,32f9d5df,2a770426,5eeca5d8,87840cab,3923d868,aa7b7b18,f9d19941,738ca006,54ccba6b),+S(c33c317b,490e2266,2649a021,e87f6596,3897633c,90be208a,193f1d52,28614059,af850be0,d18708bf,d0e1f523,c1a4fda8,9a6c156a,55f82518,2bd99bb9,b999a358),+S(2333793d,b961d3d6,740fc725,6cf9d833,81b5dc92,85b6d83c,5c343aa8,5baea83b,accc199a,ced3012f,b6db99c4,7a36c30a,f88e7eee,b62c2ed4,1352b488,ba0167bd),+S(4834aa89,caa9c25,a99ee4da,e4a64c15,25a5d74f,9ce573ab,ff44b63f,c3a578aa,fb189539,448a265b,eb87a268,b71a18db,f12fe8ac,e502720,c83ca156,c1cc7a39),+S(432cc05f,c78b0d56,e605391f,e4708bda,a1ff3edc,96a729ca,aad3cb0,300c4d4d,6675d8ee,ece8c078,e1bad373,247ce383,d4c65519,4a6aed20,a7ca5eca,34a89c30),+S(874fda6c,b284ca2d,a216bbda,28249388,88da3968,7f615ab,52c8e61f,b72a1fd,2d7199e2,b0b88f45,18e6eeb1,240b2ffd,a9bfcee4,6f754a4a,3db7959,dfe857e6),+S(7fe21a0f,3ef67d60,1de05f67,2b163285,a5577948,ee78274b,19fc35cf,2d2f6801,62fb2ade,5e2fffe1,28542038,91a6ea73,aabfa35b,1f7fb000,95190adc,de6663f6),+S(cd0540e9,efe497b6,2beb2227,a2da819,a1ac3bed,8eae24c2,6e2991c0,a707dd69,446c3218,7d0c9229,d65dad2,1392e4a1,66445386,4a5c1620,bf768fad,20a45c06),+S(a533c295,74e78024,52218573,66c30001,6159d772,f5bedcff,28d7f7cc,3051457,b61a106e,e0166d54,5e1b945a,f3e4e285,31a34cb8,56a34dd0,cd21184a,9555eeee),+S(5e144f44,ed88845a,c089331c,eb58811e,4c164e02,5d1758ee,51a7a522,c66deb30,ff95cab7,597cf62f,e1aa8df8,a2cd3844,d71ab4dd,4eb02a9e,6175077d,261e2540),+S(97487a40,9562ee2,7620fc2b,c5bd55ac,6509d487,8ab41257,53884b97,7c5a84be,e52a282,1430c540,5f1143d0,62b69faa,16592f02,cb9b8602,d52c9fc3,70769091),+S(906f9ac1,d3db4690,d74771b7,f1940679,b0de7731,a68d7d35,89caae34,c3760eea,6f2be7,2275dd5,1e77a066,b8d3c303,f565cb97,b8fb0dd3,14445d18,876665a6),+S(4c355a31,d17617f3,5d4066c7,a125b2bf,1d6f77e6,27b585ba,2d271a29,a88c81b1,6a686e69,237b75a1,a1ecb86f,b715e858,35aa0686,e2ef10bb,38b762ca,5646e9db),+S(15aac1a8,9b6b7629,57375d4e,aad87c9d,e1fc2617,89e57d29,731fe96c,1380140c,2968c0b2,2c3dd83f,3286d37a,639bcc14,3d89e75f,cac1da56,7e07799a,62af1008),+S(4642f29b,37b87118,65767998,d00b41b9,fca6718d,bfc55785,1c459efc,2ea15037,a1ded31c,be33cc1,425df851,998ddd11,1518ed13,f84756c1,c7cc46cf,3f5e9a72),+S(9554abe,9e092bd2,c4ff46a0,abd0b7c7,fb73d85f,1c01fd96,83146559,306ea727,89e2c07d,db1fe6b0,9872ce91,66ce9ca8,1124986c,c7e48e09,f80aa3cd,70987711),+S(1c0977a,a773c56,2e36dd15,58b95fff,d35b4dea,ac464011,ad7b79cd,26227238,e04ce4c5,b0b165e9,87dfef97,d32094ea,3e86e6dc,33a4c96f,c9470336,34b0db68),+S(71d44171,60361c39,6295e5cf,b1540ef2,1ca046b5,98645a23,e8c9772,ac21be4f,7122d5b,32a654a0,1476a47f,d3317a25,ed51536,4a21253,f4068dc8,14660c55),+S(d906f59b,4d56bc12,f26d60e6,6fc31733,e5450707,89025ea3,8a6193c8,520ddbc7,cd7f414b,c6cc79aa,4c65b943,ff914234,a9d85cf1,9853be59,2a71fe1d,dbb20163),+S(11b7dfb3,17dd5c23,6b8084d4,f3cc157f,c25c0e70,8248b472,240963dd,9a3fbca7,dd2c8caa,2a2d14d7,fbec267c,9fe87ab2,8b1ddd92,dd100449,f75ef1da,97d4e5e),+S(3ef8274a,fca8fbb3,1894d7a2,d1ad59a9,4951b21,328b1e84,ecaa6df9,cc1ef473,2e4f0c04,f5da671d,4a2b641,46ae749,27bc35b5,98a54190,3883469b,3e7874de),+S(a861fc27,f5e6300d,ec0fbf6c,3315d053,98f90b84,2422992,bdfba11b,1c1c7e34,75a7458,5d98bca4,e3517897,afef848,8e524168,a586d8da,18834171,4b51846b),+S(9537019f,57d7869,2a358758,47e885bd,1594a426,4412c595,62eea9ba,4ab34de8,21bfd84e,a66650dd,79cc8c13,7217a351,57b9c046,938f20b7,246362c8,6637d5f4),+S(71c80c38,b1889d4f,507132a1,87af0c91,79994b84,1b816c8a,6d130a,df1b500f,8de1f76c,100e75b5,1572da6,d08c76b2,10cdc447,cf903e0e,2b00e002,5dee0ce2),+S(2fa9ce2f,59865d10,17880d74,d31cd446,5c28ff56,50f29e6b,d74a810,977ef9ec,6c5a2073,55c0dd3a,b994778a,6bd02b87,80ba8e1a,899330ee,cd8781b7,6e15cddc),+S(96ca6bb4,bf74c748,75703386,ae02dc29,13329d9e,a5395892,df1c6f57,4a84fa4a,fcb510b6,dcfe8da5,690f8fc9,4dea8ac0,e42af209,35c33347,b088cc79,52e98b1d),+S(36a066ae,694f2645,25cba884,956ebd46,ae568acf,11664965,63cee00d,a32f2199,5d1e975a,856ebd1a,cb1fe254,101e89ab,ea089e8a,b38bbd0f,1100e914,709fd965),+S(4922879f,800234c9,63f4b572,d236843,4c4da5c8,ff741982,c3d1e341,841d1309,9b259470,24b5f4cb,97c68d18,f7f8dfca,1e57f7de,63208765,2ce15770,98f35494),+S(ee27e2b,acf95f6d,dbb5ebae,bbf181bb,43322a3d,6db87e78,14e57a3d,41b581e0,3d6a18a,daf69ae4,88ecc9d8,7d6b1bf2,c8d65544,3f4b45b4,c5a0ac51,7b1dc3ca)}+#elif (COMB_BLOCKS == 43) && (COMB_TEETH == 6) && (COMB_SPACING == 1)+{S(e3adcb1a,fe947e6e,7cc4f5a2,df78310a,b235e2c3,bcd75eba,1904de80,c8814c50,e0b27ead,c4bbb9d2,37dad580,6e366674,4a9f9c3d,e024f2bd,1edb11d2,fafc0a22),+S(612c2ec6,f0e9c4ec,c2200d23,ddca77eb,d003be35,61e52b1,890bf846,3bb53ea5,9e944d7b,dfc7a952,c1c5ee15,485d7199,dda19551,2d729628,c215a9e0,285f656a),+S(42053dc0,9f90a7f7,86feca60,d68a5c3c,789e44d2,3479aa13,2d1a427c,621373a3,b338f891,f3930ec7,738669bb,3a29ae2d,637be08a,954f2a8c,acb661af,a660bd22),+S(4d227ea1,5194ed57,10f8ea4d,a639be04,fa68ecb4,f3d2d9c9,43ec32f2,80f74051,28a94075,bda4c195,40c20493,b5391df7,166b1264,b957fef9,683cfbec,4c6e6875),+S(8ec4abf4,d4db3b0,2b0712dc,ef54a405,54b6cac9,3f88fa9d,d8cad4c0,9b94eb1e,4e37e159,517346ee,17e948c4,a17912b0,b29c303e,497cfb38,16796752,99aaf9e8),+S(ab186398,117fb83d,db8b9392,cc888fe2,50d2f604,5a0c3f89,92d8a82c,382175c0,79437224,b3b1604c,fae64902,e3030448,51ef17b8,9af02d7c,54a92c34,7fa2abda),+S(2bd09ae7,1e8d85a2,ba550bf2,9c1787a2,3d2c8985,e2ed07bd,1d39e7b9,8ef8135,ddaebb19,195bfd6c,a44ce82f,b7f3c65a,8af935ae,52e2d2fb,33cc231d,c4b16082),+S(e6da6560,c8265e7c,8f62edca,78dc739b,74bd6543,44a939cd,bac0f489,12b920af,147f5ce4,a98377cb,981dfaf0,1a1e4740,238f1c5d,ee69cfff,a54f3aeb,e53980eb),+S(7df5abfa,d6b46a37,30bd5892,69edb6fa,b70a0d31,936c0787,407d5d6,96506263,bc5cbafd,1f5fee67,1aa449ff,bacefc67,cf7c529f,86100d7c,a8160e4c,376c76d4),+S(ad672823,cfe3ac01,50038d30,81a1a109,d8629b4a,a4e26779,373ee0db,44a466d9,c288397c,f91157e6,770c401e,dc84b328,87b22534,d11e11c,c8415a4b,743fef9b),+S(72032cac,3177c280,ceb3076d,7f510405,2413706c,956ecf38,acf410ad,a12473a6,8bbaf50b,95797824,2994e6d0,a4bf6d07,149792bf,f2a74847,1095f845,bb332036),+S(36a1f78c,3bebf8c7,1fae5e29,cf08485d,d9debdae,348a20,ad84ba5d,4308fec9,842f57e2,e900d07b,eefda7e5,9dc40139,c5deefcf,11c07c42,4629c59d,593e01af),+S(5f418454,72e80d51,1c1b8bc2,b6b89224,9119ed43,5b915809,f7b26d01,8427f579,dfc29fdc,f3c65221,a6615262,cebd9a14,acba91ba,cca22ec5,d84303cc,1fe0085e),+S(5577ced2,f6bf41f9,503aa4a7,c0060fae,6d33cda6,e3c8ec55,1eaec315,bb91fedb,858ded64,6c3d6231,87c0967a,84ee5253,2b21c4e5,b329bdbb,76f6a6d4,93cdcb4b),+S(bc74b56a,c94ef36f,2b356bc5,dfd11d2e,7a371087,653ad607,dbfcfeb8,27abc502,d57d74e7,39e758ee,96a422e2,f1fa61f7,4f6308f5,71e6dca6,3b0b0103,e83cf1f3),+S(727ed91f,be4c5086,50a0d365,b28ae4aa,c9434c0,735fce3c,7b3ebb42,f4be911a,8c595547,5e627c22,6bfa855a,22ebbc56,d3d0b331,9120d8e9,13bed868,7d3bf331),+S(6286bb90,71f8887b,c4fbb3f0,a9ecb19e,fcdd2cf1,5e286da7,1bb60c9b,5ff5e644,73731ec5,ea3e537c,c6060ac5,dde716b7,2aef4117,ba747b12,1c26fc9,eddbda74),+S(3905682b,72282a78,2b8d8dba,72cf147a,de0025dc,a21521e1,ea989040,c248852b,5da3bf52,dceaa14a,a3534068,c05bb015,2cf9c722,cc80c56,cf828ace,d96fc390),+S(561a2ccd,ca12b67f,dad28ee2,c3cee78a,cf811766,9e4a2543,c81b1ca6,eb4bd16e,3b386a9d,553c2746,893477f5,17a05e99,bbc8ddf0,896249e3,85e406d6,a57b9ed9),+S(75bdfa06,6a1a42a7,50f283e8,3ec91cc0,a5b68829,6e6aa24a,28a61e33,65f378e5,c73224ec,797d6736,c1a541ab,34523d91,e1ec3754,fe7fed44,474f9cba,29f305e5),+S(e881a840,847aa2e2,2417cd3d,3e798c56,1e630290,5dff6bf7,754d9419,98d401e3,8816d775,f1555452,f624e45,710a240e,90fc5e23,7536d217,cf555349,b5e31bac),+S(1fb527e9,4e9c70e8,657de745,8b81ef9e,e3c2b4e0,128a675b,f7e28980,e18b201e,bab00a09,1145407e,693d5353,7818bd30,49e1f364,757d228,58b8aac5,416e3e78),+S(1c2bd878,b94169da,722a9de0,c4e317ce,a8802aa9,60458301,11a89d1d,9de4270c,95b7d99,bc3df31e,f0dbf17a,a09ef148,71ae6c5d,870ebe75,1f52aaad,a48dfcc5),+S(41f7fa0a,9a59513a,e221e3b8,4b91995f,c9d40eb5,d120a6d8,e663452a,d92099c8,813dbbe,92ec4b62,25d1cc5e,5820ebb7,dbdc2964,d5dd1ab3,deabceb9,5e793d32),+S(e5cbd627,89c6a843,25a24407,89b88dbb,1dc55afb,9e8296e6,bb8af7de,57a50e60,2cf01cea,ae4f4fed,46c4efd7,86ca5e4d,ef5af524,e9393d74,e9dd224c,604b9408),+S(eb3bc68c,623b1f46,ab905412,c7f2d588,fa25abb7,7a7bd782,ba9bb3aa,c05a70ae,df9f46e0,5dc1d126,2f72ef3e,8db01fbc,11915af6,4aee0c51,da1cfa,b4d15ef0),+S(5702fb8a,2602f41f,52699f68,8d4b005a,128762e1,1dfd13fd,22ea751c,cbedb2ef,a77105b3,7af534e6,46f58c3,b02543fd,9e0666c1,58051952,a61f8389,73f5847),+S(66954eca,5434263,4036fc7,fc0fe33,81f5195e,88433bc3,2c5a8a60,341e2859,d8b1b14,40e9f123,f39c8658,f9d64e7d,fe4071f0,ada879ea,42eebad6,4d37f4fc),+S(592152c3,98d6c719,636a03a6,dad64246,a5a6814a,a62c156b,ce5332f,6759b031,8d22d1e2,d93dcccc,889f3b6e,dd5e2098,2f5586d4,bac06842,d689a37b,4b845c12),+S(5699b93f,c6e1bd29,e09a328d,657a607b,4155b61a,6b5fcbed,d7c12df7,c67df8f5,c147ee87,14325497,6b2e534c,e6902748,2a5c33dc,867732a5,8338f05,73368388),+S(c62c910e,502cb615,a27c5851,2b6cc2c9,4f5742f7,6cb3d12e,c993400a,3695d413,e80c2522,898d8a22,2c4dc0b9,8dc9ce88,740fe252,5144656a,c30f978d,dba83c1f),+S(0,0,3b,78ce563f,89a0ed94,14f5aa28,ad0d96d6,795f9c63,3f3979bf,72ae8202,983dc989,aec7f2ff,2ed91bdd,69ce02fc,700ca10,e59ddf3)},+{S(efbbec14,ff6d7e18,a8015d68,ba3ceb19,d4cbfbb8,a1bbc09c,ce755a23,e9d4b3f4,a76faa08,2b02b8a4,405573c9,5ac067f3,ab936127,24bfc14e,a27f923d,3adf0133),+S(f02f6744,a0ee7b0c,7bf0abb3,c7ec0a5a,3275d109,92be2893,7e9ef649,23fa932d,955f3630,c5621787,13e6d8f,39efee26,d91a0947,8da36db9,4ab4a89f,aaf9019a),+S(1c6f9f0f,d6ecbca1,fbcfbe9d,1f3d2476,dbd3b6ca,ac8e18a5,949b993d,8c0063e5,e3e3770e,33081dc9,5125d69d,c631450e,5494d21b,2ddf48f1,fbc3169f,3cc1eb91),+S(2062725b,739b793d,c9798397,dfc7b1a7,24ebe8f7,5e5654df,536adff1,25970841,22f3e3e5,c0201265,5e6d8e58,b8ba633d,9a9216b5,445a7f78,a2605688,4a5b6092),+S(57ffda66,e0c29448,7a1570f7,e2f5dc58,ecf9b906,5f374046,5bd1734,841785df,22ae8728,a8800436,1264c380,3beddb65,a9dee575,6f0cfa97,c01dc047,3c806def),+S(4b49fa7d,463cbb43,b14928c6,7b3a85a6,8132ad9c,427d3cc3,bba76d1a,7c9a69dc,7e7e3133,3782b30,5c7c3bd6,94e3c306,b3f9829f,86f76f08,d44b1a76,a207f2c5),+S(411a3b18,c9b638fa,38a0e811,ee370f34,5c9476db,61df1843,863d6d7f,4e803ccf,bb306f97,e97e492d,e74afcd0,a771570a,8210b51,9e61df78,4e6e97e0,ac23e109),+S(c8227510,49de1572,37afdf55,d175196d,5d315001,3670b478,a0255a4c,ebe95075,16be5950,a3f12be9,5905fb52,8d5bd93,23eb5908,211d2e8c,26204b32,556c5c45),+S(e46bdb74,8692d0fa,e6fc9f50,6685487,31d61f8a,5717fb88,4e1f7a41,70e4997e,35398e06,48bea42,cc48fa4f,2805efbe,6bead663,c054eb08,2c15ad46,c0611052),+S(d18293cb,d0902dab,e4c014e1,22969601,84aedbbf,a01526a8,6978e144,88ca794f,3a5b423e,32c1d2f4,bf754f42,9da3c9b6,84bb798c,ea73f637,1777ba77,1aae6086),+S(7b9cbbfa,a53923fd,e9f50845,3130101,3b17548a,8097433,79d3a526,d1c90c31,3fd7b71,5b6801cf,30fe22a9,8b7895d8,1b483f6e,9fdefe7e,6c59fec8,fb9786b4),+S(ab6e185c,be9ee393,5ad6278c,167396fa,aa4d936,80524d16,27ca8e93,48fce67c,7154007d,3f96ce60,d09499a5,1262c7bc,3ab5e9aa,929e0594,994a9671,8f912987),+S(56ffb418,8b9c9c13,4a110c03,8df8636a,71141ff9,8448cb79,eb6dece8,a28b65b4,1d728ed5,23ab821,ac0c40e2,b9348e27,191536c6,79a73835,8bd9b3c,b43dcafe),+S(bdba1eff,bf6af786,dca1da26,cc226102,1f95d56f,245298c0,b87a40e1,fa9a0cbc,fa18673b,41f765b8,25d13f2d,7963f1c6,b3308a14,b033fecd,e1d0d597,583440b2),+S(d9a4a7f5,5b3af93b,1c49ffa7,4f8154e8,23aa1477,16b16441,39fbc86b,2d9346ef,19ca90e7,538ac3d8,a28e1aad,5d8b1dcc,756f8a84,240e5769,a0f561d,f53289b),+S(ee5c17b2,74c78b87,9eda9341,256b1506,25582835,60a0bdcc,c8eba320,32d58638,d7d02f4a,b81215b1,7843e3c6,abb63755,c7e05d20,6c61a4f6,bb08d1b0,256409ee),+S(6953ae81,7ec599fa,5f739bef,dc4cd8b,4670eac6,912bd03a,a3fbe91a,5122ba0b,61bca3fe,36245ced,31cae918,fab6d463,50856947,f64a3be,d0eb62d6,f9f16059),+S(3bd721f7,59f7c3a9,93474472,4ffd3e34,503cbe45,fa7fa5ef,40a5a173,b8bebcea,bd7cbfbb,797034c2,d293aa64,1bf175dc,74a44dba,84b8d99b,8182d2be,6512ef2),+S(ab6e36ae,f5b7ff2f,fd2f42f5,8c408b7f,3ac84253,e1d8a43a,55cac222,678dd38e,ff0dc59e,51e504b2,9a0ba824,3ef26eb1,2446f628,78293da2,d924028c,21f57342),+S(bf1a1f6d,7f73b09d,3efbd73,eb9ea2c6,23e17911,9063489b,42fb1303,7b53fce4,236566ae,5371fc97,b5449b9c,2db32175,90e02412,b44539d3,bda7a814,3cd4a634),+S(fa0c6aa3,4c4825de,304cfece,37a20bbb,f72044e3,94cad202,c9e1edc3,b288ed57,df8e64ba,5f5e8381,4b6891b6,14dd4753,fed5f566,956a6dd,95540bdd,25c73995),+S(d2ea634d,ab56961f,52e39ba8,ebc5c150,ba9eeb1c,6178aef9,64fa97d5,e80581c6,2928f71e,a09a35b9,6fc1976c,f6cd3c1c,7d1fcea0,2142eb80,9666917d,c9a0621b),+S(827d6a36,697cb2f1,cf19e27a,ac30c06d,20d818c9,fe869309,6435f1f2,171c9b75,53237d41,3781a1df,d0d977c2,9690d488,b051dc2a,841ba226,c552cc28,12ae7caf),+S(59dafec5,4df05695,e123004d,38d9aa12,6a06c399,e5215245,5392e5e3,f1a47dd6,ff7d173d,ceda39ec,ca8d2c95,ab1658a8,6ad99618,e3fdb7cb,b07b03c5,2f96a86b),+S(5c4f5b9,2acb30ee,8c7ec4b0,ec577f41,a9502af9,a5a384dd,3386f230,3e62a830,8aea5f7,145de3a3,679c86ce,72e8b36,f3d6ac81,bb1d2043,9d719c32,ca2f8b30),+S(38add3d6,209080c8,efb65551,3d9420aa,457f06ac,d3ec84e8,db84e208,a0664ba9,ad95a891,c60f01a1,5fcddf2c,923790e2,d5596334,4d83a21c,dfe5f6bc,4c2b32b3),+S(9038876f,21c3bc14,111d5f6a,4749d07,34e40a53,7d398c68,809355f,764cf1ba,da030216,5e661aff,53367578,4a4d3447,707f14af,cf0d771a,53e8e687,b9dc29e5),+S(b07d3e8,dbbe686e,5e163725,8402cac3,e1e4f29,fdf154f7,bf008c5f,9969da10,c8b668e0,56bf8173,2d9778e2,eaa069d0,cdfbf826,47f615c3,6d0b311a,b2e14922),+S(8bc89c2,f919ed15,8885c356,844d49,890905c7,9b357322,609c4570,6ce6b514,2cec0c32,283233e9,21889013,c4a76d3e,e8d2cfa9,eed8890f,909c0b30,5736aad8),+S(308913a2,7a52d922,2bc77683,8f73f576,a4d04712,2a9b184b,5ec32ad,51b03f6c,b5a4f6a,bc0141a0,6e1cace0,993fc8a2,57ccc015,7d42e0ed,9f54a102,1701afc8),+S(3f0e80e5,74456d8f,8fa64e04,4b2eb72e,a22eb53f,e1efe3a4,43933aca,7f8cb0e3,34992828,d693436e,16f463f7,b7a2fe4c,6afedac5,59a4ac5b,34fd761c,15a0bbe0),+S(d30199d7,4fb5a22d,47b6e054,e2f378ce,dacffcb8,9904a61d,75d0dbd4,7143e65,6afc7262,f51c2a3c,4c292136,167c7f9a,e089f33c,9b127e69,fa4c00df,dbef9176)},+{S(983e1ca0,5dd64afe,8d39e15e,43c1cf9f,6badf550,12cdea89,5fd85021,b49f173b,18200e81,d75a745,c1ecfe5a,3ead988e,4327693b,7e3c0e04,329b0c80,3d9934ba),+S(4e1200fe,d3e5048f,f6c9fe53,cdff8ef7,5d78e601,4df471fe,369f3d1e,80e46674,a62aca58,4ecf32bd,cc297b38,c1951c71,a66966f,b9ceb2ad,de411da7,d175df94),+S(82f5f27b,83d49042,63e69f48,b676c9a9,2446955,cbc18ec7,fd4346fe,37e0b0a1,e523d039,d0b8ccae,737bfc11,9b83dfd3,d6878403,862618bd,40ddfc89,9a688557),+S(a8c0fd4e,ab1f0e3a,cab37da6,58fbab3d,949ad9a4,31d6461,b2648308,35762d19,950200a9,63c3dc2e,6d2771e2,eff401d1,f9ce037e,75782943,3fd3c560,a169713a),+S(25c1b464,33068900,bff89a4,ee973937,b03c11a,5b33d16c,4f672fd4,bfaa11f9,471f1f8c,df18e73a,e12cae35,43506cf2,c57894a8,f633ad4c,e1c5330f,eae42b43),+S(497e56ce,8793bfec,4dc6f972,dbaf4a72,aa5d8412,3bcac5d4,2aa9baf8,ccfd6723,1d3d028e,b70105b6,eae66785,5dfe7e0b,7c0a6b3a,b069a475,bd913aa9,c29cf426),+S(68a285b0,d30c2dbb,b543e480,f66824b1,69aa339f,7e2282c1,5dc60f50,8e3f2fa6,87529a0e,1d53588d,21064447,99a8fee8,ffc791a7,cacc9e26,f7a7d94b,25e74cdf),+S(721c92ae,931712f6,15f4d7c,498dda23,e1029dbc,944cea16,9442b22e,d755a100,7ef052e6,a0d2646c,a5dff39f,3b2a1019,de43e3b2,5e51913f,d636281d,cee74a85),+S(aae8418f,1b124d79,ad15f773,1bdcea1b,453493ad,4cb0cd6b,ee5c9a8e,34335ba3,c2558bb1,4a7addab,62d1f308,1a9e6fd5,92a06976,3be877d2,af9ae1e8,b510d98c),+S(b6a06052,b492d74,c68640de,8bd3251d,fbaaeb0,ce1eb997,f2127ead,4bd0b81,7bb4269c,4a9ece8b,e8ea2f0f,d663a193,2a571249,2814eb73,4ae1493a,6a97b39a),+S(42fbe048,38761203,11e43178,6af555ed,d7bea551,d4d5aa18,afaa4c05,2c6d0c19,9ba562c0,a4cdc664,87caf55c,291d8246,65c29f32,2a56360e,90138b06,f109d83b),+S(9d6dcb88,b378e7bd,233464e0,25e97bf9,97768e29,6e4aac31,301fa1c8,bfbcc27b,f434ea54,3f7269cb,1ae1279d,4178dd25,bbc337ad,2f0d5141,610dc061,80daa8c0),+S(fa6fa5c8,1e6713d8,90cd6f29,cc8b7d03,c5f8f2d5,88963652,7c199f6e,8f98e060,726194a,2a5da1b5,85eba1a5,5e06ce36,5aebb89d,ba5f7971,db3c1571,c848c5f9),+S(809167d6,85e432c7,372dc111,8573e620,d9ce7e9b,c3ebc15b,ea7e866a,3a8addf4,bf0cb694,f00fd1b4,b62119b3,9dd6c88a,22ef1fed,a94ac0a0,9cf33225,9298b968),+S(99d28ee0,962c1bd2,fa63109d,f5485653,964059df,bd514206,24117eb4,e582ad46,8cbdbb66,4ee209b3,419c0b80,36affa24,85cdfbc6,e6644429,33908490,f6f6353e),+S(559d0617,e0860cd1,87f1c68,e9a9951b,fef7dba,3a67594a,eade6e25,e2df593f,194595af,721e3b26,786fc25a,cf5b2d77,1fe00649,b0cc4938,7168a9ea,1fd2947e),+S(ab9a7228,f0d533a3,4a95af3a,51021b55,bb324229,8d101a66,eb362c97,eac48b02,80a6d111,e451eb09,cbebdd5,a3ce4fdb,42b3665,f8974df8,912221b0,fc7db6af),+S(42c6680d,18b0f528,274c2eb5,422e4731,560ea862,adcc4419,68bb5f3a,5bbfcf16,c8961934,e5bd6e7d,d64d4b1d,f7867c7b,978d182e,48315ae4,3fe2e082,a9455792),+S(e8bc0f9a,c3687bb,69627de1,df71fb34,21e0252a,e33d15da,3039a200,43ec3374,15de9e9e,2ac74839,5116ef76,1267300d,78c2e583,9286e6b6,366c8a6a,540036cf),+S(604ee928,4ea1c8a9,a0a75bf7,be3a5c02,8f52d71,b5fb6340,53401e8d,8f5d3d6,43bc16af,5875b25d,8e2427b3,3913f6e0,bda886a7,52a3b812,f8f191cf,f7bee54b),+S(7f589067,5b771ce,ac754412,a9984352,4f2a4a6b,a5cecae8,5106bb81,f7e4d9dd,a74f2eee,584696c6,88157a3f,fc27085c,6445c7eb,e363c6ed,7a1f5902,63de2024),+S(80aa63b3,1fdd0d2d,ef602bab,dd88a15,71abd052,270988a4,63abe269,fc489fcb,9a145d0f,6dcf0edb,a4873287,a2f221dc,4be613df,f70f7755,f28879a,6e7d9978),+S(ca9793bd,796ae0c1,d778f3,6445bb8b,aa50d859,4be28fe0,ea1e2d16,30972503,7304af4,4c56106e,f0064436,c09b411b,926c4c56,cd82577f,f8c01ab9,9f7c4c6),+S(4cca305c,baf6615e,8cdc8a58,f3a9e52e,97ee20f3,ef080793,ce105a03,a1f1d3d2,637ea84c,9578321b,b5dcc239,7f6206bd,abdfff2a,128d3645,47d474f4,8a8ae493),+S(cb7813b1,a7227a24,cc53b458,1985592a,a9077113,28fb2a05,1d4972a2,3127a913,208b7263,f8f8193b,76dbfb1a,6c4f9264,dd12f63f,e852aa8f,8375fd00,eef83482),+S(d61676be,a11dd1a5,79164cfb,b2488e54,555d7d55,23ddc8a5,454c49e,4a86d8ea,1875b5d5,6db950bc,60b1eeb8,17a94af6,5a19f690,d48aacb0,e483ad52,61995cd9),+S(7142872,6f59c2c8,b398b22f,2ab5c3ca,e803a34c,ab580947,9b7b4d83,1f8e8c0d,3702510e,324c0911,b3154c61,e064ba23,68eff5fe,6f05353a,34980ec1,87ab9ad),+S(72a73d15,9cf7f79b,950971b7,1c66f362,54d13783,c5ef67b8,4da61dcd,4cf432aa,77d711e5,c1793c36,eabf9b86,bf3a692d,234f02db,e4d5854f,5deef926,b9818d2f),+S(ab3b2de,c0a8f23a,a7d3b9d2,88870969,2e45ef47,37a792a5,d65af92b,e58f6347,ac4e4ac9,1bbb57cc,1437e612,e4d4ce37,3d4f0286,5905b621,56826d80,895cb48f),+S(fe5efdb4,32715fed,f9bbb16f,d65ddf6,4ce9bb13,14a491c3,3bfedeba,cb4704ef,e5dc36f5,5fac6974,eaf9d8e4,232a22c3,8aacc6b9,1225a97c,2e695940,ec795c21),+S(5f94851c,a4149e75,e44a0d8,17e81c75,132eb242,c96ae41f,53f30ab9,c8c828a,d9473c47,505e0117,1a0f8682,777d0ca1,7399208a,b03974fb,4014f5bf,c8cbaeaf),+S(5d1bdb4e,a172fa79,fce4cc29,83d8f8d9,fc318b85,f423de0d,edcb6306,9b920471,d7bc7d98,86c861d1,86b4466b,c75dd9a9,8614e166,693a9184,8fccf998,847cb2c)},+{S(8cf1437b,d87e7faf,550fcbe8,81b0741c,ae0b48e6,e0b3c3d9,9b1b1924,2a925a26,17b40146,c313b1c5,3bdf52e0,efebda45,80d86783,910996fb,8b2d0acf,9bd253a8),+S(fedc65f0,d622743c,53fa6172,e68d983c,2c9b8fbc,58943f48,ad06a852,c98403e1,ca5dcf28,1a2f20d1,5fed06db,89dfd290,8c9d32a,cf40fe6,817e861f,7f168ea9),+S(846c6a48,e771b90,4ae1e8d9,d3daf1ff,d1cb4c88,bbd1de98,454bc817,954654f0,5a4947a5,8a0ab994,3cd0a90,6c1d1f0c,3fb73d2a,49b9c0d1,a9bd35b2,99475dd7),+S(4998795e,a7d80937,e4abee13,6c14585b,40b2dbbb,3fd3c80f,c8c61b45,cd1d59e8,8c817eab,e210398b,59b31660,267c099,baf29e4c,894e09d9,a50894b4,ebbe97f6),+S(76c29921,eb3f3d12,5c11b906,3d1ac276,a205804b,b3e7484b,72ae0483,e4b3c517,48d8a8a5,fe658e1a,4d736bd1,8f07b5ad,28cbb775,d9388e7c,4fecd837,c8eb964e),+S(78de8fb2,b15ff39a,487135a2,636bdcea,57bb3a14,efc329f5,a06bcefa,7ffeaf09,a55c9e98,5e1f529b,ba7ccb6d,3a5c00ce,28cb14f3,e9012d5f,9f66d8cd,5e45113d),+S(71fb3464,b0600c08,7fe70906,2792a676,27830e50,a0bfb473,ec909530,30799282,fe036726,cb928a8a,8affed30,38977377,2a016e7b,1dbde8f3,6db810d7,cd423f36),+S(f1f23de6,bf779cfc,d864dbc7,b46009cd,d2306b1d,cd0de2c3,65f3006e,565d9e21,84f5a011,74ff8e7c,c9a98f52,3f2980eb,4b013695,f6239016,9cc5a1d2,acd8193),+S(f18909a5,a5db0daa,ece22ac7,12ae04ee,53484793,6fd8355f,9ff5ffcc,ab6ca78d,6306f08d,13ce2b0c,b60b3b8a,b0bd5f46,b3ef2a83,7edce51f,2cb5ce41,79f46344),+S(7598d96b,189f476c,bcb1992d,9a38adcf,9d1b6ce9,6c87058e,24584514,a0df4770,7f288be1,b82da02c,a37f655b,d23643ba,bf3d5cff,3b6c2726,9ece7409,ed78bcd6),+S(1e44193e,8223b57d,8fc68641,924cded8,3a04d806,cf9dc18b,7af06010,4e6216eb,45ea3ada,fd726fbe,2b1d6fd1,858ccc2d,57b237bb,bc2965ca,ebcd1b63,53c2f2e1),+S(80954b78,4872286,8fe38891,2d76dfba,d676b4e7,7901e559,dd5983e4,e908f13b,6fe564cd,a0966639,e0237f29,46e92d29,4aee124f,cb33da53,974e8882,b0acf22f),+S(6dd8a9a9,ad7196c1,3c36464a,5cb9fb41,aad8b0cc,423b99fa,a281c5d5,a6ce6ead,79a51469,8767adcf,ed287aa4,914eedc5,8382af71,5485c2aa,c3a77c4,efe2aafe),+S(1895cc13,f99534a1,187a3d65,d1480669,f0d0c0bf,b42b2a9f,1a6392d8,7e1d2c6e,b7905afa,c0eb9b66,51de3583,2cfb9ac7,ae8d2355,1e334d59,32909de9,ed400a0c),+S(f1efcb8a,86f94997,65b38fa5,8edced68,7737b8e9,49dc05f2,190b359d,9ed2c0a9,79b2c874,22de216b,904572b7,a39f320d,f53e392,8dd8e533,a1a28d93,fdd4945e),+S(2944af80,c207d107,ce89fb90,ea6daa2a,c65c1360,503c36c5,ad798333,90432ce4,44b53d27,fd6730f2,33b8c29,f1256136,c637740,86e001a7,60bc1ff0,f8b6211a),+S(938a1dff,117540c8,f6ee7df6,2d3c2cf3,31b38593,131527c3,9804c6d9,874752fb,4683d049,f096bc21,2e0dc20,a8600b8a,a02133d5,d0ae8d6c,b26e4694,ed6f2aa9),+S(b1b3b2c9,54d1fb6e,98fcf939,efc18803,2f693989,81f19c32,f5e55b30,1f59eb16,423a6754,1a29bb01,95adfe15,c1df1c9d,81394e96,2bd1926c,cc789f5b,eef9ec29),+S(52e23f2b,19048d43,b1725695,e3bdfc7a,f4ebd2bf,594f013b,b80d6d0c,ec10632f,258a6236,67090b8a,73881e39,746906f8,eabb6683,4bc3473e,1c6fa8b6,54641cdc),+S(5799a463,cc817bfa,26bcc543,efe0e00b,ca9d2320,1989e854,620fc9b1,ffc14afe,645238d1,8c69338f,9c9395fa,5ef7c9b0,f62b7dc9,c4c6b9e,c545c850,95b6b7ad),+S(1c493b52,3f5a4467,6268220a,58246228,608a603d,f6edb1c9,1a90b060,70b16069,8d311a45,5af92640,e9fe08f0,2981db57,3b22bf4,8fd5e76f,31c175be,23e24fd4),+S(84f5a9c9,cda291c0,71aa9f8d,d7af5a8b,f2ee0dda,fb9139ed,fee08f0f,3f9cec2,df381327,16527be1,d86991a9,bc28966a,c3c6c081,4fc0def8,85e5d160,f59f4458),+S(712c18a0,ae87e7e,87856c8b,ff6e3f6d,996ae157,970e754f,bba80bee,421fcde7,b2788ba,e69d34ba,eb5dfd62,830396df,3b8934a9,551c6070,ae8203c,ccc50ac9),+S(a5104184,ee996a34,7122a460,cd2eba5a,11d04aaa,a47d2ede,25ea13fa,41ee01f4,f4b5f2b3,f7ec9061,7ab5f3cb,763233d0,afc8d4bf,fc535076,5dc5fd41,cc547ffc),+S(79383075,a46a8eb,559ac95e,7dbeb9ee,51b6e906,27e55b9b,922473fd,5f2eb63a,243f56e9,84fd2673,58754a67,2bac56a7,9ae71a5d,68150740,8eaf8c2d,b55ef1a0),+S(2b22635f,b83ab0d4,9b82edfa,a54d6234,8d3bee6f,edbe3315,9470b18a,96f97821,41d9f3a9,52f17182,ccf02725,b58ebd7a,1f37235,1fbb8f2c,15403890,e8b25b82),+S(272fdefe,148ef7e6,957fb8a1,4a07f0ad,b17c27ea,49532547,5114c1f4,76170a0,789b8eb,5846e50b,d489bf66,cebd873f,7cf05619,3674e7d7,147ea691,6a9b8451),+S(2c2da4c0,8a6e73c0,2efd6e7d,13006135,f09990a1,4c0a0eac,1f286108,f4a2a0e0,8011a521,d7fa0ab2,75765bcf,50dba163,9e89c9,300e8a25,31942cc3,fdade63d),+S(19a9e5f,1c4cae30,797a98db,a24051a4,38ea755c,7b062094,a34ed6e8,8a8ff2cf,e199e398,157a50a1,56f9d6d,afed48cf,f3181411,77b792ca,c5881898,24f1b8dd),+S(f7a4be3d,fc6579fb,43c5a960,890893a,f4026165,ed9e3ab2,e6929378,b63968b6,29221093,17dc39ea,de2d6fcf,c735ad2d,668fd047,2eefefa1,b6b225cc,2f3cb3ad),+S(e5380fe8,575f26ad,b7924ae0,d58138d2,68112776,b11bd34b,3eb5e196,33f0e9aa,4680278c,6f784be2,a496ec9c,6db371fe,9046b1a2,b97ce71,3b45bec8,bf7d8a20),+S(4c1b9866,ed9a7e9b,553973c6,c93b02bf,b62fb01,2edfb59d,d2712a5c,af92c541,3e086d2c,df4175f0,804348ac,31a91963,39ad1528,1bc14e52,8d3b0c01,39701c0f)},+{S(5a13b9b2,5aa6944,1b0b5fb7,f7665dda,95aff48,e3250b4e,34cf8e28,87406c1c,245f250d,78fd66ef,24745e09,f067f16d,d400c387,66d2a1a9,af51e84f,733d0ba2),+S(617b41c6,8534072f,2302290a,4956171e,902634bb,4356bd27,ab83a377,13d8ef6,c867779b,97383817,dfd0971f,64c09c71,7c468a5d,e1bb8ed0,feb98f5a,305d8e6a),+S(ac118ae,ed46b08b,488202f6,96d9469a,e9af3cc7,ddc8eb71,44903a3c,ee43c654,f992fcea,8268ca6b,79f5ce69,c87dcfa8,42ea0345,d7c85a5e,a1b89f1c,9d0217aa),+S(741dc47d,2e0d1424,3f2bd96d,9033d8c2,9008c1e3,66bfb5a1,1434f1cb,3d85310f,c3135d44,e86f574c,266f97d0,f0279dc7,52aee0ab,8e3ed78b,ee0fc646,c133000e),+S(2e973138,f6cea9c0,5adfbb5f,49a7b928,5ae0c15d,120a8b1f,2d0c76ea,1fdcc7e,a05bc93e,68bc82da,7a7c7e38,95a647d8,7f724f20,c5b312b,738c6dee,90de771a),+S(9d938d6a,cf56104b,5522351a,3c424e01,e4d21c33,771ca94c,f55357fc,fe51f91e,881d05fd,4658b08b,edf87396,be3fbb95,ec9f371d,79ff4586,6ddc803b,65ae763f),+S(37a8ed2b,4085961b,84645ad9,8f2c901d,fe9a9a8b,4de8fc89,2cfbca5,c8909835,b1bdacde,94fdc3a8,78cd0eac,f8865d64,77e2cff5,efef834,97b93835,5b7b401a),+S(da1ba954,899cb05,dae6fea2,dc8ddd7c,5ef9e91c,3455838c,a49d2858,ec217d66,14051c3a,12332d70,f8ad8ffa,567765fb,def69640,4291b81e,d3978bf4,51f788a0),+S(92d2ef44,5a10dbc6,73f8c1e6,af093596,13bd1e3,c1b24705,bad2b3de,e8f11b81,adfed916,800d3e94,91a42c59,dd72e3ea,57d47081,b9afe668,f853cec2,c72cbab7),+S(e62208bd,52620df8,91b3ddbf,e6cf0641,6059ce50,be3b00ce,14e7a53,6d1acb07,1fb71455,53b2f4c,431fd86f,c72d51af,5e2edb41,dd3f69a1,9a971371,d9679dc5),+S(191fec47,a48ee268,35ed37ff,6758a80a,532f7011,ab099048,b024efbf,cde1d0ab,47b6389,b3f5534d,a632924d,5b65918d,f65c9c2a,2904ee95,4f24aeb8,c6a02557),+S(60c822fe,a74d52b7,d5203720,b2c2a361,b7628aea,d2a683bd,80655636,bed15714,5d9a9c0,120211b2,e8285b77,8f8d4bc0,b06240d9,22944248,e1cfce73,826bb67d),+S(f602da1c,788ea65b,cc339a38,c353bc08,1c43c2f2,6e05ea6d,ab52648f,890c9101,21468929,89348f8c,67cfdeda,31ef3429,23b5a450,9fbe9a49,f011d42e,57f998e6),+S(756240c0,5274101b,3059d23c,76d9ecdf,33e1312b,7a36af,ea21e6a6,c52cdbb5,ab24e853,900c7ff1,3e4f813d,a2acdd5f,53ce1710,b785ffbd,e74494ab,43e583ee),+S(8e815b45,7adf482e,e30e475a,4949e5ae,c7ff494a,a918f07f,c39441e2,360d112c,a966f04,2dd9edb9,436b0005,7473aa66,dd19b4d2,cbb3bd95,932ba98e,f1a1f406),+S(216d5970,36c661f2,cf6122c0,a136cc33,9660306f,1c190ee5,5f3bf438,e7189261,5bd23797,c6753eee,6fb934bf,dc897ec1,25b31c9b,9e797ef1,56d8cdda,2ec1d128),+S(a30ed06e,ce34d29,a92fdeef,6954b5ed,4065d592,3af09be4,f0ad4a73,e7c24346,f6aea418,6b38c188,b84fb6f4,2b6559be,f52dc13e,b7ddeccb,6e85a76a,8d4efeaa),+S(aa42d20d,8acf7c47,fe40ac15,3fcaf1ac,6c4ecc37,dfa39c39,fe5c7657,c78444d5,bc3becdf,464ce930,e42a05b2,c52d3589,fd45ff37,c7d1767e,f8462811,89634059),+S(7585f8cb,4812e306,de02393c,c06e9871,1953133c,bcb67ec5,c6a79228,69124ff5,c242853d,1a2c1c9,a1cd1b5b,364888fd,28bb23c1,2b0e169,67961b3,e7c8b95b),+S(b096a1aa,fb969483,185ba1fb,a5fa3f3a,d1da87dc,a10344a4,d74ef471,45cc45ce,edbc9490,23801861,44ee39a5,7bdec0a,230df57a,72649e04,c4c99883,a147f0f),+S(7034d8cf,df226df1,6b310628,35dc02c9,f3e3f91a,635ad93c,46be292d,56c0ec2d,f783b6e8,29447cf2,32769a13,7ff33f82,f9fb166a,aec8c3ad,1679c48,c1a913a0),+S(9f88b01b,b936defd,f61156a,b55ca290,cf282a2f,3718b0cc,2d32dd3c,49248b4f,c24ebc35,27052f77,41087cb0,e772ce12,1035042e,603f1301,e19cee0d,30029230),+S(14443190,51f05d23,343367e9,6add133d,fcb63209,2f218847,59ad81ba,c65e7445,745216d2,d11f2556,7e3b224b,6dce478c,bb988b96,a1240093,964e4ba6,f3b15554),+S(54aa2e02,3038fd83,f17a633f,d9ab441f,e039dd0c,57f9368,3da013f1,751c6813,f4d163ac,a9af3e08,c009b44c,b358ebaf,31aacc5e,e0bdb917,d1b4df5,420d2d34),+S(fd44e742,b04ca4df,693e3109,3ec52ad6,1f67264e,100618e5,88d638d6,d96efa41,7ac09cb1,2134a246,b17ce054,b38f3bb7,7d794f9b,2fca3786,a0ba665d,3eb0f14e),+S(f662f214,10cf6e6b,7f79fca8,7ea3925,6760d83,17478419,ff4671f0,2bd2ab6c,be4ad0b7,a56c87a4,8fbc166b,da8473ba,6518385d,bd004b5d,c85126bf,7b9309bb),+S(520e2755,1cd804d2,67f9b4ca,b3986952,612bb099,cbd3f3be,a54f505e,bba4db64,e3c75cd2,c831c539,b095ac18,3bb13a72,ba7cb152,5b9c214c,288509a3,98a9cc3b),+S(4d16fa3,2d74de13,111b3f22,c4133ea5,377921ba,e54af1d,666d6e9f,b01e117d,a63bdf75,78d73f03,75aed657,fbb8675,67230c3f,868f2cf7,b7275ec8,b02ac46f),+S(ab928c61,ad1c2f68,905b9e95,3c2629ad,9bb7c8cf,ad9f5a4b,35b35fad,69a92568,bf39ec2f,6c1ae222,ff383375,6bd83882,c05be6ae,692539a4,5124b972,e72159ee),+S(8731aaa4,93580732,66b96577,7bc24a46,17fb8363,51c5ad8f,c8bc053e,802dd07d,36957f16,1020430f,69a3b1c3,1a6df993,d9ca8e2a,8f487b7f,b2ccd44c,7f528ce9),+S(3514d41e,8b9388e4,33d1155c,c777c398,22ab36c6,3c2aaad7,ce674831,21231d11,7657cdaf,e9fe8147,10bb2ee1,a97c6100,6c7b0ce2,f5086141,ac2904be,1c7a9e3a),+S(9bb8a13,2dcad2f2,c8731a0b,37cbcafd,b3b2dd82,4f23cd3e,7f64eae,9ad1b1f7,6ba44d4d,50111c46,490622d7,b079c17a,f0ab57bf,b8ad2ac,9becf9d7,3c7edfaf)},+{S(e60e88f1,dc24f079,f835b687,778307af,83446e,71809086,e6dac0db,9f191de4,25a0b86e,ff05c849,d79a176,1a634d82,29d2a759,fbd003c,b6ca4147,85726362),+S(55a5e6cd,c9e11103,749d469,dae84a88,9e744dd5,d9309762,15050a83,fef66fe,31278ace,a971a41,e2f9fb16,8e80ec03,37009cd5,b0a49938,c28c902c,a7c71fd2),+S(5f25326d,e99a7c5a,d81bf2ea,61a9195d,48832bfa,8caa9777,53e483f2,b5a62580,40b69a1b,baa2d0d1,5cb78a3d,3d184c08,5b4c16d2,90751ec9,bf3eb3c1,d3ec2ab5),+S(1a32cc7a,f88976b6,cbc89865,89e685ac,49381a29,1579bd2a,13f9488,c0333d19,4667a3e2,2048f781,11f009ae,5d7b1b97,850a3a5b,86f77880,b128c8c6,a9720acc),+S(1d78e74c,66247be9,352c9797,5fbc1299,743f9c74,68c64d1,f2d8affd,1b098769,37adf553,fa2a11e2,6913ab02,e59c4f2a,48133fe7,d9aa3c24,a76e9af9,48a29d8f),+S(8bb6f83f,6be5c2e2,b2bb265a,9bb3c931,bd5cce6a,48efccdf,daa040da,535dbc86,eb96a982,23278b81,6284fee7,b5b8a121,7350cdba,d56b6078,89602bba,bc003481),+S(a9f19ca8,1d2ebafc,4bb5d881,76bce19a,d2d2564e,185f905b,8f9eeca5,d6b12d6b,ab23a468,3279a9f8,e2e8f880,e0accbba,844bd4e9,4d3e4b43,74db2b55,d998771e),+S(19680305,c887467a,c3bfe44a,dbe65431,7323d8e5,62271e25,1a794b78,618befcc,48e9303a,3d6371f7,cf0a904c,cf16f606,b0007583,87ae0952,c6119521,dde25532),+S(18b3bd03,ed4696c4,7c3f896e,5df7481d,6f19a5ef,53d62ff8,2948f1b2,154175c,85fb04fd,6573a19f,2c136753,a1ca2585,d39dd64e,6e6e3fa5,fba362b4,ae9dad36),+S(38e3bee1,3cc3e18,a57aef97,4ffee58a,a392c311,14ac8baa,1376b56d,f8ac017e,8596c7f9,8abf3e44,4ab5491b,fe659619,f6defb58,f48e2b7b,57842193,cd48fb5c),+S(dba5da08,8cd17c33,3e892bcc,46261694,d2ff3a22,2a26f92c,17c5e1e2,797b235f,ebc15bfc,5729e986,85a19afb,d7f9a219,e60d2784,e9b283cd,3697f782,630fe222),+S(60456426,caea7fc4,48970eea,fab9c632,3e66fcee,50f92630,7b130937,25b85ee8,dd22df89,c5dae339,49459593,1433f2f6,5f719379,68e56f92,a38d1290,17881924),+S(f1ceac82,15670212,279f36e,f0c8ce28,3a192f66,460e4875,d90b2f51,a38f5712,ec11f026,c76c271e,fabd7d55,c8488d99,3298f6ff,c05ad4a1,26be9447,7d878b9e),+S(2c2fb5de,5dea249a,7bf6b196,8bdec8d6,1838da2c,12147045,18d6494,f09e50e,6c0d020a,d6bfd730,5ee73634,e939ac89,ca2b7d4f,dcbe760c,2d14ade2,659a5b8c),+S(2858ea8c,d40ce264,3c9a305,c0e2c758,af5b0b4d,5c57ed21,60cf7ec4,154ffdc2,33586bf,a61a3cde,4f402bea,123c69e2,2410c0e,590a71d8,9a1e8130,85cbb579),+S(2749a250,4e7cefa3,a3647088,6bec22fa,339fec0d,ec63c02,19e6af39,7fdec3e0,d3415104,a9070af8,b61acdf0,77954d37,57fcf742,a006129a,5c0d3529,3aa95407),+S(8edf3ad8,39e661b5,f7f16a85,dce3caf5,d571acf4,d0c6195c,53b618e,5311ac65,fca0efba,35a14d3a,9944367e,db4ac982,7dcb7aa0,12438c5b,aa5627c4,c4a15ed1),+S(dbb92358,8b083294,5d6d3b62,9cced57d,7085d3e2,d0890bde,95d80400,98c22745,42816661,5515429a,aa023737,5fb77804,624546f2,1f0a34ac,1ed4e4ee,dceddccd),+S(aaca9896,6196ce2,e13df3c7,d058a5e5,10566df0,5fefc04e,51f9dd,85a4349d,be389d02,789548e0,aaf67c57,3b91b389,c7e6ed80,ca3e637a,2a147262,80cd5620),+S(104804ab,e621b098,61fc540f,f4d6be9a,750e3cfb,706170db,e34c06ed,e0a431ea,14b700ed,a465915a,eff84ab9,fa568535,f63e4f44,1387ab4b,d841072d,97739071),+S(b2215070,a8ea71f9,b71f1a73,d6ce366,c322b8ac,4d135b3d,ccea68e5,a51f1c0f,9e415cce,3bcc4e62,6f3c8caf,fd632eea,862a046e,bb45e8bc,84fc05a7,a4b87e00),+S(600c6e28,be5ebd28,d83e6c86,bbbd9b0b,aca22006,42234634,6124133f,3348e6f7,822b1816,79e253db,a47ddd76,c0023991,5c0c0206,8f422415,94ac38b8,ff7994fc),+S(f8b9b45f,c6298dc7,13355bf1,3ee33ca9,c4c1aace,c09776e2,56b3746d,ccae0dc,bf4b7f96,1844aa2c,6ed8c8a5,6626386d,174e77fb,98c0c23e,e2b6de90,3f1f79cd),+S(63987b18,67fe5a17,333eef28,5385a0a6,576163e,2c74cd00,ba87b6fc,96a57faa,23ce6655,51d48ca3,c702a5be,87a05d98,b5aa1097,dd5877e8,11e32d76,4873e6cc),+S(2eb06c4f,5ea9ad2b,124a1202,cb13c1ae,aec4394f,4af7c96,d6a9ecba,540ee04d,b96173dc,77b46ef0,6f4141ec,96ce8d1,4adfcfde,f0bd7ea2,479ba6d7,522d037f),+S(5db39904,153002b3,1498bb01,16efd0b5,838e3495,62d9428c,912987f1,3aae5ae,2115b896,479d0d0f,75ffcb54,ff9e3f73,d1356ff1,4b14292c,6bfe8d54,e9e08861),+S(c0f14110,7f324ffc,f3d3e6c,78d5a628,6000d57d,7e85bc7c,fda15f75,79cef3ed,6eb03650,c8142b12,b330b96b,81214a4d,d01b068a,74827611,53d2c52e,e1315ce5),+S(7e3d1510,ed767345,bbb3515b,6f9819bf,33ed9dea,fab35d01,a7284cc2,371b0e66,4c6b3aca,5159023b,d43ec0b2,57e77e87,e5a6b745,178bb017,9960c89,361fd97),+S(f98b5dbc,3e54c227,b002f458,94850ff4,3b15b2d6,1607851c,50d1e4d1,8b20907d,1d2af742,b0b5ec05,bd6c648f,94563361,be03261f,da56f1ca,7caece63,a336d580),+S(188ef3bf,ab103784,37e1859a,7d53e899,6124c395,ca422c05,d6b21b3c,efc76ac1,19036685,fad04566,2ffa04e7,30c671c7,1b299217,c389c78a,cae9fcd4,ad70fb73),+S(b89070ae,96ead4dc,49be16f6,a1a30bc2,41b4e98b,c18d0227,4c9d9d87,dcbf00eb,90db373d,375d2770,b8dd6b1b,3e3b5899,34f274f9,49469598,e480e431,e4f195e1),+S(381c4ad7,a7a97bfd,a61c6031,c118495f,c4ea4bc0,8f6766d6,76bee908,47d297fd,6c950ac4,dc71111b,70c1a058,f66ea133,fbaefcd,246c63ff,6c531ce6,82b6bc6a)},+{S(704a26e5,19071bb0,24eb2a16,48b66a6e,157b07a5,52fc4258,381f7d02,e8fd9b9e,d169ea55,8650aa3b,ce52c645,278422a3,69326e74,46039381,920f5857,fa3492fa),+S(705063f5,e481735,60afe9dd,5b2beeda,d6e46391,75ad7fb6,f73350df,51edf53c,32290956,61cacec9,472dd014,bda52364,3399d7cd,9ce2bb31,a5b23590,22c6ee5c),+S(972e7585,f8b1725f,4a7d18e7,77939aa6,3600a7b,a07c4d94,5da9511e,889473f5,aae4382a,49b4c97a,bc3edb7d,26ba7bad,16752047,dc99b434,f306c673,2851310b),+S(260530bb,e338f4a9,71930b12,4f18c82d,e33f22d7,32de9375,81e2b0d5,15e59d97,77c66c36,d6b09205,8ade9c0c,a311b60,a705c8c8,73fd2d4,8e6327cb,71eefd4a),+S(15464351,d21d2513,f792ee32,aca3eca7,a52cdaaf,9862172a,e7224a03,804581dd,d9ee19f4,502f1c44,f656ad4e,add6adbb,d8a04f5e,5344b554,894721eb,8e3e2285),+S(4fcc68a3,caf3ff91,dcce9770,11ad5157,6c844132,321791ca,a652593f,6cafcd04,e8db3aea,a35371bf,9700a9bf,b85e90b3,93cc088,9cd655e3,fb18635b,49fb59eb),+S(301c65ad,567952dc,6b39134e,c361030b,3f5203ed,da89784b,225548ec,45c75eee,95e2c0bc,7b4a7cde,8ce3dace,a691bafb,f78fb03f,3170b347,ee807f42,6b947560),+S(96ca5edd,8047ec6f,b5f8c37c,a734533d,13f0e6e7,f55d28,b8b10b5,121f4abe,1a21f1ba,f6a2e336,247f6ee0,88cca9ff,816b0667,3badc241,d9ed00fc,d2070f1f),+S(c94633f5,783c4e68,12143fc4,6e670978,8e8a526,819afea9,404dfa00,df1bd839,874f8760,33dba9,de463f86,b597219a,c1ea37f3,970bdadf,97c96c48,feec4ec5),+S(963146d4,5bdaa05a,b5115ac2,3ee862a0,2305ba9c,75003f4e,ab838f7,e9adcdfa,d75766de,299e5cf3,c8796234,5db9866c,cf011c5c,f108a794,5642a6b9,dd33eb0f),+S(dde8c870,ec4e9890,2a820a7b,c5784034,19ac261e,de5afd0b,82b8c5a0,7c2863df,e7833936,50d4af7,427158e4,6c753ac1,a5143c9b,c09de97b,3b27065,6f622b82),+S(546c6b00,c5e34a8c,4cc7255c,2edea33,d9f77e7a,c67ee629,bbdf1879,4622265e,5ae149da,f65aba8d,e214fa63,be9bbf11,3dd3c220,12d206bd,d56026e7,4a019897),+S(4340c850,d91b63fd,bdaf41bc,f8d8c010,d3f30eb5,79eeefc9,e67c127a,33324071,dd66033e,eb5ae8b3,3c47a940,2482bcdd,4db5c8e,dda3b422,35627434,dc3bad1f),+S(f796431f,679d9cb5,77bce62d,236d1fe9,b5042a83,fdd1cf94,1a2e00c0,5a261d11,718fffe7,68aa2591,d3fb1fd6,1a00537,3b529f9d,f9c27f79,31ad0df9,9aa74859),+S(f3d17ae9,d5b4cf41,27423894,916318bc,adfb5a9a,6c2ca219,1b918e43,eb5ed129,9da6d033,49c64d79,7ad09a33,bf71cf87,8e0ae6a7,9fa7bc3f,1451126,18415960),+S(23899a73,a4b52d27,29ab52a8,370ceef8,4c7684c,cd535f4a,ec360eab,cfa5a787,f1bcde3c,5c4740c7,37b066b3,8a1a88fa,c43357f7,f3fa23a7,b00815a3,85336320),+S(5805914f,5418971b,106305cf,c397dc12,f63a3b2d,8b451e5d,c1b60c2e,3d9e9208,616e2764,67a5f1b6,46279ee9,6e8645f3,76a80192,31e17a5,c92e26ec,1b76e62b),+S(85ffc326,1991848b,5e918c4a,53f291a8,31796b52,d56a5c38,8bebe625,d78cd07e,95fd6f12,7b155e6f,806c089f,3f5abe95,344e9014,e2c72fdb,e720bb8a,93d864a6),+S(6f1a57d0,6566bf81,f4b16329,19f477ef,aab4f829,e29dda4b,27627b96,1cbfe3eb,de1e8359,7ff20c63,3d28b909,caef273a,a57898f1,a797fd91,e00e2e7,da1872f4),+S(3d28eba0,4d0ae2f6,208adc71,cd6af3b0,e208860c,722903ab,e106feb0,af3185e9,cf8bad18,40d3d2b4,abfb5b28,b50702dc,512527d9,5bcd403d,9713ec7b,ef1dda13),+S(46511979,2b845113,1b32663e,baa14c4,20a5408c,1f53afb2,43cd496e,c4b18118,40bd602b,d740096e,842b40fd,8304ee73,842b074e,415d5ac,c5e2243,28b241f9),+S(393a8bb8,7ffe4265,51678524,8ac940c6,4aa70e71,512ebbc2,3485596c,a6d9da5,25773032,d2c1f80b,3954715a,6e4132a1,74b4468e,658f6cc,4d5f5d63,d458980b),+S(aeb37eed,35274696,2b85a21c,86b9fe34,60433606,9ae4ce6e,3a8235a5,e43c48ad,d94165e1,5372330a,7b5507f0,377a966a,541b6fcb,949398c8,dd6d6f52,2411d86d),+S(b0bbb4d3,100ce417,dec58f46,95ed8b30,4306f21f,ee11f899,585fb37e,a9905c59,89141fcc,9344e617,7742e31c,42c565d0,45c7ccb8,6f88df7c,5c36d23e,45e51d75),+S(49694de7,330b4c3,1431d452,f3e9e562,eddfe029,1cce58c,73b69cdc,b89e0f49,4715ea3,b6fdccf8,e224b93a,ffdfd1ac,ad8baf44,c5bce735,e7c9b4ef,3faa2656),+S(9a7720b3,ff0363dd,7263e1ad,83c32526,67b67d3b,72c2c14c,95f0804a,dd20f7a8,815a769c,494824a,a819ea,54b560ed,e1df9bca,d7df2d63,aae69c4,a02f9f20),+S(b89c399f,cdb3aacf,99796fd0,95c17cc9,786d79b4,9a1a255d,5c9ee510,38d3620e,ee3c4936,d4f9d1f9,d2642043,d25b21a1,aa32fa3e,ef44f409,73db47a,96965cdc),+S(add68bac,d7180ac1,4e9bbc5d,1e0c3911,f2202d90,1f9ba649,46b06507,b86ed5e9,fcffc13e,a9be67be,8d090a77,9fd9107b,f62bc785,3f98e97a,c0358b3b,7719944d),+S(9bf62cdc,cdabe928,c1ab44ce,38cd0611,135971ed,81ce6c6f,dfc5eb5b,d9c3996f,885b2381,e0e785d3,cc3f78c7,f9fd54b,ecdd9d9f,c2979e23,f97e9bd2,a4f10d3c),+S(bb223cee,f11450d5,c5e0b75d,20eb44be,9d44dcff,28574117,12fc5875,3b839339,8bb29985,87eb6f5c,c8cb615,285d9e69,71db8e31,8d81fd5d,6318909b,8311a00b),+S(9ed73f09,2263e84c,d022388e,da82361b,445f573d,b646cc62,fa0bf5c5,1d33fd27,49ce7698,144e1115,118a4b0c,bdb98dab,6b57dc1a,4d1bb6cb,a68d4d20,d8e937d7),+S(e747333f,d75d5175,5a0cc9f0,a7287084,65a02c58,7737a7b8,b8fa1b8b,4bb2629a,d5001fe,baf8f3ee,b33bc9fc,7fb3da7e,377c8955,91e56965,607269e4,96b90559)},+{S(516ea742,3f956765,a15f856,182f1e7c,18d3e548,b9fdca94,ea46024a,1a8fcbc0,cfddd98f,be500604,28beb901,92c01282,aaf9ed93,76f0e26b,e912ac42,a378d542),+S(8ed072cb,13eb90c9,e5c107f6,ba576a87,ac75a431,53025e6a,86addb95,bba7862f,eece8a5a,f28d356b,f1a84c14,2549ae7f,894f7c07,305194f3,18e30e0c,873fb5b0),+S(3e0e488b,1c8acc24,f81bfa1a,f6761afd,b4fa5f5e,6317ba72,bfba2f07,6c2ff593,2c4ec39b,2f37b948,fdbc9e3b,a3fa82c0,dcfde2e2,57830a04,4c178759,ef5bbc8b),+S(f6b3f19f,cd7eac5a,13630ad1,bbf331b9,5608b7a0,ceaa67e2,4a1e830b,5eed9825,a2a64078,19ba0f7e,7a890df9,523c6736,50ad08d5,c2557cd1,53c6ee65,ef493ce5),+S(e2de599a,879285ad,398b1031,8e1a8387,21a5c4f7,1105469e,affc8e37,189548a,dd977e62,3dc05cd6,3155a71d,d87d91d1,d74d6e31,5f73434b,679b605d,9db264df),+S(bc52359,683840a8,59fc2c8e,22d72ec5,da2493a4,bb5073a7,f658517a,de83f867,76a13651,712ff42e,a0c10f09,45c4ce41,2cc8c4f2,ac3ae446,7cb383c8,656d3186),+S(d87e2b08,154e38c0,13847a5a,2f84c276,dc088b6f,c19a9bf3,90a8a433,fa937fda,d91447f,7c9042e4,6f64a9c6,40a5c294,1a6f08f5,d3eed464,b09b2a1,1c402c0c),+S(4359ac5c,5dd70bf1,d4f24f00,1301b9f6,17d9c69b,63350dad,9a8cd192,655ea801,c9e14f94,d8ec39aa,46092657,5d770426,350794a4,b1ef2410,a9b0118c,ac5d55c1),+S(3ab3f503,29e22bf6,8fe9882b,3b4dc989,36dfd840,be6af588,ab6d61de,48094b9e,4a40c435,9f4dd21b,11664095,4b55e6b9,f0308786,eec32fca,6bcdd5d5,8d055ac6),+S(a0f1ac27,d046d987,b9a98bf3,f770205,931fce93,59b75944,6494d221,dc2752b2,bf1bfdc6,47a15997,97b5b6cf,2d8a2a44,e9c36b9a,20b53abe,58ce9e0a,395fab70),+S(a9aa63ed,3b0260d2,b35b030c,7a5511c8,679b6170,b8a4f386,fae0bfa8,92735905,2f654620,4dba9b31,99bd648c,cb1605f7,62f312d1,67123d98,ed66f02e,4d794e90),+S(e51da157,5e566ef3,bad3fa66,e55432e1,29be6c36,32e390c0,f4d76719,bae34b7b,55930b79,2ffc91de,674820b1,eec290d7,74ecd79d,1ca07d6f,5ea2f817,4759984e),+S(8b69a891,b417ea65,7ba52bae,58920eb7,f101bb92,e150dc1b,c961c37e,73cd18b7,5b824edb,f4a68988,39de0d70,ec16ee1c,a01a4692,f29263e1,1069aec8,6b149214),+S(ee5c1186,77462649,6d37fba,e48e797,dc69f31c,d6ad22cc,937c7224,ef7ce8db,13f7987c,f2cc4551,e058d410,3d5c24d5,13c2d602,ddccadae,fddcab82,d14d5310),+S(b961cb45,5de8b5b6,c4c5c2d5,75303c81,35b5d278,503a15d2,371b0551,5b236b,3ed18486,5ca969ba,31c734a,19055129,1cd664be,576925a3,2a142769,4fc40df2),+S(83effa4,c127b5ad,7a0c53df,5be5596b,d4a42987,2eafd8f1,5498a6d2,47b87314,efa99759,c9360b14,7643de2d,64ad07ea,39cfabe0,2bc94e00,dc9b2e70,c2e2c217),+S(f253fc52,4fb0254e,e772f50e,5d6c16d8,48692455,c855d4be,15ea9f9e,9a5411dc,59bd1f8,2cece609,8a63fa1d,48e4166a,d79174ec,5f8216c3,16c48c1f,e5c9a0d7),+S(6b61024e,e6451d97,1446b55,1476c3ec,eb6b19ec,16155acd,317bc2be,11086411,8de5c6e,37b562da,ca5a203e,ea028b76,e6befaff,e54b49d2,6605f169,592242cd),+S(1691a90b,9cf72621,3680a72d,af59ef24,985448ff,5f35372a,ab6e2aef,df8b33e5,83d2032b,6ca761d1,286c1348,31250054,5a230558,cba391e6,f0db9c9f,97c2d618),+S(42a078dd,cf749f25,aec7a1f2,8e976f79,e268c36,a7b5b0cd,6aaee3e0,925746ea,c60f1846,6f025987,e0ea6ca0,3eb98df6,99389753,b57abbf4,f5739509,bfd09d1e),+S(21bfc1a7,16b09543,5142c31e,5038d4ea,4643d9c3,2fd4728d,1374dba8,1ca1f07a,a991d491,2601ca23,8e289e71,e9d743da,4385aed6,c732f808,6dc21406,74540acb),+S(e75223e8,fe247a98,5220cbfe,52151978,c98d1460,746f8de2,8696d235,71f3336b,dbbb8075,ab489582,52472982,c7b0c3bb,d82a0762,36c07c05,44417ff3,883f6f18),+S(7a756a,72fee88c,7a2758a5,3294da85,6b06129c,1978e217,2bc7952c,92b05265,c4ad3a0d,be72fd27,bfa475d0,fbd16a92,5e939362,bc0748c,c39ba9f0,3ad84133),+S(2bc697fa,d947fd62,63bb2841,1a274520,f5d582f6,7f039114,293438fc,9aad7c82,543109b9,82097efc,cb44d854,11fc5230,6c7a219f,2f58b37e,3dd354a8,2ffb28ad),+S(3862db95,1ed8994b,a8cc0178,f6dc97ef,db6e1380,c18719ab,cd24a88c,87039744,af1e8ac9,2b195d3,6fe1b1be,a68e9215,a453e638,67e65d88,64a8baf3,ff5c1267),+S(7b648cfa,40ce7274,59a6fae2,2836ea1d,b18ada4,9b18a61d,748127f7,7ceee771,f2a30c56,42887135,30124a69,da2c0355,8688bac3,dae6d95f,a252855,a85a9b4f),+S(f803d7c6,1820f980,ebe0b297,87aa688c,ddadefca,229b99b3,a6bde5e9,922f94d2,a5f8b450,34dc7de1,461dfb74,e7ed9c49,80407bf0,4b0d9159,af703a9e,1e0f9c61),+S(2247f630,9be2f3aa,e30c5907,c29095d4,b9198d25,1a17bb34,7cf5cb35,a2ecb1f1,82685964,20d87b07,1c5a4044,b79b069f,7fa6ecf2,cfc0f839,b2161475,5728c2f1),+S(1d770ace,ceb2183,fea7c924,a8fba197,579df37a,908992be,d42c8e80,8bd98ee1,d87077fa,b910a21,8769cfc7,49aad579,c809e35b,f1c2a813,6047e85,e2c6fc65),+S(5d134e5c,5da47f7b,a495f216,b4994d90,4a79057a,3d0076be,34f09013,99f1f366,fc4e10b2,c1f7bafb,d241d5b5,1c57d48c,30fd29e9,df5774c6,1d4f2c15,3b66ed03),+S(a49ed10e,aaab9323,3a5f485d,4bd18c06,28ab2629,f0b8c3db,4d05956d,6c953fa9,338d476b,99f0ac67,1fcb893f,5f202204,a5178acb,6971e7e4,984d42dc,b904afbd),+S(4d000b62,1adb87e1,c53261af,9db2e179,141ecae0,b331a187,aa4040a,ee752b08,95f2a470,e71f2daa,34927daa,7d268d33,34820a0e,e638d6c5,c18d7adf,b7cfcf45)},+{S(44d42980,eb92b3e3,b16816f5,56858355,e031b88c,99117385,def6599e,f274e56f,6e3de5ba,4f693fdc,747caacd,b2cf0107,f29fa7c,9c6a1a09,a527cd16,4c2c1484),+S(9812d508,d6da303,6f08fa7b,54cae319,232f925d,6af91d71,fe6c2fb3,bc86be5,735081a0,35fc17f6,7547b9b8,f0f91ac7,f0ddb965,19f6f398,dea745a9,81441e2c),+S(5a022ba,a90ddc87,42246783,4f692ecf,dd2c2dcf,b054308f,4afeb17a,7ff6ddcf,6fc2a9a5,4c7a130d,fd26ca48,82406fb9,f67db0ab,7e6a6d95,1675fef,2e2d4256),+S(c181ffeb,a8ea7d69,c524cd42,18af3030,1cac8e97,69eaf6f6,ba73027d,30fb7bd6,e88959e5,b07b7d3e,693756a,f94590bf,997763b,afa7d850,a80dd9fb,88e6e904),+S(e29375b8,21c056c,30954b81,4f9ce795,c1493dfb,ebf06f6f,f32c92c8,c74839f1,a9040ad0,95c9d45b,1527c624,bac86841,a1f28b7,ccf8dd37,b7e950b4,858e6e18),+S(69445948,ebec5ae3,9fcb505d,7efb7902,6bc1e8fd,5d3024ac,2b772439,72142d80,5b6c2694,abac3938,db899396,62635c21,e64fe2aa,40d18678,9c246e9,fe3f4be6),+S(a86f3aad,85d0bbb3,8270956f,58c2fd65,f5425428,27d7a658,da1b111f,64c02c36,dec740b0,ee35208c,dbec5b7f,69bb94f0,7fccd075,7868a37,6ecec7b6,dcbe20e0),+S(ba2bf65f,aac92da5,6c252b50,8dd74e3e,99ace1bc,42b9d2db,9d0ead3d,b6820306,37bcd01a,75027b42,eb0d7b85,564bedf9,67153930,6fc97106,ab6623e9,90b031ba),+S(78419e61,4e8b5eb9,d09e0c09,79ce4eaa,26271696,fcc68269,4cddf1d9,6a4c7fa,a32dbb3b,46f9b6b4,9adf4dde,f1986af9,72662a6,2ed6b6a2,f8b920b6,82b32363),+S(71163271,204207c8,a84b5993,88beb505,640898ab,b24c4c10,42195dd8,15d77985,aab43609,9370f246,7035ddc2,e71d73f3,c0f1aa13,148303bd,840459da,ae307e8d),+S(473f52a1,fb7c3920,f09ba6e0,a3c891c3,3f4a13cd,9dbf51f0,f3d39ef2,d6bc07d0,b2c403d2,4aef71eb,1b834df2,8bc08b67,5130897f,a6d9855a,eb21ccf2,780444cc),+S(581e93b2,99b8c50e,e6338c0f,f426502a,d8699563,f17935dd,abe08a73,6932b71f,46e7c7c5,1e076fd8,9b8aa98c,f0b3933b,8ca82cc4,d21783a4,d74ae1b6,ca9896e6),+S(e65d9e24,e7340122,875a9d86,d6071a48,691ed5e5,a94b315c,76f169f7,f3d69c48,73575103,a70b7a59,90d9b880,8698b651,271c8c0c,ac93122a,66873bf1,fa3c6fab),+S(cceab216,41d0597,f9c7ab64,7f99154c,b22d4827,70395d6f,ddd6db5a,dc752825,4084c57d,5aafc328,e7a250d0,a7c3c0a9,627ddd70,c77c2be7,e5a1af34,359b9b86),+S(4222ee66,5baff421,17f47df5,c1c1df5a,dbafb790,d5c75bb7,2646cf85,7ae85923,43088d6c,a029903f,f5a789f8,16730345,5a5cd0af,cab57e15,12781396,fcc9b6da),+S(391c5d0b,17a8c11,3440cd30,83434841,969b0833,71758b30,27e38a25,e778da6a,69f3d295,be55f859,4bbb2fb4,116de5d0,b24b5a80,ed62c1e2,8fca9b8,3f6d7439),+S(803b7149,f87e86c0,13599898,b0c9050c,d4a6e030,e07e8d7c,a49c46a3,8a6ea6a1,6b367fcc,6d5916e,72f670a6,5ada9c39,54800e90,a8830fad,c9ea17c0,494cd9aa),+S(f7aa1c64,f8f92f20,1319f316,353d89bb,eaa4d65a,e148b01f,ab66aff6,c9deb179,e9b407d9,4c2b385a,74f22eba,93dc35e9,bebca7d5,17401b7b,576b7d2b,e13ff0c0),+S(f1c34d52,2b7493ec,cefd49da,99732e00,85ace2c9,fd14e9b0,69b67dcd,5acd5e23,29460fc7,dd77494e,a5a7764c,7ca6db5d,5d7a5e3f,65e865b9,e5f85d58,e77713e9),+S(db19a1f6,38ef7034,5340e3df,8d384944,7500640d,cdbc3be4,df3b191c,edb9db87,baac873,a76e0b91,c4847770,9dbe88e9,6195e9c4,ac4d7749,71ca204d,4a5e748b),+S(4ad12e00,f384c7f6,ea669c71,3649da6,55e0abec,67551a58,224b9f9d,de6bdaf9,2e0314a,8e3f32da,33a22ecf,ccac4965,1f1f6f5,20baeddf,39a02bd8,423cd40c),+S(c9130b88,cd451d4f,6eafffc8,357ba391,ae920c27,69e7c48b,49881070,fd088ad5,aac7c2f,4f2f8b90,bea9267,897e0079,7d6515e1,937fa4fb,1043111,6b5e1de),+S(88260ca,df81b391,be79bde7,b54f8a98,428aeacf,970cd843,d683e6e9,50686db9,3b9b187a,b998a22b,56b2933c,fcd09333,9c23889d,1180e365,10dc086,9869cf2c),+S(3984fce2,ab73c70f,a5538206,c2a61e60,2f160b1d,2eb61980,fe174cbe,fe464dac,b7e65c1a,46b50c72,621e3fc8,4f4c7cf3,6860567f,abf00743,5fd1b13f,7400326a),+S(e6b48495,c8277598,23b73f35,762c55fd,8cd20420,fe5be6ad,f27f12b0,68bdd63c,ccbb7124,3b0300fd,993dc9d3,4b55534a,12515243,e07ab78a,8d8fd528,46e5a69b),+S(6af5144f,342f492f,3f506ee7,fc515d3d,d3c93d02,27ba841d,74bc6548,97d4830e,b195d9e0,8113eeaf,fab92a2,81ddeaa0,95356053,a51cf84a,b5d60fec,5368f98),+S(14439b7f,e40ca407,374da12e,217edd9a,86c84397,e2fcf6fc,965023,ba984a1f,112ad656,47c47c30,f19ae62,e0c06b35,effd49bf,d5e604d,6d621471,9f088fee),+S(d4a7e4b3,863fece9,660baefc,ee57d09f,6f60cd25,f4aa178c,cb6f8a17,5fda9d4f,4985a973,ab0e8627,f6de7ef4,470de4c7,1adecaf9,f3766197,a86f4e40,14ea474c),+S(facc2a9b,9d3ad0e8,9fa479e0,ba777a0c,90a0c229,59d4b719,a9304df5,f1e96ff0,6e12c914,70c78733,3e5a65b9,8c01d342,827810aa,be3e4e33,cba0b7bf,eb283b91),+S(3d1b3f54,2809a7d7,79ca2416,a7b7d007,4a728599,e4f30cc9,14bbbba8,3daa091f,dccd0d01,e56c7e6b,90829ec1,f0fc733c,8f1cbcb8,79916982,3b466448,cc21674e),+S(a8c1ec56,3cf9596,d761e41a,bd6bc960,562eeaf5,b54eb83e,3d7e7259,f69671d5,a03c9fae,e160ba53,8aaf38cd,96ebe3a6,db59a04c,ce7074e7,dc3757f1,ccc244e9),+S(219b4f9c,ef6c6000,7659c79c,45b0533b,3cc9d916,ce29dbff,133b40ca,a2e96db8,db2639fa,26a61015,a5bbe7f,3fc8d591,c6b0753a,c16fa89a,d820fe57,72c49068)},+{S(b445babc,55be50ee,bedb8c27,dfc6c37b,492649ef,8a65de02,111b9f74,29b8c3af,6f74c5b9,f9a022b1,8d3a706c,5c608b31,9f7ce25d,8424d893,4cbd2f90,84b78bcb),+S(dbed76fb,7e46e1d4,1b507edd,8994fefc,f94bd651,a9720d9f,8d62dc3e,9f329104,c047fc1a,41689ba6,9855f063,c563bfe8,49bd8b5d,37b3836b,d8bc57ca,fd02ef64),+S(844426e0,860ff2db,f012ed29,ad2919d6,f46eb102,68073862,c1792e99,f1b2b33c,243512c9,c6ca739f,fb181482,a901ecc6,a41893f1,371d6b12,31d5427b,fb486394),+S(1df697b5,9a2f9c91,b2c5d4a7,8035ea2a,351dc000,4e1c3bd5,5973020c,24836aa1,e89f949c,f6af652e,d7e79758,74a994ff,46475df5,4f7b17f2,a5c29cd9,7f722831),+S(cf4ffa86,87d9a39,7b4727ba,a033cd02,7d8a5377,46903db3,34c35f1d,855999a1,d1316b65,e027ed02,b4be11bc,4c21c1a8,585bb247,45cdfa67,5fb9cccc,faf0c546),+S(e3eed1d6,1813e3ec,d1b9fcfe,3e8bd700,bf3412ff,78a0a9b9,724d4dde,ddfd98b,dcb09803,b70d4c34,ee2bd7ae,6444724e,9ab27c20,5c3c736b,172af37f,cc673105),+S(3a202c1d,94a94eef,18fa396e,5cb8a867,8c3ae45a,e4ee64b0,822d207e,6c814fe7,147992e5,ab565bc2,ad1b1355,60f37dc6,b5cbee74,fef8e5ca,4e4f418f,811a0482),+S(6ce8f558,a853dacf,205db4a5,80c4cbab,8ef477a6,47bca6cc,9e676cb6,5f3f696a,e88e3934,b2857ec,6edb911f,acd132fa,f0078971,2805aa59,9afb3d80,942dc23c),+S(7fef9aa5,b2df37ac,99ca488a,ba598b4d,eb222149,55e1cb4d,c3ef1e7e,7bd38945,d4b7cb4a,8f9edfd2,3a0efd1,9882baf,98312b6f,7b5775ca,65e9dbf1,f2c32870),+S(6ec1ce91,d1eff7ed,9beba2b8,2f4a526f,736e717d,6442dd29,b55ae2e5,3371e0a2,28240ee,12e2b1ed,b40698e,ba6f087a,145eb772,caece880,b3e94b97,700dbd58),+S(645b9fba,2cb739ee,9b148b29,8fbe9884,f284893d,968c21d9,50696d2f,efbbf0bd,b06977a1,2d19836f,add50b7,b73399bc,698729fb,fd182026,d918a267,eab4b7c6),+S(7b930561,3a4a7cc5,ce1e7f5f,29314e1b,40bc8b93,40604f81,76578c18,69abf6c5,55a7e3e3,3f19805e,b5056d15,deaaa4f7,aea07a46,f9dc6a09,6ce15392,e146fb3c),+S(bbcc74ca,3697ef46,e7415ec6,b31a0808,1e6ade01,c7e2264c,f9d4d94d,d849ccaf,27bf64e,e1005f13,989639a0,8772c42c,b4249ba6,9d90cae,3f542ee1,78929f26),+S(4a45fd82,af96af67,9e640bbf,561cb385,2585a8e6,1b57df7a,e028ed33,a017c680,4ba76ea1,19a0267a,f019b3b9,89cde9ce,7b1c0b6e,da3c773d,ca31e44,61e048ed),+S(c3efb1ce,ddc6a749,a5db9daf,48032a6f,3f1a848b,aef9e44c,ebd76127,a9c90d0e,3de258cf,e593b489,8f92e8ac,50be894c,3636019b,a9f31f70,28468eac,687b8f89),+S(ec71a2a4,6f24acb2,8fda6bbd,ab9326e9,6590a96f,b9b9a4ef,405949a5,e3d2858d,31a91fa1,71207da3,1b0acc25,cace1e7c,5126ca2b,4c8d9733,4c50a7f5,29bc61d2),+S(65dc268e,cfd191fa,f07421f0,dcb16701,f979ad24,81ac5ddb,1f77d3ab,41a773e0,f8c9ac90,255d6460,15ddd1d3,57b92522,53bb55c7,e2f5d843,d7d9a025,2766d2c0),+S(62152eaf,df564900,4379891,4b53ddd7,3b91fb60,f16f2d18,941caa96,18d8ffd3,3a185ef0,a8d8a35d,112f678a,6a04a654,df565a8f,87e99abd,95fb4977,1b278ce1),+S(f68e6fcd,b2c49661,ae59bff1,f24e97e6,fffe7cfd,f185d0b8,133d58e3,bec1c89b,223dee27,5e9cc518,af12be21,ee7ef3a9,ab39c7d4,4f950fdd,9ce5c78e,b50514a2),+S(5d02e9c4,108860e8,2b1ae04a,4afbe1e2,9e0a8444,89876776,7e5b60d9,3fe5c753,25fdcc35,5f1970c1,43dae96c,a1ef0a7c,f95853e4,102548f3,d869d3d5,8bcf962d),+S(f6217e4d,4e6d06d1,27668a01,8225f88f,a1e0fcd8,e8654fd,ab26c8a5,4c6d4751,65a6acbc,19bb2835,13eea5d2,5fae521d,aeed63ca,50f9aed8,edb74dd9,c43d066b),+S(c18bb768,bae77077,35b4d3d0,e82cac24,fe3d7ee8,dcba20b6,a320ba6b,4695a406,b7a7ded3,a589153f,8ee504cf,fb5b45eb,b2d8e121,40f2f475,186153df,1fcf84d6),+S(36fc443c,1350b40b,881e41c4,d3c15952,31f8da9f,cdcac4be,f1d0c5da,ceb9844b,9843bb7b,fd0ebca1,762785cd,55669233,16c36aa2,d2c37b3f,2b196f78,bfa5830a),+S(ba7b8c09,d5293e6b,a2548e6f,ff3c939b,80d2ac54,34903039,dfb8b661,29e19cfc,54fe2a,9353fc1d,a0d34e07,b6d34d1f,f3a1f67d,f4aafa7e,57919142,95c2a5e3),+S(50a8ddf1,17a91c92,37a48fe8,f1a00e72,a5dff682,7398a4c5,d2f78b4d,d49ee339,f91d9b20,da28e51b,99fa102f,13f5e451,ab22e139,80052384,6b9c66bf,b7da1578),+S(642ece53,832d1859,c6543147,56b618f9,520a5888,2549277f,6b27f16,e08e3d1f,d9963beb,2c6da204,339a49c5,f253498c,48cc3e99,b715ea8f,a5eb00cb,1d6cffbb),+S(a68c0d3c,13d764d0,7b513390,5842c9,a7171e4f,755a9737,609db06e,1a44e5e0,a2c3fdd7,b7938a87,86f3756d,dbc66b29,72469e79,839a1448,b367db5a,2bc52c15),+S(5b33d730,288fde53,b123fdee,177758b1,ec113adf,74e79eac,513eadd4,cef377ac,1bbc10e,9d45cb00,db58fceb,bc4bcf4,a0e2bcd2,a7d3ec12,7d87beb7,a134a20b),+S(aa6dc4d3,ce531af3,e68590fc,acbe7816,c8293af0,d77914a3,c7119e23,e50ce56e,14386670,5dbe1ad6,91e09123,a19a199c,3ee67b25,708ef57,4620c5ca,821224f6),+S(180a4ece,d74ceaab,e0f7db3b,b038034e,5e659c61,3c66a534,8d962d14,efa32402,b675b2a8,b845281d,524403d0,db01417a,59fd3a6c,80232e74,cdfc87f1,3b76b0e1),+S(3a55690d,abb5e00d,c2d0d8a4,96d16c44,76ee767c,a9d0d1d3,694c856e,e5b7ad0d,3c1d71e6,8a5f9a84,4de0453,6810660c,fe353475,353cede7,2936786e,4d173828),+S(33b35baa,195e729d,c350f319,996950df,3bc15b8d,3d0389e7,77d2808b,f13f0351,5a75fe7a,9bf54078,6b9bfc9,db72ad43,559a9f10,4377648f,d43afc32,34728817)},+{S(52f79560,fdfadd45,6165a204,6bf61bbb,726cd726,3a3ed2d2,45f07631,5b0b6ae8,e6c46e55,5b4a0410,bf38965e,5a7ba381,fd259482,2280482f,877a7ec5,84d14012),+S(29eeb07c,7b27f82a,1b031881,11d324a9,4df77713,a8cadb36,2ce4012f,52cafb19,b7538574,28faf258,f240d4a9,f464797c,dffd0a68,f9f978fc,476f9bf0,1a0a2df5),+S(2191ebbd,a95c29f8,e7062f21,a70cb368,ac67ed59,dc44b167,66e52120,cfe8e742,2812f1fe,557496f8,f21b1f11,2df7bd19,db6aad90,59494ad4,eaed4d77,49f66a4c),+S(3c29d849,e25364d7,576779ec,78755ff1,8aa64e2a,65140a2,bbcf22e3,da33a4f3,3658d9ff,e2e283c,f8973cc0,ede5af6b,69ac4970,3c6b1370,f6a2ba4a,78a28a97),+S(37230e16,e11db299,f54ca0f9,f5423ac6,5f05840a,e166175a,ff0732be,c72ba88d,2a26ac2c,e8f9ebdd,20f1f5f0,f628d3d,d0e02745,6132cbf8,78b614b4,51db28f2),+S(8fbb3be7,98e16bfd,b738a512,ceeea92c,1be8eeb8,5374702b,e927c614,ab1f1baa,8280f387,64a48061,26392be0,c95f0c58,3607343f,d0b24b98,afe3605b,8f7e79f4),+S(fb639ee6,29dd1f03,8e12330c,bf40ec7e,129d7da7,655c1c21,86452fe4,9589c89e,171adbae,2efe213c,8d01e273,ed9c5d47,c4e85503,de3849b4,d909823a,bb1da898),+S(2399064b,876b7584,8c977bf8,e35d6b32,2e45d1a0,c4243fe1,2a31a581,d1d5d826,79c1ef29,c1af9497,f3b3db13,17432d42,86fa014e,17e5d780,a0d39df,b61369c1),+S(dd5663da,63acee49,eb7fde29,6ac1215a,772512ee,6a080f3b,1266c7ef,51da5dd2,d19c7348,3754112e,9cb3a4ce,8986f748,3eba26ab,c415abdc,5effc956,27efb7dc),+S(30862c58,43b161ba,c127bea6,7b23d3cc,46b6c42f,8faaa281,6ae47092,8ae47993,44ea1101,26a7c448,dfed4995,46a0fc8a,3658e540,d7d0c2b4,18f8cba0,accf9537),+S(df7ebbdd,4e416e4d,6b1e67aa,34915da2,cc15bf8f,f6d79ebf,273b63a8,32d6610a,d05fddd7,e9618753,21f473b1,bfb5ff48,65b3c4f7,5cf4ae26,549989a9,e13056d8),+S(13adba8d,2485bda5,1ac7994b,c45a7e4a,1b21aa9e,8188e631,59b217a,29d4237c,6256a795,3f24b25a,c1f59384,aac3eabb,4458e504,af3b99c1,99ae614f,8def4ff4),+S(c160f7ac,9a453a1f,8811d031,9849be43,22d8bbe4,89cad7a9,cb815927,d4b54720,7958b41c,751ef3a1,fb985ea9,c7cc85f6,c16282a4,c374fed,5999d8d6,3227b720),+S(c66af931,82a7a9d6,588e9c7b,3eda3b49,40fdcb99,346aa55e,e6549d4f,f9382228,ffe4d0df,43f00af4,fe885b10,92ae38fb,97d21a8d,26aa5f69,9751d52c,a9ccea4b),+S(d3a4f4d7,d208b43e,c4c2fd00,798d882d,922f302d,a199b707,76a70f36,5ff404aa,8df220d9,63faa827,1c4ee360,67a536ab,25813239,82252483,311616d0,1458e1b),+S(47bdd428,d57ed451,cd8754ea,817c5f5f,9658274c,ef6757b8,70527b4e,96f372f9,fbcf0ee,9fb14de6,3c288dbd,b1888fcf,72f0265d,3fe2209e,12c85841,2c375b53),+S(6e6deb95,7f2eea30,5d625288,3cb311c7,f0365a42,480fb807,36315c4c,62495438,ba0fdd63,9b8678f2,ab0fe3e9,a16512e,ffd9ec23,e691cd4f,86146969,534978aa),+S(dcd2775,7cd691e8,28e21987,d6eb6b54,e8def24d,27238cd5,dfb36a3d,d0f05caf,40bf37e7,bd776a62,ab420209,c71df7df,74d185c,f0d6b038,dea9c8e0,c1dad163),+S(eda569f9,9bccdc21,580da94f,92d89312,cef87d13,f08d8ad5,f1574e12,30a64ce6,4e1da1ac,dd274e3,f9d7def7,746f0652,678e549,ad5476d1,410adbbf,aa3c1e42),+S(5d3d4a29,734fb7ad,2846ae12,4c803364,ea3d57bf,e8d77d9e,6a3b3f8c,9cff26b6,d3e598a7,1a469323,a357df08,319dcd1a,d7337a32,c9894b80,6a30c575,b19756b0),+S(10161fa4,61e87595,f269da7a,ae3ccf01,40e910fa,891276c2,df1bd91a,95e4d046,b36eb5f4,b8291a01,18691f1e,50235d8b,f66e14a7,f0641dd6,18ad7ddd,ea150196),+S(7ba1b276,3df207f3,cfd1d58d,5190eb91,99cf82f4,9d2d0927,f5f260f7,2ea0f178,cb9fcac,4be96ef5,3134f513,5509c178,99af24c6,4eabd650,afc599d8,3927969d),+S(4bd6edd3,aaa1802a,b0f46e05,418ada37,e75728e8,6ea4b293,6619c92f,57674dc3,c9e962d3,de71eafc,7fc9a329,3bfd721f,305e876e,a2a4755a,f9567dca,21aa3c0b),+S(95fa0b32,40b24ba,29a484d7,f8f022eb,b3f30349,9d8abc1,9a69b690,3e885b68,dfe6b88e,56d7b923,dcf8bac6,2241d663,3ac2ae55,c3a01fcb,9f966d62,8f3acadd),+S(d0fd4d10,18c37114,2d5f8a86,617c250e,b6c3d5,210ca465,6ec84e87,d0ae42b3,4e3bf443,290404a9,3af38e72,a54fa06c,3b2d6a81,161fc8de,554edd9b,f3399587),+S(992e1183,d4e7afde,166c45e1,37c71c88,d4039709,4262163,b4ae38e,538293f1,c29534fb,55e47a08,ecee311c,8f0ba4c0,39096edf,b2d7ed63,21a2810,32e85900),+S(9c124ecd,4e6ce167,f60dcf38,25976f33,64cc30ff,61f7dde,966f8c23,4c13a4d9,7ad73bdb,e0afe3c2,c89d9135,d445ba4c,796066eb,1909349,9e6ec14a,f74f664c),+S(b09cdc9b,d102f89f,bcca0ed5,888519b,7c5c02b1,64ccbfa0,3d0fe42,b1b113e4,f409865f,6ab4371d,f52790eb,88df67d,84b3b74,f17edbc1,29b802cb,d5e49a59),+S(6b4f628e,beb6d619,1d616e87,3233ae37,ca4cc3f2,ac881e59,9c2c8e3d,295ccdc0,1140b988,60f4ac7b,659eb012,6fdfb796,c0baa652,2202cce0,bf54b3a4,865f171b),+S(a728c830,10169439,3af3f780,b1ceae3a,6ca08ea,4bdc7554,2ae84564,f542c28b,7b68fde9,8c97db32,eb3cdbd7,15816e51,9aa58458,259dc74f,5d722dc,f48f1933),+S(21ce4401,4ce959de,f16b3912,e88ff48b,d44ef79f,5fed2d35,bdd2dc78,de8f7605,cdc598fd,c5d30508,a2690299,e0e25b91,b1ccb69,97b99fd3,eca1baed,76aae6d0),+S(89912259,11b9132d,28f5c6bc,763ceab7,d18c3706,e8bd1d7,ed44db75,60788c1e,2574b267,83365364,d84789ca,a64ec905,c969637b,21061ee,9ca3bddc,7170ed3e)},+{S(5914f66e,28c1a0a3,47f461d8,1d7f2c55,845e35eb,3dc39945,584b5efa,8d71a215,cd2ac885,3f681e4d,884e308e,ed3ca185,b47e2d63,3fdfff6e,efb6dc67,4d7de056),+S(519834c0,d16c807a,7867b8fe,c99dc93c,3b9ed218,87a9ca17,9343729d,3ba9e294,b867d57e,fe2dd7c7,8586303,152f02fd,f67b5648,78a7727a,190d304e,64f97203),+S(959eda70,cbabcb05,fa8fae96,7227b6be,876db942,ae38bfea,a9c3d359,977e1c52,86373396,9338053b,b00d206c,5d67abd,f95d35e6,992ad69d,8d8a3322,7370fdc),+S(a40279c8,48dc042b,a3ee929c,2910e326,eded6051,9d9eb1a4,98fdd7e1,fc88a6bd,f2c962a9,f2950d2c,acbfcf29,35bad39e,2709c0e7,36378968,fa04d957,1dadc4ee),+S(650b8181,edcfe46c,eea03ec9,f8ee5af2,c288e618,7d634961,6c95554e,25957334,ce140ddc,c2e2b07,a57e5627,62da3eb5,ca1acba5,463e97,fff7eae3,55b954c0),+S(eb04688d,5f4c8d2e,4ccd509a,3d003b30,8c5539b2,dd160a45,cbe71efe,36fd9005,37d80690,2062bde0,b96fc8ba,7a7f751f,9461f774,a1d6f3e8,8999c676,a2ae76b),+S(f79206b6,7813cd64,9f946313,3bac4aca,3762975e,954e0ef5,a876b78e,4b5a5d24,6033d4ee,936e956a,af117dca,6086eb1f,6466ab18,d503503d,4b011315,365242d8),+S(539c99d7,728cf662,13e024c0,9f1226f5,ca5d09cf,67bac12d,47814b2b,b1e7d611,87efd14e,e58fbff,5491bf85,aafd48ae,6680f37,e0d928f0,13fb6cec,6f417f76),+S(2308281d,e761f602,66fb8228,45eec88b,e32f8fdd,4a06b8b9,3dfad9c3,75d64a8e,933f4071,e4f2a9ae,95f4a299,f4267098,94b661de,c96443c5,f03f6cb,f3be87ed),+S(a93d05ae,fa31c0c1,54c02f68,9184c1ff,344c670b,e13eb304,2de517f2,1f6124ed,b7549c5,4651fa60,61f4103e,27d316a5,db531e3e,d7396a46,e360341e,f53ed274),+S(35717dcb,4feada90,b039aa79,10cf064a,c8c998b5,fcbb037c,22bf9e92,eba560d8,b6ff9371,d98bf532,f82d7fdb,24fffa69,2afeb0e6,59ba30da,602b3399,2bbe5a5),+S(941d37ef,1671d5f5,675be9d0,d5cb1f0a,ab6dffdd,2bd342c5,c5b62be9,88d5a0aa,4834d5ee,a8f9ae8e,ba5cc8b,2fb52260,33e35767,d55b6aa6,d204e0e1,a38b42ed),+S(c22cecb,aff78c61,f6e34c9d,9367c4f4,1acc9c35,29e9d894,7989a874,1d70bccf,38a37fb0,5fd9036e,762e2f0c,fef8fcbd,c04a92a5,4cb72ee2,ba08213c,4b58f1e1),+S(7863ac2f,1704fd,5015f0ed,30edf5d4,33c5ea2c,e150833b,a15c1db8,a5e4d2f4,7468fa15,eeab5653,c9f982b4,ad9e4c99,2f44083f,a7a93e9a,25ff70e5,b8742b4d),+S(f702cfa6,f0cfd275,a2c7af50,b53d0c94,bb965063,c433f4f2,cfd13d99,800da48d,3da4a4e1,bc5f2c6d,2f8daec4,599a9704,7c1b930a,b37d6b2c,f8a586cd,ef7dce1),+S(c3a1da3c,6e6b8f2c,2a8eb81a,1875f2b9,1e9cd286,414862d6,57626b47,a413d7dd,983d0892,5983d42e,bdbce2d8,df116bc2,f5cf8c87,aeb833da,e5e7e9ca,f9699798),+S(df0a4106,d61fc3c6,b2a14ecf,ebea3dcf,7e38069b,8faac576,a0b8a1b,7c8e7b5e,dd97a06b,840d64db,1798cee4,9334b033,e8d3f4a,79da565d,c6130da,f0bea75b),+S(ee9901fd,9312a21c,879d4e1b,24d5a299,b8200a15,6e65e147,4a2055c8,a2363423,1bb2933c,8b10f8e8,ab93ecee,16f861ff,a86781ea,59b891b7,740fdc2d,f6c206d),+S(52890b99,c8dc48c4,b6b1e4ae,5b823fca,ad9495b9,8217fa4a,b4f8e960,77cdaf9,6ca2ba73,72606e82,9c3395fb,dd2e4b74,8c771231,e86fade,5e2d728f,e5e7391e),+S(a372b545,bf56b58,b7c4628d,aca9bc14,e8bc634d,d79d139d,8eb7a2d4,13465c3e,afde23df,fad41c68,df94abdf,90a642b,31d62f84,c6254c4b,4cad2934,376372f2),+S(89d02f41,f88b1f7c,90b01078,d7599a70,a1eb9c23,1059e856,4237b0a3,2c18010a,7e8e810b,b063d75b,c224f41,a842972d,6fe065c2,aa6b16e5,7bf224fe,e44b2275),+S(7ef367d7,23fedacf,86425861,f67c5ba2,2deaf04,69e31988,7a3a3a12,2f39576a,4b81e743,e00bfbc,1d98cbc2,5c98c516,55e574,fc7fa1f5,86f15d9b,1b5b7ac1),+S(2eec37a1,5fdd1caf,b4c0855f,e86c5534,1a78cdc,b3944798,311b1cf4,7df768ac,1c18cf5c,1a98fe9,70d1e635,ab133668,4e0d964b,4df0b16d,7c51ea01,c9a63),+S(72208b8c,fd9840d,76dfa6e0,f36cf57e,502f285b,422f0ba1,9b119500,6b2ddd11,fa09196e,a89ce6a,888415ec,a8eb92f4,149bb39a,50174a85,8a29bf63,65b4e577),+S(9f46479a,69411d57,c3c7ea6a,dfa833f9,1fb2109a,fd30c790,2ce323ae,4b14be0c,6cd6d7e0,8494cb95,9e67c258,1be426f6,4eee4514,83e9a9a1,278b073d,758487c3),+S(a9aaf56b,5016db58,5b8116dd,cbad1169,4b16de8d,9db5ea5a,279ccf4d,91b1d7a,218fed41,389a4abc,44fb2a83,7016eb50,99c40e86,bb419265,7f57714e,194a5900),+S(5f950f20,b610c06b,76949dab,52fc6149,97d254be,a1330a0,493f1ea2,1d608864,d9098481,823b3ff9,d1c0b7d0,bce90856,186b45ec,6f20da26,9b158283,8a4c96df),+S(ed621f77,98add722,b0dc5e52,9c6fec6b,dff60827,b0b12c85,18d798dc,761f1075,a8973e79,a9caf1fc,e3165145,df08b7db,6b7187a5,28b12712,6c62bb5d,4f0c46d7),+S(15b8390d,652d7338,e18ee091,97e0e176,74f8c4ba,fa2e7b85,8f5badc9,9c89240f,87930df3,710172f7,c5422833,385a6066,4cfc9854,a3e5ccca,d1d06106,1cd90be5),+S(ac2acb9b,21999a70,540708ab,68338266,aef650ee,d81c5b30,da1e87d8,a8a923b7,897bbd7a,ee3e8db2,e36505f2,ec2614c,9f4f2f40,ed2d85b0,5d23edb4,2832db89),+S(17c072d5,6bdd1382,a782481b,8aa4d223,2db79438,5870bcad,c3063330,a5cd5379,26fe420b,d7c25f9b,1883edb8,50e2fcb0,76a65389,d9a452f2,8351fad,4ef72f0a),+S(8d262002,50cebdae,120ef31b,4c80cd5,d4cddc8,eadbcf29,fc696d32,c0ade462,1412c44b,8ea40bc8,2ce090d2,3c11c945,e2b504b1,8d9874c5,271f5745,f0d9b523)},+{S(ad9144f1,bdcc3673,26d51685,a047ea9c,3c4feb3c,da4b9b83,80e1ada6,300ba487,68003744,ab5b2c8a,cca5bcfd,e1c4262e,88ffbc0f,b0ad4206,2d57dcf8,62c93c47),+S(f3b90a0d,7a8cbf1d,9b994b19,7ce215f9,b8ed861d,d526228,59fe1811,68727bab,95f48e8b,c05a7bf1,e47fdc86,87513ae,5a56472a,44f384f6,1153a954,2db68b81),+S(24af6d7a,99122466,45b07a1d,29b4bb1,a68b5b0e,f9422065,b5bb0050,61d43cdb,f9dc7725,f628cc4e,d4e5554e,f0166b22,566d59e0,4d55c28,a4d0e975,8306c31a),+S(f704aa4c,2bf19c9b,128311c7,1bab5f8a,f2a3865b,728f4838,b8ccc7d7,82574cdf,ae7c46ce,c44d54a7,2e3f758a,e855710,dee6b189,1223d120,9e059620,38d12453),+S(f701adf5,a1bd988d,d7e1fadd,9903c453,e6798760,252579c8,b90cdce2,a046d9a7,db39a987,48aa20d0,5d8b8538,fc4b7d77,95e2810b,160198c7,ad98305,96407c31),+S(bfe36081,c492ed7e,3b91059d,bb1af376,47dca509,69be6665,50f94903,d948ca7c,a1fc9468,2c3dc954,764ee858,822b8c1a,5d0184e0,93f12bbe,21e9931,18911f03),+S(e707057a,297a3d7d,904a615d,ac1b8e81,78f52481,32fa166e,afb621e3,af3f4f34,9161a930,bfd583c0,bfd3b121,acf574a3,6eb534ab,5198aa84,ef38253d,9ca19bc1),+S(27a6c7a7,970a9e3a,7cd42b6b,4478be62,31f53ff8,481791c,4394e78a,968fdddb,e4bf1b16,6bd56269,9e2c341b,b1a51c8a,c2ac7d28,807899e1,3ab1f726,90f44108),+S(e65f799a,8fb3b6c,ad088351,614db5c3,d64660ef,8c977ec1,2bbe58fa,a53314d6,5897f680,253a948e,fc260fa2,8ac39377,4e6a445d,d2bde00e,4e01ff03,b4398e2),+S(8406a84c,e9e63204,761dd406,9651f20d,6fc3efe3,f98951d0,d0a2db9b,cf86e0a4,ef81aeb3,eac17e5,676f4455,b4372ccc,e405b786,f11a871b,d781e54c,6307d1f2),+S(c012cad9,4742fd49,8daaedfe,5b847f34,7a45c792,53c8a645,2192e905,e256c7a1,c4866f98,48f31660,8a81da9f,da112a71,34232f9c,75e388,7ff987b6,8404cd42),+S(73795313,e9de1efe,3d91ae5,15c620c4,4f9c6bb3,a21e3097,c8794710,b2032683,548ce754,93817f22,cb96c674,5d67708d,c7b9b133,c71cba5f,fede1316,c55245f7),+S(352b89f4,78a47e86,b5575fbe,ee1373bc,e93ca316,1f594564,9efaf048,a60bfebe,d784e6cd,88d7862a,d82747d9,b23340cd,b50235c7,65f30be2,ab5d313b,edb0624d),+S(8a0b3d0a,80d41abc,4b8a028c,6c523923,7b040445,525dc345,d2d8a319,c4708316,7b7a427a,f0e1f902,dd1b9bb4,65b6b376,ee68b9a3,f495cffa,c52fcb9c,705443e9),+S(b4bf6756,61462829,53f9a44a,ee3b5427,2485b45,951013a2,8d59346d,62f65894,85d0c26d,2987dbd9,e26c9673,71ca86af,3b8cfb4f,cbf97404,c99ef900,5379a1c6),+S(bff69744,3ac23a6e,574bd1ac,d0fea305,2f05ea65,14814f1c,65e86e9d,5b46a2a5,36961462,5b998565,9324f5f,c8714d9d,57ff314b,5d5c2cc6,99a4ab39,69add4f4),+S(ecb09f5d,122adf91,e68e98ea,d39e5790,27e7c4ca,405bcaf2,e086d4a3,e68242ed,aa214cca,8a601fa0,a92633cd,a353ca02,7a7dee71,cf335af8,fc75de56,a3405f60),+S(310d957f,10fb34ef,ca3a2a0b,35c901f5,35c0862c,68310134,10982d7d,e74af8ae,289cda3f,29a489a8,86121f4b,4e75a90d,2bc4ff20,e95aa103,4044ea80,cff56378),+S(3a5f1ad7,c59ee6cf,e090f210,7040b419,4ca15fa7,dc8e9f69,20825fc4,e012ac2e,8ac8986b,48d7bd1f,5ae99535,2505b0ad,78f855e,d8411b03,15725571,dc99c920),+S(725f136d,1b426894,c24f8782,43fdc1d3,79636a23,d682f389,dbaf71de,d4672067,db0ffaac,ec5ffadd,f32396be,3f01fe2f,45bb0cbe,eb0d98bc,2390f3ca,c3dfec84),+S(b28e523e,6fc68192,445180d9,5da3e411,2fe0db1a,5b3bd5e8,e00a1090,39c69d53,7c172a4b,31339fb3,47db74a6,beedf59d,c24e6aea,c71e2a0c,434714b4,d61a2f70),+S(b808db0c,e34b5607,8166b308,1dd4b2ca,cf9d2d51,3079648f,fc3c617b,8e45ba09,d69c4ab2,fc7e490f,6887f2c2,49e0b71a,746e3e2b,97a7415f,34475bd6,f6dee79),+S(5e0b091f,3144d7bd,c7e40dbc,98c716cf,d7e64eda,ee9c1fa4,6838bcd9,e0c6878f,1586cf7c,da66b005,8b2d0d49,f588d444,65eecf42,1d94c004,a078dbd,47e0bd20),+S(1c3e88b3,ba46410d,8e08f9fd,5db8b53f,8dff33c6,4f5314f5,e005442d,10cef1f8,ba365020,5f85aa9f,71a42c0,392345b7,4a17a5ab,9ff91109,4d81252c,d8c8f72f),+S(b4926018,fb0e9c,e80c5614,37c3f22c,cc223412,384321e3,6f408e4c,ec0d81ac,55544f6e,cea3575d,e81649b8,4950f225,8a94e78f,13325ffb,16debe1a,8387173d),+S(f4bfac1c,b0834e1a,e332b7b7,1ab84500,b1c8460d,c8c2efad,6a5efbb8,ae78cd1d,5faab691,59ce9d3f,6bdb1818,676684b1,cc2309af,1401b5d5,137e1c61,5fbe287),+S(220ed3d1,fe028d87,b96e8ad9,37ede03e,ed8f262,ce877c0a,42718ab9,cb2ddfb6,5ee2d60d,f96a1b8b,e11c9139,7abf9b4f,a0671966,34bf37a2,8d26864,31933fb6),+S(dca5fad2,d045526,b6a4c309,de1d95b5,23f9a7db,e669b558,edd75ca9,40c85878,f350337e,877c9c61,98fc912b,5d53876c,78ea94cb,bbf3744b,62a52fa5,f5ae4399),+S(486ba509,3272eb1d,16ece443,861eae7b,2d8604f3,37014bc5,11267485,9872642,688d4585,9fa732c4,f582d65c,45930567,8c27dc6e,5525d47c,3908daff,f0a534fe),+S(96bc1bd3,b4840354,14aa92eb,6db81f5,403e2858,c0552d5a,6b21d33e,c468f31a,83027873,f4066b5e,ba6f413d,6a7d4d18,d57f4a62,25cc9289,b514f153,91ede3b9),+S(9f131ffa,b53e20b4,e9cd9e33,793f4614,922c03df,7d11222c,7fffec33,42fddec6,c4deffeb,3f4cd90b,102cb6b,3f713728,2c5cdcab,bc6e7153,91ea890d,76207bdd),+S(c15c8c23,d90c8e35,c1a214dd,e2d4383c,735ae45,bef61f10,aa1a1c25,5984cf74,d456ab27,d7adddca,372390ba,1da02845,b84088d2,af4fea5d,3b5b7326,c6334c2f)},+{S(e24b71ae,8fdea24b,2d42a2c6,5cb022a8,2aa9e03a,3067a889,e778caf8,34903fa,f87d5757,cae83263,1233b840,296d6066,52cd1ddc,e8334629,25c992db,7e0ee14a),+S(886a7626,6203c559,807acbf6,7e1631ae,1f6bcacf,3fde277b,ddcd795b,292c38f6,b1f590a1,52d3ecc3,2b699c23,a89b2601,de78be2d,fa11b20a,1ef1235d,93ed9e99),+S(3079f709,3d5270f2,95fee75e,a6c5cd3a,5638ee37,aef535b6,523604d2,eed0d57e,492dd2cf,d76705d7,42187f38,f38982d1,85efa30a,fd1639cb,984a8772,3e912a91),+S(7773469e,c557e3e9,4097bd55,33a87583,a79e3eb4,2e421cd6,592363c2,76641966,f827b0dd,46f4b5fb,4a656731,d827cf21,df1ec610,f36dc2d1,215f33fa,20a08020),+S(ebeec367,eb032a6f,7c421ae6,f8fb56f9,3fcdaa68,f6741e46,1992d019,7567336d,6e78af43,e10c742c,35467149,3323f8c4,a6cff91e,7b1f1c2c,65b21fa1,e63f3a6f),+S(b41658a,3683b512,c751d817,f5d92f8e,5d158632,1f2eb836,b446aebf,d276030,9396ba60,ca61b35e,4e52e879,a457ce5b,fee9121a,b2673c19,15e78236,483e069a),+S(2e2ed965,a926700a,1428af7b,68b7dbf7,61d1bf53,6eb9f75e,d56afa0b,63852cd6,8d77656e,d5f11224,3a94e462,3dcfbbdc,61749930,dfcca6cd,c4303cc4,617e9133),+S(4b54bd22,e5604384,9ff2268e,88c695d6,4766e0c8,4f598f5b,634e1dac,d03063ba,176c68e4,a1f25683,37c14fee,dcf9a64b,17cba4f7,283428c,1514990c,98d29d71),+S(b6cf7c38,2d4c63cf,78557116,55b5de99,1fd32da6,8b8d2dd4,cfcd6f5c,59c45251,c4c190ac,2870142f,2a13d7bd,5d6768b8,fb5ccdfa,b99d0e3f,6bda805f,7741ff52),+S(857b6db4,79177eca,82a6c801,bd763647,c1a49021,e5b4f405,ad02e6ec,7ccc3629,586cde8e,cbf7907f,704a6610,f7a8a910,16599e9a,93bc6a6b,1b70d59e,39c0db4b),+S(a18a23b7,6643d92a,9e1bd2c7,7bfee61d,c5171b33,12f64d7f,821fbe05,6a771ee2,321f460b,b9525303,c159fe3a,6762dd97,60432307,919a2f1d,6120c946,47cd8568),+S(19b91028,cc2e5434,b162cee8,c77351d9,d38d9eb6,8ff9b09b,f26cb25f,4b88510e,cbcf2e52,3335ee5c,56ee2a06,7c565627,a5c60f16,808ea8e9,94250c15,e427c883),+S(657e2f30,b1e0241,82c0e57d,996cccf4,7bdf8eec,5a4da875,1638b3f4,9bcdbd2e,8e0a3117,12da36b2,2d0cd048,a9a99b26,5faadec2,14162083,5210f1bc,bb79fe3),+S(576879e4,f4a8e697,45014bee,36ba4267,cf72038a,f5997d38,cf512f08,f0ccf6b0,3f313f,388c011c,18ba0938,51b0e7e,84627277,2e9da999,b839b58,92ede5c0),+S(ed72d681,6516c2f2,7a9e97c7,1a7c99f2,faeb8e31,a5f29260,faa0bbf8,6475117f,331fb25b,e71c24fe,f4d2133b,f1591f3f,e5f8830b,15615134,36fc47fc,522ad4b),+S(e4ed422d,9152f00b,96bce64b,bc3ddaee,6089e1a4,1ffbb58a,109c688e,ba44699f,6dae6420,2dc6cec2,e4a49203,6b16c9f5,9c517436,bf3b9d9b,7e8f458f,7fcba8e9),+S(fc3b8afc,fe39404c,29622db5,b06c989a,8d7a0c4d,85018796,d006bd5e,43dec087,7b77feef,2211c1a5,724af5e9,a841e09c,d7940bc5,43d70c7e,51676689,7682ef15),+S(9c2421ee,e2e7e66b,decbd152,a8839f1e,4cf03808,649399bd,ba55cfbd,9dda6360,8d9477c1,c66a532b,967895ae,66c7585e,608e9653,4f870bd2,c97d7398,74a84700),+S(22040517,334bb5cd,2252d1b9,8a9da91f,a0bd32b5,562c8218,4d991e01,d94e8f13,167d3dd5,738a467e,f8e03064,d6482c2d,64503892,b4f5b9d3,c4b04684,fe2f15c0),+S(b648a617,3c728243,f3c0c7ec,2aadcb13,dfab92fd,77da9aca,1602d47a,80022dd4,7199a3cf,89c596e0,d607d05e,de95c8db,ad763ac0,76fa7ee8,ba7ae6e1,4c14308a),+S(a7d7ab3,6722b9d7,940b2a15,c94bb9fb,41a139d4,26215286,bfff84ec,57386dae,25ea853a,c3e772b6,f400d850,a7cf5760,ed568add,a145ea75,6f20b77a,c32d9f28),+S(9787a21d,ea3dab74,366214b4,933a702c,7a07c4ab,696eddb7,3a84cb5f,80f2ba41,8663b959,2214a018,e373e360,a9e035be,f68d9e01,f6fff1ab,f8ad9b8d,3f6f324),+S(1d2ebbd0,65bd4f50,8dd697db,9c8bafff,b548edef,856fa4e,39f893cd,349ff205,85d0716b,109ab208,a96367e3,bd0a2314,ad2c8586,169096ef,9521d780,61df01a4),+S(d0a506ce,14e88414,46c08a61,98ea0aaf,75b9dfc2,c4d2cc58,1238a597,154981b4,dc8c863c,7c4611a1,85744975,34c8c02d,7cb7504b,dffa91f5,96765a25,98d1f506),+S(b6c4d103,a57d0af,27e93627,f55a34b7,75b2ef48,47d7612a,5fac0748,b41afee9,dc9440a1,596cbfd9,ff87fade,8b426091,4799dad1,ce0f7b60,d032e94b,bbaf53f9),+S(5b5d965c,f2f37462,86f088e8,b58887ab,2182f874,484686dd,43a245e3,dcbc55c7,6718ba28,cf43ba30,eeba6e49,a7234ec8,7f01762,e915ff12,41fb461b,6d87a875),+S(bc85aec9,55e6e99a,c5fa7738,c7972354,57b3935b,bb69e8e1,ddc69d01,d34a47f5,59dd49e8,cb3100a0,9c48ceaa,20cbde82,5072e13a,7af0a44e,601044a,361dd971),+S(66b7ffeb,a34d8cbc,e00b4d1b,a0558741,5123d8b2,89ebdba0,47587d66,b260bc99,43bafb96,c88a5917,c6333dd9,b4a546b5,1c37ab48,3f3873a3,6932ab97,efd79712),+S(3cf9208a,b230b73d,68470411,bf3d4899,e0f19675,f829e32f,cd148d,3c07d7c8,21fc39b3,ea5079a2,ae131935,9a3e98df,62b97b37,2a473a63,f3b56e24,25b30e27),+S(66e3fcef,b7b24cf7,af0f8de2,8e53c2df,2bd1dfb2,c0289b10,31239da0,948e129e,df4074b0,488f3f09,a674a40c,b3207f34,a0282661,2e5ac4ae,8d443c9e,d1184045),+S(28df781d,4ec05680,590f4658,713c8a91,fef23763,87ddb6dd,674a35c8,b0e74459,eb66159,95ecf0e8,34f24e87,6f0dd86b,5c86a45a,fe5190f5,721f833e,10a196c0),+S(85d8da47,48ad1a73,dec8409b,e84f1a13,16e65c51,96aad27e,766746f,3d477c2d,a76b74ac,99a3996f,a794ac9a,ce103843,6b4f5fdf,cc3b2a59,df867e8f,382e1ebf)},+{S(39ca1e6b,9fd848fb,ac24c444,5a9f398b,8639fa6f,c0c2f2b0,8058d84e,6c0caf1a,8797227c,f956ba7e,5228a452,91cdd51f,8958ab7f,43f6c8b5,e06176b0,dc9048e4),+S(4c87e538,c9eac9ba,d5a2a81e,43a6f1e5,f8403c01,68ad5020,4adef77d,5e3aecde,6ee8b74d,dd0b9bb7,c8b7ed7a,728dd99d,a9fab941,f0132d0e,998e65b9,ffbcb9a),+S(1226617,9f5dabe4,6d963b7,e96247e1,e29f2440,f831c8be,578d628a,78561987,2d3552bf,ddb5ec6e,a7758830,9badce7b,41d71926,857962d3,c3bb28cd,5d68ce7f),+S(866c0a90,893b6b3d,807a96fe,3c67b928,67c1d95,e05146fb,40038476,26981201,8d8f3188,da86e510,b7a7642a,97778201,3926dae6,4ce80663,335bc448,d204413d),+S(8eeb2e94,9a66824,26a6f474,9e7578d3,1b356aa8,d1b42049,5fb83e5f,5d08f723,e439d710,c45063c6,d23aad9e,ac0cae8e,36552ab,ca6f2c02,6eeb03ff,6162a052),+S(ffc93fcd,85fd9502,78369b3d,291f1ffd,5da44964,888d5eba,3c3f60c,95082bfa,9aa66635,a4b0defc,b2514e97,515aa0ec,3f65ce8,6f6962f7,72eaca41,d5ea7983),+S(605ccd66,4f18c83d,edf36f62,e5089f14,4ed23f4,f88635fa,ab161567,fd20c8d5,cfccf020,363a805c,1d614aa5,b9a912ec,99cfea61,5c088789,275ef531,dddf2418),+S(d1e4f37e,7d3902aa,dfdd7254,fc727a44,98eb9303,a12fe71b,4d193be4,8dba6913,bdd29d53,4881cbc6,c2e301fb,7d757bc9,9224f12f,4296e834,9badb88f,84fcc289),+S(f30b6d53,f330e6b6,b23d21df,7b4350a0,c42ad202,4a92751a,5dfed94c,47bbe60f,b5ca6c03,b31d06cb,183b0b18,4432a06d,8143d511,8af4bc01,c364f024,b46e0c38),+S(540944cd,42101851,c2cdb0ad,61264e18,cbf948cf,2090df68,54482628,74271ecf,cd16820b,4ccf9131,476b8778,ba3e83,f5970507,7110686c,653be572,2e99db3f),+S(846e5478,5d9cad5b,5109c7e4,6fd62b04,f686c723,1fc3c0af,66bea20a,d9d60dd0,4b1a28c1,78bd097f,aeee951f,fd4f46a9,4658a76c,268ee7b7,9aea4bcd,e75fc8ff),+S(16e732f4,43b4c616,24a495d5,4497a23c,c95612d0,58df9f81,11d1340c,4b2b8b5f,61ee476f,30ac2be7,e3ff09f3,ebf0b3e,2d76177a,30573465,101f4cc4,ec0585be),+S(4f30ef37,2c730ba,a6a40ff1,94b6b58f,436111d6,848b4e60,10be9b9f,abef17b7,b579a133,7f3247f2,8c6afc05,644778f2,3668e73a,a7c6d14b,649bf948,ef126142),+S(595a0d2f,1668c0b4,9ba0994f,3b681c42,6e3a67be,e957bf52,47acd9c4,7cb7d009,fb10684b,3ef1b0ee,37684ba7,53858b3,3586b837,aba6d82a,958eb947,2eca319e),+S(85dfb59e,d7ef6e0e,355e0ce1,304fe5dc,8bc6a3ad,74de3352,2089f224,8894e0c4,7a9b9ad1,10099903,d0d84a33,6838d422,5f98abde,32d82ab1,a383969c,1fb98bb2),+S(c8e13980,cf58416d,8719bc94,96e21774,c29f2e1c,5a36e760,2ce7783e,2c810fd5,5bdcded7,bb484d46,48bc40e3,ee6a3761,cf995e36,2af21f0,10048a91,6fbd4717),+S(80b98fb8,e48f44e,db69fd8b,18eec95,2404fb59,45c8a35c,bf3616e8,c746aecd,d44010a7,20622d14,6af5319e,155fe4ff,591bb829,f5086c7b,1fc1ed6a,32ccbaa5),+S(17629b1,cf015e58,eccdc7a,de049215,fca806e7,805e0e35,951df2ed,5cb87d38,afd56698,44f6aefb,528dcea4,29438e0c,d10c4b21,23f02444,a950834,97a61f17),+S(592677f8,695479dc,b215af2d,bbc90621,e7f3cba8,650563fe,1b2a8765,6c44107b,3741e4e1,b39b0e2a,58373166,854a1d31,ed062a25,c4e3e1fe,bc82e941,eeaaf50d),+S(98d5f85a,a93c9d87,e34e3bb3,597d9380,f0a7e5c5,b03ec219,4025c89e,42126453,dbe42a83,66753aec,61f7f01d,e5dfde1e,b4b989cf,95bd36bc,a66ddc0e,ffeea196),+S(9187b546,70d2b9a6,b711c88d,353bee60,72a1f5d9,ce75288d,4e6c9111,80dd4126,80e73529,d211ea24,d4bccff2,b9de3e31,c6307ee2,3cd9267e,b2d372ef,78f8d2c0),+S(e38c81ad,8ddfd8ca,4e01f380,78eafecb,f8edba6,8e33e565,309a3ad9,f0abe0eb,9f0ace1,f05f0a85,a1488644,88cce81a,2cf55eb3,a91fc10a,e6b82f47,60dbe618),+S(7ee9955f,99e218e7,dadfed94,dad7054e,3e0b97ba,932338db,69ed056b,6f8adf55,5244e198,524a105e,2b5de11,81d7bfe9,ad56aa0,128a3d87,8cbcc5c0,25b41ca),+S(eb9e5ae8,cdf64b28,76349aab,c3f75c9c,9d95a335,3214d0cd,d43123c,265b08d,858611ee,f67a32b9,7b8a9090,6639e998,a05d9bbf,8ccb7c1b,9e5eb711,4216b877),+S(2aa74ebd,7e8b6b2d,952effaf,e5545eb9,e99b9678,a2515698,975247ac,c83ff081,1ec12cbe,6877aafc,f353f641,1a5edf9f,e4bcc09f,31422df,d076932d,8f0defbf),+S(1b7b8fee,a3ed4af1,cf9b07fe,b435ef76,1d081b1d,f1007697,f78fe5d9,89076aec,b4aa0d8a,efbc71d9,d338e998,197054f0,20c5a2df,7a9504b1,ca7cb603,6641f85d),+S(3f293b75,9f152a4c,b92e319d,e5d02b82,f5dcfbc,2ee7a53d,fdf7ef6c,e2595c32,b67babb8,d1d1963,fd742c22,5ad5bbe4,27e57d6e,b9e17bbb,f91d2c1e,a455c1d0),+S(3eb9968a,c9b01fd0,882ec65a,8f9f5a5a,b0fbec2d,e2dcbf88,cc9a70b7,887ca59a,1a4de130,4a46fcc7,6719c254,dad5e88e,9d6a0839,9a9a28ac,7f171aa5,9624ee2d),+S(a559381a,f41b944f,e2bab9d9,62ec7c53,efb25ce4,1ff1a456,54a99f46,d97ce20c,ebc6f66f,75ad7322,4c1319c6,4268c997,4142,11ca65b4,58c5f79a,be0ba0cd),+S(a8bc942f,c60ff2e1,140f9a97,3d7e0b8b,77698254,57098005,f9186e97,9e430593,2a82070f,25480267,c4fca773,3173b354,fcd5cc1b,ae497af8,58b7d451,8f048c73),+S(2f456ca2,c4f8806b,ce4caf12,32446b07,3405dcab,7b3cdcc0,247dd079,adc7a626,7308e58,5b9bafab,b2dee049,9bbf60ac,fdb37242,3e915156,15314ffe,5ad866fd),+S(b56f4e9f,9e4fd1fc,7d8edde0,98f935f8,4c750d70,5f0c132b,d8c465b6,6a540f17,cd171acb,d63357a9,2c23ee52,fa7d2e2,de2bd69c,343357ab,b95d0350,fdffec02)},+{S(ec474055,43c52e68,5c9e6c75,97616fbe,edb70df4,fe3c375d,d7d24729,2b120851,22c1c1a7,30066375,5ef8c2fc,86452667,90347223,f11a32d7,9f1c0169,a467530c),+S(3f50e502,c45fd922,94fcc46c,b3118a86,43af00d1,634bd694,dfc0eeb8,be2dd4d5,7cb992e0,f29fbc5f,2887161e,6d1e266d,f11fb723,3b6c020f,26eee393,fe96b526),+S(443007f2,43c3f6f9,76914031,c41e0d49,61337340,9bd4a681,f20e4c79,934fc2de,df67adec,c9ce5f6a,e6c8312,699e0353,68ee87e3,1e96790f,f0bd3408,94af74e2),+S(1e15b9e9,c28f77df,75837a0,cc9504ab,a3a49aef,26a88d99,543fa7d2,a875620b,2a081093,6afbc025,3808ba31,f5597287,e32898ac,77fd0021,9e6fc298,26b0370c),+S(cfff0258,ff6c0d97,99823447,775b75b9,1881e06e,bbd72ba4,28f8248c,5cf2144e,61e63569,5c4a8fb4,f68f974,219bbf4e,e0c277dd,4b74b843,88f99041,f97809e8),+S(2824f4b,f72f9229,2aa04058,7a0c5395,4c87e7dd,bc5dd199,af6918e,6db62f1e,16ab1473,3bf8382c,521af6fd,27f8b2b3,b421dbdd,bcf06c62,3bcd86b6,4bf33274),+S(5dc7571e,27d6b955,6c789b4a,80d49fd3,17416fa4,e04a7eb2,3cdbb88c,9c253a44,b7261e2e,39327d68,a5456abc,9d4600c7,fb6d6e51,a732c7f6,c64cbd0d,56de4a17),+S(e93f3aaa,5d9edc53,6029d332,9ac0bffe,af27d4dd,40f550e5,3df879a2,a5c1d993,25b442d7,f2e2e03e,c7f1588,16a1af43,b5d2870f,e0cdf429,babb19e8,951c0982),+S(8f91f5a5,7aa40d62,ba407d8,6ea5678b,65c84ea8,f241e2aa,dd6df242,52635a86,e9333d7b,d6c319be,3ff4f5b6,f286a8eb,27d5a1bd,29646cdf,77441c40,f716a6f0),+S(77d398e0,228add30,e9e120ea,b16436be,30c254ae,65016672,8bea1198,de1fb17f,749a20c8,ad6f4312,fb6e6fa,c390a4a8,209704be,3355362f,31db9b45,f3876963),+S(96976a85,b6dfc4b6,13dde357,c21c3518,a5f55c7b,a2d22976,592d7632,3b5a8546,96dc660f,8ef3b0b6,adbe77b5,69024fb5,dd713566,617cfc51,c8013f2,5b424e9a),+S(49093c4d,26194278,623c2ff9,6c8e2f11,f9edf3b,13c33099,57b57f1,9db451c6,5d53ff56,50b82edc,9dee9f43,ed6db93b,f6a26233,2dbcd699,130aa9ce,5130384f),+S(49187f03,d5f5f628,b9210b88,8ac4f1b5,2f754015,541e9f38,162e969d,6a99f4f8,276aacaf,d38d0bbb,416bcd0b,8ea590d9,7735a3f2,8de72aaa,76bed0d,6644bd80),+S(7d64e446,65c03917,87fe0b14,16ab1048,3a6025af,b20e8c19,3bbba444,2864c587,2c0da181,6507f8b6,4c9e5684,a4d53d98,d6b88215,772def9f,fa5a7a1b,f2b2ccee),+S(2223484b,9ee12b26,2a21a18d,2682ab01,c291ee1c,fe3b4b9e,2e93fb67,aa08535d,4cd26418,bf0d62fd,b266a768,5f7aaffe,d7bc95e1,be41c6bc,7a0c9076,1ace3974),+S(aac92330,7d6a55d8,552ce6f3,9c531d5e,afdd5313,f801242c,21df07b3,a656c618,93d9be6c,590901a9,1413cc23,94cb426e,e6a61593,93511c,e67e1ffe,68b8f3c4),+S(6ec1a0c7,fe40c40a,f3515ff6,60f0b53b,8fb6be3d,d912f8b2,c7a473d2,3e49d201,b10f000c,191e9423,60fe6b5b,2b6b7b85,73c0c2ee,384dedd6,e3dc04a9,7834f93b),+S(bd982a5d,a4d0291c,38568fae,ebc76df3,f2b0e5b9,1cd0d3b6,d2f32077,6c35c43,48566068,d5142f6a,90b13105,e7841d32,38d869d4,fcc7319,3e3cc9ea,76739c5b),+S(25d54513,b9084ddc,a3f20e18,94382290,115ad5f2,dc72c267,ba845b3c,6ade39f9,e908508,7fc5efab,a6f62c41,ea8fe856,226c8e2f,95dc31fd,2b49a7c3,6aa53b39),+S(29ab6cd5,add595d0,cb64ead9,c3d275a6,ce383f15,9340faf5,118ec2d2,9bb9a62d,54584613,dc27c249,d5d1210e,9e121aa4,7d606fad,1c4621e1,67f67b90,d8f3434c),+S(4cfd960,86f86d5,bd805667,55979c32,d5419dbc,946d63a3,40dcc6f,6d6dcd48,f032b7b5,9d85d0a9,fdc290bd,a1fc703,55b5404c,f70d45c,d15fa9e1,33ee9319),+S(9c786066,b6642e11,139aa303,800314b0,6afd4d97,e8314a1,de9d7002,5b7bbbf4,463a2ded,e2185c8d,944f29f0,140f6b66,9ad6e3aa,8ab6e292,a2af551e,685e58ca),+S(4e98485,f15c506d,6cd29d7c,3f9a59ea,4bfab065,78d86b63,f25e74e3,e7aea96,2baf3fb1,c26f2b0b,1a0725b1,5d1ceeaa,7ccece9,a1dd8f2,7f80d825,d8cf1d71),+S(8412c389,bc88e9bc,b157d835,85af0dfd,48689532,e38044b9,117b8acd,ce3b62cb,17eaa404,ffc1f62a,38f7ce99,6216b1f,40bb62e9,6d1f7a5,8bca370,c0d30b44),+S(31b9b8dd,7d37b38e,892e94c7,a5e817c8,ffaa1c1c,f56979ff,7f25815b,758b6d09,cdb680a,ae795ef1,f94e7e87,50ad9077,7a55eec6,c6f0795a,ef951e3c,ab45d186),+S(2be45d05,e89c58b1,8212890b,b6eaf935,6f03e37a,fd957291,4ab71a97,7af8350d,c3b05f04,c9f7a1db,b6689fe0,6ecf7a80,3ecaa147,8d09a1ec,9a7d71dd,a75406da),+S(5185cfa5,fe6302c,b5573594,61f375dd,c483a66b,c615b5f9,30abbd4a,5c7ae0c,83cc447e,53c91e07,6f44d265,389bef06,549b8d78,9776000b,5c35ce36,5fcff98d),+S(cd42328d,e4a16323,c51ef888,b7e67ba,f9ee1c53,82161b90,65e1db15,bddcffd9,caed06b1,7e86b470,b665de93,74725fdc,94792c57,5509ebfd,f012133e,122302f3),+S(7a1ffea,8fe5114b,8a638306,3b7811c3,25a40c19,42451557,679e75e2,b304ab91,1ef3fbde,4f0283ab,96efbc83,bcbb5a6a,d781a215,e6ff6262,ca50b9c3,986816db),+S(cf0bdf47,a3f15b24,5c7136c2,3a3e38f2,661fa8a9,4df29fbd,8b41ef22,c291dc6e,c73d1fe3,919e0aee,5b3adc4b,1a86e709,4b039302,d44a0d56,638c3eba,24857a99),+S(3a571630,935c1f02,d6fd8744,2c082060,cd5e792a,1c6f92bd,c4eed01,686df50d,7a1ec78c,4a660cd0,ae90c00d,1a8f5f22,1f5507e1,4487e5ee,2dea74d6,17a69494),+S(1c5e5481,32b49a7f,66ae9fed,8323480e,d1ab974,622e7cf0,8993895e,ec87fac,b00309f0,7c80b970,d446a605,e2b3d52c,5c215314,d901cdb3,aaa284c1,a03d2740)},+{S(2b081f0,268d6ff4,1090561d,79144bb9,554b1f3f,1f0f2cfb,c9344e2,b692157a,597920fb,c528543c,26499af1,8b5e7d7b,5ebf5ada,5df4a46c,edef52f2,1e2fda5e),+S(2ce45dc7,d84d3143,884d6696,73738e55,e30f6045,8bac95cc,c30e86f8,71779827,deb79108,80a1b675,a628fb09,725c9307,d1629b07,8027f566,29f8560c,2ea80458),+S(9dfa0cb6,2a63244a,35ce3a0c,f102e7c7,93a4530e,21c6c03f,15a4fb91,e116c480,b01c1aff,902f0831,bc8cd268,663f0ce3,6d8e22be,86026460,a8950636,ce44626b),+S(61a32d1d,cbd7e887,def51ffc,9c1dfd55,d06d72f6,a73ee2df,f83cfa0f,52d47bb4,69a3b17c,fa91e3d6,faf28d83,2695aa66,c87b14ee,7b2d987c,80242fc,ce2cc42e),+S(8cbbac63,5414c0ac,b6d7f659,5c6eca39,886c3ceb,82549f72,d07a4019,e3076eb8,c838dc49,fd5af1b5,e503a430,71901bcc,90e1ea38,9f735e31,236491ec,43e7b621),+S(d3f77c5f,663c6efa,670b46bf,dfa96af4,fc4720d8,e1df6e8c,1ffc5696,f37cb55,aeea0c3e,50eee6a9,16462a13,90ce5d47,c060efff,1fd3108,1db77513,34300332),+S(6f774118,4a0210a0,79695d20,f93f861b,658137c,3a072076,7d80e5fb,8b1ebdff,c12aecc9,b55bff04,bd6b6e73,870deadc,666973b8,ec498bfd,bcc4c33d,23f5d674),+S(fecfabd4,897a948e,5fab7200,969f9955,9eb1c9dd,2a31325f,34dc4f80,13da72c9,ba70c9bc,c8048aee,6fdaf5f1,8ef638ba,ce739c0c,76ec4c13,fd4dd6c1,1663d02d),+S(d1a1a1d4,24fb5ab1,3e985c86,9bd7c02f,f81b4633,dcd22e96,c3f33489,2e80d543,cd5b79ae,af62769f,dce99530,8b921b5e,39a60fd6,f989dd7e,1d0d7219,e9ee8865),+S(7099682a,c3c083a8,80467746,fb924d4a,56f23d16,a3b57f10,1a824b9e,653d45,6a9c296b,cdd72c93,df840003,24ce78b9,1f9df6b2,bfa33922,ef32733,fe49cb31),+S(1035866a,4e9ff0fe,6b0066c6,3f0a2392,c0b8cd61,36e13ada,21f6dae9,f22c39eb,6390f9ae,ec1989de,2146cd00,a5eee99e,76ea4536,423e9bf2,c778ff29,85538fa8),+S(e18351cf,163e4df7,d31851c0,409b5705,a5ffd472,dbda5dd3,bf05e66b,fae50fec,264c1d26,41f185e2,72b908d4,77222484,c651e8e1,9a9e1fb0,1ec5ed4a,8a4b6c08),+S(dfbee778,ae4bc89,24f32c18,bc0a740f,d01922b1,28e1a595,283bfb4a,fd8f2f76,d11f9b3c,25ae3619,99ec2c9c,2f1a5903,d80eae59,e096c5d,c5e37201,81756acb),+S(842cdb54,414fa977,58ae3fb1,9316ef32,af9c4f0d,649f0abd,cb94267a,124b59fe,a016f899,288f4caf,dcc6edcc,3cbcb561,fdb4047a,f789e1a8,51ad21b3,be62f5c8),+S(3deb5d22,a81540ef,cff29ac5,585a056a,204e4d67,2fb858f3,5c23e939,790c744f,20d73911,5b24b1a0,a4b31302,73321dc5,d8b74398,d6516439,4e1423f8,b4022d6f),+S(3108e61a,1e0f079,f76e3ab0,d69cf068,779674e6,49768aab,718a09b0,640251bc,245a9f2d,141f390c,f1a17bcc,a06c5a66,5cf3a87c,1096f5e9,b04c4fd6,737d9a56),+S(63b9eaa,ce6b32cb,e4cf4a69,6599f8fb,3797bff5,9103ba0,c1351e78,b16cb0fa,938ac414,ef911df6,bda32b5f,1f69cd7a,87a25d82,177763de,568ca95,e846fa5a),+S(f37a5a41,cc96a04c,c882c27e,e362d054,7d6267f1,c91c5403,2daa5c12,1700abda,108bd6ad,27aa72de,48406693,758a74df,53a3ff98,d490e303,54c45ffa,c64638bc),+S(52afb7fd,6a16dc6b,98f9d7d9,555068d2,c2317035,b7492e8a,fbf28aea,3b1fcaf3,548d8ca1,2cf7a11a,b0100455,c7240290,6cb2e92b,101d1e2e,32ab263a,3f3de413),+S(f644fce7,874e9154,8f3fb284,b7d1ba17,fad6eb6e,c581f57d,5aa11804,86de9889,b2acbd8f,5bed4270,ec131ea,1891c99d,ddb46648,60acaf39,d68d2a54,a58b92bc),+S(863cdfdc,66065a4,50c2b7c3,1d694c58,e63ccc09,fccfacdb,4fdf0b1a,b150e937,14d168dc,c84d859b,55a3d5af,9d17ce4e,83bd90ed,55e099f2,50932dad,b5d2693a),+S(9f5569e0,50a26288,5d91f82e,9cacdf9e,f4487676,730f4da1,46ce8769,3d8807ba,cba008af,547e01f,6a9c6c45,8f9d71e1,8ad062c4,4b305b52,3f3a6655,3979a2b9),+S(a0f14b6b,99f0bd74,cf9864bb,17b1c43d,51ade513,6cd72a15,89312dee,706d50c1,e2bd2d82,c549b4da,cebfb888,c1a7c5d2,f0757fe8,53e07fb4,747eb7a1,542137cc),+S(9e7bd727,fbab45a9,db36d17d,5e5437eb,f028a10b,392ea470,d5cff0d3,2e9bb0fc,fb52eb32,e43133db,28125280,e3cc55a6,76877c58,b4051f70,9c031f84,24f12d9f),+S(7d8b1a30,4c0c8931,2d5d712d,ab396efc,7a117483,7f62bb38,62a81a3,660b1068,472a2dbf,ee99c398,94d14c1e,ce87cf17,c8aee10a,4720357c,c5ce79a6,19aafe2b),+S(d5eb073c,a5afa126,70602de8,417fe50d,bd8f0768,d615ef2f,565e421b,4e7842f9,52571e4c,e4f0c424,fd288f3e,8b6c54b7,7481c3a,43230fc7,4c6f48b,d4041089),+S(3c41cd8a,77728b07,ea592254,5ac45462,2c7927fb,6a7aeefd,61635cc4,217acc90,eab0f00e,84099fcc,c2f4d339,77ff7d68,4c035b3f,34c6c4e6,aa812c9f,43af366c),+S(1eeeca5e,cadfae31,188218ae,7beda45,57f85c25,5c99dd64,1d00d8ce,2e6f7809,d7e5c2ff,4ddf421f,cf09b655,113b8cf1,a4c25e90,d02b871,91dbac55,d6606ef1),+S(54c13737,454414e1,76bfaf1e,b4402bf8,678daab1,555412d0,c6d3fd44,653510ae,753f6a,f382d0be,f1dab47c,1b9368f9,57d586c4,acef0d19,dc241ce,f008ea3a),+S(4d608c37,1fd6f635,9ffc57c1,9f1aa5b3,5b0f5702,55851cec,34278d2f,465fc8f4,12d1592d,c2cbccc3,7e5c9fae,4b864e9a,ca6967e,9d4852e,9adc9e31,1000670f),+S(71157d64,8c0a1a33,19b713af,f806cf9b,c91a446e,2ba48ca2,fdd1ed4e,8c43da59,c2ac2aeb,a298fcfa,c0d5eefc,6eae54ec,330f5c0,5b34952a,9821ded3,9b72d383),+S(327f876c,93652555,fa80a054,968b4712,930dc930,12ee6b8d,c10263ed,3b89a762,4d2bfb15,4cadbfd9,4f6696da,a1e66846,8aacaf8f,1428201,636026a5,46dfc92e)},+{S(4d3b98d0,b5926a8b,3e5622d6,10b30e88,caa6e7ba,eb10bc3c,38aec3c9,c1267578,e84056d8,4726291d,e6880a2f,2d3b0b01,371dfa27,5b8c9cff,4805d18e,a5bdc788),+S(6e463689,111d1a5d,d10b09e1,5d0f438b,1cebdb67,7a6cd230,bf6349c3,70667db9,de10eb3f,5d2f4320,7265952f,b33fc23f,154972fd,d3394cc0,21b66276,1b51db3),+S(48235e7b,76c94c32,b0d21bf1,7fc215ed,df036366,a9ef494,19723485,78db8943,4f5ac8ce,36c77403,b2fa83ba,1fd0e88a,3da4c8cd,3c10ddb,aafe2d0,5da40a2d),+S(668af7c1,4063dfba,1a4187f3,f69cb457,cae4edbf,a3bf9669,4080b6de,bc3e2f0e,ec95f37c,7bac26a0,df23275a,283828a8,5a102d8,f33eef1e,87cb56c1,850740cf),+S(d4426fcd,cbdfd904,725fb501,656b9f2e,2a9f9ee3,c6522064,f078165f,61c31d97,e73f2a38,c56838a7,174ee704,948d28fa,5b5fdc34,7774df9f,72f27834,a85eb4d),+S(d0f49ec3,42076b68,4cd91172,f15584fc,ea38aaf0,a3201063,f854ff1d,f68d4600,28d95ef2,82dd7d6d,72be7854,e8858b1d,a142002b,ad7b7b4d,bd1e582e,94341e16),+S(8a36f3c3,50bc0f1a,1b1687ed,4ff83a68,1578d74c,c28fa875,f6969e52,4887bbb1,15ab9e05,c3ff823d,ba090e21,1033c34c,fa713d39,feec4346,88e3ecba,4b431e10),+S(4d1ef23b,b316e821,7d2cc409,a1baa273,cc06f79,8fdd4d16,5d5b6805,3718e238,fc37e62b,db18154a,2add98b0,ec221e8b,bd1a2096,ac2dd1fb,cf8e2e64,821301fe),+S(eec1f8e5,76e87803,bac48bb4,65ed923a,a68b2965,64365d45,bd1c24c4,cf7041b0,2c6985e4,7cccbc38,3b85be66,ab34a166,c98a8000,aad08f73,616e4d2,2a15a009),+S(9fbc20e4,de372a38,90443786,bd7cfc40,c6195b29,4cf51874,6ccd9ecb,cee223e9,f734bfc8,a6973209,903edaf8,52f63bca,b23fc1a4,879906b9,1c5df169,9d24683a),+S(7984c8ec,a2b02dd4,e8b9c69c,6f803418,48f108fc,b63d7038,de58e567,e64a894,49adeb11,13c705a0,9eb01e50,dea5be48,86e5d424,689282ba,6d64f745,74f45e8c),+S(29a7400b,16f5712a,2324becc,29fc4b98,57fbb926,f8741dcb,324c26d9,6cd178a3,90770be5,5c0a94a8,16bcfa38,aeab11aa,5ec3b7d9,eb4e7d29,1bee1c02,69e87267),+S(8299d2fc,84770bff,a4e630b9,8f2e6744,99b1c7f5,719e907a,d70515f5,140a00c0,c790968f,a3c3d4ee,3e25a1ee,8e1d4923,3c22f034,ba7c172,b5d7d91c,99eabfa8),+S(5cfbd498,5b608db3,5d1a2872,b9cd03fd,d775e498,4629f41,61a2bde4,fb2582f1,8288fa89,81056333,acd1720b,bde757b4,e83d0a49,9c5f2220,521a0bc8,dbe827f8),+S(281f1fb8,e144e39d,9ec2104a,96bf0f1d,494eaff3,57fe084,63825228,ecd286e1,ae40e075,d19ee5f1,1dd7e22b,f1c277ed,9a02abe9,975609c,a7c811f9,7c54e493),+S(51698bc6,73d3289d,6b4882b0,cab14e67,97d31221,e5bc6e53,af061aa1,9f546daf,7b850099,fe977f6c,f50abe00,bb3a0b68,90f47c45,24e9ae02,94304b6b,20bd986c),+S(db701e92,9b696c86,d7fb459c,97af90df,ef847bf5,1d235337,2a2a4792,5fa8ae53,edc7e98f,1a108bc4,8fdbe65c,2904058f,7da5e188,e71d194c,4e9dbfe6,8a55d18),+S(c900f57f,e9a31d4c,9715a822,5a906e90,22d81c12,714006d5,81be0c7b,aeb5a490,8493eb00,90517d9c,b70a4bc,39043ffb,e0863475,17cde2,a9bd0d95,f616bb66),+S(d74e842a,fe2da0df,df6342bb,582fc223,717e0641,f1ce0e14,584c5c63,f379ad72,cefdbd7b,b4ecbdaf,409a0fa3,9a0a305,b1bd986,4913f977,bec6c47d,5d525c10),+S(b00a5f4,f033d126,64366147,a1bbb9b6,ea60a38b,863c5f3a,e323e8e5,1aee200c,11e9f1f7,b7701a4c,26a881ce,30fac1e0,92e157d7,b9c2e4ce,cffeb38a,172ead87),+S(5772b134,68bf9f09,d26074c5,16dd7472,d3a83624,92306cc5,c7544ec0,d73de280,2e2a7931,aefe2a31,6dbad1c,e7f9d42b,7f38197f,43024f16,9e27fbc,7af31d0b),+S(8bf8af02,ccdafb15,598f6725,5f172fb4,ba8960e0,6c81ffa5,b4c1c313,6f95f29b,96041af,1efd128,ef133e5e,b0aa3d9a,6ac3a651,92598b09,ed649847,385a9b2c),+S(292889a2,d8329139,3410385f,cf5bf489,7e1ee23c,e0e3b5ed,82ceb340,d89f87a5,41099fb2,bcec7e07,d4d4ad14,3cf605d1,b0a32487,1736063b,e49b06f6,d648aa69),+S(ad227b2b,737dfd02,665c15d5,9b28c7e8,76413dfa,25c9068b,90efa79,ce83142b,82f1eef1,7e2f6b86,87137302,741f8486,26fad679,9c6a22fb,3a49e341,c7e51e9a),+S(b4245dc5,5df02839,4cff2610,4a4255ef,89f3e708,21541c3a,4631ee4c,145bf85,5a40f72b,7a67540b,6858e5e,b15005c1,3fee862f,3cc54a52,7643204f,d0b8be2f),+S(15aaef61,568537a4,695c1990,c05ecb9,2c605232,f705c3e3,729720de,7e9c2400,e6efd1fb,b74e9e43,ec1244e0,bb4cff2,2a5ede8c,848a4f5f,5eec6f8c,77b6f5af),+S(ade2e63d,4a828328,b4c53763,30790331,734d7f90,37c1a584,59570c8,f31e72d1,c42898ab,3633dc7b,f3a454f9,d5475c4e,fcf1f786,d1f609fa,23616f26,b23a1a97),+S(d8a9043d,297681ea,c5ed63a5,de306500,6b66e4fb,167aa5ec,c76a8e2e,df426e7a,cd3de058,a0a93d7d,7122d777,1446b2b4,d4cf53a7,1759fea3,78adcf03,5093f4f6),+S(30651cb,592d282b,5348f192,5be3f04d,da5033bc,39e2fc7b,1e61500d,9769b57c,dadf77cc,44853f67,53b1dbdc,17a97d3c,e6d5b2e7,8c6087fa,800c5af9,ccdc54c),+S(aa21c60d,6f7d6253,9d42bafe,95c58f30,33c0396c,fa0ceef9,6d2f91ed,d6569044,4d519779,3b19515,92e2d952,2be520b1,11a5453e,ec6d7ccb,3e6db3bd,3d0c84c9),+S(5335cea5,e99eeb23,765b3444,d9bc7be6,1da67d6,91bcc42f,d43ae543,e9c22bc,c4072fdf,8963addb,5f980f7f,f314795,373cf3dc,935e0e64,c3d3d98c,342530cf),+S(708a530e,9e52c73b,ee87c9d8,8161c810,5d5762,2c29ae69,1cf999a8,3a1187a5,6477b7ee,1e065768,569a923,4492c7d7,c13258c3,92cac175,a75b0e63,b8c2426f)},+{S(3fbd5a4d,ebbeff54,8c2271e5,33dbaed3,fb8ccc23,e3fa2579,4c8f7fd4,47ae186e,fdee4625,45bf75f5,5c29a724,6496d970,4616c54,ba01d0ba,feb9155b,cafdb555),+S(c1483ec1,78ba8414,c371b57c,49c687fa,69669e2,e3e1067,cc6d2a93,b1a9d24e,edf94395,962adfed,c2ebb3bb,29346136,e4dc870c,5c76299e,3b07da35,6bb26bed),+S(26df4b09,693a3905,2cb7a1be,5bc2cc97,222b70e3,3d297a54,43741228,beb77017,a3d6b908,cc6d5f80,aecda93,99e17a8,ce33c423,f00cfc4,dea8354,af502760),+S(b6c265d5,90475506,e15b2388,b894718b,be67aee5,ba40ceca,51876946,e336d903,b451d3f1,2c666c85,bf9486cb,296c39f9,49f9f98e,96d50a19,80f86f85,a1efb999),+S(da6cf69c,feec7b1f,c848639a,7e27932a,f49cd695,a2e56a50,693fa862,6e257c66,4506f44e,e6e0d822,7e67dc4a,9f8e2ec2,d3ec0c3a,c2a70c7d,d25fa9c,34cbe3ae),+S(d57648db,adf18b77,db185ffe,3f86f859,6adeec05,ffb86215,4b894a0,75776eac,a3f2fec7,7186d81e,4228cb1f,691e00e4,82a125a5,bbe9e6ec,45a53604,4932491e),+S(4de6cc4,d64d52c8,49c0e8d2,45409ba0,88248399,1916df3c,238be4de,ee2504d2,b389e7f1,ca72e9e,1cec2ed7,70f21441,590f0bab,1b963f1c,411f9bff,d3df03f0),+S(15f1bb11,78b01439,f26412,1d36a44d,b8333fbc,eabeb471,da2e6c1,1b8b3ee3,bf137117,35e10854,95acf3ad,97fe510b,33d6628f,e67d0067,499169e6,6c12274c),+S(badc76d5,481e77,9df71d6e,223c6965,9e9ecba5,8415a95b,eb7118cc,b1f931a4,475e47ee,115d258,3f0607f1,7542ccde,626e6d57,6ea884f9,61b41354,aef37247),+S(13015ae5,d770f4a9,75825bae,a6cbbece,78536dcb,78d7116e,d304aaca,199add2b,f5e28585,7a99ff0d,a4fd15e,8ac650a,98421629,aa102bca,25df3930,7e5cfcbb),+S(7734d2ac,707b9b53,afbd2a64,50c9b609,1905c391,958d7215,f92353ee,fd3c7be5,751d38f,ef48bfea,8fa5de06,8188a658,ae6c9c75,a359a4ea,efaac5e0,b5e859aa),+S(91814384,7fe2ed34,e9cc9c61,3fc2c67f,2b76a208,561d0e06,271b812f,6c678856,9a97f6e0,9888e076,93c9ebec,b8773485,c3c5d208,c793a77c,6984fb09,cdfd67b2),+S(98c516fa,2a2c8073,70ca9d7c,b4187108,ea345652,c8f814b8,b4a9405f,b48c2469,7b3446f3,2e8c4764,a8eb0846,4be3bc6d,f42b8d14,b7da65a2,ac96a018,d0831c7a),+S(5691d1e3,713302c7,48bf633,189ce032,10832e4a,9af1dbc2,abc3e99b,cb4faa01,d802e21a,fab84c54,5d665ed3,54130d9d,f7f18283,30b3a1fe,e30c2298,8b71654b),+S(1f8cb624,6440b640,aadba62d,c02f4ce7,a0ba9be7,d535987,64072fed,95c0d1a1,647a9dea,abf8247e,f46b60c6,53cdcd5e,cff0d1c6,88b7519b,a778f9ff,c894e1f6),+S(1489af53,94878f07,5cfb2e20,931fa3a4,e585d494,78818e4,f47f05e1,2be54d14,cd5bd721,4e535822,43270bc2,dc692ba4,c57e494c,eba92d4c,dd2e13c8,e24d8550),+S(66159248,2b2229d,ea70ff76,d2a5e70f,ad1905c0,9211e3d6,2d1d652f,ccd709a7,8f5ab85,57948aec,67e7b538,fa9c704b,ae939c22,4041e6e1,65f6045b,a6fd0fdf),+S(bc894efc,d0fb7497,ba70d654,961aa79b,6ac5a795,95537c80,82c525c,2c44c3a1,d5254292,ef0fb6fc,db587393,3b17adfd,87d13320,858ff783,75e356fb,b0d3415e),+S(f117d7f6,85457601,9b559bf5,f5bc150c,13363e7b,72123435,b441d98b,d169dd27,a8f4a23e,dd0d8f2f,8950c124,1abac43e,e629b0e1,8505c3bf,780ea378,20c8623f),+S(2a8d99c2,65a66a51,56b60556,775c61bc,b2a81a62,34896a31,16238c2a,b7716ec3,5e842306,efe11f66,5a049c0b,fe3ac74d,d72c5033,6dbd04bf,2a77b0d2,4d7ea651),+S(ea747597,1a6b6d94,2e368bcd,9979876e,afa4622d,313d819d,5e8291c8,2da95830,41d4a478,e0950bb9,e6595bef,3c197e5,d0f77ae,6340ca8f,2947fec4,70465193),+S(114150c3,fe8853ed,9f3e26f7,bc9f3d6f,aa50ba0e,6ae2d8ff,97924b04,dd9678b4,5530c22f,4ac30716,2b272015,460426ba,9602256c,ab735174,1a2fbbfd,cd71d134),+S(65d96017,c91a746a,656eb595,d39dc9bb,3476dc0b,1a1036f2,df7a4ea8,1846631,de46bfad,6999b108,1f358edd,7809919e,4de768f1,fb21dc09,4b248bbd,56b3dc76),+S(f2aec214,61c040c0,ebd18204,bc277312,732b452,266bfd55,aa071853,e458bea7,52a1b71a,eefe2c48,5ae2918,e236f1d2,1622d37,13b4bc04,36124567,d48cc453),+S(370ef89d,c39e637e,8bf6be31,63a4f76,7cebb202,c868647e,db18f991,977681de,e6d402ba,9769363a,b963729,822bd6aa,9794592f,36e54461,579ae53d,4c8bc4cd),+S(8db6356c,4f31f46f,961e4342,a1ff50a1,8240629c,a0decc36,e1bb24af,f6742e57,8ee033bb,96958466,15626ad6,736e9025,fb76320b,c2d0ceb8,ce3400cd,743f934f),+S(14a1a08,502510e7,1060f291,1316ee01,b1fc2bd3,c88eaa1b,656cba0e,8e3515e4,5a4dc536,b62c349b,c9bfc6d7,fb677231,1368655e,fcb9c89e,572aa58d,a57f08c6),+S(d530fc7c,4d5b4fd1,5f44ba0,c0f08f24,889b278a,93ee30ab,935fc112,5e244a58,39c0ea88,5984c2d1,d5119a28,7cd842ca,d3cb54c8,ab6aa222,c01e7152,98aad10f),+S(50f3c13c,a474f604,ca992658,bca68207,76acff7d,d507d63a,b5e18b28,5c5be81,685e151c,7d8fddee,6c9d8513,dbf167e2,c32dd70f,b6932397,38eb63fb,3e4f7afe),+S(c0a72dda,13174682,726ede1f,7ecbaa68,b4b137f6,d44298d3,4e17b7fc,10e19d4a,1e45ff3e,4a4239ba,4a897489,a265a60d,9a91f3f2,83fe2e75,9e770156,c9ebb3ca),+S(7121e14e,7e2a2c57,76b5702e,c83a845c,28785c79,9099a007,54b50fca,b4d9279c,e6b3ff5,ce62fa35,adf45e69,2ccafb91,b805d7cc,b6eff2e1,38dfd680,d0684401),+S(c0c01f34,ae41b8cf,e466b4c9,c6a5d5f6,14f570d6,fcbef768,a81a6c8f,5ff4adb,f47b0a41,1bca80a3,836c85f4,bf8a4731,3243bc2e,8f2ea47a,3b1008b,53caebca)},+{S(4f20ce51,84fb2949,443286cd,8ea201eb,15248749,6e15aab6,f3ea2597,d4cbf47c,bf37770,62691c5a,d6c6cb8d,c30fd3b1,73578a3,bcac43c2,c8404b6e,c085c97c),+S(17ceec36,7fad4365,520599d7,62c66c12,5abeff81,ce7242dc,bde4e799,402759c0,91e024e1,e2147fe9,73091001,984dd3c0,9f887257,73bbbedf,47f00c7b,c5c9f626),+S(dcffc4a,5557f2a6,ac7a3527,5a8228ec,325ea0bd,d9bf52c3,8a78217,6bd716,87658163,dcfc39e2,ad08a499,898a1505,988d9b86,72b6d1e9,64e6845b,cb41129e),+S(625fff43,45337aa2,1efa0884,73a6662e,d5340470,a79576a4,362e30dc,bcf762d4,92ad0a66,d0bea2a6,d7eedfe0,e33295b9,3a656e45,9220026a,5ff3be8f,83184187),+S(410b96fe,7db23faa,7d123e97,c1a82a9,7b24a26a,80143e50,dcc6d9a9,1a6e81d2,ca0da356,dce88799,5f8cc790,64d197aa,6532dcf1,20fe93c3,7e2ff4e2,f14394a7),+S(8136e51d,ca68170b,136d40fe,76980b4d,d4f435fd,e38f3017,99de734c,b2491551,823dd1ed,de1d326,676649a3,9d5ba083,7c48e180,ecd0a648,eaffe7c8,2894e819),+S(64a67d9a,a7a31390,3ed9e348,e7300917,6c1d52d0,be63f54b,aa3ee8f3,f1227a52,ef770581,df4aa013,6d191e99,cde7f42,a14fdfbb,11e1b709,bb540100,1dcda1ed),+S(5fcf0465,a905aa8a,a1da5073,d524e8a3,30af663e,f4307359,c03a4c6c,c423dd9a,58641e67,fa821fc1,2307a66e,fe0129e6,4ace7c36,c3f5395c,db87667e,5e742a42),+S(aae6747f,ac3d8c9a,148009ea,c2d25574,39a8b546,455fb3a4,5016891a,f9372dbc,66084f19,b1d97f2c,22e182c,d5450d43,d56636e4,92651cf6,22772a7c,5b46d9),+S(377dc2c8,13e36bb4,642d1e02,cafce754,2ac6d9fd,c2212edb,5432674f,38e242c7,8395dc2a,39d3b1cd,ae9d7d37,d0c4597a,11f931d8,75c8bcf5,8eab03d3,674d5841),+S(35c598c0,7ac5dc3,7afe6895,29d815e9,406e2608,292ffa0e,7b24df65,3278d8ce,e793aaf1,45f538f6,c133309e,53cb5343,dc1dcc74,985c57f,27361c6,aae23e7b),+S(e9666336,6bb286d6,c86f425a,2d5658cc,1d733223,9ec2e9de,c8ab7295,4b329845,908dc533,b6098e9e,9b737e4,b96e7345,e635f591,60bb3df2,75e165bd,d1cc5998),+S(46fab0d4,7fc6586a,31cf861d,ff5e0bb8,cc12b60a,53103007,c8974ab8,204af703,845ab7de,7654fb36,618dbfb1,287534a9,2d43db6f,2a2cdfe4,5365b4b1,893fbe9d),+S(4d80486f,fe748d1e,f88aabff,76bb82c6,a45db736,76ee0ff7,d77cdffa,2c69d07c,2a52044b,d4fc6a59,fd16dabb,df35bb6,8057ad4c,292e87b5,528a3847,c8784638),+S(2c1d108b,f4945c0e,df62cc15,6bf0830f,7a45ca,1baa636e,9f759bb8,bf078a55,81e34495,d269afbc,1be39ce7,5417ebf7,d45decb6,eaddb635,4480a7f7,8d7dd34d),+S(320a08af,eac009eb,7f254b8d,395d836f,ca6ea527,4e2f309d,dfb7f120,2f1b3cdb,75269a2,41199c0e,5f1cd9e2,d102a294,2324a3ea,cfae231f,99ccc5f3,e0af00c2),+S(8b893fcb,9a524af2,6de5aa38,8ac3dc,2159817c,7062e5c9,d5c9e7f7,dd889ad8,cec6a5ba,481f7e3,88c1cab,c11505f2,39afa143,68977ed6,52ea2d6a,19d2cbfd),+S(ea89b95b,36cd5203,22c8e5af,7461f9e1,a054f23d,2720469,fa74cd67,3a52aab5,5325d16c,4b866865,2437b6b8,598b31c4,59e6101,2cc1b147,e0473527,5935ada5),+S(cdfea79a,8c16ce78,75a9fa1c,5b7647fb,ad641ffc,5b73fb31,d9354a1c,3c1cabfc,184c309b,b0f52999,2a3f6b93,77b9e6a7,6da6b943,d8031408,b71223cf,b3ba9100),+S(3daaaf0f,785a6397,c652331,630931ee,a975c522,35899736,1b7e5fcb,409880fa,952efec1,ebd4c107,b26a98f3,c6683903,a498c840,ff4a36c7,ade569e4,c899919b),+S(7cea5226,a56d21cd,45bfdbb0,7fea6670,40247c70,ef43da28,d1f8bbf0,6e4ef2a6,b03edff9,6a5f32c5,6f8f63f6,ba9feb68,f43cca62,391ea587,81396c7,5d963b67),+S(1f5f4c27,847ba921,c63cef52,8b57fef5,5bdb5344,ea67a23,c173828d,c59199e1,d37f6918,e0b774ad,317dbcac,75c82188,c8a421f0,ff5756bd,853a05b0,c95ef089),+S(36cd4da9,2a77613b,6417deac,1d9a0dad,1bf0e506,de26b529,7fffbd03,4a4663f3,ec1dd8f6,6226bf5f,fedb071f,7027f9d8,d931e6af,e378396c,d0d296eb,a63737e3),+S(9835c156,1be21ce5,db788f1,3c0aea13,fde6861e,97cb2cc7,a67fbd37,17eefadc,7fad454b,7372d969,a6e754ef,c73415d7,fcd4d589,c8e255c5,1adf5a9a,82228f42),+S(5e218414,d9c9f0ad,35ded20e,76a484a1,d41b3894,ba9d3be4,bcb4546b,371d0e4d,76966ecf,9c8f1c9a,452cf971,10ca6555,2ca59d31,21092e93,333bbd61,6eb9cfcb),+S(b105f4f4,40e7ea66,e3272da9,d6b2b76e,d00e96a5,6f95224,34ca0df1,5340c585,9e8fea7f,35bc9eec,f82ae118,bcb6dc33,acae587b,f37b149,1f8312e2,4ffc86d8),+S(81d5713e,a732b4d,98d085a9,75cac9b5,3fa65171,e5cf49f4,684a7856,7c24fea9,32480cf7,a0bc0c50,a4de8200,9343b524,4a0f2aa8,ce67b11f,4a5482cc,6fa00bf2),+S(d47b4f1,88f5e7ed,a9eab2e5,8ad2c140,c6278d63,517bfaca,8cfb64aa,cfbcc7ec,524f6580,9d3ee034,afb1e64b,1a0f8ae1,1e464915,3722e345,bfda9671,1b94a5),+S(16e85ad8,6a953564,39b97957,7bedd0e9,6e2eed72,76ba269a,626fbd58,447996c0,8bf74f51,4bdbb6c1,4de81a3,1ff12aa5,de49bd52,63a962ab,b777439a,47eadee7),+S(c299c6b0,6e6c78ae,852bd55c,dea35f99,d264cb5a,e836b77d,ab209ac9,c05201e1,a558c66d,c9ee7fa4,c777b0db,288b328,428b230a,7c53d516,522ccec4,af0ae08c),+S(63c4624,35ef974b,393b05b3,7d1c89d7,b0d8958,ebd541d7,584e2bbc,7235c795,1d806446,ecfc7bfb,bce099f2,6ce37a49,61b53453,5b65642,c0cd23f5,a4eef9d7),+S(6d36d105,ed8cc5ce,53f2cb69,8ab620f9,469a3e5c,b25bf6e6,d413f414,c5af726a,1b45a3cb,1c889961,8d273993,6a3affd6,233a66c9,4bef75ca,3a8fb6e4,ec05ffb2)},+{S(abdd85c7,a2f8bc31,343382d4,e405978,3874c8d0,1405ef14,85047cf7,f0f71d50,d5a03157,798fe828,a03ab63e,84bb007,b53a5315,1db7af14,e4ab612a,736232d4),+S(31297c6c,f567267b,3c8d65a9,72afc752,e8525eb3,de2958aa,76f72e14,5ad903d7,f4735877,a6c6d89b,d1beb50b,edd1235b,5f5e5d0a,878e4610,e7d756c5,34813389),+S(64706e69,11a7d0a1,2e587c86,91117a27,cbfa64ad,1d5617fc,81e55b8f,64e0da86,59d9af3a,419957d2,b3de7570,15fd8531,a5d07430,5cfd7444,5e7e70b3,57e62772),+S(a4988ed2,89d8397c,f1b897d3,b81d80fa,92658ce,2b935f4e,e2e3f0f9,b193af51,813fb8,73270570,50f23c3,f8082bcb,563ee366,1f6b2af3,f631f5f,916c8478),+S(3c2769bf,af401993,595a01d9,9c72a6f2,699591fe,4b869077,8c6b5ee0,f172a866,f3e0d8b6,cff168c,95873f44,871d27b,df1e79a2,d9e0bd4f,6f90f682,538c1f24),+S(49d93e09,df655edd,19548fbe,affce201,4c6822a7,e196eb98,b9ddfad7,3cb70125,26e6957f,84ced17b,c64f710f,b37656d,31ba088a,98350337,8f7323cf,c57f0eee),+S(53c06842,49997cb2,6e5b4cc,5f166fe7,db0ec0bd,52639a27,d8fedea7,214a78bb,8a8dd3f1,b3081dd4,948255ed,dd178089,a0fa7342,1ea616a5,1f639057,34a489c6),+S(7a8e7d18,3f2aa640,d0e2ea02,4cdca5fa,1767d9f,9ae38805,5d38e8e4,a81d33b7,c2fb92e3,5556fd14,4a894be2,3d97c6d4,30872ccb,25e239c0,d959a24f,aaa77397),+S(a5221a2d,29cf3ef2,f066897e,4ee74ac2,95b34cd7,54390814,297537ae,abdf603f,ec0ff395,8c3a1d1b,5a379417,5a61cd97,782c9683,aa2c7c07,5d147db0,2b134278),+S(3f49da9c,1d62eccc,afc4b88c,814e44dc,8440341d,f347de1,fb60126d,59578dbd,c3cf8e96,2fa9478a,f1be08dc,961734ca,5021a65d,b1b45f80,78fa8e8f,d2813a79),+S(47b16636,f5a64b07,534be14d,6ae37af1,9da79b42,666b201d,d0afda9a,2daeb6b6,f1218111,31ebd87e,e1fd7c9b,d24a0a11,a12e842c,6c00f445,6a342309,9b171f12),+S(a7b5a8ea,1f23ff1e,c1768eaa,2fef0d66,b75744c6,dc925d3f,9068beff,d69b32f4,fe01a23c,b0e5acac,e60058a2,889f9434,9ffce6c,b24f4a3a,662e0079,99bcb690),+S(3e14e2c,e7044716,d42e9b6e,54cb0500,a1e4374e,18917336,e3205e31,4a878b47,18af982d,2c78ac23,818644f1,ec657da8,ad66bdb,3d5a9b84,3f8bb988,4ef8dc3f),+S(71393e6,746d3072,830299c6,c1244303,750742be,361c5f08,6eb314a4,76f1736a,dc30a7ea,9b644339,ce8f1fe4,eeeba07,5bb08934,8135e819,cb061559,aa14e42f),+S(37721b73,e6861f15,7993696d,aded49d3,78994f3d,e2b573a7,defc907e,d6f301f2,ee0e1755,d8efb25a,5cf4d783,ec847425,746fa442,d460cead,56e73a69,42561de1),+S(7803c663,509fc9cc,55b372e1,dc0fa76f,149a0ca6,3db4516c,4abc0ad7,5961e4ac,356c72f7,794a70e4,db3463be,eaa847cb,256c58cd,b6a7d862,fde4feef,d896a46f),+S(32976d3d,a3d033cd,c073b0f,c7d2f445,25646893,fbded1c8,1a0a1761,a8703206,5e6b7900,a069ce4c,65cd84cd,f290f092,2b936bda,af6ea40d,9c36a321,a7c9dcfc),+S(c52c7b18,b5fae5fd,a4e3597f,39c96b8c,6d6c856a,80f1210d,a1ebfc15,34850763,b87e50f6,20b66865,307d0747,a02ba22a,b310712b,cb0bab6b,963c589c,c5a208b1),+S(7de59c8c,3922fd51,68f4151e,cb783775,cd0bc0b,1185ecd3,6ee075e1,14e66cf7,688e2cad,e4d49da7,fe691497,412c9372,c67288e8,ca4b64de,308eabeb,723fda15),+S(ac49d6f3,32cda691,c345f099,667ace08,f6496126,830c39ed,877223a8,cedc8be7,267e6a52,5ddae4f6,7e05f0e8,52b9dfe,5101c491,64d791c9,82249937,c3a7b031),+S(5a92401b,698cc394,c9b714c8,bdcd92d1,20fa72e9,b1311839,1c383024,f469ed22,e29f2926,84c255a9,a739ef0e,5d13cc55,987f5b3a,5c6ed623,29431033,70edb4a2),+S(3609dfba,51616095,ab060e77,d6779025,6456eddb,f4b651c6,442cd673,f893878b,f85fa9b9,442050d8,ad9d9314,9ede8698,91dfc99e,c05a2a48,5854cbeb,55a6c380),+S(332bb85e,92c90a15,3bf602f,45dc33ab,3dea5ef8,7034af81,944113a7,4edc94d9,59b6c879,5f2a824,96d631b5,ceff8708,507db41a,375c7257,7533d8f1,461fbaf1),+S(16e9e054,916b894e,730d7126,27b1bc81,e7689efc,23cfeacb,a423362,df49d87f,303d0428,b701f1e5,fe8ae460,e54adeb2,d4b5aa93,a9c7d7ec,7b903cdb,20e440f3),+S(4e62ab89,1d4c4cf0,2c44915a,4e2fd522,88d75aa8,e22b7463,30dbfbca,97ed9515,a7c21be3,3b5cd522,4de0bd25,faa9c2de,5d6b2f50,b50a6901,b7167b3,c4def4fc),+S(649eedbd,5612c429,2aedbacc,b846e759,4a2b5870,f21452f3,1ac9e697,fc055db9,ca694303,ee206a4a,acfc4cb3,1aa9f117,8fcbe37f,d6bd11a4,669289cc,7c37b0a),+S(e858f72a,5fe2314,951ca096,8ba59760,e3d2a667,e76dcae8,c3ae2d7a,4721afbc,f1c7131d,3e2d0468,ebb89bce,700e0eca,ae83afee,75620938,60e1fc70,cfc7810a),+S(cd351498,29ccb1e6,9b18e35a,72a24b30,e074793d,aab4028b,1c5eefe2,b7b3163d,6bbd52b2,93b43cb3,a19f6291,69ba5b2a,59785099,16842093,1e58dc1,a040c57b),+S(19ffe344,69ba3e43,7d901863,3be7c298,ad8b65a0,49c30dc1,bae30ca5,97ab38fb,c33ca345,efeec662,96802e95,69f0f34d,12ceb64f,30fc704b,b77261f0,ce5c98eb),+S(8a2f772a,a38a5b55,a7081d0a,61bc27d5,89f9832b,1326a230,d81b9f58,4d634293,a4707a0e,a7bf528c,ac62e361,6f09287c,182aa3b6,6862430,dcfef3c2,69d1567),+S(e583bee3,1dbc8f0e,572eb18f,366f88e9,3a7a0484,b4299b9d,335f7836,a222636,8a4fae1b,be122228,be9d8afe,be223c53,dac161ae,ca77ff4f,e14d9c78,894fdfec),+S(8b6e862a,35566848,50b6d4f4,39a25950,47abf695,c08b6414,f95a1335,8dd553fd,15a1f76e,f12ee34b,f2ef43d2,b14605e,db53c3a5,e7cc7c2f,27fc252b,c1641642)},+{S(1c185b5d,e988ae93,eebe0aa4,a98396aa,fff2671d,8246ce2a,4394db96,7a541ad4,dddf4244,3532024f,d225f86d,133b8156,3ea8c92b,f0ddc354,88e6a04a,d41da5fc),+S(addee173,b29de510,58dc107a,47fad47e,c48bf332,2f7c138d,51060322,571faacd,3890624e,c6920ca8,6a9aadb9,90a15156,799dd771,901823e4,9f3bfcb6,8bf05d5c),+S(9e20bbed,ccdd5c05,d683b2ef,852760b8,e246e5d9,6a8900ea,999ac8bf,5e8f12e3,9f28e5a,b4257f6b,b826d076,ffff259e,1caeda5b,7d34f658,ddfa0401,7cd4768e),+S(dc825d1,5f707c17,46920014,9d7be56,acf2d1d3,c444fa27,cefe5019,6f5b317f,226d4960,2f349d4e,9cd10a57,6bf01681,e4981cb6,4235d347,72a1e5ce,7694a20c),+S(812e2cda,3f473919,1f2ac087,7d70d0e0,2ca0551f,10c96d95,51ba4199,22780f90,c8d05855,6b6364bc,d9aff119,5b9ef26b,85cffa72,1e880b83,eed73cbd,d23b91e1),+S(aebb0870,76f5918e,68194fce,42d0b925,cfd2a506,359af62,146c8ceb,8502231a,c1c19605,e0456cb1,3e57229b,45c83ff7,c3695a2a,31908bc0,31b08140,9c2040fb),+S(af7332f3,3ec274c8,d34f47ac,fcbacf8f,7980cca5,7220012b,8fd5ff94,cbf3d8b,d439f1a2,89799dc8,92b7e53d,a84a9e82,7bf7bdb,7240c34a,caef59a,777188a8),+S(baf71cf,7851a758,12d7e09b,192741f2,1b5d2a36,6e31892e,e54c282c,81163a6b,1ef3bf2c,a81acdfe,17cd6b45,266241a0,22caf299,ed4d87cd,68d3d4d4,526b4d38),+S(615991c5,d250cebf,8c7bd1b2,969213f0,403c7da1,a3ba913,44fd0490,88c2474d,4f014177,12142cca,163f29a1,f5790004,32726712,93c2e87e,f46d2138,c14040b6),+S(b1574b39,26ff27c7,b2dace6,6108b93f,3fc75d48,478567cc,66bba29e,750c0c86,2759967d,8d05be25,3f88a66f,830dfb83,5139e32d,6f42cf3a,43b199ce,ab85b55c),+S(5fe92a7f,d1c407fc,967dbb19,e9fd4d,8361aefc,a3d5a9a4,2f8237a3,458e5e90,9b89ce35,57d469b6,9b9034d6,cee93609,c291d023,d1d9349a,d9bcf47a,aed8b2a9),+S(d65b0a5c,41b2dc6b,e5aa87e4,adfef952,621f9d99,550e424d,176ee180,65f666e,a76fad91,3b80b0cc,3d3ceac3,9a465cb9,4d8c79de,92adf9cd,7a4efae7,c85c30a4),+S(61d7de65,fe34ec4c,f82f67b1,75887263,11683263,145cbeae,18ed192d,14ced48d,effac049,d7e5412c,5052160a,6d1b2230,7157669b,856af0e,e3e46a25,2d2ee19),+S(9a77de66,5165a9be,3dd2758c,39aa7a14,1f052358,fbac634,5ea701c8,c93bc4a9,1044e428,bb381024,70108d56,b8b3e3bc,7512300c,5a6ae44b,93b2098f,a13fc023),+S(4ccb2426,b6eed0f9,651f80d5,72b23e78,d84d6928,57648077,3663216a,bc8a418f,1840c,bf5ccdd7,19f7fa8a,33e7151,aa351d,2f620972,6ec67d1f,fdada8c6),+S(53f96bb7,86516e0f,2ac7611a,1aac61d3,cfbca76a,9609fe,e4cae036,52f68271,97e3acbc,468b777b,bd1c8263,5332dcc4,b08b9fb1,9608fb35,cd51e49b,f09d9087),+S(395253a1,b6a349a6,dfdb0d6e,65695572,2a597411,fdea9294,6e48d107,596d8ac8,c57110d4,dd0d35a7,663fb3aa,e15d8c4,dce5cb67,d3173d91,a6ff7ea2,1bd28107),+S(d7becbeb,c47d0de0,899ffdff,8620124d,b29c8e5a,fd71a0ed,76e0df76,bd4e26e6,d8b52fa3,e16e7f19,e925e769,3b5a731e,18f3163b,1ad4db34,7f878381,da75fc15),+S(fa3afae0,4f8c1fa2,778446af,88e29150,256b0413,d9bfeb44,45288e41,29be15a5,9dc76b39,574453ab,2d46cf23,ce8cdb06,cbe7df15,d03fd390,4470a86a,822028df),+S(da56da00,dfdd788f,90a12219,db03cac1,403efef3,ae706031,e153aa16,b3a52eb3,1012ca8e,ae20efdf,41c77128,93fce97,fc66b187,caec55db,7aaa81ef,cc12838f),+S(f07866f0,cca3474c,40e7fa59,26df41c0,e46fbfce,faab92e8,9ccd1170,3ccf79bf,37ed66d5,5e891f4,e644fa04,182f34b6,1f1aedbc,d2a71aac,dd1523bf,f579dace),+S(853f72d1,edc4d953,348528b8,3656894d,67032333,28a16801,64a84511,15c5e968,197737d0,de83e73b,247d861,510ac76c,3ca214d8,ebbb958a,74ce1c31,5e715e87),+S(7c7eae74,dce7ef76,9ef0ce86,cf6ac861,ffc3d4a9,6313f379,fb2c0325,daa91aba,131e1689,fb017e15,e869d858,2dcfc4f9,153d1e8d,246fd613,b3922302,5b5c3767),+S(56028652,bce9dc6c,c8b4ad5c,f9f222c3,412e5bb7,8d556225,2c06c2e4,25a6e31a,2aa8e093,d8653f6,2153972c,e54806ba,666d49ba,3787934a,a37bd65e,79374ac0),+S(2eb98b01,550a00dc,59d280b0,71e472b5,a65eea89,298fe4b0,9f6f0e07,9315ad7b,74e22fc5,3daecdee,6a0b50be,e17f1d7d,d9481e77,28778957,274c8d29,a0d89fdc),+S(7268b61b,f65d73aa,37766a99,9960d998,18aa4ef2,ae8a97b1,db8476fb,32f891a4,824e99db,3157b706,38573513,618f6901,ce1fcff8,f25019d7,c5c45bb2,f3bb4d47),+S(cdea8771,4a764e3f,a94e7356,879b7d9e,da7c5b6f,28c172a6,1c0ab012,9b9ddd7b,daf49b12,34ce20aa,263b4349,f9f88cc5,1334db26,59b7c587,212f407f,cbb2644b),+S(38831af3,193c8860,690a9d74,cc0079c0,9e3ae0fa,ebe0da02,67ad6e23,99059d19,be188500,5193f11f,e34e70a7,e470cedc,902bee92,e7041403,c2f1ae53,7a8bb077),+S(df3acf55,bc6d97ce,34ebeb46,34fe1010,ed3d6d6,383c11a7,53a93123,e9c8381f,94c22735,ae6f858a,59f663e2,12532e14,4efe6a81,981c7619,e5002968,dcb81df5),+S(a8b08b86,4946ac6d,a101eb85,ee7bdf55,24282ca1,a9956e4a,eeb1afe9,87a43ddc,80ff0174,375c95fe,cea6e00,20f17123,5cda4bba,d4ef893c,78ffe37c,205d5577),+S(fd9941ce,e1c26864,248f7035,352787d1,aba9e93e,f5edd333,d08c89b8,4bb9dc8f,85be138a,42bf190b,921681fa,8777a619,878d4d02,11016c72,8bc151ab,1a687b5a),+S(7e2cd40e,f8c94077,f44b1d15,48425e3d,7e125be6,46707bad,2818b0ed,a7dc0151,6fa48af7,d523054c,7d59e574,cde106a2,776411bf,5111f7d3,65c43ac5,df8ddd68)},+{S(282c5bc7,5b9c3f76,73e244af,29f22b80,c171bcac,d7e39b4f,ac7ba6cc,656d9010,e8db2eb0,a56699f1,73d5b5f7,99d39e14,dde34648,f159ad0d,c1c7767a,19ae72aa),+S(d5a3eb7,cad9c548,839ceb7f,67145e0e,96c60d8d,68415f76,73b73700,5ce3a8b,34ae4e12,355d1df1,25149efb,1a9050fd,490e251c,4404fb37,31b6dcc9,e233b9f1),+S(68718b29,86197989,3c5f7b1b,48abc254,13bd23c8,96c8828,7000ebe6,6db742a2,bef9d2a1,bb596fdb,3caeef3b,4d950568,8a94b436,4fd85f37,30b20de,b9e9a4fe),+S(a5ed1709,7932011f,9a597511,a526e61d,f22d0bd8,ae3e15ce,655820e6,b1ff1238,dd6dc7d0,81e70b57,4f235c10,c7c3dbed,a57743c1,15e6fe01,a20ac751,34cdace),+S(ec37904d,9662a487,1a471d9f,778bdef3,430df9e2,26fc42e4,7fc4bf5f,80e3a9c4,8413f2f,1ed55d8b,8448e336,ac9d1418,c48846e2,acb43509,f1a3d935,8cd18ed6),+S(b09f9c76,1cbbb685,f695328,61c459a4,d2b16989,3cbbad2f,dd49c87,1d860db4,dbbf9049,31b18454,21c41f2d,2185e3d6,c8f55dad,f1514ab0,655c856e,3391278e),+S(ed1a335,48864e9d,b41abcad,3344f4e7,ebe57841,9371095a,6b95fe4e,ae59edd7,d1146be9,83adc77d,bd9c107f,3092a9c2,9c271248,d78ce913,7831127c,c403f44c),+S(d39507d2,6ba377f5,c7116aca,78df331d,a795cdfb,54e5c912,8558c0e,997b74f3,fa7971d4,32cb5a44,589dc705,de28ad0,382206f1,6e11229f,86ff82a,efef3131),+S(641dc311,baa77b14,35f408e1,528445df,53c5ac5c,32803a3d,84e8fb66,60d71d,2b355a47,76980bfc,8a4e0ac6,a3bd7b02,a6b20ffb,f8650b16,89010456,6953e49c),+S(c3dd73bc,cfb744bc,57bc95f9,3c260df7,7f3b7e74,9e4a5237,f3865f8f,f0c89489,15d58dfb,83654754,80e53bb2,a1ba430a,ce213c38,ea71c7b7,51b4143a,fe2bd124),+S(3f883fa2,e834df1a,6e9b5c46,b663880e,9a0b42f1,891b92c,eb30600d,5641813e,7acff194,a5fb76e5,bd3d8fd4,2c7f07a8,3a991ba6,7f0e4edd,c55e1d8d,3025d590),+S(70c8d4f5,21d808e7,221bd5c6,31f171a9,5e7aa358,4477068c,2549c59e,228688bf,52badf20,6106d5a8,d7bff921,580eb5f5,3a53aeff,e0369f9a,1bcb282d,7b4cc26c),+S(ae08db34,874d39ff,bfb9c92c,5e4253ca,7ed508fd,d12841e9,63600461,b2b3a0e1,dc0504ef,d209be71,381eefd2,91508120,fb6ec1e,df62d24a,cb1d77a9,4eebf1be),+S(627027ad,4aa88477,c6240517,87a25b88,7d5b98f,b968221e,8e45d584,3db6e0bc,34b553a7,c6ac7004,69367afd,17c5eaf8,7605ca18,6a57667b,650fd8c7,18ab76aa),+S(573ef2ae,72ae8fd5,eeb0b720,f8967b44,f7d9d96d,c8a4825c,23a3dbed,fd2bb442,264f508e,efe5e0a2,55e55a54,bbf739b5,757d0a15,994ea9b8,4e139738,7c484786),+S(28907848,cf84eec6,773a384,ce5f4a5a,24c8afc8,606488a2,ccdeff25,6f896dab,ea87d4f,41df8727,2fe84537,d11126d5,62618bee,a51008ca,895a8375,4f05ec5e),+S(163db4c4,536114f0,75521627,c61f62d9,14214d64,ac9e66b0,d85b9991,62c54c5b,7ffc24e1,11c0c845,1c574e9b,e4b56610,696d3667,a6e6abbe,9d1a5ea9,4122aa1f),+S(2ec11f2b,71ffc28c,fb5e779e,7739098e,c969bc78,3cca5a22,77d2bf53,e6574d1c,c5e9fdf2,89a3090d,e24d13a1,bc8377d9,de0bcf4,63482ebd,9620cbdf,8b238fb0),+S(30549ae0,9a46820f,f49423b8,9c6fdd48,703132fd,ac166dc9,90609a32,49039f0a,b8c94b4b,36d39247,732976e,fc16d500,ccdc07f0,d7b97db5,7a1d9fbf,d8cb5d2),+S(98685f94,a043399c,89e74674,240322ac,5a595bf5,41aaa44e,d781781a,10fe9225,4506b1ef,7561b811,53f44e8f,325f9222,e999013,30523885,d8c59864,db13a3ef),+S(9acba196,3014ea9,1baba28c,e273c6e5,b9a2e1a0,98216c3b,194a0b56,dbda7db6,f0a3358e,eec737af,2e313262,b29ddf6,2adb9e97,9f56def2,65102272,6b976290),+S(e81e91a1,7aeec75c,19df0ef7,fd07ce2b,e477c031,179e3f99,4ca13857,e2b5ff93,65236424,aaa8b6cb,fdb2fb20,46ae3c3d,839d97ed,217edc6c,c774f889,d2ce8b45),+S(61e60aeb,821c3f80,b53ca78,2c3b4d21,960eb0d2,c90202f0,a5fba651,1725ddba,b029275f,690d10bc,b52e8bb2,acceb071,f07834fe,64175088,a97e26f9,8ff34432),+S(a931c410,8fcb4346,6802dd4a,8ec2cf62,cf4c5558,8129299c,b3a87e95,6fba2a34,c21a8dd1,43d4a639,339fec49,f56d717c,658a55af,ad72da1,c754fb9a,117cf6e7),+S(fb5c106f,da32fcfe,ffe9b5a2,7ac8cfd8,d9a73da1,5fa6340f,e09d187a,7a83cb88,a3f4c60f,90003375,11c39100,ba4c4721,c6c138c1,cbae09dc,46d1a1d2,5baa95fb),+S(dc25e18a,18f0035c,2a05e80d,d6b38830,7fb3b176,a66ae451,8c5640db,7540dd24,3ba83beb,3e6b29c2,97a0ead6,148f9b93,711556e2,e5fd513e,ee649228,c62d8f3c),+S(ecf7b689,ca03b840,739283e9,c3003a01,65ea3f,3bd17e06,9260c0e9,ad403273,5e0dbad6,47997fca,c0d7ba2a,170a7954,67036ae8,e61dc532,b5fe184a,deb8a7ea),+S(263e593b,10c982d5,1bf89ec9,71f6a3f4,60e53bf4,cb2f6af3,2381214b,2e981bbc,e255bc11,11470eb8,894ead67,c618d7ca,a6b76ae1,a230ef05,3830d028,4a7faf37),+S(f79781e7,a4137ac4,7a9a9d00,9d239b37,6cd0fa3c,b9f5de46,8cba5a11,ffcdd69,d10ba78,896e086d,5e25444,165e79d9,7b3d485,1a448e03,26d8906b,2f27745b),+S(a4d28024,11f577c1,c5d08fbc,457a46bd,428f4d2a,b29475ea,ef622876,593e49f0,e4855491,ac0342b1,dc804bc2,7ae23877,82eeaf22,52874a00,4d4e0d66,b07b434f),+S(87195a80,dc83be4e,cfc9d4b8,29725cbe,11101c26,13c98f2,641753af,1ee840f8,f9fce233,66931c51,4ea09224,b565dec7,22763d8f,6f572057,fdd7d96e,9811289a),+S(210a917a,d9df2779,6746ff30,1ad9ccc8,78f61a5f,1ff4082b,5364dacd,57b4a278,98f1e4ab,af4a1a84,85c6417e,7298c82,c87619e5,500df403,80d8ec01,f384d9fe)},+{S(6c16768c,433a000b,adc47b10,ba4e132c,f5480e65,ae83d1a6,8aec34d2,c00c76dd,ca1a47dd,66c2d74a,ddb69283,2ea289a6,ae679669,edd80bdd,4ffdab2a,defbb542),+S(f757e860,ed04db61,594bd647,5ae81b7e,d6d2fa58,80cad10a,7756fa26,810b8543,f2aad599,4e491e02,9b1ae256,2c90912a,1c9aa6cd,dfc2331d,a0069a79,861208a),+S(d9f269d2,9aa777c6,9989d706,91403dfd,9025b491,ba03ddf2,dab8c9,af7dc764,1b39b85c,cb4749fb,7f47086a,ce63924f,3ebb4213,af5dfc95,fda796e6,c6b0b8b0),+S(d05e14f6,fe6ca50,a23e9339,e449f771,98e842d4,80a72d5f,8f5e4c06,43547cb9,869e3bea,6b19e0f2,de83fa8a,e932086d,d66e838b,637ea603,5f0fa081,5912c8f1),+S(9f723d81,1818046f,b7512abb,faeb46d3,52d8da9b,3abe819f,3861f9c9,963c583b,37df0657,3f2bb428,6c8b3efe,f6941e2c,4e48d90b,931cd0a5,78a4b52c,6581ee7a),+S(e65f0b42,54ad9df9,681c0db,3428ccaa,11194df3,9e837aab,4564e1fa,254e6f97,43e59d10,54aa35b5,80373e08,cfc02aaa,4f581406,58341e67,7e50977e,5bd893dc),+S(605d61db,589fd91,78a65cb5,99697001,73afca81,23f663ac,5fffd0b9,8f5e7a64,a976a9d,a47745f,447ad4dd,7eb63875,c228b979,a7dda50a,d994df7b,545d0ede),+S(43298aaa,faf20e9d,c2240256,493ef19f,5630db6b,f6376e4a,356bd034,98f1be7e,737551c3,653af1cb,4f8c1e8a,347f50ca,142c03e0,29007f29,c76bb763,b52ed053),+S(8afba782,d6373f0c,54734f1b,4b854e63,bf2a3b4f,23f57a3e,6c2eae86,25c691c6,da3054aa,228b9757,b7321da0,64516249,652fd814,15017584,2c7683ce,1a3638a2),+S(3156d359,e01d64fa,9c8fd8b2,c47c3492,82dd459a,fe89d94f,35906da2,c6d0208,85a23f48,f0a7448f,c57ee545,3978e2cb,6f2bbe54,864477d8,a63775f7,7ff7289f),+S(88e1a44b,1e206eab,49fe97af,30be5e47,25e1011f,312a5222,e9e80819,b3f26357,63dfe52e,10317c4e,227b2a5a,d61b713e,2d93aba7,f0a51e0,b5621191,40c58ded),+S(d10de96b,f2e4a6f8,78e0f37e,15569f3c,b9717a38,7fb98928,6d65d171,4b81b301,2c0a46c9,6a2e3884,e7f3b146,acc170d2,6d12b959,4b75a901,dd535016,f0355ae2),+S(eb36b865,812ae4bd,7893e50,5aef6f14,bfc90c1b,42e75ea5,91615aa,a2101784,1523537b,790b2a61,fb6696d0,a622ff31,efea1255,e1dceb86,763985e2,6c5ca8df),+S(d54be697,e41396c6,3d63f96f,bde9bba2,36ab1649,3c156159,3df81d69,c906fe60,89de1769,433b5678,1f7a2206,ca98258,20d0c7dd,a6d5b672,f77029c2,6bb59f33),+S(d5aa72fc,9063c2f8,bd0fec97,da30dcd2,a5b36aee,7894463a,f7042795,1998c979,ed90095d,bf2d3a67,2d2f1a0f,9737c4d,e8f3e773,c04b77d3,a2345dda,ab662199),+S(ee8cd53e,8ab64281,b5cad323,f03fd06d,7aa166eb,df9185b4,8d0eb0e6,1bd0bc61,4781263d,fc518e4,809e5ea7,7f9df238,1ee7b6ee,ab25c1d9,5cbf3fce,72fdd615),+S(ddc5e95e,2a46736d,9bbeee74,74364bf9,e1d2724f,c43522c,cffa05a8,7d078be9,60908fb,809ae964,98a26cd9,67532df2,409491aa,73c46803,eb58861,7ad86745),+S(ae503a2b,b6250ff6,6ee615d8,41cae4e,751160fe,aef7f33b,dd1feaad,ab236b58,6e53d2a8,8f09f78f,96d49a6,2f98773b,a282b575,ab6e24f8,4d604c3c,8583a66c),+S(8a502d08,bb3cc1da,438c5780,e2120c50,12c1a972,8aaab6bc,5d908b6e,2a83dbdb,fa02e62b,85d7de78,8cf11d9e,ab406523,bba1f912,53006a89,f3a491cc,dd99575c),+S(b52891bf,5acb0019,a8d10b94,87fa47c4,22f83a00,ef539e91,44bd9f7a,d5075716,ae58653a,b167a9e4,b71eecd7,4f4a8786,19c19026,29c0018d,9f082e7d,5920b2f),+S(176170af,b40a3e79,8a88b98f,fb6c578c,d1ab56b5,b7f4142e,b2d84a59,1b009f97,6e1d5682,36176d58,ce5fcac6,4d4d2885,5db107dd,5215c71f,b4076aaf,d31c5d24),+S(27359f7e,8d3e3dcd,ea35f603,d8fb15c0,bd63c08c,3ae4d2fe,8cb6434a,ae2e716d,a0d64207,8fba00dd,4683d597,27f3c67f,3c25075d,802a4ea8,eb08c20b,47a941f9),+S(1e9d955a,2f68478,5227e866,491990a5,62c802ed,1b106bb5,42d02d29,93542067,fbf5f466,57707b3,3f116a23,fe5991a8,90a9583f,fd063943,37a19aa7,e125ccab),+S(b5c4c10b,1b0e0813,37deef6f,c089d2e1,ee14da2d,cbb48e6,74b7dbd4,429e22eb,fdac245,b109947,8f6a53a2,8a1ec4fe,da43b4a9,2ef49e25,8f9296c2,88c48378),+S(bd2f651c,ff6e614b,1d6535cf,c3a2c5d2,da5307b0,1cbd3f48,655623c2,55503916,3715b0bd,bcf29d97,63d7fb35,f9c5b54c,769a863,3517a2d6,8dde74e4,c4277779),+S(c4c2a8e8,f1e257a8,fcd0b11b,30635c5e,782fedcf,f99b0b95,828e1369,3ee0af73,3a08abb4,777a066b,49ec4c01,aa5b0868,f100a473,e555def1,7c5a9d84,b1fd9ae),+S(4aa77ce,15dd97ff,47c1125a,77bcf0e9,d302b79a,e8a919c6,a875e5ed,eab8c2ec,31a09dc4,89a90240,334836f6,302d7e81,57f19762,a9b5f727,6c276e63,560a9d10),+S(3731162e,66a8d2d8,ff4df3e,95950103,f5a03f9a,86bf37e5,605746,cf4be846,e19d7835,10af5daf,724be4b1,932dfac6,23899ccf,7e3e58ab,5bf3265c,667cbf28),+S(6e2114ed,297ba44f,c3926603,bc03a87c,af3e9f2c,8bd84e64,afcd9846,bd9c8f0a,faa6e5f3,3d90f91d,82592af0,7f3a26e2,f6f4138a,2f06a6a1,4286eb71,2e95cf94),+S(50d775b5,f72d186b,266a14e5,254cb5aa,49fd8633,81c36b09,842632d7,ff004130,cbfe11c4,f0b15aa8,3ae8dbcb,9feff9c0,d68a26ba,11095b3c,ba94739a,2091bbc2),+S(8f3ccf31,f8b74b9b,624a5d1b,7cb1096e,202fe5e7,233777aa,859864d3,775732c0,980e32c1,d2c61ace,7610b926,6831ac27,56f19788,ab7a77da,18c421a0,9a46bad4),+S(24cfc017,6da2b46f,a8bb5bf9,636be1ef,fd7e297f,29122fb3,e84c9ab0,c18ada5f,14007044,f8639e59,67978eb2,a21256d8,126a635e,5b07eb0d,97059ec5,6875a3c4)},+{S(6efcde8b,e99d9ee8,ee0d6b8f,a76584bd,5deb67b1,415e729b,48f3d41a,f1cc1386,4ddcef4a,a6ad5be2,d1e83449,9eca4a8c,73219f80,464a4a9e,ebb7f3f1,b70c9fd2),+S(24fdd052,a1e535e2,4eb79ffd,f03093f8,5778241a,b845b548,31b9a82,730ee3e,c6ff8ebc,7edfd9df,9b7410a,7f54c93d,ff0c682b,152bf4db,1b79c0a6,9889797d),+S(aaaf86ed,31dbf395,687c959,6c445b6c,dcd1fe7e,ba2aa13d,1bf41867,dc87b30b,582b9683,729be5c,85fa83e,2ba2abac,e3037262,2a24aa35,c7753312,1de2fb93),+S(23930d0d,2400db1d,56525bb4,67172fe5,e930bf86,21124fa4,6c5a421e,10b059ea,5e11f202,beca3d5e,dc9b282c,2e86d5d9,30f8f5d,27a5c4d,d2cd6dde,6d1497ef),+S(76ad10d0,bc92ad8f,55b665a1,8ee84e01,2e92dcc9,37e0c604,59bd6fd4,ded2d9d2,d4ca7386,ce0c4c5,fd37da9b,eb8fb040,97d98891,35a5ecc0,320dfffc,95ed3c10),+S(10b324b,e959f0c8,c8a82142,4a8f87c1,fdeb7f88,258e1021,c9cfaa66,b131f3a4,590e672a,daa8d547,161f635f,153fa12,b3500694,677af3f8,90dd4ca6,9620bb56),+S(afdb2acb,ebfdc11b,3577177c,d8bcde00,65151495,79c6ad2b,f7386275,a9314317,87d7786f,5ba775c0,ea47b141,cd0d4274,c7e58634,b64e4c58,f7f0c595,5a307250),+S(574cddbd,59b34df5,30f5dc4,61884ebd,1c867ed5,6cb60832,4a11b1f5,29ebf733,1bfea852,34256807,1fdb4f5c,485caa73,7136e3c3,b4b8a39a,389d7dc8,724f16fa),+S(97ffea2b,5de34e1d,495ce082,d0097b72,e7daddb8,1cb622c,2c14e814,bb0ae278,45fd3d2a,9d1e6530,61b4a356,65aa9e70,43766950,622e1c25,2baab265,6d4ed95f),+S(de627f6a,a7b56d85,535c398,80d0276b,b910ce4a,6066435b,512e5e0,21ef55ef,753033a6,ef89f053,c0e662c8,1557e6cc,d8b4c8d4,5204f5d,e1c8c742,72b96277),+S(b126c35a,d7993bd0,164867c,58c88421,d2cddb6f,d16a5966,7d9683bb,1b428eb5,a9ed1bb9,e9eacf9e,e712bcda,be629143,ad0e7652,82cbfab8,e586cb07,131e5b1d),+S(847b90cb,8837f488,ef027a05,71b2be6c,620cf86f,ead235ad,e76e3408,d0dd1073,9a2667be,6ce36e7b,d76117a9,fdb8f1b8,7c7cb45e,1a03f53e,7b32bc63,6f274b4e),+S(8ea21457,6f1bc2c8,fbee9065,c2cf5c3e,7a3b9fe5,403fb980,96040c2e,c6fe1488,dd75b454,acef4d3b,1b355a63,f0cd17a6,66aa9e65,f1262629,f0c7d1e0,33571b58),+S(9e11bb60,ba4b2d5d,fe53bb9c,598edb16,f3926bea,1cc90eb4,3e05ca34,e83f1896,263d7ea,50d83b8,791fc911,a4f73cac,4d42a09a,85f5ae68,86cb268a,fd562dd0),+S(f741856e,f353a7c7,17db9a13,4ab4aaf9,13c1f7da,cef08bfd,6f81dce5,b1130e20,ee63dd2f,48e15f68,d1acbf49,705fe010,231e26b5,14146c47,1a689960,d568eca4),+S(671ef05a,410b41d9,3b092b04,e523468d,44837d2d,26dba670,27400715,eeefa2b5,686d318b,b49eccbf,40dc18af,f1938fa9,b16d4d2c,c19dd2ac,47c7830f,89b8d55c),+S(59ea10a1,e5bffd6,a34593f4,b986e37b,5294ddbc,60d92906,52c6e9d5,75f88c55,c0a2eb5,6d04ab99,abb5b76f,7b2b55c9,c09d44f3,3785e3d4,64554c3e,dc7a334c),+S(37f2c7c5,69c6fd15,9b721d8b,8d40138e,a8873b6b,452af0a7,89a50551,e9703c1e,d114109f,f9e6d7c0,c51a542f,b2e3ef5b,74654bef,5eb84aef,c87f5096,2a30c078),+S(1d280637,9d77e509,126a440e,b1e56f1a,8723728e,97c92420,5ed13081,98c868b9,85003989,93a4a600,dfd0f092,b13a1186,c1c52dd8,8fc8eace,9bd4f1c1,b47741d8),+S(39aed6e6,a123061c,228d3d1f,857e0c9b,29b70cdc,549b4ea1,9fb6802a,8d8beacf,6bf86967,98e3dbf6,75865a1a,b86d5bbb,10f16e8,4f9104a0,87602c,e6946aec),+S(aa770804,4a996b1d,5bda074c,941b30c1,d1474da6,47d7c4ed,248d3a9f,c3c3c525,10ba5652,b20482f,fc2434ce,ac185d8d,af6cc6e3,61e77d3f,258abc0b,55610879),+S(7626a96,9f9ef188,3ea82737,83e5571e,4054fb73,6190977a,299c2a05,d29f60c7,172d4618,e5f88055,ebfcdf9f,55267ee5,cdf18396,1d5a2a22,55b87ba3,c7d7d2b9),+S(1a550684,d1195da7,c4b09349,f149eae2,5a1ef23,c9a81109,115d93e4,c98cdbda,c31d7dc1,b7efd019,c491010e,30f90ed8,7503c4bb,1b37fbce,3dae199,6609e3b1),+S(8d2306d2,dd8c753f,2b093e62,86fc282,ba3e1dbd,7b4ba101,83d1070e,d2d06e67,97dd14c2,d2c1d147,486a3dfc,d608ba28,d63fc03,251a106c,9811b088,978e3a5e),+S(f31a69ab,97039589,940851f3,cdc98bc5,d400ff93,63794f81,4d88215,4f00db99,56e510be,7f41b009,89792401,13641590,40f5f305,f27fe1e2,db1cd7ae,887ff5e2),+S(ce96b3e9,6eb94b7c,8bdc7b57,efd2186f,62e23e72,f11337ab,be7405d3,43b4d762,cc0dc898,33e7a632,d0fed52d,487f2c60,96c69664,f698a71c,3f7f8a29,4f181add),+S(bed97e25,7d31b5fd,36b41227,462d9122,706da670,d432ceff,5d37d83e,fefda56c,c0cfe30a,2c3b3074,1af492b6,e3797c4f,3b00593c,6806e2e2,f2cff401,6e877ff6),+S(923bc6c9,960f6e4d,ca2a7070,6d160e19,83a16b6c,8535783f,12c5ac69,4aad226a,c47f08b,6b2056d2,8e9f119,9ec6d5ce,b48801b8,7ee56280,d6a48352,b2b42b1),+S(b3cb28fb,7465cdda,85823dcf,819400b,357bce11,23d9229a,eddb8262,53b246c3,cf035ed0,b624dd68,8a31eb5f,3b28e83e,c0bf9453,649dfe4f,44078eac,9345f2a6),+S(c69aa2b9,ab3c5e45,8713a912,e7f95bb,4e5498a6,d4090323,5cfed1c9,c2a60709,2e95e198,85637d55,744e32a7,98c02c7e,b29f3bf5,7cf7c870,7cafdf41,f6710f0c),+S(45996af,5795ea6e,43e0fd29,671e119b,8b8d6ad2,4eac90ec,d27d5db1,b4fb6a39,2c0651f3,1c7d93cc,98d79d7d,f21110fc,8c1dd74b,f1ffefac,a3d52484,f8da40cd),+S(264559d8,7829256b,ed116900,d82d0c37,9f0e4d12,53c68e6f,cf2d41ae,7cddab8b,861a42e6,d92caed3,108439c8,fcbf8d28,8579ce50,c6350e19,3609b4b9,ffe217bc)},+{S(ac13e0db,846df259,fc38d6,3b0248ec,9fcfa8d4,bcee368b,1f4a66c6,d41f9163,6721b0df,2ed06fda,9b485cc2,aa56f1f3,3a913e99,f6809577,95280451,9ddc96ec),+S(b6b7227f,228da269,a0e5640b,8a2cfa34,555ccdec,2243dd0d,4b2da0a9,b4cb5e4,6afe41f9,dc129d28,4786bb76,17786c8d,42597435,240f998a,f970620,90d32059),+S(460672e4,4f2768b9,842a98a5,ca8b90df,7d9f52bc,3fa2665c,4272d7ad,5f48b992,6d7f8b36,13b38fa5,80ed1d4a,21d196bf,be491b46,49c96da8,342441d3,f4af4ca2),+S(1d3d4ab8,b7c06136,8dfd612a,25f04016,2bd3f6cd,cd9cf58d,c11647a0,d28b629f,434dca08,17bbf964,eb0a316c,b2b0df20,eb2e965d,c4d8d795,1d4a6e66,5ed23d38),+S(9c5d6342,303bc7c,73763cb9,2e3d7069,7d913f6c,1a6e2f47,39470da3,22b7c1b,825c1a54,395b9b41,ccc2e3b5,3fe1092,f04c382f,b2ee3a29,fd59e255,5f22fc15),+S(5c751285,a4b55535,fe24fe27,568868f3,afb43cf,aad1d2b1,c6367daa,ac9493b2,e2388ab4,414c4e4f,e34a4c78,c869dd93,7094ce2d,4f4666a8,2eef8047,3b681fb6),+S(8c1592f3,8d73e277,d3c18d4,ee3eabce,32e86f92,2b27c2f0,1f50509e,74dbc211,399c9507,43cd9e7b,200c255b,bd25670e,cc111462,2d5dfacf,9dbebdb,53ee59ab),+S(85320e36,5f40235e,621171d5,c8008845,890f521b,d7e2cccb,88c7fb7f,a08200c,96bbe8ec,74b5f1b1,2a6ecbee,2aea6f0c,b6d0657,aac3556c,ddc4e46f,17cd31f1),+S(5fc21f20,13403705,687b8ad3,387a725a,f2e6300e,13d28403,569d4cb6,5dda7f34,bb709fbf,be95aeef,c00846b6,a4645b72,dbb4e1ed,866edb57,7bc5d9a8,2b774b0b),+S(fa40e658,588f8a5e,29d380e9,c1a6482c,888f53e5,e331f8ed,9b1273a,56d094e5,5486cff5,3b7baaaa,de8a51a6,1d1a9255,95ecbea3,39955c0e,172de4c3,4762eca1),+S(9f87d04c,5fcc48f,375c40af,3197c28f,c62cf3c5,10fcdbde,5aec79a7,4e6a6bc0,9a6cc172,23a770c7,a03b5333,6922170d,e9409f3b,9846b9f4,41832ae1,f70f5c57),+S(bb66dd5b,2f88786e,736b50,e536a0f0,3d59b86,511e95ca,1bab2cb8,875bb187,f8215527,c76a5af,e5e76a33,eb2622d,5f822ad1,d284c68b,c840f65d,4f731c63),+S(74d223e4,bce2d6b9,b2fa9482,46327e04,18eda6c,cfdd76c7,cda8be62,3f6dd3a9,b7276bb3,817c0e72,e1ab002d,50531065,e1c4ca30,9c6d6f18,bb5796ee,457b4270),+S(80298b62,eb4d3ff2,e10607dd,dbcacda4,3bb30e57,f3c8c7e7,6f9f3968,bf391316,fc72362b,48c8b606,4e428e6d,1ef2ac87,931caf75,e936a33c,228a5caa,c460c5f0),+S(8519f27d,9560acdc,509fddee,9b4a4a7a,8b13496f,14760a08,22609f3b,2ae07963,193aa9db,b98293f8,e70d7253,51d3893,a9f5fc73,6f3c8e65,28a2dfd6,5dedc220),+S(49d734f9,c8eff915,fd66757b,d6484bc9,548f20a,d8c05959,f651eb36,e45cb88,4c594f79,7651b49e,929932a4,59e3bf21,3e74c0b8,acb20907,697a25a7,ed21057b),+S(6a528c6d,19b1e28d,b4d9ec9e,19c4f7be,184ef845,1f41b322,e5932f05,575bcc4a,7350b90b,c22ab41f,40c13a80,18749e8c,275d3e5e,5d687df0,ddd47133,c092eadc),+S(6f3df40f,5647143f,cb93b23,4795d9a7,708db6b8,2e2df53c,f214de4b,61eebaa9,dee10664,54b625ba,34ce4b54,f7285714,7874b5d0,6b38b1dc,37b7471f,9208dcbe),+S(5abfd7eb,c4c5dc14,cbf0e335,f2e87e7a,7db96a2c,b78000aa,64fa8aca,517ee1e5,d65a98d4,20d872e4,4c43997,55cca5c0,bb94ccc0,b25e30fe,8b5a4fcc,7006364f),+S(1bf3714b,da04d769,782e37cb,c4a4b347,f9fc769d,a18e4940,d19a205a,bdd22a23,d0852b21,33b04274,183f4de4,9a20769e,4a08ea16,ca8782bd,84a4da7c,64c928a2),+S(773ab884,a4e90454,ea467caf,f18c3b64,e316468c,b5789fa6,4958f73e,ec3204f1,62213b85,b4838d8a,fa3a14f9,32db7d79,dec538c7,d872d9d2,be1640a2,4e367caa),+S(33a283d9,9b7564ed,6ed10d88,ba26ba,fbf3a375,e00e10d1,577fce27,2c204324,bf84dac3,40736625,cf0e6be6,98072c6c,5fb8bf9d,2850be84,ded3f652,569370d2),+S(62bdb467,596ffefa,22b735fd,d3dfd959,d4a6e187,a19d4c1f,4d647b4e,db380c3b,210a8e93,d1a184d0,a3548be7,6283d180,8e4f32d9,52834c,515953f0,4ecf9acf),+S(ef16d3a3,233f03da,5864801a,c246756b,d1356137,971bc164,b5512067,b369dad2,480e3d32,7f1df8b0,646c3b58,a51126a3,e91522de,ab77d6d2,f2bedadf,1219b877),+S(a6834869,c006d044,a9dcfb9,8a5a14df,86469fd1,fd0cba06,a4e8ec1e,1fba89d6,c1a3e0ff,7abeb1e,8cac11a6,8c1b4c1c,f663e615,9f508c35,f4747f50,84b247e9),+S(203d13c6,53a3c36e,55a836de,b38c7443,681d7b7,c681d71a,38fb0fde,986ce9c3,5d7dba97,573ffd85,b3fd4417,f09192e1,92461c4c,125a9947,ced9c737,ecac65b2),+S(c48819,b8f32966,bd50f162,30f5c0a1,45cb3570,d9c4b104,4c306696,2f4d6667,feb08ff9,1f543c1,35b6e0f0,b21d7624,91ac096a,181bf093,fcf8f4b7,bf6559a2),+S(31441031,ceabfbf8,59bcdd8b,6e177f91,df7bfe08,f9015172,1ead3acd,ab64acff,e36315bf,6f087118,32894704,8d2fd259,6b8beae2,e1917341,d690a1f,786db5f9),+S(e3e4750a,310c48,38920654,b6afa032,79589d52,74e48139,6e22d9cd,3c05fbdd,f05868fe,5452da6f,fadcafb6,69e5edfb,4b9a7840,3a305004,345ddce1,eaca43ac),+S(3659ba70,60d8200c,9512facb,5c730111,4cdc2b9b,aa5bde14,8ad9bf9d,d8f8fb8c,b1185617,f91fe5e8,ec68da07,138b6780,e1ebd12b,1bb44eca,8a1b9472,8337585e),+S(1a46b7e9,fe99a4ea,492fbc90,3281b924,6831fe59,9360af53,bde4ce8b,43ed5996,97c317e1,5c0e23a8,f1c11f7b,5f9c140a,af786b56,10ad8ba3,d11b12ed,17379f81),+S(f16a409c,677a40be,402f8efb,3752373c,aced053c,6f702b82,8bda222c,a412b6fd,d5becee8,ebacd866,285958a5,8b1cf1b1,e9abf9a6,db61435b,d9725187,135fa955)},+{S(32c932eb,6fa35974,90a408a6,ce962d7a,ef2bd22,72cdaa,cb80f798,9836abc3,3e145848,c2f8197e,f0264d7c,370d1784,7d21a09c,77fd9f7a,73245ce7,2ce5f3f6),+S(49d837bb,63890b4e,8a4a63ea,6d88599a,c9961c20,80dcc955,aca6a101,bc935f16,358a7f6d,b540ac03,78d83bc,304cabf1,84c7580c,46c258ec,58f22254,e3e03aa),+S(23516ddd,40dab9d8,63dcad6c,cd325503,b783379,d870ace0,9a0b238c,d7b6b2bf,b1fb8268,a7814efc,54f3d637,88956b67,a3997a31,10a738a4,94786d95,a5fa1c59),+S(6b4e215e,df56e6ce,6378fa98,5d604f68,e3561275,788283d6,c40cb249,6d16310e,cdf9537e,e6f4304,dbcb9df,f8b97a71,a12f014e,29867e5,6b09b388,78c9ce8d),+S(f4f30433,c933dddb,949ad868,cc0d52e5,247149a,7ec98f12,3e7f63b4,acf6b7b9,949123eb,9fb848fc,d7b94401,a64b21a3,53fde44c,d93dae3e,b7a2d3d4,78055af2),+S(dc3523f4,cd24be1b,30787dd7,5140fff,b66e4487,55e9a3c9,6124fe59,c07faa28,47b945d7,6d37b855,8ede59fe,e297a8e7,81d3ea96,f0a81588,b68db767,9b9641f5),+S(b92cace4,e31dc724,3b3530b1,f90de1c3,47cc39e5,5b247455,a1296912,4e3c2a09,78f89163,c735cb13,b1d8fe7e,547027f,68d8f864,a1f093b,22c0d9cb,95fe28c2),+S(8f7ed1f1,77238a68,bbe32e4d,ae6d67fd,be07c9a2,9fc6b940,6ef81a77,65a8fb75,98e627d8,d32095bd,5913daa5,920c5c60,334691be,537b08d6,da5b8c19,7bf81c8f),+S(47fa27ac,e035176f,34c59581,8d3dca2c,a2b40e53,29756c55,7cf81f75,4f99316a,ddee5921,f381ce26,3634a34d,1b4f9513,4d9f0e50,5e96bb79,b87d98b5,282aee7c),+S(7584cb68,60ae81f2,e0df701c,97d7aa29,8132cb96,fee4ad59,15424bec,2e280dcd,4b76458b,e3926b5b,bf59ad77,da4a96c9,1f9147bd,88a234c0,74b0e09c,a6993228),+S(2cd4c11e,70d432ff,38550aca,481667f4,d09ad11f,9aed62d4,968492d7,5de28dae,82514708,3e5bf46,341177e8,9ad2cfb3,a215578c,52f9436,d3952432,e9acd430),+S(2b524c99,2b18a6e0,30863716,362d236d,e385a10c,3679eec,2774edb7,a1a89be9,1abb3b28,3477769a,5c7b4580,93efb22e,f2e61296,da90d4d3,1d6b2ff9,1766f89d),+S(d642c258,9d0e47ef,f5b2b60d,9321db58,727315ad,522daf58,3bdf35d3,336f1081,1019505a,994030be,484e5340,abea0b7a,51276c99,29cd1f1b,9d19798d,aaacf3d9),+S(3e5e09b,451bcf5d,549f1d66,b96da0ea,25e63270,dae59606,bfc3165b,f89f29fd,2ce591f5,32d57be6,4fc48aa4,ba40231d,9c104615,b76ed6bf,11957694,16d2f0e9),+S(4756965b,82fc23bf,64041d23,a23cba32,cb71d3e7,ef3e6c03,51b20f3f,dec049b6,75f3a293,eae07f4,362c47e9,44a78561,323244ac,bcecef0c,6ba2f5fe,d1933679),+S(f296e9c1,41694ce2,c197ba85,bb9f172,54fc0bc7,f89347,a0e92b8,58491a39,73c7fbdd,91c88ce2,bbcadaae,df8880f6,aff07e8d,3a1ce05,a468e3c2,3008d98d),+S(b437d387,ddae39cf,e26edc85,b0e600bc,2a199b6d,b521f9c9,88d921dd,7e6fc761,ce2111f4,d937905e,2af7f2dc,559f9eb8,bef286dd,909a5965,53c7f61c,f51aed18),+S(bacd4a38,f3e1b7b1,b601fa5a,2a579e87,459fd189,a607314,5a0dcfb6,1ad3c21b,8be8d6b3,9553648f,2a94754f,4c6c14,c4917296,aa9987f0,deeb7e66,d81c3777),+S(d8164748,8ac6bca,945fce70,e8f6a256,90512c8c,dd4c8fbf,b553c131,96f7f607,16b75474,65a80a67,86b5246f,e086d32c,4db03b83,58271938,41877c38,2b5bebed),+S(9c2b0749,cef57b4e,36b31328,e01503dd,ddbd2834,5cd86ca2,5224b967,1b7897d5,f020f978,4eed44cf,cc4aa33f,b2eb4b71,f24b5f3a,a8dc1d72,569bdefb,5f6276fc),+S(ea277814,9f0ab428,63b05bb1,c113ea7b,91afb815,e8f0791,12c11573,eb044e4d,8199dc4f,4e72b691,1c562ded,1220aec3,ab967029,139d30ac,58c753d2,f4548030),+S(4be6fcf8,40673659,5a9e4f2e,877ad7bf,28e25177,63d74238,6e43e6da,1c1c43fd,eb5456f3,d1c40592,2eec37ab,3e0d08da,b7cd257d,9babab02,44e5b2d6,a827a7cb),+S(3f1e9ab5,160733e2,9e7aeb6a,378d169f,9be5c266,a6462e2d,e736be07,f88c1da1,907fa0b9,814da057,9bb11309,aab51902,a0699aad,9422e1f,b8f1a8c4,aa9d4399),+S(eb730dbb,1ba9b2f,50453837,35ec6da2,ac4b5019,86cf03f0,3f5061e2,a28285f9,41dc3a0f,f42fb1b5,d3b464a5,6e305fe5,c60c4561,d6e5a6a7,8cba87ce,15c392fa),+S(aeac891d,f7032059,54d0bab7,41927702,1a595a4c,37bfc34c,5d315876,3e85f3ce,168f8260,1331b5c5,edf941d9,9f1cfe0b,72fd2a1c,3e4bbc2c,c62d47e6,6399105d),+S(667e04e6,daca6315,4888ac26,a268876a,f4b754fb,87687ca7,3c4cff77,d6dac204,1826a26a,cdca828,8e2ac81b,855a4d40,86f3009b,162fba82,83cb1d17,b9f7aa4c),+S(240ec754,24e46326,8e2e4ce0,240f335c,78c46150,1e18cedc,b32e3c51,77ade3e5,be09c744,cf6e9c6a,75976c03,530329af,5e11e5ed,3fb13e8c,af40bc5f,95872645),+S(7b83e4b7,70e7a442,3efbb501,c23881c5,2bbde4b9,d5aacc38,7071decf,79690025,d242ed74,441d1ae6,61b97c83,70be2f52,dcbc2831,1e8707e0,1b44c827,420dcd45),+S(63589c41,fa8975f4,c8738f57,579cc0d8,447218c,69da1a34,ee06af0c,215f6c27,c34f2ede,7589760b,80dbae48,94a3c13c,7351bf5c,33a35351,9988ba67,c2a56d48),+S(db092b0f,4638ee45,190473c7,cb60cfec,45c94d96,99aaf289,82d28af,16ba1c66,8a96ecdf,29ad2fd6,3a85a7fc,b73ab6d7,719bbd6b,98d052b3,3a0cd91,ab924f46),+S(11c4dd8d,3eddc0cd,9a832dd2,dc91c8bd,491fdb51,f5da21c5,732dfb7a,362b8df9,ba4c2789,740b53d5,51bc9fbc,776f049b,e848182d,9d13abb7,e7cd860,96911eff),+S(a65a3a01,df3b5ef2,e620d431,49fbe1,4d71457f,19d1ed35,aea39d57,89303fdd,86715f6b,f300a390,470bc272,6f12d389,7979e2fd,b0512c35,252bb571,fd19752c)},+{S(d8558716,b7033a9b,29afb346,fd71663a,79b6e86,2719bf12,6e532dc3,f581b7d,a790d460,1e5b2630,1ad6ec43,62f79120,d75449d,8a500e2e,6f17c021,8037a405),+S(842c01b3,54353026,c43dedc7,8829ead1,db35b63d,8c4d0d36,8cd7b661,2eb5e11,f173cab1,a37ee0d0,68e097af,17bf859c,13bb4823,255abddb,f0dbeffc,573e06e7),+S(acac5cae,414c3556,38e293fa,e7cda051,18924e9d,abb81bdd,29123768,c7f21443,5d17b909,5b997254,5f56770c,dcb8af40,e37e1a8b,6e01a989,34ec22fb,f7d04537),+S(c8e73810,c024c6eb,d5398bda,3784261e,542279e5,3438d49e,83b2639f,80889aea,7a2183e7,be4f81,b0337993,935657c4,c55d20df,729d2e8d,b25af238,f3d85f4b),+S(f78c5f53,5e7ccb53,555a6f2c,b1de1c5f,da379360,f6a7fc52,eaf86ecb,dbb3bf90,cf2d33f5,eab2ee1d,5a32eea3,18f9927b,cc982fed,cc9add2e,2461ba14,9def0292),+S(4cd40c43,bdb8a042,2babc95d,eb00a405,59519074,5906a8b7,b5ea00da,b7f995f5,a0bd1c74,79125d2f,5baec520,21fb7c62,415817f7,2afb80,b2315dda,40cf4c4b),+S(647c5950,f8a7fe9,e6945b3d,6da91932,b486a4fb,ed903836,9fbc20f9,a849ac08,d331cf32,d72e148,b47af547,6794a33d,55f49ffb,be47db02,7d2de73c,542bbbc5),+S(97664e78,980a49f0,8269ff19,649e86cd,7da88a76,eb1441d8,a5f3fd2a,6ea335d2,b2898268,9a8cd91b,b1b16be8,ee46b4bc,252f7016,f72432c0,431f1264,8d7450a7),+S(523f68b,b39c2ded,81d22a4e,575483ee,d8748c9f,52c06081,391c27d7,7afe3805,5c331672,4464dc47,cc9cfe32,864b6095,ee8bd6a8,42c1af98,b3e33183,a46e2471),+S(cad866de,5cbf4938,989b835d,5aed958,cd7c316b,980b7c76,2109d688,d7ef5b25,3ae79c30,e77d6d4e,fe404b8f,324179c2,f677f434,8a1c4367,2a0fb5eb,b706607a),+S(ba065cef,b47170a,d6796033,d157fd1c,f22052d0,7b7f9992,6cd58e03,316f95a5,26177c08,bc535702,7f5d03a4,9d982637,d74a6b20,696be76e,742243be,b9ecddca),+S(27ca8178,be756f12,22cebe6c,d05310d8,5a6c4f59,eec71613,7777b625,e6d44c97,de547a17,ddee9fc5,1fecee01,45f9cda1,b65f097,5d1b9544,aa2317f5,102537cb),+S(bfab1d94,d04f4909,dee00998,78f77cc7,d9de94a7,96b5b770,5f3c759d,2ae97ec1,6ec39a8d,9e900a79,b8b88098,d1e5d79d,b75ef91,e442cb2f,27ea531a,2db21bb9),+S(b48a4f25,9d82242,59f08a08,29b05ac8,ae6b97b5,56cccb84,20a479f5,df92701e,beef137f,9f9acdc,8d31a780,2290fe79,9d9470a7,3c8a01a,35abcbee,9730d17a),+S(e3f5d307,ed2f2f13,d23ae5b5,9dd567f0,8161996,776d506f,b53e14f2,70a52370,40ecc697,7da3771f,32a66438,cf70ea9e,550194be,1af85a08,c8a4515d,32365803),+S(818b0462,d5a815b1,57216ab2,4d795886,17cc99bb,7a7abd91,655cacb7,ba99335e,c6ad05a6,7d2a391,a15b6600,7716e02c,9fe40db2,f82283ef,c9c0a7d5,ebe854f4),+S(7e3c52ed,23220b73,ba47613a,bf39a9fb,b3a6bb6e,22c972a9,3ef21a61,50cdf830,b3e4a95b,875719b3,bec1b113,9e29670d,4ba8f39a,2fb76700,f69961fc,bd01fa2c),+S(594e4129,9c1a117e,ce8564bf,ba88ce04,297f2e14,7ecda07c,5f12913c,14d9a5cc,60bd54c8,7395fee2,7fedccfb,ca9524a9,b5750b2d,d712621d,e73e0692,46c2e347),+S(3686bf4c,f387e340,6fc314e,f02c637,ee6f5062,ee9bb567,235b00e6,4d516648,915e5904,b106e057,a0db43,151ac9f8,4871e843,126d5285,337dc3b4,52c67165),+S(338dbd1f,42480753,516d3cb2,c535492b,72849870,a7828b48,643dc143,b966ea61,e51f11ec,86104334,9e9dae17,78116032,949c66c5,3c4d441d,3c88cf4,c7ad61c9),+S(56f935ae,f58bb403,7649198d,1a5da704,26fd944e,c5694c18,38c94287,2130215e,a9c48fd0,3b059474,e528016f,9c998e02,cac7c40b,8c859852,b58b9082,b638222b),+S(1faadcd3,da472591,cc723754,82546c81,c4f53c14,d0d8dc5e,ab95a58f,379e6899,5bdcc45f,42d0ba3f,783a0806,a5d08c74,a1b1b9f5,a559248a,8681b153,74e74958),+S(532d8cd8,fdf838c7,70b87ca1,4703a884,116dd928,74acc660,6ddddd61,8eb053e8,67a31325,853db4d,3e5877b1,c76e7e39,468d2d77,37cb8a6d,af4f16b8,17cd8ad8),+S(8a8cbfd6,d45e5740,aa9f0a21,f40e3671,ef897fe,bf2bf753,ee2d2f75,844ab648,d00eed6,efefa26,46c36895,3a54045d,96da4cce,8ffc554b,9bc989ac,2f62acaf),+S(38ae095a,3c705343,38e542ff,6789902b,cc1b0b5,7763cc43,2f50cd9a,d26d0f1f,100de239,87026f09,e483839c,fe9e1f10,11bcfafa,662a9331,95a8e4ec,e4fc804c),+S(82d9e5a8,385de1f4,fa541796,a00533d9,a3aa4656,74583d07,c4b3c344,b6ff8cb6,70bf2bd3,5765165b,a466171e,f26439e8,f790e178,f67ef5,d2e15e98,435b4261),+S(1843988b,42ddec86,dcc6c9ab,36b381ad,a0ca745e,aba36bf0,237e2830,579aaafb,f1bdc95c,d76337e,cb3cfd65,d9c30b7a,e7c7d667,65c9db5a,6130edf5,e240cec4),+S(a32f7415,9c2743c7,2ef192bf,4a68e838,97a86a0a,3997d1ce,fda3c581,b4fbe683,8862903b,db791be1,dbab5031,ca57f161,b6449bcc,db061438,f45e610d,50ff3bef),+S(b09dcc04,d9c30c35,2bd63880,a766da1,f6314287,dc201bbf,9605516,3db2a09,7580cf9b,7e30dbf2,8f72e9c,a5152ff1,956ae42b,3e952b18,512824c4,7f4e5b9c),+S(ca07cbfb,b24ad1a5,edd9a12a,8ac54157,6f3f2ba1,4b878d82,ab7dc996,bd7e2c95,5123ceef,cd20f120,b575dd98,43ef9936,c53cf90c,c481f340,fa166452,72af1c8d),+S(f8058324,c6b9c2e7,e62147e9,a41ad78d,60e3ecf4,17524c05,80832add,f11349e2,6a39f1a5,f577a932,3217e559,f15eeddc,af6b674a,9d921772,a053b960,a4dfd633),+S(2e3c0532,6255d80f,a42fc69,d5c92aa4,cd326a5,3e8535f0,435efb7b,694a09ec,ffe0076e,9a93904a,42251dbf,47d03e54,1fb75ac3,8f8499ae,dacb797d,7738c9b1)},+{S(7bd8469f,80f009fa,b4960cdc,bbfbd4ad,d8e37bb,a4b2a34e,d5c95d17,7a94c207,f3062154,c3bcc160,b2aee99,aac98446,516a277d,85b37fe9,34be9359,4af905c6),+S(139b7c10,ce844844,f5d0a9db,bd7e1679,17b37e93,9bb6fd2b,4f19643,f22a6af1,32d4e929,27f5951b,ffa4ddde,4b091ec8,531a6f23,f1772c9d,ada292db,2b88c1da),+S(f49cdd14,14b38e5a,2dd34bff,3d01e1cf,ddefb954,2a641edb,df698d83,774ee70,5c10a6d9,200253e4,a932a42d,2e770f18,69d0336f,3c44f480,ce4a3305,83050c31),+S(ee145304,4771c862,745f03b,4776ade3,104ea0cf,eda8710a,5fa108eb,1e946826,b91f14,b6127808,f1175b72,2c09e02c,66eae622,109f4156,261d65ff,506b88bd),+S(c9ebbdda,867f333d,39142483,2e4150a8,c98090ec,d8ba9c09,3673330a,8777d790,c46d72c6,6028477c,e4754960,d40bd10b,b2defc1a,17dbf018,538b71b2,d208372b),+S(707bf0e3,9f2c8c6c,73a5d0d3,3edb32e3,46e73ac5,dbeef6c,60fb5ebe,b95ece24,adc6edbe,151bcb7c,2ed5fab,1cb9b2de,3ba2f3c5,ca762082,902582cd,e9e27f54),+S(4a002722,9fda7d33,320fc533,27b6c9cb,88a09c2d,e95aad01,65f68f45,1c82e2a9,233416cf,1cc1ee38,90816a09,17c5fd0d,da0bb8f5,d33c709f,6f1b07b9,916282e0),+S(8efefe27,b45a4cc0,3088b6e2,2a0baeb0,3e772763,58af3217,f39c7222,1e20b59a,b9f3fcdf,65771acf,cc7b7486,9b10bc3f,b0e8fb2,960cad82,24ea2430,fdad1634),+S(7bd3815d,6779f321,195047a5,b1772b19,ab29a99f,cc082e93,c442e927,b1ddb235,eeeb4bb7,480f3dd0,92e627a,a042533d,a9eb598a,6cd1ed9,2d75aa89,a592ae8f),+S(883f939b,6bc9169a,3860d36,9894c4b5,2863b5d8,d0348c4c,62368a94,737fc3cb,96e37629,c05b7231,8800ad96,8e922f7e,5b8a2c39,62a25210,9b3e4949,4b24934f),+S(4ad8cfb8,e8ba3265,4d32a656,76822176,95c40b92,e97c6d3b,af26449e,149f4b3c,491d3eda,89930ffe,e401b994,54919947,7ef33a8d,6cfdfb9,eb28295a,c5ce94fa),+S(ff15cd1a,4b185632,c6f11ee7,19319bd3,abce5167,65539608,b1ee3a4e,1671369,24df322b,ab157296,40aeb039,c00ab8,91c96833,4142f87a,1e00d105,b08c63a2),+S(3fc8e63e,995fda97,1d09d96d,4c84e18c,3e0f4d6a,9f8bca41,20c7c832,c4e9d49b,e17b239d,8e6f7fe7,3c4e46d,3aef9040,6bd631f2,da1677c8,db698484,85922ae0),+S(d88b3d3,6bfe995e,45812e9f,63e8b6e7,d5a87562,1c4a23b7,ab46f6ad,2f7d1e81,63079694,7c97b00e,311bfdb6,198c2c4e,eda57d09,b17fd74f,7140b40e,d2842d06),+S(da6971d1,4c0e9c37,e5b1379b,9cedd83e,218ba47,95e4af56,7956922,c64750cc,a14a0bd1,ebd0727a,258c1246,3aaff478,fcb490f0,53d08a40,44cedc97,61be43fa),+S(d098ccf,e2fee442,74377e1c,57d0b924,45f0954f,7af643d8,b7ed5d9e,956fba23,85c99754,17df24ef,2786621b,c0be5069,a9c59da1,61e14759,ee26b524,e9587d18),+S(633f9b18,9dd98f3d,8c4de,528f7170,1c9d5972,cabe3219,cc4e5f0e,e7e094e0,3d69c877,28c859e5,d9e8ea27,3c04ec98,ca084df5,d7c9cb34,9fa537ad,f7da0b5e),+S(2e14be9,af0dda46,8d59df19,9ac9edb0,c875f829,5715cdda,5ba3bed5,d54fcab2,a04688b,64c5d34c,752396d7,f864a9e1,59eea9aa,db8c93c1,5b4d7cd2,539bfa0),+S(adc92567,7678b197,1e45ed31,38a991dd,a4cd3586,a1ce1498,3ea30be0,642a2dbf,70f2c69b,7e47aa55,cab6ab22,e6482571,e8e1ea52,a52df934,d5ab99d9,acce2770),+S(ab89aaff,b04be186,183e8076,46c64111,476c552d,10df84ba,10a1efdb,32c01162,fccc1e20,17ac63a4,b9f78ca5,af245a74,4174c952,cfe29491,11ce1d71,e4be8f87),+S(1195576c,ca3a49b9,4db3f827,1ff2308e,66b66739,a30d73cd,e8acda4,a382002c,6a2be3a1,c6ae9f0d,b314a7d4,728977f2,17e7c7d0,199868fb,c7f79d31,6cd7d32),+S(8a15bed9,bfa215f5,42c62c89,da0adb8,c68cbc33,d9c879d7,a2f2803,b7068556,ef437bc1,1786cd73,6dc321d0,a3360517,3e7572f5,bce04b7a,3c8cdb85,cb56e697),+S(b4521d6d,f9b20080,4d3799ca,4cdc87bc,ea970d60,a3005071,e910210f,5654da88,c4ddf348,2a23e98f,b86ab9e8,4decc6b6,ad18d879,e96435d7,4b944d8c,f7cc1587),+S(4074523e,b75634f7,6442c3bf,ed9a52d4,5f6636f0,77a10e84,5e6ed950,b673a9ea,d8889a02,ec95b511,aa74db1a,10c91547,45b89b57,981011a0,9d4ce57b,e4e1f032),+S(b2e71794,e6ac98d1,ce532974,df79215e,bed8c668,561dc391,505e9e26,8444a858,94d8ff19,b8a74599,fbe5f471,e7f3e1ff,e0238cc9,2504f99a,9c4f5fbc,2e482854),+S(2e672209,8a6b4ca3,905a8910,6d23daf5,aeee63e4,34e7bade,70395df0,e5a1af87,708e9fd2,a3c0a3b1,b0e03f96,c3d477d2,abf6dc0c,bb8a7181,ca4b18db,ed12e3f7),+S(7ec0fbda,63fe7404,438e36,d567d9b0,bdf18b09,d929329b,24a8bc91,816fd433,f80ab84a,99d214fa,5d288e3b,c2b5560f,a1791412,9c3d16ff,cabed23,736e4f85),+S(f166252a,34572146,8bf3a3d7,bdd2c67c,b0d36b02,d7a70033,add26f97,128b1637,134eea4a,42b482c7,ad625407,bb89a615,656e3a2d,232f4bbb,a33660b2,403d6f63),+S(7af860e0,27d3b1df,aa0244e2,51f9459e,488afbce,6a3aa610,e5e223b7,81ba2d93,6ad22116,415c668,7dd3f4f7,b5a00599,bd35705,951e1093,3f85f815,4d0c8af7),+S(e4ad03b7,e01c5d04,7030fe59,6e7e7960,77d9847a,e604d2c1,d801a5eb,e21c0731,c7757ea8,f57af58f,b64f3eb9,c7762bc9,544f28d,a80d760f,c46b0c9,589019e8),+S(ffb2f941,f27aa8ad,6a59ed01,24e83bb,d49f2588,a5602389,15329f6d,f77220dc,6812c00,7dd44185,fc3f0687,6f7a62d0,d31adc40,c0a1a060,c67df13b,e4cd4873),+S(42ca15ab,9f245041,ce991e19,3d696f4f,4c277df9,8cad603,8ad0772c,2da6e03,972d10d9,37e3a836,9b831b2e,347ff11,29917a59,7ef94158,7c977604,73cb849c)},+{S(576abbcb,8b768480,882aefc,81380709,831625a4,b9de63a7,b9c3390b,9cb4c7fe,b49453e4,6e17bbae,2f1f8f9b,91c3ed04,80d5f194,33917cbb,d28b878,bc6e6c4e),+S(f9d8a157,c151181,3e085c1d,ef2958fb,df2a17b2,6b330a0b,2d512c87,69e5c14,7eacca29,26aa402f,f8b78d57,f5e02add,91087da9,d607bb41,b56a40f8,f7b19b78),+S(d31dff73,7d2d3422,7fe39dee,b2eb4bcf,dc84bd39,d6cfc4ea,ff09812,23400a80,4af55e8a,fe8e8ab1,2e2c4463,d41824df,7b53e44d,efd946ad,b6128214,4244055d),+S(9ff2bce8,a9fe6c7e,e68a8292,f0d2f4c4,8d963c47,63018a55,89a2c130,667bc861,eb138923,94aadfc9,6eca7c5,78c0fcc,bb31a40f,98d02e93,a140abd3,cdf041b3),+S(1397cd8b,aed3c601,b6eee616,243a61dc,fead22fa,da50db4c,1f9e2776,6e5bc9da,534a8e23,59316503,cae233f0,3b6ef0bf,1c7e0105,119d1a49,ee688f04,40695c66),+S(4ee38986,511024ab,5385f710,42bc3778,7cbedd0a,ad13ba24,b77f42c8,2ae935d6,cf87468,24a38404,f313965,a64c927e,4ba0b7e0,140f6b36,47e2049e,35a74e4f),+S(7614cd7f,9b5f1455,74d0d38a,370f69ca,f3050297,10af5242,e5ccf19b,187dd189,b946eded,e4b72db1,6dad876e,396e836a,875d7c9a,28a9c739,f665c741,29ab7648),+S(67fd2372,5bfb445e,5254bc42,f7dbc1a1,65bd4017,cd1019b0,8a3f96cb,7b3c7cec,b556e950,a144febd,a81dd3f2,f729ecb,fe43fc78,8658bb7d,2b9735d7,b06a920a),+S(57572b1f,1f17070e,e9b30b6b,c7168cb2,4741ec5a,b3496b1a,c06ec0f2,5f910fce,8cfe2940,3dc97084,7ab28da7,167e78fe,f2310c83,ca476a97,91ca35a9,610bc560),+S(1f111332,1e31a294,cab4df73,5a0ef333,e753c2f,7c83705c,9a5bf27,1321c4f8,8fed26de,202c92dc,5b51b13b,6e9bae41,3c7c88d7,b858dd72,a11f073b,e2945f9b),+S(23c9e313,b04eebff,15fb0625,43de6975,d19decf6,6416f4d1,855083bb,d738f882,90673370,f380ca49,e876d5f4,b6649de0,24f4454,29cf9d91,96f4f196,8a49ed99),+S(b9251407,6ef7f01e,379aafe8,8f22c156,65a85ead,f671d8c9,89602c5f,804725e7,b3a9409f,7bf973b4,aebe08e1,5ac65562,56983f89,23415e0d,eeda4f4a,c0d7c5f2),+S(1bf9deee,948b3fe1,b4345800,51c67266,8fdb7af2,99275a83,706f9716,7e38e38a,688fc563,771b7d27,f9c09953,c40cf009,a55d7329,5fae0b7d,8fc37710,729a3911),+S(34e20de5,9d00dd45,19a70b3f,2994fc4,588ca9b2,beaf6afe,4a1daae2,10692f33,7804aff0,a43f1ba0,438c05ff,8d013e3b,e5180bb7,3a969825,fc97ef52,6da1b6a8),+S(80fc119e,85e88b0c,8c84d23f,9e44e96,1c7722d8,51d4c9bf,f1824fb3,365823ef,efee941a,a60743a,28b6ffd,39762f9e,437d2b00,206e718,7fc423bf,4eff0caa),+S(89ab0f45,e3860393,f24b1845,7578fe79,b812926a,6bff3788,c8baf283,89fdbf0e,57d4fc21,42bf446f,8e4d9331,659e7673,90391fe6,62e77ee7,f7a4886c,8f440c8d),+S(1f092931,664bb98b,79d8fb4c,efb287a0,f72641fb,1cebe711,820c92e0,42f26437,59f63ca0,b8e2e959,a97b1c1d,1cfa4c02,380dc42f,db7cb5b0,995ceba1,d7e45d94),+S(95ac9f36,f447928f,344eb4e1,9ea806,717600e5,148ad222,fdd52a83,86bc3537,cdef5355,e928b1e8,225b5a53,bb976822,6fb50d1f,6c6cde20,758d5ab0,e9f28543),+S(a9ce5ddd,9941ea69,1343ea71,c85fcd73,6269826d,6eda5008,44cdd1b9,4a66044d,29504563,1fcb7590,27d904c5,4ffc325,2ce3c8a2,169f4649,907db751,2ef3ce43),+S(2edf81,45c4bcf9,62425707,ccb36a3e,7fa1fadb,4062d14d,f78771eb,f3ec15d9,dcfc961c,547548f2,73206d9e,aa0d829,a235f66c,5afbba92,68fdf9e6,abc8260b),+S(fcf5b985,c935e207,92907b93,e9976ceb,ed320a14,3cf286ad,b38540ad,b4077dee,8a0e0b4d,1ab114b1,caf7d0d,f749f219,b75acea5,6a71b3f6,aa18557b,1da85262),+S(2bd4391f,42b70803,2baf4816,54569f48,95f1434e,be6f146d,41447f45,f14581b3,dbc9937a,61f43af7,42635810,5cdfa02c,49a5186,ce67bbbd,7ced2842,19a37506),+S(eb00deae,6cf69ccb,abe6b93e,e5493e05,d22e53c1,b069a6c,4660330a,4e3bc069,18002f2f,61b08dbb,60c784b8,4c6d71d4,6b004e6a,3089a0d5,f853d659,83242d9b),+S(c7c62a5f,ce15326f,25b2fc5b,697cc7f7,26d231e9,e7e9f15f,5998b8b0,10605524,8ad4b370,ea0506f6,f25eb16a,78f87ef2,f408cd17,fa4ec63d,4ee21448,1d5286b7),+S(aa1c2baf,632673de,6f6704aa,5a76c077,be0c24b5,223de654,88d1386f,15a1a002,de4648e4,fda7db79,41efc5e8,6fec516b,c6aef164,62d6dc08,fe93ebc7,a85261f5),+S(11871161,13c3c670,e7f5366,edd22282,1f76ec98,d1a3500d,f0e483d1,e53f2666,d0042c9e,8dc1d72c,f53836f3,2c76b5b6,52fd5ec1,9e8fde42,aed1a7e0,9d242745),+S(e232a92c,9ffdabcf,24422182,34078534,6b6b79f5,983ddd57,2580c3df,e4ee4118,6c1144c7,471342d8,7a784fe1,587ef576,483f8980,bbab12f9,35aa0d84,83c1d76d),+S(1ab6237,3998ded,e50aec45,8043f830,8a7b4564,2dd3c9bb,4804f98e,a7c2e0c9,5528e158,6a23aec9,81f04b51,b90576a9,a9e7feb5,53200e51,e604898f,e55996f3),+S(3bc24bc9,cbc58de3,46644de9,b17ffa7,39a0f7d8,83eb9f52,af19eaf4,d8d52891,f71cf5b,7587c275,8014127b,f404b70b,b257bad7,f5b78d2e,c792e1d6,b2fa4493),+S(a2bf9afe,e6eec182,ef5866a,b4bdfe2e,9d045323,343aa422,8c1a13ae,fee515dd,a5ee438e,3aa35484,c5f5a1d5,43fa15d7,ff0d1c55,6571678b,a3c5694e,f93cfa1d),+S(a0b2b4f,ed0ddd23,8812806c,fccdfa9,7fb3b42a,748721ae,6477dc9b,18953133,325ee7d3,4a540d0,fc3e3935,79ba7372,905c7b17,4f12b456,b43db5c7,cb50ec66),+S(e7b9796b,5ca006d1,632f482d,7f0fe393,2cf16a5a,e104eea7,a7ea1c25,1073e879,ed476773,e6e961d0,20bdefd5,8c833e35,634a40da,1256750c,c718ef75,45575e97)},+{S(a8565dfb,75f8eea8,ca9ca6e7,c7d18a5,bf3e437,5d1f4e87,68d5f51a,57199ac5,daa7d7c6,cb86b215,a682141f,2308d9b,4c204196,eb779f32,fcddf0a2,da194921),+S(974619cb,86016199,20f507ee,62d10295,44abdd66,456952a0,54e945bd,7890250f,6c8d8bc8,21da8234,1ffd0cf0,548be1dc,a1bb7e1f,47354dc8,3e5d96c8,2c9676f3),+S(24bbdc24,1396b6e1,75f23a6,4bfb41fe,f8329b80,d306586a,ecb69e41,2a2014b8,aa6448ec,f00a0710,27b46f09,d696642b,9274ce3a,11a3e986,e84536e3,7fd7b2f8),+S(eed9a6b4,68004486,e3bd388d,591d3b65,2f35a3f1,9401e5de,81a86f5e,b7cd972c,c81f9aaa,d7300671,b3dbdd73,a095c79a,d73ffbd5,9f845eed,9fe3a57f,a41e9468),+S(5260e0f6,fdc6858a,8d519d3f,6c71929e,36979b65,431a6f3a,a7507797,e54654e2,5af860e5,fbcf9676,bb00c329,d3e2e058,efc860e5,cb9006ad,224caa32,9fd49f07),+S(11e53f67,d844c511,b8118f28,de6ed9b8,66b70bf,214d4d1,ed79adfc,18f7d6bb,20dd984d,7b9eb626,77e411da,2e823045,685a4bc5,2a3f4e5a,3aedea95,1060b330),+S(98c9f3f6,81e220e6,d4bba711,fa8b212a,dcc21bc4,8219b813,eabdfac5,70e6fffe,bd0890be,d9cf4ec9,44f6abb1,56250329,a37d2cc4,64c931ba,8606c2ce,55127aa2),+S(f644f4f0,43d7713,ba4380d8,26ad0f3f,44106352,142fef13,7c6e05ce,5e9f1571,3192280b,f3971223,c00ed336,94779866,536020b6,79ba8cb5,c4f9c515,69d2f97d),+S(334ab869,32c4097c,8d8d8a23,d529b079,6a759d47,a907b047,548e735,5b3b766b,18f11736,d54c9d00,89149b07,35f5a9de,b15d9c,cde4ee06,155a4f3f,de98a7bb),+S(983542dc,61b43ee5,c4a7f36f,22da008e,832d4eac,6791d838,1a095d0e,6d8a14b5,cd225f2c,334d1ba9,94b0a681,d6be7696,16bfb2a2,426e9939,d2238cd4,43bebd02),+S(dbbac008,1b678270,4a0fcef0,73683822,a3d4107,d7f1a71b,41497da2,9cc942a0,cd25ef66,36f21a8b,532371ae,b91b67a,deea5797,983dc36f,54aed202,d9845515),+S(477949e6,9ed28a74,879bc8cc,660696cb,115e6392,5a63817b,60e5187f,1f77f3be,dd8ca490,fb8e3bc1,44f5fe9f,aa41ce73,56a1dce1,cc8e11c3,ca5725e,d1b764ae),+S(7616b9e8,b451d4e2,e4826586,9bfad6c8,ddbf5fd2,2342c6c8,42d6bbe0,398f94a2,4e3bb1a9,76efd345,3c4474ad,e6a494f6,4f97c6dc,c98cf68,72bca24b,dd9e946f),+S(b87fb86f,6ec4ad7d,5bec3bee,e8d68618,c8e4906d,1c584368,ec819f2f,871ca8c3,c64723c0,aa587911,4dda9c75,493f739b,e8c2221b,b2e75ee5,b25def54,a1d40c2f),+S(56ea4572,61a6ccfb,46fced99,1258b31e,8573a488,aa53b7ad,65333452,b06d41c4,d8529601,4145e12e,a72ae4d1,5ae6e5f6,9cc88ba1,4d79467a,3df3bfef,33d84290),+S(e4c6540a,19682e0d,e1f1258a,103037a0,af4df5ad,f27cbb7c,9e3ce67d,e23e13d8,a31e1b08,4bdb5728,36e53d93,1de035,c90b1efe,b5343b23,cac0e7a2,bf5b3868),+S(1902cf3b,90fae93,1855d758,24995b03,e1604861,199853c6,ece84903,c8bd67de,3b3d41e3,a2dd4c28,16d492c3,e6c53c83,e5203c7c,a8100d41,24cbdcd0,e12fe222),+S(6519f4d3,b5d731fe,eada6806,727623a4,daf924d9,b6337a51,56096ec4,16ab42d4,62e2c1ea,afa990bd,6dd91675,e3b2d1e2,acb2fee8,e56ec30b,eb25bdce,2d3ad30e),+S(e1128682,519b965e,a933f197,eb0997a0,16114459,4c0915cc,9c55ea4,a30c1ad1,cb1370ba,f8707c78,84817ee2,8227da3b,7b7c97c8,266af491,e0d52bc4,ea0f9614),+S(4366960c,6ff595d4,143d4cd4,f0f0df2d,3bf864d5,73790abc,23419c7d,6ed9201b,623faab8,2caebb5a,b4c42bf6,b2a686cd,4640cde1,a95a65a1,f8d32836,9e5ee0cb),+S(5acdf691,3c1e283,c1220355,6efd99c5,d347ef69,bda1d040,44cbf0d1,ae41b16a,1bca567a,71698c35,e35e031c,e8a98dd,e34270d1,4e2e2439,9276a7c3,6a1f35df),+S(807ecc04,81aae374,1efec46c,8c6c194b,faa0607c,cf5b7cda,fc270fb5,f5b416bd,cc60be6a,6736dd94,848fbb05,375f6459,d556866d,165a2c16,41984411,dda33fc3),+S(29c470bd,97737284,765adcaa,68a98af7,5e6c275f,fa4fcd5d,6c71d428,bd3bfd79,b19ab40f,33c15201,41fed31f,681f176,4a464373,23283677,a40b4018,99a6eec0),+S(41a6d6f9,40bb8abd,9e8748,dcfd23f0,5333eafc,4ce311a3,161440a6,619efabb,b2a3702e,900788cd,bf35204,27e0facd,b090804,62f65418,89a3c34f,ae2cc008),+S(d5f5096d,776ffdb,f694b9c5,c9a9ae0,ab5897ff,c5ca3320,82cb2a2b,8afcfe89,6461e24e,28560d11,336244da,2038e13,c69ed5,a7a435a6,d07a1d72,be43daa0),+S(f65a00d9,5707ce6c,6bd55e8b,4b0ef381,1eca65b2,9845433,d7b307e,518ea724,7ae079e,9aecabf0,4ec5210a,b85328f7,e60c8ff7,3deb037b,c8e6e1d3,34774734),+S(346cff42,23c9ed2d,a1082d46,eeaff341,f7866e72,d95561b9,678def2d,9f7cd187,f97f85d8,92002750,11efcc9e,f8ff58e4,894f105f,b94e7390,7e185806,575698b3),+S(d0e3cdff,a47417f3,86f64a2,4029e3fd,9bc7a464,6e839bf9,232a0d50,349ecaac,5bdbecfa,2a2b35d3,ce2e9837,222535c1,57ec5bda,5fd70186,1920803d,a279989e),+S(f6bbbd77,b8dba8fd,704a3f02,1bc418c0,f8524c49,ccfcd14d,fcbf7f04,c9a18d,38184001,f39b257b,6755a132,86bdfd92,1a8ff771,fdd5530d,48eb8227,ea70be1),+S(6717bbd0,f019990a,c01a2996,e34f0912,9bf60a3a,71d8124e,fd86c777,9cfad879,9581f790,a16825d8,f44f316f,db3f0bde,108643cc,b390bdc0,75f3dccb,6520029f),+S(417c765,ca91a120,2b07459e,3713d5e1,bbcdfa82,bbc26cc9,279fa2d2,59251fa2,8d281a2a,ed38a80a,cb697989,9839d7c5,265b4e78,8a9e1176,66cfb6fc,4143a935),+S(e2f349b0,f89c69bd,3c8cf2a4,10730dc5,8e0beed4,7048c58c,15f9ffc2,508d2cc2,e014d0d7,f07d8dc8,7e79f513,89fdea45,bdcbb417,1f63424c,81cb8426,1f2b3be0)},+{S(aceb57c9,187a5202,118c4dbe,573906e1,646b0325,781c1352,574ed15,e02b87b,68ece7f4,4037ff05,d4b89120,d90f08c6,f0499fee,d4e9e02a,a2e68bcc,2d7b70a),+S(365e555e,de9130af,99f996b2,106229c,c36c1ea5,8b065cb5,38af3a5d,2cec1145,81fc523c,b4b97bd3,cccce1e1,d1980769,fbc25a9f,a403adba,8e7e8074,13c87f9c),+S(d0a3812c,b9244d7b,c1f5b652,adbb0df,22d15d41,b1724071,fd297d00,bc8cbb01,f8d7650e,fda2be30,24ded196,eb3baf7f,351d2013,2479640,16ee4c6,b469951),+S(8f4ce1e2,a51c0ebf,f5e34cb1,c6aedd87,85e415dc,e7307119,143bbe9a,3e7fc632,617009a,ee7d4d81,1ba2bf14,d1647911,bf1a3bbe,cba8dfda,9030ead3,803fc217),+S(ea23d837,54cb2e9f,9b884ef,f4d1a708,bc1826c6,59fea53b,f52c51b4,9fe0e21b,7e8c691b,cfc3b7e,56a7699c,4f56a11a,fca5710d,963d602b,b102e1c5,b36dc3f7),+S(e3c970b2,c764c9f4,ad8bdc15,cf995690,807f5d09,4a849787,9d278d18,eed6ceea,aad8c7d7,13ce5439,b9125d9e,c14b5d8a,1c694cfc,f84e6922,b7e58df1,4ab8a34),+S(8ade30a,94b236b9,9597be14,bd421130,b6843895,a85f3613,efcfa0ce,9781a96e,78e4bf57,974cfc0f,c310330e,6aa47de8,2b0f5009,5a703fa,50093d5b,a8e8f0ef),+S(fa5f1cd3,4427d71a,de7e79b2,b0a17ba9,66d05324,1f9996e,be8143c1,9186d24a,3481bd18,2319ddf8,f344e4b0,196b3ddb,10deef4,d8d75c0e,49fc5fe4,cbd6e1fc),+S(8b88b79e,8cd28dc8,58e3f1a6,155146b9,af1e3697,d57b7435,c649f6c3,bf8574ca,e736106c,8ffb9bf4,d83d79f2,4faf8fe2,ba5dc258,e4ae1b1b,b58a1a7e,4922c95b),+S(12078a5,5c46d721,96a148d2,fdf6505b,d059e423,c5d5295e,facc2b82,aec51f5d,66a4332d,cd265085,add9a141,2fae2562,17441d7,dd9596ad,46309a0d,bfb4e55e),+S(841523ef,29f5bffa,b31a526d,bf74b16b,fac3a3aa,391f7404,6675cba8,7808c171,7a3fc3f5,bac300b5,7ef843df,e334c995,cf66de11,2283fdfc,767cb57e,e7e7329c),+S(c8831ece,f4545c2b,387378b4,f88173d3,f1cc7db9,d064774d,60394f0a,ecaf5af6,f32f1a48,bb802757,34e66cbe,58a3ed3f,adf28dd9,374a42a,a824a095,6701322a),+S(30001ff3,7b1b1691,9a135a31,287e3a3d,383ef3ca,94748e33,a52c146,586dc4b9,9d71b25d,6fc35db7,26b58d1f,642dabb,46dfa64d,e0ec2a12,c53c414a,9dd2574b),+S(a17d3621,74d3c789,c4e00888,fd4b0f4e,ea3929cf,afea9e9f,7439901e,d6b0fe44,2bcf09ef,2d374194,510fc057,dc973fe1,bb687428,91e9056d,a5b4df7a,de79bf),+S(4725e2cb,19f95359,2da72565,d8405e09,92a64299,9ad74ed5,b41f5d24,44cb6b0f,be23fa82,7aec3121,7b90028d,b61d1092,764b2824,9f3fa0ef,91929db9,b2e0246b),+S(67c560dd,74c276c4,df3efbe3,b95dca4e,a56c4563,cc7ae225,ebea90e0,f5e212fa,2c9e3120,d52ef31d,7e9e36d6,eafbcdbf,ed8a28c6,7edefb94,1df7f38b,cb05c160),+S(8468da98,7b33b79b,e08da5fd,57cee298,ef86f624,3bb975da,2f4261e8,f7531d92,455d8a8e,b4f45693,2e8b6f77,ddefe070,591dd37f,d6ad3a27,5774055b,8a63e650),+S(3416d4bb,78de7570,b1e9e912,83a3e8fc,be6524d7,4463dee6,82e84e52,72c0953c,94e55458,2c17fffd,321364c9,16658093,986b56,f88b4818,129e19c8,ce685dcc),+S(5c66928c,a39a6e22,672c1dba,8bb6331b,41a7f43c,a72276a6,afd3e209,6416a9c5,181cdfc4,15e7d6a3,c24be94b,7fe328cc,ab624c0d,dfabb1b8,f9a73b56,cdfe1b28),+S(971f7a13,210680a3,ff6a12ad,17481a63,ef624d0c,e4121166,7e63aaf7,9cafce,5de2fd1b,3149e321,2980c7d,88a49018,26f83f18,7438061e,9bdb8d33,6a4b08f6),+S(650277a7,9ae7682d,c5f3526b,8411342e,b48277a4,9876caa7,61ec6815,9a1f13c3,a903255,fcf09808,cd97d92a,26dbd2e4,7a29571f,ae91107a,7cb6f0cc,3aea1985),+S(76a79cc9,7fb80ab3,e8d31e5a,d11f5ce4,74696d23,f1ee7aab,3928848b,556f483e,1779bc5d,c763d1ef,7611b402,4583f07d,c7dc9c96,7afcf83f,e6b6ee42,da75972e),+S(6e0b4015,474fe250,d372400f,13efa0b,70c4e8df,816c0e8b,8d27a7,a8168d54,f01dafc8,8178dcf7,15f8fcc2,e7163137,9e1dd4cb,6c88cfbd,e9a051f,ad204c3f),+S(ee5dd472,b5efeba9,d0e354dc,21228d22,40a69088,842d00dd,6b6358e4,309d1f5b,bce93ac,3fd4a098,9e74448f,5832643a,a2a172f2,eff1e2c6,c61ea99,cc6e7cdc),+S(df99a925,ef2e9f9e,57208fe6,5373ff94,876b1448,368dd453,436c59d0,f2a857e2,88dcfe81,4397f990,56f92a27,143c902a,2a6a66f7,f7e9652e,e0b16f13,33252a1e),+S(9186f095,43dc64db,ad582561,cab96a38,89be54ad,e1cdb27d,674af836,22b5d284,71ae31d5,a73b29f,54af1aa3,2d8e541b,14f7cebc,9279ac26,c846d466,aa975e20),+S(645da454,63357bfb,61b5b932,1897a73b,87af6077,81487bc8,af1a66ba,49bc5e37,4b925aab,aa7bbc19,5963025e,f1896cb5,b6463242,cd8a35f3,b1b404b0,7faf8e94),+S(5cd9a6c4,e9d372db,90a65f11,1f1a1b5,f28bc3b8,3d05f599,39979c91,5277eab1,c147420f,7dfc4ef4,d7d1f08c,1c523771,86a8d7a7,10cd7017,82b97c55,63287aa8),+S(4fd699b1,2c720ccd,7b977e5b,dc622671,18ac3028,bd635b26,fce648cf,335cacbb,3936f10c,aee5f51,26b86240,3249e1d3,5566714d,17ddc19e,cc4d1056,71e523f6),+S(b3fa0545,83510d6b,91226711,4bac7f4,ba4ae5fb,baad7230,3003efcc,4c3c18e1,57a3db8a,6cbf0a94,845e7d67,f9b01902,55aa5b66,ef31abd,34ee0410,ed55d0e0),+S(fd73c052,b194c6c6,dd46aca9,d640981a,ec796009,17a565eb,e77fd534,649a2115,9df8973e,37e877bb,fdf5454f,d9082926,fb09fea9,d162bde0,fb635483,59458f55),+S(2982dbbc,5f366c9f,78e29ebb,ecb1bb22,3deb5c4e,e638b458,3bd3a9af,3149f8ef,59e4a416,5099ddf5,4605acc6,384a4362,f6a2466b,ed1c127b,a918d94e,e93859e7)},+{S(8aff982a,fbe09f67,6d6e0f49,e2b68f88,8f20dd2e,6387b420,8157ab24,d19027ed,f2350ea9,d00fd861,41259f03,b51b5326,6ce05a34,74508bd4,31ca74e1,366eaf92),+S(27ff285b,1e14961d,a042bd31,56aa44af,5e73717d,fa413a47,b300f358,e1960dd0,8b578851,264a8fea,2e29bbcb,cb9c90e4,93e8c731,983f4bba,65381e88,bc83a8a7),+S(fc6acf61,4a214859,1418ab5e,e0f0274a,309a8248,2cf01f73,db8a9790,825486df,190b9c0d,46953d99,c9de2bdc,bcc15d23,ee90485c,c4c152d8,e28322e5,4c927d54),+S(743bcc6,ac86b0be,a25cce81,1fdcfc13,73f23926,e3116fc8,9415b8c0,4c1983ac,f3df10fd,4afbd3b2,dc0678c9,102150e6,3d005680,6a5e45fe,c95ea495,9f2b8555),+S(bb165428,2c13362b,b1e017e6,6402613e,f82bbe22,9429f29c,6a1a522e,4956d67c,ec542c4f,7fbf3c6c,32e71aaa,86e3e4e7,e52b0d43,98589e15,1f17417a,40b31b07),+S(b3f74ed2,5a7fd474,5820a2f6,221349aa,e41af762,25c2b706,160a463d,1d59e7bc,a9af9d2d,89dcdfe0,21ca46e8,5f09bdb5,197c8f23,bc56d705,851974da,1608dad2),+S(20c0914e,f88902a8,6af0ff68,a08f96ea,25f15ea6,b1128900,120028a1,1049a77a,339567f2,71a1f1c7,16eb1d56,2f009537,68ff4cd3,9a81c6d9,6359d2f5,5d04db9c),+S(a3555aea,2e96f05,d25a145e,4ad0d2f7,fb453974,8c4a3097,a703c0f5,404a0e7a,ee236b76,8fa04380,b0448beb,d2589665,e43299ee,b9fc78fe,5a64db69,ac92b7df),+S(37191a66,1d2a7bd,c96a0767,ce47d97d,7acfb8c0,ce251e9a,1421e2d6,29230c2b,57093393,4783afd7,2df6524e,871c8e67,ff2f48c9,c73e2054,fb219cf,d3c2a68c),+S(1a2f5b6c,5fbe300,8b01407a,b0b28c3d,c823cca9,b4c71a1e,4fc814f1,e186e062,b2f1c632,a9d92a4c,82d31a55,f4fd50bd,d53ee99a,2e1452a4,e43e5ac4,b8cbb7c6),+S(2976575c,c5e70e47,cd9c10e1,32a593dd,12b65215,38613cb7,22390022,73fb41d0,c3f0b08d,a2a3a046,d87dcb13,38c35824,1a8b9959,e2567543,852dcf73,c4f5cba2),+S(bca28e75,5cd6ab74,85884b30,ef399f,44188695,fe9c4143,6016bdec,25d502f7,b67538d4,a571e935,cbefe237,c5a01f77,4ade337c,fec9f95f,3e9cf042,f0dbab6c),+S(3dfe1718,beafee83,b858048d,25d46ee6,7741d3bc,bec1e52d,3ce308cf,738b715,8499a8b3,a0c7c599,f62f056a,a8364494,ec6e0198,2c47bbf8,7e2df591,de0ff537),+S(bde6252e,a9e4823f,36bd1737,ce188fae,be4a271,9984c9e6,76f9f4ff,d070c1c1,2e5db82d,e02a1fe1,39d903,7e7adeef,12d40366,de0eb164,c04b2ef4,b1e849b6),+S(2c74b766,eebac93c,479fc0bd,78a3805,de50be2d,a6ad70c6,9048e43e,c91343af,ab7a929d,588ff993,55094f83,6e7b3b58,c6381bfb,b284f9bf,7dc44cc2,67cc741c),+S(f0e084a7,af9abfaf,b6ebf3c5,b526d545,b8b1cf5e,8e09a06c,3670aa37,6af83a3d,6bb279db,abdb2b2d,fcc97510,2b075dfe,b42d9e6a,5a8af760,f4b63788,c315f8dc),+S(715aa28f,4e52fc26,a2f4b9f,391894b0,6adc3b69,b508827b,4732396f,5eb7edb5,c5d0d68b,3a8c6532,2f6303ab,99b6c48a,88572c4c,56c780d1,d51d2441,86ba110c),+S(8f980e69,3511ec3,cca89b2c,362835bd,24d9c8a6,97deff86,5540f7c2,b0bacf8b,2d5e8470,f2041ca6,f158ac83,e92a2345,4059492f,af27ada2,92bbe51a,d67ee5aa),+S(6823a4e9,d80838b2,750dada3,cc31f59f,3cc9d6c8,3f33aa5,38d949aa,c4d6d657,e087127a,3ddc19cb,e4088a2a,6df61863,e8e81cf5,c5cea4a8,8cd2ab51,bfbcba8d),+S(8c9af14b,11add28a,818f85f3,276d1d7a,1e3478f4,23e74b72,caaf2440,24558538,a7c17174,da1eed2,7eeb7b6,c1d93e4e,9e4515c5,3cd888d5,e4527cdb,94a64fb1),+S(5fadb7c4,74b13592,a1a27f76,b7c2011a,102b66a0,c6ffbc02,a7306e1b,a9ccf49c,7bf61c4f,134f8b4,7a5f90a1,938918a1,4d151f2c,7f1c4bea,cb8c4773,cf11609d),+S(79a21b82,9325fbe5,c01ac979,8b89cc47,379eac4b,682fd747,47e0c04b,879b404d,abfa4d5c,7ff916c4,9f489c12,5235bd9d,a0395b6b,84d6699f,c96f9c0a,5a4cab2b),+S(b213d11d,e4b5601a,5f10827e,d39a7825,adc36bc0,1130a055,cf8b3e8e,fc96d10b,27c0e5b7,a739fcd0,5eb73321,3fd1bbb7,873de0a1,2b92cbc,21de57c6,2bc812b1),+S(299ef8e,e131f523,72949d7e,fc2f0f7f,9965e69b,56725b55,4d513435,ac8b0b3e,8ba93fa0,2a4d97b3,54d47c10,d5d791c5,f724b68,4f501eda,1931e563,2c6faf06),+S(5143ab76,43a21de7,7ffd0f3b,c4746fb0,589be22d,9d9ca2fb,89403a39,86d1cd37,20991000,a7c01e4b,26d9236a,45568bbd,91c968d6,c87dbe05,15063af,d8db5a03),+S(738ce787,49783066,923ceec9,a841d60b,56855e09,93e67cb9,9d52a0ca,7a64b5b2,aba44aa,272945fc,5eee0330,976b659a,a6455dde,feb5c894,cd274414,71610384),+S(6bb9bbe0,4c3dbaf,6c60adcf,5ec5fa59,29cdb04b,14633c10,5dfca2c,183e1d97,b7dac59b,5c35c3cc,15521da5,89c0d333,9dac05c6,614acaf1,d8b9e834,8e02c3c9),+S(f325eeb8,49a32b2a,fb19491d,8c3c112f,a7ca3443,438c8c19,99bdf791,6981472a,169df94,a26f26b1,e5aaf810,7a148faa,17742c3,10cac320,6daa69,f8aad67b),+S(d279bc0c,f7f58a85,b5abbe25,936d5088,4d8ae8a4,b415ea30,2c0f1133,de98603c,1e69875e,2e38f9af,222e03b1,6c833bd1,12bc10f8,1724da7e,bc780e6f,5228fd17),+S(224d079c,750eb1b4,2d70aa25,5fa0c3fd,c2d07c1d,ae4d6cb1,17c1e61c,5ec1c6b3,e54dc4fa,b0e05362,60d27fa7,ba53c37c,a37ce30e,617365dd,1c58a59d,2c93ed00),+S(f4741ca2,b3de5414,49426531,d546272d,ab8fc55d,8f65eb3d,5ea780a,d25cb53b,3b7290bf,dda0d0f,e3704f27,d8537063,f2fe9571,4a0791a3,e1a25865,96a5b0b1),+S(e931258e,8eb5559c,6d697272,8a704c17,b775a26,5b4527d4,a4d4d742,bbfd71fa,4e1ccc9,b3c0211f,17a14be9,636ab4bf,4c6b931e,44a1ca0c,c2642f2b,e8b2c928)},+{S(fa01dd32,fada2843,c51845e6,3cdc1b76,79dee47b,d2f4b767,5133aa5e,62029057,6ea6596a,b0ea0201,b6c8bbbc,e9d07fd0,8040e1fa,198c8767,67ab6055,34a33),+S(97ec9d33,a9d88115,471619b5,3fc58a08,e6997662,7a28afc0,b75b2f49,55eba300,92ad1d6a,f8a0a100,27d9ba90,4f7fea6a,571f3c32,53393a7c,79abb0cf,9a558390),+S(ef364ba7,626d72a6,87bc9776,3f2c0833,50640bec,6ff4d80,9dabcf2,9ea9145c,7f8d7c48,1bd80ff4,8eccfa9d,2de5eeb9,800cb98,c02da539,3b3d6c83,8fe4a2ff),+S(45961303,a778b47a,89109231,3242304,30a17859,7d940e9f,fc2f25bd,1be61c00,5fa356b6,daad2b1d,7bb19cce,b9148d31,58d2651a,b4b436c0,b99193f6,61cb037d),+S(8aa677f4,d73c0725,e2163e5d,ed3dc312,7ad5ee29,f9bad8b8,5ab8f50d,ec6d77e9,1fcb9da0,d3fb9bc3,3a45bcdc,50aa2ba1,16c2b05e,836b539c,863163c7,2436c334),+S(8c6b2873,33082bf5,a3597a26,7cc14696,2b689f20,59caf1d9,35972c98,9b14c86b,aa86d282,a1107f8e,21307e0,2ad1420a,a4061fea,3e3dd6f5,9b5d6900,6bf4827c),+S(46c963f0,3bdbf433,cbd60858,5a4d659e,9815c286,9f684eaa,cd879d66,ceed05ed,be2a8d60,636c5b80,e443b13a,9e21c91e,90a9e781,1c35101a,dfd61a49,88193e86),+S(cdbe43bc,582f3936,314a88f9,fa21b29d,f4b5acf5,96cdac3,4667e9c4,b02b926b,8f2a5b62,4f20b20d,cce97348,d73d5653,8651dd41,dfedd476,8792fa61,1bac16fa),+S(6f9c5a84,1ffededc,ec45dc63,7ad15aea,207116aa,a3036ea,ddfb0656,1dfd074d,ddf1c22f,9168232d,cf9c36a5,dfb7835e,62d28405,bd32ec15,5e3ddb3e,df834088),+S(42000663,3223b99,e15a2a65,bd95b229,820abee9,5ba5be39,6f8879b7,3f421e7b,9f3f3d66,40de91bf,c6872619,87487226,57e60a4,3ac633cc,48f684c0,cf42696b),+S(f02335b9,9cb524b7,45fa9167,41da4259,f70279d8,efe851ab,f5b0b8a5,32a087ff,e1bc6767,ba068b22,cb7389e1,36805da5,c30ca62a,e59b92f5,48e4dd1d,5327cfbc),+S(5bbda2dc,cf8154e8,28ed49b1,2fdabc3e,eb8c3f9,d0da5878,77611ff4,49d72e7c,312377c3,6277addb,d5b044e,fe136626,d5f7e7e7,a73cfc4b,9751e8ec,e4f77084),+S(5cd5cb83,ba2f225d,1ef4faf6,22e226e1,eaa85a5e,99721d3,82aae23a,f9dff565,254f58ba,9c49244a,4178a067,b0e4bf6f,dd7f3e15,65e21637,bc41f9f3,55045908),+S(3b20ebc6,b453aa16,e5b61381,1d81ca1,f87dce6d,b54ba85b,d8578ee3,23bff228,8c9d3054,56627a,7313505b,4aa5140d,9fc40d83,bcc298a6,43842f04,70a335f4),+S(cd531999,cf33db75,df4430c6,bbcf32d0,642be18,5736d79b,f2947989,e52c8da8,c7e99c34,2a5c1112,400edc69,f58246e3,d3cebbef,2c43ff47,7520b027,e2aa7d78),+S(40b3856b,273bd2a5,145b70f,d16a2972,e488b33a,f3719143,db7bc567,26ff23c4,d8bf895f,71d96e6e,20d523dd,1256bd56,44e11442,c4757d74,f116ae44,69dc9b21),+S(1a0cf029,2d7cce75,32b74bae,acec6864,9e682788,3cef4bbd,c8b24fdb,53e885a5,32c87d92,6f969f69,7989837d,d8ec8ef1,c284d9db,2a86ecd3,5bbb6772,dea06692),+S(7fd5d251,93dd6c17,8d0be92c,342f94a3,c92c061,27998f4d,54f7dfb6,1326fefa,ea7d0755,e0a804bb,8b7ac8f2,dbe1dd7f,9ccd36ca,2fa94365,631ae455,5d080075),+S(51820145,6c07fa3e,70d7b24a,7754b11,e42828e9,c1b96b0f,fd79bead,2f44050e,126f5526,1a55b724,7d08c868,366d697f,a6898c66,d14094f3,44b0a6b3,613d043c),+S(86f2c87d,46038770,3be5ddc6,c2ba1ccc,7dfdd56c,a9986663,882f85da,345886da,ed34fc59,4b66f7e,f06f54de,84f3c7f6,ea1d877b,bbfc4185,3df800f2,fa805027),+S(7f7d8a69,5b86ca13,d6a0ba07,99e60cbe,f5c4e1f4,c74a62bb,93d94d4f,8c1f296e,44a14061,b2c741c4,6a52639e,9bf08776,5db5d496,92bb6d1b,e97f9ced,a89953e7),+S(ec61e956,83714c55,1b72ed5f,c5b09663,6dbdea9a,64d13ef8,c9cf0c55,89da5ae4,39a6e38f,9f7927cf,ffcd0847,df91e856,4188bf58,276bb4df,3721335a,5357c77a),+S(e5906c85,4a75bee9,322d70be,a5d31c76,31a59389,2f479bf,8dc11bef,9ad5101c,125b3a58,8c6c1c5f,288402f4,3ce74ec5,fe9c2dd3,3f3605df,9ab41210,32641524),+S(6c9faca8,b1b435b9,213fde17,ce967f05,46e6f27a,cf0e131,8496bcfd,d856b092,a04ac67d,4bb07624,6b59df97,2fbe2c1f,bb04be99,e269d33f,ccc81f76,3f567577),+S(61031a0c,730cf279,d929b4f,5608f16e,6b1b1440,c04e5a9,fa300ff8,27303def,acc4d732,afb4730e,39a10c0f,5ae2cee9,5099be03,bf5612ac,391900fd,b51238c2),+S(e58fa07f,ebc3aa4c,61ff4fe3,bfc8d04d,48a1e3c9,935317e1,83d537f9,7f35826b,d2402844,7e63c3e0,be630190,8139a75e,2e1a2b22,b05ce52b,e453ccf7,7c35f1fa),+S(4d4d2982,b45a339,1720af,cf6b92df,2c201d38,5b9b6c3a,8fc53b4f,fd3bfdd1,d72650fb,d130482d,116524fa,e2b3dd71,c68b4bbd,54fc55a8,f9824578,cff67503),+S(9adeb6f9,6ffcbb56,f171919c,a8a64c70,9b8ae835,828bd573,b7a1bbc1,3efb0360,6d920a2e,d2e3f41b,4820d838,ca342b66,9af35a7f,7b6d09fd,b1ba4298,9abe027c),+S(64ba9514,d8680f6c,dd66895d,9c5ad45f,6e29,33506f8e,d7be9770,822aa9b8,7ed8c0dd,59bce424,481f88d7,3e641b61,a010e490,97cf84ca,16c2e045,49e9c6ca),+S(9e4ac64d,9ca58a04,46ca18bf,c1700f2c,16937ef9,c82e8b55,9ccbd751,2a0c0222,315ba2e2,601b18b2,cf7f1720,9c4cff2f,e39dfcf0,c2546fb1,e930898b,5b023274),+S(f13a99e5,8dc72fcb,c62a492,d2850704,621ddf48,f1f433e6,9a9814c4,17d4b84a,cc3d3732,f0f4166a,55946e32,e1c01f91,491c82b8,ef0d269d,7a66f039,ac02dfae),+S(fd6451fb,84cfb18d,3ef0acf8,56c4ef4d,553c562,f7ae4d2a,303f2ea3,3e8f62bb,18ba314d,4e78ea87,490185a3,e43cbb33,5d54b6d,2dff17c0,2f526f78,ecd3f31e)},+{S(f1a749e,6cab100e,2aeef8ee,6a654551,c0ff906e,e7d11d77,f390955e,9d29d783,a60f7295,3c8c3bf7,f1dc1358,e39baf76,3dba22a0,1ce7917e,aeabd996,e21e845b),+S(e8c45020,4c9d9ad,f7878aa4,184a1576,d4c65d5a,c1c4d494,ff427e86,8b42ec1e,aabff02d,8a715c2c,34414b27,808882c3,f656389c,71c26d6b,d7ac8013,83f4c57c),+S(c1febd79,1784fea9,bf378237,a05522de,1081df6c,27d22ea2,aad805dc,7c2f1c4c,c38782e9,fcc1004e,aa677f79,536aa069,7dd9002d,ac16936a,1f0b8736,8734174e),+S(91925564,4d9bdf2d,4522825b,5758b3f0,4d32da73,3a4e772,bfe3eb2c,9909f4ef,2568e18c,1a0448ab,d038ae62,a652d152,4bdec1c1,a0293695,9772bb65,d78450af),+S(25bb4202,9880c39,f5bde432,c1fa357c,7f4867f,6fee48b9,24ecc824,5e1a5253,5d43db2,64c23715,b4b0eeae,63127cf6,9b4bc79e,f96ea8cc,d17cb53c,c3ac0fc5),+S(2597e080,e772d36f,df500782,5f92f797,c61c72c7,8d801dd1,3deb1bfb,9e91b12a,fd5918b8,938ded17,a458d0ae,559c552f,bd45feb2,5b4f59a8,f5b735cb,bdab92c1),+S(70231b28,f578dc12,9f8ac54d,fd4e3577,73d0fcbf,65be0dcd,51132882,5a36e7e1,d12aaf89,4dff3e42,405a4140,58524e30,b7c6c4a1,83763268,6852acff,83d2b7cb),+S(f8ddfd5e,5f3b46a1,ab363169,12b74c97,b0bd654d,87824040,bf6d2cad,b4fcbf95,931fc58f,5b429636,5e080d5a,8fb35ba0,f92104d3,891d6584,8d24c0f7,fc95bda3),+S(a033f432,670a382c,57e2408d,3bdcd2a6,6758e63d,77574598,6b123e4,d927bf10,83b52f69,d79e7445,b6e33545,c23f16fd,52691151,96ee60d6,2ecf6de5,b2961a0c),+S(8e77f9ed,9a643f3c,bf197b09,80f92860,f37d8b83,93633230,6c902c38,3bb7f96d,71b4da9f,f736f9f1,f8c3c099,c34c1bc4,30bb5d26,3c861e2c,726fe891,cdf7d1ce),+S(f34153e2,29934c71,5d895102,778425f5,e92f4ee5,b96d1333,df207e62,6761b328,954584f1,64c8f35f,2c4e0188,76186ceb,3e91523a,5e8ac03,d5998253,49b7b8ac),+S(e133aa94,c0252f05,379b5bd7,75ba3f1f,92de2876,68613613,28946904,11b3ed52,40363801,613423b7,cc6c0cc5,af3641f4,dc2a7ac4,48b178ae,d1393605,103bd6dc),+S(28119c6f,a57d02ac,856edb00,f594c7be,22772b0d,700ad14,713affe5,7e385b5c,969b6cb2,8ef483a0,db4a96bb,92e2d332,6e6d86a1,73bc3d5,831bcbf2,5efc437d),+S(8c728d65,8b78d96,44003708,dadb48b,65dcf6f,6d9412c0,e31cce3d,b5384d00,bb3cf660,9908467d,285f1c7f,40f4f18,ca618093,92633beb,b4ce30c4,72680662),+S(477321b6,1fd5b4ef,3acd1e8d,8432ef5d,e70576ee,6b8490e6,839f1985,dec96490,88008466,2244e3f9,7d2ded5d,2193c70e,2d72c67b,9b7cd70e,9f14cb05,70306bee),+S(ebedd345,ccdd0e04,4bd3d4d7,e1f1cb6b,ec06ad10,5ec2cec8,821580f5,d08a63d4,4278bfb0,88e4ff81,a3fe15bb,e01be36,40450f85,885da0ae,e15c6b9f,e78ad14a),+S(f4795df9,41b315e2,24a98dac,d9149ff2,8b9a7bf,e758a1f3,5cb6336e,8e1f9814,6982bc20,285c27d8,12c5c648,d0635c7,fdab85e6,fc6905d8,65da387e,596da791),+S(65a5964e,ea76e30c,74c472bd,3ddd5169,11dcfb3e,1f2d7ff2,9661e254,4a38ea30,a7c394af,80ebbd32,e442271f,b061bb42,a7b1758f,44d7d952,89152fa2,a88fe3f9),+S(f3d10725,da6b6c76,6da6fb5b,969ba7c6,3e33b4f2,d062a446,4ffb20bc,dea2d376,4d65ff69,64518942,bc3142a6,2148137,7bb609dd,6545bc26,9678ea19,62812ddb),+S(f5fe0f35,cde00589,301584a2,f4f5b1e9,3977082e,9c9bd50d,7c2c672b,ef05cc9f,1b49ac82,486e6344,dea32ca3,c96cd5c1,446ac2fb,2a658a42,50425f32,e8d72e94),+S(fce17cd4,d9519a53,f0a100f,ca54d1f9,fa87eded,98a12654,769c95be,151e33c3,40d342ef,83a4d715,bd13df0,f21197c6,e189681b,efa0d925,248733f,5ee07b8),+S(fd5d90d4,a97c1d1c,4fe18a10,6808f46,f6ea4422,c4408860,c2256b66,618af8e0,7ffc76c3,539bdec8,f59a9a7b,b36fd534,99306cf3,2dd1fe43,a2db5b59,af2f7e3b),+S(1c71f824,1b147abd,9e3c1ca3,fad5146b,e531dae7,c9c0d586,4f2d8bd8,7a6457aa,23e7e758,2cfc92dd,e498c0af,b942182a,92e02bb0,7e95bc1b,763d8030,9ddc9137),+S(dfb018bd,9bc352,f36889b8,2a46512,8850a158,872554cb,3a3dad28,a0496f20,2daa780b,d615d778,3de8f5e8,25cbd934,5c021df1,9ef80a6d,39ff87db,67a1e5ca),+S(bbd320ee,dacc1282,d3fd2109,c26f6bcd,46205ec1,d96b806,dca35dc1,4baa823d,ae7beed,3b5f72bc,ba66c794,89c05666,efa85966,14bacc45,9a99d882,8edbdbfe),+S(c9cd8f21,a068f78b,ce5129c0,9084be52,e48d688b,f474e690,b7720360,e362dfce,a10b9fe2,78c7814e,37851b5a,36aa4246,54c6279e,89df8fc2,ed189ad8,11518f22),+S(ddcf39db,aba52181,72c36a53,50883245,39ccddd8,46ec4258,e72dcd71,40041491,85cadc4a,a569265d,412c8fa9,4872bce1,51a750f7,b43385e2,2db405e3,54428a5b),+S(391562c3,f19436b1,a6e41d06,7435fbe8,27de66b5,555540c5,3ca7a0cc,c7876457,c3a5d917,5b56f67c,66ff269f,72c0a1ac,74503106,9059aaad,f3e66dad,45a80ee0),+S(63d4b224,7b2d441d,680a0437,604533cf,1dc48c9,bdcb9e10,e0249960,f966b2d4,e25cb896,ba165d4,46f73344,61e6856d,4c186736,402dc6a0,d866f97e,bd5cdfff),+S(5fe057df,5d2508c7,611dc21d,412739fe,3e7cf9e9,670812df,cbb00255,4d44cb22,33b88e83,9f22a7bd,17c149bb,65bd4a49,29b2a29e,b975776c,e82189de,80c7d45c),+S(5ac83bf,498f7eb0,79507ac,d5fbc587,f758afa9,b6a1ee51,4c857f8d,608a7b1f,1c866393,8a91904,f0530bdd,ba15390a,4c10fc4c,ef8a2f07,d799c89f,69a33097),+S(b0f9e4b9,b29790b6,33bcc04f,d860cb0f,823d8d1a,4cc1a1c1,413c1606,cc9a8e2c,b617d40e,7bc52192,be344f46,f9021c0f,ccaf33fd,3e8e3118,93df993a,20c2ee7b)},+{S(eccf169c,9514a854,8f7e1131,a7438469,4df7dc2,fab96462,20e5799d,6d3f672d,452e53a2,aaf17617,37055bb7,24b64f4a,8fef29ed,f8571ff9,a3a6d2c4,6acdb91e),+S(a77bcddd,a0fecd39,a99c6387,57bda1bf,30257248,6a3fa08a,e2d6ff17,e6e4b6ea,debf4c03,b4bb5c7a,8a386a7b,1e459426,6c78eec6,55f01cd9,f137ff18,c5fbdb1d),+S(a77b91ec,6db6a66e,a48de424,65079a2e,ce220fba,da221601,840546ec,2295c2a2,3c721fea,81f5fe05,163562a9,849bdb15,90bc818e,86674ea2,57fe8d0f,4050086c),+S(99a28a1a,3bf2af79,ef2bf134,d31880a,71c2aad3,824fb7df,23fc4fb7,d54b2910,620e2918,df14e3c5,dbfceada,1905941d,32d77592,89ec607a,f9851a6c,5592803d),+S(7eb52616,71402db8,905c7097,2af96b72,2bd77d,f124bbcc,5418f217,f6d8c7be,ce1e663c,8276bf42,99919592,11feb13b,66aefa37,5d6dca15,8b7b66a3,ffc6d7ec),+S(c88b1815,f183e6ea,3ce8469f,ada5b88b,805288d6,828473ba,368d52f,2145e7a4,55e78f2d,3784952e,cb47f6b0,113eb471,8cc58225,85f9d1e,2198dc60,af3f90c9),+S(dd893c5e,a2e4e70a,fcc161ac,47232d3b,77f16c95,54c98770,9a7a6f64,c0cf7ab1,a1a58b41,c7d4d0c5,6d6c908b,32d97467,b8b6ed20,73e6a677,54935665,6a92a480),+S(591b8422,eddbfaf9,d2c27c28,dd84dd30,712a15a0,deb752dd,dee682cc,34722ea7,877b0c99,6a248082,fd442509,b0ce4cc1,b181d4f8,8ff755dd,5f0dba66,ebf95d1f),+S(75f9e3a1,ffdd902,be5d1d2b,3ed18b37,62e42e95,8b024ce8,f892ee13,ab35c674,57fabc84,7c68cfdf,272effee,e7a6ee2c,5fecdeb4,8e4877c,ccf2a8de,2e2264cc),+S(c8a53d5,e1895cdf,db61c1a2,395a866b,ad803773,23ea43ca,775408f7,a4141cc6,ddeff9c9,97a11e4d,d0afab30,f63229f8,1b52ac,c25749ae,2749ddb4,2b201196),+S(8827d23,668f3006,b966cb19,698a066d,aea556b7,4108739d,d6414d8,e8dd78c9,3d009ac7,2baabb53,2e3658e1,8941d4b1,efe512b8,fd7696d5,14b12216,215f10e0),+S(dde6b713,5cf165c6,53c7f5db,542501bc,b0a41e3c,c6779aa6,194ac1d1,8a830b01,25c04b4a,937e16b6,e72616e2,d64a413b,6a7c29ac,71dfcbf6,826261dc,2507c16),+S(8cf6210c,5426b3a5,ed594699,da6cb8b9,8069a3d7,b926cae9,fedb2e96,25d20010,78017fc1,7915e3c8,62557896,acd002fc,7263bd7f,aed38fca,d63ccaa3,57391f30),+S(35772904,91661db6,340e7d1c,a98db8bc,2f50f557,283ccf11,8e446f71,925ade9b,fd8a4a56,b82dff95,a59e29ea,bd5d8e8b,a876bf95,4abf0537,60832d1b,d7edc31c),+S(60e4201c,4dbd9c99,c5eda030,f041f51d,f648f77b,13ec2072,4d89b6be,f249d793,ebd96057,d60b7cae,71349c51,1a3ca99e,847419ff,cdcaa0c8,54d75d40,8263d81b),+S(f39d686,b17ad518,3a7d300f,1bfd015c,57541f08,a96b5943,43d2ef82,bf20bb6e,f1298c9c,633a958a,a0d12b87,8c95836d,f9f93b5f,5e3a6bbd,93a75ba1,1b96d4d0),+S(37ea7dc7,2a3a0b4e,72412814,bc1e1233,17ea3e1c,c4ede35f,cab5d31c,93cc330b,aebaca93,8b14b315,708360e,5662e6a1,af25069b,cc07f581,225dd131,c656c607),+S(ff1f61ed,ba3cfc6f,2fdf3043,37205bab,301c965b,501e4f2f,fcacde00,dd127b25,fb1edca5,90e00f87,eeb56ef9,94e9bb12,b64ad1ea,f5ef0afe,6f0125b4,e100a483),+S(3376e0a5,b93f15b6,c46b92ea,e313ea2d,c5d0b961,a2623487,8919cf5e,25e9ae38,a4cfc1be,fd24647a,20ae014b,2041ab3f,6cb7585d,48a607f8,299e0c10,96bcfdf1),+S(be575f99,842187b,30bcb312,987ea218,3d613442,8878804,b5e7d920,12e58d9c,154e02b0,b573c81b,d2079a4f,4a6efe5f,5f37502b,33225064,4eb38b2c,3f0a1767),+S(5a215836,f1f2997d,9b09d4d0,6473c55c,46cd3006,70d85d6f,6b5531aa,c8da043f,ef5fba1e,b6e1deaf,bd83e480,fcd4984d,cf60f91f,4799e8b4,3f4edd15,f94b6d33),+S(d73fee2,16a503e3,a7d6b0a2,675adb1d,197c3fae,4d43835c,b6b043f5,d44909f5,6f2cc9ee,fbc36b4d,a5b3e704,c13daee9,cb81ce9d,470f1290,8b32f047,ae231053),+S(26fda2e4,d07ec613,ded58e14,ee84e421,ea58e5b9,5beed698,d847f6a6,db185f6,683c0002,bcd6d8b7,1d06e592,db4b961d,f2518fbb,47cb4ad9,96020d84,ed8a5909),+S(cd3d4e87,e433f2b5,5dc55c6,a3f280fc,57f899e1,f8f0777f,32705f3,eb24551c,2315d85b,7521e4e3,8e69f29b,a49a3203,abc7f280,ad49365a,4c78f21c,3ee12542),+S(652476ac,2c9b871c,e108fa13,6a739766,879a76ec,60d787ac,a1b7447a,67f8afd8,b66bf6db,cd3a1393,f70ac7b6,d53069d2,5f084dd7,f05c97a8,76f7f646,c7b67fa8),+S(61ab4f97,61c96446,ea7a75de,7ed36224,7b5ce8b9,e7b442c3,432f9fa0,ec74355e,f391652b,17a910f,6d476c29,89e854f7,d31a5f31,fead5fbd,5013ea56,e44985db),+S(36e4bb36,e62f78a6,a6155351,36a73637,13fe8be8,1c8c3460,a94bb642,4f7c80de,12b38983,c10079f9,b0016df7,fba0685d,5eb87518,234c65c0,7dff006,dbb6a563),+S(f5e4cb89,101e90d4,b2f50097,aa0b22fa,df076932,f4045e9b,7a9ce8d6,ba178780,c12ec4ae,56db7971,3a1bb0f,2559e3a1,de3f8200,650c809,74101940,181eb52b),+S(1138ad12,333790f9,20e979f6,a6471274,2a9bb567,2356e3c,80ffff89,a9de533,4caada48,a78ae26b,790f23c1,606a5820,98642f4,bab5bfff,95748f6a,2ccd6bc),+S(e0346d21,121ff741,fe4eaa23,938a4347,a71df442,9e55359e,aa20d691,c9f40840,c1197c8e,c36676a9,28a92b56,811845d5,d9632c65,9142cc12,3c65e54f,c282dbd),+S(d42011d6,1061388,fec6b7f,3f332b20,24ab318f,2a9ba7ed,23731207,3e32478e,451a2b16,5c82b1f3,e4d2a0a0,bb407b84,904db4d0,caaf733c,e31fa97d,2fb1735b),+S(63964eee,619074e0,780140fe,2e90836,e72328d2,448386d4,59c5be23,187f5048,c49304c5,947630be,5c60064e,3cb40436,c2a7f46c,b221937b,c7c5d7b1,76cf5e37)},+{S(8f741868,43906722,ab9f5c6e,c796573b,622fa2ae,6d985bfe,ea4d51a1,8f141792,61ecd858,d6992c4a,bdc22472,fb8fd242,929dc5b5,36ea8e35,d1c8c513,bcb9e31e),+S(f2dd67e5,6f75c397,76b29366,149ba4ff,69385651,53afb385,3853acb7,9fc2bd59,3a24641c,d48ca39f,fe992bf1,50291604,79066af4,a0cf364c,9e52a9f,9b51eb66),+S(9386aa5e,c3452728,a8f65141,e2f43a14,c250173,9349c96d,e1968a4e,48cd30,a3a38a85,4f68048,d8f81002,3eef9966,780262cb,aacbe859,a8fc66fc,27c37f32),+S(6c9901ea,920c0f4c,ce51fde7,ab283f98,eebc30dd,c76a3219,1df4c4c9,db467aac,6773f8ae,e601201a,84dd4485,fa560e22,81d5eabb,25a3b3d8,525f4a56,65f79d05),+S(ed1eafec,876154e0,58597caa,8250b0ef,7262ff70,b719ec9b,63c0b2ff,9d167fe3,73505073,2b563f93,89078cc3,93ff9837,227ab8a6,c7d789c,6d2bc835,2018f77b),+S(515806b5,13d4d4bf,83533b56,3b39bf9c,4e808426,f2e4cf16,562e759,cf2d56ab,83c2fb,673a08a6,b8a86b1f,e1ba23d9,3347903a,d6855059,130d8d39,737ddead),+S(30a726d4,d8db1cfa,d59331a0,8f4b5376,36848547,914dcd75,37a80e40,109b8e35,8f628b92,6a11ddc0,dfb1cebb,934aeaa4,3840d442,a61145d1,803f771f,7bf65d7d),+S(116867a8,d72fb00e,80a6f267,e8163770,34affeff,36d667cd,38219f0a,e3c9038d,270f15be,b2a3d50a,4088720a,e9a2c3dd,df00817e,31e1a5b1,d850fe23,dfe51657),+S(abea2899,e4575c6a,201c96fb,a60a24ee,1f1fe0c9,b718b54d,18981938,4f33a1f4,d43d54e3,9e8d433a,ce66ad94,e52662fa,8013e778,f8bc2e3f,31938a6d,5681c660),+S(1fa796d,9f658aa8,6ccd0fb4,6a735651,102e3181,302e371b,8c965dd4,5f078b30,69815d18,43c3b4d9,f7fa4af7,3d2e5dda,390e5372,28608912,79826a53,a437031b),+S(f5022faa,c8caa29f,304ab6c3,d00931c5,e09085e2,73beab04,c1d18f87,1c0fde73,c6abd143,73213fe8,ffa5ec64,8a22dddd,fdf2cb25,e32afd58,4f92dca7,838e8249),+S(8190b10b,97bc72b9,301b1dc,cc60e69e,460e389e,ce7d5d11,4e2284de,853ea02f,f1ffb850,dbff0f06,561b75f6,5d2ae823,cb13881f,d1150eff,274db4cf,112d2253),+S(ea230fbe,c58d7e2f,1a3cea60,f9018562,d2fefb49,8efa312f,4beafcd3,139da094,6045d69d,b27bee6f,3357180c,e92d3866,b480faf4,2debc033,cfa118fb,b89c3bd2),+S(333d063,ccef6aa1,f78c81b3,4a84975c,82bc2cc2,bb897608,f0bed49d,cd08829,90ad105e,f72b7e4f,a927240d,9c69729b,a0aae3a2,3a45342,3be2c385,488840a1),+S(4d95cb48,58d808a3,be82f42c,da4f64a8,c64ae176,3b50257f,2e4ae655,fcc4802,5f6efffc,99bdde54,6d8ffde5,e9a551d0,121a39c3,86db540d,1caf74b4,894c5559),+S(b87b5eca,6e0111bc,5b756816,fa82acf9,77f81376,af796cdd,1e8fcb09,4d363d1,442fa845,9c2a7799,2c09015a,db80f26a,28428851,62432660,56026009,5f2f9d8),+S(34baf43a,a82cce1b,19945590,ef3cb582,2ab03142,6538ea5f,74571582,ee14cf00,9a76705b,c0141e29,75d11543,215377b5,3c051c31,156697cb,e8f56721,da386e2b),+S(f07c5d98,a2579c17,53b3fb58,22a139a1,53e7deeb,ae9304b,114bb188,d61cdd0a,ec18ce0c,1e51b8bc,e12f3d85,23739f8,bc25708f,32deb81d,a780cc4a,1010692d),+S(9a146c80,5ee261ad,3e708885,aa41041a,53bd3758,b3d1ab7a,1a44aa7e,29acca7,fc553e71,4ad8a192,90f94ed7,7c171f9d,9ad9a047,6791f045,4a3ab7d3,f8834f02),+S(c8088409,650feb74,9f9fe21,61772279,128db1d7,58610a9a,8b9fc4b,ef9683b7,692a6be3,132a08d3,82295ee7,1c469465,ae7d63d6,c20c7357,36935003,28799639),+S(53bdc8b2,3edd83b6,b149b79,c88130c6,b207f999,e7045285,7e828f81,b325b9d8,a9a039d1,79486167,8fda727b,1706e9ec,7ec3eba3,26e6a4a7,e27db3f0,8a6ee238),+S(fd08fb47,4af98207,3d8b4ef6,d39012f4,78225f1a,bde3c841,6fe3881b,4fd276c6,d38b53a9,100da1fd,1d2a987e,6907370e,7bca492e,98a22e5d,74a10c9b,93a197e1),+S(5c42ad93,2306363e,a0edf86d,31d14b04,c3f7bc09,c9fe1326,d1ad085d,c84fb7ca,1bdbf812,e9ad6486,ff572d4e,de5be4c9,59de7be3,f21e0dd8,76534091,f13ca3d3),+S(66257876,115e7eef,fc0e6132,9f177d3a,437c81c4,1150f86b,45904f86,30bae971,df830e1e,33aeded,721a0a6a,62a3a402,1d2b7ab7,438b7b3c,d834d67,3a857aed),+S(4feea8d8,2cc6601,c847deff,35581c1d,bf1f4070,402bb948,ce9a41ee,16661627,c09a7686,ad6bcec4,ea9ab0f7,8316adc0,7c7a2899,9332cee7,5d70c50d,249a0007),+S(2d3bb180,73f5345e,cff0c901,9a6f2fb4,e0a237a3,9315fc11,fd53c7d5,aec43670,58a9459c,2710ac75,ff2510ce,4c9c5fb8,b4f739c9,c6611494,daf896db,e43b080),+S(bd539f5f,47b25116,7159153,f402e0af,8650c17a,de7c5dde,2d9d9cc2,d0a3103d,407cab4f,ca581f10,eb386e20,9158541b,8649951e,b2f5e454,2a7032b6,53f0caa),+S(c7a72935,87ba5114,744c3d0,9030be19,9ccea57c,7f80be87,bfb5b79a,8f8e200,7c2a98f8,b4526422,b211bea0,875a81f1,d379012,486db005,e31b9682,404e14a3),+S(cdf20316,f4b63ca4,c472e1cd,b3a938be,291d98b9,3ad8f3f2,4f3e1a4d,f1a6cc80,ab993e8a,68988d4d,2749760f,241399c8,136ee9d2,3d4ae7d1,e6d26df4,6056587b),+S(1d341e6,2eca1f48,165bb2f3,86207da1,f2c7fc86,dff7a75,cb63976e,f21bb074,923b53ed,fe2f5bb5,56aa7cae,2a08ff86,160e3344,c4adc09a,e7aeadfd,f31e2b9c),+S(8704f69d,9d335975,f0e3bb83,5aa3024a,60103d89,e5578253,fbb3d537,1983ce4e,94f4adfa,31dbd13d,95c738b2,8a569453,cba45efd,1cfd20b6,78f6a724,e9a8d025),+S(7175407f,1b58f010,d4cda4c6,2511e59d,b7edcf28,f5476d99,5cf39944,b26b64f1,bc4baabc,bb1c2aaf,c92cbfe,ecb33791,4fe01748,8bb8e2d5,bd918104,4dbdc75a)},+{S(a16a4734,9afd167f,d5e79d24,9784d87,5121fa24,2c3a54a,88f9b176,72669aa1,4df3fb81,7021efdc,e5296735,3a177b5c,51cc7762,4755ba28,1084db5c,4809e02c),+S(91d1abe3,8d3f9671,54337e03,d27fa6f8,c3007f32,323d15c8,31306b3a,30900328,b1b8c71d,b388009b,98000f9f,291b66e3,f890d42c,a5812f34,5c070f6,e73b89f6),+S(61b64b1c,f2a0e720,e9bb4853,537b9f38,66baff87,388df7f9,f14c06c7,12080b96,44444011,b6ddadc5,7ee00eed,b6af3772,e4116711,c3853f13,7f9c7b00,2bf2a1dc),+S(3b96b2ee,d9cf1ed6,3aaed8e9,aca3a464,d6a6fbf5,e6fd48f0,5aacc318,dfdbc87,51c41c26,506cac9e,bd0c5dbc,8ce8788a,3469e42d,de794707,9e0cd0d9,826e9c58),+S(7bbd147f,77b293ac,ff797b9,a52778de,5874b754,c08df397,72ed8ef7,53242efc,3e843df6,75abef2b,e4d32c83,205322cb,f53bde0,2563eb8e,b5dfbe6f,27d4cada),+S(becb7fc5,de84f994,9f97e55d,bdb6981e,f38c0c45,1e0e454,519c9411,5bae3d7,754145ec,ee6f9c7c,f91963fb,5b0a683a,ef24313f,1125570c,c9b9c7d2,afab99a8),+S(87936626,aa88346d,6d4330d9,3a188ed6,992bdbb8,387b395e,d21dab93,63d833eb,a28c868a,18dbe0e7,12ca5237,53f6a50b,9313e687,85f3b31f,ec778fac,87aa9327),+S(e79d4b2d,e33de1e2,e7eeeb44,d197aec1,f5883ad6,1394dd79,de274ef9,76e3b022,9c73ade7,7c661527,ec2ec6cd,b370c130,380bdd9a,4bcb668a,86e8259a,ca85f293),+S(863f0d65,34de1222,237a07bd,ebb066b5,2c1cdd83,d7a6d3df,278e57c8,bb59b8c7,c546940b,99d04ae2,5cf7c881,28a985cc,9b6223a6,ffc06fe9,8a3e0f68,439b9db6),+S(71e9b0d1,3972d9e0,2225bbda,5a1024e9,c373eeb,f6514eb1,c113ef88,dffdc3a,4436c52e,c58a34c,562638c7,8d76e3fa,29e3586d,fa667577,2fe0b932,c4a1ade2),+S(ef4a500d,c9369125,78fcfcbe,3c313bbf,f0323caa,75750b6b,a317e1e3,dd8054e3,e807e9cf,7911c919,fef82e40,a3ae1b9b,ed8ded38,e74126ed,863199de,c031f2a1),+S(806dd4e0,fbf72904,c7b0080b,4e7526bc,c71fc52d,f143da80,e571041,dd964915,2f4e2e67,3348c32d,6bcc0741,2e76f4fe,944f96bb,d73382c8,c6880cf6,629eac8a),+S(9ea889e8,acf0441d,6e299687,c532ea8f,8b9453ed,5fea0d47,f735056b,1eb3bfa1,e43f79a8,4d302f3c,88698896,5fa7b8f1,a92c620,dfcb3462,c4befe3f,4afbff5e),+S(9a990a22,1d27d8f3,40e79489,58cff3ca,2720dd3d,ac71688d,9c3c9e2f,afeee215,4957ac76,db370918,7992b0b,63370656,7e0f4a0a,9e5f1d9a,be8f7d5e,8a950eef),+S(d3291003,98ad3d92,1d6cbc6e,b37ac3f3,9360cea6,23edd794,64d34a51,fa7adc60,657c110,5bd8df6b,fe52addb,2fdfc41b,810a1ff7,8662021c,7c220b0d,b3509d14),+S(65eac576,e149d97,3cbd772c,60570870,e437e92c,2e5138ac,9c0534df,b7a45582,ebecb6a,edb87cc1,417e066e,fef8e52e,c61eb00c,dfd98205,91d63c08,9dfd5347),+S(b6976b99,c2515be2,2bc901fd,8671255b,f8fd76ca,1f3474cd,5eebe39e,98f6f14f,84ab17d,da67b61c,fd01881e,b1087e69,845aecc9,ce1535fe,1c7245fa,8df98181),+S(c7f5967f,f9910e10,54c93e1e,d0290102,9bf31787,15f53758,f5c53cd3,c79a52bf,bfb01210,5c1ec69c,847ceffc,d1105ac0,528129fe,3b4d3086,2b6e9562,836f5eb2),+S(ffa0da7a,e8984e4,d02a0fe3,acfb4e81,2a63d6b1,682dcd78,fd2635bf,88cfdf1d,49459ee5,3fad1097,2da786fe,45a2d201,e4a52260,7779b1d4,23defafe,29e70098),+S(5a53d683,3bc1740f,d02f278b,2ac15a87,f137f2,c798f157,725a4aac,63f1798d,ac5e7ec5,86d5960f,e25f9e25,7cf9ee05,110d9595,e440d032,c416d444,6242d10),+S(70f67487,9b030a4d,9ccc0bf2,90d5b78,c455f8bd,a1fa2b52,efaf0200,6b70a6cb,10f5b1c5,dc46c0c0,68757804,93805aa7,5a259dbd,95b4bd14,d031daef,a81bf7bb),+S(a4baf0d7,d3a53c29,e78ff81a,52d634a,e009391b,30a9aa91,df8f7bb6,13e3c16,c9f9d001,7f388f09,b6802c45,e1fa036e,99443467,c3847937,8b384a9,dada35cc),+S(351b8e4a,dd336c28,5d140c57,9f2b089d,3c656a05,b1ed6,4cdbaf7e,e5bc671b,b996e61c,cb14553c,b7b79803,c82332b6,704ce97,fb4e19a5,1f70b13d,f8e2732f),+S(d248350,92898c0,5dbb4465,18695efa,e59ac007,d58b5df5,bb3b7038,82f18e61,23455e7f,5104051a,44600be5,2e242a90,95213d25,b4fd65a7,62c3f9fc,9234c2a5),+S(d3fc6d75,10cb0b20,77b52b00,93e84d47,54dd1a28,4f3928f2,a9e3cc02,f1869588,26e86b02,c16171d4,4238aecf,666146f4,9386e0eb,52dfed87,7ac0b409,51ced10b),+S(1c611335,3d115906,182b0e4a,7eb3d39f,552c49f0,c5928aa1,15ae00dd,c23a3b70,1c3e3c4e,ed65ce47,ea82a33f,df8fa6b5,532977d9,53aed38a,f0f4dab3,98477c6b),+S(6487c5c6,abb6e673,821c4b0,2c485f83,3e149af1,83b3f025,71a81fbe,660e98e3,63c4f6b4,7eb37ed6,7668b41,1e83d9c8,9ea323f3,2d9e8918,20b65276,a8a7b7d6),+S(1b0baf63,6daaf2c4,28a62bce,bdd41de2,a4d7cf69,93f0b931,222a40cb,9f5f9a2f,af9a62cd,f91e2c6b,47f308af,e2de8f16,def4972f,24bf4c5b,2b1f92ac,f63a21d2),+S(95bbd974,78e1b8a4,1622e460,8aa82fe9,e77d43e7,492a0d21,1146d987,f9b8f255,412bc52e,d61c3880,210d3df7,f0d2f27,d458d51,388803e,fef1c016,d7c9e7f6),+S(a3466715,5b6ea598,2d3945fb,743a1510,c671b96f,a3494a57,e0349010,55ae087,de35a05a,1a943a42,7210165e,55d5cfae,3ac15490,dc6b0f43,34c0c99b,dd778608),+S(2ed76c11,52ac3600,7aa17c85,a5f902f1,7c845a05,a4e0aaa0,7b05e836,cbcad59,9c60b2bf,bc47a0dd,d3259151,37e89812,a08d39fe,cf5806be,eb538575,3b159531),+S(20e6e2e7,96946bb6,30c7071e,f1b92ea3,d53d280e,e450111,5f5da36f,840dd273,2c528501,b0eaa61b,b5f45e52,6878b9aa,7ee13686,c25796c3,3f8302e9,44b9469c)},+{S(f040a2fa,b839c753,4e216425,6c2e8dd8,57c52dac,e75cab3d,512a7b1d,562075d2,9e211cf4,bab24e0e,f745e2a0,9b59565b,be7b2449,8123f6b2,ba383b25,29554b36),+S(c66813b,904831cc,12f89e3f,bde93eb3,11ade6dd,f6cfdf72,21cc61a2,ff46bf26,3b60c8c9,9da35a58,7b9650af,f85ca785,ece41146,e7ed8d6d,ef8d26d1,f3d055ce),+S(cd38ece8,7c7a9cbb,e23b58ef,59925633,734de285,f93b3ac4,eb01e03a,adab904b,a5f48fcd,afe414f4,1a44917a,5dcb80b9,30373af9,70e9f22d,c1af80f,a8b06320),+S(72d6f7db,199564a2,6e823a49,eb0171cb,ebb76a2a,add56c7c,6d3102a,9c3ee18c,bd2039ec,c390839f,e2d4451c,9437fef6,3e98dc62,3ab0eea4,c56376f2,e270f626),+S(2ea6c313,1e101867,2454e15c,d34d5fad,13829d5,4ca86062,f074e512,a274167e,67e3d34a,56f12e1b,43687f51,c2d56395,14355d7d,9cc52726,22f62ab8,91c8d5de),+S(d66bdd78,8b20da57,b2485804,a2f6e2ef,78c7ca87,ae1c5c66,fc533533,5b624162,1a8688a1,300e6d39,e130037d,3f074ccc,57addd1b,88977e64,2ab296ac,d6e054c9),+S(6d6458d5,d1683d85,8f9e40,15e5a94a,73868bda,54f6139c,446b5283,6d211542,e44c7ca8,33761e13,ca5458ff,dc682f22,3819411c,a3c5feb6,24f06412,471b9f5a),+S(49f8063,b3d98f6,f159f2e6,65b0e07,8ef8c7df,44da06c3,55b592ac,13402b9d,b0b2d838,4b24ab11,de895013,e897e825,45c3e8dd,6cdb0990,555cd871,5841f8cd),+S(8b2fb6bd,e60449da,2684f8e3,6267fff7,254051ac,faea37cb,102c9bfa,91abb2ca,c82cb9ab,c33c1817,10d3fb19,60f2850b,5072eb47,404266f7,c7964fb,f98027d3),+S(cf90331d,73644476,47c8f86e,eaa6e67b,f3fb4b3c,4c895b82,30ab2f38,80df1e42,9c493d94,3471efd5,ea90f723,db576a35,8cd1ee6,1a119b56,6c65b16,112eb2b4),+S(e70667cd,8d2759e,43f99417,ecc505a7,953d80dd,e7ce2cba,3c8c948b,d43a912a,92a534b3,51449a66,82395a3,b75877ae,851923a2,e791acc3,7293d728,777a2247),+S(4cc07d11,4a715e9f,4b4d0811,f0337c7e,f4bdff74,2fb008d2,1ce8a9ea,50520d47,478b279,613d92d3,dd24ae31,2658eda8,28a7d628,f0346e04,5d5d9dff,7178f093),+S(2a1cee60,4cdd3b2c,1f859bfa,af63d7e3,9aaad910,92c2a38f,a9362798,9753c30d,325c248e,d409e8f3,b96dccab,6fdb62a6,83b7eaf3,36d2864e,b821663d,ed31a6f5),+S(7c18d0bb,9a01969d,302616cb,bad8722e,d00103fa,9985a50b,765f0e2b,9a2ea14c,f6365a6c,b06e4749,c48c212c,63fff571,8f46e0cf,6fdc8c42,34d4db64,ceb72080),+S(a706754,65cde407,e853e882,8fb7a2fe,98638d7e,64b8df0f,b0a7a0b4,e629d0ee,fd694b2c,1354a5e9,415926d0,1590eaac,dbd1b36b,5ecc46b5,72467c3f,e2cc5393),+S(7ff57a63,36ec73da,cc1dc527,928cc6ff,4ec063b1,56b36292,23b8bbb0,a8ba2c7d,4d6dfc43,da0fe33a,1e75dbf5,5e5d669e,be6471d,eb8a4102,6db1a41e,9d5da637),+S(d4b1f7bc,87558c27,7e0fdf91,22bfe488,b3182555,599dd384,5cc039b5,93218e9f,992f79dd,c8f46682,5c44a54d,626b352f,7f59139b,d545f78b,44bd0b10,55c3c1fa),+S(897773f,a9de63a7,46ebf58e,248d0c21,10f90230,a792f0b6,ea5a25a0,9d1940d2,b7c7dd27,d561dde6,ca7588b,8e3a09c7,16297ba3,9d501744,f9639a25,b16b4f64),+S(2f9cb312,b071a600,e5d24cfc,79b0fdbb,f6da1527,10ec395d,53078453,1a3b07e7,49260f95,757b9b66,feeb5c20,16aa051,b444bfc8,836fd8a2,ab913e98,731fa97e),+S(5c53b27c,4c0ae241,8569c806,8dd43a5c,6fa23ac6,74d001b4,eee6a748,d86c9e6d,4e0e720a,f430972f,b0ab89b8,79a56eb4,f0af5161,cae83ca1,964a8099,f9d497c1),+S(2671ef50,5a321387,9560f0d9,e8588707,1c2b87b5,d06bb9d,dec3d179,6275b098,750ea18b,dbdcbd58,be994eb5,cb3539f5,8c3dc630,7d50bbf1,f69050d6,235826be),+S(59baa5ce,9d6e707b,b0738f4f,d37c9890,801ed796,a82afb2a,ecd2c5ba,195be65b,e6b66356,20a8a106,b58dc202,10cccdd1,e0e8c579,c92f3fbf,8b335765,b30d8291),+S(bb422d0,88abedca,e4686479,295aa1a1,77d7e68b,293bcd31,4097ddc1,af764b90,a96d33f6,46d4861d,a471f853,e0c6ae32,b1eea619,a7441504,a773f5e6,fc548805),+S(8d7df8a5,f08ba2b0,923662fc,e594f111,5295cf6e,c5aec9ca,df0f7236,fe51b362,26452215,7d8572d0,f057ec9,6f572f11,ebad3fd0,56032240,26b54df2,991f9046),+S(9e2b1637,352d8988,1e76fdec,c2dc8533,6a71b18b,3c98e59d,397602f5,8b9087d7,b997404f,1c0b1e64,90cff078,fdc47c42,aedf245a,e69d844c,18a146fa,6d8c3d13),+S(972c7bc4,6362bca6,b58f1d0b,87c0b8dc,fe91a217,7f0cd7af,404f6f06,47e09358,cfda778,a59d944b,4ec08bcb,3aabd70a,cd6f29c5,204c9161,fe2e5bd5,71d03f6c),+S(f7dd32ed,89ceaace,52e7f26b,202ea6a5,c7e8ff42,6c7ebc16,12106f7c,6fe51a54,7349c17d,d8ea6ad1,cb346e3d,26989950,3de00c11,4205b3b5,50d27ff7,67efe75d),+S(c9f96f88,3e34aed,97351928,fa77b07a,f4b01bb4,e4515f0,59745ee5,decc9fbc,6fd62453,dd6c9dab,10fb7d79,c15b4822,178eba31,258800e4,519e627e,91ef20c9),+S(9c28cc93,809b35b3,96a4c9cd,d6976391,17402ffb,5588cd76,7c41a92f,e971a9a,ca3b2634,28513516,86a661c4,747aece4,c8130d93,ff4108a6,3365e725,2bbb80ce),+S(263a3fca,437c4dbf,48ca36e6,aa892d61,abf58f6a,d3c82b1f,fe945dc,c45a15f8,604c5bec,69e0f1a7,3e8f8a80,4f762cda,96ba2198,35268887,910c8df0,e83d3044),+S(7fe42dfb,b3466ed4,d7cb8242,5e66b5e1,14a70516,b118911f,9170656a,3dbb04fa,d11385f4,b0a3a0bc,cf09374f,868cb30f,55175d77,2d3e463a,a298b6ed,1e6f6fa6),+S(53f2432b,a8171714,3fa9df3d,ff41ced2,4a29b314,bc5a8c96,f5f6400a,d7c0979,42ad1004,3e0f8648,332b1c1f,6ee4f821,b42a5b0a,361747ba,60816f2,ac84c58d)},+{S(b8b52efd,bc367a5c,a1534bb2,f339a048,50fc4941,1668780,dcdb8b51,2daa7526,306a2236,856070ea,1e0fd846,cd571889,e20968cf,cd490bc9,facfc4e5,a5970b2a),+S(27e226b6,ed59c89,5bd20232,bc677c35,495d9601,5f37493f,5075718c,2017e42c,a130a5c8,54ed8ab3,ed657e0f,ee4a04cc,1b59a291,6e96465a,74b36144,7cc621f0),+S(1733f1c0,da38fa79,a7b37988,1822ef51,2392d8cb,59d1ad1e,afaf535a,e151fb64,a93ddb00,af779565,eeb230af,815f9434,958ad39b,387d9069,a03cfcb,8563a920),+S(e3f4b777,d06c8839,c63dfb41,73281787,72debac0,ed45b991,724c19bd,85ab3c58,2d6a84ea,745decd9,e6444b7a,dbb59fa3,21957b7c,3f8141e6,fd633d3f,7539dcdb),+S(a2b42fb8,9ac10df9,ebe804b6,c105e855,25cb05eb,7407d383,3031e216,64491ff5,d0973dbd,346a87b4,f4ddfddd,12be3131,e6c6a397,8e17be2c,bda23683,62f80765),+S(66d441a2,6b28378b,cf23d33b,ffac1163,7c23bbb7,7ad352e7,ff5cc09f,41bf6e91,982aa46e,5fa0b19a,28ecfdee,539c0ec,b5f06e2a,217f7687,6c3cbf1d,e92a6068),+S(3721fccc,20338f8a,779aceb8,eae3fc7f,bb0e4040,1de2c8e5,27941ad7,f789d0f7,d9516c54,8f457b6e,d44f6bbb,23f36c7c,e6fdc548,60e5042a,b3dd4f67,ad5ae3ea),+S(959e980,4618bed2,73b5cc48,5565df27,b8e09c9,a128a9e5,ea92e347,66e02015,cee3a227,1bddee01,3582d65d,c3e26c8a,f80a4601,abcff432,b1737127,91ca15a4),+S(f2e81d16,c19466a6,1b56931,935d03e2,aad6b8d0,7f193d97,bacdc29e,13cdcf38,afb8e973,8d563dc4,1e7688f6,c6b43b71,f366b576,9479f093,88fd09e5,faa1063f),+S(98305a48,800f92e0,bd815192,7b8658fc,60a97c64,c9f97383,68812614,3563910e,d32db8e2,6699b969,5b644c08,39f2399,f8ef45ad,a0d857c5,2d0c7c3f,96a62993),+S(8dbd4fba,113c50ba,ff3f251c,96aba9c0,440d8e69,8a1e4ec1,84fba97a,e497c443,f642b1d9,b012eef2,40c6ad38,fe441d11,cfb42ec2,a3c15540,45e64c76,c15be491),+S(deea5bb6,c7eac0a2,93e90817,836a3e55,2a7f1354,395296c8,97964c2a,4527a727,4cbe143c,c9fde617,c6142335,4323b9d8,bba13dd7,fbd46db5,cbf4ce2a,11c9c00),+S(349f46a5,8621034,9f207a07,4558787d,336cb0cf,a56c1e67,8dd3b04a,4d717f4b,a6479d8,f7f017a6,32c369c0,8679fecd,985b3c16,ff444ba0,3fe43575,8b96455a),+S(a6d818c9,dc182fd7,81343bc,b737811f,611c8499,e44a6cdb,33a36beb,7e44b545,1a8ee36e,d6e9b191,b9cbf840,3924e6b8,ac3c3f8a,cbc9a0b5,ff965d6c,734d741d),+S(f9cad333,7b82ea41,b00f3ef1,bba37b8b,fcb24e8a,175fe380,8e399b67,d21837e7,cb206854,4e7f2cda,28c035f1,b8b50009,319797da,bb498b99,d31e24e2,4fa27ca9),+S(25042b59,f9b29a9c,83d04515,c78f1c25,5b72f97f,7b387113,e88c36b9,9da3ebdc,d966ba9e,a7eb9734,e1481cb7,2df63252,7492e1c4,43f1fc9,c0efe0af,442b5a13),+S(e19c4319,b5c9a01e,b588c629,8a7c6b76,1b80bf4b,e39424e0,666ddc45,fd57e0f6,1b0a2c30,4a1bb1b1,9dd0b50d,29df625,bf958a73,46cc6b1d,81a213a3,b6636285),+S(59c26fc1,6d151c0c,7da0edf6,c474463c,587c45cb,7e407589,d15aad89,de223fa0,f7b227b5,4855c1c4,1e576431,8a7106eb,ea214686,ef815b42,db8c18ae,d5c940a5),+S(d967d546,e07ac1c2,31fd50df,a1d25a51,60594d88,3e816f6a,bd62c15c,446aeff6,8eee6c03,6e22a014,5d9cf3af,9b44e005,cd1d36ce,d7c420f5,e2db918b,e4fbf83a),+S(424b149d,9104254e,3f5772b3,7d973cf2,a46bd110,89d8f850,7666f04d,382c972b,7272ad07,54c18fbd,66e2abb3,952c526,d8113d5b,166283a3,9ac8ecb6,2b7a3e46),+S(40b4b2ac,bd299270,e64bc470,8607c586,3bb50913,45e573f3,a5e2461b,47dbc053,d094311e,fd81bb1f,4622d17e,68044107,a2a8ed54,3cd5ff8c,b531b28b,9b8ec99e),+S(79e79ded,6bc0d851,fa769b5e,8d65857c,f3c1c18e,6c990cb6,116fc45b,63e9f924,4fa89e89,ae4214fc,ba2aecdb,41984788,8154eaa6,bcbbe29f,f04a6262,7299f469),+S(a11ad5ea,59c644b2,8dd7402a,5f96a970,68d96e2e,eb77d59a,fe0c2fc,cc6b252f,38e379d5,150109df,36ed7ad3,a2daa41b,4fb9c731,718cf5e3,8f8f8cf7,d1f3d770),+S(b3002b00,ec5be154,cd8e5226,4b97f5c9,f444b305,8f59c4c,bcda5edf,9d10dc88,f7e9ae65,6ad2c823,8e8e0436,e007d821,b17d9405,984eccc4,617e3977,2f25d636),+S(8d1267b1,94da1334,fd20cb8f,77fa01cf,9e9ced90,43107e41,d1ec4057,eb6115a2,a7ba1b9e,2c6f0f19,5ff1f50a,7a8da22f,da3003fa,44b818b9,953b44d3,e6d6a0df),+S(dde6a3a0,87ef41db,2359e4e7,ca7cb064,424301e7,c5cbb5bc,4b6e504a,f3af4837,24175b1c,b4b39b7e,23718e26,be4a22bb,8bf54302,1f156234,e7f18010,d538aeb),+S(79efa584,2fb89f4e,85f556e,c4be170d,5c1ef88a,3f3f75cf,6b20fc1a,96984ad,b0704aaf,e4d8f30f,4f29fa85,6d55da13,91f5f3ce,36cdef6f,25133999,cc8541a),+S(3aa09dc0,5546977f,7369fa0a,7b60c94b,eab86a1,10d85af7,7b826475,7d67eaf5,343b4cf3,aa6c5ebc,ed041d7f,2381be57,f7fd32d0,29a2f42,a7c8821,4f425d8),+S(53fe8af9,8f9419fb,1445bb6a,94750d46,46be9f37,b7155763,88b11064,df2e6ffa,6cd77e81,84aeab9d,e9bf3093,bb9b21a3,a04a0719,fc428f3d,d5e14c8c,9b16cd7a),+S(fc395dc4,a5114dc8,bcb0f7f0,3a4d3e9,38a87a3d,78d33864,d1dc4cba,9e41e20e,c7991f6e,f72f82f6,b3147e56,74224929,fddeb8a5,97a1b1d4,8852733c,1830b941),+S(b1d25d51,b4558f5f,d0ccb868,3af9a9cf,62a169c6,91627fa5,92d80b18,36695f94,8f92258d,fcf16f4e,8415f53,e65457e8,9f090e72,5479c123,5a481464,a11cd4f9),+S(b866d6b1,42df940f,2cf28b54,c92f0c12,94e0b6a2,2a91f2ef,44bcd88c,4384480d,e6eb4f4c,bd95148f,765d8728,15652853,db1add7f,b4e27929,f19a64b7,f3b34c87)},+{S(d4aaf32e,dd897f48,5ab16466,76d747cd,fec5b7a0,a05c917b,60c07311,45d16f89,4857e649,beff4089,2470f700,cadb73ae,d4866a84,c3f0b975,6fd8570e,df9d29d8),+S(4ebe5b8a,f3b1583c,9f41bd98,afaba549,f45c381e,c93ec9d1,4a543d87,9cefbaf3,63ed1d17,9b215f34,f1f580be,4b3f671f,2fa14689,74cd03d1,19fadae3,c92935ff),+S(20df6160,556dd3c5,a26620a8,70ff5323,cbbab94,be3e3bdd,ad8b936c,554f28f1,7168e7ab,cdbafad,26fbb5be,a09dadde,ed36c20f,c8deafaf,75a480b5,f980e981),+S(86c663f2,cc6f7ee2,50be25fd,fb35fd8e,5873481b,c477bf5b,c0f1bc1e,3f1320f,c13c5795,cce0ad92,e31240da,90a823d0,d2352314,f2852e67,cb62e0c2,8570994a),+S(3fd8085e,57f6870,b25e41d9,7df00126,150f6022,a7ede22f,d27da581,d234ccaa,c6657746,98d6ac03,ed1ea2d7,bd3f70be,86351c5d,407a4d7c,227fd7d0,c330ef04),+S(1510fcf0,b0fb5a23,c15e041,2a7f6d89,9fac4244,8ce316bf,d88fb58b,10e23118,1879dc07,b34d0a62,f0b9517f,3629ae0f,e8aa6d30,5a783f37,69bdf65,3b40408e),+S(67e9982b,c40f427,98df055c,2d8bdcc0,2ea97bad,68d34024,85498e27,d99e19e4,4f087caa,efc5fd7f,b099c134,a273635c,d1d5ace3,26e3103f,9b2fe22c,e95f288e),+S(e8eeab21,6c3395d6,d16338ea,de4108da,1c25e471,67fb13d5,99e8daaf,93e7345f,7fd2ba87,7c7266a5,65a31548,99950ea1,e5e3d73f,612addea,318ad5bc,a965228d),+S(ab20c7c8,9dd74c20,447bc762,e374c548,e7a8ac31,eec11123,1a040cd1,36e9a546,facacfb2,52eb9532,9106a26a,60128a0f,ae1d7e5c,fd39483c,aeb54dd9,231b55ee),+S(a9004211,b7cf5494,1c530a0e,d658fb6e,3b5d2ee1,37b7d7de,45fef6b5,efddbf0f,58cbaf67,5cc5a131,54eef7a1,462b5d1c,408d5d56,3553ca55,45388d77,c6391d4f),+S(8db64274,422ae0f5,6474b83a,89912fa,e3a39b6c,b3fb8370,308a572e,b6b3c020,9b71a72d,431fd44,aa8632ee,23bc678,61d96edd,b7ec72ab,4b1679b8,a4ba73e4),+S(301b330,c478189d,dce4314f,380cb2d8,38bbd416,5dfad8c4,90f2443f,2a56148b,737da0,1c05cf73,db36a1a4,5005f562,1327167f,d3b60ece,3da3705d,131903fe),+S(b9cbc7a3,4a1cbdd1,300e789d,b7ffec1c,dfe1f738,fbe1fe19,67dd7c14,92ee3ba7,5a816a0,9d08c4be,2b8d062f,200fde4c,534fbdbf,854c7e53,64532c08,60c97c01),+S(6a15e51,6f9f0a7c,25f2eac7,649285ea,d86a1e01,5a386dc,c7f94ba8,4782b45b,63eafaf4,660642ef,988aeee7,642e7c4b,71124a1c,2ca2f5c3,d4f2eec9,ea72d70e),+S(f4c696f3,34c56e08,2ab2e627,4d450f34,fa7fbce,29f3e14d,332bcadf,87d5fe0d,6ee44edf,f574d9a8,363f98b6,b863a648,27d3020,1e652935,be12041c,1bbcc7c3),+S(d2f3d5ad,237ba177,ed312bbb,1d02fb2a,e4bda20f,41f5c217,8b70dd9a,c26ee9b0,cc5912d4,2ea1af01,aa914b98,8c42cef8,46a5a059,664c8545,fc00b662,e0327920),+S(5588b0a4,757beb33,e668af5f,adf87fb3,2aed8e16,e6ceabf1,1576ae17,c6a2b843,70d8961b,ac203e89,c437b88b,ce331309,c4f7eca8,d614299c,74aef9b2,17c741de),+S(f993cd07,f6eb75ad,d41426d5,cc653886,18dde1f0,88aaf3cd,b2631eea,158373e0,1e74f804,5f60349e,a85b90e1,206f0ea4,b0cd3740,861186be,648063e8,58c2b395),+S(2cd04170,78291a50,750218b9,44a11a64,1cb75e7d,cd5cc4f9,64f53c8d,a1ef08f4,1f54a70f,f66ce343,c7ed3001,78d7b99e,49129e23,90b5a026,7ba25af5,3467b6d3),+S(52fc09a1,d4f0cc2e,c7ba6cba,1b30e1f0,b9e37f31,3bf59c33,60fc02e3,3b0c15e8,9bd14bcd,a7c7b6ab,dd7e17dd,ab81a1cf,846be336,a76858a1,8e8a0194,776f0a80),+S(90d29aba,764a9b49,1e2878c2,9b964bf6,e510af,3dd5aeb9,3fe29e13,b8f03b23,396b1f6d,e9b8fd1f,463ca064,11b09823,26cb6ab7,4bbbcaef,43031497,f149a620),+S(ce1d6e8e,ddd063f4,316cb006,b4a4213d,9e0952c8,43e6e1e7,570a35e,aad7fa53,a1abcd7,e2c23ad0,895c5aa8,82a805cd,1d7d434c,72f0c528,2ceec0b7,a7016f7c),+S(4df6e1d3,93a4be66,6fd88c75,e1e686a1,e2cb1844,f5f1303e,f7b0a751,99b42bf5,262d8b9,f7e202a3,78a51928,91ee3fc9,f269ef5d,e14dd0ff,f1fec9f4,4cdb9058),+S(f71b9bfa,bcc353a4,11a055eb,a7d6f48f,47c4e437,96382bcc,d5b882cd,a9059638,bfc1c3f8,fea7df8b,d1cd088c,b1f02e47,377d6656,9b3bd8a2,8b457ba5,e6453468),+S(ad5e9212,d3ef76d,8319fd98,72ee753f,ec99fab0,6244f4e2,a9567068,a635eb53,65fb538f,cb570092,7b0f775a,73ffb0c1,4e6c2274,e253f3a6,2dba9caa,27a3e5e4),+S(81a7dfa0,7659fdbd,57e1c8ae,20c14a80,ee8bfc51,46caa8db,b077b653,23bad4a,ac9d2438,3ef0d99f,26744be4,77e69d51,49d44ab9,84801bb,759d3a5b,7fed1e2e),+S(3bf8c1d0,a613316b,e90eab62,6788c8c3,b1641d65,d0e50245,9e5b19c1,ab1eb617,e1edb59a,8594d73,669e6f93,ca10e210,1254946b,8c9e8eac,3fa84a49,e4e2944f),+S(30f9283a,767c551c,e9fe87d9,5730eff6,fc302a4a,1810e4de,11ba62af,fa17eaae,1f383ac5,e714240d,67980617,d96b0c05,76008599,f8e3fa04,d57454e9,927e729b),+S(1c5d4ac6,91d37d0c,9db5e071,c809a59e,99056263,fbd83028,ee9530e9,c2b3f3c9,b98c7be9,7a2fb196,3d3d4a75,4f7fecce,2fbeb8fd,cf23c229,73b6875,86bd276a),+S(3dfe48e5,2f055be1,1db79fa4,501b44d8,f5ae8447,c5a1293a,a79f683f,1e1e9bf,2d7e8303,b988fc17,18c9b64c,1c03373d,27fd0c32,13c26e6c,b684ca94,49f79d5e),+S(adc4251b,c3ef6d5a,a4d6eb22,46ab2787,bc835b65,1d17ceae,489f181d,57d37248,4f0c489d,1c3a1814,a2f9c1c9,d6fe908f,4623aa44,ebaf4143,79fb8352,15234014),+S(edfe16b2,db401803,11f98920,7a2fef7,d05b2a3b,b676899f,9c6e2192,d38f93e0,1196fd0e,35a24c9,6b28b055,b4fa2f2d,a4c2aeff,3b91dd81,c2fe86c1,1d6bf682)},+{S(b4b57b34,6e1b41b,7394e655,e059cc93,44c5d83e,f0ef17db,2789db5d,13777b78,6fa187a7,4d983b7e,cea6a268,61039430,63e599e7,cba73144,fe3eb23,677c6265),+S(9937238,7300054a,1a8713b7,6942f003,99818b28,6c6fba5d,ca60b9da,1aa7767,6c003e1,848ce30a,65601eb,e7b76acf,b2e122b6,882d7439,f463c042,ef1b31a),+S(ebd177f8,b5757665,58851c7f,a7ada38b,e3596080,f2679181,f994efd3,82714784,d0fe8eb0,97c852f7,b284d5f,bd81f77f,79c35af7,cc30338f,4e63211e,9e20a244),+S(367ef258,b279f923,a18215b7,67d396e4,c6bc874d,2be6b369,b01afffa,2e041741,bd961242,2452eddb,33831dcf,fb3a0273,30ef141f,6db77d91,5bec2ecb,553b6e6c),+S(d89f40c4,f752cff4,5bae5762,37f5096e,f27d46d0,d934d4de,c3011a28,59464e8e,9d32661e,e2319d6,f6427ea,a3014b5,cf98306c,666c4a9e,970dba2e,65e04886),+S(ef6ff862,1d84c5d5,22e490f4,db21181f,a17bafea,3e097868,4f1f0215,759772b9,ae006f11,aa85db2d,3624cf51,ae319ad2,8b4970e7,eac03301,1eb15db8,dc59d62b),+S(8b0a1b1b,d476bbfb,6da1d071,68d3a988,3b49802f,8ffa04a3,bbba1313,17c67a00,d8c74ae5,65c38597,8d9fda2e,dff6b932,1512e40b,ec5b62e2,59d4d81c,9b657b55),+S(9aa9250f,12ffde38,21384434,849d7eb7,bcafbae5,9a3b861f,68a3addb,d75d3715,19b4b1a8,8d8bfeee,38b54564,30d5f73e,ed0365fe,49092d4a,2f52fa12,b65e3ac7),+S(aaccc00f,55e96f0c,e66d9b43,12f9abd2,6772d8b4,30a6c62,edd2aab4,97acbc22,5af203cf,97d11147,82374056,f012f5f9,2825476a,820dce2e,6e1c4b33,cef5337c),+S(43c34546,2836b544,ddd6e432,6aa19b4a,9de7fdfb,86f43cae,ce98ce7c,32b1ccaf,dd518249,f1fbc1c7,1f905860,17a6f60b,15be97d4,18c66d42,f4f9adcd,d722c096),+S(9a38eb25,935441ab,8983097a,d58c821f,d784f091,5f85dc26,3f0c020b,b80c39a0,d8e6dc57,41e4ba5c,576179e8,9a6dcb4a,bd7178c6,13a1100b,e2bd731b,f3e819e2),+S(6b10527,204a4f7c,e8afcacc,fe771634,376f18da,f12774e,50f23a90,9efe0223,b443a451,529b4208,c8c98904,f5eb2ee,2e2ede2d,80ca50c5,aa29b95a,714181a),+S(1a88fecc,71d7550a,abf7faf0,8e884e95,835f6dc8,1815d2d7,7dab66ea,b238d6b2,82cf6711,1dd38ff,d0daebbc,ea2c064b,17b6b21d,34804f93,4a037936,9edec692),+S(a6b1751,f30507fe,5927b6d4,a92ebbbd,77358c02,9b750d05,a56e4d41,efb99144,ccf7c048,a2a0983d,fdcccfd,a071b80,e8035866,c479ea3a,3bbe7c80,12dfd618),+S(e186601e,8b545292,f23ae7fa,4cadc80f,1fcaa1a3,430ddec6,cfd2af47,c835cdf9,fd471f16,7c3683c9,2e5fc0c2,89b646a5,c8ebda6d,5b6da213,d862c3f6,2c292e9c),+S(91b3935,d8ce2b80,c179ee0b,87850140,4c418c7f,7cf94e4a,64b9fc9c,e396a093,45a5043b,8184546c,9083982f,550807d7,d61fe677,ce73ef21,9b3aa573,97c4eca1),+S(3fbe61fd,2a387654,dfc428e7,dac09e91,5e1ae7d6,d3794288,743f2535,20858ef5,206fd9a0,e3265118,e0a6475c,4df87e43,cc7c8898,59d8aa08,23b6dfff,b68b34d7),+S(31a35020,697d9d52,55476289,ce4fcbdc,4e1e0690,c2c36d1b,a4f4640f,e4c5ba18,91f660f9,159d463a,857f08ad,fc3c5ddd,804507c5,92f73de4,2ee44555,da538553),+S(7dc6b83a,10f26e71,e12c0bd,7ebcccc6,61b4394a,68f576fe,bfca1c23,256e8aa2,b4796977,bd386b98,f3e2fa8e,798b6548,fae52a80,40bb12ea,7e6ad675,64fc8736),+S(67a9c3ff,9c7b99b2,5318ff9e,2b85ee23,ec244655,8042ea8b,d880e23e,7d3ce221,a7bcbbbb,895ca7b1,847a43fa,98809ce4,98016123,bbb3c099,7d34debd,cb023f8d),+S(36602997,eba2c6c5,aab4cb65,8d4efd46,65ab3965,f643ff66,831646dc,f6443bf3,c82d0e80,ef775f9c,7ec7862a,e3158556,a57038d,e6850dd1,e349629c,2546239),+S(9eb9244b,299bfd76,f63bb140,ae2f42a1,4af1e072,83f8259f,6478ac03,d411df24,e43f91da,13c2ba21,a9d17d2f,7a8a629d,9051346,93a6552a,538d590,9d2bdd38),+S(ba4450fa,27d57993,3d949a1a,66013906,7d1a9716,6794993d,e45d9426,b4bfc5ed,8e3f3b9b,d8cb8210,7a5ae2af,92b96259,b73633f,6528ac04,20c3e101,6bb6d8a8),+S(e6d5335f,b67abd36,2712c7fe,575ee769,53d488b,236e8589,5664fb04,7f385248,9e255154,e070a5bb,e98e97f6,281fb999,a75e68ea,7681fdf6,fea093bd,919aa5a4),+S(63c099a9,300a331a,3bc4348a,a373e514,c84a810e,1ea8a8d1,4ac8d7cb,818eb534,ed7d4029,3cc4a086,b1d40c24,6086109,a02dbcb5,a864777,27939024,6fd6bf91),+S(7088617f,66cd93f,8130eaeb,874c3f77,3bcb0daa,78923b70,a65512a2,992554dc,5a3ff995,3c712066,291ac4a2,dfc2573e,1d0aed56,75ef526b,b15f61b0,d20f8156),+S(cc354aaf,746d756b,9387730f,2f12b999,4fcd815c,6d25cdab,2e1185aa,4aa639b3,fb1dead9,4fd76859,1aac8d79,5c337924,dc155fbe,5cd5c953,4d55ee31,f6d284a6),+S(e7e47c3a,e2bf4307,7f33ec3d,ac1ae2a7,5c669e61,e248f588,590cfe07,3e2186e0,46e9c4d5,4429fdcf,5efb375e,18f46cc8,3fa7a403,6013777f,e450e228,aebd4cd0),+S(c6ed5e63,28ec31b1,37041108,42d4ac23,fbb883bb,349d88db,1d747cf7,325fe9cc,21b8bfa4,b62807cf,d6cd11ed,a38084d5,7bb068d4,9f0dd30e,f3f431e2,b57022e4),+S(331924c7,50b3417e,48e279ff,6ed7f3dc,ba2e121e,9f69f8fb,e64093b6,c38a8cc6,357086be,e4cc0fe7,d45a49fe,41d004ce,80466165,316164ab,3b171f03,b9a7841f),+S(b4319cc9,f3e0d3b,313626ae,5385796b,c49b300c,88ba4553,dec0aa4a,77829372,b8f82bb6,6590afd4,48501f,63de3a5d,8f84edea,35c1ee44,88d6333e,f522a808),+S(da433d5e,11ceccc0,abc5c762,6ce7bab4,2e89b221,f785c409,282de545,f3fceb19,1b67242c,de57efcf,e214423b,506a1ade,718803d2,6dd84d88,97b18ede,590a2fcb)},+{S(ebae7464,ece277b8,309d056c,cf3775e2,11a77aa,81c316a4,b6b7b953,6f90f539,62a4d6a2,95fdd811,f2051715,322f17e5,1753c9d0,835ef9a0,3e8dc9f5,c69bda31),+S(5b20700c,1af63394,a3e4cadb,b0ea682e,19cf495a,b908418a,d41f4c6c,ea4477f0,8435d15e,34b03a22,ca89c73d,326c2f88,142d2e23,8964ef6d,99287125,79738f78),+S(b2f25f91,138b974b,561328c0,92f50fdf,8a694004,fd4879d0,12a4a6cc,c8059d1d,d9ec0b2d,b8e81b2,f6feaf55,9776ff78,cda3401b,47826de0,ca06e579,9d866c09),+S(64e79790,7783d6fb,321eb785,acdeb2ff,4628270,fec3342c,527c8db0,a34c516e,c0c4da5d,abf3da9c,a8613f82,ca28e84,a1a18376,c9967c08,aaf70bea,7a2f34c2),+S(a50cae84,a08f4f32,4984853a,d4c6bdaf,77eaa788,9cb8fe95,72fd56e,9078ee73,120ecbf,76e47b38,503067c8,36853003,60ed261a,40fdf440,161ef2cd,19786b93),+S(76ff3ac8,80a451a9,6741fc70,82bc4c82,7bd51c08,95eea8c8,b422b8a9,96ba4794,25555d71,d4313a60,b189a154,58e0a40,c643c204,277334e,966e2abd,3a23f6c3),+S(307e5caa,8b708760,3d9f845b,b78f4f10,72c49c10,9747f91d,192f8d6e,70c0f4be,f5992f76,37167e1d,55cd31a6,1cdb4756,85eb1503,34fb6009,e0240a18,fa8302b8),+S(d8e62e47,b28fd165,4d420137,884dcf21,c10cb159,d9885843,da34b0d9,d09b2758,675c75b4,b903ad28,2055a71b,2c470e2b,1dce69bf,ecf160cf,3a027de2,55b723a9),+S(ec5639c7,73dac23d,3008dabf,732dc005,3154703d,26ee3bbc,7689286e,4a73e39f,aaa5ea4a,2cf5c23d,57cdd0d8,8accbbf9,9fd2c213,97bb45f8,83547876,3aab1248),+S(3d928ee3,2065557a,27722f08,5202f48f,40917ed6,c7ac1963,2a122226,8b0cb9df,ece112a4,e7a05ad6,17c2fd83,76f89102,9eb94eb0,930fb23c,a342d7f1,f021a0c7),+S(616228a5,cc6c3a92,cd694cec,4b2b8574,5dfffa90,b2a36d8f,32eaa6cc,2530de51,50d8d140,4d506a78,700f8e82,967b36a5,1b4de644,a8e22271,d509c8d2,4adf3148),+S(6f85f308,e847b145,c13a07be,bebdd4ba,6c138939,6afd8670,733f44a8,969406d0,864bcde1,be36c9c7,b7e04ef8,cd2366e2,b3c22902,5ee7efce,d005ef5b,ff7dae2b),+S(f3d1ecc3,53a82621,1bd78f0f,aa029076,c6ca779,9bdc54b2,128fa3d2,aec00c6d,75aa0cf9,fd0b7bed,19183e34,58142f66,c94a5aa9,3915435e,ae51c1fe,96625ccd),+S(a5918de3,f18cd8d1,2a234f9f,3a19fcaa,2d83671d,ad566f16,8aea2b1f,b9de41b0,c515dda6,43c0f6c8,d8fea16,5d595917,16b7f521,43d3b941,f28585ed,8a49c06c),+S(3c49e2ef,1d2d3464,81e05fa0,33366609,1615ebcf,535f68,be257f35,7bd91592,57901e0a,c8af3a31,aa404987,72c903fd,175c9b00,5c7458ee,ed667f11,57754132),+S(6c45ff2,c0c30320,83c343e6,dc80b4f7,bb64502a,52f412ff,ada521d4,a544a9f0,e9936037,f1e641eb,1cd6f801,a25271d3,cffe67d,c9bd7162,babf9855,9628a9a8),+S(66df5d95,acdf4260,ee0e465c,e3916d79,395df522,aa086aeb,6c283bb7,18296d46,cb1f3deb,8aea0337,625f46dd,903416d1,5647be91,1633c4c0,cf0e629a,413476fc),+S(428bbba5,ef351762,9eee4059,a3339213,40c7fee2,5ccb051c,88d75e53,ba618858,ef18809c,28227ccc,115876df,b3f378cd,374c0670,2c658501,7990e767,922c3999),+S(e8993820,d782657,ed8badc2,d515e360,df336730,860ef49e,65ca58dd,1a385815,feb41189,16c7e8f6,53c7f5a6,5fd7b6be,7a029814,149c4645,847073be,770959de),+S(2b77e42a,63502244,d6c7d1be,54b7857,9e2742d2,7143d689,fa3f70a3,5986ccf1,721e9da8,bee88ad4,2155dc9a,28be505,86648378,1d6af5b1,382cd47d,771e6428),+S(acffce3a,ed6beea3,2ad71633,21e1ca53,6f69ce76,fb5cd394,9d9dcc14,bbcee96,5384c97d,eac946c0,afc85b54,f3a56b79,fe263bff,63e1894c,6d52ef1b,9b456602),+S(e13d8d4b,25bece8d,90a008e4,c004824e,223b06b,7cf65ebd,1215e910,2e67b639,3e92b1f,14cbee57,9640b377,6ed5938f,9aee0e11,b139a678,3f207cf4,6dd7e20b),+S(d8f356d9,d2498eaa,b3fa12a,cb64562b,dff3e270,c7809a31,25a9ae65,9cb1f3c5,a5403cda,2d499a7c,7402b57c,c9f99e3,64f5085a,91fd8cfd,8a67c7a8,dbce04fb),+S(350062b5,22fb5d0a,8c79a5db,29e92216,79b9fbc6,3e1f95ca,e7d087f3,fedffc49,74cacf57,5e79c85b,d7e77a40,796e8750,a3ca57f2,a47cce8f,3d2de02d,b014df0b),+S(c159e630,9ab23135,58ebfb6b,22edaf93,eac8e16,77cd9f3b,1cd9492,20bf8e54,99244263,53f32608,831c6d74,da51d61,c344defe,f4c1e401,6a3db44b,4c57f4ae),+S(9e568b70,36a2daa2,fe7a3a52,49c56eb8,3fe4afa2,decebd60,c6c3245f,17bc6a13,b6643644,274eab9f,5e83c598,14978681,17c5a078,765156ae,3cb65fd3,830e06ae),+S(9bee7471,6b6c1ff5,62c1bc36,57a65de3,99a91d72,115703f4,4c3819a1,87828478,bb23a3da,ed34028a,7d39a7ed,fe2e23b,73e085a2,d6c2e51a,ef2a2076,a7c902ad),+S(c430c044,91228a7a,ea835698,ecf0f552,9aeef469,a36305cb,52902ccd,1c897473,40d0ee56,61cca82,80d11da,bffe97c4,f10c93aa,5e07224c,154b666e,bcd58c74),+S(2be073f6,b294a01b,eda0b0db,6832e4bc,23ef3889,7a859853,5ee726ef,ae0f15b1,6153f846,349c2a98,26008065,8be2a7d8,311a5e70,cc310ff8,7935a901,8d575813),+S(2934de46,a6d921f8,720567e6,b46e6362,36a7ed53,483b13ed,20958452,3225accd,5979698,26927cd7,abfe4c57,c53fc72a,48b71679,174c749d,aecdb057,e6a2d961),+S(4e9991b,92fa8c4e,4e8efe45,66966073,319e80d3,a54d4b7a,b61cfcc4,7ddaa5d5,9d03ea22,21d4d80e,261952e2,73f6a8cf,c31f6091,e5aa0a8f,2281ffbf,1345df9e),+S(ff3d6136,ffac5b0c,bfc6c5c0,c30dc01a,7ea3d56c,20bd3103,b178e3d3,ae180068,eccdc641,7b1bfff1,bf2fc8d3,2269523e,ab89890d,bffe0a19,8f594490,e7739bb8)}+#else+#    error Configuration mismatch, invalid COMB_* parameters. Try deleting precomputed_ecmult_gen.c before the build.+#endif+};+#undef S
+ vendor/external/secp256k1/src/precomputed_ecmult_gen.h view
@@ -0,0 +1,26 @@+/*********************************************************************************+ * Copyright (c) 2013, 2014, 2015, 2021 Thomas Daede, Cory Fields, Pieter Wuille *+ * Distributed under the MIT software license, see the accompanying              *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.          *+ *********************************************************************************/++#ifndef SECP256K1_PRECOMPUTED_ECMULT_GEN_H+#define SECP256K1_PRECOMPUTED_ECMULT_GEN_H++#ifdef __cplusplus+extern "C" {+#endif++#include "group.h"+#include "ecmult_gen.h"+#ifdef EXHAUSTIVE_TEST_ORDER+static secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS];+#else+extern const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS];+#endif /* defined(EXHAUSTIVE_TEST_ORDER) */++#ifdef __cplusplus+}+#endif++#endif /* SECP256K1_PRECOMPUTED_ECMULT_GEN_H */
+ vendor/external/secp256k1/src/scalar.h view
@@ -0,0 +1,105 @@+/***********************************************************************+ * Copyright (c) 2014 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_SCALAR_H+#define SECP256K1_SCALAR_H++#include "util.h"++#if defined(EXHAUSTIVE_TEST_ORDER)+#include "scalar_low.h"+#elif defined(SECP256K1_WIDEMUL_INT128)+#include "scalar_4x64.h"+#elif defined(SECP256K1_WIDEMUL_INT64)+#include "scalar_8x32.h"+#else+#error "Please select wide multiplication implementation"+#endif++/** Clear a scalar to prevent the leak of sensitive data. */+static void secp256k1_scalar_clear(secp256k1_scalar *r);++/** Access bits (1 < count <= 32) from a scalar. All requested bits must belong to the same 32-bit limb. */+static uint32_t secp256k1_scalar_get_bits_limb32(const secp256k1_scalar *a, unsigned int offset, unsigned int count);++/** Access bits (1 < count <= 32) from a scalar. offset + count must be < 256. Not constant time in offset and count. */+static uint32_t secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count);++/** Set a scalar from a big endian byte array. The scalar will be reduced modulo group order `n`.+ * In:      bin:        pointer to a 32-byte array.+ * Out:     r:          scalar to be set.+ *          overflow:   non-zero if the scalar was bigger or equal to `n` before reduction, zero otherwise (can be NULL).+ */+static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow);++/** Set a scalar from a big endian byte array and returns 1 if it is a valid+ *  seckey and 0 otherwise. */+static int secp256k1_scalar_set_b32_seckey(secp256k1_scalar *r, const unsigned char *bin);++/** Set a scalar to an unsigned integer. */+static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v);++/** Convert a scalar to a byte array. */+static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar* a);++/** Add two scalars together (modulo the group order). Returns whether it overflowed. */+static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b);++/** Conditionally add a power of two to a scalar. The result is not allowed to overflow. */+static void secp256k1_scalar_cadd_bit(secp256k1_scalar *r, unsigned int bit, int flag);++/** Multiply two scalars (modulo the group order). */+static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b);++/** Compute the inverse of a scalar (modulo the group order). */+static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *a);++/** Compute the inverse of a scalar (modulo the group order), without constant-time guarantee. */+static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_scalar *a);++/** Compute the complement of a scalar (modulo the group order). */+static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a);++/** Multiply a scalar with the multiplicative inverse of 2. */+static void secp256k1_scalar_half(secp256k1_scalar *r, const secp256k1_scalar *a);++/** Check whether a scalar equals zero. */+static int secp256k1_scalar_is_zero(const secp256k1_scalar *a);++/** Check whether a scalar equals one. */+static int secp256k1_scalar_is_one(const secp256k1_scalar *a);++/** Check whether a scalar, considered as an nonnegative integer, is even. */+static int secp256k1_scalar_is_even(const secp256k1_scalar *a);++/** Check whether a scalar is higher than the group order divided by 2. */+static int secp256k1_scalar_is_high(const secp256k1_scalar *a);++/** Conditionally negate a number, in constant time.+ * Returns -1 if the number was negated, 1 otherwise */+static int secp256k1_scalar_cond_negate(secp256k1_scalar *a, int flag);++/** Compare two scalars. */+static int secp256k1_scalar_eq(const secp256k1_scalar *a, const secp256k1_scalar *b);++/** Find r1 and r2 such that r1+r2*2^128 = k. */+static void secp256k1_scalar_split_128(secp256k1_scalar *r1, secp256k1_scalar *r2, const secp256k1_scalar *k);+/** Find r1 and r2 such that r1+r2*lambda = k, where r1 and r2 or their+ *  negations are maximum 128 bits long (see secp256k1_ge_mul_lambda). It is+ *  required that r1, r2, and k all point to different objects. */+static void secp256k1_scalar_split_lambda(secp256k1_scalar * SECP256K1_RESTRICT r1, secp256k1_scalar * SECP256K1_RESTRICT r2, const secp256k1_scalar * SECP256K1_RESTRICT k);++/** Multiply a and b (without taking the modulus!), divide by 2**shift, and round to the nearest integer. Shift must be at least 256. */+static void secp256k1_scalar_mul_shift_var(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b, unsigned int shift);++/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time.  Both *r and *a must be initialized.*/+static void secp256k1_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag);++/** Check invariants on a scalar (no-op unless VERIFY is enabled). */+static void secp256k1_scalar_verify(const secp256k1_scalar *r);+#define SECP256K1_SCALAR_VERIFY(r) secp256k1_scalar_verify(r)++#endif /* SECP256K1_SCALAR_H */
+ vendor/external/secp256k1/src/scalar_4x64.h view
@@ -0,0 +1,19 @@+/***********************************************************************+ * Copyright (c) 2014 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_SCALAR_REPR_H+#define SECP256K1_SCALAR_REPR_H++#include <stdint.h>++/** A scalar modulo the group order of the secp256k1 curve. */+typedef struct {+    uint64_t d[4];+} secp256k1_scalar;++#define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}}++#endif /* SECP256K1_SCALAR_REPR_H */
+ vendor/external/secp256k1/src/scalar_4x64_impl.h view
@@ -0,0 +1,1000 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_SCALAR_REPR_IMPL_H+#define SECP256K1_SCALAR_REPR_IMPL_H++#include "checkmem.h"+#include "int128.h"+#include "modinv64_impl.h"+#include "util.h"++/* Limbs of the secp256k1 order. */+#define SECP256K1_N_0 ((uint64_t)0xBFD25E8CD0364141ULL)+#define SECP256K1_N_1 ((uint64_t)0xBAAEDCE6AF48A03BULL)+#define SECP256K1_N_2 ((uint64_t)0xFFFFFFFFFFFFFFFEULL)+#define SECP256K1_N_3 ((uint64_t)0xFFFFFFFFFFFFFFFFULL)++/* Limbs of 2^256 minus the secp256k1 order. */+#define SECP256K1_N_C_0 (~SECP256K1_N_0 + 1)+#define SECP256K1_N_C_1 (~SECP256K1_N_1)+#define SECP256K1_N_C_2 (1)++/* Limbs of half the secp256k1 order. */+#define SECP256K1_N_H_0 ((uint64_t)0xDFE92F46681B20A0ULL)+#define SECP256K1_N_H_1 ((uint64_t)0x5D576E7357A4501DULL)+#define SECP256K1_N_H_2 ((uint64_t)0xFFFFFFFFFFFFFFFFULL)+#define SECP256K1_N_H_3 ((uint64_t)0x7FFFFFFFFFFFFFFFULL)++SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) {+    r->d[0] = v;+    r->d[1] = 0;+    r->d[2] = 0;+    r->d[3] = 0;++    SECP256K1_SCALAR_VERIFY(r);+}++SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_limb32(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {+    SECP256K1_SCALAR_VERIFY(a);+    VERIFY_CHECK(count > 0 && count <= 32);+    VERIFY_CHECK((offset + count - 1) >> 6 == offset >> 6);++    return (a->d[offset >> 6] >> (offset & 0x3F)) & (0xFFFFFFFF >> (32 - count));+}++SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {+    SECP256K1_SCALAR_VERIFY(a);+    VERIFY_CHECK(count > 0 && count <= 32);+    VERIFY_CHECK(offset + count <= 256);++    if ((offset + count - 1) >> 6 == offset >> 6) {+        return secp256k1_scalar_get_bits_limb32(a, offset, count);+    } else {+        VERIFY_CHECK((offset >> 6) + 1 < 4);+        return ((a->d[offset >> 6] >> (offset & 0x3F)) | (a->d[(offset >> 6) + 1] << (64 - (offset & 0x3F)))) & (0xFFFFFFFF >> (32 - count));+    }+}++SECP256K1_INLINE static int secp256k1_scalar_check_overflow(const secp256k1_scalar *a) {+    int yes = 0;+    int no = 0;+    no |= (a->d[3] < SECP256K1_N_3); /* No need for a > check. */+    no |= (a->d[2] < SECP256K1_N_2);+    yes |= (a->d[2] > SECP256K1_N_2) & ~no;+    no |= (a->d[1] < SECP256K1_N_1);+    yes |= (a->d[1] > SECP256K1_N_1) & ~no;+    yes |= (a->d[0] >= SECP256K1_N_0) & ~no;+    return yes;+}++SECP256K1_INLINE static int secp256k1_scalar_reduce(secp256k1_scalar *r, unsigned int overflow) {+    secp256k1_uint128 t;+    VERIFY_CHECK(overflow <= 1);++    secp256k1_u128_from_u64(&t, r->d[0]);+    secp256k1_u128_accum_u64(&t, overflow * SECP256K1_N_C_0);+    r->d[0] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, r->d[1]);+    secp256k1_u128_accum_u64(&t, overflow * SECP256K1_N_C_1);+    r->d[1] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, r->d[2]);+    secp256k1_u128_accum_u64(&t, overflow * SECP256K1_N_C_2);+    r->d[2] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, r->d[3]);+    r->d[3] = secp256k1_u128_to_u64(&t);++    SECP256K1_SCALAR_VERIFY(r);+    return overflow;+}++static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b) {+    int overflow;+    secp256k1_uint128 t;+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_SCALAR_VERIFY(b);++    secp256k1_u128_from_u64(&t, a->d[0]);+    secp256k1_u128_accum_u64(&t, b->d[0]);+    r->d[0] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, a->d[1]);+    secp256k1_u128_accum_u64(&t, b->d[1]);+    r->d[1] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, a->d[2]);+    secp256k1_u128_accum_u64(&t, b->d[2]);+    r->d[2] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, a->d[3]);+    secp256k1_u128_accum_u64(&t, b->d[3]);+    r->d[3] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    overflow = secp256k1_u128_to_u64(&t) + secp256k1_scalar_check_overflow(r);+    VERIFY_CHECK(overflow == 0 || overflow == 1);+    secp256k1_scalar_reduce(r, overflow);++    SECP256K1_SCALAR_VERIFY(r);+    return overflow;+}++static void secp256k1_scalar_cadd_bit(secp256k1_scalar *r, unsigned int bit, int flag) {+    secp256k1_uint128 t;+    volatile int vflag = flag;+    SECP256K1_SCALAR_VERIFY(r);+    VERIFY_CHECK(bit < 256);++    bit += ((uint32_t) vflag - 1) & 0x100;  /* forcing (bit >> 6) > 3 makes this a noop */+    secp256k1_u128_from_u64(&t, r->d[0]);+    secp256k1_u128_accum_u64(&t, ((uint64_t)((bit >> 6) == 0)) << (bit & 0x3F));+    r->d[0] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, r->d[1]);+    secp256k1_u128_accum_u64(&t, ((uint64_t)((bit >> 6) == 1)) << (bit & 0x3F));+    r->d[1] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, r->d[2]);+    secp256k1_u128_accum_u64(&t, ((uint64_t)((bit >> 6) == 2)) << (bit & 0x3F));+    r->d[2] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, r->d[3]);+    secp256k1_u128_accum_u64(&t, ((uint64_t)((bit >> 6) == 3)) << (bit & 0x3F));+    r->d[3] = secp256k1_u128_to_u64(&t);++    SECP256K1_SCALAR_VERIFY(r);+    VERIFY_CHECK(secp256k1_u128_hi_u64(&t) == 0);+}++static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *b32, int *overflow) {+    int over;+    r->d[0] = secp256k1_read_be64(&b32[24]);+    r->d[1] = secp256k1_read_be64(&b32[16]);+    r->d[2] = secp256k1_read_be64(&b32[8]);+    r->d[3] = secp256k1_read_be64(&b32[0]);+    over = secp256k1_scalar_reduce(r, secp256k1_scalar_check_overflow(r));+    if (overflow) {+        *overflow = over;+    }++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar* a) {+    SECP256K1_SCALAR_VERIFY(a);++    secp256k1_write_be64(&bin[0],  a->d[3]);+    secp256k1_write_be64(&bin[8],  a->d[2]);+    secp256k1_write_be64(&bin[16], a->d[1]);+    secp256k1_write_be64(&bin[24], a->d[0]);+}++SECP256K1_INLINE static int secp256k1_scalar_is_zero(const secp256k1_scalar *a) {+    SECP256K1_SCALAR_VERIFY(a);++    return (a->d[0] | a->d[1] | a->d[2] | a->d[3]) == 0;+}++static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a) {+    uint64_t nonzero = 0xFFFFFFFFFFFFFFFFULL * (secp256k1_scalar_is_zero(a) == 0);+    secp256k1_uint128 t;+    SECP256K1_SCALAR_VERIFY(a);++    secp256k1_u128_from_u64(&t, ~a->d[0]);+    secp256k1_u128_accum_u64(&t, SECP256K1_N_0 + 1);+    r->d[0] = secp256k1_u128_to_u64(&t) & nonzero; secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, ~a->d[1]);+    secp256k1_u128_accum_u64(&t, SECP256K1_N_1);+    r->d[1] = secp256k1_u128_to_u64(&t) & nonzero; secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, ~a->d[2]);+    secp256k1_u128_accum_u64(&t, SECP256K1_N_2);+    r->d[2] = secp256k1_u128_to_u64(&t) & nonzero; secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, ~a->d[3]);+    secp256k1_u128_accum_u64(&t, SECP256K1_N_3);+    r->d[3] = secp256k1_u128_to_u64(&t) & nonzero;++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_half(secp256k1_scalar *r, const secp256k1_scalar *a) {+    /* Writing `/` for field division and `//` for integer division, we compute+     *+     *   a/2 = (a - (a&1))/2 + (a&1)/2+     *       = (a >> 1) + (a&1 ?    1/2 : 0)+     *       = (a >> 1) + (a&1 ? n//2+1 : 0),+     *+     * where n is the group order and in the last equality we have used 1/2 = n//2+1 (mod n).+     * For n//2, we have the constants SECP256K1_N_H_0, ...+     *+     * This sum does not overflow. The most extreme case is a = -2, the largest odd scalar. Here:+     * - the left summand is:  a >> 1 = (a - a&1)/2 = (n-2-1)//2           = (n-3)//2+     * - the right summand is: a&1 ? n//2+1 : 0 = n//2+1 = (n-1)//2 + 2//2 = (n+1)//2+     * Together they sum to (n-3)//2 + (n+1)//2 = (2n-2)//2 = n - 1, which is less than n.+     */+    uint64_t mask = -(uint64_t)(a->d[0] & 1U);+    secp256k1_uint128 t;+    SECP256K1_SCALAR_VERIFY(a);++    secp256k1_u128_from_u64(&t, (a->d[0] >> 1) | (a->d[1] << 63));+    secp256k1_u128_accum_u64(&t, (SECP256K1_N_H_0 + 1U) & mask);+    r->d[0] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, (a->d[1] >> 1) | (a->d[2] << 63));+    secp256k1_u128_accum_u64(&t, SECP256K1_N_H_1 & mask);+    r->d[1] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, (a->d[2] >> 1) | (a->d[3] << 63));+    secp256k1_u128_accum_u64(&t, SECP256K1_N_H_2 & mask);+    r->d[2] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64);+    r->d[3] = secp256k1_u128_to_u64(&t) + (a->d[3] >> 1) + (SECP256K1_N_H_3 & mask);+#ifdef VERIFY+    /* The line above only computed the bottom 64 bits of r->d[3]; redo the computation+     * in full 128 bits to make sure the top 64 bits are indeed zero. */+    secp256k1_u128_accum_u64(&t, a->d[3] >> 1);+    secp256k1_u128_accum_u64(&t, SECP256K1_N_H_3 & mask);+    secp256k1_u128_rshift(&t, 64);+    VERIFY_CHECK(secp256k1_u128_to_u64(&t) == 0);++    SECP256K1_SCALAR_VERIFY(r);+#endif+}++SECP256K1_INLINE static int secp256k1_scalar_is_one(const secp256k1_scalar *a) {+    SECP256K1_SCALAR_VERIFY(a);++    return ((a->d[0] ^ 1) | a->d[1] | a->d[2] | a->d[3]) == 0;+}++static int secp256k1_scalar_is_high(const secp256k1_scalar *a) {+    int yes = 0;+    int no = 0;+    SECP256K1_SCALAR_VERIFY(a);++    no |= (a->d[3] < SECP256K1_N_H_3);+    yes |= (a->d[3] > SECP256K1_N_H_3) & ~no;+    no |= (a->d[2] < SECP256K1_N_H_2) & ~yes; /* No need for a > check. */+    no |= (a->d[1] < SECP256K1_N_H_1) & ~yes;+    yes |= (a->d[1] > SECP256K1_N_H_1) & ~no;+    yes |= (a->d[0] > SECP256K1_N_H_0) & ~no;+    return yes;+}++static int secp256k1_scalar_cond_negate(secp256k1_scalar *r, int flag) {+    /* If we are flag = 0, mask = 00...00 and this is a no-op;+     * if we are flag = 1, mask = 11...11 and this is identical to secp256k1_scalar_negate */+    volatile int vflag = flag;+    uint64_t mask = -vflag;+    uint64_t nonzero = (secp256k1_scalar_is_zero(r) != 0) - 1;+    secp256k1_uint128 t;+    SECP256K1_SCALAR_VERIFY(r);++    secp256k1_u128_from_u64(&t, r->d[0] ^ mask);+    secp256k1_u128_accum_u64(&t, (SECP256K1_N_0 + 1) & mask);+    r->d[0] = secp256k1_u128_to_u64(&t) & nonzero; secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, r->d[1] ^ mask);+    secp256k1_u128_accum_u64(&t, SECP256K1_N_1 & mask);+    r->d[1] = secp256k1_u128_to_u64(&t) & nonzero; secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, r->d[2] ^ mask);+    secp256k1_u128_accum_u64(&t, SECP256K1_N_2 & mask);+    r->d[2] = secp256k1_u128_to_u64(&t) & nonzero; secp256k1_u128_rshift(&t, 64);+    secp256k1_u128_accum_u64(&t, r->d[3] ^ mask);+    secp256k1_u128_accum_u64(&t, SECP256K1_N_3 & mask);+    r->d[3] = secp256k1_u128_to_u64(&t) & nonzero;++    SECP256K1_SCALAR_VERIFY(r);+    return 2 * (mask == 0) - 1;+}++/* Inspired by the macros in OpenSSL's crypto/bn/asm/x86_64-gcc.c. */++/** Add a*b to the number defined by (c0,c1,c2). c2 must never overflow. */+#define muladd(a,b) { \+    uint64_t tl, th; \+    { \+        secp256k1_uint128 t; \+        secp256k1_u128_mul(&t, a, b); \+        th = secp256k1_u128_hi_u64(&t);  /* at most 0xFFFFFFFFFFFFFFFE */ \+        tl = secp256k1_u128_to_u64(&t); \+    } \+    c0 += tl;                 /* overflow is handled on the next line */ \+    th += (c0 < tl);          /* at most 0xFFFFFFFFFFFFFFFF */ \+    c1 += th;                 /* overflow is handled on the next line */ \+    c2 += (c1 < th);          /* never overflows by contract (verified in the next line) */ \+    VERIFY_CHECK((c1 >= th) || (c2 != 0)); \+}++/** Add a*b to the number defined by (c0,c1). c1 must never overflow. */+#define muladd_fast(a,b) { \+    uint64_t tl, th; \+    { \+        secp256k1_uint128 t; \+        secp256k1_u128_mul(&t, a, b); \+        th = secp256k1_u128_hi_u64(&t);  /* at most 0xFFFFFFFFFFFFFFFE */ \+        tl = secp256k1_u128_to_u64(&t); \+    } \+    c0 += tl;                 /* overflow is handled on the next line */ \+    th += (c0 < tl);          /* at most 0xFFFFFFFFFFFFFFFF */ \+    c1 += th;                 /* never overflows by contract (verified in the next line) */ \+    VERIFY_CHECK(c1 >= th); \+}++/** Add a to the number defined by (c0,c1,c2). c2 must never overflow. */+#define sumadd(a) { \+    unsigned int over; \+    c0 += (a);                  /* overflow is handled on the next line */ \+    over = (c0 < (a));         \+    c1 += over;                 /* overflow is handled on the next line */ \+    c2 += (c1 < over);          /* never overflows by contract */ \+}++/** Add a to the number defined by (c0,c1). c1 must never overflow, c2 must be zero. */+#define sumadd_fast(a) { \+    c0 += (a);                 /* overflow is handled on the next line */ \+    c1 += (c0 < (a));          /* never overflows by contract (verified the next line) */ \+    VERIFY_CHECK((c1 != 0) | (c0 >= (a))); \+    VERIFY_CHECK(c2 == 0); \+}++/** Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits. */+#define extract(n) { \+    (n) = c0; \+    c0 = c1; \+    c1 = c2; \+    c2 = 0; \+}++/** Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits. c2 is required to be zero. */+#define extract_fast(n) { \+    (n) = c0; \+    c0 = c1; \+    c1 = 0; \+    VERIFY_CHECK(c2 == 0); \+}++static void secp256k1_scalar_reduce_512(secp256k1_scalar *r, const uint64_t *l) {+#ifdef USE_ASM_X86_64+    /* Reduce 512 bits into 385. */+    uint64_t m0, m1, m2, m3, m4, m5, m6;+    uint64_t p0, p1, p2, p3, p4;+    uint64_t c;++    __asm__ __volatile__(+    /* Preload. */+    "movq 32(%%rsi), %%r11\n"+    "movq 40(%%rsi), %%r12\n"+    "movq 48(%%rsi), %%r13\n"+    "movq 56(%%rsi), %%r14\n"+    /* Initialize r8,r9,r10 */+    "movq 0(%%rsi), %%r8\n"+    "xorq %%r9, %%r9\n"+    "xorq %%r10, %%r10\n"+    /* (r8,r9) += n0 * c0 */+    "movq %8, %%rax\n"+    "mulq %%r11\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    /* extract m0 */+    "movq %%r8, %q0\n"+    "xorq %%r8, %%r8\n"+    /* (r9,r10) += l1 */+    "addq 8(%%rsi), %%r9\n"+    "adcq $0, %%r10\n"+    /* (r9,r10,r8) += n1 * c0 */+    "movq %8, %%rax\n"+    "mulq %%r12\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* (r9,r10,r8) += n0 * c1 */+    "movq %9, %%rax\n"+    "mulq %%r11\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* extract m1 */+    "movq %%r9, %q1\n"+    "xorq %%r9, %%r9\n"+    /* (r10,r8,r9) += l2 */+    "addq 16(%%rsi), %%r10\n"+    "adcq $0, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r10,r8,r9) += n2 * c0 */+    "movq %8, %%rax\n"+    "mulq %%r13\n"+    "addq %%rax, %%r10\n"+    "adcq %%rdx, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r10,r8,r9) += n1 * c1 */+    "movq %9, %%rax\n"+    "mulq %%r12\n"+    "addq %%rax, %%r10\n"+    "adcq %%rdx, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r10,r8,r9) += n0 */+    "addq %%r11, %%r10\n"+    "adcq $0, %%r8\n"+    "adcq $0, %%r9\n"+    /* extract m2 */+    "movq %%r10, %q2\n"+    "xorq %%r10, %%r10\n"+    /* (r8,r9,r10) += l3 */+    "addq 24(%%rsi), %%r8\n"+    "adcq $0, %%r9\n"+    "adcq $0, %%r10\n"+    /* (r8,r9,r10) += n3 * c0 */+    "movq %8, %%rax\n"+    "mulq %%r14\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    "adcq $0, %%r10\n"+    /* (r8,r9,r10) += n2 * c1 */+    "movq %9, %%rax\n"+    "mulq %%r13\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    "adcq $0, %%r10\n"+    /* (r8,r9,r10) += n1 */+    "addq %%r12, %%r8\n"+    "adcq $0, %%r9\n"+    "adcq $0, %%r10\n"+    /* extract m3 */+    "movq %%r8, %q3\n"+    "xorq %%r8, %%r8\n"+    /* (r9,r10,r8) += n3 * c1 */+    "movq %9, %%rax\n"+    "mulq %%r14\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* (r9,r10,r8) += n2 */+    "addq %%r13, %%r9\n"+    "adcq $0, %%r10\n"+    "adcq $0, %%r8\n"+    /* extract m4 */+    "movq %%r9, %q4\n"+    /* (r10,r8) += n3 */+    "addq %%r14, %%r10\n"+    "adcq $0, %%r8\n"+    /* extract m5 */+    "movq %%r10, %q5\n"+    /* extract m6 */+    "movq %%r8, %q6\n"+    : "=&g"(m0), "=&g"(m1), "=&g"(m2), "=g"(m3), "=g"(m4), "=g"(m5), "=g"(m6)+    : "S"(l), "i"(SECP256K1_N_C_0), "i"(SECP256K1_N_C_1)+    : "rax", "rdx", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "cc");++    SECP256K1_CHECKMEM_MSAN_DEFINE(&m0, sizeof(m0));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&m1, sizeof(m1));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&m2, sizeof(m2));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&m3, sizeof(m3));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&m4, sizeof(m4));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&m5, sizeof(m5));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&m6, sizeof(m6));++    /* Reduce 385 bits into 258. */+    __asm__ __volatile__(+    /* Preload */+    "movq %q9, %%r11\n"+    "movq %q10, %%r12\n"+    "movq %q11, %%r13\n"+    /* Initialize (r8,r9,r10) */+    "movq %q5, %%r8\n"+    "xorq %%r9, %%r9\n"+    "xorq %%r10, %%r10\n"+    /* (r8,r9) += m4 * c0 */+    "movq %12, %%rax\n"+    "mulq %%r11\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    /* extract p0 */+    "movq %%r8, %q0\n"+    "xorq %%r8, %%r8\n"+    /* (r9,r10) += m1 */+    "addq %q6, %%r9\n"+    "adcq $0, %%r10\n"+    /* (r9,r10,r8) += m5 * c0 */+    "movq %12, %%rax\n"+    "mulq %%r12\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* (r9,r10,r8) += m4 * c1 */+    "movq %13, %%rax\n"+    "mulq %%r11\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* extract p1 */+    "movq %%r9, %q1\n"+    "xorq %%r9, %%r9\n"+    /* (r10,r8,r9) += m2 */+    "addq %q7, %%r10\n"+    "adcq $0, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r10,r8,r9) += m6 * c0 */+    "movq %12, %%rax\n"+    "mulq %%r13\n"+    "addq %%rax, %%r10\n"+    "adcq %%rdx, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r10,r8,r9) += m5 * c1 */+    "movq %13, %%rax\n"+    "mulq %%r12\n"+    "addq %%rax, %%r10\n"+    "adcq %%rdx, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r10,r8,r9) += m4 */+    "addq %%r11, %%r10\n"+    "adcq $0, %%r8\n"+    "adcq $0, %%r9\n"+    /* extract p2 */+    "movq %%r10, %q2\n"+    /* (r8,r9) += m3 */+    "addq %q8, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r8,r9) += m6 * c1 */+    "movq %13, %%rax\n"+    "mulq %%r13\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    /* (r8,r9) += m5 */+    "addq %%r12, %%r8\n"+    "adcq $0, %%r9\n"+    /* extract p3 */+    "movq %%r8, %q3\n"+    /* (r9) += m6 */+    "addq %%r13, %%r9\n"+    /* extract p4 */+    "movq %%r9, %q4\n"+    : "=&g"(p0), "=&g"(p1), "=&g"(p2), "=g"(p3), "=g"(p4)+    : "g"(m0), "g"(m1), "g"(m2), "g"(m3), "g"(m4), "g"(m5), "g"(m6), "i"(SECP256K1_N_C_0), "i"(SECP256K1_N_C_1)+    : "rax", "rdx", "r8", "r9", "r10", "r11", "r12", "r13", "cc");++    SECP256K1_CHECKMEM_MSAN_DEFINE(&p0, sizeof(p0));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&p1, sizeof(p1));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&p2, sizeof(p2));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&p3, sizeof(p3));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&p4, sizeof(p4));++    /* Reduce 258 bits into 256. */+    __asm__ __volatile__(+    /* Preload */+    "movq %q5, %%r10\n"+    /* (rax,rdx) = p4 * c0 */+    "movq %7, %%rax\n"+    "mulq %%r10\n"+    /* (rax,rdx) += p0 */+    "addq %q1, %%rax\n"+    "adcq $0, %%rdx\n"+    /* extract r0 */+    "movq %%rax, 0(%q6)\n"+    /* Move to (r8,r9) */+    "movq %%rdx, %%r8\n"+    "xorq %%r9, %%r9\n"+    /* (r8,r9) += p1 */+    "addq %q2, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r8,r9) += p4 * c1 */+    "movq %8, %%rax\n"+    "mulq %%r10\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    /* Extract r1 */+    "movq %%r8, 8(%q6)\n"+    "xorq %%r8, %%r8\n"+    /* (r9,r8) += p4 */+    "addq %%r10, %%r9\n"+    "adcq $0, %%r8\n"+    /* (r9,r8) += p2 */+    "addq %q3, %%r9\n"+    "adcq $0, %%r8\n"+    /* Extract r2 */+    "movq %%r9, 16(%q6)\n"+    "xorq %%r9, %%r9\n"+    /* (r8,r9) += p3 */+    "addq %q4, %%r8\n"+    "adcq $0, %%r9\n"+    /* Extract r3 */+    "movq %%r8, 24(%q6)\n"+    /* Extract c */+    "movq %%r9, %q0\n"+    : "=g"(c)+    : "g"(p0), "g"(p1), "g"(p2), "g"(p3), "g"(p4), "D"(r), "i"(SECP256K1_N_C_0), "i"(SECP256K1_N_C_1)+    : "rax", "rdx", "r8", "r9", "r10", "cc", "memory");++    SECP256K1_CHECKMEM_MSAN_DEFINE(r, sizeof(*r));+    SECP256K1_CHECKMEM_MSAN_DEFINE(&c, sizeof(c));++#else+    secp256k1_uint128 c128;+    uint64_t c, c0, c1, c2;+    uint64_t n0 = l[4], n1 = l[5], n2 = l[6], n3 = l[7];+    uint64_t m0, m1, m2, m3, m4, m5;+    uint32_t m6;+    uint64_t p0, p1, p2, p3;+    uint32_t p4;++    /* Reduce 512 bits into 385. */+    /* m[0..6] = l[0..3] + n[0..3] * SECP256K1_N_C. */+    c0 = l[0]; c1 = 0; c2 = 0;+    muladd_fast(n0, SECP256K1_N_C_0);+    extract_fast(m0);+    sumadd_fast(l[1]);+    muladd(n1, SECP256K1_N_C_0);+    muladd(n0, SECP256K1_N_C_1);+    extract(m1);+    sumadd(l[2]);+    muladd(n2, SECP256K1_N_C_0);+    muladd(n1, SECP256K1_N_C_1);+    sumadd(n0);+    extract(m2);+    sumadd(l[3]);+    muladd(n3, SECP256K1_N_C_0);+    muladd(n2, SECP256K1_N_C_1);+    sumadd(n1);+    extract(m3);+    muladd(n3, SECP256K1_N_C_1);+    sumadd(n2);+    extract(m4);+    sumadd_fast(n3);+    extract_fast(m5);+    VERIFY_CHECK(c0 <= 1);+    m6 = c0;++    /* Reduce 385 bits into 258. */+    /* p[0..4] = m[0..3] + m[4..6] * SECP256K1_N_C. */+    c0 = m0; c1 = 0; c2 = 0;+    muladd_fast(m4, SECP256K1_N_C_0);+    extract_fast(p0);+    sumadd_fast(m1);+    muladd(m5, SECP256K1_N_C_0);+    muladd(m4, SECP256K1_N_C_1);+    extract(p1);+    sumadd(m2);+    muladd(m6, SECP256K1_N_C_0);+    muladd(m5, SECP256K1_N_C_1);+    sumadd(m4);+    extract(p2);+    sumadd_fast(m3);+    muladd_fast(m6, SECP256K1_N_C_1);+    sumadd_fast(m5);+    extract_fast(p3);+    p4 = c0 + m6;+    VERIFY_CHECK(p4 <= 2);++    /* Reduce 258 bits into 256. */+    /* r[0..3] = p[0..3] + p[4] * SECP256K1_N_C. */+    secp256k1_u128_from_u64(&c128, p0);+    secp256k1_u128_accum_mul(&c128, SECP256K1_N_C_0, p4);+    r->d[0] = secp256k1_u128_to_u64(&c128); secp256k1_u128_rshift(&c128, 64);+    secp256k1_u128_accum_u64(&c128, p1);+    secp256k1_u128_accum_mul(&c128, SECP256K1_N_C_1, p4);+    r->d[1] = secp256k1_u128_to_u64(&c128); secp256k1_u128_rshift(&c128, 64);+    secp256k1_u128_accum_u64(&c128, p2);+    secp256k1_u128_accum_u64(&c128, p4);+    r->d[2] = secp256k1_u128_to_u64(&c128); secp256k1_u128_rshift(&c128, 64);+    secp256k1_u128_accum_u64(&c128, p3);+    r->d[3] = secp256k1_u128_to_u64(&c128);+    c = secp256k1_u128_hi_u64(&c128);+#endif++    /* Final reduction of r. */+    secp256k1_scalar_reduce(r, c + secp256k1_scalar_check_overflow(r));+}++static void secp256k1_scalar_mul_512(uint64_t *l8, const secp256k1_scalar *a, const secp256k1_scalar *b) {+#ifdef USE_ASM_X86_64+    const uint64_t *pb = b->d;+    __asm__ __volatile__(+    /* Preload */+    "movq 0(%%rdi), %%r15\n"+    "movq 8(%%rdi), %%rbx\n"+    "movq 16(%%rdi), %%rcx\n"+    "movq 0(%%rdx), %%r11\n"+    "movq 8(%%rdx), %%r12\n"+    "movq 16(%%rdx), %%r13\n"+    "movq 24(%%rdx), %%r14\n"+    /* (rax,rdx) = a0 * b0 */+    "movq %%r15, %%rax\n"+    "mulq %%r11\n"+    /* Extract l8[0] */+    "movq %%rax, 0(%%rsi)\n"+    /* (r8,r9,r10) = (rdx) */+    "movq %%rdx, %%r8\n"+    "xorq %%r9, %%r9\n"+    "xorq %%r10, %%r10\n"+    /* (r8,r9,r10) += a0 * b1 */+    "movq %%r15, %%rax\n"+    "mulq %%r12\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    "adcq $0, %%r10\n"+    /* (r8,r9,r10) += a1 * b0 */+    "movq %%rbx, %%rax\n"+    "mulq %%r11\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    "adcq $0, %%r10\n"+    /* Extract l8[1] */+    "movq %%r8, 8(%%rsi)\n"+    "xorq %%r8, %%r8\n"+    /* (r9,r10,r8) += a0 * b2 */+    "movq %%r15, %%rax\n"+    "mulq %%r13\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* (r9,r10,r8) += a1 * b1 */+    "movq %%rbx, %%rax\n"+    "mulq %%r12\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* (r9,r10,r8) += a2 * b0 */+    "movq %%rcx, %%rax\n"+    "mulq %%r11\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* Extract l8[2] */+    "movq %%r9, 16(%%rsi)\n"+    "xorq %%r9, %%r9\n"+    /* (r10,r8,r9) += a0 * b3 */+    "movq %%r15, %%rax\n"+    "mulq %%r14\n"+    "addq %%rax, %%r10\n"+    "adcq %%rdx, %%r8\n"+    "adcq $0, %%r9\n"+    /* Preload a3 */+    "movq 24(%%rdi), %%r15\n"+    /* (r10,r8,r9) += a1 * b2 */+    "movq %%rbx, %%rax\n"+    "mulq %%r13\n"+    "addq %%rax, %%r10\n"+    "adcq %%rdx, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r10,r8,r9) += a2 * b1 */+    "movq %%rcx, %%rax\n"+    "mulq %%r12\n"+    "addq %%rax, %%r10\n"+    "adcq %%rdx, %%r8\n"+    "adcq $0, %%r9\n"+    /* (r10,r8,r9) += a3 * b0 */+    "movq %%r15, %%rax\n"+    "mulq %%r11\n"+    "addq %%rax, %%r10\n"+    "adcq %%rdx, %%r8\n"+    "adcq $0, %%r9\n"+    /* Extract l8[3] */+    "movq %%r10, 24(%%rsi)\n"+    "xorq %%r10, %%r10\n"+    /* (r8,r9,r10) += a1 * b3 */+    "movq %%rbx, %%rax\n"+    "mulq %%r14\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    "adcq $0, %%r10\n"+    /* (r8,r9,r10) += a2 * b2 */+    "movq %%rcx, %%rax\n"+    "mulq %%r13\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    "adcq $0, %%r10\n"+    /* (r8,r9,r10) += a3 * b1 */+    "movq %%r15, %%rax\n"+    "mulq %%r12\n"+    "addq %%rax, %%r8\n"+    "adcq %%rdx, %%r9\n"+    "adcq $0, %%r10\n"+    /* Extract l8[4] */+    "movq %%r8, 32(%%rsi)\n"+    "xorq %%r8, %%r8\n"+    /* (r9,r10,r8) += a2 * b3 */+    "movq %%rcx, %%rax\n"+    "mulq %%r14\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* (r9,r10,r8) += a3 * b2 */+    "movq %%r15, %%rax\n"+    "mulq %%r13\n"+    "addq %%rax, %%r9\n"+    "adcq %%rdx, %%r10\n"+    "adcq $0, %%r8\n"+    /* Extract l8[5] */+    "movq %%r9, 40(%%rsi)\n"+    /* (r10,r8) += a3 * b3 */+    "movq %%r15, %%rax\n"+    "mulq %%r14\n"+    "addq %%rax, %%r10\n"+    "adcq %%rdx, %%r8\n"+    /* Extract l8[6] */+    "movq %%r10, 48(%%rsi)\n"+    /* Extract l8[7] */+    "movq %%r8, 56(%%rsi)\n"+    : "+d"(pb)+    : "S"(l8), "D"(a->d)+    : "rax", "rbx", "rcx", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "cc", "memory");++    SECP256K1_CHECKMEM_MSAN_DEFINE(l8, sizeof(*l8) * 8);++#else+    /* 160 bit accumulator. */+    uint64_t c0 = 0, c1 = 0;+    uint32_t c2 = 0;++    /* l8[0..7] = a[0..3] * b[0..3]. */+    muladd_fast(a->d[0], b->d[0]);+    extract_fast(l8[0]);+    muladd(a->d[0], b->d[1]);+    muladd(a->d[1], b->d[0]);+    extract(l8[1]);+    muladd(a->d[0], b->d[2]);+    muladd(a->d[1], b->d[1]);+    muladd(a->d[2], b->d[0]);+    extract(l8[2]);+    muladd(a->d[0], b->d[3]);+    muladd(a->d[1], b->d[2]);+    muladd(a->d[2], b->d[1]);+    muladd(a->d[3], b->d[0]);+    extract(l8[3]);+    muladd(a->d[1], b->d[3]);+    muladd(a->d[2], b->d[2]);+    muladd(a->d[3], b->d[1]);+    extract(l8[4]);+    muladd(a->d[2], b->d[3]);+    muladd(a->d[3], b->d[2]);+    extract(l8[5]);+    muladd_fast(a->d[3], b->d[3]);+    extract_fast(l8[6]);+    VERIFY_CHECK(c1 == 0);+    l8[7] = c0;+#endif+}++#undef sumadd+#undef sumadd_fast+#undef muladd+#undef muladd_fast+#undef extract+#undef extract_fast++static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b) {+    uint64_t l[8];+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_SCALAR_VERIFY(b);++    secp256k1_scalar_mul_512(l, a, b);+    secp256k1_scalar_reduce_512(r, l);++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_split_128(secp256k1_scalar *r1, secp256k1_scalar *r2, const secp256k1_scalar *k) {+    SECP256K1_SCALAR_VERIFY(k);++    r1->d[0] = k->d[0];+    r1->d[1] = k->d[1];+    r1->d[2] = 0;+    r1->d[3] = 0;+    r2->d[0] = k->d[2];+    r2->d[1] = k->d[3];+    r2->d[2] = 0;+    r2->d[3] = 0;++    SECP256K1_SCALAR_VERIFY(r1);+    SECP256K1_SCALAR_VERIFY(r2);+}++SECP256K1_INLINE static int secp256k1_scalar_eq(const secp256k1_scalar *a, const secp256k1_scalar *b) {+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_SCALAR_VERIFY(b);++    return ((a->d[0] ^ b->d[0]) | (a->d[1] ^ b->d[1]) | (a->d[2] ^ b->d[2]) | (a->d[3] ^ b->d[3])) == 0;+}++SECP256K1_INLINE static void secp256k1_scalar_mul_shift_var(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b, unsigned int shift) {+    uint64_t l[8];+    unsigned int shiftlimbs;+    unsigned int shiftlow;+    unsigned int shifthigh;+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_SCALAR_VERIFY(b);+    VERIFY_CHECK(shift >= 256);++    secp256k1_scalar_mul_512(l, a, b);+    shiftlimbs = shift >> 6;+    shiftlow = shift & 0x3F;+    shifthigh = 64 - shiftlow;+    r->d[0] = shift < 512 ? (l[0 + shiftlimbs] >> shiftlow | (shift < 448 && shiftlow ? (l[1 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[1] = shift < 448 ? (l[1 + shiftlimbs] >> shiftlow | (shift < 384 && shiftlow ? (l[2 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[2] = shift < 384 ? (l[2 + shiftlimbs] >> shiftlow | (shift < 320 && shiftlow ? (l[3 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[3] = shift < 320 ? (l[3 + shiftlimbs] >> shiftlow) : 0;+    secp256k1_scalar_cadd_bit(r, 0, (l[(shift - 1) >> 6] >> ((shift - 1) & 0x3f)) & 1);++    SECP256K1_SCALAR_VERIFY(r);+}++static SECP256K1_INLINE void secp256k1_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag) {+    uint64_t mask0, mask1;+    volatile int vflag = flag;+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_CHECKMEM_CHECK_VERIFY(r->d, sizeof(r->d));++    mask0 = vflag + ~((uint64_t)0);+    mask1 = ~mask0;+    r->d[0] = (r->d[0] & mask0) | (a->d[0] & mask1);+    r->d[1] = (r->d[1] & mask0) | (a->d[1] & mask1);+    r->d[2] = (r->d[2] & mask0) | (a->d[2] & mask1);+    r->d[3] = (r->d[3] & mask0) | (a->d[3] & mask1);++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_from_signed62(secp256k1_scalar *r, const secp256k1_modinv64_signed62 *a) {+    const uint64_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4];++    /* The output from secp256k1_modinv64{_var} should be normalized to range [0,modulus), and+     * have limbs in [0,2^62). The modulus is < 2^256, so the top limb must be below 2^(256-62*4).+     */+    VERIFY_CHECK(a0 >> 62 == 0);+    VERIFY_CHECK(a1 >> 62 == 0);+    VERIFY_CHECK(a2 >> 62 == 0);+    VERIFY_CHECK(a3 >> 62 == 0);+    VERIFY_CHECK(a4 >> 8 == 0);++    r->d[0] = a0      | a1 << 62;+    r->d[1] = a1 >> 2 | a2 << 60;+    r->d[2] = a2 >> 4 | a3 << 58;+    r->d[3] = a3 >> 6 | a4 << 56;++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_to_signed62(secp256k1_modinv64_signed62 *r, const secp256k1_scalar *a) {+    const uint64_t M62 = UINT64_MAX >> 2;+    const uint64_t a0 = a->d[0], a1 = a->d[1], a2 = a->d[2], a3 = a->d[3];+    SECP256K1_SCALAR_VERIFY(a);++    r->v[0] =  a0                   & M62;+    r->v[1] = (a0 >> 62 | a1 <<  2) & M62;+    r->v[2] = (a1 >> 60 | a2 <<  4) & M62;+    r->v[3] = (a2 >> 58 | a3 <<  6) & M62;+    r->v[4] =  a3 >> 56;+}++static const secp256k1_modinv64_modinfo secp256k1_const_modinfo_scalar = {+    {{0x3FD25E8CD0364141LL, 0x2ABB739ABD2280EELL, -0x15LL, 0, 256}},+    0x34F20099AA774EC1LL+};++static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *x) {+    secp256k1_modinv64_signed62 s;+#ifdef VERIFY+    int zero_in = secp256k1_scalar_is_zero(x);+#endif+    SECP256K1_SCALAR_VERIFY(x);++    secp256k1_scalar_to_signed62(&s, x);+    secp256k1_modinv64(&s, &secp256k1_const_modinfo_scalar);+    secp256k1_scalar_from_signed62(r, &s);++    SECP256K1_SCALAR_VERIFY(r);+    VERIFY_CHECK(secp256k1_scalar_is_zero(r) == zero_in);+}++static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_scalar *x) {+    secp256k1_modinv64_signed62 s;+#ifdef VERIFY+    int zero_in = secp256k1_scalar_is_zero(x);+#endif+    SECP256K1_SCALAR_VERIFY(x);++    secp256k1_scalar_to_signed62(&s, x);+    secp256k1_modinv64_var(&s, &secp256k1_const_modinfo_scalar);+    secp256k1_scalar_from_signed62(r, &s);++    SECP256K1_SCALAR_VERIFY(r);+    VERIFY_CHECK(secp256k1_scalar_is_zero(r) == zero_in);+}++SECP256K1_INLINE static int secp256k1_scalar_is_even(const secp256k1_scalar *a) {+    SECP256K1_SCALAR_VERIFY(a);++    return !(a->d[0] & 1);+}++#endif /* SECP256K1_SCALAR_REPR_IMPL_H */
+ vendor/external/secp256k1/src/scalar_8x32.h view
@@ -0,0 +1,19 @@+/***********************************************************************+ * Copyright (c) 2014 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_SCALAR_REPR_H+#define SECP256K1_SCALAR_REPR_H++#include <stdint.h>++/** A scalar modulo the group order of the secp256k1 curve. */+typedef struct {+    uint32_t d[8];+} secp256k1_scalar;++#define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}}++#endif /* SECP256K1_SCALAR_REPR_H */
+ vendor/external/secp256k1/src/scalar_8x32_impl.h view
@@ -0,0 +1,816 @@+/***********************************************************************+ * Copyright (c) 2014 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_SCALAR_REPR_IMPL_H+#define SECP256K1_SCALAR_REPR_IMPL_H++#include "checkmem.h"+#include "modinv32_impl.h"+#include "util.h"++/* Limbs of the secp256k1 order. */+#define SECP256K1_N_0 ((uint32_t)0xD0364141UL)+#define SECP256K1_N_1 ((uint32_t)0xBFD25E8CUL)+#define SECP256K1_N_2 ((uint32_t)0xAF48A03BUL)+#define SECP256K1_N_3 ((uint32_t)0xBAAEDCE6UL)+#define SECP256K1_N_4 ((uint32_t)0xFFFFFFFEUL)+#define SECP256K1_N_5 ((uint32_t)0xFFFFFFFFUL)+#define SECP256K1_N_6 ((uint32_t)0xFFFFFFFFUL)+#define SECP256K1_N_7 ((uint32_t)0xFFFFFFFFUL)++/* Limbs of 2^256 minus the secp256k1 order. */+#define SECP256K1_N_C_0 (~SECP256K1_N_0 + 1)+#define SECP256K1_N_C_1 (~SECP256K1_N_1)+#define SECP256K1_N_C_2 (~SECP256K1_N_2)+#define SECP256K1_N_C_3 (~SECP256K1_N_3)+#define SECP256K1_N_C_4 (1)++/* Limbs of half the secp256k1 order. */+#define SECP256K1_N_H_0 ((uint32_t)0x681B20A0UL)+#define SECP256K1_N_H_1 ((uint32_t)0xDFE92F46UL)+#define SECP256K1_N_H_2 ((uint32_t)0x57A4501DUL)+#define SECP256K1_N_H_3 ((uint32_t)0x5D576E73UL)+#define SECP256K1_N_H_4 ((uint32_t)0xFFFFFFFFUL)+#define SECP256K1_N_H_5 ((uint32_t)0xFFFFFFFFUL)+#define SECP256K1_N_H_6 ((uint32_t)0xFFFFFFFFUL)+#define SECP256K1_N_H_7 ((uint32_t)0x7FFFFFFFUL)++SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) {+    r->d[0] = v;+    r->d[1] = 0;+    r->d[2] = 0;+    r->d[3] = 0;+    r->d[4] = 0;+    r->d[5] = 0;+    r->d[6] = 0;+    r->d[7] = 0;++    SECP256K1_SCALAR_VERIFY(r);+}++SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_limb32(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {+    SECP256K1_SCALAR_VERIFY(a);+    VERIFY_CHECK(count > 0 && count <= 32);+    VERIFY_CHECK((offset + count - 1) >> 5 == offset >> 5);++    return (a->d[offset >> 5] >> (offset & 0x1F)) & (0xFFFFFFFF >> (32 - count));+}++SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {+    SECP256K1_SCALAR_VERIFY(a);+    VERIFY_CHECK(count > 0 && count <= 32);+    VERIFY_CHECK(offset + count <= 256);++    if ((offset + count - 1) >> 5 == offset >> 5) {+        return secp256k1_scalar_get_bits_limb32(a, offset, count);+    } else {+        VERIFY_CHECK((offset >> 5) + 1 < 8);+        return ((a->d[offset >> 5] >> (offset & 0x1F)) | (a->d[(offset >> 5) + 1] << (32 - (offset & 0x1F)))) & (0xFFFFFFFF >> (32 - count));+    }+}++SECP256K1_INLINE static int secp256k1_scalar_check_overflow(const secp256k1_scalar *a) {+    int yes = 0;+    int no = 0;+    no |= (a->d[7] < SECP256K1_N_7); /* No need for a > check. */+    no |= (a->d[6] < SECP256K1_N_6); /* No need for a > check. */+    no |= (a->d[5] < SECP256K1_N_5); /* No need for a > check. */+    no |= (a->d[4] < SECP256K1_N_4);+    yes |= (a->d[4] > SECP256K1_N_4) & ~no;+    no |= (a->d[3] < SECP256K1_N_3) & ~yes;+    yes |= (a->d[3] > SECP256K1_N_3) & ~no;+    no |= (a->d[2] < SECP256K1_N_2) & ~yes;+    yes |= (a->d[2] > SECP256K1_N_2) & ~no;+    no |= (a->d[1] < SECP256K1_N_1) & ~yes;+    yes |= (a->d[1] > SECP256K1_N_1) & ~no;+    yes |= (a->d[0] >= SECP256K1_N_0) & ~no;+    return yes;+}++SECP256K1_INLINE static int secp256k1_scalar_reduce(secp256k1_scalar *r, uint32_t overflow) {+    uint64_t t;+    VERIFY_CHECK(overflow <= 1);++    t = (uint64_t)r->d[0] + overflow * SECP256K1_N_C_0;+    r->d[0] = t & 0xFFFFFFFFUL; t >>= 32;+    t += (uint64_t)r->d[1] + overflow * SECP256K1_N_C_1;+    r->d[1] = t & 0xFFFFFFFFUL; t >>= 32;+    t += (uint64_t)r->d[2] + overflow * SECP256K1_N_C_2;+    r->d[2] = t & 0xFFFFFFFFUL; t >>= 32;+    t += (uint64_t)r->d[3] + overflow * SECP256K1_N_C_3;+    r->d[3] = t & 0xFFFFFFFFUL; t >>= 32;+    t += (uint64_t)r->d[4] + overflow * SECP256K1_N_C_4;+    r->d[4] = t & 0xFFFFFFFFUL; t >>= 32;+    t += (uint64_t)r->d[5];+    r->d[5] = t & 0xFFFFFFFFUL; t >>= 32;+    t += (uint64_t)r->d[6];+    r->d[6] = t & 0xFFFFFFFFUL; t >>= 32;+    t += (uint64_t)r->d[7];+    r->d[7] = t & 0xFFFFFFFFUL;++    SECP256K1_SCALAR_VERIFY(r);+    return overflow;+}++static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b) {+    int overflow;+    uint64_t t = (uint64_t)a->d[0] + b->d[0];+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_SCALAR_VERIFY(b);++    r->d[0] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)a->d[1] + b->d[1];+    r->d[1] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)a->d[2] + b->d[2];+    r->d[2] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)a->d[3] + b->d[3];+    r->d[3] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)a->d[4] + b->d[4];+    r->d[4] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)a->d[5] + b->d[5];+    r->d[5] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)a->d[6] + b->d[6];+    r->d[6] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)a->d[7] + b->d[7];+    r->d[7] = t & 0xFFFFFFFFULL; t >>= 32;+    overflow = t + secp256k1_scalar_check_overflow(r);+    VERIFY_CHECK(overflow == 0 || overflow == 1);+    secp256k1_scalar_reduce(r, overflow);++    SECP256K1_SCALAR_VERIFY(r);+    return overflow;+}++static void secp256k1_scalar_cadd_bit(secp256k1_scalar *r, unsigned int bit, int flag) {+    uint64_t t;+    volatile int vflag = flag;+    SECP256K1_SCALAR_VERIFY(r);+    VERIFY_CHECK(bit < 256);++    bit += ((uint32_t) vflag - 1) & 0x100;  /* forcing (bit >> 5) > 7 makes this a noop */+    t = (uint64_t)r->d[0] + (((uint32_t)((bit >> 5) == 0)) << (bit & 0x1F));+    r->d[0] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)r->d[1] + (((uint32_t)((bit >> 5) == 1)) << (bit & 0x1F));+    r->d[1] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)r->d[2] + (((uint32_t)((bit >> 5) == 2)) << (bit & 0x1F));+    r->d[2] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)r->d[3] + (((uint32_t)((bit >> 5) == 3)) << (bit & 0x1F));+    r->d[3] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)r->d[4] + (((uint32_t)((bit >> 5) == 4)) << (bit & 0x1F));+    r->d[4] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)r->d[5] + (((uint32_t)((bit >> 5) == 5)) << (bit & 0x1F));+    r->d[5] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)r->d[6] + (((uint32_t)((bit >> 5) == 6)) << (bit & 0x1F));+    r->d[6] = t & 0xFFFFFFFFULL; t >>= 32;+    t += (uint64_t)r->d[7] + (((uint32_t)((bit >> 5) == 7)) << (bit & 0x1F));+    r->d[7] = t & 0xFFFFFFFFULL;++    SECP256K1_SCALAR_VERIFY(r);+    VERIFY_CHECK((t >> 32) == 0);+}++static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *b32, int *overflow) {+    int over;+    r->d[0] = secp256k1_read_be32(&b32[28]);+    r->d[1] = secp256k1_read_be32(&b32[24]);+    r->d[2] = secp256k1_read_be32(&b32[20]);+    r->d[3] = secp256k1_read_be32(&b32[16]);+    r->d[4] = secp256k1_read_be32(&b32[12]);+    r->d[5] = secp256k1_read_be32(&b32[8]);+    r->d[6] = secp256k1_read_be32(&b32[4]);+    r->d[7] = secp256k1_read_be32(&b32[0]);+    over = secp256k1_scalar_reduce(r, secp256k1_scalar_check_overflow(r));+    if (overflow) {+        *overflow = over;+    }++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar* a) {+    SECP256K1_SCALAR_VERIFY(a);++    secp256k1_write_be32(&bin[0], a->d[7]);+    secp256k1_write_be32(&bin[4], a->d[6]);+    secp256k1_write_be32(&bin[8], a->d[5]);+    secp256k1_write_be32(&bin[12], a->d[4]);+    secp256k1_write_be32(&bin[16], a->d[3]);+    secp256k1_write_be32(&bin[20], a->d[2]);+    secp256k1_write_be32(&bin[24], a->d[1]);+    secp256k1_write_be32(&bin[28], a->d[0]);+}++SECP256K1_INLINE static int secp256k1_scalar_is_zero(const secp256k1_scalar *a) {+    SECP256K1_SCALAR_VERIFY(a);++    return (a->d[0] | a->d[1] | a->d[2] | a->d[3] | a->d[4] | a->d[5] | a->d[6] | a->d[7]) == 0;+}++static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a) {+    uint32_t nonzero = 0xFFFFFFFFUL * (secp256k1_scalar_is_zero(a) == 0);+    uint64_t t = (uint64_t)(~a->d[0]) + SECP256K1_N_0 + 1;+    SECP256K1_SCALAR_VERIFY(a);++    r->d[0] = t & nonzero; t >>= 32;+    t += (uint64_t)(~a->d[1]) + SECP256K1_N_1;+    r->d[1] = t & nonzero; t >>= 32;+    t += (uint64_t)(~a->d[2]) + SECP256K1_N_2;+    r->d[2] = t & nonzero; t >>= 32;+    t += (uint64_t)(~a->d[3]) + SECP256K1_N_3;+    r->d[3] = t & nonzero; t >>= 32;+    t += (uint64_t)(~a->d[4]) + SECP256K1_N_4;+    r->d[4] = t & nonzero; t >>= 32;+    t += (uint64_t)(~a->d[5]) + SECP256K1_N_5;+    r->d[5] = t & nonzero; t >>= 32;+    t += (uint64_t)(~a->d[6]) + SECP256K1_N_6;+    r->d[6] = t & nonzero; t >>= 32;+    t += (uint64_t)(~a->d[7]) + SECP256K1_N_7;+    r->d[7] = t & nonzero;++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_half(secp256k1_scalar *r, const secp256k1_scalar *a) {+    /* Writing `/` for field division and `//` for integer division, we compute+     *+     *   a/2 = (a - (a&1))/2 + (a&1)/2+     *       = (a >> 1) + (a&1 ?    1/2 : 0)+     *       = (a >> 1) + (a&1 ? n//2+1 : 0),+     *+     * where n is the group order and in the last equality we have used 1/2 = n//2+1 (mod n).+     * For n//2, we have the constants SECP256K1_N_H_0, ...+     *+     * This sum does not overflow. The most extreme case is a = -2, the largest odd scalar. Here:+     * - the left summand is:  a >> 1 = (a - a&1)/2 = (n-2-1)//2           = (n-3)//2+     * - the right summand is: a&1 ? n//2+1 : 0 = n//2+1 = (n-1)//2 + 2//2 = (n+1)//2+     * Together they sum to (n-3)//2 + (n+1)//2 = (2n-2)//2 = n - 1, which is less than n.+     */+    uint32_t mask = -(uint32_t)(a->d[0] & 1U);+    uint64_t t = (uint32_t)((a->d[0] >> 1) | (a->d[1] << 31));+    SECP256K1_SCALAR_VERIFY(a);++    t += (SECP256K1_N_H_0 + 1U) & mask;+    r->d[0] = t; t >>= 32;+    t += (uint32_t)((a->d[1] >> 1) | (a->d[2] << 31));+    t += SECP256K1_N_H_1 & mask;+    r->d[1] = t; t >>= 32;+    t += (uint32_t)((a->d[2] >> 1) | (a->d[3] << 31));+    t += SECP256K1_N_H_2 & mask;+    r->d[2] = t; t >>= 32;+    t += (uint32_t)((a->d[3] >> 1) | (a->d[4] << 31));+    t += SECP256K1_N_H_3 & mask;+    r->d[3] = t; t >>= 32;+    t += (uint32_t)((a->d[4] >> 1) | (a->d[5] << 31));+    t += SECP256K1_N_H_4 & mask;+    r->d[4] = t; t >>= 32;+    t += (uint32_t)((a->d[5] >> 1) | (a->d[6] << 31));+    t += SECP256K1_N_H_5 & mask;+    r->d[5] = t; t >>= 32;+    t += (uint32_t)((a->d[6] >> 1) | (a->d[7] << 31));+    t += SECP256K1_N_H_6 & mask;+    r->d[6] = t; t >>= 32;+    r->d[7] = (uint32_t)t + (uint32_t)(a->d[7] >> 1) + (SECP256K1_N_H_7 & mask);++    /* The line above only computed the bottom 32 bits of r->d[7]. Redo the computation+     * in full 64 bits to make sure the top 32 bits are indeed zero. */+    VERIFY_CHECK((t + (a->d[7] >> 1) + (SECP256K1_N_H_7 & mask)) >> 32 == 0);++    SECP256K1_SCALAR_VERIFY(r);+}++SECP256K1_INLINE static int secp256k1_scalar_is_one(const secp256k1_scalar *a) {+    SECP256K1_SCALAR_VERIFY(a);++    return ((a->d[0] ^ 1) | a->d[1] | a->d[2] | a->d[3] | a->d[4] | a->d[5] | a->d[6] | a->d[7]) == 0;+}++static int secp256k1_scalar_is_high(const secp256k1_scalar *a) {+    int yes = 0;+    int no = 0;+    SECP256K1_SCALAR_VERIFY(a);++    no |= (a->d[7] < SECP256K1_N_H_7);+    yes |= (a->d[7] > SECP256K1_N_H_7) & ~no;+    no |= (a->d[6] < SECP256K1_N_H_6) & ~yes; /* No need for a > check. */+    no |= (a->d[5] < SECP256K1_N_H_5) & ~yes; /* No need for a > check. */+    no |= (a->d[4] < SECP256K1_N_H_4) & ~yes; /* No need for a > check. */+    no |= (a->d[3] < SECP256K1_N_H_3) & ~yes;+    yes |= (a->d[3] > SECP256K1_N_H_3) & ~no;+    no |= (a->d[2] < SECP256K1_N_H_2) & ~yes;+    yes |= (a->d[2] > SECP256K1_N_H_2) & ~no;+    no |= (a->d[1] < SECP256K1_N_H_1) & ~yes;+    yes |= (a->d[1] > SECP256K1_N_H_1) & ~no;+    yes |= (a->d[0] > SECP256K1_N_H_0) & ~no;+    return yes;+}++static int secp256k1_scalar_cond_negate(secp256k1_scalar *r, int flag) {+    /* If we are flag = 0, mask = 00...00 and this is a no-op;+     * if we are flag = 1, mask = 11...11 and this is identical to secp256k1_scalar_negate */+    volatile int vflag = flag;+    uint32_t mask = -vflag;+    uint32_t nonzero = 0xFFFFFFFFUL * (secp256k1_scalar_is_zero(r) == 0);+    uint64_t t = (uint64_t)(r->d[0] ^ mask) + ((SECP256K1_N_0 + 1) & mask);+    SECP256K1_SCALAR_VERIFY(r);++    r->d[0] = t & nonzero; t >>= 32;+    t += (uint64_t)(r->d[1] ^ mask) + (SECP256K1_N_1 & mask);+    r->d[1] = t & nonzero; t >>= 32;+    t += (uint64_t)(r->d[2] ^ mask) + (SECP256K1_N_2 & mask);+    r->d[2] = t & nonzero; t >>= 32;+    t += (uint64_t)(r->d[3] ^ mask) + (SECP256K1_N_3 & mask);+    r->d[3] = t & nonzero; t >>= 32;+    t += (uint64_t)(r->d[4] ^ mask) + (SECP256K1_N_4 & mask);+    r->d[4] = t & nonzero; t >>= 32;+    t += (uint64_t)(r->d[5] ^ mask) + (SECP256K1_N_5 & mask);+    r->d[5] = t & nonzero; t >>= 32;+    t += (uint64_t)(r->d[6] ^ mask) + (SECP256K1_N_6 & mask);+    r->d[6] = t & nonzero; t >>= 32;+    t += (uint64_t)(r->d[7] ^ mask) + (SECP256K1_N_7 & mask);+    r->d[7] = t & nonzero;++    SECP256K1_SCALAR_VERIFY(r);+    return 2 * (mask == 0) - 1;+}+++/* Inspired by the macros in OpenSSL's crypto/bn/asm/x86_64-gcc.c. */++/** Add a*b to the number defined by (c0,c1,c2). c2 must never overflow. */+#define muladd(a,b) { \+    uint32_t tl, th; \+    { \+        uint64_t t = (uint64_t)a * b; \+        th = t >> 32;         /* at most 0xFFFFFFFE */ \+        tl = t; \+    } \+    c0 += tl;                 /* overflow is handled on the next line */ \+    th += (c0 < tl);          /* at most 0xFFFFFFFF */ \+    c1 += th;                 /* overflow is handled on the next line */ \+    c2 += (c1 < th);          /* never overflows by contract (verified in the next line) */ \+    VERIFY_CHECK((c1 >= th) || (c2 != 0)); \+}++/** Add a*b to the number defined by (c0,c1). c1 must never overflow. */+#define muladd_fast(a,b) { \+    uint32_t tl, th; \+    { \+        uint64_t t = (uint64_t)a * b; \+        th = t >> 32;         /* at most 0xFFFFFFFE */ \+        tl = t; \+    } \+    c0 += tl;                 /* overflow is handled on the next line */ \+    th += (c0 < tl);          /* at most 0xFFFFFFFF */ \+    c1 += th;                 /* never overflows by contract (verified in the next line) */ \+    VERIFY_CHECK(c1 >= th); \+}++/** Add a to the number defined by (c0,c1,c2). c2 must never overflow. */+#define sumadd(a) { \+    unsigned int over; \+    c0 += (a);                  /* overflow is handled on the next line */ \+    over = (c0 < (a)); \+    c1 += over;                 /* overflow is handled on the next line */ \+    c2 += (c1 < over);          /* never overflows by contract */ \+}++/** Add a to the number defined by (c0,c1). c1 must never overflow, c2 must be zero. */+#define sumadd_fast(a) { \+    c0 += (a);                 /* overflow is handled on the next line */ \+    c1 += (c0 < (a));          /* never overflows by contract (verified the next line) */ \+    VERIFY_CHECK((c1 != 0) | (c0 >= (a))); \+    VERIFY_CHECK(c2 == 0); \+}++/** Extract the lowest 32 bits of (c0,c1,c2) into n, and left shift the number 32 bits. */+#define extract(n) { \+    (n) = c0; \+    c0 = c1; \+    c1 = c2; \+    c2 = 0; \+}++/** Extract the lowest 32 bits of (c0,c1,c2) into n, and left shift the number 32 bits. c2 is required to be zero. */+#define extract_fast(n) { \+    (n) = c0; \+    c0 = c1; \+    c1 = 0; \+    VERIFY_CHECK(c2 == 0); \+}++static void secp256k1_scalar_reduce_512(secp256k1_scalar *r, const uint32_t *l) {+    uint64_t c;+    uint32_t n0 = l[8], n1 = l[9], n2 = l[10], n3 = l[11], n4 = l[12], n5 = l[13], n6 = l[14], n7 = l[15];+    uint32_t m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12;+    uint32_t p0, p1, p2, p3, p4, p5, p6, p7, p8;++    /* 96 bit accumulator. */+    uint32_t c0, c1, c2;++    /* Reduce 512 bits into 385. */+    /* m[0..12] = l[0..7] + n[0..7] * SECP256K1_N_C. */+    c0 = l[0]; c1 = 0; c2 = 0;+    muladd_fast(n0, SECP256K1_N_C_0);+    extract_fast(m0);+    sumadd_fast(l[1]);+    muladd(n1, SECP256K1_N_C_0);+    muladd(n0, SECP256K1_N_C_1);+    extract(m1);+    sumadd(l[2]);+    muladd(n2, SECP256K1_N_C_0);+    muladd(n1, SECP256K1_N_C_1);+    muladd(n0, SECP256K1_N_C_2);+    extract(m2);+    sumadd(l[3]);+    muladd(n3, SECP256K1_N_C_0);+    muladd(n2, SECP256K1_N_C_1);+    muladd(n1, SECP256K1_N_C_2);+    muladd(n0, SECP256K1_N_C_3);+    extract(m3);+    sumadd(l[4]);+    muladd(n4, SECP256K1_N_C_0);+    muladd(n3, SECP256K1_N_C_1);+    muladd(n2, SECP256K1_N_C_2);+    muladd(n1, SECP256K1_N_C_3);+    sumadd(n0);+    extract(m4);+    sumadd(l[5]);+    muladd(n5, SECP256K1_N_C_0);+    muladd(n4, SECP256K1_N_C_1);+    muladd(n3, SECP256K1_N_C_2);+    muladd(n2, SECP256K1_N_C_3);+    sumadd(n1);+    extract(m5);+    sumadd(l[6]);+    muladd(n6, SECP256K1_N_C_0);+    muladd(n5, SECP256K1_N_C_1);+    muladd(n4, SECP256K1_N_C_2);+    muladd(n3, SECP256K1_N_C_3);+    sumadd(n2);+    extract(m6);+    sumadd(l[7]);+    muladd(n7, SECP256K1_N_C_0);+    muladd(n6, SECP256K1_N_C_1);+    muladd(n5, SECP256K1_N_C_2);+    muladd(n4, SECP256K1_N_C_3);+    sumadd(n3);+    extract(m7);+    muladd(n7, SECP256K1_N_C_1);+    muladd(n6, SECP256K1_N_C_2);+    muladd(n5, SECP256K1_N_C_3);+    sumadd(n4);+    extract(m8);+    muladd(n7, SECP256K1_N_C_2);+    muladd(n6, SECP256K1_N_C_3);+    sumadd(n5);+    extract(m9);+    muladd(n7, SECP256K1_N_C_3);+    sumadd(n6);+    extract(m10);+    sumadd_fast(n7);+    extract_fast(m11);+    VERIFY_CHECK(c0 <= 1);+    m12 = c0;++    /* Reduce 385 bits into 258. */+    /* p[0..8] = m[0..7] + m[8..12] * SECP256K1_N_C. */+    c0 = m0; c1 = 0; c2 = 0;+    muladd_fast(m8, SECP256K1_N_C_0);+    extract_fast(p0);+    sumadd_fast(m1);+    muladd(m9, SECP256K1_N_C_0);+    muladd(m8, SECP256K1_N_C_1);+    extract(p1);+    sumadd(m2);+    muladd(m10, SECP256K1_N_C_0);+    muladd(m9, SECP256K1_N_C_1);+    muladd(m8, SECP256K1_N_C_2);+    extract(p2);+    sumadd(m3);+    muladd(m11, SECP256K1_N_C_0);+    muladd(m10, SECP256K1_N_C_1);+    muladd(m9, SECP256K1_N_C_2);+    muladd(m8, SECP256K1_N_C_3);+    extract(p3);+    sumadd(m4);+    muladd(m12, SECP256K1_N_C_0);+    muladd(m11, SECP256K1_N_C_1);+    muladd(m10, SECP256K1_N_C_2);+    muladd(m9, SECP256K1_N_C_3);+    sumadd(m8);+    extract(p4);+    sumadd(m5);+    muladd(m12, SECP256K1_N_C_1);+    muladd(m11, SECP256K1_N_C_2);+    muladd(m10, SECP256K1_N_C_3);+    sumadd(m9);+    extract(p5);+    sumadd(m6);+    muladd(m12, SECP256K1_N_C_2);+    muladd(m11, SECP256K1_N_C_3);+    sumadd(m10);+    extract(p6);+    sumadd_fast(m7);+    muladd_fast(m12, SECP256K1_N_C_3);+    sumadd_fast(m11);+    extract_fast(p7);+    p8 = c0 + m12;+    VERIFY_CHECK(p8 <= 2);++    /* Reduce 258 bits into 256. */+    /* r[0..7] = p[0..7] + p[8] * SECP256K1_N_C. */+    c = p0 + (uint64_t)SECP256K1_N_C_0 * p8;+    r->d[0] = c & 0xFFFFFFFFUL; c >>= 32;+    c += p1 + (uint64_t)SECP256K1_N_C_1 * p8;+    r->d[1] = c & 0xFFFFFFFFUL; c >>= 32;+    c += p2 + (uint64_t)SECP256K1_N_C_2 * p8;+    r->d[2] = c & 0xFFFFFFFFUL; c >>= 32;+    c += p3 + (uint64_t)SECP256K1_N_C_3 * p8;+    r->d[3] = c & 0xFFFFFFFFUL; c >>= 32;+    c += p4 + (uint64_t)p8;+    r->d[4] = c & 0xFFFFFFFFUL; c >>= 32;+    c += p5;+    r->d[5] = c & 0xFFFFFFFFUL; c >>= 32;+    c += p6;+    r->d[6] = c & 0xFFFFFFFFUL; c >>= 32;+    c += p7;+    r->d[7] = c & 0xFFFFFFFFUL; c >>= 32;++    /* Final reduction of r. */+    secp256k1_scalar_reduce(r, c + secp256k1_scalar_check_overflow(r));+}++static void secp256k1_scalar_mul_512(uint32_t *l, const secp256k1_scalar *a, const secp256k1_scalar *b) {+    /* 96 bit accumulator. */+    uint32_t c0 = 0, c1 = 0, c2 = 0;++    /* l[0..15] = a[0..7] * b[0..7]. */+    muladd_fast(a->d[0], b->d[0]);+    extract_fast(l[0]);+    muladd(a->d[0], b->d[1]);+    muladd(a->d[1], b->d[0]);+    extract(l[1]);+    muladd(a->d[0], b->d[2]);+    muladd(a->d[1], b->d[1]);+    muladd(a->d[2], b->d[0]);+    extract(l[2]);+    muladd(a->d[0], b->d[3]);+    muladd(a->d[1], b->d[2]);+    muladd(a->d[2], b->d[1]);+    muladd(a->d[3], b->d[0]);+    extract(l[3]);+    muladd(a->d[0], b->d[4]);+    muladd(a->d[1], b->d[3]);+    muladd(a->d[2], b->d[2]);+    muladd(a->d[3], b->d[1]);+    muladd(a->d[4], b->d[0]);+    extract(l[4]);+    muladd(a->d[0], b->d[5]);+    muladd(a->d[1], b->d[4]);+    muladd(a->d[2], b->d[3]);+    muladd(a->d[3], b->d[2]);+    muladd(a->d[4], b->d[1]);+    muladd(a->d[5], b->d[0]);+    extract(l[5]);+    muladd(a->d[0], b->d[6]);+    muladd(a->d[1], b->d[5]);+    muladd(a->d[2], b->d[4]);+    muladd(a->d[3], b->d[3]);+    muladd(a->d[4], b->d[2]);+    muladd(a->d[5], b->d[1]);+    muladd(a->d[6], b->d[0]);+    extract(l[6]);+    muladd(a->d[0], b->d[7]);+    muladd(a->d[1], b->d[6]);+    muladd(a->d[2], b->d[5]);+    muladd(a->d[3], b->d[4]);+    muladd(a->d[4], b->d[3]);+    muladd(a->d[5], b->d[2]);+    muladd(a->d[6], b->d[1]);+    muladd(a->d[7], b->d[0]);+    extract(l[7]);+    muladd(a->d[1], b->d[7]);+    muladd(a->d[2], b->d[6]);+    muladd(a->d[3], b->d[5]);+    muladd(a->d[4], b->d[4]);+    muladd(a->d[5], b->d[3]);+    muladd(a->d[6], b->d[2]);+    muladd(a->d[7], b->d[1]);+    extract(l[8]);+    muladd(a->d[2], b->d[7]);+    muladd(a->d[3], b->d[6]);+    muladd(a->d[4], b->d[5]);+    muladd(a->d[5], b->d[4]);+    muladd(a->d[6], b->d[3]);+    muladd(a->d[7], b->d[2]);+    extract(l[9]);+    muladd(a->d[3], b->d[7]);+    muladd(a->d[4], b->d[6]);+    muladd(a->d[5], b->d[5]);+    muladd(a->d[6], b->d[4]);+    muladd(a->d[7], b->d[3]);+    extract(l[10]);+    muladd(a->d[4], b->d[7]);+    muladd(a->d[5], b->d[6]);+    muladd(a->d[6], b->d[5]);+    muladd(a->d[7], b->d[4]);+    extract(l[11]);+    muladd(a->d[5], b->d[7]);+    muladd(a->d[6], b->d[6]);+    muladd(a->d[7], b->d[5]);+    extract(l[12]);+    muladd(a->d[6], b->d[7]);+    muladd(a->d[7], b->d[6]);+    extract(l[13]);+    muladd_fast(a->d[7], b->d[7]);+    extract_fast(l[14]);+    VERIFY_CHECK(c1 == 0);+    l[15] = c0;+}++#undef sumadd+#undef sumadd_fast+#undef muladd+#undef muladd_fast+#undef extract+#undef extract_fast++static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b) {+    uint32_t l[16];+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_SCALAR_VERIFY(b);++    secp256k1_scalar_mul_512(l, a, b);+    secp256k1_scalar_reduce_512(r, l);++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_split_128(secp256k1_scalar *r1, secp256k1_scalar *r2, const secp256k1_scalar *k) {+    SECP256K1_SCALAR_VERIFY(k);++    r1->d[0] = k->d[0];+    r1->d[1] = k->d[1];+    r1->d[2] = k->d[2];+    r1->d[3] = k->d[3];+    r1->d[4] = 0;+    r1->d[5] = 0;+    r1->d[6] = 0;+    r1->d[7] = 0;+    r2->d[0] = k->d[4];+    r2->d[1] = k->d[5];+    r2->d[2] = k->d[6];+    r2->d[3] = k->d[7];+    r2->d[4] = 0;+    r2->d[5] = 0;+    r2->d[6] = 0;+    r2->d[7] = 0;++    SECP256K1_SCALAR_VERIFY(r1);+    SECP256K1_SCALAR_VERIFY(r2);+}++SECP256K1_INLINE static int secp256k1_scalar_eq(const secp256k1_scalar *a, const secp256k1_scalar *b) {+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_SCALAR_VERIFY(b);++    return ((a->d[0] ^ b->d[0]) | (a->d[1] ^ b->d[1]) | (a->d[2] ^ b->d[2]) | (a->d[3] ^ b->d[3]) | (a->d[4] ^ b->d[4]) | (a->d[5] ^ b->d[5]) | (a->d[6] ^ b->d[6]) | (a->d[7] ^ b->d[7])) == 0;+}++SECP256K1_INLINE static void secp256k1_scalar_mul_shift_var(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b, unsigned int shift) {+    uint32_t l[16];+    unsigned int shiftlimbs;+    unsigned int shiftlow;+    unsigned int shifthigh;+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_SCALAR_VERIFY(b);+    VERIFY_CHECK(shift >= 256);++    secp256k1_scalar_mul_512(l, a, b);+    shiftlimbs = shift >> 5;+    shiftlow = shift & 0x1F;+    shifthigh = 32 - shiftlow;+    r->d[0] = shift < 512 ? (l[0 + shiftlimbs] >> shiftlow | (shift < 480 && shiftlow ? (l[1 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[1] = shift < 480 ? (l[1 + shiftlimbs] >> shiftlow | (shift < 448 && shiftlow ? (l[2 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[2] = shift < 448 ? (l[2 + shiftlimbs] >> shiftlow | (shift < 416 && shiftlow ? (l[3 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[3] = shift < 416 ? (l[3 + shiftlimbs] >> shiftlow | (shift < 384 && shiftlow ? (l[4 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[4] = shift < 384 ? (l[4 + shiftlimbs] >> shiftlow | (shift < 352 && shiftlow ? (l[5 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[5] = shift < 352 ? (l[5 + shiftlimbs] >> shiftlow | (shift < 320 && shiftlow ? (l[6 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[6] = shift < 320 ? (l[6 + shiftlimbs] >> shiftlow | (shift < 288 && shiftlow ? (l[7 + shiftlimbs] << shifthigh) : 0)) : 0;+    r->d[7] = shift < 288 ? (l[7 + shiftlimbs] >> shiftlow)  : 0;+    secp256k1_scalar_cadd_bit(r, 0, (l[(shift - 1) >> 5] >> ((shift - 1) & 0x1f)) & 1);++    SECP256K1_SCALAR_VERIFY(r);+}++static SECP256K1_INLINE void secp256k1_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag) {+    uint32_t mask0, mask1;+    volatile int vflag = flag;+    SECP256K1_SCALAR_VERIFY(a);+    SECP256K1_CHECKMEM_CHECK_VERIFY(r->d, sizeof(r->d));++    mask0 = vflag + ~((uint32_t)0);+    mask1 = ~mask0;+    r->d[0] = (r->d[0] & mask0) | (a->d[0] & mask1);+    r->d[1] = (r->d[1] & mask0) | (a->d[1] & mask1);+    r->d[2] = (r->d[2] & mask0) | (a->d[2] & mask1);+    r->d[3] = (r->d[3] & mask0) | (a->d[3] & mask1);+    r->d[4] = (r->d[4] & mask0) | (a->d[4] & mask1);+    r->d[5] = (r->d[5] & mask0) | (a->d[5] & mask1);+    r->d[6] = (r->d[6] & mask0) | (a->d[6] & mask1);+    r->d[7] = (r->d[7] & mask0) | (a->d[7] & mask1);++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_from_signed30(secp256k1_scalar *r, const secp256k1_modinv32_signed30 *a) {+    const uint32_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4],+                   a5 = a->v[5], a6 = a->v[6], a7 = a->v[7], a8 = a->v[8];++    /* The output from secp256k1_modinv32{_var} should be normalized to range [0,modulus), and+     * have limbs in [0,2^30). The modulus is < 2^256, so the top limb must be below 2^(256-30*8).+     */+    VERIFY_CHECK(a0 >> 30 == 0);+    VERIFY_CHECK(a1 >> 30 == 0);+    VERIFY_CHECK(a2 >> 30 == 0);+    VERIFY_CHECK(a3 >> 30 == 0);+    VERIFY_CHECK(a4 >> 30 == 0);+    VERIFY_CHECK(a5 >> 30 == 0);+    VERIFY_CHECK(a6 >> 30 == 0);+    VERIFY_CHECK(a7 >> 30 == 0);+    VERIFY_CHECK(a8 >> 16 == 0);++    r->d[0] = a0       | a1 << 30;+    r->d[1] = a1 >>  2 | a2 << 28;+    r->d[2] = a2 >>  4 | a3 << 26;+    r->d[3] = a3 >>  6 | a4 << 24;+    r->d[4] = a4 >>  8 | a5 << 22;+    r->d[5] = a5 >> 10 | a6 << 20;+    r->d[6] = a6 >> 12 | a7 << 18;+    r->d[7] = a7 >> 14 | a8 << 16;++    SECP256K1_SCALAR_VERIFY(r);+}++static void secp256k1_scalar_to_signed30(secp256k1_modinv32_signed30 *r, const secp256k1_scalar *a) {+    const uint32_t M30 = UINT32_MAX >> 2;+    const uint32_t a0 = a->d[0], a1 = a->d[1], a2 = a->d[2], a3 = a->d[3],+                   a4 = a->d[4], a5 = a->d[5], a6 = a->d[6], a7 = a->d[7];+    SECP256K1_SCALAR_VERIFY(a);++    r->v[0] =  a0                   & M30;+    r->v[1] = (a0 >> 30 | a1 <<  2) & M30;+    r->v[2] = (a1 >> 28 | a2 <<  4) & M30;+    r->v[3] = (a2 >> 26 | a3 <<  6) & M30;+    r->v[4] = (a3 >> 24 | a4 <<  8) & M30;+    r->v[5] = (a4 >> 22 | a5 << 10) & M30;+    r->v[6] = (a5 >> 20 | a6 << 12) & M30;+    r->v[7] = (a6 >> 18 | a7 << 14) & M30;+    r->v[8] =  a7 >> 16;+}++static const secp256k1_modinv32_modinfo secp256k1_const_modinfo_scalar = {+    {{0x10364141L, 0x3F497A33L, 0x348A03BBL, 0x2BB739ABL, -0x146L, 0, 0, 0, 65536}},+    0x2A774EC1L+};++static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *x) {+    secp256k1_modinv32_signed30 s;+#ifdef VERIFY+    int zero_in = secp256k1_scalar_is_zero(x);+#endif+    SECP256K1_SCALAR_VERIFY(x);++    secp256k1_scalar_to_signed30(&s, x);+    secp256k1_modinv32(&s, &secp256k1_const_modinfo_scalar);+    secp256k1_scalar_from_signed30(r, &s);++    SECP256K1_SCALAR_VERIFY(r);+    VERIFY_CHECK(secp256k1_scalar_is_zero(r) == zero_in);+}++static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_scalar *x) {+    secp256k1_modinv32_signed30 s;+#ifdef VERIFY+    int zero_in = secp256k1_scalar_is_zero(x);+#endif+    SECP256K1_SCALAR_VERIFY(x);++    secp256k1_scalar_to_signed30(&s, x);+    secp256k1_modinv32_var(&s, &secp256k1_const_modinfo_scalar);+    secp256k1_scalar_from_signed30(r, &s);++    SECP256K1_SCALAR_VERIFY(r);+    VERIFY_CHECK(secp256k1_scalar_is_zero(r) == zero_in);+}++SECP256K1_INLINE static int secp256k1_scalar_is_even(const secp256k1_scalar *a) {+    SECP256K1_SCALAR_VERIFY(a);++    return !(a->d[0] & 1);+}++#endif /* SECP256K1_SCALAR_REPR_IMPL_H */
+ vendor/external/secp256k1/src/scalar_impl.h view
@@ -0,0 +1,321 @@+/***********************************************************************+ * Copyright (c) 2014 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_SCALAR_IMPL_H+#define SECP256K1_SCALAR_IMPL_H++#ifdef VERIFY+#include <string.h>+#endif++#include "scalar.h"+#include "util.h"++#if defined(EXHAUSTIVE_TEST_ORDER)+#include "scalar_low_impl.h"+#elif defined(SECP256K1_WIDEMUL_INT128)+#include "scalar_4x64_impl.h"+#elif defined(SECP256K1_WIDEMUL_INT64)+#include "scalar_8x32_impl.h"+#else+#error "Please select wide multiplication implementation"+#endif++static const secp256k1_scalar secp256k1_scalar_one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1);+static const secp256k1_scalar secp256k1_scalar_zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0);++SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) {+    secp256k1_memclear(r, sizeof(secp256k1_scalar));+}++static int secp256k1_scalar_set_b32_seckey(secp256k1_scalar *r, const unsigned char *bin) {+    int overflow;+    secp256k1_scalar_set_b32(r, bin, &overflow);++    SECP256K1_SCALAR_VERIFY(r);+    return (!overflow) & (!secp256k1_scalar_is_zero(r));+}++static void secp256k1_scalar_verify(const secp256k1_scalar *r) {+    VERIFY_CHECK(secp256k1_scalar_check_overflow(r) == 0);++    (void)r;+}++#if defined(EXHAUSTIVE_TEST_ORDER)+/* Begin of section generated by sage/gen_exhaustive_groups.sage. */+#  if EXHAUSTIVE_TEST_ORDER == 7+#    define EXHAUSTIVE_TEST_LAMBDA 2+#  elif EXHAUSTIVE_TEST_ORDER == 13+#    define EXHAUSTIVE_TEST_LAMBDA 9+#  elif EXHAUSTIVE_TEST_ORDER == 199+#    define EXHAUSTIVE_TEST_LAMBDA 92+#  else+#    error No known lambda for the specified exhaustive test group order.+#  endif+/* End of section generated by sage/gen_exhaustive_groups.sage. */++/**+ * Find r1 and r2 given k, such that r1 + r2 * lambda == k mod n; unlike in the+ * full case we don't bother making r1 and r2 be small, we just want them to be+ * nontrivial to get full test coverage for the exhaustive tests. We therefore+ * (arbitrarily) set r2 = k + 5 (mod n) and r1 = k - r2 * lambda (mod n).+ */+static void secp256k1_scalar_split_lambda(secp256k1_scalar * SECP256K1_RESTRICT r1, secp256k1_scalar * SECP256K1_RESTRICT r2, const secp256k1_scalar * SECP256K1_RESTRICT k) {+    SECP256K1_SCALAR_VERIFY(k);+    VERIFY_CHECK(r1 != k);+    VERIFY_CHECK(r2 != k);+    VERIFY_CHECK(r1 != r2);++    *r2 = (*k + 5) % EXHAUSTIVE_TEST_ORDER;+    *r1 = (*k + (EXHAUSTIVE_TEST_ORDER - *r2) * EXHAUSTIVE_TEST_LAMBDA) % EXHAUSTIVE_TEST_ORDER;++    SECP256K1_SCALAR_VERIFY(r1);+    SECP256K1_SCALAR_VERIFY(r2);+}+#else+/**+ * The Secp256k1 curve has an endomorphism, where lambda * (x, y) = (beta * x, y), where+ * lambda is: */+static const secp256k1_scalar secp256k1_const_lambda = SECP256K1_SCALAR_CONST(+    0x5363AD4CUL, 0xC05C30E0UL, 0xA5261C02UL, 0x8812645AUL,+    0x122E22EAUL, 0x20816678UL, 0xDF02967CUL, 0x1B23BD72UL+);++#ifdef VERIFY+static void secp256k1_scalar_split_lambda_verify(const secp256k1_scalar *r1, const secp256k1_scalar *r2, const secp256k1_scalar *k);+#endif++/*+ * Both lambda and beta are primitive cube roots of unity.  That is lamba^3 == 1 mod n and+ * beta^3 == 1 mod p, where n is the curve order and p is the field order.+ *+ * Furthermore, because (X^3 - 1) = (X - 1)(X^2 + X + 1), the primitive cube roots of unity are+ * roots of X^2 + X + 1.  Therefore lambda^2 + lamba == -1 mod n and beta^2 + beta == -1 mod p.+ * (The other primitive cube roots of unity are lambda^2 and beta^2 respectively.)+ *+ * Let l = -1/2 + i*sqrt(3)/2, the complex root of X^2 + X + 1. We can define a ring+ * homomorphism phi : Z[l] -> Z_n where phi(a + b*l) == a + b*lambda mod n. The kernel of phi+ * is a lattice over Z[l] (considering Z[l] as a Z-module). This lattice is generated by a+ * reduced basis {a1 + b1*l, a2 + b2*l} where+ *+ * - a1 =      {0x30,0x86,0xd2,0x21,0xa7,0xd4,0x6b,0xcd,0xe8,0x6c,0x90,0xe4,0x92,0x84,0xeb,0x15}+ * - b1 =     -{0xe4,0x43,0x7e,0xd6,0x01,0x0e,0x88,0x28,0x6f,0x54,0x7f,0xa9,0x0a,0xbf,0xe4,0xc3}+ * - a2 = {0x01,0x14,0xca,0x50,0xf7,0xa8,0xe2,0xf3,0xf6,0x57,0xc1,0x10,0x8d,0x9d,0x44,0xcf,0xd8}+ * - b2 =      {0x30,0x86,0xd2,0x21,0xa7,0xd4,0x6b,0xcd,0xe8,0x6c,0x90,0xe4,0x92,0x84,0xeb,0x15}+ *+ * "Guide to Elliptic Curve Cryptography" (Hankerson, Menezes, Vanstone) gives an algorithm+ * (algorithm 3.74) to find k1 and k2 given k, such that k1 + k2 * lambda == k mod n, and k1+ * and k2 are small in absolute value.+ *+ * The algorithm computes c1 = round(b2 * k / n) and c2 = round((-b1) * k / n), and gives+ * k1 = k - (c1*a1 + c2*a2) and k2 = -(c1*b1 + c2*b2). Instead, we use modular arithmetic, and+ * compute r2 = k2 mod n, and r1 = k1 mod n = (k - r2 * lambda) mod n, avoiding the need for+ * the constants a1 and a2.+ *+ * g1, g2 are precomputed constants used to replace division with a rounded multiplication+ * when decomposing the scalar for an endomorphism-based point multiplication.+ *+ * The possibility of using precomputed estimates is mentioned in "Guide to Elliptic Curve+ * Cryptography" (Hankerson, Menezes, Vanstone) in section 3.5.+ *+ * The derivation is described in the paper "Efficient Software Implementation of Public-Key+ * Cryptography on Sensor Networks Using the MSP430X Microcontroller" (Gouvea, Oliveira, Lopez),+ * Section 4.3 (here we use a somewhat higher-precision estimate):+ * d = a1*b2 - b1*a2+ * g1 = round(2^384 * b2/d)+ * g2 = round(2^384 * (-b1)/d)+ *+ * (Note that d is also equal to the curve order, n, here because [a1,b1] and [a2,b2]+ * can be found as outputs of the Extended Euclidean Algorithm on inputs n and lambda).+ *+ * The function below splits k into r1 and r2, such that+ * - r1 + lambda * r2 == k (mod n)+ * - either r1 < 2^128 or -r1 mod n < 2^128+ * - either r2 < 2^128 or -r2 mod n < 2^128+ *+ * See proof below.+ */+static void secp256k1_scalar_split_lambda(secp256k1_scalar * SECP256K1_RESTRICT r1, secp256k1_scalar * SECP256K1_RESTRICT r2, const secp256k1_scalar * SECP256K1_RESTRICT k) {+    secp256k1_scalar c1, c2;+    static const secp256k1_scalar minus_b1 = SECP256K1_SCALAR_CONST(+        0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL,+        0xE4437ED6UL, 0x010E8828UL, 0x6F547FA9UL, 0x0ABFE4C3UL+    );+    static const secp256k1_scalar minus_b2 = SECP256K1_SCALAR_CONST(+        0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFEUL,+        0x8A280AC5UL, 0x0774346DUL, 0xD765CDA8UL, 0x3DB1562CUL+    );+    static const secp256k1_scalar g1 = SECP256K1_SCALAR_CONST(+        0x3086D221UL, 0xA7D46BCDUL, 0xE86C90E4UL, 0x9284EB15UL,+        0x3DAA8A14UL, 0x71E8CA7FUL, 0xE893209AUL, 0x45DBB031UL+    );+    static const secp256k1_scalar g2 = SECP256K1_SCALAR_CONST(+        0xE4437ED6UL, 0x010E8828UL, 0x6F547FA9UL, 0x0ABFE4C4UL,+        0x221208ACUL, 0x9DF506C6UL, 0x1571B4AEUL, 0x8AC47F71UL+    );+    SECP256K1_SCALAR_VERIFY(k);+    VERIFY_CHECK(r1 != k);+    VERIFY_CHECK(r2 != k);+    VERIFY_CHECK(r1 != r2);++    /* these _var calls are constant time since the shift amount is constant */+    secp256k1_scalar_mul_shift_var(&c1, k, &g1, 384);+    secp256k1_scalar_mul_shift_var(&c2, k, &g2, 384);+    secp256k1_scalar_mul(&c1, &c1, &minus_b1);+    secp256k1_scalar_mul(&c2, &c2, &minus_b2);+    secp256k1_scalar_add(r2, &c1, &c2);+    secp256k1_scalar_mul(r1, r2, &secp256k1_const_lambda);+    secp256k1_scalar_negate(r1, r1);+    secp256k1_scalar_add(r1, r1, k);++    SECP256K1_SCALAR_VERIFY(r1);+    SECP256K1_SCALAR_VERIFY(r2);+#ifdef VERIFY+    secp256k1_scalar_split_lambda_verify(r1, r2, k);+#endif+}++#ifdef VERIFY+/*+ * Proof for secp256k1_scalar_split_lambda's bounds.+ *+ * Let+ *  - epsilon1 = 2^256 * |g1/2^384 - b2/d|+ *  - epsilon2 = 2^256 * |g2/2^384 - (-b1)/d|+ *  - c1 = round(k*g1/2^384)+ *  - c2 = round(k*g2/2^384)+ *+ * Lemma 1: |c1 - k*b2/d| < 2^-1 + epsilon1+ *+ *    |c1 - k*b2/d|+ *  =+ *    |c1 - k*g1/2^384 + k*g1/2^384 - k*b2/d|+ * <=   {triangle inequality}+ *    |c1 - k*g1/2^384| + |k*g1/2^384 - k*b2/d|+ *  =+ *    |c1 - k*g1/2^384| + k*|g1/2^384 - b2/d|+ * <    {rounding in c1 and 0 <= k < 2^256}+ *    2^-1 + 2^256 * |g1/2^384 - b2/d|+ *  =   {definition of epsilon1}+ *    2^-1 + epsilon1+ *+ * Lemma 2: |c2 - k*(-b1)/d| < 2^-1 + epsilon2+ *+ *    |c2 - k*(-b1)/d|+ *  =+ *    |c2 - k*g2/2^384 + k*g2/2^384 - k*(-b1)/d|+ * <=   {triangle inequality}+ *    |c2 - k*g2/2^384| + |k*g2/2^384 - k*(-b1)/d|+ *  =+ *    |c2 - k*g2/2^384| + k*|g2/2^384 - (-b1)/d|+ * <    {rounding in c2 and 0 <= k < 2^256}+ *    2^-1 + 2^256 * |g2/2^384 - (-b1)/d|+ *  =   {definition of epsilon2}+ *    2^-1 + epsilon2+ *+ * Let+ *  - k1 = k - c1*a1 - c2*a2+ *  - k2 = - c1*b1 - c2*b2+ *+ * Lemma 3: |k1| < (a1 + a2 + 1)/2 < 2^128+ *+ *    |k1|+ *  =   {definition of k1}+ *    |k - c1*a1 - c2*a2|+ *  =   {(a1*b2 - b1*a2)/n = 1}+ *    |k*(a1*b2 - b1*a2)/n - c1*a1 - c2*a2|+ *  =+ *    |a1*(k*b2/n - c1) + a2*(k*(-b1)/n - c2)|+ * <=   {triangle inequality}+ *    a1*|k*b2/n - c1| + a2*|k*(-b1)/n - c2|+ * <    {Lemma 1 and Lemma 2}+ *    a1*(2^-1 + epsilon1) + a2*(2^-1 + epsilon2)+ * <    {rounding up to an integer}+ *    (a1 + a2 + 1)/2+ * <    {rounding up to a power of 2}+ *    2^128+ *+ * Lemma 4: |k2| < (-b1 + b2)/2 + 1 < 2^128+ *+ *    |k2|+ *  =   {definition of k2}+ *    |- c1*a1 - c2*a2|+ *  =   {(b1*b2 - b1*b2)/n = 0}+ *    |k*(b1*b2 - b1*b2)/n - c1*b1 - c2*b2|+ *  =+ *    |b1*(k*b2/n - c1) + b2*(k*(-b1)/n - c2)|+ * <=   {triangle inequality}+ *    (-b1)*|k*b2/n - c1| + b2*|k*(-b1)/n - c2|+ * <    {Lemma 1 and Lemma 2}+ *    (-b1)*(2^-1 + epsilon1) + b2*(2^-1 + epsilon2)+ * <    {rounding up to an integer}+ *    (-b1 + b2)/2 + 1+ * <    {rounding up to a power of 2}+ *    2^128+ *+ * Let+ *  - r2 = k2 mod n+ *  - r1 = k - r2*lambda mod n.+ *+ * Notice that r1 is defined such that r1 + r2 * lambda == k (mod n).+ *+ * Lemma 5: r1 == k1 mod n.+ *+ *    r1+ * ==   {definition of r1 and r2}+ *    k - k2*lambda+ * ==   {definition of k2}+ *    k - (- c1*b1 - c2*b2)*lambda+ * ==+ *    k + c1*b1*lambda + c2*b2*lambda+ * ==  {a1 + b1*lambda == 0 mod n and a2 + b2*lambda == 0 mod n}+ *    k - c1*a1 - c2*a2+ * ==  {definition of k1}+ *    k1+ *+ * From Lemma 3, Lemma 4, Lemma 5 and the definition of r2, we can conclude that+ *+ *  - either r1 < 2^128 or -r1 mod n < 2^128+ *  - either r2 < 2^128 or -r2 mod n < 2^128.+ *+ * Q.E.D.+ */+static void secp256k1_scalar_split_lambda_verify(const secp256k1_scalar *r1, const secp256k1_scalar *r2, const secp256k1_scalar *k) {+    secp256k1_scalar s;+    unsigned char buf1[32];+    unsigned char buf2[32];++    /* (a1 + a2 + 1)/2 is 0xa2a8918ca85bafe22016d0b917e4dd77 */+    static const unsigned char k1_bound[32] = {+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+        0xa2, 0xa8, 0x91, 0x8c, 0xa8, 0x5b, 0xaf, 0xe2, 0x20, 0x16, 0xd0, 0xb9, 0x17, 0xe4, 0xdd, 0x77+    };++    /* (-b1 + b2)/2 + 1 is 0x8a65287bd47179fb2be08846cea267ed */+    static const unsigned char k2_bound[32] = {+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+        0x8a, 0x65, 0x28, 0x7b, 0xd4, 0x71, 0x79, 0xfb, 0x2b, 0xe0, 0x88, 0x46, 0xce, 0xa2, 0x67, 0xed+    };++    secp256k1_scalar_mul(&s, &secp256k1_const_lambda, r2);+    secp256k1_scalar_add(&s, &s, r1);+    VERIFY_CHECK(secp256k1_scalar_eq(&s, k));++    secp256k1_scalar_negate(&s, r1);+    secp256k1_scalar_get_b32(buf1, r1);+    secp256k1_scalar_get_b32(buf2, &s);+    VERIFY_CHECK(secp256k1_memcmp_var(buf1, k1_bound, 32) < 0 || secp256k1_memcmp_var(buf2, k1_bound, 32) < 0);++    secp256k1_scalar_negate(&s, r2);+    secp256k1_scalar_get_b32(buf1, r2);+    secp256k1_scalar_get_b32(buf2, &s);+    VERIFY_CHECK(secp256k1_memcmp_var(buf1, k2_bound, 32) < 0 || secp256k1_memcmp_var(buf2, k2_bound, 32) < 0);+}+#endif /* VERIFY */+#endif /* !defined(EXHAUSTIVE_TEST_ORDER) */++#endif /* SECP256K1_SCALAR_IMPL_H */
+ vendor/external/secp256k1/src/scratch.h view
@@ -0,0 +1,44 @@+/***********************************************************************+ * Copyright (c) 2017 Andrew Poelstra                                  *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_SCRATCH_H+#define SECP256K1_SCRATCH_H++/* The typedef is used internally; the struct name is used in the public API+ * (where it is exposed as a different typedef) */+typedef struct secp256k1_scratch_space_struct {+    /** guard against interpreting this object as other types */+    unsigned char magic[8];+    /** actual allocated data */+    void *data;+    /** amount that has been allocated (i.e. `data + offset` is the next+     *  available pointer)  */+    size_t alloc_size;+    /** maximum size available to allocate */+    size_t max_size;+} secp256k1_scratch;++typedef struct secp256k1_scratch_space_struct secp256k1_scratch_space;++static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t max_size);++static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch);++/** Returns an opaque object used to "checkpoint" a scratch space. Used+ *  with `secp256k1_scratch_apply_checkpoint` to undo allocations. */+static size_t secp256k1_scratch_checkpoint(const secp256k1_callback* error_callback, const secp256k1_scratch* scratch);++/** Applies a check point received from `secp256k1_scratch_checkpoint`,+ *  undoing all allocations since that point. */+static void secp256k1_scratch_apply_checkpoint(const secp256k1_callback* error_callback, secp256k1_scratch* scratch, size_t checkpoint);++/** Returns the maximum allocation the scratch space will allow */+static size_t secp256k1_scratch_max_allocation(const secp256k1_callback* error_callback, const secp256k1_scratch* scratch, size_t n_objects);++/** Returns a pointer into the most recently allocated frame, or NULL if there is insufficient available space */+static void *secp256k1_scratch_alloc(const secp256k1_callback* error_callback, secp256k1_scratch* scratch, size_t n);++#endif
+ vendor/external/secp256k1/src/scratch_impl.h view
@@ -0,0 +1,99 @@+/***********************************************************************+ * Copyright (c) 2017 Andrew Poelstra                                  *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_SCRATCH_IMPL_H+#define SECP256K1_SCRATCH_IMPL_H++#include "util.h"+#include "scratch.h"++static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {+    const size_t base_alloc = ROUND_TO_ALIGN(sizeof(secp256k1_scratch));+    void *alloc = checked_malloc(error_callback, base_alloc + size);+    secp256k1_scratch* ret = (secp256k1_scratch *)alloc;+    if (ret != NULL) {+        memset(ret, 0, sizeof(*ret));+        memcpy(ret->magic, "scratch", 8);+        ret->data = (void *) ((char *) alloc + base_alloc);+        ret->max_size = size;+    }+    return ret;+}++static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch) {+    if (scratch != NULL) {+        if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {+            secp256k1_callback_call(error_callback, "invalid scratch space");+            return;+        }+        VERIFY_CHECK(scratch->alloc_size == 0); /* all checkpoints should be applied */+        memset(scratch->magic, 0, sizeof(scratch->magic));+        free(scratch);+    }+}++static size_t secp256k1_scratch_checkpoint(const secp256k1_callback* error_callback, const secp256k1_scratch* scratch) {+    if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {+        secp256k1_callback_call(error_callback, "invalid scratch space");+        return 0;+    }+    return scratch->alloc_size;+}++static void secp256k1_scratch_apply_checkpoint(const secp256k1_callback* error_callback, secp256k1_scratch* scratch, size_t checkpoint) {+    if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {+        secp256k1_callback_call(error_callback, "invalid scratch space");+        return;+    }+    if (checkpoint > scratch->alloc_size) {+        secp256k1_callback_call(error_callback, "invalid checkpoint");+        return;+    }+    scratch->alloc_size = checkpoint;+}++static size_t secp256k1_scratch_max_allocation(const secp256k1_callback* error_callback, const secp256k1_scratch* scratch, size_t objects) {+    if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {+        secp256k1_callback_call(error_callback, "invalid scratch space");+        return 0;+    }+    /* Ensure that multiplication will not wrap around */+    if (ALIGNMENT > 1 && objects > SIZE_MAX/(ALIGNMENT - 1)) {+        return 0;+    }+    if (scratch->max_size - scratch->alloc_size <= objects * (ALIGNMENT - 1)) {+        return 0;+    }+    return scratch->max_size - scratch->alloc_size - objects * (ALIGNMENT - 1);+}++static void *secp256k1_scratch_alloc(const secp256k1_callback* error_callback, secp256k1_scratch* scratch, size_t size) {+    void *ret;+    size_t rounded_size;++    rounded_size = ROUND_TO_ALIGN(size);+    /* Check that rounding did not wrap around */+    if (rounded_size < size) {+        return NULL;+    }+    size = rounded_size;++    if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {+        secp256k1_callback_call(error_callback, "invalid scratch space");+        return NULL;+    }++    if (size > scratch->max_size - scratch->alloc_size) {+        return NULL;+    }+    ret = (void *) ((char *) scratch->data + scratch->alloc_size);+    memset(ret, 0, size);+    scratch->alloc_size += size;++    return ret;+}++#endif
+ vendor/external/secp256k1/src/secp256k1.c view
@@ -0,0 +1,831 @@+/***********************************************************************+ * Copyright (c) 2013-2015 Pieter Wuille                               *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++/* This is a C project. It should not be compiled with a C++ compiler,+ * and we error out if we detect one.+ *+ * We still want to be able to test the project with a C++ compiler+ * because it is still good to know if this will lead to real trouble, so+ * there is a possibility to override the check. But be warned that+ * compiling with a C++ compiler is not supported. */+#if defined(__cplusplus) && !defined(SECP256K1_CPLUSPLUS_TEST_OVERRIDE)+#error Trying to compile a C project with a C++ compiler.+#endif++#define SECP256K1_BUILD++#include "../include/secp256k1.h"+#include "../include/secp256k1_preallocated.h"++#include "assumptions.h"+#include "checkmem.h"+#include "util.h"++#include "field_impl.h"+#include "scalar_impl.h"+#include "group_impl.h"+#include "ecmult_impl.h"+#include "ecmult_const_impl.h"+#include "ecmult_gen_impl.h"+#include "ecdsa_impl.h"+#include "eckey_impl.h"+#include "hash_impl.h"+#include "int128_impl.h"+#include "scratch_impl.h"+#include "selftest.h"+#include "hsort_impl.h"++#ifdef SECP256K1_NO_BUILD+# error "secp256k1.h processed without SECP256K1_BUILD defined while building secp256k1.c"+#endif++#define ARG_CHECK(cond) do { \+    if (EXPECT(!(cond), 0)) { \+        secp256k1_callback_call(&ctx->illegal_callback, #cond); \+        return 0; \+    } \+} while(0)++#define ARG_CHECK_VOID(cond) do { \+    if (EXPECT(!(cond), 0)) { \+        secp256k1_callback_call(&ctx->illegal_callback, #cond); \+        return; \+    } \+} while(0)++/* Note that whenever you change the context struct, you must also change the+ * context_eq function. */+struct secp256k1_context_struct {+    secp256k1_ecmult_gen_context ecmult_gen_ctx;+    secp256k1_callback illegal_callback;+    secp256k1_callback error_callback;+    int declassify;+};++static const secp256k1_context secp256k1_context_static_ = {+    { 0 },+    { secp256k1_default_illegal_callback_fn, 0 },+    { secp256k1_default_error_callback_fn, 0 },+    0+};+const secp256k1_context *secp256k1_context_static = &secp256k1_context_static_;+const secp256k1_context *secp256k1_context_no_precomp = &secp256k1_context_static_;++/* Helper function that determines if a context is proper, i.e., is not the static context or a copy thereof.+ *+ * This is intended for "context" functions such as secp256k1_context_clone. Functions that need specific+ * features of a context should still check for these features directly. For example, a function that needs+ * ecmult_gen should directly check for the existence of the ecmult_gen context. */+static int secp256k1_context_is_proper(const secp256k1_context* ctx) {+    return secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx);+}++void secp256k1_selftest(void) {+    if (!secp256k1_selftest_passes()) {+        secp256k1_callback_call(&default_error_callback, "self test failed");+    }+}++size_t secp256k1_context_preallocated_size(unsigned int flags) {+    size_t ret = sizeof(secp256k1_context);+    /* A return value of 0 is reserved as an indicator for errors when we call this function internally. */+    VERIFY_CHECK(ret != 0);++    if (EXPECT((flags & SECP256K1_FLAGS_TYPE_MASK) != SECP256K1_FLAGS_TYPE_CONTEXT, 0)) {+            secp256k1_callback_call(&default_illegal_callback,+                                    "Invalid flags");+            return 0;+    }++    if (EXPECT(!SECP256K1_CHECKMEM_RUNNING() && (flags & SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY), 0)) {+            secp256k1_callback_call(&default_illegal_callback,+                                    "Declassify flag requires running with memory checking");+            return 0;+    }++    return ret;+}++size_t secp256k1_context_preallocated_clone_size(const secp256k1_context* ctx) {+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(secp256k1_context_is_proper(ctx));+    return sizeof(secp256k1_context);+}++secp256k1_context* secp256k1_context_preallocated_create(void* prealloc, unsigned int flags) {+    size_t prealloc_size;+    secp256k1_context* ret;++    secp256k1_selftest();++    prealloc_size = secp256k1_context_preallocated_size(flags);+    if (prealloc_size == 0) {+        return NULL;+    }+    VERIFY_CHECK(prealloc != NULL);+    ret = (secp256k1_context*)prealloc;+    ret->illegal_callback = default_illegal_callback;+    ret->error_callback = default_error_callback;++    /* Flags have been checked by secp256k1_context_preallocated_size. */+    VERIFY_CHECK((flags & SECP256K1_FLAGS_TYPE_MASK) == SECP256K1_FLAGS_TYPE_CONTEXT);+    secp256k1_ecmult_gen_context_build(&ret->ecmult_gen_ctx);+    ret->declassify = !!(flags & SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY);++    return ret;+}++secp256k1_context* secp256k1_context_create(unsigned int flags) {+    size_t const prealloc_size = secp256k1_context_preallocated_size(flags);+    secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);+    if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {+        free(ctx);+        return NULL;+    }++    return ctx;+}++secp256k1_context* secp256k1_context_preallocated_clone(const secp256k1_context* ctx, void* prealloc) {+    secp256k1_context* ret;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(prealloc != NULL);+    ARG_CHECK(secp256k1_context_is_proper(ctx));++    ret = (secp256k1_context*)prealloc;+    *ret = *ctx;+    return ret;+}++secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {+    secp256k1_context* ret;+    size_t prealloc_size;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(secp256k1_context_is_proper(ctx));++    prealloc_size = secp256k1_context_preallocated_clone_size(ctx);+    ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);+    ret = secp256k1_context_preallocated_clone(ctx, ret);+    return ret;+}++void secp256k1_context_preallocated_destroy(secp256k1_context* ctx) {+    ARG_CHECK_VOID(ctx == NULL || secp256k1_context_is_proper(ctx));++    /* Defined as noop */+    if (ctx == NULL) {+        return;+    }++    secp256k1_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx);+}++void secp256k1_context_destroy(secp256k1_context* ctx) {+    ARG_CHECK_VOID(ctx == NULL || secp256k1_context_is_proper(ctx));++    /* Defined as noop */+    if (ctx == NULL) {+        return;+    }++    secp256k1_context_preallocated_destroy(ctx);+    free(ctx);+}++void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {+    /* We compare pointers instead of checking secp256k1_context_is_proper() here+       because setting callbacks is allowed on *copies* of the static context:+       it's harmless and makes testing easier. */+    ARG_CHECK_VOID(ctx != secp256k1_context_static);+    if (fun == NULL) {+        fun = secp256k1_default_illegal_callback_fn;+    }+    ctx->illegal_callback.fn = fun;+    ctx->illegal_callback.data = data;+}++void secp256k1_context_set_error_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {+    /* We compare pointers instead of checking secp256k1_context_is_proper() here+       because setting callbacks is allowed on *copies* of the static context:+       it's harmless and makes testing easier. */+    ARG_CHECK_VOID(ctx != secp256k1_context_static);+    if (fun == NULL) {+        fun = secp256k1_default_error_callback_fn;+    }+    ctx->error_callback.fn = fun;+    ctx->error_callback.data = data;+}++static secp256k1_scratch_space* secp256k1_scratch_space_create(const secp256k1_context* ctx, size_t max_size) {+    VERIFY_CHECK(ctx != NULL);+    return secp256k1_scratch_create(&ctx->error_callback, max_size);+}++static void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space* scratch) {+    VERIFY_CHECK(ctx != NULL);+    secp256k1_scratch_destroy(&ctx->error_callback, scratch);+}++/* Mark memory as no-longer-secret for the purpose of analysing constant-time behaviour+ *  of the software.+ */+static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context* ctx, const void *p, size_t len) {+    if (EXPECT(ctx->declassify, 0)) SECP256K1_CHECKMEM_DEFINE(p, len);+}++static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge, const secp256k1_pubkey* pubkey) {+    secp256k1_ge_from_bytes(ge, pubkey->data);+    ARG_CHECK(!secp256k1_fe_is_zero(&ge->x));+    return 1;+}++static void secp256k1_pubkey_save(secp256k1_pubkey* pubkey, secp256k1_ge* ge) {+    secp256k1_ge_to_bytes(pubkey->data, ge);+}++int secp256k1_ec_pubkey_parse(const secp256k1_context* ctx, secp256k1_pubkey* pubkey, const unsigned char *input, size_t inputlen) {+    secp256k1_ge Q;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubkey != NULL);+    memset(pubkey, 0, sizeof(*pubkey));+    ARG_CHECK(input != NULL);+    if (!secp256k1_eckey_pubkey_parse(&Q, input, inputlen)) {+        return 0;+    }+    if (!secp256k1_ge_is_in_correct_subgroup(&Q)) {+        return 0;+    }+    secp256k1_pubkey_save(pubkey, &Q);+    secp256k1_ge_clear(&Q);+    return 1;+}++int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey* pubkey, unsigned int flags) {+    secp256k1_ge Q;+    size_t len;+    int ret = 0;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(outputlen != NULL);+    ARG_CHECK(*outputlen >= ((flags & SECP256K1_FLAGS_BIT_COMPRESSION) ? 33u : 65u));+    len = *outputlen;+    *outputlen = 0;+    ARG_CHECK(output != NULL);+    memset(output, 0, len);+    ARG_CHECK(pubkey != NULL);+    ARG_CHECK((flags & SECP256K1_FLAGS_TYPE_MASK) == SECP256K1_FLAGS_TYPE_COMPRESSION);+    if (secp256k1_pubkey_load(ctx, &Q, pubkey)) {+        ret = secp256k1_eckey_pubkey_serialize(&Q, output, &len, flags & SECP256K1_FLAGS_BIT_COMPRESSION);+        if (ret) {+            *outputlen = len;+        }+    }+    return ret;+}++int secp256k1_ec_pubkey_cmp(const secp256k1_context* ctx, const secp256k1_pubkey* pubkey0, const secp256k1_pubkey* pubkey1) {+    unsigned char out[2][33];+    const secp256k1_pubkey* pk[2];+    int i;++    VERIFY_CHECK(ctx != NULL);+    pk[0] = pubkey0; pk[1] = pubkey1;+    for (i = 0; i < 2; i++) {+        size_t out_size = sizeof(out[i]);+        /* If the public key is NULL or invalid, ec_pubkey_serialize will call+         * the illegal_callback and return 0. In that case we will serialize the+         * key as all zeros which is less than any valid public key. This+         * results in consistent comparisons even if NULL or invalid pubkeys are+         * involved and prevents edge cases such as sorting algorithms that use+         * this function and do not terminate as a result. */+        if (!secp256k1_ec_pubkey_serialize(ctx, out[i], &out_size, pk[i], SECP256K1_EC_COMPRESSED)) {+            /* Note that ec_pubkey_serialize should already set the output to+             * zero in that case, but it's not guaranteed by the API, we can't+             * test it and writing a VERIFY_CHECK is more complex than+             * explicitly memsetting (again). */+            memset(out[i], 0, sizeof(out[i]));+        }+    }+    return secp256k1_memcmp_var(out[0], out[1], sizeof(out[0]));+}++static int secp256k1_ec_pubkey_sort_cmp(const void* pk1, const void* pk2, void *ctx) {+    return secp256k1_ec_pubkey_cmp((secp256k1_context *)ctx,+                                     *(secp256k1_pubkey **)pk1,+                                     *(secp256k1_pubkey **)pk2);+}++int secp256k1_ec_pubkey_sort(const secp256k1_context* ctx, const secp256k1_pubkey **pubkeys, size_t n_pubkeys) {+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubkeys != NULL);++    /* Suppress wrong warning (fixed in MSVC 19.33) */+    #if defined(_MSC_VER) && (_MSC_VER < 1933)+    #pragma warning(push)+    #pragma warning(disable: 4090)+    #endif++    /* Casting away const is fine because neither secp256k1_hsort nor+     * secp256k1_ec_pubkey_sort_cmp modify the data pointed to by the cmp_data+     * argument. */+    secp256k1_hsort(pubkeys, n_pubkeys, sizeof(*pubkeys), secp256k1_ec_pubkey_sort_cmp, (void *)ctx);++    #if defined(_MSC_VER) && (_MSC_VER < 1933)+    #pragma warning(pop)+    #endif++    return 1;+}++static void secp256k1_ecdsa_signature_load(const secp256k1_context* ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_ecdsa_signature* sig) {+    (void)ctx;+    if (sizeof(secp256k1_scalar) == 32) {+        /* When the secp256k1_scalar type is exactly 32 byte, use its+         * representation inside secp256k1_ecdsa_signature, as conversion is very fast.+         * Note that secp256k1_ecdsa_signature_save must use the same representation. */+        memcpy(r, &sig->data[0], 32);+        memcpy(s, &sig->data[32], 32);+    } else {+        secp256k1_scalar_set_b32(r, &sig->data[0], NULL);+        secp256k1_scalar_set_b32(s, &sig->data[32], NULL);+    }+}++static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature* sig, const secp256k1_scalar* r, const secp256k1_scalar* s) {+    if (sizeof(secp256k1_scalar) == 32) {+        memcpy(&sig->data[0], r, 32);+        memcpy(&sig->data[32], s, 32);+    } else {+        secp256k1_scalar_get_b32(&sig->data[0], r);+        secp256k1_scalar_get_b32(&sig->data[32], s);+    }+}++int secp256k1_ecdsa_signature_parse_der(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {+    secp256k1_scalar r, s;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(sig != NULL);+    ARG_CHECK(input != NULL);++    if (secp256k1_ecdsa_sig_parse(&r, &s, input, inputlen)) {+        secp256k1_ecdsa_signature_save(sig, &r, &s);+        return 1;+    } else {+        memset(sig, 0, sizeof(*sig));+        return 0;+    }+}++int secp256k1_ecdsa_signature_parse_compact(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input64) {+    secp256k1_scalar r, s;+    int ret = 1;+    int overflow = 0;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(sig != NULL);+    ARG_CHECK(input64 != NULL);++    secp256k1_scalar_set_b32(&r, &input64[0], &overflow);+    ret &= !overflow;+    secp256k1_scalar_set_b32(&s, &input64[32], &overflow);+    ret &= !overflow;+    if (ret) {+        secp256k1_ecdsa_signature_save(sig, &r, &s);+    } else {+        memset(sig, 0, sizeof(*sig));+    }+    return ret;+}++int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature* sig) {+    secp256k1_scalar r, s;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(output != NULL);+    ARG_CHECK(outputlen != NULL);+    ARG_CHECK(sig != NULL);++    secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);+    return secp256k1_ecdsa_sig_serialize(output, outputlen, &r, &s);+}++int secp256k1_ecdsa_signature_serialize_compact(const secp256k1_context* ctx, unsigned char *output64, const secp256k1_ecdsa_signature* sig) {+    secp256k1_scalar r, s;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(output64 != NULL);+    ARG_CHECK(sig != NULL);++    secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);+    secp256k1_scalar_get_b32(&output64[0], &r);+    secp256k1_scalar_get_b32(&output64[32], &s);+    return 1;+}++int secp256k1_ecdsa_signature_normalize(const secp256k1_context* ctx, secp256k1_ecdsa_signature *sigout, const secp256k1_ecdsa_signature *sigin) {+    secp256k1_scalar r, s;+    int ret = 0;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(sigin != NULL);++    secp256k1_ecdsa_signature_load(ctx, &r, &s, sigin);+    ret = secp256k1_scalar_is_high(&s);+    if (sigout != NULL) {+        if (ret) {+            secp256k1_scalar_negate(&s, &s);+        }+        secp256k1_ecdsa_signature_save(sigout, &r, &s);+    }++    return ret;+}++int secp256k1_ecdsa_verify(const secp256k1_context* ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const secp256k1_pubkey *pubkey) {+    secp256k1_ge q;+    secp256k1_scalar r, s;+    secp256k1_scalar m;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(msghash32 != NULL);+    ARG_CHECK(sig != NULL);+    ARG_CHECK(pubkey != NULL);++    secp256k1_scalar_set_b32(&m, msghash32, NULL);+    secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);+    return (!secp256k1_scalar_is_high(&s) &&+            secp256k1_pubkey_load(ctx, &q, pubkey) &&+            secp256k1_ecdsa_sig_verify(&r, &s, &q, &m));+}++static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len) {+    memcpy(buf + *offset, data, len);+    *offset += len;+}++static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) {+   unsigned char keydata[112];+   unsigned int offset = 0;+   secp256k1_rfc6979_hmac_sha256 rng;+   unsigned int i;+   secp256k1_scalar msg;+   unsigned char msgmod32[32];+   secp256k1_scalar_set_b32(&msg, msg32, NULL);+   secp256k1_scalar_get_b32(msgmod32, &msg);+   /* We feed a byte array to the PRNG as input, consisting of:+    * - the private key (32 bytes) and reduced message (32 bytes), see RFC 6979 3.2d.+    * - optionally 32 extra bytes of data, see RFC 6979 3.6 Additional Data.+    * - optionally 16 extra bytes with the algorithm name.+    * Because the arguments have distinct fixed lengths it is not possible for+    *  different argument mixtures to emulate each other and result in the same+    *  nonces.+    */+   buffer_append(keydata, &offset, key32, 32);+   buffer_append(keydata, &offset, msgmod32, 32);+   if (data != NULL) {+       buffer_append(keydata, &offset, data, 32);+   }+   if (algo16 != NULL) {+       buffer_append(keydata, &offset, algo16, 16);+   }+   secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, offset);+   for (i = 0; i <= counter; i++) {+       secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);+   }+   secp256k1_rfc6979_hmac_sha256_finalize(&rng);++   secp256k1_memclear(keydata, sizeof(keydata));+   secp256k1_rfc6979_hmac_sha256_clear(&rng);+   return 1;+}++const secp256k1_nonce_function secp256k1_nonce_function_rfc6979 = nonce_function_rfc6979;+const secp256k1_nonce_function secp256k1_nonce_function_default = nonce_function_rfc6979;++static int secp256k1_ecdsa_sign_inner(const secp256k1_context* ctx, secp256k1_scalar* r, secp256k1_scalar* s, int* recid, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void* noncedata) {+    secp256k1_scalar sec, non, msg;+    int ret = 0;+    int is_sec_valid;+    unsigned char nonce32[32];+    unsigned int count = 0;+    /* Default initialization here is important so we won't pass uninit values to the cmov in the end */+    *r = secp256k1_scalar_zero;+    *s = secp256k1_scalar_zero;+    if (recid) {+        *recid = 0;+    }+    if (noncefp == NULL) {+        noncefp = secp256k1_nonce_function_default;+    }++    /* Fail if the secret key is invalid. */+    is_sec_valid = secp256k1_scalar_set_b32_seckey(&sec, seckey);+    secp256k1_scalar_cmov(&sec, &secp256k1_scalar_one, !is_sec_valid);+    secp256k1_scalar_set_b32(&msg, msg32, NULL);+    while (1) {+        int is_nonce_valid;+        ret = !!noncefp(nonce32, msg32, seckey, NULL, (void*)noncedata, count);+        if (!ret) {+            break;+        }+        is_nonce_valid = secp256k1_scalar_set_b32_seckey(&non, nonce32);+        /* The nonce is still secret here, but it being invalid is less likely than 1:2^255. */+        secp256k1_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid));+        if (is_nonce_valid) {+            ret = secp256k1_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, r, s, &sec, &msg, &non, recid);+            /* The final signature is no longer a secret, nor is the fact that we were successful or not. */+            secp256k1_declassify(ctx, &ret, sizeof(ret));+            if (ret) {+                break;+            }+        }+        count++;+    }+    /* We don't want to declassify is_sec_valid and therefore the range of+     * seckey. As a result is_sec_valid is included in ret only after ret was+     * used as a branching variable. */+    ret &= is_sec_valid;+    secp256k1_memclear(nonce32, sizeof(nonce32));+    secp256k1_scalar_clear(&msg);+    secp256k1_scalar_clear(&non);+    secp256k1_scalar_clear(&sec);+    secp256k1_scalar_cmov(r, &secp256k1_scalar_zero, !ret);+    secp256k1_scalar_cmov(s, &secp256k1_scalar_zero, !ret);+    if (recid) {+        const int zero = 0;+        secp256k1_int_cmov(recid, &zero, !ret);+    }+    return ret;+}++int secp256k1_ecdsa_sign(const secp256k1_context* ctx, secp256k1_ecdsa_signature *signature, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void* noncedata) {+    secp256k1_scalar r, s;+    int ret;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));+    ARG_CHECK(msghash32 != NULL);+    ARG_CHECK(signature != NULL);+    ARG_CHECK(seckey != NULL);++    ret = secp256k1_ecdsa_sign_inner(ctx, &r, &s, NULL, msghash32, seckey, noncefp, noncedata);+    secp256k1_ecdsa_signature_save(signature, &r, &s);+    return ret;+}++int secp256k1_ec_seckey_verify(const secp256k1_context* ctx, const unsigned char *seckey) {+    secp256k1_scalar sec;+    int ret;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(seckey != NULL);++    ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);+    secp256k1_scalar_clear(&sec);+    return ret;+}++static int secp256k1_ec_pubkey_create_helper(const secp256k1_ecmult_gen_context *ecmult_gen_ctx, secp256k1_scalar *seckey_scalar, secp256k1_ge *p, const unsigned char *seckey) {+    secp256k1_gej pj;+    int ret;++    ret = secp256k1_scalar_set_b32_seckey(seckey_scalar, seckey);+    secp256k1_scalar_cmov(seckey_scalar, &secp256k1_scalar_one, !ret);++    secp256k1_ecmult_gen(ecmult_gen_ctx, &pj, seckey_scalar);+    secp256k1_ge_set_gej(p, &pj);+    secp256k1_gej_clear(&pj);+    return ret;+}++int secp256k1_ec_pubkey_create(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) {+    secp256k1_ge p;+    secp256k1_scalar seckey_scalar;+    int ret = 0;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubkey != NULL);+    memset(pubkey, 0, sizeof(*pubkey));+    ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));+    ARG_CHECK(seckey != NULL);++    ret = secp256k1_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &seckey_scalar, &p, seckey);+    secp256k1_pubkey_save(pubkey, &p);+    secp256k1_memczero(pubkey, sizeof(*pubkey), !ret);++    secp256k1_scalar_clear(&seckey_scalar);+    return ret;+}++int secp256k1_ec_seckey_negate(const secp256k1_context* ctx, unsigned char *seckey) {+    secp256k1_scalar sec;+    int ret = 0;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(seckey != NULL);++    ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);+    secp256k1_scalar_cmov(&sec, &secp256k1_scalar_zero, !ret);+    secp256k1_scalar_negate(&sec, &sec);+    secp256k1_scalar_get_b32(seckey, &sec);++    secp256k1_scalar_clear(&sec);+    return ret;+}++int secp256k1_ec_privkey_negate(const secp256k1_context* ctx, unsigned char *seckey) {+    return secp256k1_ec_seckey_negate(ctx, seckey);+}++int secp256k1_ec_pubkey_negate(const secp256k1_context* ctx, secp256k1_pubkey *pubkey) {+    int ret = 0;+    secp256k1_ge p;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubkey != NULL);++    ret = secp256k1_pubkey_load(ctx, &p, pubkey);+    memset(pubkey, 0, sizeof(*pubkey));+    if (ret) {+        secp256k1_ge_neg(&p, &p);+        secp256k1_pubkey_save(pubkey, &p);+    }+    return ret;+}+++static int secp256k1_ec_seckey_tweak_add_helper(secp256k1_scalar *sec, const unsigned char *tweak32) {+    secp256k1_scalar term;+    int overflow = 0;+    int ret = 0;++    secp256k1_scalar_set_b32(&term, tweak32, &overflow);+    ret = (!overflow) & secp256k1_eckey_privkey_tweak_add(sec, &term);+    secp256k1_scalar_clear(&term);+    return ret;+}++int secp256k1_ec_seckey_tweak_add(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {+    secp256k1_scalar sec;+    int ret = 0;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(seckey != NULL);+    ARG_CHECK(tweak32 != NULL);++    ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);+    ret &= secp256k1_ec_seckey_tweak_add_helper(&sec, tweak32);+    secp256k1_scalar_cmov(&sec, &secp256k1_scalar_zero, !ret);+    secp256k1_scalar_get_b32(seckey, &sec);++    secp256k1_scalar_clear(&sec);+    return ret;+}++int secp256k1_ec_privkey_tweak_add(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {+    return secp256k1_ec_seckey_tweak_add(ctx, seckey, tweak32);+}++static int secp256k1_ec_pubkey_tweak_add_helper(secp256k1_ge *p, const unsigned char *tweak32) {+    secp256k1_scalar term;+    int overflow = 0;+    secp256k1_scalar_set_b32(&term, tweak32, &overflow);+    return !overflow && secp256k1_eckey_pubkey_tweak_add(p, &term);+}++int secp256k1_ec_pubkey_tweak_add(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) {+    secp256k1_ge p;+    int ret = 0;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubkey != NULL);+    ARG_CHECK(tweak32 != NULL);++    ret = secp256k1_pubkey_load(ctx, &p, pubkey);+    memset(pubkey, 0, sizeof(*pubkey));+    ret = ret && secp256k1_ec_pubkey_tweak_add_helper(&p, tweak32);+    if (ret) {+        secp256k1_pubkey_save(pubkey, &p);+    }++    return ret;+}++int secp256k1_ec_seckey_tweak_mul(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {+    secp256k1_scalar factor;+    secp256k1_scalar sec;+    int ret = 0;+    int overflow = 0;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(seckey != NULL);+    ARG_CHECK(tweak32 != NULL);++    secp256k1_scalar_set_b32(&factor, tweak32, &overflow);+    ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);+    ret &= (!overflow) & secp256k1_eckey_privkey_tweak_mul(&sec, &factor);+    secp256k1_scalar_cmov(&sec, &secp256k1_scalar_zero, !ret);+    secp256k1_scalar_get_b32(seckey, &sec);++    secp256k1_scalar_clear(&sec);+    secp256k1_scalar_clear(&factor);+    return ret;+}++int secp256k1_ec_privkey_tweak_mul(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {+    return secp256k1_ec_seckey_tweak_mul(ctx, seckey, tweak32);+}++int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) {+    secp256k1_ge p;+    secp256k1_scalar factor;+    int ret = 0;+    int overflow = 0;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubkey != NULL);+    ARG_CHECK(tweak32 != NULL);++    secp256k1_scalar_set_b32(&factor, tweak32, &overflow);+    ret = !overflow && secp256k1_pubkey_load(ctx, &p, pubkey);+    memset(pubkey, 0, sizeof(*pubkey));+    if (ret) {+        if (secp256k1_eckey_pubkey_tweak_mul(&p, &factor)) {+            secp256k1_pubkey_save(pubkey, &p);+        } else {+            ret = 0;+        }+    }++    return ret;+}++int secp256k1_context_randomize(secp256k1_context* ctx, const unsigned char *seed32) {+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(secp256k1_context_is_proper(ctx));++    if (secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)) {+        secp256k1_ecmult_gen_blind(&ctx->ecmult_gen_ctx, seed32);+    }+    return 1;+}++int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey *pubnonce, const secp256k1_pubkey * const *pubnonces, size_t n) {+    size_t i;+    secp256k1_gej Qj;+    secp256k1_ge Q;++    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(pubnonce != NULL);+    memset(pubnonce, 0, sizeof(*pubnonce));+    ARG_CHECK(n >= 1);+    ARG_CHECK(pubnonces != NULL);++    secp256k1_gej_set_infinity(&Qj);++    for (i = 0; i < n; i++) {+        ARG_CHECK(pubnonces[i] != NULL);+        secp256k1_pubkey_load(ctx, &Q, pubnonces[i]);+        secp256k1_gej_add_ge(&Qj, &Qj, &Q);+    }+    if (secp256k1_gej_is_infinity(&Qj)) {+        return 0;+    }+    secp256k1_ge_set_gej(&Q, &Qj);+    secp256k1_pubkey_save(pubnonce, &Q);+    return 1;+}++int secp256k1_tagged_sha256(const secp256k1_context* ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, const unsigned char *msg, size_t msglen) {+    secp256k1_sha256 sha;+    VERIFY_CHECK(ctx != NULL);+    ARG_CHECK(hash32 != NULL);+    ARG_CHECK(tag != NULL);+    ARG_CHECK(msg != NULL);++    secp256k1_sha256_initialize_tagged(&sha, tag, taglen);+    secp256k1_sha256_write(&sha, msg, msglen);+    secp256k1_sha256_finalize(&sha, hash32);+    secp256k1_sha256_clear(&sha);+    return 1;+}++#ifdef ENABLE_MODULE_ECDH+# include "modules/ecdh/main_impl.h"+#endif++#ifdef ENABLE_MODULE_RECOVERY+# include "modules/recovery/main_impl.h"+#endif++#ifdef ENABLE_MODULE_EXTRAKEYS+# include "modules/extrakeys/main_impl.h"+#endif++#ifdef ENABLE_MODULE_SCHNORRSIG+# include "modules/schnorrsig/main_impl.h"+#endif++#ifdef ENABLE_MODULE_MUSIG+# include "modules/musig/main_impl.h"+#endif++#ifdef ENABLE_MODULE_ELLSWIFT+# include "modules/ellswift/main_impl.h"+#endif
+ vendor/external/secp256k1/src/selftest.h view
@@ -0,0 +1,32 @@+/***********************************************************************+ * Copyright (c) 2020 Pieter Wuille                                    *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_SELFTEST_H+#define SECP256K1_SELFTEST_H++#include "hash.h"++#include <string.h>++static int secp256k1_selftest_sha256(void) {+    static const char *input63 = "For this sample, this 63-byte string will be used as input data";+    static const unsigned char output32[32] = {+        0xf0, 0x8a, 0x78, 0xcb, 0xba, 0xee, 0x08, 0x2b, 0x05, 0x2a, 0xe0, 0x70, 0x8f, 0x32, 0xfa, 0x1e,+        0x50, 0xc5, 0xc4, 0x21, 0xaa, 0x77, 0x2b, 0xa5, 0xdb, 0xb4, 0x06, 0xa2, 0xea, 0x6b, 0xe3, 0x42,+    };+    unsigned char out[32];+    secp256k1_sha256 hasher;+    secp256k1_sha256_initialize(&hasher);+    secp256k1_sha256_write(&hasher, (const unsigned char*)input63, 63);+    secp256k1_sha256_finalize(&hasher, out);+    return secp256k1_memcmp_var(out, output32, 32) == 0;+}++static int secp256k1_selftest_passes(void) {+    return secp256k1_selftest_sha256();+}++#endif /* SECP256K1_SELFTEST_H */
+ vendor/external/secp256k1/src/util.h view
@@ -0,0 +1,451 @@+/***********************************************************************+ * Copyright (c) 2013, 2014 Pieter Wuille                              *+ * Distributed under the MIT software license, see the accompanying    *+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*+ ***********************************************************************/++#ifndef SECP256K1_UTIL_H+#define SECP256K1_UTIL_H++#include "../include/secp256k1.h"+#include "checkmem.h"++#include <string.h>+#include <stdlib.h>+#include <stdint.h>+#include <stdio.h>+#include <limits.h>+#if defined(_MSC_VER)+/* For SecureZeroMemory */+#include <Windows.h>+#endif++#define STR_(x) #x+#define STR(x) STR_(x)+#define DEBUG_CONFIG_MSG(x) "DEBUG_CONFIG: " x+#define DEBUG_CONFIG_DEF(x) DEBUG_CONFIG_MSG(#x "=" STR(x))++/* Debug helper for printing arrays of unsigned char. */+#define PRINT_BUF(buf, len) do { \+    printf("%s[%lu] = ", #buf, (unsigned long)len); \+    print_buf_plain(buf, len); \+} while(0)++static void print_buf_plain(const unsigned char *buf, size_t len) {+    size_t i;+    printf("{");+    for (i = 0; i < len; i++) {+        if (i % 8 == 0) {+            printf("\n    ");+        } else {+            printf(" ");+        }+        printf("0x%02X,", buf[i]);+    }+    printf("\n}\n");+}++# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )+#  if SECP256K1_GNUC_PREREQ(2,7)+#   define SECP256K1_INLINE __inline__+#  elif (defined(_MSC_VER))+#   define SECP256K1_INLINE __inline+#  else+#   define SECP256K1_INLINE+#  endif+# else+#  define SECP256K1_INLINE inline+# endif++/** Assert statically that expr is true.+ *+ * This is a statement-like macro and can only be used inside functions.+ */+#define STATIC_ASSERT(expr) do { \+    switch(0) { \+        case 0: \+        /* If expr evaluates to 0, we have two case labels "0", which is illegal. */ \+        case /* ERROR: static assertion failed */ (expr): \+        ; \+    } \+} while(0)++/** Assert statically that expr is an integer constant expression, and run stmt.+ *+ * Useful for example to enforce that magnitude arguments are constant.+ */+#define ASSERT_INT_CONST_AND_DO(expr, stmt) do { \+    switch(42) { \+        /* C allows only integer constant expressions as case labels. */ \+        case /* ERROR: integer argument is not constant */ (expr): \+            break; \+        default: ; \+    } \+    stmt; \+} while(0)++typedef struct {+    void (*fn)(const char *text, void* data);+    const void* data;+} secp256k1_callback;++static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback * const cb, const char * const text) {+    cb->fn(text, (void*)cb->data);+}++#ifndef USE_EXTERNAL_DEFAULT_CALLBACKS+static void secp256k1_default_illegal_callback_fn(const char* str, void* data) {+    (void)data;+    fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);+    abort();+}+static void secp256k1_default_error_callback_fn(const char* str, void* data) {+    (void)data;+    fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);+    abort();+}+#else+void secp256k1_default_illegal_callback_fn(const char* str, void* data);+void secp256k1_default_error_callback_fn(const char* str, void* data);+#endif++static const secp256k1_callback default_illegal_callback = {+    secp256k1_default_illegal_callback_fn,+    NULL+};++static const secp256k1_callback default_error_callback = {+    secp256k1_default_error_callback_fn,+    NULL+};+++#ifdef DETERMINISTIC+#define TEST_FAILURE(msg) do { \+    fprintf(stderr, "%s\n", msg); \+    abort(); \+} while(0);+#else+#define TEST_FAILURE(msg) do { \+    fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \+    abort(); \+} while(0)+#endif++#if SECP256K1_GNUC_PREREQ(3, 0)+#define EXPECT(x,c) __builtin_expect((x),(c))+#else+#define EXPECT(x,c) (x)+#endif++#ifdef DETERMINISTIC+#define CHECK(cond) do { \+    if (EXPECT(!(cond), 0)) { \+        TEST_FAILURE("test condition failed"); \+    } \+} while(0)+#else+#define CHECK(cond) do { \+    if (EXPECT(!(cond), 0)) { \+        TEST_FAILURE("test condition failed: " #cond); \+    } \+} while(0)+#endif++/* Like assert(), but when VERIFY is defined. */+#if defined(VERIFY)+#define VERIFY_CHECK CHECK+#else+#define VERIFY_CHECK(cond)+#endif++static SECP256K1_INLINE void *checked_malloc(const secp256k1_callback* cb, size_t size) {+    void *ret = malloc(size);+    if (ret == NULL) {+        secp256k1_callback_call(cb, "Out of memory");+    }+    return ret;+}++#if defined(__BIGGEST_ALIGNMENT__)+#define ALIGNMENT __BIGGEST_ALIGNMENT__+#else+/* Using 16 bytes alignment because common architectures never have alignment+ * requirements above 8 for any of the types we care about. In addition we+ * leave some room because currently we don't care about a few bytes. */+#define ALIGNMENT 16+#endif++/* ceil(x/y) for integers x > 0 and y > 0. Here, / denotes rational division. */+#define CEIL_DIV(x, y) (1 + ((x) - 1) / (y))++#define ROUND_TO_ALIGN(size) (CEIL_DIV(size, ALIGNMENT) * ALIGNMENT)++/* Macro for restrict, when available and not in a VERIFY build. */+#if defined(SECP256K1_BUILD) && defined(VERIFY)+# define SECP256K1_RESTRICT+#else+# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )+#  if SECP256K1_GNUC_PREREQ(3,0)+#   define SECP256K1_RESTRICT __restrict__+#  elif (defined(_MSC_VER) && _MSC_VER >= 1400)+#   define SECP256K1_RESTRICT __restrict+#  else+#   define SECP256K1_RESTRICT+#  endif+# else+#  define SECP256K1_RESTRICT restrict+# endif+#endif++#if defined(__GNUC__)+# define SECP256K1_GNUC_EXT __extension__+#else+# define SECP256K1_GNUC_EXT+#endif++/* Zero memory if flag == 1. Flag must be 0 or 1. Constant time. */+static SECP256K1_INLINE void secp256k1_memczero(void *s, size_t len, int flag) {+    unsigned char *p = (unsigned char *)s;+    /* Access flag with a volatile-qualified lvalue.+       This prevents clang from figuring out (after inlining) that flag can+       take only be 0 or 1, which leads to variable time code. */+    volatile int vflag = flag;+    unsigned char mask = -(unsigned char) vflag;+    while (len) {+        *p &= ~mask;+        p++;+        len--;+    }+}++/* Cleanses memory to prevent leaking sensitive info. Won't be optimized out. */+static SECP256K1_INLINE void secp256k1_memclear(void *ptr, size_t len) {+#if defined(_MSC_VER)+    /* SecureZeroMemory is guaranteed not to be optimized out by MSVC. */+    SecureZeroMemory(ptr, len);+#elif defined(__GNUC__)+    /* We use a memory barrier that scares the compiler away from optimizing out the memset.+     *+     * Quoting Adam Langley <agl@google.com> in commit ad1907fe73334d6c696c8539646c21b11178f20f+     * in BoringSSL (ISC License):+     *    As best as we can tell, this is sufficient to break any optimisations that+     *    might try to eliminate "superfluous" memsets.+     * This method is used in memzero_explicit() the Linux kernel, too. Its advantage is that it+     * is pretty efficient, because the compiler can still implement the memset() efficently,+     * just not remove it entirely. See "Dead Store Elimination (Still) Considered Harmful" by+     * Yang et al. (USENIX Security 2017) for more background.+     */+    memset(ptr, 0, len);+    __asm__ __volatile__("" : : "r"(ptr) : "memory");+#else+    void *(*volatile const volatile_memset)(void *, int, size_t) = memset;+    volatile_memset(ptr, 0, len);+#endif+#ifdef VERIFY+    SECP256K1_CHECKMEM_UNDEFINE(ptr, len);+#endif+}++/** Semantics like memcmp. Variable-time.+ *+ * We use this to avoid possible compiler bugs with memcmp, e.g.+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189+ */+static SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n) {+    const unsigned char *p1 = s1, *p2 = s2;+    size_t i;++    for (i = 0; i < n; i++) {+        int diff = p1[i] - p2[i];+        if (diff != 0) {+            return diff;+        }+    }+    return 0;+}++/* Return 1 if all elements of array s are 0 and otherwise return 0.+ * Constant-time. */+static SECP256K1_INLINE int secp256k1_is_zero_array(const unsigned char *s, size_t len) {+    unsigned char acc = 0;+    int ret;+    size_t i;++    for (i = 0; i < len; i++) {+        acc |= s[i];+    }+    ret = (acc == 0);+    /* acc may contain secret values. Try to explicitly clear it. */+    secp256k1_memclear(&acc, sizeof(acc));+    return ret;+}++/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time.  Both *r and *a must be initialized and non-negative.*/+static SECP256K1_INLINE void secp256k1_int_cmov(int *r, const int *a, int flag) {+    unsigned int mask0, mask1, r_masked, a_masked;+    /* Access flag with a volatile-qualified lvalue.+       This prevents clang from figuring out (after inlining) that flag can+       take only be 0 or 1, which leads to variable time code. */+    volatile int vflag = flag;++    /* Casting a negative int to unsigned and back to int is implementation defined behavior */+    VERIFY_CHECK(*r >= 0 && *a >= 0);++    mask0 = (unsigned int)vflag + ~0u;+    mask1 = ~mask0;+    r_masked = ((unsigned int)*r & mask0);+    a_masked = ((unsigned int)*a & mask1);++    *r = (int)(r_masked | a_masked);+}++#if defined(USE_FORCE_WIDEMUL_INT128_STRUCT)+/* If USE_FORCE_WIDEMUL_INT128_STRUCT is set, use int128_struct. */+# define SECP256K1_WIDEMUL_INT128 1+# define SECP256K1_INT128_STRUCT 1+#elif defined(USE_FORCE_WIDEMUL_INT128)+/* If USE_FORCE_WIDEMUL_INT128 is set, use int128. */+# define SECP256K1_WIDEMUL_INT128 1+# define SECP256K1_INT128_NATIVE 1+#elif defined(USE_FORCE_WIDEMUL_INT64)+/* If USE_FORCE_WIDEMUL_INT64 is set, use int64. */+# define SECP256K1_WIDEMUL_INT64 1+#elif defined(UINT128_MAX) || defined(__SIZEOF_INT128__)+/* If a native 128-bit integer type exists, use int128. */+# define SECP256K1_WIDEMUL_INT128 1+# define SECP256K1_INT128_NATIVE 1+#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64))+/* On 64-bit MSVC targets (x86_64 and arm64), use int128_struct+ * (which has special logic to implement using intrinsics on those systems). */+# define SECP256K1_WIDEMUL_INT128 1+# define SECP256K1_INT128_STRUCT 1+#elif SIZE_MAX > 0xffffffff+/* Systems with 64-bit pointers (and thus registers) very likely benefit from+ * using 64-bit based arithmetic (even if we need to fall back to 32x32->64 based+ * multiplication logic). */+# define SECP256K1_WIDEMUL_INT128 1+# define SECP256K1_INT128_STRUCT 1+#else+/* Lastly, fall back to int64 based arithmetic. */+# define SECP256K1_WIDEMUL_INT64 1+#endif++#ifndef __has_builtin+#define __has_builtin(x) 0+#endif++/* Determine the number of trailing zero bits in a (non-zero) 32-bit x.+ * This function is only intended to be used as fallback for+ * secp256k1_ctz32_var, but permits it to be tested separately. */+static SECP256K1_INLINE int secp256k1_ctz32_var_debruijn(uint32_t x) {+    static const uint8_t debruijn[32] = {+        0x00, 0x01, 0x02, 0x18, 0x03, 0x13, 0x06, 0x19, 0x16, 0x04, 0x14, 0x0A,+        0x10, 0x07, 0x0C, 0x1A, 0x1F, 0x17, 0x12, 0x05, 0x15, 0x09, 0x0F, 0x0B,+        0x1E, 0x11, 0x08, 0x0E, 0x1D, 0x0D, 0x1C, 0x1B+    };+    return debruijn[(uint32_t)((x & -x) * 0x04D7651FU) >> 27];+}++/* Determine the number of trailing zero bits in a (non-zero) 64-bit x.+ * This function is only intended to be used as fallback for+ * secp256k1_ctz64_var, but permits it to be tested separately. */+static SECP256K1_INLINE int secp256k1_ctz64_var_debruijn(uint64_t x) {+    static const uint8_t debruijn[64] = {+        0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,+        62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,+        63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,+        51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12+    };+    return debruijn[(uint64_t)((x & -x) * 0x022FDD63CC95386DU) >> 58];+}++/* Determine the number of trailing zero bits in a (non-zero) 32-bit x. */+static SECP256K1_INLINE int secp256k1_ctz32_var(uint32_t x) {+    VERIFY_CHECK(x != 0);+#if (__has_builtin(__builtin_ctz) || SECP256K1_GNUC_PREREQ(3,4))+    /* If the unsigned type is sufficient to represent the largest uint32_t, consider __builtin_ctz. */+    if (((unsigned)UINT32_MAX) == UINT32_MAX) {+        return __builtin_ctz(x);+    }+#endif+#if (__has_builtin(__builtin_ctzl) || SECP256K1_GNUC_PREREQ(3,4))+    /* Otherwise consider __builtin_ctzl (the unsigned long type is always at least 32 bits). */+    return __builtin_ctzl(x);+#else+    /* If no suitable CTZ builtin is available, use a (variable time) software emulation. */+    return secp256k1_ctz32_var_debruijn(x);+#endif+}++/* Determine the number of trailing zero bits in a (non-zero) 64-bit x. */+static SECP256K1_INLINE int secp256k1_ctz64_var(uint64_t x) {+    VERIFY_CHECK(x != 0);+#if (__has_builtin(__builtin_ctzl) || SECP256K1_GNUC_PREREQ(3,4))+    /* If the unsigned long type is sufficient to represent the largest uint64_t, consider __builtin_ctzl. */+    if (((unsigned long)UINT64_MAX) == UINT64_MAX) {+        return __builtin_ctzl(x);+    }+#endif+#if (__has_builtin(__builtin_ctzll) || SECP256K1_GNUC_PREREQ(3,4))+    /* Otherwise consider __builtin_ctzll (the unsigned long long type is always at least 64 bits). */+    return __builtin_ctzll(x);+#else+    /* If no suitable CTZ builtin is available, use a (variable time) software emulation. */+    return secp256k1_ctz64_var_debruijn(x);+#endif+}++/* Read a uint32_t in big endian */+SECP256K1_INLINE static uint32_t secp256k1_read_be32(const unsigned char* p) {+    return (uint32_t)p[0] << 24 |+           (uint32_t)p[1] << 16 |+           (uint32_t)p[2] << 8  |+           (uint32_t)p[3];+}++/* Write a uint32_t in big endian */+SECP256K1_INLINE static void secp256k1_write_be32(unsigned char* p, uint32_t x) {+    p[3] = x;+    p[2] = x >>  8;+    p[1] = x >> 16;+    p[0] = x >> 24;+}++/* Read a uint64_t in big endian */+SECP256K1_INLINE static uint64_t secp256k1_read_be64(const unsigned char* p) {+    return (uint64_t)p[0] << 56 |+           (uint64_t)p[1] << 48 |+           (uint64_t)p[2] << 40 |+           (uint64_t)p[3] << 32 |+           (uint64_t)p[4] << 24 |+           (uint64_t)p[5] << 16 |+           (uint64_t)p[6] << 8  |+           (uint64_t)p[7];+}++/* Write a uint64_t in big endian */+SECP256K1_INLINE static void secp256k1_write_be64(unsigned char* p, uint64_t x) {+    p[7] = x;+    p[6] = x >>  8;+    p[5] = x >> 16;+    p[4] = x >> 24;+    p[3] = x >> 32;+    p[2] = x >> 40;+    p[1] = x >> 48;+    p[0] = x >> 56;+}++/* Rotate a uint32_t to the right. */+SECP256K1_INLINE static uint32_t secp256k1_rotr32(const uint32_t x, const unsigned int by) {+#if defined(_MSC_VER)+    return _rotr(x, by);  /* needs <stdlib.h> */+#else+    /* Reduce rotation amount to avoid UB when shifting. */+    const unsigned int mask = CHAR_BIT * sizeof(x) - 1;+    /* Turned into a rot instruction by GCC and clang. */+    return (x >> (by & mask)) | (x << ((-by) & mask));+#endif+}++#endif /* SECP256K1_UTIL_H */
+ vendor/external/sha3/LICENSE view
@@ -0,0 +1,22 @@+The MIT License (MIT)++Copyright (c) 2015 Markku-Juhani O. Saarinen++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.+
+ vendor/external/sha3/VERSION.txt view
@@ -0,0 +1,26 @@+Upstream:  tiny_sha3 (Markku-Juhani O. Saarinen)+Origin:    https://github.com/mjosaarinen/tiny_sha3+Commit:    dcbb3192047c2a721f5f851db591871d428036a9+License:   MIT (see LICENSE in this directory)++Vendored files:+  sha3.c, sha3.h   - the Keccak-f[1600] permutation and the OpenSSL-style+                     init/update/final sponge API.+  LICENSE          - upstream MIT license, copied verbatim.++Provides both digests required by Plutus, which share the Keccak-f permutation+and the 136-byte rate for a 256-bit output and differ only in the domain pad+byte appended at finalization:+  - SHA3-256 : pad byte 0x06 (FIPS-202), via sha3_final().+  - Keccak-256 (Ethereum-style) : pad byte 0x01, via sha3_final_pad().++Removed from the upstream sources to keep this lean:+  - main.c, Makefile, README.md (test driver and build glue, not vendored).+  - The SHAKE128/SHAKE256 extensible-output functions (shake_xof, shake_out)+    and their convenience macros from sha3.h/sha3.c - not needed by Plutus.++Added (cardano-c local change, no upstream copyright text altered):+  - sha3_final_pad(md, c, pad): the upstream sha3_final body parameterized by+    the pad byte so both SHA3-256 (0x06) and Keccak-256 (0x01) are produced+    from the same vendored permutation. The original sha3_final is kept and+    now delegates to sha3_final_pad(md, c, 0x06), preserving its behaviour.
+ vendor/external/sha3/sha3.c view
@@ -0,0 +1,172 @@+// sha3.c+// 19-Nov-11  Markku-Juhani O. Saarinen <mjos@iki.fi>++// Revised 07-Aug-15 to match with official release of FIPS PUB 202 "SHA3"+// Revised 03-Sep-15 for portability + OpenSSL - style API++#include "sha3.h"++// update the state with given number of rounds++void sha3_keccakf(uint64_t st[25])+{+    // constants+    const uint64_t keccakf_rndc[24] = {+        0x0000000000000001, 0x0000000000008082, 0x800000000000808a,+        0x8000000080008000, 0x000000000000808b, 0x0000000080000001,+        0x8000000080008081, 0x8000000000008009, 0x000000000000008a,+        0x0000000000000088, 0x0000000080008009, 0x000000008000000a,+        0x000000008000808b, 0x800000000000008b, 0x8000000000008089,+        0x8000000000008003, 0x8000000000008002, 0x8000000000000080,+        0x000000000000800a, 0x800000008000000a, 0x8000000080008081,+        0x8000000000008080, 0x0000000080000001, 0x8000000080008008+    };+    const int keccakf_rotc[24] = {+        1,  3,  6,  10, 15, 21, 28, 36, 45, 55, 2,  14,+        27, 41, 56, 8,  25, 43, 62, 18, 39, 61, 20, 44+    };+    const int keccakf_piln[24] = {+        10, 7,  11, 17, 18, 3, 5,  16, 8,  21, 24, 4,+        15, 23, 19, 13, 12, 2, 20, 14, 22, 9,  6,  1+    };++    // variables+    int i, j, r;+    uint64_t t, bc[5];++#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__+    uint8_t *v;++    // endianess conversion. this is redundant on little-endian targets+    for (i = 0; i < 25; i++) {+        v = (uint8_t *) &st[i];+        st[i] = ((uint64_t) v[0])     | (((uint64_t) v[1]) << 8) |+            (((uint64_t) v[2]) << 16) | (((uint64_t) v[3]) << 24) |+            (((uint64_t) v[4]) << 32) | (((uint64_t) v[5]) << 40) |+            (((uint64_t) v[6]) << 48) | (((uint64_t) v[7]) << 56);+    }+#endif++    // actual iteration+    for (r = 0; r < KECCAKF_ROUNDS; r++) {++        // Theta+        for (i = 0; i < 5; i++)+            bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20];++        for (i = 0; i < 5; i++) {+            t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1);+            for (j = 0; j < 25; j += 5)+                st[j + i] ^= t;+        }++        // Rho Pi+        t = st[1];+        for (i = 0; i < 24; i++) {+            j = keccakf_piln[i];+            bc[0] = st[j];+            st[j] = ROTL64(t, keccakf_rotc[i]);+            t = bc[0];+        }++        //  Chi+        for (j = 0; j < 25; j += 5) {+            for (i = 0; i < 5; i++)+                bc[i] = st[j + i];+            for (i = 0; i < 5; i++)+                st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];+        }++        //  Iota+        st[0] ^= keccakf_rndc[r];+    }++#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__+    // endianess conversion. this is redundant on little-endian targets+    for (i = 0; i < 25; i++) {+        v = (uint8_t *) &st[i];+        t = st[i];+        v[0] = t & 0xFF;+        v[1] = (t >> 8) & 0xFF;+        v[2] = (t >> 16) & 0xFF;+        v[3] = (t >> 24) & 0xFF;+        v[4] = (t >> 32) & 0xFF;+        v[5] = (t >> 40) & 0xFF;+        v[6] = (t >> 48) & 0xFF;+        v[7] = (t >> 56) & 0xFF;+    }+#endif+}++// Initialize the context for SHA3++int sha3_init(sha3_ctx_t *c, int mdlen)+{+    int i;++    for (i = 0; i < 25; i++)+        c->st.q[i] = 0;+    c->mdlen = mdlen;+    c->rsiz = 200 - 2 * mdlen;+    c->pt = 0;++    return 1;+}++// update state with more data++int sha3_update(sha3_ctx_t *c, const void *data, size_t len)+{+    size_t i;+    int j;++    j = c->pt;+    for (i = 0; i < len; i++) {+        c->st.b[j++] ^= ((const uint8_t *) data)[i];+        if (j >= c->rsiz) {+            sha3_keccakf(c->st.q);+            j = 0;+        }+    }+    c->pt = j;++    return 1;+}++// finalize and output a hash with the given pad byte+// (0x06 = FIPS-202 SHA-3, 0x01 = original Keccak)++int sha3_final_pad(void *md, sha3_ctx_t *c, uint8_t pad)+{+    int i;++    c->st.b[c->pt] ^= pad;+    c->st.b[c->rsiz - 1] ^= 0x80;+    sha3_keccakf(c->st.q);++    for (i = 0; i < c->mdlen; i++) {+        ((uint8_t *) md)[i] = c->st.b[i];+    }++    return 1;+}++// finalize and output a hash++int sha3_final(void *md, sha3_ctx_t *c)+{+    return sha3_final_pad(md, c, 0x06);+}++// compute a SHA-3 hash (md) of given byte length from "in"++void *sha3(const void *in, size_t inlen, void *md, int mdlen)+{+    sha3_ctx_t sha3;++    sha3_init(&sha3, mdlen);+    sha3_update(&sha3, in, inlen);+    sha3_final(md, &sha3);++    return md;+}
+ vendor/external/sha3/sha3.h view
@@ -0,0 +1,43 @@+// sha3.h+// 19-Nov-11  Markku-Juhani O. Saarinen <mjos@iki.fi>++#ifndef SHA3_H+#define SHA3_H++#include <stddef.h>+#include <stdint.h>++#ifndef KECCAKF_ROUNDS+#define KECCAKF_ROUNDS 24+#endif++#ifndef ROTL64+#define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y))))+#endif++// state context+typedef struct {+    union {                                 // state:+        uint8_t b[200];                     // 8-bit bytes+        uint64_t q[25];                     // 64-bit words+    } st;+    int pt, rsiz, mdlen;                    // these don't overflow+} sha3_ctx_t;++// Compression function.+void sha3_keccakf(uint64_t st[25]);++// OpenSSL - like interfece+int sha3_init(sha3_ctx_t *c, int mdlen);    // mdlen = hash output in bytes+int sha3_update(sha3_ctx_t *c, const void *data, size_t len);+int sha3_final(void *md, sha3_ctx_t *c);    // digest goes to md++// Same as sha3_final but with an explicit domain-separation/pad byte:+// 0x06 yields FIPS-202 SHA-3, 0x01 yields the original (Ethereum) Keccak.+// Added for cardano-c; not part of the upstream tiny_sha3 API.+int sha3_final_pad(void *md, sha3_ctx_t *c, uint8_t pad);++// compute a sha3 hash (md) of given byte length from "in"+void *sha3(const void *in, size_t inlen, void *md, int mdlen);++#endif
+ vendor/include/cardano/address/address.h view
@@ -0,0 +1,916 @@+/**+ * \file address.h+ *+ * \author angel.castillo+ * \date   Apr 15, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ADDRESS_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ADDRESS_H++/* INCLUDES ******************************************************************/++#include <cardano/address/address_type.h>+#include <cardano/common/network_id.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* FORWARD DECLARATIONS *****************************************************/++/**+ * \brief Defines a pointer to a structure representing a Cardano base address.+ */+typedef struct cardano_base_address_t cardano_base_address_t;++/**+ * \brief Represents a Byron-era address in the Cardano blockchain.+ */+typedef struct cardano_byron_address_t cardano_byron_address_t;++/**+ * \brief Represents an enterprise address in the Cardano blockchain ecosystem.+ *+ * Enterprise addresses carry no stake rights, so using these addresses means that you are opting out of participation+ * in the proof-of-stake protocol.+ *+ * Note that using addresses with no stake rights effectively decreases the total amount of stake, which plays+ * into the hands of a potential adversary.+ */+typedef struct cardano_enterprise_address_t cardano_enterprise_address_t;++/**+ * \brief Represents a pointer address in the Cardano blockchain ecosystem.+ *+ * A pointer address indirectly specifies the stake key that should control the stake for the address. It references+ * a stake key by a stake key pointer, which is a location on the blockchain of the stake key registration certificate+ * for that key.+ */+typedef struct cardano_pointer_address_t cardano_pointer_address_t;++/**+ * \brief Represents a reward address in the Cardano blockchain ecosystem.+ */+typedef struct cardano_reward_address_t cardano_reward_address_t;++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a Cardano address.+ *+ * This structure encapsulates all the necessary information for a Cardano address.+ */+typedef struct cardano_address_t cardano_address_t;++/**+ * \brief Constructs a Cardano address from a serialized byte array.+ *+ * This function decodes a byte array into a \ref cardano_address_t object. The function ensures that the+ * byte array provided conforms to the expected format for a Cardano address before creating the+ * address object.+ *+ * \param[in] data A pointer to the byte array containing the serialized address data.+ * \param[in] size The size of the byte array.+ * \param[out] address A pointer to a pointer of \ref cardano_address_t that will be set to the+ *                     address of the newly created address object upon successful decoding.+ *+ * \return A \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the address was successfully created, or an appropriate error code if an error occurred,+ *         such as invalid format or insufficient data for decoding.+ *+ * \note The caller is responsible for freeing the created \ref cardano_address_t object by calling+ *       \ref cardano_address_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const byte_t serialized_address[] = { ... };+ * size_t size = sizeof(serialized_address);+ * cardano_address_t* address = NULL;+ *+ * cardano_error_t result = cardano_address_from_bytes(serialized_address, size, &address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the address+ *+ *   // Clean up+ *   cardano_address_unref(&address);+ * }+ * else+ * {+ *   printf("Failed to decode address: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_address_from_bytes(+  const byte_t*       data,+  size_t              size,+  cardano_address_t** address);++/**+ * \brief Retrieves the size of the byte array required to serialize a Cardano address.+ *+ * This function calculates the number of bytes necessary to serialize the specified+ * \ref cardano_address_t object. It is useful for allocating the appropriate amount of memory+ * before serializing the address using \ref cardano_address_to_bytes.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object whose serialized+ *                     size is to be determined. The object must not be NULL.+ *+ * \return The size in bytes required to store the serialized form of the address. If the input+ *         address is NULL, the function returns 0, indicating an error in usage.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = cardano_address_from_bytes(...);+ *+ * if (address)+ * {+ *   size_t required_size = cardano_address_get_bytes_size(address);+ *   byte_t* buffer = (byte_t*)malloc(required_size);+ *+ *   if (buffer)+ *   {+ *     // Serialize the address into buffer+ *     cardano_address_to_bytes(address, buffer, required_size);+ *     // Use the buffer ...+ *     free(buffer);+ *   }+ *+ *   // Clean up the address object+ *   cardano_address_unref(&address);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_address_get_bytes_size(+  const cardano_address_t* address);++/**+ * \brief Serializes a Cardano address into a byte array.+ *+ * This function serializes the given \ref cardano_address_t object into a preallocated buffer.+ * The buffer must be large enough to hold the serialized data, which should be determined+ * by calling \ref cardano_address_get_bytes_size prior to this function.+ *+ * \param[in] address  A constant pointer to the \ref cardano_address_t object that is to be serialized.+ *                     The object must not be NULL.+ * \param[out] data  A pointer to the buffer where the serialized data will be written.+ * \param[in] size  The size of the buffer pointed to by \p data. It must be at least as large+ *                  as the value returned by \ref cardano_address_get_bytes_size for successful serialization.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the buffer \p data+ *         is too small, returns \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE. If \p address or \p data is NULL,+ *         returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = cardano_address_from_bytes(...);+ * size_t required_size = cardano_address_get_bytes_size(address);+ * byte_t* buffer = (byte_t*)malloc(required_size);+ *+ * if (buffer)+ * {+ *   cardano_error_t result = cardano_address_to_bytes(address, buffer, required_size);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the serialized data+ *   }+ *+ *   free(buffer);+ * }+ *+ * cardano_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_address_to_bytes(+  const cardano_address_t* address,+  byte_t*                  data,+  size_t                   size);++/**+ * \brief Retrieves a pointer to the internal byte array of a Cardano address.+ *+ * This function provides read-only access to the internal byte representation of a Cardano address.+ * The returned pointer points directly to the internal data structure within the \ref cardano_address_t object.+ * This approach avoids copying data and allows efficient access to the address's byte representation.+ *+ * \param[in] address  A constant pointer to the \ref cardano_address_t object whose byte array is to be accessed.+ *+ * \return A constant pointer to the internal byte array of the Cardano address. This pointer should not be modified+ *         or freed by the caller, as it is managed internally by the Cardano library. The content pointed to remains+ *         valid as long as the \ref cardano_address_t object itself is not freed or modified.+ *+ * \note Modifying or freeing the data pointed to by the returned pointer will lead to undefined behavior. Treat this pointer+ * as read-only.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = cardano_address_from_bytes(...);+ * const byte_t* byte_ptr = cardano_address_get_bytes(address);+ *+ * if (byte_ptr)+ * {+ *   // Read the bytes but do not modify them+ * }+ *+ * cardano_address_unref(&address);  // This also invalidates byte_ptr+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_address_get_bytes(+  const cardano_address_t* address);++/**+ * \brief Creates a Cardano address from a string representation.+ *+ * This function constructs a \ref cardano_address_t object by parsing the provided string. The string+ * should contain a valid representation of a Cardano address, either in base58 or Bech32 format.+ *+ * \param[in] data A pointer to the character array containing the string representation of the address.+ * \param[in] size The length of the string pointed to by \p data, not including the null terminator.+ * \param[out] address A pointer to a pointer to \ref cardano_address_t that will be set to the address+ *                     of the newly created Cardano address object upon successful parsing. The caller+ *                     is responsible for managing the lifecycle of this object, including freeing it+ *                     when it is no longer needed using \ref cardano_address_unref.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address is successfully created from the string. Returns+ *         \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the string is not a valid address format. If the \p data is+ *         NULL or \p address is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL. Returns+ *         \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if memory for the decoding buffers could not be allocated.+ *         Allocation failures inside the Bech32 decoder itself are reported as \ref CARDANO_ERROR_DECODING.+ *+ * Usage Example:+ * \code{.c}+ * const char* address_str = "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x";+ * size_t size = strlen(address_str);+ * cardano_address_t* address = NULL;+ *+ * cardano_error_t result = cardano_address_from_string(address_str, size, &address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the address+ * }+ * else+ * {+ *   printf("Failed to parse address: %d\n", result);+ * }+ *+ * // Clean up the address object once done+ * cardano_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_address_from_string(+  const char*         data,+  size_t              size,+  cardano_address_t** address);++/**+ * \brief Retrieves the size needed for the string representation of a Cardano address.+ *+ * This function calculates the size of the buffer required to hold the string representation+ * of a \ref cardano_address_t object, including the null terminator. This size is necessary+ * to ensure that the buffer allocated for converting the address to a string is sufficient.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object for which the string+ *                    size is being calculated. The object must not be NULL.+ *+ * \return The size in bytes needed to store the string representation of the address, including+ *         the null terminator. If the input \p address is NULL, the behavior is undefined.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = cardano_address_new(...);+ * size_t required_size = cardano_address_get_string_size(address);+ *+ * char* address_str = (char*)malloc(required_size);+ *+ * if (address_str)+ * {+ *   cardano_error_t result = cardano_address_to_string(address, address_str, required_size);+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("Address: %s\n", address_str);+ *   }+ *   free(address_str);+ * }+ *+ * // Clean up the address object once done+ * cardano_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_address_get_string_size(const cardano_address_t* address);++/**+ * \brief Converts a Cardano address into its string representation.+ *+ * This function serializes the given \ref cardano_address_t object into a string format.+ * The string is written to a user-provided buffer, and the size of this buffer must be+ * adequate to hold the entire string, including the null terminator. The required size+ * can be determined by calling \ref cardano_address_get_string_size.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object that is to be converted to a string.+ *                    The object must not be NULL.+ * \param[out] data A pointer to the buffer where the string representation of the address will be written.+ * \param[in] size The size of the buffer pointed to by \p data. This size should be at least as large as the value+ *                 returned by \ref cardano_address_get_string_size to ensure successful serialization.+ *+ * \return Returns \ref CARDANO_SUCCESS if the conversion is successful. If the buffer is too small, returns+ *         \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE. If the \p address or \p data is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = cardano_address_new(...);+ * size_t required_size = cardano_address_get_string_size(address);+ * char* address_str = (char*)malloc(required_size);+ *+ * if (address_str)+ * {+ *   cardano_error_t result = cardano_address_to_string(address, address_str, required_size);+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("Address: %s\n", address_str);+ *   }+ *+ *   free(address_str);+ * }+ *+ * // Clean up the address object once done+ * cardano_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_address_to_string(+  const cardano_address_t* address,+  char*                    data,+  size_t                   size);++/**+ * \brief Retrieves the string representation of a Cardano address.+ *+ * This function provides access to the string form of the \ref cardano_address_t object. The function+ * returns a pointer to a constant string which represents the address. This string should not be modified+ * or freed by the user, as it is managed internally by the address object.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object from which+ *                    the string is to be retrieved.+ *+ * \return A constant pointer to the internal string representation of the address. If the input+ *         \p address is NULL, the return value is NULL, indicating an error.+ *+ * \note The returned string will remain valid as long as the \ref cardano_address_t object is not modified+ *       or freed. Once \ref cardano_address_unref is called on the address object, the string pointer+ *       should be considered invalid.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = cardano_address_new(...);+ * const char* address_str = cardano_address_get_string(address);+ *+ * if (address_str)+ * {+ *   printf("Address: %s\n", address_str);+ * }+ *+ * // Clean up the address object once done+ * cardano_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_address_get_string(const cardano_address_t* address);++/**+ * \brief Checks if the provided string is a valid Bech32-encoded Cardano address.+ *+ * This function verifies if the given string conforms to the Bech32 encoding format specific to Cardano addresses.+ *+ * \param[in] data A pointer to the character array containing the potential Bech32 address.+ * \param[in] size The length of the string pointed to by \p data.+ *+ * \return \c true if the string is a valid Bech32-encoded Cardano address; otherwise, \c false.+ *+ * Usage Example:+ * \code{.c}+ * const char* address = "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgsqqxw8x";+ * size_t address_length = strlen(address);+ *+ * bool is_valid = cardano_address_is_valid_bech32(address, address_length);+ *+ * if (is_valid)+ * {+ *   printf("The address is a valid Bech32 Cardano address.\n");+ * }+ * else+ * {+ *   printf("The address is not a valid Bech32 Cardano address.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_address_is_valid_bech32(const char* data, size_t size);++/**+ * \brief Checks if the provided string is a valid Byron-encoded Cardano address.+ *+ * This function verifies if the given string conforms to the Byron address encoding format used in earlier versions of the Cardano blockchain. It performs checks on the structure and integrity of the address, ensuring it follows the expected format and contains a valid checksum.+ *+ * \param[in] data A pointer to the character array containing the potential Byron address.+ * \param[in] size The length of the string pointed to by \p data.+ *+ * \return \c true if the string is a valid Byron-encoded Cardano address; otherwise, \c false.+ *+ * \note This function does not modify the input string and does not allocate any dynamic memory.+ *+ * Usage Example:+ * \code{.c}+ * const char* address = "Ae2tdPwUPEZFRbyhz3cpfC2CumGzNkFBN2L42rcUc2yjQpEkxDbkPodpMAi";+ * size_t address_length = strlen(address);+ *+ * bool is_valid = cardano_address_is_valid_byron(address, address_length);+ *+ * if (is_valid)+ * {+ *   printf("The address is a valid Byron Cardano address.\n");+ * }+ * else+ * {+ *   printf("The address is not a valid Byron Cardano address.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_address_is_valid_byron(const char* data, size_t size);++/**+ * \brief Checks if the provided string is a valid Cardano address.+ *+ * This function verifies if the given string conforms to the encoding formats used for Cardano addresses,+ * including both Byron and Shelley address formats. It checks the structure and integrity of the address, ensuring+ * it follows the expected format.+ *+ * \param[in] data A pointer to the character array containing the potential Cardano address.+ * \param[in] size The length of the string pointed to by \p data.+ *+ * \return \c true if the string is a valid Cardano address; otherwise, \c false.+ *+ * Usage Example:+ * \code{.c}+ * const char* address = "addr1qxy2cnx2l2s54at80au205tswxpnuvsgsn9rqlat4zuyghqp6v3hj4t4c7szlevu9hxy6w2scv0hecqlq5v3x6jts0sqqx5scn";+ * size_t address_length = strlen(address);+ *+ * bool is_valid = cardano_address_is_valid(address, address_length);+ *+ * if (is_valid)+ * {+ *   printf("The address is a valid Cardano address.\n");+ * }+ * else+ * {+ *   printf("The address is not a valid Cardano address.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_address_is_valid(const char* data, size_t size);++/**+ * \brief Retrieves the type of a given Cardano address.+ *+ * This function examines the provided \ref cardano_address_t object and determines its address type,+ * such as whether it is a base, pointer, enterprise, reward, or Byron address. The address type is determined+ * based on the structure and prefix of the address.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object whose type is to be determined.+ *                    The object must not be NULL.+ * \param[out] type A pointer to \ref cardano_address_type_t where the address type will be stored upon successful+ *                  determination. This parameter cannot be NULL.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address type was successfully determined.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the input address or type pointer is NULL.+ *         Returns other error codes as defined in \ref cardano_error_t if the address type cannot be determined+ *         due to the address not conforming to any known Cardano address format.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = NULL;+ * cardano_address_type_t address_type;+ *+ * cardano_error_t result = cardano_address_from_string("addr1...", strlen("addr1..."), &address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   cardano_error_t get_type_result = cardano_address_get_type(address, &address_type);+ *+ *   if (get_type_result != CARDANO_SUCCESS)+ *   {+ *     printf("Failed to determine the address type.\n");+ *   }+ *   else+ *   {+ *     printf("Address type: %d\n", address_type);+ *   }+ * }+ * else+ * {+ *   printf("Failed to determine the address type.\n");+ * }+ *+ * cardano_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_address_get_type(+  const cardano_address_t* address,+  cardano_address_type_t*  type);++/**+ * \brief Retrieves the network ID from a given Cardano address.+ *+ * This function extracts the network identifier from the provided \ref cardano_address_t object.+ * The network ID indicates whether the address belongs to the test network or the main network.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object from which the network ID is to be retrieved.+ * \param[out] network_id A pointer to \ref cardano_network_id_t where the network ID will be stored upon successful+ *                        extraction. This parameter cannot be NULL.+ *+ * \return Returns \ref CARDANO_SUCCESS if the network ID was successfully retrieved.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the input address or network_id pointer is NULL.+ *         Returns other error codes as defined in \ref cardano_error_t if the network ID cannot be retrieved due to+ *         malformed or unrecognized address formats.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = NULL;+ * cardano_network_id_t network_id;+ *+ * cardano_error_t result = cardano_address_from_string("addr1...", strlen("addr1..."), &address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   cardano_error_t get_network_id = cardano_address_get_network_id(address, &network_id);+ *+ *   if (get_network_id != CARDANO_SUCCESS)+ *   {+ *     printf("Failed to determine the address network id.\n");+ *   }+ *   else+ *   {+ *     printf("Network ID: %d\n", network_id);+ *   }+ * }+ * else+ * {+ *   printf("Failed to retrieve the network ID.\n");+ * }+ *+ * cardano_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_address_get_network_id(+  const cardano_address_t* address,+  cardano_network_id_t*    network_id);++/**+ * \brief Converts a general Cardano address to a Byron-specific address format.+ *+ * This function creates a \ref cardano_byron_address_t object from a given \ref cardano_address_t object.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object to be converted.+ *                    The object must not be NULL and must represent a valid Byron address.+ *+ * \return A pointer to a newly created \ref cardano_byron_address_t object if the conversion is successful.+ *         Returns NULL if the address cannot be converted to a Byron address due to an invalid format or+ *         if the provided address does not correspond to a Byron address. The caller is responsible for managing+ *         the lifecycle of the returned object, including freeing it when it is no longer needed using+ *         \ref cardano_byron_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = cardano_address_to_byron_address(address);+ *+ * if (byron_address)+ * {+ *   // Byron address is successfully converted+ *   // Proceed with operations that require a Byron address+ *+ *   cardano_byron_address_unref(&byron_address);+ * }+ * else+ * {+ *   printf("Conversion to Byron address format failed.\n");+ * }+ *+ * cardano_address_unref(&shelley_address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_byron_address_t* cardano_address_to_byron_address(const cardano_address_t* address);++/**+ * \brief Converts a general Cardano address to a reward-specific address format.+ *+ * This function creates a \ref cardano_reward_address_t object from a given \ref cardano_address_t object.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object to be converted.+ *                    The object must not be NULL and must represent a valid reward address.+ *+ * \return A pointer to a newly created \ref cardano_reward_address_t object if the conversion is successful.+ *         Returns NULL if the address cannot be converted to a reward address due to an invalid format or+ *         if the provided address does not correspond to a reward address. The caller is responsible for managing+ *         the lifecycle of the returned object, including freeing it when it is no longer needed using+ *         \ref cardano_reward_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* reward_address = cardano_address_to_reward_address(address);+ *+ * if (reward_address)+ * {+ *   // Reward address is successfully converted+ *   // Proceed with operations that require a reward address+ *+ *   cardano_reward_address_unref(&reward_address);+ * }+ * else+ * {+ *   printf("Conversion to reward address format failed.\n");+ * }+ *+ * cardano_address_unref(&general_address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_reward_address_t* cardano_address_to_reward_address(const cardano_address_t* address);++/**+ * \brief Converts a general Cardano address to a pointer address format.+ *+ * This function creates a \ref cardano_pointer_address_t object from a given \ref cardano_address_t object.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object to be converted.+ *                    The object must not be NULL and must represent a valid pointer address.+ *+ * \return A pointer to a newly created \ref cardano_pointer_address_t object if the conversion is successful.+ *         Returns NULL if the address cannot be converted to a pointer address due to an invalid format or+ *         if the provided address does not correspond to a pointer address. The caller is responsible for managing+ *         the lifecycle of the returned object, including freeing it when it is no longer needed using+ *         \ref cardano_pointer_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = ...;+ * cardano_pointer_address_t* pointer_address = cardano_address_to_pointer_address(address);+ *+ * if (pointer_address)+ * {+ *   // Pointer address is successfully converted+ *   // Proceed with operations that require a pointer address+ *+ *   cardano_pointer_address_unref(&pointer_address);+ * }+ * else+ * {+ *   printf("Conversion to pointer address format failed.\n");+ * }+ *+ * cardano_address_unref(&general_address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_pointer_address_t* cardano_address_to_pointer_address(const cardano_address_t* address);++/**+ * \brief Converts a general Cardano address to an enterprise address format.+ *+ * This function creates a \ref cardano_enterprise_address_t object from a given \ref cardano_address_t object.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object to be converted.+ *                    The object must not be NULL and must represent a valid enterprise address.+ *+ * \return A pointer to a newly created \ref cardano_enterprise_address_t object if the conversion is successful.+ *         Returns NULL if the address cannot be converted to an enterprise address due to an invalid format or+ *         if the provided address does not correspond to an enterprise address. The caller is responsible for managing+ *         the lifecycle of the returned object, including freeing it when it is no longer needed using+ *         \ref cardano_enterprise_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = ...;+ * cardano_enterprise_address_t* enterprise_address = cardano_address_to_enterprise_address(address);+ *+ * if (enterprise_address)+ * {+ *   // Enterprise address is successfully converted+ *   // Proceed with operations that require an enterprise address+ *+ *   cardano_enterprise_address_unref(&enterprise_address);+ * }+ * else+ * {+ *   printf("Conversion to enterprise address format failed.\n");+ * }+ *+ * cardano_address_unref(&general_address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_enterprise_address_t* cardano_address_to_enterprise_address(const cardano_address_t* address);++/**+ * \brief Converts a general Cardano address to a base address format.+ *+ * This function creates a \ref cardano_base_address_t object from a given \ref cardano_address_t object.+ *+ * \param[in] address A constant pointer to the \ref cardano_address_t object to be converted.+ *                    The object must not be NULL and must represent a valid base address.+ *+ * \return A pointer to a newly created \ref cardano_base_address_t object if the conversion is successful.+ *         Returns NULL if the address cannot be converted to a base address due to an invalid format or+ *         if the provided address does not correspond to a base address. The caller is responsible for managing+ *         the lifecycle of the returned object, including freeing it when it is no longer needed using+ *         \ref cardano_base_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address = ...;+ * cardano_base_address_t* base_address = cardano_address_to_base_address(address);+ *+ * if (base_address)+ * {+ *   // Base address is successfully converted+ *   // Proceed with operations that require a base address+ *+ *   cardano_base_address_unref(&base_address);+ * }+ * else+ * {+ *   printf("Conversion to base address format failed.\n");+ * }+ *+ * cardano_address_unref(&general_address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_base_address_t* cardano_address_to_base_address(const cardano_address_t* address);++/**+ * \brief Compares two address objects for equality.+ *+ * This function compares two address objects to determine if they are equal.+ *+ * \param[in] lhs Pointer to the first address object.+ * \param[in] rhs Pointer to the second address object.+ *+ * \return \c true if the address objects are equal, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* address1 = NULL;+ * cardano_address_t* address2 = NULL;+ *+ * // Assume address1 and address2 are initialized properly+ *+ * bool are_equal = cardano_address_equals(address1, address2);+ *+ * if (are_equal)+ * {+ *   printf("The address objects are equal.\n");+ * }+ * else+ * {+ *   printf("The address objects are not equal.\n");+ * }+ *+ * // Clean up+ * cardano_address_unref(&address1);+ * cardano_address_unref(&address2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_address_equals(const cardano_address_t* lhs, const cardano_address_t* rhs);++/**+ * \brief Decrements the address's reference count.+ *+ * If the reference count reaches zero, the address memory is deallocated.+ *+ * \param[in] address Pointer to the address whose reference count is to be decremented.+ */+CARDANO_EXPORT void cardano_address_unref(cardano_address_t** address);++/**+ * \brief Increments the address's reference count.+ *+ * Ensures that the address remains allocated until the last reference is released.+ *+ * \param[in] address address whose reference count is to be incremented.+ */+CARDANO_EXPORT void cardano_address_ref(cardano_address_t* address);++/**+ * \brief Retrieves the address's current reference count.+ *+ * \warning Does not account for transitive references.+ *+ * \param[in] address Target address.+ * \return Current reference count of the address.+ */+CARDANO_EXPORT size_t cardano_address_refcount(const cardano_address_t* address);++/**+ * \brief Sets the last error message for a given address.+ *+ * This function records an error message in the address's last_error buffer,+ * overwriting any previous message. The message is truncated if it exceeds+ * the buffer size. This function is typically used to store descriptive+ * error information that can be retrieved later with+ * cardano_address_get_last_error.+ *+ * \param[in,out] address A pointer to the cardano_address_t instance whose last error+ *               message is to be set. If the address is NULL, the function+ *               has no effect.+ * \param[in] message A null-terminated string containing the error message to be+ *                recorded. If the message is NULL, the address's last_error+ *                will be set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters due to the fixed size+ *       of the last_error buffer (1024 characters), including the null+ *       terminator. Messages longer than this limit will be truncated.+ */+CARDANO_EXPORT void cardano_address_set_last_error(cardano_address_t* address, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific address.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_address_set_last_error for the given+ * address. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in,out] address A pointer to the \ref cardano_address_t instance whose last error+ *               message is to be retrieved. If the address is \c NULL, the function+ *               returns a generic error message indicating the null address.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified address. If the address is \c NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the address and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_address_set_last_error for the same address, or until+ *       the address is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_address_get_last_error(const cardano_address_t* address);++/**+ * \brief Creates an independent deep copy of a \ref cardano_address_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_address_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_address_deep_clone(const cardano_address_t* source, cardano_address_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ADDRESS_H
+ vendor/include/cardano/address/address_type.h view
@@ -0,0 +1,126 @@+/**+ * \file address_type.h+ *+ * \author angel.castillo+ * \date   Apr 12, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ADDRESS_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ADDRESS_TYPE_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Enumerates types of addresses used within the Cardano blockchain in the Shelley era and beyond.+ *+ * Shelley introduces several different types of addresses, each serving distinct purposes and supporting different functionalities.+ * In addition to these new address types, Shelley continues to support Byron-era bootstrap addresses.+ */+typedef enum+{+  /** Base addresses with both payment and stake credentials as key hashes.+   * \li bits 7-6 : 00+   * \li bit  5   : stake cred is keyhash+   * \li bit  4   : payment cred is keyhash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_BASE_PAYMENT_KEY_STAKE_KEY = 0b0000,++  /** Base addresses with payment credentials as script hash and stake credentials as key hash.+   * \li bits 7-6 : 00+   * \li bit  5   : stake cred is keyhash+   * \li bit  4   : payment cred is scripthash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_BASE_PAYMENT_SCRIPT_STAKE_KEY = 0b0001,++  /** Base addresses with payment credentials as key hash and stake credentials as script hash.+   * \li bits 7-6 : 00+   * \li bit  5   : stake cred is scripthash+   * \li bit  4   : payment cred is keyhash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_BASE_PAYMENT_KEY_STAKE_SCRIPT = 0b0010,++  /** Base addresses with both payment and stake credentials as script hashes.+   * \li bits 7-6 : 00+   * \li bit  5   : stake cred is scripthash+   * \li bit  4   : payment cred is scripthash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_BASE_PAYMENT_SCRIPT_STAKE_SCRIPT = 0b0011,++  /** Pointer addresses with payment credential as keyhash.+   * \li bits 7-5 : 010+   * \li bit  4   : payment cred is keyhash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_POINTER_KEY = 0b0100,++  /** Pointer addresses with payment credential as scripthash.+   * \li bits 7-5 : 010+   * \li bit  4   : payment cred is scripthash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_POINTER_SCRIPT = 0b0101,++  /** Enterprise addresses with payment credential as keyhash.+   * \li bits 7-5 : 010+   * \li bit  4   : payment cred is keyhash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_ENTERPRISE_KEY = 0b0110,++  /** Enterprise addresses with payment credential as scripthash.+   * \li bits 7-5 : 010+   * \li bit  4   : payment cred is scripthash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_ENTERPRISE_SCRIPT = 0b0111,++  /** Byron-era bootstrap addresses, continuing support for backward compatibility.+   * \li bits 7-4 : 1000+   * \li bits 3-0 : unrelated data (no network ID in Byron addresses)+   */+  CARDANO_ADDRESS_TYPE_BYRON = 0b1000,++  /** Reward account addresses with credential as keyhash.+   * \li bits 7-5 : 111+   * \li bit  4   : credential is keyhash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_REWARD_KEY = 0b1110,++  /** Reward account addresses with credential as scripthash.+   * \li bits 7-5 : 111+   * \li bit  4   : credential is scripthash+   * \li bits 3-0 : network id+   */+  CARDANO_ADDRESS_TYPE_REWARD_SCRIPT = 0b1111++  // 1001-1101 are reserved for future formats+} cardano_address_type_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ADDRESS_TYPE_H
+ vendor/include/cardano/address/base_address.h view
@@ -0,0 +1,697 @@+/**+ * \file base_address.h+ *+ * \author angel.castillo+ * \date   Apr 15, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_BASE_ADDRESS_H+#define BIGLUP_LABS_INCLUDE_CARDANO_BASE_ADDRESS_H++/* INCLUDES ******************************************************************/++#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++#include <cardano/common/credential.h>+#include <cardano/common/network_id.h>++/* FORWARD DECLARATIONS *****************************************************/++/**+ * \brief Represents a Cardano address.+ *+ * This structure encapsulates all the necessary information for a Cardano address.+ */+typedef struct cardano_address_t cardano_address_t;++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Defines a pointer to a structure representing a Cardano base address.+ */+typedef struct cardano_base_address_t cardano_base_address_t;++/**+ * \brief Constructs a Cardano base address from payment and stake credentials.+ *+ * This function creates a base address by combining payment and stake credentials, along with specifying+ * the network ID (either mainnet or testnet).+ *+ * \param[in]  network_id The network identifier, specifying whether the address is for mainnet or testnet.+ * \param[in]  payment The payment credential, which is a pointer to a \ref cardano_credential_t that defines+ *                     who controls the funds.+ * \param[in]  stake The stake credential, which is a pointer to a \ref cardano_credential_t that who controls+ *                   staking rewards are directed.+ * \param[out] base_address A pointer to a pointer to \ref cardano_base_address_t that will hold the address+ *                           if the function succeeds.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully created, otherwise it returns an+ *         error code indicating what went wrong (e.g., CARDANO_ERROR_POINTER_IS_NULL if any input pointers are NULL).+ *+ * \note It is the caller's responsibility to manage the lifecycle of the created \ref cardano_base_address_t object,+ *       which includes freeing it when it is no longer needed by calling \ref cardano_base_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* payment_credential = ...; // Assume this is initialized+ * cardano_credential_t* stake_credential = ...; // Assume this is initialized+ * cardano_base_address_t* base_address = NULL;+ * cardano_error_t result = cardano_base_address_from_credentials(+ *     CARDANO_NETWORK_ID_MAIN_NET, payment_credential, stake_credential, &base_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the base_address+ *   cardano_base_address_unref(&base_address);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_base_address_from_credentials(+  cardano_network_id_t     network_id,+  cardano_credential_t*    payment,+  cardano_credential_t*    stake,+  cardano_base_address_t** base_address);++/**+ * \brief Converts a general Cardano address to a base address.+ *+ * This function takes a general Cardano address and attempts to interpret it as a base address,+ * which is a specific type of Cardano address that includes separate payment and stake credentials.+ * If the conversion is successful, a new \ref cardano_base_address_t object is created.+ *+ * \param[in]  address A constant pointer to the \ref cardano_address_t object representing the general+ *                     Cardano address to be converted.+ * \param[out] base_address A pointer to a pointer to \ref cardano_base_address_t that will hold the+ *                           base address object if the conversion is successful.+ *+ * \return Returns \ref CARDANO_SUCCESS if the conversion is successful. If the address is not of a+ *         base address type, returns an appropriate error code such as \ref CARDANO_ERROR_INVALID_ADDRESS_TYPE.+ *         If the \p address is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * \note The newly created \ref cardano_base_address_t object is fully managed by the caller, who is responsible+ *       for freeing it when it is no longer needed by calling \ref cardano_base_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* general_address = ...; // Assume this is initialized as a general Cardano address+ * cardano_base_address_t* base_address = NULL;+ * cardano_error_t result = cardano_base_address_from_address(general_address, &base_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The conversion was successful, and base_address can now be used+ *   cardano_base_address_unref(&base_address);+ * }+ * else+ * {+ *   printf("Failed to convert to base address: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_base_address_from_address(+  const cardano_address_t* address,+  cardano_base_address_t** base_address);++/**+ * \brief Converts a base address to a general Cardano address.+ *+ * This function takes a \ref cardano_base_address_t object and converts it into a general+ * \ref cardano_address_t object. This allows for the use of the base address in any context+ * that requires a generic address format.+ *+ * \param[in] base_address A constant pointer to the \ref cardano_base_address_t object that+ *                         is to be converted into a general Cardano address.+ *+ * \return A pointer to a new \ref cardano_address_t object that represents the general Cardano+ *         address. If the conversion fails due to memory allocation issues, returns NULL.+ *+ * \note The newly created \ref cardano_address_t object is fully managed by the caller, who is+ *       responsible for freeing it when it is no longer needed by calling \ref cardano_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* base_address = ...; // Assume this is initialized+ * cardano_address_t* general_address = cardano_base_address_to_address(base_address);+ *+ * if (general_address)+ * {+ *   // The conversion was successful, and general_address can now be used+ *   cardano_address_unref(&general_address);+ * }+ * else+ * {+ *   printf("Failed to convert base address to general address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_address_t* cardano_base_address_to_address(+  const cardano_base_address_t* base_address);++/**+ * \brief Retrieves the payment credential from a base address.+ *+ * This function extracts the payment credential from a \ref cardano_base_address_t object.+ * The payment credential is a hash of a public key or a script that is authorized+ * to spend funds from the address.+ *+ * \param[in] base_address A constant pointer to the \ref cardano_base_address_t object from which+ *                         the payment credential is to be retrieved.+ *+ * \return A pointer to a \ref cardano_credential_t object that holds the payment credential. If+ *         the base address does not have a payment credential or if an error occurs, returns NULL.+ *+ * \note The newly created \ref cardano_credential_t object is fully managed by the caller, who is+ *       responsible for freeing it when it is no longer needed by calling \ref cardano_credential_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* base_address = ...; // Assume this is initialized+ * cardano_credential_t* payment_credential = cardano_base_address_get_payment_credential(base_address);+ *+ * if (payment_credential)+ * {+ *   // Use the payment credential+ *   cardano_credential_unref(&payment_credential);+ * }+ * else+ * {+ *    printf("Failed to retrieve payment credential from base address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_base_address_get_payment_credential(+  cardano_base_address_t* base_address);++/**+ * \brief Retrieves the stake credential from a base address.+ *+ * This function extracts the stake credential from a \ref cardano_base_address_t object.+ * The stake credential is a hash of a public key or a script that is in control+ * of the staking rewards from the address.+ *+ * \param[in] base_address A constant pointer to the \ref cardano_base_address_t object from which+ *                         the stake credential is to be retrieved.+ *+ * \return A pointer to a \ref cardano_credential_t object that holds the stake credential. If+ *         the base address does not have a stake credential or if an error occurs, returns NULL.+ *+ * \note The newly created \ref cardano_credential_t object is fully managed by the caller, who is+ *       responsible for freeing it when it is no longer needed by calling \ref cardano_credential_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* base_address = ...; // Assume this is initialized+ * cardano_credential_t* stake_credential = cardano_base_address_get_stake_credential(base_address);+ *+ * if (stake_credential)+ * {+ *   // Use the stake credential+ *   cardano_credential_unref(&stake_credential);+ * }+ * else+ * {+ *    printf("Failed to retrieve stake credential from base address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_base_address_get_stake_credential(+  cardano_base_address_t* base_address);++/**+ * \brief Creates a base address from a serialized byte array.+ *+ * This function constructs a \ref cardano_base_address_t object from a byte array that+ * contains serialized address data. It attempts to deserialize the data and create+ * a base address object from it.+ *+ * \param[in] data A pointer to the byte array containing the serialized base address data.+ * \param[in] size The size of the byte array in bytes.+ * \param[out] address A pointer to a pointer to \ref cardano_base_address_t. On successful+ *                     deserialization, this will point to a newly allocated base address object.+ *+ * \return A \ref cardano_error_t indicating the result of the function call. This will be+ *         \ref CARDANO_SUCCESS if the address was successfully created from the provided data.+ *         If an error occurs, a corresponding error code will be returned.+ *+ * \note The newly created \ref cardano_base_address_t object is fully managed by the caller,+ *       who is responsible for freeing it when it is no longer needed by calling \ref cardano_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * const byte_t serialized_data[] = {0x00, 0x01, 0x02, ...}; // example serialized data+ * size_t size = sizeof(serialized_data);+ * cardano_base_address_t* base_address = NULL;+ * cardano_error_t result = cardano_base_address_from_bytes(serialized_data, size, &base_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the base_address+ *+ *   // Once done, ensure to clean up and release the base address+ *   cardano_address_unref(&base_address);+ * }+ * else+ * {+ *   printf("Failed to create base address from bytes: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_base_address_from_bytes(+  const byte_t*            data,+  size_t                   size,+  cardano_base_address_t** address);++/**+ * \brief Retrieves the size of the byte array needed to serialize a base address.+ *+ * This function calculates the size in bytes that a serialized form of the specified+ * \ref cardano_base_address_t object would occupy. This size is necessary to allocate a buffer+ * of appropriate size for serialization.+ *+ * \param[in] address A constant pointer to the \ref cardano_base_address_t object whose+ *                    serialized size is to be calculated. The object must not be NULL.+ *+ * \return The size in bytes required to serialize the base address. If the input address is NULL,+ *         the function returns 0.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* base_address = ...; // Assume this is initialized+ * size_t required_size = cardano_base_address_get_bytes_size(base_address);+ *+ * if (required_size > 0)+ * {+ *   byte_t* buffer = (byte_t*)malloc(required_size);+ *+ *   if (buffer)+ *   {+ *     // Proceed to serialize the base address+ *   }+ *   free(buffer);+ * }+ * else+ * {+ *   printf("Failed to determine the size needed for serialization\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_base_address_get_bytes_size(const cardano_base_address_t* address);++/**+ * \brief Retrieves a pointer to the internal byte array representation of a base address.+ *+ * This function provides access to the internal byte array that represents the serialized form+ * of a \ref cardano_base_address_t object. The data returned by this function is useful for+ * operations that require direct access to the serialized address, such as hashing or networking.+ *+ * \param[in] address A constant pointer to the \ref cardano_base_address_t object from which+ *                    the byte array is to be retrieved. The object must not be NULL.+ *+ * \return A pointer to the constant byte array that represents the serialized base address.+ *         If the input address is NULL, returns NULL. The data returned by this function should+ *         not be modified or freed by the caller, as it is managed internally by the Cardano library.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* base_address = ...; // Assume this is initialized+ * const byte_t* byte_data = cardano_base_address_get_bytes(base_address);+ *+ * if (byte_data)+ * {+ *   // Use the byte array for operations like sending over a network+ * }+ * else+ * {+ *   printf("Failed to retrieve byte data from base address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_base_address_get_bytes(const cardano_base_address_t* address);++/**+ * \brief Serializes a base address into a provided byte array.+ *+ * This function serializes the specified \ref cardano_base_address_t object into a byte array+ * provided by the caller. The size of the buffer must be sufficient to hold the serialized data;+ * the required size can be obtained by calling \ref cardano_base_address_get_bytes_size.+ *+ * \param[in] address A constant pointer to the \ref cardano_base_address_t object to be serialized.+ * \param[out] data A pointer to the buffer where the serialized data will be written. This buffer+ *                  must be pre-allocated by the caller.+ * \param[in] size The size of the buffer pointed to by \p data. It must be at least as large as the value+ *                 returned by \ref cardano_base_address_get_bytes_size to ensure successful serialization.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the buffer is too small,+ *         returns \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE. If the \p address or \p data is NULL, returns+ *         \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* base_address = ...; // Assume this is initialized+ * size_t required_size = cardano_base_address_get_bytes_size(base_address);+ * byte_t* buffer = (byte_t*)malloc(required_size);+ *+ * if (buffer)+ * {+ *   cardano_error_t result = cardano_base_address_to_bytes(base_address, buffer, required_size);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the serialized data+ *   }+ *+ *   free(buffer);+ * }+ * else+ * {+ *   printf("Memory allocation failed\n");+ * }+ *+ * cardano_base_address_unref(&base_address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_base_address_to_bytes(+  const cardano_base_address_t* address,+  byte_t*                       data,+  size_t                        size);++/**+ * \brief Creates a base address from a Bech32 encoded string.+ *+ * This function decodes a Bech32 encoded string and constructs a \ref cardano_base_address_t object.+ * The Bech32 string should correctly represent a Cardano base address according to the+ * Cardano address specifications. This function will parse the string and if valid, will allocate+ * and initialize a new base address object.+ *+ * \param[in] data A pointer to the character array containing the Bech32 encoded address.+ * \param[in] size The length of the character array pointed to by \p data.+ * \param[out] address A pointer to a pointer to \ref cardano_base_address_t. If the decoding is+ *                     successful, this will be set to point to the newly created base address object.+ *+ * \return Returns \ref CARDANO_SUCCESS if the base address is successfully created from the Bech32 string.+ *         Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the Bech32 string does not conform to the expected format or+ *         if the decoding fails. Returns \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *         Returns \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if memory for the decoding buffers could not be allocated.+ *         Allocation failures inside the Bech32 decoder itself are reported as \ref CARDANO_ERROR_DECODING.+ *+ * \note The caller is responsible for freeing the created \ref cardano_base_address_t object using the+ *       \ref cardano_base_address_unref function when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const char* bech32_data = "addr1qxy...";+ * size_t bech32_size = strlen(bech32_data);+ * cardano_base_address_t* base_address = NULL;+ *+ * cardano_error_t result = cardano_base_address_from_bech32(bech32_data, bech32_size, &base_address);+ *+ * if (result == CARDANO_SUCCESS && base_address != NULL)+ * {+ *   // The base address has been successfully created+ *   // Use the base_address for operations+ * }+ * else+ * {+ *   printf("Failed to create base address from Bech32 data: %d\n", result);+ * }+ *+ * // Clean up+ * cardano_base_address_unref(base_address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_base_address_from_bech32(+  const char*              data,+  size_t                   size,+  cardano_base_address_t** address);++/**+ * \brief Calculates the size of the Bech32 encoded string of a base address.+ *+ * This function calculates the length of the Bech32 string that would be generated+ * from the given \ref cardano_base_address_t object. This size includes the null+ * terminator needed for string termination in C.+ *+ * \param[in] address A constant pointer to the \ref cardano_base_address_t object+ *                    whose Bech32 string size is to be calculated.+ *+ * \return The size in bytes of the Bech32 string representation of the address,+ *         including the null terminator. If the input address is NULL, returns 0.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* base_address = ...; // Assume this is initialized+ * size_t bech32_size = cardano_base_address_get_bech32_size(base_address);+ *+ * if (bech32_size > 0)+ * {+ *+ *   char* bech32_string = (char*)malloc(bech32_size);+ *+ *   if (bech32_string)+ *   {+ *     // Proceed to encode or use the bech32_string as needed+ *     free(bech32_string);+ *   }+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_base_address_get_bech32_size(const cardano_base_address_t* address);++/**+ * \brief Encodes a base address into a Bech32 formatted string.+ *+ * This function converts a \ref cardano_base_address_t object into its corresponding+ * Bech32 string representation. The caller must provide a buffer of sufficient size to hold+ * the Bech32 encoded string, which can be determined by \ref cardano_base_address_get_bech32_size.+ *+ * \param[in] address A constant pointer to the \ref cardano_base_address_t object to be encoded.+ * \param[out] data A pointer to a buffer where the Bech32 string will be written.+ * \param[in] size The size of the buffer provided in \p data. This size must be at least as large+ *                 as the value returned by \ref cardano_base_address_get_bech32_size to ensure+ *                 successful encoding.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully encoded into Bech32 format.+ *         If the provided buffer is too small, returns \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE.+ *         If \p address or \p data is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* base_address = ...; // Assume this is initialized+ * size_t bech32_size = cardano_base_address_get_bech32_size(base_address);+ *+ * char* bech32_string = (char*)malloc(bech32_size);+ *+ * if (bech32_string)+ * {+ *   cardano_error_t result = cardano_base_address_to_bech32(base_address, bech32_string, bech32_size);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("Bech32 Address: %s\n", bech32_string);+ *   }+ *   else+ *   {+ *     printf("Failed to encode base address to Bech32: %d\n", result);+ *   }+ *+ *   free(bech32_string);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_base_address_to_bech32(+  const cardano_base_address_t* address,+  char*                         data,+  size_t                        size);++/**+ * \brief Retrieves the string representation of a base address.+ *+ * This function provides access to the string representation of a \ref cardano_base_address_t object.+ * The string is in Bech32 or another. This function does not allocate new memory for the string; instead,+ * it returns a pointer to the internal representation within the object.+ *+ * \param[in] address A constant pointer to the \ref cardano_base_address_t object from which+ *                    the string representation is to be retrieved.+ *+ * \return A constant pointer to the internal string representation of the address. If the address+ *         is NULL, returns NULL. The returned string should not be modified or freed by the caller,+ *         as it is managed internally by the \ref cardano_base_address_t object.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* base_address = ...; // Assume this is initialized+ * const char* address_str = cardano_base_address_get_string(base_address);+ *+ * if (address_str)+ * {+ *   printf("Base Address: %s\n", address_str);+ * }+ * else+ * {+ *   printf("Failed to retrieve string representation of the base address.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_base_address_get_string(const cardano_base_address_t* address);++/**+ * \brief Retrieves the network ID from a given Cardano base address.+ *+ * This function extracts the network identifier from the provided \ref cardano_base_address_t object.+ * The network ID indicates whether the address belongs to the test network or the main network.+ *+ * \param[in] address A constant pointer to the \ref cardano_base_address_t object from which the network ID is to be retrieved.+ * \param[out] network_id A pointer to \ref cardano_network_id_t where the network ID will be stored upon successful+ *                        extraction. This parameter cannot be NULL.+ *+ * \return Returns \ref CARDANO_SUCCESS if the network ID was successfully retrieved.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the input address or network_id pointer is NULL.+ *         Returns other error codes as defined in \ref cardano_error_t if the network ID cannot be retrieved due to+ *         malformed or unrecognized address formats.+ *+ * Usage Example:+ * \code{.c}+ * cardano_base_address_t* address = NULL;+ * cardano_network_id_t network_id;+ *+ * cardano_error_t get_network_id = cardano_base_address_get_network_id(address, &network_id);+ *+ * if (get_network_id != CARDANO_SUCCESS)+ * {+ *   printf("Failed to determine the network id.\n");+ * }+ * else+ * {+ *   printf("Network ID: %d\n", network_id);+ * }+ *+ * cardano_base_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_base_address_get_network_id(+  const cardano_base_address_t* address,+  cardano_network_id_t*         network_id);++/**+ * \brief Decrements the base address's reference count.+ *+ * If the reference count reaches zero, the base address memory is deallocated.+ *+ * \param[in] address Pointer to the base address whose reference count is to be decremented.+ */+CARDANO_EXPORT void cardano_base_address_unref(cardano_base_address_t** address);++/**+ * \brief Increments the base address's reference count.+ *+ * Ensures that the base address remains allocated until the last reference is released.+ *+ * \param[in] address base address whose reference count is to be incremented.+ */+CARDANO_EXPORT void cardano_base_address_ref(cardano_base_address_t* address);++/**+ * \brief Retrieves the base address's current reference count.+ *+ * \warning Does not account for transitive references.+ *+ * \param[in] address Target base address.+ * \return Current reference count of the base address.+ */+CARDANO_EXPORT size_t cardano_base_address_refcount(const cardano_base_address_t* address);++/**+ * \brief Sets the last error message for a given base address.+ *+ * This function records an error message in the base address's last_error buffer,+ * overwriting any previous message. The message is truncated if it exceeds+ * the buffer size. This function is typically used to store descriptive+ * error information that can be retrieved later with+ * cardano_base_address_get_last_error.+ *+ * \param[in,out] address A pointer to the cardano_base_address_t instance whose last error+ *               message is to be set. If the base address is NULL, the function+ *               has no effect.+ * \param[in] message A null-terminated string containing the error message to be+ *                recorded. If the message is NULL, the base address's last_error+ *                will be set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters due to the fixed size+ *       of the last_error buffer (1024 characters), including the null+ *       terminator. Messages longer than this limit will be truncated.+ */+CARDANO_EXPORT void cardano_base_address_set_last_error(cardano_base_address_t* address, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific base address.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_base_address_set_last_error for the given+ * base address. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in,out] address A pointer to the \ref cardano_base_address_t instance whose last error+ *               message is to be retrieved. If the base address is \c NULL, the function+ *               returns a generic error message indicating the null base address.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified base address. If the base address is \c NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the base address and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_base_address_set_last_error for the same base address, or until+ *       the base address is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_base_address_get_last_error(const cardano_base_address_t* address);++/**+ * \brief Creates an independent deep copy of the address and its credentials.+ * \param[in] source Address to copy. Must not be NULL.+ * \param[out] clone Receives one owned reference, or NULL on failure. Must not be NULL.+ * \return CARDANO_SUCCESS, CARDANO_ERROR_POINTER_IS_NULL, or CARDANO_ERROR_MEMORY_ALLOCATION_FAILED.+ * \note Release the result with cardano_base_address_unref. The source is unchanged.+ */+CARDANO_EXPORT cardano_error_t+cardano_base_address_deep_clone(const cardano_base_address_t* source, cardano_base_address_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_BASE_ADDRESS_H
+ vendor/include/cardano/address/byron_address.h view
@@ -0,0 +1,751 @@+/**+ * \file byron_address.h+ *+ * \author angel.castillo+ * \date   Apr 15, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_BYRON_ADDRESS_H+#define BIGLUP_LABS_INCLUDE_CARDANO_BYRON_ADDRESS_H++/* INCLUDES ******************************************************************/++#include <cardano/address/byron_address_attributes.h>+#include <cardano/address/byron_address_type.h>+#include <cardano/common/network_id.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* FORWARD DECLARATIONS *****************************************************/++/**+ * \brief Represents a Cardano address.+ *+ * This structure encapsulates all the necessary information for a Cardano address.+ */+typedef struct cardano_address_t cardano_address_t;++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a Byron-era address in the Cardano blockchain.+ */+typedef struct cardano_byron_address_t cardano_byron_address_t;++/**+ * \brief Creates a Byron-era address from given credentials.+ *+ * This function generates a \ref cardano_byron_address_t object based on the provided root hash, address attributes,+ * and address type.+ *+ * \param[in] root A pointer to \ref cardano_blake2b_hash_t representing the root hash of the address.+ * \param[in] attributes A \ref cardano_byron_address_attributes_t structure containing optional address attributes+ *                       such as derivation path and network magic.+ * \param[in] type The type of Byron address, defined by \ref cardano_byron_address_type_t, which indicates+ *                 whether the address is based on a public key, a script, or a redeem key.+ * \param[out] address A pointer to a pointer of \ref cardano_byron_address_t where the newly created Byron+ *                     address object will be stored.+ *+ * \return A \ref cardano_error_t indicating the result of the operation. Returns \ref CARDANO_SUCCESS on success+ *         or an appropriate error code on failure. Returns \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if memory for+ *         the address could not be allocated.+ *+ * \note It is the caller's responsibility to manage the lifecycle of the created \ref cardano_byron_address_t object,+ *       including freeing it when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_blake2b_hash_t* root_hash = ...; // Assume root_hash is initialized+ * cardano_byron_address_attributes_t attributes = { .derivation_path = "...", .magic = 0x1234 };+ * cardano_byron_address_t* byron_address = NULL;+ *+ * cardano_error_t result = cardano_byron_address_from_credentials(+ *      root_hash, attributes,+ *      CARDANO_BYRON_ADDRESS_TYPE_PUBKEY,+ *      &byron_address);+ *+ * if (result == CARDANO_SUCCESS && byron_address)+ * {+ *   // Byron address has been successfully created and can be used+ *   // Free the Byron address when done+ *   cardano_byron_address_unref(byron_address);+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_from_credentials(+  cardano_blake2b_hash_t*            root,+  cardano_byron_address_attributes_t attributes,+  cardano_byron_address_type_t       type,+  cardano_byron_address_t**          address);++/**+ * \brief Converts a generic Cardano address to a Byron-era address.+ *+ * This function attempts to convert a \ref cardano_address_t object into a \ref cardano_byron_address_t object.+ *+ * \param[in] address A constant pointer to the generic \ref cardano_address_t object to be converted.+ * \param[out] byron_address A pointer to a pointer of \ref cardano_byron_address_t where the newly created+ *                           Byron address object will be stored if the conversion is successful.+ *+ * \return A \ref cardano_error_t indicating the result of the operation. Returns \ref CARDANO_SUCCESS on successful+ *         conversion, \ref CARDANO_ERROR_INVALID_ADDRESS_TYPE if the input address is not a valid Byron address, or other+ *         appropriate error codes for different failures.+ *+ * \note The caller is responsible for managing the lifecycle of the created \ref cardano_byron_address_t object,+ *       including freeing it when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* generic_address = ...; // Assume this is initialized and points to a Byron address+ * cardano_byron_address_t* byron_address = NULL;+ *+ * cardano_error_t result = cardano_byron_address_from_address(generic_address, &byron_address);+ *+ * if (result == CARDANO_SUCCESS && byron_address)+ * {+ *   // Byron address has been successfully converted and can be used+ *   // Free the Byron address when done+ *   cardano_byron_address_unref(byron_address);+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_from_address(+  const cardano_address_t*  address,+  cardano_byron_address_t** byron_address);++/**+ * \brief Converts a Byron-era address to a generic Cardano address.+ *+ * This function converts a \ref cardano_byron_address_t object to a \ref cardano_address_t object.+ *+ * \param[in] byron_address A constant pointer to the \ref cardano_byron_address_t object that represents the+ *                          Byron-era address to be converted.+ *+ * \return A pointer to a new \ref cardano_address_t object representing the generic Cardano address. This object+ *         represents a "strong reference" to the address, meaning that it is fully initialized and ready for use.+ *         The caller is responsible for managing the lifecycle of this object, including freeing it when it is+ *         no longer needed.+ *+ * \note If the conversion fails, NULL is returned. It is the caller's responsibility to check the return value+ *       before using it.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = ...; // Assume this is initialized+ * cardano_address_t* cardano_address = cardano_byron_address_to_address(byron_address);+ *+ * if (cardano_address)+ * {+ *   // Use the generic Cardano address+ *   // Remember to free the Cardano address when done+ *   cardano_address_unref(&cardano_address);+ * }+ * else+ * {+ *   // Handle conversion failure+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_address_t* cardano_byron_address_to_address(+  const cardano_byron_address_t* byron_address);++/**+ * \brief Retrieves attributes from a Byron-era address.+ *+ * This function extracts the attributes associated with a Byron-era address encapsulated in a \ref cardano_byron_address_t object.+ * These attributes might include optional fields such as a derivation path or a network magic identifier, which were specific to+ * the Byron address format.+ *+ * \param[in] address A constant pointer to the \ref cardano_byron_address_t object from which the attributes are to be retrieved.+ * \param[out] attributes A pointer to a \ref cardano_byron_address_attributes_t structure where the attributes of the address will be stored.+ *+ * \return \ref CARDANO_SUCCESS if the attributes were successfully retrieved, or an appropriate error code if an error occurred.+ *+ * \note The function assumes the \p address pointer and the \p attributes pointer are not NULL. If either is NULL, the function+ *       returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = ...; // Assume this is initialized+ * cardano_byron_address_attributes_t attributes;+ * cardano_error_t result = cardano_byron_address_get_attributes(byron_address, &attributes);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the attributes+ * }+ * else+ * {+ *   // Handle error+ *   printf("Failed to retrieve attributes: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_get_attributes(+  const cardano_byron_address_t*      address,+  cardano_byron_address_attributes_t* attributes);++/**+ * \brief Retrieves the type of a Byron-era address.+ *+ * This function extracts the type from a Byron-era address encapsulated in a \ref cardano_byron_address_t object.+ * The type determines the nature of the credentials used in the address, such as a public key, a script, or a redeem key.+ *+ * \param[in] address A constant pointer to the \ref cardano_byron_address_t object from which the type is to be retrieved.+ * \param[out] type A pointer to a \ref cardano_byron_address_type_t variable where the type of the address will be stored.+ *+ * \return \ref CARDANO_SUCCESS if the type was successfully retrieved, or an appropriate error code if an error occurred.+ *+ * \note The function assumes the \p address pointer and the \p type pointer are not NULL. If either is NULL, the function+ *       returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = ...; // Assume this is initialized+ * cardano_byron_address_type_t type;+ * cardano_error_t result = cardano_byron_address_get_type(byron_address, &type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved type+ *   switch (type)+ *   {+ *     case CARDANO_BYRON_ADDRESS_TYPE_PUBKEY:+ *       printf("Address type is Public Key\n");+ *       break;+ *     case CARDANO_BYRON_ADDRESS_TYPE_SCRIPT:+ *       printf("Address type is Script\n");+ *       break;+ *     case CARDANO_BYRON_ADDRESS_TYPE_REDEEM:+ *       printf("Address type is Redeem Key\n");+ *       break;+ *     default:+ *       printf("Unknown address type\n");+ *   }+ * }+ * else+ * {+ *   // Handle error+ *   printf("Failed to retrieve address type: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_get_type(+  const cardano_byron_address_t* address,+  cardano_byron_address_type_t*  type);++/**+ * \brief Retrieves the root hash from a Byron-era address.+ *+ * This function extracts the root hash associated with a Byron-era address, which is encapsulated in a \ref cardano_byron_address_t object.+ *+ * \param[in] address A constant pointer to the \ref cardano_byron_address_t object from which the root hash is to be retrieved.+ * \param[out] root A pointer to a pointer of \ref cardano_blake2b_hash_t that will be set to point to the root hash of the address.+ *                  The function will allocate memory for the root hash, and it is the caller's responsibility to free it using+ *                  \ref cardano_blake2b_hash_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the root hash was successfully retrieved, or an appropriate error code if an error occurred.+ *+ * \note The function assumes the \p address pointer is not NULL and that \p root is a valid double pointer. If either is NULL,+ *       the function returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = ...; // Assume this is initialized+ * cardano_blake2b_hash_t* root_hash = NULL;+ * cardano_error_t result = cardano_byron_address_get_root(byron_address, &root_hash);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the root hash+ *   // ...+ *+ *   // Clean up+ *   cardano_blake2b_hash_unref(&root_hash);+ * }+ * else+ * {+ *   // Handle error+ *   printf("Failed to retrieve root hash: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_get_root(+  const cardano_byron_address_t* address,+  cardano_blake2b_hash_t**       root);++/**+ * \brief Constructs a Byron-era address from a byte array.+ *+ * This function creates a \ref cardano_byron_address_t object from raw byte data, interpreting it as a serialized Byron address.+ * It verifies the structure and validity of the data before constructing the address object.+ *+ * \param[in] data A pointer to the byte array containing the serialized Byron address data.+ * \param[in] size The size of the byte array in bytes.+ * \param[out] address A pointer to a pointer of \ref cardano_byron_address_t that will be set to the address of the newly created+ *                     Byron address object upon successful decoding.+ *+ * \return \ref CARDANO_SUCCESS if the Byron address is successfully created from the provided bytes, \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT+ *         if the byte array does not represent a valid Byron address, or \ref CARDANO_ERROR_POINTER_IS_NULL if any pointer parameter is NULL.+ *+ * \note The caller is responsible for managing the lifecycle of the created \ref cardano_byron_address_t object. Specifically,+ *       once the address is no longer needed, the caller must release it by calling \ref cardano_address_unref.+ *+ * Usage Example:+ * \code{.c}+ * const byte_t address_data[] = {...}; // Assume this contains valid Byron address bytes+ * size_t address_data_size = sizeof(address_data);+ * cardano_byron_address_t* byron_address = NULL;+ * cardano_error_t result = cardano_byron_address_from_bytes(address_data, address_data_size, &byron_address);+ * if (result == CARDANO_SUCCESS) {+ *   // Byron address is successfully created and can be used+ *   // ...+ *+ *   // Once done, clean up+ *   cardano_address_unref(&byron_address);+ * } else {+ *   printf("Failed to create Byron address from bytes: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_from_bytes(+  const byte_t*             data,+  size_t                    size,+  cardano_byron_address_t** address);++/**+ * \brief Retrieves the size in bytes of the serialized form of a Byron-era address.+ *+ * This function calculates the size of the byte array needed to store the serialized form of a given+ * \ref cardano_byron_address_t object. This size is useful for allocating the correct amount of memory+ * for serialization.+ *+ * \param[in] address A constant pointer to the \ref cardano_byron_address_t object whose serialized size is to be determined.+ *+ * \return The size in bytes required to store the serialized form of the Byron address. Returns zero if the input address+ *         is NULL or if any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = ...; // Assume this is a valid Byron address object+ * size_t required_size = cardano_byron_address_get_bytes_size(byron_address);+ *+ * if (required_size > 0)+ * {+ *   byte_t* buffer = (byte_t*)malloc(required_size);+ *+ *   if (buffer)+ *   {+ *     // Proceed to serialize the Byron address into the buffer+ *     ...+ *     free(buffer);+ *   }+ * }+ * else+ * {+ *   printf("Error determining the required size for the serialized Byron address.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_byron_address_get_bytes_size(const cardano_byron_address_t* address);++/**+ * \brief Retrieves a pointer to the internal byte array representation of a Byron-era address.+ *+ * This function provides direct read-only access to the internal byte array that represents+ * a Byron-era address in its serialized form. This is useful for operations that require direct+ * access to the raw data of the address, such as hashing or verification.+ *+ * \param[in] address A constant pointer to the \ref cardano_byron_address_t object from which+ *                    the byte array is to be accessed.+ *+ * \return A pointer to the constant byte array representing the serialized Byron address. If the+ *         input address is NULL, returns NULL. The data should not be modified, and the lifetime+ *         of the returned pointer is tied to the lifetime of the \ref cardano_byron_address_t object.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = ...; // Assume this is a valid Byron address object+ * const byte_t* byte_data = cardano_byron_address_get_bytes(byron_address);+ *+ * if (byte_data)+ * {+ *   // Use the byte data for reading purposes+ *   ...+ * }+ * else+ * {+ *   printf("Failed to access the byte data of the Byron address.\n");+ * }+ * \endcode+ *+ * \note Modifying the data pointed to by the returned pointer is undefined behavior.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_byron_address_get_bytes(const cardano_byron_address_t* address);++/**+ * \brief Serializes a Byron-era address into a byte array.+ *+ * This function serializes the given \ref cardano_byron_address_t object into a preallocated buffer in its raw byte form.+ * The buffer size can be determined by calling \ref cardano_byron_address_get_bytes_size prior to this function.+ *+ * \param[in] address A constant pointer to the \ref cardano_byron_address_t object that is to be serialized.+ * \param[out] data A pointer to the buffer where the serialized byte data will be written.+ * \param[in] size The size of the buffer pointed to by \p data. It must be at least as large as the value+ *                 returned by \ref cardano_byron_address_get_bytes_size to ensure successful serialization.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the buffer is too small, returns+ *         \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE. If the \p address is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = cardano_byron_address_new(...);+ * size_t required_size = cardano_byron_address_get_bytes_size(byron_address);+ * byte_t* buffer = (byte_t*)malloc(required_size);+ *+ * if (buffer)+ * {+ *   cardano_error_t result = cardano_byron_address_to_bytes(byron_address, buffer, required_size);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the serialized data+ *   }+ *   free(buffer);+ * }+ *+ * cardano_byron_address_unref(&byron_address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_to_bytes(+  const cardano_byron_address_t* address,+  byte_t*                        data,+  size_t                         size);++/**+ * \brief Creates a Byron-era address from a Base58-encoded string.+ *+ * This function constructs a \ref cardano_byron_address_t object by decoding the provided+ * Base58-encoded string that represents the address data.+ *+ * \param[in] data A pointer to a character array containing the Base58-encoded representation of the address.+ * \param[in] size The size of the Base58 string in bytes.+ * \param[out] address A pointer to a pointer to \ref cardano_byron_address_t that will be set to the address+ *                     of the newly created Byron address object upon successful decoding.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully created. Returns \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p data or \p address pointer is NULL. Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the Base58 data+ *         could not be decoded into a valid Byron address.+ *+ * \note The function checks the format and validity of the Base58 string. It is the caller's responsibility to+ *       ensure that the string is correctly formatted and of appropriate length. Malformed or incorrect Base58+ *       data may lead to decoding errors.+ *+ * Usage Example:+ * \code{.c}+ * const char* base58_address = "3P3QsMVK8...";+ * size_t base58_size = strlen(base58_address);+ * cardano_byron_address_t* byron_address = NULL;+ *+ * cardano_error_t result = cardano_byron_address_from_base58(base58_address, base58_size, &byron_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the Byron address+ *+ *   // Once done, ensure to clean up and release the Byron address+ *   cardano_byron_address_unref(&byron_address);+ * }+ * else+ * {+ *   printf("Failed to decode Byron address from Base58: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_from_base58(+  const char*               data,+  size_t                    size,+  cardano_byron_address_t** address);++/**+ * \brief Retrieves the size in bytes of the Base58-encoded representation of a Byron-era address.+ *+ * This function calculates the size necessary to store the Base58-encoded representation of a given+ * \ref cardano_byron_address_t address object, including the null-termination character.+ *+ * \param[in] address A pointer to a \ref cardano_byron_address_t object whose Base58 size is to be retrieved.+ *+ * \return The size in bytes of the Base58-encoded representation of the address. Returns 0 if the \p address+ *         pointer is NULL or if the address is invalid.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = NULL;+ * // Assume byron_address is already created and valid+ * size_t base58_size = cardano_byron_address_get_base58_size(byron_address);+ *+ * if (base58_size > 0)+ * {+ *   char* base58_string = (char*)malloc(base58_size);+ *+ *   if (base58_string)+ *   {+ *     // Proceed to convert address to Base58 string+ *   }+ *+ *   free(base58_string);+ * }+ * else+ * {+ *   printf("Invalid address or unable to determine size\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_byron_address_get_base58_size(const cardano_byron_address_t* address);++/**+ * \brief Converts a Byron-era address into a Base58-encoded string.+ *+ * This function takes a \ref cardano_byron_address_t object and converts it to its Base58 string+ * representation. The resulting string is written into the provided \p data buffer, which must be large+ * enough to hold the Base58 string and the null-termination character.+ *+ * \param[in] address A pointer to the \ref cardano_byron_address_t object to be converted.+ * \param[out] data A pointer to a character buffer where the Base58-encoded string will be stored.+ * \param[in] size The size of the provided buffer in bytes. This size should be at least the value returned+ *                 by \ref cardano_byron_address_get_base58_size for this address.+ *+ * \return Returns \ref CARDANO_SUCCESS if the conversion was successful. Returns \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         the \p address or \p data pointer is NULL. Returns \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if the \p size is too+ *         small to hold the Base58 representation including the null terminator.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = NULL;+ * // Assume byron_address is previously created and valid+ * size_t base58_size = cardano_byron_address_get_base58_size(byron_address);+ * char* base58_string = (char*) malloc(base58_size);+ *+ * if (base58_string)+ * {+ *   cardano_error_t result = cardano_byron_address_to_base58(byron_address, base58_string, base58_size);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("Base58 representation: %s\n", base58_string);+ *   }+ *   else+ *   {+ *     printf("Failed to convert Byron address to Base58: %d\n", result);+ *   }+ *+ *   free(base58_string);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_to_base58(+  const cardano_byron_address_t* address,+  char*                          data,+  size_t                         size);++/**+ * \brief Retrieves the string representation of a byron era address.+ *+ * This function provides access to the string representation of a \ref cardano_byron_address_t object.+ * The string is in Base58. This function does not allocate new memory for the string; instead,+ * it returns a pointer to the internal representation within the object.+ *+ * \param[in] address A constant pointer to the \ref cardano_byron_address_t object from which+ *                    the string representation is to be retrieved.+ *+ * \return A constant pointer to the internal string representation of the address. If the address+ *         is NULL, returns NULL. The returned string should not be modified or freed by the caller,+ *         as it is managed internally by the \ref cardano_byron_address_t object.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* byron_address = ...; // Assume this is initialized+ * const char* address_str = cardano_byron_address_get_string(byron_address);+ *+ * if (address_str)+ * {+ *   printf("Base Address: %s\n", address_str);+ * }+ * else+ * {+ *   printf("Failed to retrieve string representation of the base address.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_byron_address_get_string(const cardano_byron_address_t* address);++/**+ * \brief Retrieves the network ID from a given Cardano byron address.+ *+ * This function extracts the network identifier from the provided \ref cardano_byron_address_t object.+ * The network ID indicates whether the address belongs to the test network or the main network.+ *+ * \param[in] address A constant pointer to the \ref cardano_byron_address_t object from which the network ID is to be retrieved.+ * \param[out] network_id A pointer to \ref cardano_network_id_t where the network ID will be stored upon successful+ *                        extraction. This parameter cannot be NULL.+ *+ * \return Returns \ref CARDANO_SUCCESS if the network ID was successfully retrieved.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the input address or network_id pointer is NULL.+ *         Returns other error codes as defined in \ref cardano_error_t if the network ID cannot be retrieved due to+ *         malformed or unrecognized address formats.+ *+ * Usage Example:+ * \code{.c}+ * cardano_byron_address_t* address = NULL;+ * cardano_network_id_t network_id;+ *+ * cardano_error_t get_network_id = cardano_byron_address_get_network_id(address, &network_id);+ *+ * if (get_network_id != CARDANO_SUCCESS)+ * {+ *   printf("Failed to determine the network id.\n");+ * }+ * else+ * {+ *   printf("Network ID: %d\n", network_id);+ * }+ *+ * cardano_byron_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_byron_address_get_network_id(+  const cardano_byron_address_t* address,+  cardano_network_id_t*          network_id);++/**+ * \brief Decrements the byron address's reference count.+ *+ * If the reference count reaches zero, the byron address memory is deallocated.+ *+ * \param[in] address Pointer to the byron address whose reference count is to be decremented.+ */+CARDANO_EXPORT void cardano_byron_address_unref(cardano_byron_address_t** address);++/**+ * \brief Increments the byron address's reference count.+ *+ * Ensures that the byron address remains allocated until the last reference is released.+ *+ * \param[in] address byron address whose reference count is to be incremented.+ */+CARDANO_EXPORT void cardano_byron_address_ref(cardano_byron_address_t* address);++/**+ * \brief Retrieves the byron address's current reference count.+ *+ * \warning Does not account for transitive references.+ *+ * \param[in] address Target byron address.+ * \return Current reference count of the byron address.+ */+CARDANO_EXPORT size_t cardano_byron_address_refcount(const cardano_byron_address_t* address);++/**+ * \brief Sets the last error message for a given byron address.+ *+ * This function records an error message in the byron address's last_error buffer,+ * overwriting any previous message. The message is truncated if it exceeds+ * the buffer size. This function is typically used to store descriptive+ * error information that can be retrieved later with+ * cardano_byron_address_get_last_error.+ *+ * \param[in,out] address A pointer to the cardano_byron_address_t instance whose last error+ *               message is to be set. If the byron address is NULL, the function+ *               has no effect.+ * \param[in] message A null-terminated string containing the error message to be+ *                recorded. If the message is NULL, the byron address's last_error+ *                will be set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters due to the fixed size+ *       of the last_error buffer (1024 characters), including the null+ *       terminator. Messages longer than this limit will be truncated.+ */+CARDANO_EXPORT void cardano_byron_address_set_last_error(cardano_byron_address_t* address, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific byron address.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_byron_address_set_last_error for the given+ * byron address. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in,out] address A pointer to the \ref cardano_byron_address_t instance whose last error+ *               message is to be retrieved. If the byron address is \c NULL, the function+ *               returns a generic error message indicating the null byron address.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified byron address. If the byron address is \c NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the byron address and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_byron_address_set_last_error for the same byron address, or until+ *       the byron address is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_byron_address_get_last_error(const cardano_byron_address_t* address);++/**+ * \brief Creates an independent deep copy of the address and its credentials.+ * \param[in] source Address to copy. Must not be NULL.+ * \param[out] clone Receives one owned reference, or NULL on failure. Must not be NULL.+ * \return CARDANO_SUCCESS, CARDANO_ERROR_POINTER_IS_NULL, or CARDANO_ERROR_MEMORY_ALLOCATION_FAILED.+ * \note Release the result with cardano_byron_address_unref. The source is unchanged.+ */+CARDANO_EXPORT cardano_error_t+cardano_byron_address_deep_clone(const cardano_byron_address_t* source, cardano_byron_address_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_BYRON_ADDRESS_H
+ vendor/include/cardano/address/byron_address_attributes.h view
@@ -0,0 +1,68 @@+/**+ * \file byron_address_attributes.h+ *+ * \author angel.castillo+ * \date   Apr 12, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_BYRON_ADDRESS_ATTRIBUTES_H+#define BIGLUP_LABS_INCLUDE_CARDANO_BYRON_ADDRESS_ATTRIBUTES_H++/* INCLUDES ******************************************************************/++#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Attributes specific to Byron addresses in the Cardano blockchain.+ *+ * This structure holds optional attributes associated with Byron addresses. Byron addresses were used during+ * the Byron era of the Cardano blockchain. The `derivation_path` attribute was utilized by legacy random wallets+ * for key derivation, a practice that has since been replaced by more modern wallet structures such as Yoroi and+ * Icarus. The `magic` attribute serves as a network tag, used primarily on test networks to distinguish between+ * different network environments.+ */+typedef struct cardano_byron_address_attributes_t+{+    /**+     * \brief  Holds the derivation path used by legacy wallets.+     */+    byte_t derivation_path[64];++    /**+     * \brief  The size of the derivation path encrypted data.+     */+    size_t derivation_path_size;++    /**+     * \brief * Network magic identifier used for network discrimination, primarily relevant in test network scenarios. This+     * int32_t value helps ensure that transactions are broadcast on the correct Cardano network. It will be set to -1+     * if the address is not associated with a specific network.+     */+    int64_t magic;+} cardano_byron_address_attributes_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_BYRON_ADDRESS_ATTRIBUTES_H
+ vendor/include/cardano/address/byron_address_type.h view
@@ -0,0 +1,62 @@+/**+ * \file byron_address_type.h+ *+ * \author angel.castillo+ * \date   Apr 12, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_BYRON_ADDRESS_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_BYRON_ADDRESS_TYPE_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Enumerates the types of spending data associated with Byron addresses.+ *+ * This enumeration defines the type of data that can be associated with a Byron address. Each type corresponds to a different method of controlling the spending of funds:+ */+typedef enum+{+  /**+   * \brief Indicates that the address uses a public key to control spending. The payload for+   * this address type is a public key.+   */+  CARDANO_BYRON_ADDRESS_TYPE_PUBKEY = 0,++  /**+   * \brief Indicates that the address uses a script to control spending. The payload for+   * this address type includes the script itself and possibly its version, depending on the script type.+   */+  CARDANO_BYRON_ADDRESS_TYPE_SCRIPT = 1,++  /**+   * \brief Indicates that the address uses a redeem public key. Redeem addresses are a+   * special type of address mainly used during the initial distribution phase of ADA.+   * The payload is a redeem public key.+   */+  CARDANO_BYRON_ADDRESS_TYPE_REDEEM = 2+} cardano_byron_address_type_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_BYRON_ADDRESS_TYPE_H
+ vendor/include/cardano/address/enterprise_address.h view
@@ -0,0 +1,685 @@+/**+ * \file enterprise_address.h+ *+ * \author angel.castillo+ * \date   Apr 15, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ENTERPRISE_ADDRESS_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ENTERPRISE_ADDRESS_H++/* INCLUDES ******************************************************************/++#include <cardano/common/credential.h>+#include <cardano/common/network_id.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* FORWARD DECLARATIONS *****************************************************/++/**+ * \brief Represents an enterprise address in the Cardano blockchain ecosystem.+ *+ * Enterprise addresses carry no stake rights, so using these addresses means that you are opting out of participation+ * in the proof-of-stake protocol.+ *+ * Note that using addresses with no stake rights effectively decreases the total amount of stake, which plays+ * into the hands of a potential adversary.+ */+typedef struct cardano_address_t cardano_address_t;++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents an enterprise address in the Cardano blockchain ecosystem.+ *+ * Enterprise addresses carry no stake rights, so using these addresses means that you are opting out of participation+ * in the proof-of-stake protocol.+ *+ * Note that using addresses with no stake rights effectively decreases the total amount of stake, which plays+ * into the hands of a potential adversary.+ */+typedef struct cardano_enterprise_address_t cardano_enterprise_address_t;++/**+ * \brief Creates an enterprise address from specified network and payment credentials.+ *+ * This function constructs a \ref cardano_enterprise_address_t object by combining a network identifier+ * and payment credentials. The resulting enterprise address does not include staking capabilities.+ *+ * \param[in] network_id The network identifier, which specifies the Cardano network (e.g., mainnet, testnet).+ * \param[in] payment A pointer to a \ref cardano_credential_t object representing the payment credentials.+ * \param[out] enterprise_address A pointer to a pointer to \ref cardano_enterprise_address_t that will be set+ *                                to the address of the newly created enterprise address object upon successful+ *                                address creation.+ *+ * \return Returns \ref CARDANO_SUCCESS if the enterprise address was successfully created. Returns+ *         \ref CARDANO_ERROR_POINTER_IS_NULL if the \p payment or \p enterprise_address pointer is NULL.+ *+ * \note The caller is responsible for managing the lifecycle of the created \ref cardano_enterprise_address_t object.+ *       This involves ensuring that `cardano_enterprise_address_unref` is called to free the address object when it is no longer needed, to avoid memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t payment_credentials = {...};  // Initialized elsewhere+ * cardano_enterprise_address_t* address = NULL;+ * cardano_error_t result = cardano_enterprise_address_from_credentials(CARDANO_NETWORK_ID_MAIN_NET, &payment_credentials, &address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the address for transactions+ *   // Once done, ensure to clean up and release the enterprise address+ *   cardano_enterprise_address_unref(&address);+ * }+ * else+ * {+ *   printf("Failed to create enterprise address: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_enterprise_address_from_credentials(+  cardano_network_id_t           network_id,+  cardano_credential_t*          payment,+  cardano_enterprise_address_t** enterprise_address);++/**+ * \brief Converts a general Cardano address to an enterprise address.+ *+ * This function takes an existing \ref cardano_address_t object and attempts to create a corresponding+ * \ref cardano_enterprise_address_t object.+ *+ * \param[in] address A pointer to the \ref cardano_address_t object that is to be converted into an enterprise address.+ * \param[out] enterprise_address A pointer to a pointer to \ref cardano_enterprise_address_t that will be set+ *                                to the address of the newly created enterprise address object upon successful+ *                                conversion.+ *+ * \return Returns \ref CARDANO_SUCCESS if the conversion was successful. Returns \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         the \p address or \p enterprise_address pointer is NULL. Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the+ *         provided address cannot be converted to an enterprise address.+ *+ * \note It is the caller's responsibility to manage the lifecycle of the created \ref cardano_enterprise_address_t object,+ *       including calling `cardano_enterprise_address_unref` to free the object when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* general_address = NULL;+ * // Assume general_address is previously created and represents a valid Cardano address+ * cardano_enterprise_address_t* enterprise_address = NULL;+ * cardano_error_t result = cardano_enterprise_address_from_address(general_address, &enterprise_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The address has been successfully converted to an enterprise address+ *   // Use the enterprise address for transactions+ *+ *   // Once done, ensure to clean up and release the enterprise address+ *   cardano_enterprise_address_unref(&enterprise_address);+ * }+ * else+ * {+ *   printf("Failed to convert to enterprise address: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_enterprise_address_from_address(+  const cardano_address_t*       address,+  cardano_enterprise_address_t** enterprise_address);++/**+ * \brief Converts an enterprise address to a general Cardano address.+ *+ * This function takes a \ref cardano_enterprise_address_t object representing an enterprise address and converts+ * it to a general \ref cardano_address_t object.+ *+ * \param[in] enterprise_address A pointer to the \ref cardano_enterprise_address_t object that is to be converted+ *                               into a general Cardano address.+ *+ * \return A pointer to a newly created \ref cardano_address_t object representing the general address. Returns NULL+ *         if the \p enterprise_address is NULL or if the conversion fails due to an invalid address format.+ *+ * \note The caller is responsible for managing the lifecycle of the returned \ref cardano_address_t object, including+ *       calling `cardano_address_unref` to free the object when it is no longer needed. Failure to do so can result in+ *       memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_enterprise_address_t* enterprise_address = NULL;+ * // Assume enterprise_address is previously created and represents a valid enterprise address+ * cardano_address_t* general_address = cardano_enterprise_address_to_address(enterprise_address);+ *+ * if (general_address != NULL)+ * {+ *   // The enterprise address has been successfully converted to a general Cardano address+ *   // Use the general address as needed+ *+ *   // Once done, ensure to clean up and release the general address+ *   cardano_address_unref(&general_address);+ * }+ * else+ * {+ *   printf("Failed to convert enterprise address to a general address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_address_t* cardano_enterprise_address_to_address(+  const cardano_enterprise_address_t* enterprise_address);++/**+ * \brief Retrieves the payment credential from an enterprise address.+ *+ * This function extracts the payment credential from a \ref cardano_enterprise_address_t object.+ *+ * \param[in] enterprise_address A pointer to the \ref cardano_enterprise_address_t object from which the payment+ *                               credential is to be retrieved.+ *+ * \return A pointer to a \ref cardano_credential_t object representing the payment credential. Returns NULL if the+ *         \p enterprise_address is NULL.+ *+ * \note The lifecycle of the returned \ref cardano_credential_t object must be managed by the caller. It is important to+ *       call `cardano_credential_unref` to free this object when it is no longer needed to prevent memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_enterprise_address_t* enterprise_address = NULL;+ * // Assume enterprise_address is previously created and represents a valid enterprise address+ * cardano_credential_t* payment_credential = cardano_enterprise_address_get_payment_credential(enterprise_address);+ *+ * if (payment_credential != NULL)+ * {+ *   // The payment credential can be used to initiate transactions or for other purposes+ *   // Once done with the credential, ensure to clean up and release it+ *   cardano_credential_unref(&payment_credential);+ * }+ * else+ * {+ *   printf("Failed to retrieve payment credential from enterprise address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_enterprise_address_get_payment_credential(+  cardano_enterprise_address_t* enterprise_address);++/**+ * \brief Creates an enterprise address from a byte array.+ *+ * This function constructs a \ref cardano_enterprise_address_t object by decoding a byte array that+ * represents an enterprise address in serialized form.+ *+ * \param[in] data A pointer to the byte array containing the serialized enterprise address data.+ * \param[in] size The size of the byte array in bytes.+ * \param[out] address A pointer to a pointer to \ref cardano_enterprise_address_t that will be set to the address+ *                     of the newly created enterprise address object upon successful decoding.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully created. Returns \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p data or \p address pointer is NULL. Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the byte array data+ *         could not be decoded into a valid enterprise address.+ *+ * \note It is the caller's responsibility to manage the lifecycle of the created \ref cardano_enterprise_address_t object,+ *       including ensuring that `cardano_enterprise_address_unref` is called to free the address object when it is no+ *       longer needed, to prevent memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * byte_t serialized_address[] = { ... };  // Example serialized data+ * size_t serialized_size = sizeof(serialized_address);+ * cardano_enterprise_address_t* enterprise_address = NULL;+ *+ * cardano_error_t result = cardano_enterprise_address_from_bytes(serialized_address, serialized_size, &enterprise_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the enterprise address as needed+ *   // Once done, ensure to clean up and release the enterprise address+ *   cardano_enterprise_address_unref(&enterprise_address);+ * }+ * else+ * {+ *   printf("Failed to create enterprise address from bytes: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_enterprise_address_from_bytes(+  const byte_t*                  data,+  size_t                         size,+  cardano_enterprise_address_t** address);++/**+ * \brief Retrieves the size in bytes required to serialize an enterprise address.+ *+ * This function calculates the size necessary to store the serialized byte array representation of a given+ * \ref cardano_enterprise_address_t object. This size is useful for allocating buffer space before serializing+ * an enterprise address into its binary form.+ *+ * \param[in] address A pointer to the \ref cardano_enterprise_address_t object whose serialized size is to be retrieved.+ *+ * \return The size in bytes required to serialize the enterprise address. Returns 0 if the \p address pointer is NULL+ *         or if the address is invalid.+ *+ * Usage Example:+ * \code{.c}+ * cardano_enterprise_address_t* enterprise_address = NULL;+ * // Assume enterprise_address is already created and valid+ * size_t required_size = cardano_enterprise_address_get_bytes_size(enterprise_address);+ *+ * if (required_size > 0)+ * {+ *   byte_t* buffer = (byte_t*)malloc(required_size);+ *+ *   if (buffer)+ *   {+ *     // Proceed to serialize the enterprise address into buffer+ *   }+ *+ *   free(buffer);+ * }+ * else+ * {+ *   printf("Invalid address or unable to determine size\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_enterprise_address_get_bytes_size(const cardano_enterprise_address_t* address);++/**+ * \brief Retrieves the byte array representation of an enterprise address.+ *+ * This function provides access to the serialized byte array form of a \ref cardano_enterprise_address_t object.+ *+ * \param[in] address A pointer to the \ref cardano_enterprise_address_t object whose byte array is to be retrieved.+ *+ * \return A pointer to the constant byte array representing the enterprise address. Returns NULL if the \p address+ *         pointer is NULL.+ *+ * \note The returned byte array is managed internally and should not be freed or modified by the caller. It remains+ *       valid as long as the \ref cardano_enterprise_address_t object is not modified or freed. Use+ *       \ref cardano_enterprise_address_get_bytes_size to determine the size of the byte array.+ *+ * Usage Example:+ * \code{.c}+ * cardano_enterprise_address_t* enterprise_address = NULL;+ * // Assume enterprise_address is already created and valid+ * const byte_t* address_bytes = cardano_enterprise_address_get_bytes(enterprise_address);+ *+ * if (address_bytes != NULL)+ * {+ *   // Process or transmit the byte array+ * }+ * else+ * {+ *   printf("Failed to retrieve byte array from enterprise address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_enterprise_address_get_bytes(const cardano_enterprise_address_t* address);++/**+ * \brief Serializes an enterprise address into a byte array.+ *+ * This function takes a \ref cardano_enterprise_address_t object and serializes it into a binary format.+ * The serialized bytes are written into the provided \p data buffer, which must be large enough to hold+ * the entire binary representation of the address.+ *+ * \param[in] address A pointer to the \ref cardano_enterprise_address_t object to be serialized.+ * \param[out] data A pointer to a byte array where the serialized data will be written.+ * \param[in] size The size of the provided buffer in bytes. This size should be at least the value returned+ *                 by \ref cardano_enterprise_address_get_bytes_size for this address.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully serialized into the byte array.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the \p address or \p data pointer is NULL. Returns+ *         \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if the \p size is too small to hold the serialized data.+ *+ * Usage Example:+ * \code{.c}+ * cardano_enterprise_address_t* enterprise_address = NULL;+ * // Assume enterprise_address is previously created and valid+ * size_t required_size = cardano_enterprise_address_get_bytes_size(enterprise_address);+ * byte_t* buffer = (byte_t*)malloc(required_size);+ *+ * if (buffer)+ * {+ *   cardano_error_t result = cardano_enterprise_address_to_bytes(enterprise_address, buffer, required_size);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // The buffer now contains the serialized address+ *     // Proceed with using the buffer for storage, transmission, etc.+ *   }+ *   else+ *   {+ *     printf("Failed to serialize enterprise address: %d\n", result);+ *   }+ *+ *   free(buffer);+ * }+ * else+ * {+ *   printf("Memory allocation for buffer failed\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_enterprise_address_to_bytes(+  const cardano_enterprise_address_t* address,+  byte_t*                             data,+  size_t                              size);++/**+ * \brief Creates an enterprise address from a Bech32-encoded string.+ *+ * This function constructs a \ref cardano_enterprise_address_t object by decoding the provided+ * Bech32-encoded string that represents the address data.+ *+ * \param[in] data A pointer to a character array containing the Bech32-encoded representation of the address.+ * \param[in] size The size of the Bech32 string in bytes.+ * \param[out] address A pointer to a pointer to \ref cardano_enterprise_address_t that will be set to the address+ *                     of the newly created enterprise address object upon successful decoding.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully created. Returns \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p data or \p address pointer is NULL. Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the Bech32 data+ *         could not be decoded into a valid enterprise address. Returns \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if+ *         memory for the decoding buffers could not be allocated. Allocation failures inside the Bech32 decoder itself+ *         are reported as \ref CARDANO_ERROR_DECODING.+ *+ * Usage Example:+ * \code{.c}+ * const char* bech32_data = "addr1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx...";+ * size_t bech32_size = strlen(bech32_data);+ * cardano_enterprise_address_t* enterprise_address = NULL;+ *+ * cardano_error_t result = cardano_enterprise_address_from_bech32(bech32_data, bech32_size, &enterprise_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the enterprise address+ *+ *   // Once done, ensure to clean up and release the enterprise address+ *   cardano_enterprise_address_unref(&enterprise_address);+ * }+ * else+ * {+ *   printf("Failed to decode enterprise address from Bech32: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_enterprise_address_from_bech32(+  const char*                    data,+  size_t                         size,+  cardano_enterprise_address_t** address);++/**+ * \brief Retrieves the size in bytes of the Bech32-encoded representation of an enterprise address.+ *+ * This function calculates the size necessary to store the Bech32-encoded representation of a given+ * \ref cardano_enterprise_address_t address object. This size includes the characters needed to represent+ * the Bech32 string but does not include the null-termination character.+ *+ * \param[in] address A pointer to the \ref cardano_enterprise_address_t object whose Bech32 size is to be retrieved.+ *+ * \return The size in bytes of the Bech32-encoded representation of the address, including the null terminator.+ *         Returns 0 if the \p address pointer is NULL or if the address is invalid.+ *+ * Usage Example:+ * \code{.c}+ * cardano_enterprise_address_t* enterprise_address = NULL;+ * // Assume enterprise_address is already created and valid+ * size_t bech32_size = cardano_enterprise_address_get_bech32_size(enterprise_address);+ *+ * if (bech32_size > 0)+ * {+ *   char* bech32_string = (char*) malloc(bech32_size);+ *+ *   if (bech32_string)+ *   {+ *     // Proceed to convert address to Bech32 string+ *   }+ *+ *   free(bech32_string);+ * }+ * else+ * {+ *   printf("Invalid address or unable to determine size\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_enterprise_address_get_bech32_size(const cardano_enterprise_address_t* address);++/**+ * \brief Converts an enterprise address to a Bech32-encoded string.+ *+ * This function takes a \ref cardano_enterprise_address_t object and converts it into a Bech32 string,+ * writing the result into the provided \p data buffer. The buffer must be large enough to hold the entire+ * Bech32 string including the null-termination character.+ *+ * \param[in] address A pointer to the \ref cardano_enterprise_address_t object to be converted.+ * \param[out] data A pointer to a character buffer where the Bech32-encoded string will be stored.+ * \param[in] size The size of the provided buffer in bytes. This size must be at least the value returned+ *                 by \ref cardano_enterprise_address_get_bech32_size to ensure it can hold the Bech32 string+ *                 and the null terminator.+ *+ * \return Returns \ref CARDANO_SUCCESS if the conversion was successful. Returns \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         the \p address or \p data pointer is NULL. Returns \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if the \p size is too+ *         small to hold the Bech32 representation including the null terminator.+ *+ * \note It is crucial to ensure that the buffer provided in \p data is sufficiently large to accommodate the+ *       Bech32 string and the null-termination character to prevent buffer overflow errors.+ *+ * Usage Example:+ * \code{.c}+ * cardano_enterprise_address_t* enterprise_address = NULL;+ * // Assume enterprise_address is previously created and valid+ * size_t required_size = cardano_enterprise_address_get_bech32_size(enterprise_address) + 1; // +1 for null-termination+ * char* bech32_string = (char*) malloc(required_size);+ * if (bech32_string)+ * {+ *   cardano_error_t result = cardano_enterprise_address_to_bech32(enterprise_address, bech32_string, required_size);+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("Bech32 representation: %s\n", bech32_string);+ *   }+ *   else+ *   {+ *     printf("Failed to convert enterprise address to Bech32: %d\n", result);+ *   }+ *   free(bech32_string);+ * }+ * else+ * {+ *   printf("Memory allocation failed for Bech32 buffer\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_enterprise_address_to_bech32(+  const cardano_enterprise_address_t* address,+  char*                               data,+  size_t                              size);++/**+ * \brief Retrieves the string representation of an enterprise address.+ *+ * This function provides access to the string form of a \ref cardano_enterprise_address_t object. It allows for+ * easy display and logging of the address in a human-readable format.+ *+ * \param[in] address A pointer to the \ref cardano_enterprise_address_t object whose string representation is to be retrieved.+ *+ * \return A pointer to a constant character string representing the enterprise address. Returns NULL if the \p address+ *         pointer is NULL or if the address cannot be properly serialized into a string form.+ *+ * \note The returned string is managed internally and should not be freed or modified by the caller. It remains+ *       valid as long as the \ref cardano_enterprise_address_t object is not modified or freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_enterprise_address_t* enterprise_address = NULL;+ * // Assume enterprise_address is previously created and valid+ * const char* address_string = cardano_enterprise_address_get_string(enterprise_address);+ *+ * if (address_string != NULL)+ * {+ *   printf("Enterprise Address: %s\n", address_string);+ * }+ * else+ * {+ *   printf("Failed to retrieve string representation of the enterprise address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_enterprise_address_get_string(const cardano_enterprise_address_t* address);++/**+ * \brief Retrieves the network ID from a given Cardano enterprise address.+ *+ * This function extracts the network identifier from the provided \ref cardano_enterprise_address_t object.+ * The network ID indicates whether the address belongs to the test network or the main network.+ *+ * \param[in] address A constant pointer to the \ref cardano_enterprise_address_t object from which the network ID is to be retrieved.+ * \param[out] network_id A pointer to \ref cardano_network_id_t where the network ID will be stored upon successful+ *                        extraction. This parameter cannot be NULL.+ *+ * \return Returns \ref CARDANO_SUCCESS if the network ID was successfully retrieved.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the input address or network_id pointer is NULL.+ *         Returns other error codes as defined in \ref cardano_error_t if the network ID cannot be retrieved due to+ *         malformed or unrecognized address formats.+ *+ * Usage Example:+ * \code{.c}+ * cardano_enterprise_address_t* address = NULL;+ * cardano_network_id_t network_id;+ *+ * cardano_error_t get_network_id = cardano_enterprise_address_get_network_id(address, &network_id);+ *+ * if (get_network_id != CARDANO_SUCCESS)+ * {+ *   printf("Failed to determine the network id.\n");+ * }+ * else+ * {+ *   printf("Network ID: %d\n", network_id);+ * }+ *+ * cardano_enterprise_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_enterprise_address_get_network_id(+  const cardano_enterprise_address_t* address,+  cardano_network_id_t*               network_id);++/**+ * \brief Decrements the enterprise address's reference count.+ *+ * If the reference count reaches zero, the enterprise address memory is deallocated.+ *+ * \param[in] address Pointer to the enterprise address whose reference count is to be decremented.+ */+CARDANO_EXPORT void cardano_enterprise_address_unref(cardano_enterprise_address_t** address);++/**+ * \brief Increments the enterprise address's reference count.+ *+ * Ensures that the enterprise address remains allocated until the last reference is released.+ *+ * \param[in] address enterprise address whose reference count is to be incremented.+ */+CARDANO_EXPORT void cardano_enterprise_address_ref(cardano_enterprise_address_t* address);++/**+ * \brief Retrieves the enterprise address's current reference count.+ *+ * \warning Does not account for transitive references.+ *+ * \param[in] address Target enterprise address.+ * \return Current reference count of the enterprise address.+ */+CARDANO_EXPORT size_t cardano_enterprise_address_refcount(const cardano_enterprise_address_t* address);++/**+ * \brief Sets the last error message for a given enterprise address.+ *+ * This function records an error message in the enterprise address's last_error buffer,+ * overwriting any previous message. The message is truncated if it exceeds+ * the buffer size. This function is typically used to store descriptive+ * error information that can be retrieved later with+ * cardano_enterprise_address_get_last_error.+ *+ * \param[in,out] address A pointer to the cardano_enterprise_address_t instance whose last error+ *               message is to be set. If the enterprise address is NULL, the function+ *               has no effect.+ * \param[in] message A null-terminated string containing the error message to be+ *                recorded. If the message is NULL, the enterprise address's last_error+ *                will be set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters due to the fixed size+ *       of the last_error buffer (1024 characters), including the null+ *       terminator. Messages longer than this limit will be truncated.+ */+CARDANO_EXPORT void cardano_enterprise_address_set_last_error(cardano_enterprise_address_t* address, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific enterprise address.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_enterprise_address_set_last_error for the given+ * enterprise address. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in,out] address A pointer to the \ref cardano_enterprise_address_t instance whose last error+ *               message is to be retrieved. If the enterprise address is \c NULL, the function+ *               returns a generic error message indicating the null enterprise address.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified enterprise address. If the enterprise address is \c NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the enterprise address and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_enterprise_address_set_last_error for the same enterprise address, or until+ *       the enterprise address is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_enterprise_address_get_last_error(const cardano_enterprise_address_t* address);++/**+ * \brief Creates an independent deep copy of the address and its credentials.+ * \param[in] source Address to copy. Must not be NULL.+ * \param[out] clone Receives one owned reference, or NULL on failure. Must not be NULL.+ * \return CARDANO_SUCCESS, CARDANO_ERROR_POINTER_IS_NULL, or CARDANO_ERROR_MEMORY_ALLOCATION_FAILED.+ * \note Release the result with cardano_enterprise_address_unref. The source is unchanged.+ */+CARDANO_EXPORT cardano_error_t+cardano_enterprise_address_deep_clone(const cardano_enterprise_address_t* source, cardano_enterprise_address_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ENTERPRISE_ADDRESS_H
+ vendor/include/cardano/address/pointer_address.h view
@@ -0,0 +1,733 @@+/**+ * \file pointer_address.h+ *+ * \author angel.castillo+ * \date   Apr 15, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_POINTER_ADDRESS_H+#define BIGLUP_LABS_INCLUDE_CARDANO_POINTER_ADDRESS_H++/* INCLUDES ******************************************************************/++#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++#include <cardano/address/stake_pointer.h>+#include <cardano/common/credential.h>+#include <cardano/common/network_id.h>++/* FORWARD DECLARATIONS *****************************************************/++/**+ * \brief Represents a Cardano address.+ *+ * This structure encapsulates all the necessary information for a Cardano address.+ */+typedef struct cardano_address_t cardano_address_t;++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a pointer address in the Cardano blockchain ecosystem.+ *+ * A pointer address indirectly specifies the stake key that should control the stake for the address. It references+ * a stake key by a stake key pointer, which is a location on the blockchain of the stake key registration certificate+ * for that key.+ */+typedef struct cardano_pointer_address_t cardano_pointer_address_t;++/**+ * \brief Creates a pointer address from network and payment credentials and a stake pointer.+ *+ * This function constructs a \ref cardano_pointer_address_t object by using a network identifier,+ * payment credentials, and a stake pointer. The stake pointer directs to a stake key registration+ * certificate on the blockchain, allowing the address to indirectly specify staking rights without+ * embedding a stake key.+ *+ * \param[in] network_id The network identifier, which specifies the Cardano network (e.g., mainnet, testnet).+ * \param[in] payment A pointer to a \ref cardano_credential_t object representing the payment credentials.+ * \param[in] pointer A \ref cardano_stake_pointer_t structure that specifies the location of the stake key+ *                    registration certificate on the blockchain.+ * \param[out] pointer_address A pointer to a pointer to \ref cardano_pointer_address_t that will be set to+ *                              the address of the newly created pointer address object upon successful+ *                              address creation.+ *+ * \return Returns \ref CARDANO_SUCCESS if the pointer address was successfully created. Returns+ *         \ref CARDANO_ERROR_POINTER_IS_NULL if any of the pointers (\p payment or \p pointer_address) are NULL.+ *+ * \note The caller is responsible for managing the lifecycle of the created \ref cardano_pointer_address_t+ *       object, including ensuring that `cardano_pointer_address_unref` is called to free the address object+ *       when it is no longer needed, to prevent memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* payment_credential = ...;     // Initialized elsewhere+ * cardano_stake_pointer_t stake_pointer = { 5756214, 1, 0 };  // Example pointer to a stake key registration+ * cardano_pointer_address_t* pointer_address = NULL;+ * cardano_error_t result = cardano_pointer_address_from_credentials(+ *      CARDANO_NETWORK_ID_MAIN_NET,+ *      payment_credentials,+ *      stake_pointer,+ *      &pointer_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the pointer address as needed+ *   // Once done, ensure to clean up and release the pointer address+ *   cardano_pointer_address_unref(&pointer_address);+ * }+ * else+ * {+ *   printf("Failed to create pointer address: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pointer_address_from_credentials(+  cardano_network_id_t        network_id,+  cardano_credential_t*       payment,+  cardano_stake_pointer_t     pointer,+  cardano_pointer_address_t** pointer_address);++/**+ * \brief Converts a general Cardano address to a pointer address.+ *+ * This function takes an existing \ref cardano_address_t object and attempts to create a corresponding+ * \ref cardano_pointer_address_t object.+ *+ * \param[in] address A pointer to the \ref cardano_address_t object that is to be converted into a pointer address.+ * \param[out] pointer_address A pointer to a pointer to \ref cardano_pointer_address_t that will be set+ *                              to the address of the newly created pointer address object upon successful+ *                              conversion.+ *+ * \return Returns \ref CARDANO_SUCCESS if the conversion was successful. Returns \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         the \p address or \p pointer_address pointer is NULL. Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the+ *         provided address cannot be converted to a pointer address.+ *+ * \note It is the caller's responsibility to manage the lifecycle of the created \ref cardano_pointer_address_t object,+ *       including calling `cardano_pointer_address_unref` to free the address object when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* general_address = NULL;+ * // Assume general_address is previously created and represents a valid Cardano address+ * cardano_pointer_address_t* pointer_address = NULL;+ * cardano_error_t result = cardano_pointer_address_from_address(general_address, &pointer_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The address has been successfully converted to a pointer address+ *   // Use the pointer address as needed+ *+ *   // Once done, ensure to clean up and release the pointer address+ *   cardano_pointer_address_unref(&pointer_address);+ * }+ * else+ * {+ *   printf("Failed to convert to pointer address: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pointer_address_from_address(+  const cardano_address_t*    address,+  cardano_pointer_address_t** pointer_address);++/**+ * \brief Converts a pointer address to a general Cardano address.+ *+ * This function takes a \ref cardano_pointer_address_t object representing a pointer address and converts+ * it back to a general \ref cardano_address_t object. This is useful for operations that require the use of+ * a generic address format instead of a pointer-specific format, particularly in interfaces that do not support+ * the direct use of pointer addresses.+ *+ * \param[in] pointer_address A pointer to the \ref cardano_pointer_address_t object that is to be converted+ *                            into a general Cardano address.+ *+ * \return A pointer to a newly created \ref cardano_address_t object representing the general address. Returns NULL+ *         if the \p pointer_address is NULL.+ *+ * \note The caller is responsible for managing the lifecycle of the returned \ref cardano_address_t object, including+ *       calling `cardano_address_unref` to free the object when it is no longer needed. Failure to do so can result in+ *       memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* pointer_address = NULL;+ * // Assume pointer_address is previously created and represents a valid pointer address+ * cardano_address_t* general_address = cardano_pointer_address_to_address(pointer_address);+ *+ * if (general_address != NULL)+ * {+ *   // The pointer address has been successfully converted to a general Cardano address+ *   // Use the general address as needed+ *+ *   // Once done, ensure to clean up and release the general address+ *   cardano_address_unref(&general_address);+ * }+ * else+ * {+ *   printf("Failed to convert pointer address to a general address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_address_t* cardano_pointer_address_to_address(+  const cardano_pointer_address_t* pointer_address);++/**+ * \brief Retrieves the payment credential from a pointer address.+ *+ * This function extracts the payment credential from a \ref cardano_pointer_address_t object.+ *+ * \param[in] pointer_address A pointer to the \ref cardano_pointer_address_t object from which the payment+ *                            credential is to be retrieved.+ *+ * \return A pointer to a \ref cardano_credential_t object representing the payment credential. Returns NULL if the+ *         \p pointer_address is NULL.+ *+ * \note The lifecycle of the returned \ref cardano_credential_t object must be managed by the caller. It is important to+ *       call `cardano_credential_unref` to free this object when it is no longer needed to prevent memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* pointer_address = NULL;+ * // Assume pointer_address is previously created and represents a valid pointer address+ * const cardano_credential_t* payment_credential = cardano_pointer_address_get_payment_credential(pointer_address);+ *+ * if (payment_credential != NULL)+ * {+ *   // The payment credential can be used to initiate transactions or for other purposes+ *+ *   cardano_credential_unref(&payment_credential);+ * }+ * else+ * {+ *   printf("Failed to retrieve payment credential from pointer address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_pointer_address_get_payment_credential(+  cardano_pointer_address_t* pointer_address);++/**+ * \brief Retrieves the stake pointer from a pointer address.+ *+ * This function extracts the stake pointer from a \ref cardano_pointer_address_t object.+ *+ * \param[in] address A pointer to the \ref cardano_pointer_address_t object from which the stake pointer+ *                    is to be retrieved.+ * \param[out] pointer A pointer to a \ref cardano_stake_pointer_t structure that will be populated with the+ *                     stake pointer information if the retrieval is successful.+ *+ * \return Returns \ref CARDANO_SUCCESS if the stake pointer was successfully retrieved. Returns+ *         \ref CARDANO_ERROR_POINTER_IS_NULL if the \p address or \p pointer argument is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* pointer_address = NULL;+ * // Assume pointer_address is previously created and represents a valid pointer address+ * cardano_stake_pointer_t stake_pointer;+ * cardano_error_t result = cardano_pointer_address_get_stake_pointer(pointer_address, &stake_pointer);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Stake Pointer - Slot: %llu, Tx Index: %llu, Cert Index: %llu\n",+ *          stake_pointer.slot, stake_pointer.tx_index, stake_pointer.cert_index);+ * }+ * else+ * {+ *   printf("Failed to retrieve stake pointer from address: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pointer_address_get_stake_pointer(+  const cardano_pointer_address_t* address,+  cardano_stake_pointer_t*         pointer);++/**+ * \brief Creates a pointer address from a byte array.+ *+ * This function constructs a \ref cardano_pointer_address_t object by decoding a byte array that+ * represents a pointer address in serialized form.+ *+ * \param[in] data A pointer to the byte array containing the serialized pointer address data.+ * \param[in] size The size of the byte array in bytes.+ * \param[out] address A pointer to a pointer to \ref cardano_pointer_address_t that will be set to the address+ *                     of the newly created pointer address object upon successful decoding.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully created. Returns \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p data or \p address pointer is NULL. Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the byte array data+ *         could not be decoded into a valid pointer address.+ *+ * \note It is the caller's responsibility to manage the lifecycle of the created \ref cardano_pointer_address_t object,+ *       including ensuring that `cardano_pointer_address_unref` is called to free the address object when it is no+ *       longer needed, to prevent memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * byte_t serialized_address[] = { ... };+ * size_t serialized_size = sizeof(serialized_address);+ * cardano_pointer_address_t* pointer_address = NULL;+ *+ * cardano_error_t result = cardano_pointer_address_from_bytes(serialized_address, serialized_size, &pointer_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the pointer address as needed+ *   // Once done, ensure to clean up and release the pointer address+ *   cardano_pointer_address_unref(&pointer_address);+ * }+ * else+ * {+ *   printf("Failed to create pointer address from bytes: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pointer_address_from_bytes(+  const byte_t*               data,+  size_t                      size,+  cardano_pointer_address_t** address);++/**+ * \brief Retrieves the size in bytes required to serialize a pointer address.+ *+ * This function calculates the size necessary to store the serialized byte array representation of a given+ * \ref cardano_pointer_address_t object.+ *+ * \param[in] address A pointer to the \ref cardano_pointer_address_t object whose serialized size is to be retrieved.+ *+ * \return The size in bytes required to serialize the pointer address. Returns 0 if the \p address pointer is NULL+ *         or if the address is invalid.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* pointer_address = NULL;+ * // Assume pointer_address is already created and valid+ * size_t required_size = cardano_pointer_address_get_bytes_size(pointer_address);+ *+ * if (required_size > 0)+ * {+ *   byte_t* buffer = (byte_t*)malloc(required_size);+ *+ *   if (buffer)+ *   {+ *     // Proceed to serialize the pointer address into buffer+ *   }+ *+ *  free(buffer);+ * }+ * else+ * {+ *   printf("Invalid address or unable to determine size\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_pointer_address_get_bytes_size(const cardano_pointer_address_t* address);++/**+ * \brief Retrieves the byte array representation of a pointer address.+ *+ * This function provides access to the serialized byte array form of a \ref cardano_pointer_address_t object.+ *+ * \param[in] address A pointer to the \ref cardano_pointer_address_t object whose byte array is to be retrieved.+ *+ * \return A pointer to the constant byte array representing the pointer address. Returns NULL if the \p address+ *         pointer is NULL.+ *+ * \note The returned byte array is managed internally and should not be freed or modified by the caller. It remains+ *       valid as long as the \ref cardano_pointer_address_t object is not modified or freed. Use+ *       \ref cardano_pointer_address_get_bytes_size to determine the size of the byte array.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* pointer_address = NULL;+ * // Assume pointer_address is already created and valid+ * const byte_t* address_bytes = cardano_pointer_address_get_bytes(pointer_address);+ * size_t bytes_size = cardano_pointer_address_get_bytes_size(pointer_address);+ *+ * if (address_bytes != NULL)+ * {+ *   // Process or transmit the byte array+ * }+ * else+ * {+ *   printf("Failed to retrieve byte array from pointer address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_pointer_address_get_bytes(const cardano_pointer_address_t* address);++/**+ * \brief Serializes a pointer address into a byte array.+ *+ * This function takes a \ref cardano_pointer_address_t object and serializes it into a binary format.+ * The serialized bytes are written into the provided \p data buffer, which must be large enough to hold+ * the entire binary representation of the address.+ *+ * \param[in] address A pointer to the \ref cardano_pointer_address_t object to be serialized.+ * \param[out] data A pointer to a byte array where the serialized data will be written.+ * \param[in] size The size of the provided buffer in bytes. This size should be at least the value returned+ *                 by \ref cardano_pointer_address_get_bytes_size to ensure it can hold the serialized data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully serialized into the byte array.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the \p address or \p data pointer is NULL. Returns+ *         \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if the \p size is too small to hold the serialized data.+ *+ * \note The buffer provided in \p data must be sufficiently large to accommodate+ *       the serialized data to prevent buffer overflow errors.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* pointer_address = NULL;+ * // Assume pointer_address is previously created and valid+ * size_t required_size = cardano_pointer_address_get_bytes_size(pointer_address);+ * byte_t* buffer = (byte_t*)malloc(required_size);+ *+ * if (buffer)+ * {+ *   cardano_error_t result = cardano_pointer_address_to_bytes(pointer_address, buffer, required_size);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // The buffer now contains the serialized address+ *     // Proceed with using the buffer for storage, transmission, etc.+ *   }+ *   else+ *   {+ *     printf("Failed to serialize pointer address: %d\n", result);+ *   }+ *+ *  free(buffer);+ * }+ * else+ * {+ *   printf("Memory allocation for buffer failed\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pointer_address_to_bytes(+  const cardano_pointer_address_t* address,+  byte_t*                          data,+  size_t                           size);++/**+ * \brief Creates a pointer address from a Bech32-encoded string.+ *+ * This function constructs a \ref cardano_pointer_address_t object by decoding the provided+ * Bech32-encoded string that represents the address data.+ *+ * \param[in] data A pointer to a character array containing the Bech32-encoded representation of the address.+ * \param[in] size The size of the Bech32 string in bytes.+ * \param[out] address A pointer to a pointer to \ref cardano_pointer_address_t that will be set to the address+ *                     of the newly created pointer address object upon successful decoding.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully created. Returns \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p data or \p address pointer is NULL. Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the Bech32 data+ *         could not be decoded into a valid pointer address. Returns \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if+ *         memory for the decoding buffers could not be allocated. Allocation failures inside the Bech32 decoder itself+ *         are reported as \ref CARDANO_ERROR_DECODING.+ *+ * Usage Example:+ * \code{.c}+ * const char* bech32_data = "addr1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx...";+ * size_t bech32_size = strlen(bech32_data);+ * cardano_pointer_address_t* cardano_pointer = NULL;+ *+ * cardano_error_t result = cardano_pointer_address_from_bech32(bech32_data, bech32_size, &cardano_pointer);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the pointer address+ *+ *   // Once done, ensure to clean up and release the pointer address+ *   cardano_pointer_address_unref(&cardano_pointer);+ * }+ * else+ * {+ *   printf("Failed to decode pointer address from Bech32: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pointer_address_from_bech32(+  const char*                 data,+  size_t                      size,+  cardano_pointer_address_t** address);++/**+ * \brief Retrieves the size in bytes of the Bech32-encoded representation of a pointer address.+ *+ * This function calculates the size necessary to store the Bech32-encoded representation of a given+ * \ref cardano_pointer_address_t address object. This size includes the characters needed to represent+ * the Bech32 string but does not include the null-termination character.+ *+ * \param[in] address A pointer to the \ref cardano_pointer_address_t object whose Bech32 size is to be retrieved.+ *+ * \return The size in bytes of the Bech32-encoded representation of the address, including the null terminator.+ *         Returns 0 if the \p address pointer is NULL or if the address is invalid.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* cardano_pointer = NULL;+ * // Assume cardano_pointer is already created and valid+ * size_t bech32_size = cardano_pointer_address_get_bech32_size(cardano_pointer);+ *+ * if (bech32_size > 0)+ * {+ *   char* bech32_string = (char*) malloc(bech32_size);+ *+ *   if (bech32_string)+ *   {+ *     // Proceed to convert address to Bech32 string+ *   }+ *+ *   free(bech32_string);+ * }+ * else+ * {+ *   printf("Invalid address or unable to determine size\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_pointer_address_get_bech32_size(const cardano_pointer_address_t* address);++/**+ * \brief Converts a pointer address to a Bech32-encoded string.+ *+ * This function takes a \ref cardano_pointer_address_t object and converts it into a Bech32 string,+ * writing the result into the provided \p data buffer. The buffer must be large enough to hold the entire+ * Bech32 string including the null-termination character.+ *+ * \param[in] address A pointer to the \ref cardano_pointer_address_t object to be converted.+ * \param[out] data A pointer to a character buffer where the Bech32-encoded string will be stored.+ * \param[in] size The size of the provided buffer in bytes. This size must be at least the value returned+ *                 by \ref cardano_pointer_address_get_bech32_size to ensure it can hold the Bech32 string+ *                 and the null terminator.+ *+ * \return Returns \ref CARDANO_SUCCESS if the conversion was successful. Returns \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         the \p address or \p data pointer is NULL. Returns \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if the \p size is too+ *         small to hold the Bech32 representation including the null terminator.+ *+ * \note It is crucial to ensure that the buffer provided in \p data is sufficiently large to accommodate the+ *       Bech32 string and the null-termination character to prevent buffer overflow errors.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* cardano_pointer = NULL;+ * // Assume cardano_pointer is previously created and valid+ * size_t required_size = cardano_pointer_address_get_bech32_size(cardano_pointer) + 1; // +1 for null-termination+ * char* bech32_string = (char*) malloc(required_size);+ * if (bech32_string)+ * {+ *   cardano_error_t result = cardano_pointer_address_to_bech32(cardano_pointer, bech32_string, required_size);+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("Bech32 representation: %s\n", bech32_string);+ *   }+ *   else+ *   {+ *     printf("Failed to convert pointer address to Bech32: %d\n", result);+ *   }+ *   free(bech32_string);+ * }+ * else+ * {+ *   printf("Memory allocation failed for Bech32 buffer\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pointer_address_to_bech32(+  const cardano_pointer_address_t* address,+  char*                            data,+  size_t                           size);++/**+ * \brief Retrieves the string representation of a pointer address.+ *+ * This function provides access to the string form of a \ref cardano_pointer_address_t object. It allows for+ * easy display and logging of the address in a human-readable format.+ *+ * \param[in] address A pointer to the \ref cardano_pointer_address_t object whose string representation is to be retrieved.+ *+ * \return A pointer to a constant character string representing the pointer address. Returns NULL if the \p address+ *         pointer is NULL or if the address cannot be properly serialized into a string form.+ *+ * \note The returned string is managed internally and should not be freed or modified by the caller. It remains+ *       valid as long as the \ref cardano_pointer_address_t object is not modified or freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* cardano_pointer = NULL;+ * // Assume cardano_pointer is previously created and valid+ * const char* address_string = cardano_pointer_address_get_string(cardano_pointer);+ *+ * if (address_string != NULL)+ * {+ *   printf("Pointer Address: %s\n", address_string);+ * }+ * else+ * {+ *   printf("Failed to retrieve string representation of the pointer address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_pointer_address_get_string(const cardano_pointer_address_t* address);++/**+ * \brief Retrieves the network ID from a given Cardano pointer address.+ *+ * This function extracts the network identifier from the provided \ref cardano_pointer_address_t object.+ * The network ID indicates whether the address belongs to the test network or the main network.+ *+ * \param[in] address A constant pointer to the \ref cardano_pointer_address_t object from which the network ID is to be retrieved.+ * \param[out] network_id A pointer to \ref cardano_network_id_t where the network ID will be stored upon successful+ *                        extraction. This parameter cannot be NULL.+ *+ * \return Returns \ref CARDANO_SUCCESS if the network ID was successfully retrieved.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the input address or network_id pointer is NULL.+ *         Returns other error codes as defined in \ref cardano_error_t if the network ID cannot be retrieved due to+ *         malformed or unrecognized address formats.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pointer_address_t* address = NULL;+ * cardano_network_id_t network_id;+ *+ * cardano_error_t get_network_id = cardano_pointer_address_get_network_id(address, &network_id);+ *+ * if (get_network_id != CARDANO_SUCCESS)+ * {+ *   printf("Failed to determine the network id.\n");+ * }+ * else+ * {+ *   printf("Network ID: %d\n", network_id);+ * }+ *+ * cardano_pointer_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pointer_address_get_network_id(+  const cardano_pointer_address_t* address,+  cardano_network_id_t*            network_id);++/**+ * \brief Decrements the pointer address's reference count.+ *+ * If the reference count reaches zero, the pointer address memory is deallocated.+ *+ * \param[in] address Pointer to the pointer address whose reference count is to be decremented.+ */+CARDANO_EXPORT void cardano_pointer_address_unref(cardano_pointer_address_t** address);++/**+ * \brief Increments the pointer address's reference count.+ *+ * Ensures that the pointer address remains allocated until the last reference is released.+ *+ * \param[in] address pointer address whose reference count is to be incremented.+ */+CARDANO_EXPORT void cardano_pointer_address_ref(cardano_pointer_address_t* address);++/**+ * \brief Retrieves the pointer address's current reference count.+ *+ * \warning Does not account for transitive references.+ *+ * \param[in] address Target pointer address.+ * \return Current reference count of the pointer address.+ */+CARDANO_EXPORT size_t cardano_pointer_address_refcount(const cardano_pointer_address_t* address);++/**+ * \brief Sets the last error message for a given pointer address.+ *+ * This function records an error message in the pointer address's last_error buffer,+ * overwriting any previous message. The message is truncated if it exceeds+ * the buffer size. This function is typically used to store descriptive+ * error information that can be retrieved later with+ * cardano_pointer_address_get_last_error.+ *+ * \param[in,out] address A pointer to the cardano_pointer_address_t instance whose last error+ *               message is to be set. If the pointer address is NULL, the function+ *               has no effect.+ * \param[in] message A null-terminated string containing the error message to be+ *                recorded. If the message is NULL, the pointer address's last_error+ *                will be set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters due to the fixed size+ *       of the last_error buffer (1024 characters), including the null+ *       terminator. Messages longer than this limit will be truncated.+ */+CARDANO_EXPORT void cardano_pointer_address_set_last_error(cardano_pointer_address_t* address, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific pointer address.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_pointer_address_set_last_error for the given+ * pointer address. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in,out] address A pointer to the \ref cardano_pointer_address_t instance whose last error+ *               message is to be retrieved. If the pointer address is \c NULL, the function+ *               returns a generic error message indicating the null pointer address.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified pointer address. If the pointer address is \c NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the pointer address and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_pointer_address_set_last_error for the same pointer address, or until+ *       the pointer address is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_pointer_address_get_last_error(const cardano_pointer_address_t* address);++/**+ * \brief Creates an independent deep copy of the address and its credentials.+ * \param[in] source Address to copy. Must not be NULL.+ * \param[out] clone Receives one owned reference, or NULL on failure. Must not be NULL.+ * \return CARDANO_SUCCESS, CARDANO_ERROR_POINTER_IS_NULL, or CARDANO_ERROR_MEMORY_ALLOCATION_FAILED.+ * \note Release the result with cardano_pointer_address_unref. The source is unchanged.+ */+CARDANO_EXPORT cardano_error_t+cardano_pointer_address_deep_clone(const cardano_pointer_address_t* source, cardano_pointer_address_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_POINTER_ADDRESS_H
+ vendor/include/cardano/address/reward_address.h view
@@ -0,0 +1,668 @@+/**+ * \file reward_address.h+ *+ * \author angel.castillo+ * \date   Apr 15, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_REWARD_ADDRESS_H+#define BIGLUP_LABS_INCLUDE_CARDANO_REWARD_ADDRESS_H++/* INCLUDES ******************************************************************/++#include <cardano/common/credential.h>+#include <cardano/common/network_id.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* FORWARD DECLARATIONS *****************************************************/++/**+ * \brief Represents a reward address in the Cardano blockchain ecosystem.+ */+typedef struct cardano_address_t cardano_address_t;++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a reward address in the Cardano blockchain ecosystem.+ *+ * A reward address is a cryptographic hash of the public stake key of the address. Reward account addresses are used+ * to distribute rewards for participating in the proof-of-stake protocol (either directly or via delegation).+ */+typedef struct cardano_reward_address_t cardano_reward_address_t;++/**+ * \brief Creates a reward address from network and credentials.+ *+ * This function constructs a \ref cardano_reward_address_t object by using a network identifier and+ * credentials.+ *+ * \param[in] network_id The network identifier, which specifies the Cardano network (e.g., mainnet, testnet).+ * \param[in] credential A pointer to a \ref cardano_credential_t object representing the credentials,+ *                    typically linked to a staking key.+ * \param[out] reward_address A pointer to a pointer to \ref cardano_reward_address_t that will be set to+ *                            the address of the newly created reward address object upon successful+ *                            address creation.+ *+ * \return Returns \ref CARDANO_SUCCESS if the reward address was successfully created. Returns+ *         \ref CARDANO_ERROR_POINTER_IS_NULL if any of the pointers (\p  or \p reward_address) are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t credential = {...};  // Initialized elsewhere+ * cardano_reward_address_t* reward_address = NULL;+ * cardano_error_t result = cardano_reward_address_from_credentials(CARDANO_NETWORK_ID_MAIN_NET, &credential, &reward_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the reward address for receiving staking rewards+ *   // Once done, ensure to clean up and release the reward address+ *   cardano_reward_address_unref(&reward_address);+ * }+ * else+ * {+ *   printf("Failed to create reward address: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_reward_address_from_credentials(+  cardano_network_id_t       network_id,+  cardano_credential_t*      credential,+  cardano_reward_address_t** reward_address);++/**+ * \brief Converts a general Cardano address to a specific reward address.+ *+ * This function constructs a \ref cardano_reward_address_t object from an existing \ref cardano_address_t object.+ *+ * \param[in] address A pointer to the \ref cardano_address_t object that represents a general Cardano address.+ * \param[out] reward_address A pointer to a pointer to \ref cardano_reward_address_t that will be set to+ *                            the address of the newly created reward address object upon successful conversion.+ *+ * \return Returns \ref CARDANO_SUCCESS if the reward address was successfully created. Returns+ *         \ref CARDANO_ERROR_POINTER_IS_NULL if any of the pointers (\p address or \p reward_address) are NULL.+ *+ * \note It is the responsibility of the caller to manage the lifecycle of the created \ref cardano_reward_address_t object,+ *       ensuring that `cardano_reward_address_unref` is called to free the address object when it is no longer needed,+ *       to prevent memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_address_t* general_address = NULL;  // Assume general_address is previously created and valid+ * cardano_reward_address_t* reward_address = NULL;+ * cardano_error_t result = cardano_reward_address_from_address(general_address, &reward_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Once done, ensure to clean up and release the reward address+ *   cardano_reward_address_unref(&reward_address);+ * }+ * else+ * {+ *   printf("Failed to convert to reward address: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_reward_address_from_address(+  const cardano_address_t*   address,+  cardano_reward_address_t** reward_address);++/**+ * \brief Converts a reward address to a general Cardano address.+ *+ * This function takes a \ref cardano_reward_address_t object representing a reward address and converts+ * it back to a general \ref cardano_address_t object.+ *+ * \param[in] reward_address A pointer to the \ref cardano_reward_address_t object that is to be converted+ *                           into a general Cardano address.+ *+ * \return A pointer to a newly created \ref cardano_address_t object representing the general address. Returns NULL+ *         if the \p reward_address is NULL.+ *+ * \note The caller is responsible for managing the lifecycle of the returned \ref cardano_address_t object, including+ *       calling `cardano_address_unref` to free the object when it is no longer needed. Failure to do so can result in+ *       memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* reward_address = NULL;+ * // Assume reward_address is previously created and represents a valid reward address+ * cardano_address_t* general_address = cardano_reward_address_to_address(reward_address);+ *+ * if (general_address != NULL)+ * {+ *   // The reward address has been successfully converted to a general Cardano address+ *   // Use the general address as needed+ *+ *   // Once done, ensure to clean up and release the general address+ *   cardano_address_unref(&general_address);+ * }+ * else+ * {+ *   printf("Failed to convert reward address to a general address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_address_t* cardano_reward_address_to_address(+  const cardano_reward_address_t* reward_address);++/**+ * \brief Retrieves the credential from a reward address.+ *+ * This function extracts the credential from a \ref cardano_reward_address_t object.+ *+ * \param[in] reward_address A pointer to the \ref cardano_reward_address_t object from which the+ *                           credential is to be retrieved.+ *+ * \note The lifecycle of the returned \ref cardano_credential_t object must be managed by the caller. It is important to+ *       call `cardano_credential_unref` to free this object when it is no longer needed to prevent memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* reward_address = NULL;+ * // Assume reward_address is previously created and represents a valid reward address+ * const cardano_credential_t* _credential = cardano_reward_address_get__credential(reward_address);+ *+ * if (_credential != NULL)+ * {+ *   // The credential can be used for transactions or other purposes+ *+ *   cardano_credential_unref(&_credential);+ * }+ * else+ * {+ *   printf("Failed to retrieve credential from reward address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_reward_address_get_credential(+  cardano_reward_address_t* reward_address);++/**+ * \brief Creates a pointer address from a byte array.+ *+ * This function constructs a \ref cardano_reward_address_t object by decoding a byte array that+ * represents a pointer address in serialized form.+ *+ * \param[in] data A pointer to the byte array containing the serialized pointer address data.+ * \param[in] size The size of the byte array in bytes.+ * \param[out] address A pointer to a pointer to \ref cardano_reward_address_t that will be set to the address+ *                     of the newly created pointer address object upon successful decoding.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully created. Returns \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p data or \p address pointer is NULL. Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the byte array data+ *         could not be decoded into a valid pointer address.+ *+ * \note It is the caller's responsibility to manage the lifecycle of the created \ref cardano_reward_address_t object,+ *       including ensuring that `cardano_reward_address_unref` is called to free the address object when it is no+ *       longer needed, to prevent memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * byte_t serialized_address[] = { ... };+ * size_t serialized_size = sizeof(serialized_address);+ * cardano_reward_address_t* reward_address = NULL;+ *+ * cardano_error_t result = cardano_reward_address_from_bytes(serialized_address, serialized_size, &reward_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the pointer address as needed+ *   // Once done, ensure to clean up and release the pointer address+ *   cardano_reward_address_unref(&reward_address);+ * }+ * else+ * {+ *   printf("Failed to create pointer address from bytes: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_reward_address_from_bytes(+  const byte_t*              data,+  size_t                     size,+  cardano_reward_address_t** address);++/**+ * \brief Retrieves the size in bytes required to serialize a pointer address.+ *+ * This function calculates the size necessary to store the serialized byte array representation of a given+ * \ref cardano_reward_address_t object.+ *+ * \param[in] address A pointer to the \ref cardano_reward_address_t object whose serialized size is to be retrieved.+ *+ * \return The size in bytes required to serialize the pointer address. Returns 0 if the \p address pointer is NULL+ *         or if the address is invalid.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* reward_address = NULL;+ * // Assume reward_address is already created and valid+ * size_t required_size = cardano_reward_address_get_bytes_size(reward_address);+ *+ * if (required_size > 0)+ * {+ *   byte_t* buffer = (byte_t*)malloc(required_size);+ *+ *   if (buffer)+ *   {+ *     // Proceed to serialize the pointer address into buffer+ *   }+ *+ *  free(buffer);+ * }+ * else+ * {+ *   printf("Invalid address or unable to determine size\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_reward_address_get_bytes_size(const cardano_reward_address_t* address);++/**+ * \brief Retrieves the byte array representation of a pointer address.+ *+ * This function provides access to the serialized byte array form of a \ref cardano_reward_address_t object.+ *+ * \param[in] address A pointer to the \ref cardano_reward_address_t object whose byte array is to be retrieved.+ *+ * \return A pointer to the constant byte array representing the pointer address. Returns NULL if the \p address+ *         pointer is NULL.+ *+ * \note The returned byte array is managed internally and should not be freed or modified by the caller. It remains+ *       valid as long as the \ref cardano_reward_address_t object is not modified or freed. Use+ *       \ref cardano_reward_address_get_bytes_size to determine the size of the byte array.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* reward_address = NULL;+ * // Assume reward_address is already created and valid+ * const byte_t* address_bytes = cardano_reward_address_get_bytes(reward_address);+ * size_t bytes_size = cardano_reward_address_get_bytes_size(reward_address);+ *+ * if (address_bytes != NULL)+ * {+ *   // Process or transmit the byte array+ * }+ * else+ * {+ *   printf("Failed to retrieve byte array from pointer address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_reward_address_get_bytes(const cardano_reward_address_t* address);++/**+ * \brief Serializes a pointer address into a byte array.+ *+ * This function takes a \ref cardano_reward_address_t object and serializes it into a binary format.+ * The serialized bytes are written into the provided \p data buffer, which must be large enough to hold+ * the entire binary representation of the address.+ *+ * \param[in] address A pointer to the \ref cardano_reward_address_t object to be serialized.+ * \param[out] data A pointer to a byte array where the serialized data will be written.+ * \param[in] size The size of the provided buffer in bytes. This size should be at least the value returned+ *                 by \ref cardano_reward_address_get_bytes_size to ensure it can hold the serialized data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully serialized into the byte array.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the \p address or \p data pointer is NULL. Returns+ *         \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if the \p size is too small to hold the serialized data.+ *+ * \note The buffer provided in \p data must be sufficiently large to accommodate+ *       the serialized data to prevent buffer overflow errors.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* reward_address = NULL;+ * // Assume reward_address is previously created and valid+ * size_t required_size = cardano_reward_address_get_bytes_size(reward_address);+ * byte_t* buffer = (byte_t*)malloc(required_size);+ *+ * if (buffer)+ * {+ *   cardano_error_t result = cardano_reward_address_to_bytes(reward_address, buffer, required_size);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // The buffer now contains the serialized address+ *     // Proceed with using the buffer for storage, transmission, etc.+ *   }+ *   else+ *   {+ *     printf("Failed to serialize pointer address: %d\n", result);+ *   }+ *+ *  free(buffer);+ * }+ * else+ * {+ *   printf("Memory allocation for buffer failed\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_reward_address_to_bytes(+  const cardano_reward_address_t* address,+  byte_t*                         data,+  size_t                          size);++/**+ * \brief Creates an  reward address from a Bech32-encoded string.+ *+ * This function constructs a \ref cardano_reward_address_t object by decoding the provided+ * Bech32-encoded string that represents the address data.+ *+ * \param[in] data A pointer to a character array containing the Bech32-encoded representation of the address.+ * \param[in] size The size of the Bech32 string in bytes.+ * \param[out] address A pointer to a pointer to \ref cardano_reward_address_t that will be set to the address+ *                     of the newly created  reward address object upon successful decoding.+ *+ * \return Returns \ref CARDANO_SUCCESS if the address was successfully created. Returns \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p data or \p address pointer is NULL. Returns \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the Bech32 data+ *         could not be decoded into a valid reward address. Returns \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if+ *         memory for the decoding buffers could not be allocated. Allocation failures inside the Bech32 decoder itself+ *         are reported as \ref CARDANO_ERROR_DECODING.+ *+ * Usage Example:+ * \code{.c}+ * const char* bech32_data = "addr1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx...";+ * size_t bech32_size = strlen(bech32_data);+ * cardano_reward_address_t* cardano_reward_address = NULL;+ *+ * cardano_error_t result = cardano_reward_address_from_bech32(bech32_data, bech32_size, &cardano_reward_address);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the  reward address+ *+ *   // Once done, ensure to clean up and release the  reward address+ *   cardano_reward_address_unref(&cardano_reward_address);+ * }+ * else+ * {+ *   printf("Failed to decode  reward address from Bech32: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_reward_address_from_bech32(+  const char*                data,+  size_t                     size,+  cardano_reward_address_t** address);++/**+ * \brief Retrieves the size in bytes of the Bech32-encoded representation of an  reward address.+ *+ * This function calculates the size necessary to store the Bech32-encoded representation of a given+ * \ref cardano_reward_address_t address object. This size includes the characters needed to represent+ * the Bech32 string but does not include the null-termination character.+ *+ * \param[in] address A pointer to the \ref cardano_reward_address_t object whose Bech32 size is to be retrieved.+ *+ * \return The size in bytes of the Bech32-encoded representation of the address, including the null terminator.+ *         Returns 0 if the \p address pointer is NULL or if the address is invalid.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* cardano_reward_address = NULL;+ * // Assume cardano_reward_address is already created and valid+ * size_t bech32_size = cardano_reward_address_get_bech32_size(cardano_reward_address);+ *+ * if (bech32_size > 0)+ * {+ *   char* bech32_string = (char*) malloc(bech32_size);+ *+ *   if (bech32_string)+ *   {+ *     // Proceed to convert address to Bech32 string+ *   }+ *+ *   free(bech32_string);+ * }+ * else+ * {+ *   printf("Invalid address or unable to determine size\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_reward_address_get_bech32_size(const cardano_reward_address_t* address);++/**+ * \brief Converts an  reward address to a Bech32-encoded string.+ *+ * This function takes a \ref cardano_reward_address_t object and converts it into a Bech32 string,+ * writing the result into the provided \p data buffer. The buffer must be large enough to hold the entire+ * Bech32 string including the null-termination character.+ *+ * \param[in] address A pointer to the \ref cardano_reward_address_t object to be converted.+ * \param[out] data A pointer to a character buffer where the Bech32-encoded string will be stored.+ * \param[in] size The size of the provided buffer in bytes. This size must be at least the value returned+ *                 by \ref cardano_reward_address_get_bech32_size to ensure it can hold the Bech32 string+ *                 and the null terminator.+ *+ * \return Returns \ref CARDANO_SUCCESS if the conversion was successful. Returns \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         the \p address or \p data pointer is NULL. Returns \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if the \p size is too+ *         small to hold the Bech32 representation including the null terminator.+ *+ * \note It is crucial to ensure that the buffer provided in \p data is sufficiently large to accommodate the+ *       Bech32 string and the null-termination character to prevent buffer overflow errors.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* cardano_reward_address = NULL;+ * // Assume cardano_reward_address is previously created and valid+ * size_t required_size = cardano_reward_address_get_bech32_size(cardano_reward_address) + 1; // +1 for null-termination+ * char* bech32_string = (char*) malloc(required_size);+ * if (bech32_string)+ * {+ *   cardano_error_t result = cardano_reward_address_to_bech32(cardano_reward_address, bech32_string, required_size);+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("Bech32 representation: %s\n", bech32_string);+ *   }+ *   else+ *   {+ *     printf("Failed to convert  reward address to Bech32: %d\n", result);+ *   }+ *   free(bech32_string);+ * }+ * else+ * {+ *   printf("Memory allocation failed for Bech32 buffer\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_reward_address_to_bech32(+  const cardano_reward_address_t* address,+  char*                           data,+  size_t                          size);++/**+ * \brief Retrieves the string representation of an  reward address.+ *+ * This function provides access to the string form of a \ref cardano_reward_address_t object. It allows for+ * easy display and logging of the address in a human-readable format.+ *+ * \param[in] address A pointer to the \ref cardano_reward_address_t object whose string representation is to be retrieved.+ *+ * \return A pointer to a constant character string representing the  reward address. Returns NULL if the \p address+ *         pointer is NULL or if the address cannot be properly serialized into a string form.+ *+ * \note The returned string is managed internally and should not be freed or modified by the caller. It remains+ *       valid as long as the \ref cardano_reward_address_t object is not modified or freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* cardano_reward_address = NULL;+ * // Assume cardano_reward_address is previously created and valid+ * const char* address_string = cardano_reward_address_get_string(cardano_reward_address);+ *+ * if (address_string != NULL)+ * {+ *   printf("Enterprise Address: %s\n", address_string);+ * }+ * else+ * {+ *   printf("Failed to retrieve string representation of the  reward address\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_reward_address_get_string(const cardano_reward_address_t* address);++/**+ * \brief Retrieves the network ID from a given Cardano reward address.+ *+ * This function extracts the network identifier from the provided \ref cardano_reward_address_t object.+ * The network ID indicates whether the address belongs to the test network or the main network.+ *+ * \param[in] address A constant pointer to the \ref cardano_reward_address_t object from which the network ID is to be retrieved.+ * \param[out] network_id A pointer to \ref cardano_network_id_t where the network ID will be stored upon successful+ *                        extraction. This parameter cannot be NULL.+ *+ * \return Returns \ref CARDANO_SUCCESS if the network ID was successfully retrieved.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if the input address or network_id pointer is NULL.+ *         Returns other error codes as defined in \ref cardano_error_t if the network ID cannot be retrieved due to+ *         malformed or unrecognized address formats.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_t* address = NULL;+ * cardano_network_id_t network_id;+ *+ * cardano_error_t get_network_id = cardano_reward_address_get_network_id(address, &network_id);+ *+ * if (get_network_id != CARDANO_SUCCESS)+ * {+ *   printf("Failed to determine the network id.\n");+ * }+ * else+ * {+ *   printf("Network ID: %d\n", network_id);+ * }+ *+ * cardano_reward_address_unref(&address);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_reward_address_get_network_id(+  const cardano_reward_address_t* address,+  cardano_network_id_t*           network_id);++/**+ * \brief Decrements the reward address's reference count.+ *+ * If the reference count reaches zero, the reward address memory is deallocated.+ *+ * \param[in] address Pointer to the reward address whose reference count is to be decremented.+ */+CARDANO_EXPORT void cardano_reward_address_unref(cardano_reward_address_t** address);++/**+ * \brief Increments the reward address's reference count.+ *+ * Ensures that the reward address remains allocated until the last reference is released.+ *+ * \param[in] address reward address whose reference count is to be incremented.+ */+CARDANO_EXPORT void cardano_reward_address_ref(cardano_reward_address_t* address);++/**+ * \brief Retrieves the reward address's current reference count.+ *+ * \warning Does not account for transitive references.+ *+ * \param[in] address Target reward address.+ * \return Current reference count of the reward address.+ */+CARDANO_EXPORT size_t cardano_reward_address_refcount(const cardano_reward_address_t* address);++/**+ * \brief Sets the last error message for a given reward address.+ *+ * This function records an error message in the reward address's last_error buffer,+ * overwriting any previous message. The message is truncated if it exceeds+ * the buffer size. This function is typically used to store descriptive+ * error information that can be retrieved later with+ * cardano_reward_address_get_last_error.+ *+ * \param[in,out] address A pointer to the cardano_reward_address_t instance whose last error+ *               message is to be set. If the reward address is NULL, the function+ *               has no effect.+ * \param[in] message A null-terminated string containing the error message to be+ *                recorded. If the message is NULL, the reward address's last_error+ *                will be set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters due to the fixed size+ *       of the last_error buffer (1024 characters), including the null+ *       terminator. Messages longer than this limit will be truncated.+ */+CARDANO_EXPORT void cardano_reward_address_set_last_error(cardano_reward_address_t* address, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific reward address.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_reward_address_set_last_error for the given+ * reward address. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in,out] address A pointer to the \ref cardano_reward_address_t instance whose last error+ *               message is to be retrieved. If the reward address is \c NULL, the function+ *               returns a generic error message indicating the null reward address.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified reward address. If the reward address is \c NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the reward address and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_reward_address_set_last_error for the same reward address, or until+ *       the reward address is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_reward_address_get_last_error(const cardano_reward_address_t* address);++/**+ * \brief Creates an independent deep copy of the address and its credentials.+ * \param[in] source Address to copy. Must not be NULL.+ * \param[out] clone Receives one owned reference, or NULL on failure. Must not be NULL.+ * \return CARDANO_SUCCESS, CARDANO_ERROR_POINTER_IS_NULL, or CARDANO_ERROR_MEMORY_ALLOCATION_FAILED.+ * \note Release the result with cardano_reward_address_unref. The source is unchanged.+ */+CARDANO_EXPORT cardano_error_t+cardano_reward_address_deep_clone(const cardano_reward_address_t* source, cardano_reward_address_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_REWARD_ADDRESS_H
+ vendor/include/cardano/address/stake_pointer.h view
@@ -0,0 +1,67 @@+/**+ * \file stake_pointer.h+ *+ * \author angel.castillo+ * \date   Apr 12, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ADDRESS_STAKE_POINTER_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ADDRESS_STAKE_POINTER_H++/* INCLUDES ******************************************************************/++#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a pointer to a stake key registration location on the blockchain.+ *+ * This structure is used to indirectly reference a stake key through its registration certificate location on the blockchain.+ * It is used in Cardano pointer addresses, which allow for the specification of stake rights without directly embedding+ * the stake key itself in the address.+ */+typedef struct cardano_stake_pointer_t+{+    /**+     * \brief The slot number on the blockchain where the stake key registration certificate is recorded.+     * This is a uint64_t value that represents the absolute slot since the genesis block of the blockchain.+     */+    uint64_t slot;++    /**+     * \brief The index of the transaction within the specified slot where the stake key registration certificate is located.+     * This value helps pinpoint the exact transaction in a given slot that contains the certificate.+     */+    uint64_t tx_index;++    /**+     * \brief The index of the certificate within the transaction. Since a single transaction can contain multiple certificates,+     * this value specifies which certificate in the transaction pertains to the stake key registration.+     */+    uint64_t cert_index;+} cardano_stake_pointer_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ADDRESS_STAKE_POINTER_H
+ vendor/include/cardano/assets/asset_id.h view
@@ -0,0 +1,647 @@+/**+ * \file asset_id.h+ *+ * \author angel.castillo+ * \date   Sep 14, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ASSET_ID_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ASSET_ID_H++/* INCLUDES ******************************************************************/++#include <cardano/assets/asset_name.h>+#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents an asset identifier in the Cardano blockchain.+ *+ * The `cardano_asset_id_t` structure encapsulates the unique identification of a native asset on the Cardano blockchain.+ * Each asset is uniquely identified by a combination of its policy ID and asset name.+ */+typedef struct cardano_asset_id_t cardano_asset_id_t;++/**+ * \brief Creates and initializes a new instance of a Cardano asset identifier.+ *+ * This function allocates and initializes a new instance of a \ref cardano_asset_id_t object,+ * which represents a unique asset identifier in the Cardano blockchain.+ * The asset ID is composed of a policy ID and an asset name.+ *+ * - **Policy ID**: A cryptographic hash (Blake2b hash) that identifies the minting policy.+ * - **Asset Name**: A user-defined name (max 32 bytes) associated with the asset.+ *+ * The function ensures that a valid asset identifier is created by linking the provided policy ID and asset name.+ *+ * \param[in] policy_id A pointer to an initialized \ref cardano_blake2b_hash_t object representing the minting policy ID.+ *                      This value must not be NULL.+ * \param[in] asset_name A pointer to an initialized \ref cardano_asset_name_t object representing the name of the asset.+ *                       This value must not be NULL.+ * \param[out] asset_id On successful creation, this will point to a newly created \ref cardano_asset_id_t object+ *                      representing the asset. The caller is responsible for managing the lifecycle of this object by calling+ *                      \ref cardano_asset_id_unref when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the asset ID was+ *         successfully created, or an appropriate error code indicating the failure reason, such as:+ *         - \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *         - \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if memory allocation for the asset ID failed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_blake2b_hash_t* policy_id = ...; // Assume policy ID is initialized+ * cardano_asset_name_t* asset_name = ...;  // Assume asset name is initialized+ * cardano_asset_id_t* asset_id = NULL;+ *+ * // Create a new asset ID+ * cardano_error_t result = cardano_asset_id_new(policy_id, asset_name, &asset_id);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset ID+ *+ *   // Once done, release the asset ID+ *   cardano_asset_id_unref(&asset_id);+ * }+ * else+ * {+ *   printf("Failed to create asset ID: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_id_new(+  cardano_blake2b_hash_t* policy_id,+  cardano_asset_name_t*   asset_name,+  cardano_asset_id_t**    asset_id);++/**+ * \brief Creates a new instance of the Cardano native asset identifier for Lovelace.+ *+ * This function allocates and initializes a new instance of a \ref cardano_asset_id_t object that represents+ * the Cardano native coin, Lovelace. Lovelace is the smallest denomination of the ADA cryptocurrency, and it+ * does not have an associated asset name or a policy ID like other assets. Instead, Lovelace is identified+ * by the special identifier "lovelace."+ *+ * \param[out] asset_id On successful creation, this will point to a newly created \ref cardano_asset_id_t object+ *                      representing the Lovelace asset. The caller is responsible for managing the lifecycle of this object+ *                      and must release it by calling \ref cardano_asset_id_unref when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the Lovelace asset ID+ *         was successfully created, or an appropriate error code indicating the failure reason, such as:+ *         - \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if memory allocation for the asset ID failed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_t* lovelace_asset_id = NULL;+ *+ * // Create a new asset ID for Lovelace+ * cardano_error_t result = cardano_asset_id_new_lovelace(&lovelace_asset_id);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the Lovelace asset ID+ *+ *   // Once done, release the asset ID+ *   cardano_asset_id_unref(&lovelace_asset_id);+ * }+ * else+ * {+ *   printf("Failed to create Lovelace asset ID: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_id_new_lovelace(cardano_asset_id_t** asset_id);++/**+ * \brief Creates and initializes a new instance of a Cardano asset ID from byte data.+ *+ * This function allocates and initializes a new instance of a \ref cardano_asset_id_t object,+ * which represents a Cardano native asset. The asset ID is formed by concatenating the bytes+ * of the policy ID and the asset name. The asset name can be an empty byte sequence, but the+ * policy ID must always be present.+ *+ * \param[in] data A pointer to an array of bytes representing the concatenation of the policy ID+ *                 and the asset name. The policy ID typically occupies the first 28 bytes, followed+ *                 by the bytes of the asset name. The data pointer must not be NULL.+ * \param[in] size The size of the byte array, which includes both the policy ID and the asset name.+ *                 The size must be at least 28 bytes (the size of the policy ID), but it can be larger+ *                 depending on the length of the asset name.+ * \param[out] asset_id On successful initialization, this will point to a newly created \ref cardano_asset_id_t object.+ *             This object represents a "strong reference" to the asset ID, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object. Specifically, once the asset ID is no longer needed,+ *             the caller must release it by calling \ref cardano_asset_id_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the asset ID was successfully created from the provided bytes, or an appropriate error code+ *         indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if the input data pointer is NULL,+ *         or \ref CARDANO_ERROR_INVALID_ARGUMENT if the size is less than 28 bytes or violates other constraints.+ *+ * Usage Example:+ * \code{.c}+ * const byte_t* asset_data = ...; // Asset data should contain policy ID followed by asset name+ * size_t asset_size = ...; // Size of asset_data (minimum 28 bytes)+ * cardano_asset_id_t* asset_id = NULL;+ *+ * cardano_error_t result = cardano_asset_id_from_bytes(asset_data, asset_size, &asset_id);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_id+ *   // Once done, ensure to clean up and release the asset_id+ *   cardano_asset_id_unref(&asset_id);+ * }+ * else+ * {+ *   printf("Failed to create asset ID: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ *+ * \note The byte data must include the policy ID followed by the asset name, which could be empty.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_id_from_bytes(+  const byte_t*        data,+  size_t               size,+  cardano_asset_id_t** asset_id);++/**+ * \brief Creates and initializes a new instance of a Cardano asset ID from a hexadecimal string.+ *+ * This function allocates and initializes a new instance of a \ref cardano_asset_id_t object,+ * which represents the ID of a Cardano native asset. The asset ID is derived from a hexadecimal-encoded+ * string, typically representing a policy ID or asset name in hexadecimal format.+ *+ * \param[in] hex_string A pointer to a null-terminated string containing the asset ID in hexadecimal format.+ *                       The string must only contain valid hexadecimal characters (0-9, a-f, A-F) and must not be NULL.+ * \param[in] size The size of the hexadecimal string, not including the null terminator. This allows for flexible+ *                 string lengths while excluding the null terminator from the conversion process.+ * \param[out] asset_id On successful initialization, this will point to a newly created \ref cardano_asset_id_t object.+ *             This object represents a "strong reference" to the asset ID, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object. Specifically, once the asset ID is no longer needed,+ *             the caller must release it by calling \ref cardano_asset_id_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the asset ID was successfully created from the provided hexadecimal string, or an appropriate error code+ *         indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if the input string pointer is NULL,+ *         or \ref CARDANO_ERROR_INVALID_ARGUMENT if the string contains invalid characters or does not meet other constraints.+ *+ * Usage Example:+ * \code{.c}+ * const char* hex_string = "616263646566..."; // Hexadecimal representation of some asset data+ * size_t hex_size = strlen(hex_string); // Size of the hexadecimal string+ * cardano_asset_id_t* asset_id = NULL;+ *+ * cardano_error_t result = cardano_asset_id_from_hex(hex_string, hex_size, &asset_id);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_id+ *   // Once done, ensure to clean up and release the asset_id+ *   cardano_asset_id_unref(&asset_id);+ * }+ * else+ * {+ *   printf("Failed to create asset ID from hex: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_id_from_hex(+  const char*          hex_string,+  size_t               size,+  cardano_asset_id_t** asset_id);++/**+ * \brief Retrieves the byte representation of a Cardano asset id.+ *+ * This function provides access to the underlying byte array of a \ref cardano_asset_id_t object.+ * The byte array represents the asset id as it is stored and used within the Cardano ecosystem.+ *+ * \param[in] asset_id A pointer of an initialized \ref cardano_asset_id_t object.+ *                       The pointer must not be NULL and should point to a valid asset id object.+ *+ * \return A pointer to the constant byte array representing the asset id. This pointer points to an+ *         internal buffer and must not be modified or freed by the caller. If the input is NULL or an+ *         error occurs, the function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_t* asset_id = ...; // Assume asset_id is already initialized+ * const byte_t* name_bytes = cardano_asset_id_get_bytes(asset_id);+ *+ * if (name_bytes != NULL)+ * {+ *   // Process the bytes of the asset id+ *   // Note: The length of the byte array should be known or determined separately+ * }+ * else+ * {+ *   printf("Failed to retrieve the bytes of the asset id.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t*+cardano_asset_id_get_bytes(const cardano_asset_id_t* asset_id);++/**+ * \brief Retrieves the size of the byte array for a Cardano asset id.+ *+ * This function returns the size of the byte array representing the asset id contained within+ * a \ref cardano_asset_id_t object.+ *+ * \param[in] asset_id A pointer of an initialized \ref cardano_asset_id_t object.+ *                       The pointer must not be NULL and should point to a valid asset id object.+ *+ * \return The size of the byte array representing the asset id. If the input is NULL or an+ *         error occurs, the function returns 0. This size does not include a null terminator, as+ *         asset ids can contain arbitrary binary data.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_t* asset_id = ...; // Assume asset_id is already initialized+ * size_t name_size = cardano_asset_id_get_bytes_size(asset_id);+ *+ * if (name_size > 0)+ * {+ *   const byte_t* name_bytes = cardano_asset_id_get_bytes(asset_id);+ *   // Process the bytes knowing the exact size of the asset id+ * }+ * else+ * {+ *   printf("Failed to retrieve the size of the asset id or asset id is empty.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_asset_id_get_bytes_size(const cardano_asset_id_t* asset_id);++/**+ * \brief Retrieves the hexadecimal string representation of a Cardano asset ID.+ *+ * This function returns the hexadecimal string representation of a \ref cardano_asset_id_t object.+ * The string encodes the asset ID, which consists of the concatenated bytes of the policy ID and asset name.+ *+ * \param[in] asset_id A pointer to an initialized \ref cardano_asset_id_t object.+ *                     The pointer must not be NULL and should point to a valid asset ID object.+ *+ * \return A pointer to a null-terminated string representing the asset ID in hexadecimal format.+ *         This string is owned by the \ref cardano_asset_id_t object and must not be modified or freed by the caller.+ *         If the input is NULL or an error occurs, the function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_asset_id_t* asset_id = ...; // Assume asset_id is already initialized+ * const char* hex_string = cardano_asset_id_get_hex(asset_id);+ *+ * if (hex_string != NULL)+ * {+ *   // Process the hexadecimal string of the asset ID+ *   printf("Asset ID in hex: %s\n", hex_string);+ * }+ * else+ * {+ *   printf("Failed to retrieve the hexadecimal string of the asset ID.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char*+cardano_asset_id_get_hex(const cardano_asset_id_t* asset_id);++/**+ * \brief Retrieves the size of the hexadecimal string for a Cardano asset ID.+ *+ * This function returns the size of the hexadecimal string representation of a \ref cardano_asset_id_t object.+ * The size includes the number of characters in the hexadecimal string, not including the null terminator.+ *+ * \param[in] asset_id A pointer to an initialized \ref cardano_asset_id_t object.+ *                     The pointer must not be NULL and should point to a valid asset ID object.+ *+ * \return The size of the hexadecimal string representing the asset ID. If the input is NULL or an+ *         error occurs, the function returns 0. The size does not include a null terminator.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_asset_id_t* asset_id = ...; // Assume asset_id is already initialized+ * size_t hex_size = cardano_asset_id_get_hex_size(asset_id);+ *+ * if (hex_size > 0)+ * {+ *   const char* hex_string = cardano_asset_id_get_hex(asset_id);+ *   // Process the hex string knowing the exact size of the asset ID+ *   printf("Hexadecimal string size: %zu\n", hex_size);+ * }+ * else+ * {+ *   printf("Failed to retrieve the size of the asset ID in hex or asset ID is empty.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_asset_id_get_hex_size(const cardano_asset_id_t* asset_id);++/**+ * \brief Checks if the given asset ID represents the native Cardano currency, Lovelace.+ *+ * This function determines if a \ref cardano_asset_id_t object corresponds to the Lovelace currency.+ * Lovelace is the smallest unit of ADA, the native cryptocurrency of the Cardano network. A Lovelace+ * asset ID is identified by the absence of an asset name and a specific policy ID.+ *+ * \param[in] asset_id A constant pointer to an initialized \ref cardano_asset_id_t object.+ *+ * \return \c true if the asset ID represents Lovelace, or \c false otherwise. If the input \c asset_id is NULL,+ *         the function returns false.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_asset_id_t* asset_id = ...; // Assume asset_id is already initialized+ * bool is_lovelace = cardano_asset_id_is_lovelace(asset_id);+ *+ * if (is_lovelace)+ * {+ *   printf("The asset is Lovelace.\n");+ * }+ * else+ * {+ *   printf("The asset is not Lovelace.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool+cardano_asset_id_is_lovelace(const cardano_asset_id_t* asset_id);++/**+ * \brief Retrieves the policy ID from a Cardano asset ID.+ *+ * This function extracts the policy ID from a given \ref cardano_asset_id_t object. The policy ID+ * is a \ref cardano_blake2b_hash_t object representing the unique identifier of the policy under which+ * the asset was issued.+ *+ * \param[in] asset_id A pointer to an initialized \ref cardano_asset_id_t object.+ *+ * \return A pointer to the \ref cardano_blake2b_hash_t object representing the policy ID. The returned+ *         policy ID is a new reference, and the caller is responsible for releasing it with \ref cardano_blake2b_hash_unref+ *         when it is no longer needed. If the asset ID is NULL, or if the asset represents Lovelace, the function returns NULL.+ *+ * \note For assets that represent the native currency Lovelace, there is no associated policy ID. Clients must first call+ *       \ref cardano_asset_id_is_lovelace to check if the asset is Lovelace before attempting to retrieve the policy ID.+ *       If the asset is Lovelace, this function will return NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_t* asset_id = ...; // Assume asset_id is already initialized+ * if (!cardano_asset_id_is_lovelace(asset_id))+ * {+ *   cardano_blake2b_hash_t* policy_id = cardano_asset_id_get_policy_id(asset_id);+ *+ *   if (policy_id != NULL)+ *   {+ *     // Use the policy ID+ *     // Ensure to release the policy ID once done+ *     cardano_blake2b_hash_unref(&policy_id);+ *   }+ *   else+ *   {+ *     printf("Failed to retrieve the policy ID or asset_id is NULL.\n");+ *   }+ * }+ * else+ * {+ *   printf("This asset is Lovelace and has no policy ID.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t*+cardano_asset_id_get_policy_id(cardano_asset_id_t* asset_id);++/**+ * \brief Retrieves the asset name from a Cardano asset ID.+ *+ * This function extracts the asset name from a given \ref cardano_asset_id_t object. The asset name+ * is a \ref cardano_asset_name_t object representing the name of the asset within the specified policy.+ *+ * \param[in] asset_id A pointer to an initialized \ref cardano_asset_id_t object.+ *+ * \return A pointer to the \ref cardano_asset_name_t object representing the asset name. The returned+ *         asset name is a new reference, and the caller is responsible for releasing it with \ref cardano_asset_name_unref+ *         when it is no longer needed. If the asset ID is NULL or if the asset represents Lovelace, the function returns NULL.+ *+ * \note For assets that represent the native currency Lovelace, there is no associated asset name. Clients must first call+ *       \ref cardano_asset_id_is_lovelace to check if the asset is Lovelace before attempting to retrieve the asset name.+ *       If the asset is Lovelace, this function will return NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_t* asset_id = ...; // Assume asset_id is already initialized+ *+ * if (!cardano_asset_id_is_lovelace(asset_id))+ * {+ *   cardano_asset_name_t* asset_name = cardano_asset_id_get_asset_name(asset_id);+ *+ *   if (asset_name != NULL)+ *   {+ *     // Use the asset name+ *     // Ensure to release the asset name once done+ *     cardano_asset_name_unref(&asset_name);+ *   }+ *   else+ *   {+ *     printf("Failed to retrieve the asset name or asset_id is NULL.\n");+ *   }+ * }+ * else+ * {+ *   printf("This asset is Lovelace and has no asset name.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_asset_name_t*+cardano_asset_id_get_asset_name(cardano_asset_id_t* asset_id);++/**+ * \brief Decrements the reference count of a cardano_asset_id_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_asset_id_t object+ * by decreasing its reference count. When the reference count reaches zero, the asset_id is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] asset_id A pointer to the pointer of the asset_id object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_t* asset_id = cardano_asset_id_new(major, minor);+ *+ * // Perform operations with the asset_id...+ *+ * cardano_asset_id_unref(&asset_id);+ * // At this point, asset_id is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_asset_id_unref, the pointer to the \ref cardano_asset_id_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_asset_id_unref(cardano_asset_id_t** asset_id);++/**+ * \brief Increases the reference count of the cardano_asset_id_t object.+ *+ * This function is used to manually increment the reference count of an cardano_asset_id_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_asset_id_unref.+ *+ * \param asset_id A pointer to the cardano_asset_id_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_id is a previously created asset_id object+ *+ * cardano_asset_id_ref(asset_id);+ *+ * // Now asset_id can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_asset_id_ref there is a corresponding+ * call to \ref cardano_asset_id_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_asset_id_ref(cardano_asset_id_t* asset_id);++/**+ * \brief Retrieves the current reference count of the cardano_asset_id_t object.+ *+ * This function returns the number of active references to an cardano_asset_id_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_asset_id_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param asset_id A pointer to the cardano_asset_id_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_asset_id_t object. If the object+ * is properly managed (i.e., every \ref cardano_asset_id_ref call is matched with a+ * \ref cardano_asset_id_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_id is a previously created asset_id object+ *+ * size_t ref_count = cardano_asset_id_refcount(asset_id);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_id_refcount(const cardano_asset_id_t* asset_id);++/**+ * \brief Sets the last error message for a given cardano_asset_id_t object.+ *+ * Records an error message in the asset_id's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] asset_id A pointer to the \ref cardano_asset_id_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the asset_id's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_asset_id_set_last_error(+  cardano_asset_id_t* asset_id,+  const char*         message);++/**+ * \brief Retrieves the last error message recorded for a specific asset_id.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_asset_id_set_last_error for the given+ * asset_id. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] asset_id A pointer to the \ref cardano_asset_id_t instance whose last error+ *                   message is to be retrieved. If the asset_id is NULL, the function+ *                   returns a generic error message indicating the null asset_id.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified asset_id. If the asset_id is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_asset_id_set_last_error for the same asset_id, or until+ *       the asset_id is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_asset_id_get_last_error(+  const cardano_asset_id_t* asset_id);++/**+ * \brief Creates an independent deep copy of a \ref cardano_asset_id_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_asset_id_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_asset_id_deep_clone(const cardano_asset_id_t* source, cardano_asset_id_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ASSET_ID_H
+ vendor/include/cardano/assets/asset_id_list.h view
@@ -0,0 +1,336 @@+/**+ * \file asset_id_list.h+ *+ * \author angel.castillo+ * \date   Aug 08, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ASSET_ID_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ASSET_ID_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents an asset identifier in the Cardano blockchain.+ *+ * The `cardano_asset_id_t` structure encapsulates the unique identification of a native asset on the Cardano blockchain.+ * Each asset is uniquely identified by a combination of its policy ID and asset name.+ */+typedef struct cardano_asset_id_t cardano_asset_id_t;++/**+ * \brief Represents a list of asset ids.+ */+typedef struct cardano_asset_id_list_t cardano_asset_id_list_t;++/**+ * \brief Creates and initializes a new instance of a asset_id_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_asset_id_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] asset_id_list On successful initialization, this will point to a newly created+ *             \ref cardano_asset_id_list_t object. This object represents a "strong reference"+ *             to the asset_id_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the asset_id_list is no longer needed, the caller must release it+ *             by calling \ref cardano_asset_id_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the asset_id_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_list_t* asset_id_list = NULL;+ *+ * // Attempt to create a new asset_id_list+ * cardano_error_t result = cardano_asset_id_list_new(&asset_id_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_id_list+ *+ *   // Once done, ensure to clean up and release the asset_id_list+ *   cardano_asset_id_list_unref(&asset_id_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_id_list_new(cardano_asset_id_list_t** asset_id_list);++/**+ * \brief Retrieves the length of a asset id list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_asset_id_list_t object.+ *+ * \param[in] asset_id_list A constant pointer to the \ref cardano_asset_id_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the asset_id_list. Return 0 if the asset_id_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_list_t* asset_id_list = cardano_asset_id_list_new();+ *+ * // Populate asset_id_list with elements+ *+ * size_t length = cardano_asset_id_list_get_length(asset_id_list);+ * printf("Length of the asset_id_list: %zu\n", length);+ *+ * // Clean up the asset_id_list object once done+ * cardano_asset_id_list_unref(&asset_id_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_id_list_get_length(const cardano_asset_id_list_t* asset_id_list);++/**+ * \brief Retrieves an element from a asset id list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_asset_id_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] asset_id_list A constant pointer to the \ref cardano_asset_id_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the asset id list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_asset_id_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_asset_id_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_list_t* asset_id_list = cardano_asset_id_list_new();+ *+ * // Populate asset_id_list with elements+ *+ * cardano_asset_id_t* element = NULL;+ * cardano_error_t result = cardano_asset_id_list_get(asset_id_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_asset_id_unref(&element);+ * }+ *+ * // Clean up the asset_id_list object once done+ * cardano_asset_id_list_unref(&asset_id_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_list_get(const cardano_asset_id_list_t* asset_id_list, size_t index, cardano_asset_id_t** element);++/**+ * \brief Adds an element to a asset id list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_asset_id_list_t object.+ *+ * \param[in] asset_id_list A constant pointer to the \ref cardano_asset_id_list_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_asset_id_t object that is to be added to the asset_id_list.+ *                    The element will be referenced by the asset_id_list after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the asset_id_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_list_t* asset_id_list = cardano_asset_id_list_new();+ *+ * // Create and initialize a new asset id element+ * cardano_asset_id_t* element = { ... };+ *+ * // Add the element to the asset_id_list+ * cardano_error_t result = cardano_asset_id_list_add(asset_id_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the asset_id_list object once done+ * cardano_asset_id_list_unref(&asset_id_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_list_add(cardano_asset_id_list_t* asset_id_list, cardano_asset_id_t* element);++/**+ * \brief Decrements the reference count of a asset_id_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_asset_id_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the asset_id_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] asset_id_list A pointer to the pointer of the asset_id_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_list_t* asset_id_list = cardano_asset_id_list_new();+ *+ * // Perform operations with the asset_id_list...+ *+ * cardano_asset_id_list_unref(&asset_id_list);+ * // At this point, asset_id_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_asset_id_list_unref, the pointer to the \ref cardano_asset_id_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_asset_id_list_unref(cardano_asset_id_list_t** asset_id_list);++/**+ * \brief Increases the reference count of the cardano_asset_id_list_t object.+ *+ * This function is used to manually increment the reference count of a asset_id_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_asset_id_list_unref.+ *+ * \param asset_id_list A pointer to the asset_id_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_id_list is a previously created asset_id_list object+ *+ * cardano_asset_id_list_ref(asset_id_list);+ *+ * // Now asset_id_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_asset_id_list_ref there is a corresponding+ * call to \ref cardano_asset_id_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_asset_id_list_ref(cardano_asset_id_list_t* asset_id_list);++/**+ * \brief Retrieves the current reference count of the cardano_asset_id_list_t object.+ *+ * This function returns the number of active references to a asset_id_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_asset_id_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param asset_id_list A pointer to the asset_id_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified asset_id_list object. If the object+ * is properly managed (i.e., every \ref cardano_asset_id_list_ref call is matched with a+ * \ref cardano_asset_id_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_id_list is a previously created asset_id_list object+ *+ * size_t ref_count = cardano_asset_id_list_refcount(asset_id_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_id_list_refcount(const cardano_asset_id_list_t* asset_id_list);++/**+ * \brief Sets the last error message for a given asset_id_list object.+ *+ * Records an error message in the asset_id_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] asset_id_list A pointer to the \ref cardano_asset_id_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the asset_id_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_asset_id_list_set_last_error(cardano_asset_id_list_t* asset_id_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific asset_id_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_asset_id_list_set_last_error for the given+ * asset_id_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] asset_id_list A pointer to the \ref cardano_asset_id_list_t instance whose last error+ *                   message is to be retrieved. If the asset_id_list is NULL, the function+ *                   returns a generic error message indicating the null asset_id_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified asset_id_list. If the asset_id_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_asset_id_list_set_last_error for the same asset_id_list, or until+ *       the asset_id_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_asset_id_list_get_last_error(const cardano_asset_id_list_t* asset_id_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_asset_id_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_asset_id_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_asset_id_list_deep_clone(const cardano_asset_id_list_t* source, cardano_asset_id_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ASSET_ID_LIST_H
+ vendor/include/cardano/assets/asset_id_map.h view
@@ -0,0 +1,658 @@+/**+ * \file asset_id_map.h+ *+ * \author angel.castillo+ * \date   Sep 05, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ASSET_ID_MAP_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ASSET_ID_MAP_H++/* INCLUDES ******************************************************************/++#include <cardano/assets/asset_id.h>+#include <cardano/assets/asset_id_list.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a map of asset id to coin amount.+ */+typedef struct cardano_asset_id_map_t cardano_asset_id_map_t;++/**+ * \brief Creates and initializes a new instance of a asset id map.+ *+ * This function allocates and initializes a new instance of \ref cardano_asset_id_map_t,+ * representing a map structure. It returns an error code to indicate the success or failure of the operation.+ *+ * \param[out] asset_id_map A pointer to a pointer to a \ref cardano_asset_id_map_t object. Upon successful+ *                        initialization, this will point to a newly created \ref cardano_asset_id_map_t+ *                        object. This object represents a "strong reference" to the asset_id_map,+ *                        fully initialized and ready for use. The caller is responsible for managing+ *                        the lifecycle of this object. Specifically, once the asset_id_map is no longer+ *                        needed, the caller must release it by calling \ref cardano_asset_id_map_unref.+ *+ * \return \ref CARDANO_SUCCESS if the asset_id_map was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map = NULL;+ *+ * // Attempt to create a new asset_id_map+ * cardano_error_t result = cardano_asset_id_map_new(&asset_id_map);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_id_map+ *+ *   // Once done, ensure to clean up and release the asset_id_map+ *   cardano_asset_id_map_unref(&asset_id_map);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_id_map_new(cardano_asset_id_map_t** asset_id_map);++/**+ * \brief Retrieves the length of the asset_id_map.+ *+ * This function returns the number of key-value pairs contained in the specified asset_id_map.+ *+ * \param[in] asset_id_map A constant pointer to the \ref cardano_asset_id_map_t object for which+ *                       the length is to be retrieved.+ *+ * \return The number of key-value pairs in the asset_id_map. Returns 0 if the asset_id_map is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map = cardano_asset_id_map_new();+ *+ * // Populate the asset_id_map with key-value pairs+ *+ * size_t length = cardano_asset_id_map_get_length(asset_id_map);+ * printf("The length of the asset_id_map is: %zu\n", length);+ *+ * cardano_asset_id_map_unref(&asset_id_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_id_map_get_length(const cardano_asset_id_map_t* asset_id_map);++/**+ * \brief Retrieves the value associated with a given key in the asset id map.+ *+ * This function retrieves the value associated with the specified key in the provided asset id map.+ * It returns the value through the output parameter `element`. If the key is not found in the asset id map,+ * the output parameter `element` will be set to NULL.+ *+ * \param[in] asset_id_map A constant pointer to the \ref cardano_asset_id_map_t object from which+ *                       the value is to be retrieved.+ * \param[in] key The key whose associated value is to be retrieved from the asset_id_map.+ * \param[out] element A pointer to a variable where the retrieved value will be stored. If the key+ *                     is found in the asset id map, this variable will be set to the associated value.+ *                     If the key is not found, this variable will be set to NULL.+ *+ * \return \ref CARDANO_SUCCESS if the value associated with the key was successfully retrieved, or+ *         an appropriate error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map = cardano_asset_id_map_new();+ *+ * // Populate the asset_id_map with key-value pairs+ *+ * cardano_asset_id_t* key = ...; // Create a asset_id object representing the key+ * int64_t value = 0;+ * cardano_error_t result = cardano_asset_id_map_get(asset_id_map, key, &value);+ *+ * if (result == CARDANO_SUCCESS && value != NULL)+ * {+ *   // Use the retrieved value+ *   // ...+ * }+ * else+ * {+ *   // Handle error or key not found+ * }+ *+ * cardano_asset_id_unref(&key); // Clean up the key resource+ * cardano_asset_id_map_unref(&asset_id_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_map_get(cardano_asset_id_map_t* asset_id_map, cardano_asset_id_t* key, int64_t* element);++/**+ * \brief Inserts a key-value pair into the asset id map.+ *+ * This function inserts the specified key-value pair into the provided asset id map.+ *+ * \param[in] asset_id_map A constant pointer to the \ref cardano_asset_id_map_t object where+ *                       the key-value pair is to be inserted.+ * \param[in] key The key to be inserted into the asset id map. The caller is responsible for managing+ *                the lifecycle of the key object.+ * \param[in] value The value to be associated with the key and inserted into the asset_id_map.+ *                  The caller is responsible for managing the lifecycle of the value object.+ *+ * \return \ref CARDANO_SUCCESS if the key-value pair was successfully inserted, or an appropriate+ *         error code if the input parameters are invalid or any other error occurs.+ *+ * \remark If the key already exists in the asset id map, the value associated with the key will be updated.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map = cardano_asset_id_map_new();+ *+ * // Create key and value objects+ * cardano_asset_id_t* key = ...;+ * int64_t value = 0;+ *+ * // Insert the key-value pair into the asset_id_map+ * cardano_error_t result = cardano_asset_id_map_insert(asset_id_map, key, value);+ *+ * if (result != CARDANO_SUCCESS)+ * {+ *   // Handle insertion failure+ * }+ *+ * // Clean up key and value objects+ * cardano_asset_id_unref(&key);+ *+ * cardano_asset_id_map_unref(&asset_id_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_map_insert(cardano_asset_id_map_t* asset_id_map, cardano_asset_id_t* key, int64_t value);++/**+ * \brief Retrieves the keys from the asset id map.+ *+ * This function retrieves all the keys from the provided asset id map and returns them as a list.+ * The caller is responsible for managing the lifecycle of the returned list by calling+ * \ref cardano_asset_id_list_t when it is no longer needed.+ *+ * \param[in] asset_id_map A constant pointer to the \ref cardano_asset_id_map_t object from which+ *                       the keys are to be retrieved.+ * \param[out] keys A pointer to a variable where the retrieved keys will be stored as a list.+ *                  If successful, this variable will be set to point to the list of keys.+ *                  The caller is responsible for managing the lifecycle of this list.+ *                  It must be released by calling \ref cardano_asset_id_list_t when no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the keys were successfully retrieved, or an appropriate+ *         error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map = cardano_asset_id_map_new();+ *+ * // Populate the asset_id_map with key-value pairs+ *+ * cardano_asset_id_list_t* keys = NULL;+ * cardano_error_t result = cardano_asset_id_map_get_keys(asset_id_map, &keys);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the list of keys+ *   // Keys must also be freed if retrieved from the list+ *+ *   // Once done, ensure to clean up and release the keys list+ *   cardano_asset_id_list_unref(&keys);+ * }+ * else+ * {+ *   // Handle error+ * }+ *+ * cardano_asset_id_map_unref(&asset_id_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_map_get_keys(cardano_asset_id_map_t* asset_id_map, cardano_asset_id_list_t** keys);++/**+ * \brief Retrieves the asset id at a specific index from the asset id map.+ *+ * This function retrieves the asset id at the specified index from the asset id map.+ *+ * \param[in] asset_id_map Pointer to the asset id map object.+ * \param[in] index The index of the asset id to retrieve.+ * \param[out] asset_id On successful retrieval, this will point to the asset id+ *                        at the specified index. The caller is responsible for managing the lifecycle+ *                        of this object. Specifically, once the asset id is no longer needed,+ *                        the caller must release it by calling \ref cardano_asset_id_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the asset id was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map = NULL;+ * cardano_asset_id_t* asset_id = NULL;+ * size_t index = 0; // Index of the key hash to retrieve+ *+ * // Assume asset_id_map is initialized properly+ *+ * cardano_error_t result = cardano_asset_id_map_get_key_at(asset_id_map, index, &asset_id);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_id+ *+ *   // Once done, ensure to clean up and release the asset_id+ *   cardano_asset_id_unref(&asset_id);+ * }+ * else+ * {+ *   // Handle the error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_map_get_key_at(+  const cardano_asset_id_map_t* asset_id_map,+  size_t                        index,+  cardano_asset_id_t**          asset_id);++/**+ * \brief Retrieves the withdrawal amount at a specific index from the asset id map.+ *+ * This function retrieves the withdrawal amount at the specified index from the asset id map.+ *+ * \param[in] asset_id_map Pointer to the asset id map object.+ * \param[in] index The index of the withdrawal amount to retrieve.+ * \param[out] amount On successful retrieval, this will point to the withdrawal amount+ *                    at the specified index.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the withdrawal amount was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map = NULL;+ * int64_t amount = 0;+ * size_t index = 0; // Index of the withdrawal amount to retrieve+ *+ * // Assume asset_id_map is initialized properly+ *+ * cardano_error_t result = cardano_asset_id_map_get_value_at(asset_id_map, index, &amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the amount+ * }+ * else+ * {+ *   // Handle the error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_map_get_value_at(+  const cardano_asset_id_map_t* asset_id_map,+  size_t                        index,+  int64_t*                      amount);++/**+ * \brief Retrieves the asset id and withdrawal amount at the specified index.+ *+ * This function retrieves the asset id and withdrawal amount from the proposed withdrawal amounts+ * at the specified index.+ *+ * \param[in]  asset_id_map    Pointer to the proposed withdrawal amounts object.+ * \param[in]  index             The index at which to retrieve the key-value pair.+ * \param[out] asset_id On successful retrieval, this will point to the asset id at the specified index.+ *                            The caller is responsible for managing the lifecycle of this object and should release it using+ *                            \ref cardano_asset_id_unref when it is no longer needed.+ * \param[out] amount On successful retrieval, this will point to the withdrawal amount at the specified index.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the key-value pair was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map = NULL;+ * // Assume asset_id_map is initialized properly+ *+ * size_t index = 0;+ * cardano_asset_id_t* asset_id = NULL;+ * int64_t amount = 0;+ *+ * cardano_error_t result = cardano_asset_id_map_get_key_value_at(asset_id_map, index, &asset_id, &amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   if (asset_id != NULL && amount != NULL)+ *   {+ *     // Use the asset id and withdrawal amount+ *   }+ *   else+ *   {+ *     printf("Key-value pair not set at index %zu.\n", index);+ *   }+ * }+ * else+ * {+ *   // Handle error+ *   printf("Failed to get key-value pair at index %zu.\n", index);+ * }+ *+ * // Clean up+ * cardano_asset_id_map_unref(&asset_id_map);+ * cardano_asset_id_unref(&asset_id);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_map_get_key_value_at(+  const cardano_asset_id_map_t* asset_id_map,+  size_t                        index,+  cardano_asset_id_t**          asset_id,+  int64_t*                      amount);++/**+ * \brief Combines two asset id maps by adding the quantities of assets with the same asset ids.+ *+ * This function adds the asset quantities from two \ref cardano_asset_id_map_t objects. It combines the quantities+ * of assets that have the same asset ids. If an asset id exists in both maps, their quantities are summed.+ * If an asset id exists in only one of the maps, its quantity is copied to the result.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_asset_id_map_t object.+ * \param[in] rhs A constant pointer to the second \ref cardano_asset_id_map_t object.+ * \param[out] result On successful execution, this will point to a newly created \ref cardano_asset_id_map_t object+ *             that represents the combined result of both input asset id maps.+ *             The result is dynamically allocated and must be freed by the caller using \ref cardano_asset_id_map_unref+ *             when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the assets were+ *         successfully combined, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_asset_id_map_t* lhs = ...; // Assume lhs is already initialized with some assets+ * const cardano_asset_id_map_t* rhs = ...; // Assume rhs is also initialized with some assets+ * cardano_asset_id_map_t* result = NULL;+ *+ * cardano_error_t add_result = cardano_asset_id_map_add(lhs, rhs, &result);+ * if (add_result == CARDANO_SUCCESS)+ * {+ *   // The assets have been successfully combined+ *   // Use the result as needed+ *+ *   // When done, release the result+ *   cardano_asset_id_map_unref(&result);+ * }+ * else+ * {+ *   printf("Failed to combine assets: %s\n", cardano_error_to_string(add_result));+ * }+ *+ * // Cleanup resources+ * cardano_asset_id_map_unref(&lhs);+ * cardano_asset_id_map_unref(&rhs);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_map_add(+  const cardano_asset_id_map_t* lhs,+  const cardano_asset_id_map_t* rhs,+  cardano_asset_id_map_t**      result);++/**+ * \brief Subtracts the quantities of assets under each asset id from one asset id map to another.+ *+ * This function subtracts the assets from the second \ref cardano_asset_id_map_t object (rhs) from the first+ * \ref cardano_asset_id_map_t object (lhs). It subtracts the quantities of assets under each asset id present+ * in both maps. If an asset id exists only in the rhs, the value is copied as negative, effectively subtracting+ * it from the lhs. If an asset id exists only in the lhs, the value is copied as is to the result.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_asset_id_map_t object from which assets will be subtracted.+ * \param[in] rhs A constant pointer to the second \ref cardano_asset_id_map_t object that provides the quantities to subtract.+ * \param[out] result On successful execution, this will point to a newly created \ref cardano_asset_id_map_t object+ *             that represents the result of the subtraction.+ *             The result is dynamically allocated and must be freed by the caller using \ref cardano_asset_id_map_unref+ *             when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the assets were+ *         successfully subtracted, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_asset_id_map_t* lhs = ...; // Assume lhs is already initialized with some assets+ * const cardano_asset_id_map_t* rhs = ...; // Assume rhs is also initialized with some assets to subtract+ * cardano_asset_id_map_t* result = NULL;+ *+ * cardano_error_t subtract_result = cardano_asset_id_map_subtract(lhs, rhs, &result);+ * if (subtract_result == CARDANO_SUCCESS)+ * {+ *   // The assets have been successfully subtracted+ *   // Use the result+ *   cardano_asset_id_map_unref(&result);+ * }+ * else+ * {+ *   printf("Failed to subtract assets: %s\n", cardano_error_to_string(subtract_result));+ * }+ *+ * // Cleanup resources+ * cardano_asset_id_map_unref(&lhs);+ * cardano_asset_id_map_unref(&rhs);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_id_map_subtract(+  const cardano_asset_id_map_t* lhs,+  const cardano_asset_id_map_t* rhs,+  cardano_asset_id_map_t**      result);++/**+ * \brief Compares two asset id map objects for equality.+ *+ * This function compares two asset_id_map objects to determine if they are equal.+ *+ * \param[in] lhs Pointer to the first asset id map object.+ * \param[in] rhs Pointer to the second asset id map object.+ *+ * \return \c true if the asset id map objects are equal, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map1 = NULL;+ * cardano_asset_id_map_t* asset_id_map2 = NULL;+ *+ * // Assume asset_id_map1 and asset_id_map2 are initialized properly+ *+ * bool are_equal = cardano_asset_id_map_equals(asset_id_map1, asset_id_map2);+ *+ * if (are_equal)+ * {+ *   printf("The asset_id_map objects are equal.\n");+ * }+ * else+ * {+ *   printf("The asset_id_map objects are not equal.\n");+ * }+ *+ * // Clean up+ * cardano_asset_id_map_unref(&asset_id_map1);+ * cardano_asset_id_map_unref(&asset_id_map2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool+cardano_asset_id_map_equals(const cardano_asset_id_map_t* lhs, const cardano_asset_id_map_t* rhs);++/**+ * \brief Decrements the reference count of a asset_id_map object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_asset_id_map_t object+ * by decreasing its reference count. When the reference count reaches zero, the asset_id_map is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] asset_id_map A pointer to the pointer of the asset_id_map object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_id_map_t* asset_id_map = cardano_asset_id_map_new();+ *+ * // Perform operations with the asset_id_map...+ *+ * cardano_asset_id_map_unref(&asset_id_map);+ * // At this point, asset_id_map is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_asset_id_map_unref, the pointer to the \ref cardano_asset_id_map_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_asset_id_map_unref(cardano_asset_id_map_t** asset_id_map);++/**+ * \brief Increases the reference count of the cardano_asset_id_map_t object.+ *+ * This function is used to manually increment the reference count of a asset_id_map+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_asset_id_map_unref.+ *+ * \param asset_id_map A pointer to the asset_id_map object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_id_map is a previously created asset_id_map object+ *+ * cardano_asset_id_map_ref(asset_id_map);+ *+ * // Now asset_id_map can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_asset_id_map_ref there is a corresponding+ * call to \ref cardano_asset_id_map_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_asset_id_map_ref(cardano_asset_id_map_t* asset_id_map);++/**+ * \brief Retrieves the current reference count of the cardano_asset_id_map_t object.+ *+ * This function returns the number of active references to a asset_id_map object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_asset_id_map_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param asset_id_map A pointer to the asset_id_map object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified asset_id_map object. If the object+ * is properly managed (i.e., every \ref cardano_asset_id_map_ref call is matched with a+ * \ref cardano_asset_id_map_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_id_map is a previously created asset_id_map object+ *+ * size_t ref_count = cardano_asset_id_map_refcount(asset_id_map);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_id_map_refcount(const cardano_asset_id_map_t* asset_id_map);++/**+ * \brief Sets the last error message for a given asset_id_map object.+ *+ * Records an error message in the asset_id_map's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] asset_id_map A pointer to the \ref cardano_asset_id_map_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the asset_id_map's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_asset_id_map_set_last_error(cardano_asset_id_map_t* asset_id_map, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific asset_id_map.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_asset_id_map_set_last_error for the given+ * asset_id_map. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] asset_id_map A pointer to the \ref cardano_asset_id_map_t instance whose last error+ *                   message is to be retrieved. If the asset_id_map is NULL, the function+ *                   returns a generic error message indicating the null asset_id_map.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified asset_id_map. If the asset_id_map is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_asset_id_map_set_last_error for the same asset_id_map, or until+ *       the asset_id_map is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_asset_id_map_get_last_error(const cardano_asset_id_map_t* asset_id_map);++/**+ * \brief Creates an independent deep copy of a \ref cardano_asset_id_map_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_asset_id_map_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_asset_id_map_deep_clone(const cardano_asset_id_map_t* source, cardano_asset_id_map_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ASSET_ID_MAP_H
+ vendor/include/cardano/assets/asset_name.h view
@@ -0,0 +1,645 @@+/**+ * \file asset_name.h+ *+ * \author angel.castillo+ * \date   Mar 07, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ASSET_NAME_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ASSET_NAME_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents an asset name.+ */+typedef struct cardano_asset_name_t cardano_asset_name_t;++/**+ * \brief Creates and initializes a new instance of a Cardano asset name from byte data.+ *+ * This function allocates and initializes a new instance of a \ref cardano_asset_name_t object,+ * which represents the name of a Cardano native asset. Native asset names in Cardano are arbitrary+ * byte strings, typically used to uniquely identify assets within a policy.+ *+ * \param[in] data A pointer to an array of bytes representing the asset name. This array should contain+ *                 the raw byte data of the asset name and must not be NULL.+ * \param[in] size The size of the byte array. This value specifies how many bytes from the `data` array+ *                 should be used for the asset name. The size must not exceed the maximum allowed length+ *                 for asset names in Cardano.+ * \param[out] asset_name On successful initialization, this will point to a newly created \ref cardano_asset_name_t object.+ *             This object represents a "strong reference" to the asset name, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object,+ *             specifically, once the asset name is no longer needed, the caller must release it+ *             by calling \ref cardano_asset_name_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the asset name was successfully created from the provided bytes, or an appropriate error code+ *         indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if the input data pointer is NULL,+ *         or \ref CARDANO_ERROR_INVALID_ARGUMENT if the size exceeds the maximum length or other constraints.+ *+ * Usage Example:+ * \code{.c}+ * const byte_t* name_data = (const byte_t*)"example_asset";+ * size_t name_size = strlen("example_asset");+ * cardano_asset_name_t* asset_name = NULL;+ *+ * cardano_error_t result = cardano_asset_name_from_bytes(name_data, name_size, &asset_name);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_name+ *   // Once done, ensure to clean up and release the asset_name+ *   cardano_asset_name_unref(&asset_name);+ * }+ * else+ * {+ *   printf("Failed to create asset name: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_name_from_bytes(+  const byte_t*          data,+  size_t                 size,+  cardano_asset_name_t** asset_name);++/**+ * \brief Creates and initializes a new instance of a Cardano asset name from a hexadecimal string.+ *+ * This function allocates and initializes a new instance of a \ref cardano_asset_name_t object,+ * representing an asset name using a hexadecimal string. Asset names in Cardano are arbitrary byte strings,+ * and this function specifically interprets the input as a hex-encoded representation of those bytes.+ *+ * \param[in] hex A pointer to a null-terminated string containing the hexadecimal representation of the asset name.+ *                The string must not be NULL, must be properly hex-encoded, and must not contain non-hex characters.+ * \param[in] size The number of characters in the hex string. This value must be even, as each pair of characters represents one byte.+ * \param[out] asset_name On successful initialization, this will point to a newly created \ref cardano_asset_name_t object.+ *             This object represents a "strong reference" to the asset name, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object,+ *             specifically, once the asset name is no longer needed, the caller must release it+ *             by calling \ref cardano_asset_name_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the asset name was successfully created from the provided hex string, or an appropriate error code+ *         indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if the input hex pointer is NULL,+ *         or \ref CARDANO_ERROR_INVALID_ARGUMENT if the size is incorrect or the hex string is not valid.+ *+ * Usage Example:+ * \code{.c}+ * const char* hex_string = "6578616d706c65"; // Hex for "example"+ * size_t hex_size = strlen(hex_string); // Should be an even number+ * cardano_asset_name_t* asset_name = NULL;+ *+ * cardano_error_t result = cardano_asset_name_from_hex(hex_string, hex_size, &asset_name);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_name+ *   // Once done, ensure to clean up and release the asset_name+ *   cardano_asset_name_unref(&asset_name);+ * }+ * else+ * {+ *   printf("Failed to create asset name from hex: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_name_from_hex(+  const char*            hex,+  size_t                 size,+  cardano_asset_name_t** asset_name);++/**+ * \brief Creates and initializes a new instance of a Cardano asset name from a UTF-8 string.+ *+ * This function allocates and initializes a new instance of a \ref cardano_asset_name_t object,+ * which represents the name of a Cardano native asset. Asset names in Cardano are arbitrary byte strings,+ * but this function specifically interprets the input as a UTF-8 encoded string, allowing for easier+ * creation of asset names from human-readable text.+ *+ * \param[in] string A pointer to a null-terminated UTF-8 encoded string representing the asset name.+ *                   This string must not be NULL and should be properly encoded in UTF-8.+ * \param[in] size The number of bytes in the string, not including the null terminator. This allows+ *                 for strings containing null bytes to be handled correctly.+ * \param[out] asset_name On successful initialization, this will point to a newly created \ref cardano_asset_name_t object.+ *             This object represents a "strong reference" to the asset name, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object,+ *             specifically, once the asset name is no longer needed, the caller must release it+ *             by calling \ref cardano_asset_name_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the asset name was successfully created from the provided string, or an appropriate error code+ *         indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if the input string pointer is NULL,+ *         or \ref CARDANO_ERROR_INVALID_ARGUMENT if the size is incorrect or other constraints are not met.+ *+ * Usage Example:+ * \code{.c}+ * const char* name_string = "example_asset";+ * size_t name_length = strlen(name_string); // Not including the null terminator+ * cardano_asset_name_t* asset_name = NULL;+ *+ * cardano_error_t result = cardano_asset_name_from_string(name_string, name_length, &asset_name);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_name+ *   // Once done, ensure to clean up and release the asset_name+ *   cardano_asset_name_unref(&asset_name);+ * }+ * else+ * {+ *   printf("Failed to create asset name: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_name_from_string(+  const char*            string,+  size_t                 size,+  cardano_asset_name_t** asset_name);++/**+ * \brief Creates a \ref cardano_asset_name_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_asset_name_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a asset_name.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] asset_name A pointer to a pointer of \ref cardano_asset_name_t that will be set to the address+ *                        of the newly created asset_name object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the asset name were successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_asset_name_t object by calling+ *       \ref cardano_asset_name_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_asset_name_t* asset_name = NULL;+ *+ * cardano_error_t result = cardano_asset_name_from_cbor(reader, &asset_name);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_name+ *+ *   // Once done, ensure to clean up and release the asset_name+ *   cardano_asset_name_unref(&asset_name);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode asset_name: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_name_from_cbor(cardano_cbor_reader_t* reader, cardano_asset_name_t** asset_name);++/**+ * \brief Serializes asset name into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_asset_name_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] asset_name A constant pointer to the \ref cardano_asset_name_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p asset_name or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_t* asset_name = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_asset_name_to_cbor(asset_name, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_asset_name_unref(&asset_name);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_to_cbor(+  const cardano_asset_name_t* asset_name,+  cardano_cbor_writer_t*      writer);++/**+ * \brief Serializes an asset name to its CIP-116 JSON string representation.+ *+ * The function writes the hexadecimal representation of the asset name+ * as a JSON string (e.g., "4d794173736574").+ *+ * \param[in]  asset_name Pointer to a valid \ref cardano_asset_name_t.+ * \param[in]  writer     Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p asset_name or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_to_cip116_json(+  const cardano_asset_name_t* asset_name,+  cardano_json_writer_t*      writer);++/**+ * \brief Retrieves the string representation of a Cardano asset name.+ *+ * This function provides access to the string representation of a \ref cardano_asset_name_t object.+ * The asset name is returned as a UTF-8 encoded null-terminated string. This string points to an internal+ * buffer of the \ref cardano_asset_name_t object and must not be modified or freed by the caller. The string+ * remains valid as long as the asset name object is not modified or freed.+ *+ * \param[in] asset_name A pointer an initialized \ref cardano_asset_name_t object.+ *                       The pointer must not be NULL and should point to a valid asset name object.+ *+ * \return A pointer to a null-terminated UTF-8 string representing the asset name. If the input is NULL+ *         or an error occurs, NULL is returned instead. The caller must not free this string as it is+ *         managed internally by the asset name object.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_t* asset_name = ...; // Assume asset_name is already initialized+ * const char* name_str = cardano_asset_name_get_string(asset_name);+ *+ * if (name_str != NULL)+ * {+ *   printf("Asset Name: %s\n", name_str);+ * }+ * else+ * {+ *   printf("Failed to retrieve the asset name string.\n");+ * }+ * // No need to free name_str, it is managed internally+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char*+cardano_asset_name_get_string(const cardano_asset_name_t* asset_name);++/**+ * \brief Retrieves the size of the string representation of a Cardano asset name, including the null terminator.+ *+ * This function calculates the length of the string representation of a \ref cardano_asset_name_t object,+ * including the null terminator. This is useful for understanding the buffer size required to store the+ * string representation of the asset name.+ *+ * \param[in] asset_name A pointer to an initialized \ref cardano_asset_name_t object.+ *                       The pointer must not be NULL and should point to a valid asset name object.+ *+ * \return The size of the string in bytes, including the null terminator. If the input is NULL or an error occurs,+ *         the function returns 0.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_t* asset_name = ...; // Assume asset_name is already initialized+ * size_t name_size = cardano_asset_name_get_string_size(asset_name);+ *+ * if (name_size > 0)+ * {+ *   printf("Size of the asset name string including null terminator: %zu\n", name_size);+ * }+ * else+ * {+ *   printf("Failed to retrieve the size of the asset name string.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_asset_name_get_string_size(const cardano_asset_name_t* asset_name);++/**+ * \brief Retrieves the byte representation of a Cardano asset name.+ *+ * This function provides access to the underlying byte array of a \ref cardano_asset_name_t object.+ * The byte array represents the asset name as it is stored and used within the Cardano ecosystem.+ *+ * \param[in] asset_name A pointer of an initialized \ref cardano_asset_name_t object.+ *                       The pointer must not be NULL and should point to a valid asset name object.+ *+ * \return A pointer to the constant byte array representing the asset name. This pointer points to an+ *         internal buffer and must not be modified or freed by the caller. If the input is NULL or an+ *         error occurs, the function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_t* asset_name = ...; // Assume asset_name is already initialized+ * const byte_t* name_bytes = cardano_asset_name_get_bytes(asset_name);+ *+ * if (name_bytes != NULL)+ * {+ *   // Process the bytes of the asset name+ *   // Note: The length of the byte array should be known or determined separately+ * }+ * else+ * {+ *   printf("Failed to retrieve the bytes of the asset name.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t*+cardano_asset_name_get_bytes(const cardano_asset_name_t* asset_name);++/**+ * \brief Retrieves the size of the byte array for a Cardano asset name.+ *+ * This function returns the size of the byte array representing the asset name contained within+ * a \ref cardano_asset_name_t object.+ *+ * \param[in] asset_name A pointer of an initialized \ref cardano_asset_name_t object.+ *                       The pointer must not be NULL and should point to a valid asset name object.+ *+ * \return The size of the byte array representing the asset name. If the input is NULL or an+ *         error occurs, the function returns 0. This size does not include a null terminator, as+ *         asset names can contain arbitrary binary data.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_t* asset_name = ...; // Assume asset_name is already initialized+ * size_t name_size = cardano_asset_name_get_bytes_size(asset_name);+ *+ * if (name_size > 0)+ * {+ *   const byte_t* name_bytes = cardano_asset_name_get_bytes(asset_name);+ *   // Process the bytes knowing the exact size of the asset name+ * }+ * else+ * {+ *   printf("Failed to retrieve the size of the asset name or asset name is empty.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_asset_name_get_bytes_size(const cardano_asset_name_t* asset_name);++/**+ * \brief Retrieves the hexadecimal string representation of a Cardano asset name.+ *+ * This function returns the hexadecimal string representation of a \ref cardano_asset_name_t object.+ * The string encodes the asset name, which consists of the concatenated bytes of the policy ID and asset name.+ *+ * \param[in] asset_name A pointer to an initialized \ref cardano_asset_name_t object.+ *                     The pointer must not be NULL and should point to a valid asset name object.+ *+ * \return A pointer to a null-terminated string representing the asset name in hexadecimal format.+ *         This string is owned by the \ref cardano_asset_name_t object and must not be modified or freed by the caller.+ *         If the input is NULL or an error occurs, the function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_asset_name_t* asset_name = ...; // Assume asset_name is already initialized+ * const char* hex_string = cardano_asset_name_get_hex(asset_name);+ *+ * if (hex_string != NULL)+ * {+ *   // Process the hexadecimal string of the asset name+ *   printf("Asset ID in hex: %s\n", hex_string);+ * }+ * else+ * {+ *   printf("Failed to retrieve the hexadecimal string of the asset name.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char*+cardano_asset_name_get_hex(const cardano_asset_name_t* asset_name);++/**+ * \brief Retrieves the size of the hexadecimal string for a Cardano asset name.+ *+ * This function returns the size of the hexadecimal string representation of a \ref cardano_asset_name_t object.+ * The size includes the number of characters in the hexadecimal string, not including the null terminator.+ *+ * \param[in] asset_name A pointer to an initialized \ref cardano_asset_name_t object.+ *                     The pointer must not be NULL and should point to a valid asset name object.+ *+ * \return The size of the hexadecimal string representing the asset name. If the input is NULL or an+ *         error occurs, the function returns 0. The size does not include a null terminator.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_asset_name_t* asset_name = ...; // Assume asset_name is already initialized+ * size_t hex_size = cardano_asset_name_get_hex_size(asset_name);+ *+ * if (hex_size > 0)+ * {+ *   const char* hex_string = cardano_asset_name_get_hex(asset_name);+ *   // Process the hex string knowing the exact size of the asset name+ *   printf("Hexadecimal string size: %zu\n", hex_size);+ * }+ * else+ * {+ *   printf("Failed to retrieve the size of the asset name in hex or asset name is empty.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_asset_name_get_hex_size(const cardano_asset_name_t* asset_name);++/**+ * \brief Decrements the reference count of a cardano_asset_name_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_asset_name_t object+ * by decreasing its reference count. When the reference count reaches zero, the asset_name is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] asset_name A pointer to the pointer of the asset_name object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_t* asset_name = cardano_asset_name_new(major, minor);+ *+ * // Perform operations with the asset_name...+ *+ * cardano_asset_name_unref(&asset_name);+ * // At this point, asset_name is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_asset_name_unref, the pointer to the \ref cardano_asset_name_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_asset_name_unref(cardano_asset_name_t** asset_name);++/**+ * \brief Increases the reference count of the cardano_asset_name_t object.+ *+ * This function is used to manually increment the reference count of an cardano_asset_name_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_asset_name_unref.+ *+ * \param asset_name A pointer to the cardano_asset_name_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_name is a previously created asset_name object+ *+ * cardano_asset_name_ref(asset_name);+ *+ * // Now asset_name can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_asset_name_ref there is a corresponding+ * call to \ref cardano_asset_name_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_asset_name_ref(cardano_asset_name_t* asset_name);++/**+ * \brief Retrieves the current reference count of the cardano_asset_name_t object.+ *+ * This function returns the number of active references to an cardano_asset_name_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_asset_name_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param asset_name A pointer to the cardano_asset_name_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_asset_name_t object. If the object+ * is properly managed (i.e., every \ref cardano_asset_name_ref call is matched with a+ * \ref cardano_asset_name_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_name is a previously created asset_name object+ *+ * size_t ref_count = cardano_asset_name_refcount(asset_name);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_name_refcount(const cardano_asset_name_t* asset_name);++/**+ * \brief Sets the last error message for a given cardano_asset_name_t object.+ *+ * Records an error message in the asset_name's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] asset_name A pointer to the \ref cardano_asset_name_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the asset_name's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_asset_name_set_last_error(+  cardano_asset_name_t* asset_name,+  const char*           message);++/**+ * \brief Retrieves the last error message recorded for a specific asset_name.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_asset_name_set_last_error for the given+ * asset_name. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] asset_name A pointer to the \ref cardano_asset_name_t instance whose last error+ *                   message is to be retrieved. If the asset_name is NULL, the function+ *                   returns a generic error message indicating the null asset_name.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified asset_name. If the asset_name is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_asset_name_set_last_error for the same asset_name, or until+ *       the asset_name is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_asset_name_get_last_error(+  const cardano_asset_name_t* asset_name);++/**+ * \brief Creates an independent deep copy of a \ref cardano_asset_name_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_asset_name_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_asset_name_deep_clone(const cardano_asset_name_t* source, cardano_asset_name_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ASSET_NAME_H
+ vendor/include/cardano/assets/asset_name_list.h view
@@ -0,0 +1,333 @@+/**+ * \file asset_name_list.h+ *+ * \author angel.castillo+ * \date   Aug 08, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ASSET_NAME_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ASSET_NAME_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents an asset name.+ */+typedef struct cardano_asset_name_t cardano_asset_name_t;++/**+ * \brief Represents a list of asset name.+ */+typedef struct cardano_asset_name_list_t cardano_asset_name_list_t;++/**+ * \brief Creates and initializes a new instance of a asset_name_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_asset_name_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] asset_name_list On successful initialization, this will point to a newly created+ *             \ref cardano_asset_name_list_t object. This object represents a "strong reference"+ *             to the asset_name_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the asset_name_list is no longer needed, the caller must release it+ *             by calling \ref cardano_asset_name_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the asset_name_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_list_t* asset_name_list = NULL;+ *+ * // Attempt to create a new asset_name_list+ * cardano_error_t result = cardano_asset_name_list_new(&asset_name_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_name_list+ *+ *   // Once done, ensure to clean up and release the asset_name_list+ *   cardano_asset_name_list_unref(&asset_name_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_name_list_new(cardano_asset_name_list_t** asset_name_list);++/**+ * \brief Retrieves the length of a asset name list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_asset_name_list_t object.+ *+ * \param[in] asset_name_list A constant pointer to the \ref cardano_asset_name_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the asset_name_list. Return 0 if the asset_name_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_list_t* asset_name_list = cardano_asset_name_list_new();+ *+ * // Populate asset_name_list with elements+ *+ * size_t length = cardano_asset_name_list_get_length(asset_name_list);+ * printf("Length of the asset_name_list: %zu\n", length);+ *+ * // Clean up the asset_name_list object once done+ * cardano_asset_name_list_unref(&asset_name_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_name_list_get_length(const cardano_asset_name_list_t* asset_name_list);++/**+ * \brief Retrieves an element from a asset name list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_asset_name_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] asset_name_list A constant pointer to the \ref cardano_asset_name_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the asset name list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_asset_name_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_asset_name_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_list_t* asset_name_list = cardano_asset_name_list_new();+ *+ * // Populate asset_name_list with elements+ *+ * cardano_asset_name_t* element = NULL;+ * cardano_error_t result = cardano_asset_name_list_get(asset_name_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_asset_name_unref(&element);+ * }+ *+ * // Clean up the asset_name_list object once done+ * cardano_asset_name_list_unref(&asset_name_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_list_get(const cardano_asset_name_list_t* asset_name_list, size_t index, cardano_asset_name_t** element);++/**+ * \brief Adds an element to a asset name list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_asset_name_list_t object.+ *+ * \param[in] asset_name_list A constant pointer to the \ref cardano_asset_name_list_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_asset_name_t object that is to be added to the asset_name_list.+ *                    The element will be referenced by the asset_name_list after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the asset_name_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_list_t* asset_name_list = cardano_asset_name_list_new();+ *+ * // Create and initialize a new asset name element+ * cardano_asset_name_t* element = { ... };+ *+ * // Add the element to the asset_name_list+ * cardano_error_t result = cardano_asset_name_list_add(asset_name_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the asset_name_list object once done+ * cardano_asset_name_list_unref(&asset_name_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_list_add(cardano_asset_name_list_t* asset_name_list, cardano_asset_name_t* element);++/**+ * \brief Decrements the reference count of a asset_name_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_asset_name_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the asset_name_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] asset_name_list A pointer to the pointer of the asset_name_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_list_t* asset_name_list = cardano_asset_name_list_new();+ *+ * // Perform operations with the asset_name_list...+ *+ * cardano_asset_name_list_unref(&asset_name_list);+ * // At this point, asset_name_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_asset_name_list_unref, the pointer to the \ref cardano_asset_name_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_asset_name_list_unref(cardano_asset_name_list_t** asset_name_list);++/**+ * \brief Increases the reference count of the cardano_asset_name_list_t object.+ *+ * This function is used to manually increment the reference count of a asset_name_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_asset_name_list_unref.+ *+ * \param asset_name_list A pointer to the asset_name_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_name_list is a previously created asset_name_list object+ *+ * cardano_asset_name_list_ref(asset_name_list);+ *+ * // Now asset_name_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_asset_name_list_ref there is a corresponding+ * call to \ref cardano_asset_name_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_asset_name_list_ref(cardano_asset_name_list_t* asset_name_list);++/**+ * \brief Retrieves the current reference count of the cardano_asset_name_list_t object.+ *+ * This function returns the number of active references to a asset_name_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_asset_name_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param asset_name_list A pointer to the asset_name_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified asset_name_list object. If the object+ * is properly managed (i.e., every \ref cardano_asset_name_list_ref call is matched with a+ * \ref cardano_asset_name_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_name_list is a previously created asset_name_list object+ *+ * size_t ref_count = cardano_asset_name_list_refcount(asset_name_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_name_list_refcount(const cardano_asset_name_list_t* asset_name_list);++/**+ * \brief Sets the last error message for a given asset_name_list object.+ *+ * Records an error message in the asset_name_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] asset_name_list A pointer to the \ref cardano_asset_name_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the asset_name_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_asset_name_list_set_last_error(cardano_asset_name_list_t* asset_name_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific asset_name_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_asset_name_list_set_last_error for the given+ * asset_name_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] asset_name_list A pointer to the \ref cardano_asset_name_list_t instance whose last error+ *                   message is to be retrieved. If the asset_name_list is NULL, the function+ *                   returns a generic error message indicating the null asset_name_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified asset_name_list. If the asset_name_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_asset_name_list_set_last_error for the same asset_name_list, or until+ *       the asset_name_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_asset_name_list_get_last_error(const cardano_asset_name_list_t* asset_name_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_asset_name_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_asset_name_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_asset_name_list_deep_clone(const cardano_asset_name_list_t* source, cardano_asset_name_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ASSET_NAME_LIST_H
+ vendor/include/cardano/assets/asset_name_map.h view
@@ -0,0 +1,786 @@+/**+ * \file asset_name_map.h+ *+ * \author angel.castillo+ * \date   Sep 05, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ASSET_NAME_MAP_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ASSET_NAME_MAP_H++/* INCLUDES ******************************************************************/++#include <cardano/assets/asset_name.h>+#include <cardano/assets/asset_name_list.h>+#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a map of asset name to coin amount.+ */+typedef struct cardano_asset_name_map_t cardano_asset_name_map_t;++/**+ * \brief Creates and initializes a new instance of a asset name map.+ *+ * This function allocates and initializes a new instance of \ref cardano_asset_name_map_t,+ * representing a map structure. It returns an error code to indicate the success or failure of the operation.+ *+ * \param[out] asset_name_map A pointer to a pointer to a \ref cardano_asset_name_map_t object. Upon successful+ *                        initialization, this will point to a newly created \ref cardano_asset_name_map_t+ *                        object. This object represents a "strong reference" to the asset_name_map,+ *                        fully initialized and ready for use. The caller is responsible for managing+ *                        the lifecycle of this object. Specifically, once the asset_name_map is no longer+ *                        needed, the caller must release it by calling \ref cardano_asset_name_map_unref.+ *+ * \return \ref CARDANO_SUCCESS if the asset_name_map was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = NULL;+ *+ * // Attempt to create a new asset_name_map+ * cardano_error_t result = cardano_asset_name_map_new(&asset_name_map);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_name_map+ *+ *   // Once done, ensure to clean up and release the asset_name_map+ *   cardano_asset_name_map_unref(&asset_name_map);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_name_map_new(cardano_asset_name_map_t** asset_name_map);++/**+ * \brief Creates a asset name map from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_asset_name_map_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a asset_name_map.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded asset_name_map data.+ * \param[out] asset_name_map A pointer to a pointer of \ref cardano_asset_name_map_t that will be set to the address+ *                        of the newly created asset_name_map object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the asset_name_map was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_asset_name_map_t object by calling+ *       \ref cardano_asset_name_map_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_asset_name_map_t* asset_name_map = NULL;+ *+ * cardano_error_t result = cardano_asset_name_map_from_cbor(reader, &asset_name_map);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_name_map+ *+ *   // Once done, ensure to clean up and release the asset_name_map+ *   cardano_asset_name_map_unref(&asset_name_map);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode asset_name_map: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_asset_name_map_from_cbor(cardano_cbor_reader_t* reader, cardano_asset_name_map_t** asset_name_map);++/**+ * \brief Serializes a asset name map into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_asset_name_map_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] asset_name_map A constant pointer to the \ref cardano_asset_name_map_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p asset_name_map or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_asset_name_map_to_cbor(asset_name_map, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_asset_name_map_unref(&asset_name_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_to_cbor(+  const cardano_asset_name_map_t* asset_name_map,+  cardano_cbor_writer_t*          writer);++/**+ * \brief Serializes an asset name map to a CIP-116 JSON object.+ *+ * The function writes a JSON object where keys are the hexadecimal representation+ * of the asset names, and values are the string representation of the amounts.+ *+ * \param[in]  map     Pointer to a valid \ref cardano_asset_name_map_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p map or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_to_cip116_json(+  const cardano_asset_name_map_t* map,+  cardano_json_writer_t*          writer);++/**+ * \brief Serializes an asset name map to a CIP-116 JSON array of key-value objects.+ *+ * This function converts the internal map structure of [AssetName -> Amount] into an+ * ordered JSON array, matching the schema required for the 'assets' field within the 'Mint' structure+ * (Transaction Body). Each map entry is serialized as a JSON object:+ * { "asset_name": "<hex_string>", "amount": "<amount_string>" }+ *+ * \param[in]  map     Pointer to a valid \ref cardano_asset_name_map_t.+ * \param[in]  writer  Pointer to the active \ref cardano_json_writer_t instance.+ *+ * \return CARDANO_SUCCESS               On successful serialization.+ * \return CARDANO_ERROR_POINTER_IS_NULL If \p map or \p writer is NULL.+ * \return CARDANO_ERROR_ENCODING        If an element within the map is NULL.+ * \return Other                         Any error propagated from nested writers.+ */+cardano_error_t+cardano_asset_name_map_to_cip116_json_ex(+  const cardano_asset_name_map_t* map,+  cardano_json_writer_t*          writer);++/**+ * \brief Retrieves the length of the asset_name_map.+ *+ * This function returns the number of key-value pairs contained in the specified asset_name_map.+ *+ * \param[in] asset_name_map A constant pointer to the \ref cardano_asset_name_map_t object for which+ *                       the length is to be retrieved.+ *+ * \return The number of key-value pairs in the asset_name_map. Returns 0 if the asset_name_map is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = cardano_asset_name_map_new();+ *+ * // Populate the asset_name_map with key-value pairs+ *+ * size_t length = cardano_asset_name_map_get_length(asset_name_map);+ * printf("The length of the asset_name_map is: %zu\n", length);+ *+ * cardano_asset_name_map_unref(&asset_name_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_name_map_get_length(const cardano_asset_name_map_t* asset_name_map);++/**+ * \brief Retrieves the value associated with a given key in the asset name map.+ *+ * This function retrieves the value associated with the specified key in the provided asset name map.+ * It returns the value through the output parameter `element`. If the key is not found in the asset name map,+ * the output parameter `element` will be set to NULL.+ *+ * \param[in] asset_name_map A constant pointer to the \ref cardano_asset_name_map_t object from which+ *                       the value is to be retrieved.+ * \param[in] key The key whose associated value is to be retrieved from the asset_name_map.+ * \param[out] element A pointer to a variable where the retrieved value will be stored. If the key+ *                     is found in the asset name map, this variable will be set to the associated value.+ *                     If the key is not found, this variable will be set to NULL.+ *+ * \return \ref CARDANO_SUCCESS if the value associated with the key was successfully retrieved, or+ *         an appropriate error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = cardano_asset_name_map_new();+ *+ * // Populate the asset_name_map with key-value pairs+ *+ * cardano_asset_name_t* key = ...; // Create a asset_name object representing the key+ * int64_t value = 0;+ * cardano_error_t result = cardano_asset_name_map_get(asset_name_map, key, &value);+ *+ * if (result == CARDANO_SUCCESS && value != NULL)+ * {+ *   // Use the retrieved value+ *   // ...+ * }+ * else+ * {+ *   // Handle error or key not found+ * }+ *+ * cardano_asset_name_unref(&key); // Clean up the key resource+ * cardano_asset_name_map_unref(&asset_name_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_get(cardano_asset_name_map_t* asset_name_map, cardano_asset_name_t* key, int64_t* element);++/**+ * \brief Inserts a key-value pair into the asset name map.+ *+ * This function inserts the specified key-value pair into the provided asset name map.+ *+ * \param[in] asset_name_map A constant pointer to the \ref cardano_asset_name_map_t object where+ *                       the key-value pair is to be inserted.+ * \param[in] key The key to be inserted into the asset name map. The caller is responsible for managing+ *                the lifecycle of the key object.+ * \param[in] value The value to be associated with the key and inserted into the asset_name_map.+ *                  The caller is responsible for managing the lifecycle of the value object.+ *+ * \return \ref CARDANO_SUCCESS if the key-value pair was successfully inserted, or an appropriate+ *         error code if the input parameters are invalid or any other error occurs.+ *+ * \remark If the key already exists in the asset name map, the value associated with the key will be updated.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = cardano_asset_name_map_new();+ *+ * // Create key and value objects+ * cardano_asset_name_t* key = ...;+ * int64_t value = 0;+ *+ * // Insert the key-value pair into the asset_name_map+ * cardano_error_t result = cardano_asset_name_map_insert(asset_name_map, key, value);+ *+ * if (result != CARDANO_SUCCESS)+ * {+ *   // Handle insertion failure+ * }+ *+ * // Clean up key and value objects+ * cardano_asset_name_unref(&key);+ *+ * cardano_asset_name_map_unref(&asset_name_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_insert(cardano_asset_name_map_t* asset_name_map, cardano_asset_name_t* key, int64_t value);++/**+ * \brief Retrieves the keys from the asset name map.+ *+ * This function retrieves all the keys from the provided asset name map and returns them as a list.+ * The caller is responsible for managing the lifecycle of the returned list by calling+ * \ref cardano_asset_name_list_t when it is no longer needed.+ *+ * \param[in] asset_name_map A constant pointer to the \ref cardano_asset_name_map_t object from which+ *                       the keys are to be retrieved.+ * \param[out] keys A pointer to a variable where the retrieved keys will be stored as a list.+ *                  If successful, this variable will be set to point to the list of keys.+ *                  The caller is responsible for managing the lifecycle of this list.+ *                  It must be released by calling \ref cardano_asset_name_list_t when no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the keys were successfully retrieved, or an appropriate+ *         error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = cardano_asset_name_map_new();+ *+ * // Populate the asset_name_map with key-value pairs+ *+ * cardano_asset_name_list_t* keys = NULL;+ * cardano_error_t result = cardano_asset_name_map_get_keys(asset_name_map, &keys);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the list of keys+ *   // Keys must also be freed if retrieved from the list+ *+ *   // Once done, ensure to clean up and release the keys list+ *   cardano_asset_name_list_unref(&keys);+ * }+ * else+ * {+ *   // Handle error+ * }+ *+ * cardano_asset_name_map_unref(&asset_name_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_get_keys(cardano_asset_name_map_t* asset_name_map, cardano_asset_name_list_t** keys);++/**+ * \brief Retrieves the asset name at a specific index from the asset name map.+ *+ * This function retrieves the asset name at the specified index from the asset name map.+ *+ * \param[in] asset_name_map Pointer to the asset name map object.+ * \param[in] index The index of the asset name to retrieve.+ * \param[out] asset_name On successful retrieval, this will point to the asset name+ *                        at the specified index. The caller is responsible for managing the lifecycle+ *                        of this object. Specifically, once the asset name is no longer needed,+ *                        the caller must release it by calling \ref cardano_asset_name_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the asset name was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = NULL;+ * cardano_asset_name_t* asset_name = NULL;+ * size_t index = 0; // Index of the key hash to retrieve+ *+ * // Assume asset_name_map is initialized properly+ *+ * cardano_error_t result = cardano_asset_name_map_get_key_at(asset_name_map, index, &asset_name);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the asset_name+ *+ *   // Once done, ensure to clean up and release the asset_name+ *   cardano_asset_name_unref(&asset_name);+ * }+ * else+ * {+ *   // Handle the error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_get_key_at(+  const cardano_asset_name_map_t* asset_name_map,+  size_t                          index,+  cardano_asset_name_t**          asset_name);++/**+ * \brief Retrieves the withdrawal amount at a specific index from the asset name map.+ *+ * This function retrieves the withdrawal amount at the specified index from the asset name map.+ *+ * \param[in] asset_name_map Pointer to the asset name map object.+ * \param[in] index The index of the withdrawal amount to retrieve.+ * \param[out] amount On successful retrieval, this will point to the withdrawal amount+ *                    at the specified index.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the withdrawal amount was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = NULL;+ * int64_t amount = 0;+ * size_t index = 0; // Index of the withdrawal amount to retrieve+ *+ * // Assume asset_name_map is initialized properly+ *+ * cardano_error_t result = cardano_asset_name_map_get_value_at(asset_name_map, index, &amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the amount+ * }+ * else+ * {+ *   // Handle the error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_get_value_at(+  const cardano_asset_name_map_t* asset_name_map,+  size_t                          index,+  int64_t*                        amount);++/**+ * \brief Retrieves the asset name and withdrawal amount at the specified index.+ *+ * This function retrieves the asset name and withdrawal amount from the proposed withdrawal amounts+ * at the specified index.+ *+ * \param[in]  asset_name_map    Pointer to the proposed withdrawal amounts object.+ * \param[in]  index             The index at which to retrieve the key-value pair.+ * \param[out] asset_name On successful retrieval, this will point to the asset name at the specified index.+ *                            The caller is responsible for managing the lifecycle of this object and should release it using+ *                            \ref cardano_asset_name_unref when it is no longer needed.+ * \param[out] amount On successful retrieval, this will point to the withdrawal amount at the specified index.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the key-value pair was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = NULL;+ * // Assume asset_name_map is initialized properly+ *+ * size_t index = 0;+ * cardano_asset_name_t* asset_name = NULL;+ * int64_t amount = 0;+ *+ * cardano_error_t result = cardano_asset_name_map_get_key_value_at(asset_name_map, index, &asset_name, &amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   if (asset_name != NULL && amount != NULL)+ *   {+ *     // Use the asset name and withdrawal amount+ *   }+ *   else+ *   {+ *     printf("Key-value pair not set at index %zu.\n", index);+ *   }+ * }+ * else+ * {+ *   // Handle error+ *   printf("Failed to get key-value pair at index %zu.\n", index);+ * }+ *+ * // Clean up+ * cardano_asset_name_map_unref(&asset_name_map);+ * cardano_asset_name_unref(&asset_name);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_get_key_value_at(+  const cardano_asset_name_map_t* asset_name_map,+  size_t                          index,+  cardano_asset_name_t**          asset_name,+  int64_t*                        amount);++/**+ * \brief Combines two asset name maps by adding the quantities of assets with the same asset names.+ *+ * This function adds the asset quantities from two \ref cardano_asset_name_map_t objects. It combines the quantities+ * of assets that have the same asset names. If an asset name exists in both maps, their quantities are summed.+ * If an asset name exists in only one of the maps, its quantity is copied to the result.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_asset_name_map_t object.+ * \param[in] rhs A constant pointer to the second \ref cardano_asset_name_map_t object.+ * \param[out] result On successful execution, this will point to a newly created \ref cardano_asset_name_map_t object+ *             that represents the combined result of both input asset name maps.+ *             The result is dynamically allocated and must be freed by the caller using \ref cardano_asset_name_map_unref+ *             when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the assets were+ *         successfully combined, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_asset_name_map_t* lhs = ...; // Assume lhs is already initialized with some assets+ * const cardano_asset_name_map_t* rhs = ...; // Assume rhs is also initialized with some assets+ * cardano_asset_name_map_t* result = NULL;+ *+ * cardano_error_t add_result = cardano_asset_name_map_add(lhs, rhs, &result);+ * if (add_result == CARDANO_SUCCESS)+ * {+ *   // The assets have been successfully combined+ *   // Use the result as needed+ *+ *   // When done, release the result+ *   cardano_asset_name_map_unref(&result);+ * }+ * else+ * {+ *   printf("Failed to combine assets: %s\n", cardano_error_to_string(add_result));+ * }+ *+ * // Cleanup resources+ * cardano_asset_name_map_unref(&lhs);+ * cardano_asset_name_map_unref(&rhs);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_add(+  const cardano_asset_name_map_t* lhs,+  const cardano_asset_name_map_t* rhs,+  cardano_asset_name_map_t**      result);++/**+ * \brief Subtracts the quantities of assets under each asset name from one asset name map to another.+ *+ * This function subtracts the assets from the second \ref cardano_asset_name_map_t object (rhs) from the first+ * \ref cardano_asset_name_map_t object (lhs). It subtracts the quantities of assets under each asset name present+ * in both maps. If an asset name exists only in the rhs, the value is copied as negative, effectively subtracting+ * it from the lhs. If an asset name exists only in the lhs, the value is copied as is to the result.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_asset_name_map_t object from which assets will be subtracted.+ * \param[in] rhs A constant pointer to the second \ref cardano_asset_name_map_t object that provides the quantities to subtract.+ * \param[out] result On successful execution, this will point to a newly created \ref cardano_asset_name_map_t object+ *             that represents the result of the subtraction.+ *             The result is dynamically allocated and must be freed by the caller using \ref cardano_asset_name_map_unref+ *             when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the assets were+ *         successfully subtracted, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_asset_name_map_t* lhs = ...; // Assume lhs is already initialized with some assets+ * const cardano_asset_name_map_t* rhs = ...; // Assume rhs is also initialized with some assets to subtract+ * cardano_asset_name_map_t* result = NULL;+ *+ * cardano_error_t subtract_result = cardano_asset_name_map_subtract(lhs, rhs, &result);+ * if (subtract_result == CARDANO_SUCCESS)+ * {+ *   // The assets have been successfully subtracted+ *   // Use the result+ *   cardano_asset_name_map_unref(&result);+ * }+ * else+ * {+ *   printf("Failed to subtract assets: %s\n", cardano_error_to_string(subtract_result));+ * }+ *+ * // Cleanup resources+ * cardano_asset_name_map_unref(&lhs);+ * cardano_asset_name_map_unref(&rhs);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_asset_name_map_subtract(+  const cardano_asset_name_map_t* lhs,+  const cardano_asset_name_map_t* rhs,+  cardano_asset_name_map_t**      result);++/**+ * \brief Compares two asset name map objects for equality.+ *+ * This function compares two asset_name_map objects to determine if they are equal.+ *+ * \param[in] lhs Pointer to the first asset name map object.+ * \param[in] rhs Pointer to the second asset name map object.+ *+ * \return \c true if the asset name map objects are equal, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map1 = NULL;+ * cardano_asset_name_map_t* asset_name_map2 = NULL;+ *+ * // Assume asset_name_map1 and asset_name_map2 are initialized properly+ *+ * bool are_equal = cardano_asset_name_map_equals(asset_name_map1, asset_name_map2);+ *+ * if (are_equal)+ * {+ *   printf("The asset_name_map objects are equal.\n");+ * }+ * else+ * {+ *   printf("The asset_name_map objects are not equal.\n");+ * }+ *+ * // Clean up+ * cardano_asset_name_map_unref(&asset_name_map1);+ * cardano_asset_name_map_unref(&asset_name_map2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool+cardano_asset_name_map_equals(const cardano_asset_name_map_t* lhs, const cardano_asset_name_map_t* rhs);++/**+ * \brief Decrements the reference count of a asset_name_map object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_asset_name_map_t object+ * by decreasing its reference count. When the reference count reaches zero, the asset_name_map is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] asset_name_map A pointer to the pointer of the asset_name_map object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_asset_name_map_t* asset_name_map = cardano_asset_name_map_new();+ *+ * // Perform operations with the asset_name_map...+ *+ * cardano_asset_name_map_unref(&asset_name_map);+ * // At this point, asset_name_map is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_asset_name_map_unref, the pointer to the \ref cardano_asset_name_map_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_asset_name_map_unref(cardano_asset_name_map_t** asset_name_map);++/**+ * \brief Increases the reference count of the cardano_asset_name_map_t object.+ *+ * This function is used to manually increment the reference count of a asset_name_map+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_asset_name_map_unref.+ *+ * \param asset_name_map A pointer to the asset_name_map object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_name_map is a previously created asset_name_map object+ *+ * cardano_asset_name_map_ref(asset_name_map);+ *+ * // Now asset_name_map can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_asset_name_map_ref there is a corresponding+ * call to \ref cardano_asset_name_map_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_asset_name_map_ref(cardano_asset_name_map_t* asset_name_map);++/**+ * \brief Retrieves the current reference count of the cardano_asset_name_map_t object.+ *+ * This function returns the number of active references to a asset_name_map object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_asset_name_map_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param asset_name_map A pointer to the asset_name_map object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified asset_name_map object. If the object+ * is properly managed (i.e., every \ref cardano_asset_name_map_ref call is matched with a+ * \ref cardano_asset_name_map_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming asset_name_map is a previously created asset_name_map object+ *+ * size_t ref_count = cardano_asset_name_map_refcount(asset_name_map);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_asset_name_map_refcount(const cardano_asset_name_map_t* asset_name_map);++/**+ * \brief Sets the last error message for a given asset_name_map object.+ *+ * Records an error message in the asset_name_map's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] asset_name_map A pointer to the \ref cardano_asset_name_map_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the asset_name_map's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_asset_name_map_set_last_error(cardano_asset_name_map_t* asset_name_map, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific asset_name_map.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_asset_name_map_set_last_error for the given+ * asset_name_map. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] asset_name_map A pointer to the \ref cardano_asset_name_map_t instance whose last error+ *                   message is to be retrieved. If the asset_name_map is NULL, the function+ *                   returns a generic error message indicating the null asset_name_map.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified asset_name_map. If the asset_name_map is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_asset_name_map_set_last_error for the same asset_name_map, or until+ *       the asset_name_map is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_asset_name_map_get_last_error(const cardano_asset_name_map_t* asset_name_map);++/**+ * \brief Creates an independent deep copy of a \ref cardano_asset_name_map_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_asset_name_map_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_asset_name_map_deep_clone(const cardano_asset_name_map_t* source, cardano_asset_name_map_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ASSET_NAME_MAP_H
+ vendor/include/cardano/assets/multi_asset.h view
@@ -0,0 +1,897 @@+/**+ * \file multi_asset.h+ *+ * \author angel.castillo+ * \date   Sep 06, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_MULTI_ASSET_H+#define BIGLUP_LABS_INCLUDE_CARDANO_MULTI_ASSET_H++/* INCLUDES ******************************************************************/++#include <cardano/assets/asset_id.h>+#include <cardano/assets/asset_name.h>+#include <cardano/assets/asset_name_map.h>+#include <cardano/assets/policy_id_list.h>+#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a collection of assets in the Cardano blockchain.+ *+ * This struct is used to represent a multi-asset, which can include various native tokens.+ * Each asset is identified by a unique combination of a policy ID and asset name, and the+ * struct manages quantities of these assets.+ */+typedef struct cardano_multi_asset_t cardano_multi_asset_t;++/**+ * \brief Creates and initializes a new instance of a Multi-Asset.+ *+ * This function allocates and initializes a new instance of a Multi-Asset,+ * which can hold various native tokens within the Cardano network.+ *+ * \param[out] multi_asset On successful initialization, this will point to a newly created+ *             cardano_multi_asset_t object. This object represents a "strong reference",+ *             meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the Multi-Asset is no longer needed, the caller must release it+ *             by calling \ref cardano_multi_asset_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the Multi-Asset was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_multi_asset_t* multi_asset = NULL;+ *+ * // Attempt to create a new Multi-Asset object+ * cardano_error_t result = cardano_multi_asset_new(&multi_asset);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the multi_asset+ *+ *   // Once done, ensure to clean up and release the multi_asset+ *   cardano_multi_asset_unref(&multi_asset);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_multi_asset_new(cardano_multi_asset_t** multi_asset);++/**+ * \brief Creates a \ref cardano_multi_asset_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_multi_asset_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a multi_asset.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] multi_asset A pointer to a pointer of \ref cardano_multi_asset_t that will be set to the address+ *                        of the newly created multi_asset object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the multi asset were successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_multi_asset_t object by calling+ *       \ref cardano_multi_asset_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_multi_asset_t* multi_asset = NULL;+ *+ * cardano_error_t result = cardano_multi_asset_from_cbor(reader, &multi_asset);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the multi_asset+ *+ *   // Once done, ensure to clean up and release the multi_asset+ *   cardano_multi_asset_unref(&multi_asset);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode multi_asset: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_multi_asset_from_cbor(cardano_cbor_reader_t* reader, cardano_multi_asset_t** multi_asset);++/**+ * \brief Serializes multi asset into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_multi_asset_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] multi_asset A constant pointer to the \ref cardano_multi_asset_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p multi_asset or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * \remark Policies whose inner asset name maps are empty are skipped, so the encoder never emits+ *         empty inner policy maps.+ *+ * Usage Example:+ * \code{.c}+ * cardano_multi_asset_t* multi_asset = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_multi_asset_to_cbor(multi_asset, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_multi_asset_unref(&multi_asset);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_to_cbor(+  const cardano_multi_asset_t* multi_asset,+  cardano_cbor_writer_t*       writer);++/**+ * \brief Serializes a multi-asset collection to its CIP-116 JSON object representation.+ *+ * This function serializes the multi-asset structure into a JSON object where+ * keys are the hex-encoded Policy IDs (ScriptHash) and values are the+ * corresponding asset name maps (also JSON objects).+ *+ * This format is used for the "assets" field within a "Value" object.+ *+ * \param[in]  multi_asset Pointer to a valid \ref cardano_multi_asset_t.+ * \param[in]  writer      Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p multi_asset or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_to_cip116_json(+  const cardano_multi_asset_t* multi_asset,+  cardano_json_writer_t*       writer);++/**+ * \brief Serializes a multi-asset collection into the specific CIP-116 'Mint' array format.+ *+ * This function converts the internal map structure (Policy ID -> Asset Name Map) into+ * a JSON **array** of policy objects, which is the format required for the 'mint' field in the+ * \ref cardano_transaction_body_t. The output structure is:+ * [ { "script_hash": "<policy_hex>", "assets": { ...asset_map... } }, ... ]+ *+ * \param[in]  multi_asset Pointer to the valid \ref cardano_multi_asset_t collection to be serialized.+ * \param[in]  writer      Pointer to the active \ref cardano_json_writer_t instance.+ *+ * \return CARDANO_SUCCESS                 On successful serialization.+ * \return CARDANO_ERROR_POINTER_IS_NULL   If \p multi_asset or \p writer is NULL.+ * \return CARDANO_ERROR_ELEMENT_NOT_FOUND If a null element is encountered in the internal array.+ * \return Other                           Any error propagated from nested serialization calls+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_to_cip116_json_ex(+  const cardano_multi_asset_t* multi_asset,+  cardano_json_writer_t*       writer);++/**+ * \brief Retrieves the number of distinct policy IDs within a multi-asset container.+ *+ * This function counts the number of distinct policy IDs in a given \ref cardano_multi_asset_t object.+ * Each policy ID can have one or more asset names associated with it, but this function only counts the+ * unique policies.+ *+ * \param[in] multi_asset A constant pointer to an initialized \ref cardano_multi_asset_t object.+ *                        The pointer must not be NULL.+ *+ * \return The number of unique policy IDs contained within the multi_asset object. If the input is NULL,+ *         the function returns 0 as a safe guard. This helps in managing conditions where the+ *         multi-asset container might be empty or incorrectly initialized.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_multi_asset_t* multi_asset = ...; // Assume multi_asset is already initialized+ * size_t policy_count = cardano_multi_asset_get_policy_count(multi_asset);+ *+ * printf("The multi-asset container has %zu distinct policy IDs.\n", policy_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_multi_asset_get_policy_count(+  const cardano_multi_asset_t* multi_asset);++/**+ * \brief Inserts assets under a specific policy ID into a multi-asset container.+ *+ * This function adds a collection of assets, identified by their names, along with their respective quantities,+ * under a given policy ID into a \ref cardano_multi_asset_t object. If the policy ID already exists in the multi-asset,+ * the assets are merged with the existing ones under that policy.+ *+ * \param[in,out] multi_asset A pointer to an initialized \ref cardano_multi_asset_t object.+ *                            This object will be modified to include the new assets under the specified policy ID.+ *                            The pointer must not be NULL.+ * \param[in] policy_id A pointer to an initialized \ref cardano_blake2b_hash_t object representing the policy ID+ *                      under which the assets are grouped. The pointer must not be NULL.+ * \param[in] assets A pointer to an initialized \ref cardano_asset_name_map_t object containing the asset names+ *                   and their corresponding quantities to be inserted. The pointer must not be NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the assets+ *         were successfully inserted, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * \remark If the key already exists in the multi asset, the value associated with the policy id will be updated.+ *+ * Usage Example:+ * \code{.c}+ * cardano_multi_asset_t* multi_asset = cardano_multi_asset_new(...); // Assume multi_asset is already initialized+ * cardano_blake2b_hash_t* policy_id = cardano_blake2b_hash_new(...); // Assume policy_id is initialized+ * cardano_asset_name_map_t* assets = cardano_asset_name_map_new(...); // Assume assets are prepared+ *+ * // Populate assets map+ * cardano_asset_name_t* asset_name = ...; // Assume asset_name is initialized+ * uint64_t quantity = 1000;+ * cardano_asset_name_map_insert(assets, asset_name, quantity);+ *+ * cardano_error_t result = cardano_multi_asset_insert_assets(multi_asset, policy_id, assets);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Assets successfully inserted under the policy ID.\n");+ * }+ * else+ * {+ *   printf("Failed to insert assets: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Cleanup resources+ * cardano_multi_asset_unref(&multi_asset);+ * cardano_blake2b_hash_unref(&policy_id);+ * cardano_asset_name_map_unref(&assets);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_insert_assets(+  cardano_multi_asset_t*    multi_asset,+  cardano_blake2b_hash_t*   policy_id,+  cardano_asset_name_map_t* assets);++/**+ * \brief Retrieves assets grouped under a specific policy ID from a multi-asset container.+ *+ * This function fetches the collection of assets associated with a given policy ID from a \ref cardano_multi_asset_t object.+ * It returns a map of asset names to their quantities.+ *+ * \param[in] multi_asset A constant pointer to an initialized \ref cardano_multi_asset_t object.+ *                        This object is queried to extract the assets associated with the specified policy ID.+ *                        The pointer must not be NULL.+ * \param[in] policy_id A pointer to an initialized \ref cardano_blake2b_hash_t object representing the policy ID+ *                      under which the assets are grouped. The pointer must not be NULL.+ * \param[out] assets On successful retrieval, this parameter will point to an initialized \ref cardano_asset_name_map_t object+ *                    containing the asset names and their corresponding quantities under the given policy ID.+ *                    The caller is responsible for managing the lifecycle of this object,+ *                    specifically, once the assets map is no longer needed, the caller must release it+ *                    by calling \ref cardano_asset_name_map_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the assets+ *         were successfully retrieved, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL, or \ref CARDANO_ERROR_ELEMENT_NOT_FOUND+ *         if the specified policy ID does not exist in the multi-asset container.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_multi_asset_t* multi_asset = ...; // Assume multi_asset is already initialized+ * cardano_blake2b_hash_t* policy_id = cardano_blake2b_hash_new(...); // Assume policy_id is initialized+ * cardano_asset_name_map_t* assets = NULL;+ *+ * cardano_error_t result = cardano_multi_asset_get_assets(multi_asset, policy_id, &assets);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Process the retrieved assets+ *   // Iterate over assets map, access names and quantities+ * }+ * else+ * {+ *   printf("Failed to retrieve assets: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Cleanup resources+ * if (assets)+ * {+ *   cardano_asset_name_map_unref(&assets);+ * }+ *+ * cardano_blake2b_hash_unref(&policy_id);+ * cardano_multi_asset_unref(&multi_asset);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_get_assets(+  const cardano_multi_asset_t* multi_asset,+  cardano_blake2b_hash_t*      policy_id,+  cardano_asset_name_map_t**   assets);++/**+ * \brief Retrieves the quantity of a specific asset identified by a policy ID and asset name from a multi-asset container.+ *+ * This function fetches the quantity of an asset based on its policy ID and asset name from a \ref cardano_multi_asset_t object.+ * It provides a direct method to access the quantity of a specified asset within the broader multi-asset structure.+ *+ * \param[in] multi_asset A constant pointer to an initialized \ref cardano_multi_asset_t object from which the asset's quantity is to be retrieved.+ *                        The pointer must not be NULL.+ * \param[in] policy_id A pointer to an initialized \ref cardano_blake2b_hash_t object representing the policy ID under which the asset is grouped.+ *                      The pointer must not be NULL.+ * \param[in] asset A pointer to an initialized \ref cardano_asset_name_t object representing the name of the asset.+ *                  The pointer must not be NULL.+ * \param[out] value On successful retrieval, this will contain the quantity of the asset. The value is represented as a signed 64-bit integer,+ *                   which accounts for possible negative quantities due to burning or other operations affecting asset balance.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the asset quantity was successfully retrieved,+ *         or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL,+ *         or \ref CARDANO_ERROR_ELEMENT_NOT_FOUND if either the specified policy ID or asset name does not exist within the multi-asset container.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_multi_asset_t* multi_asset = ...; // Assume multi_asset is already initialized+ * cardano_blake2b_hash_t* policy_id = cardano_blake2b_hash_new(...); // Assume policy_id is initialized+ * cardano_asset_name_t* asset = cardano_asset_name_new(...); // Assume asset is initialized+ * int64_t value = 0;+ *+ * cardano_error_t result = cardano_multi_asset_get(multi_asset, policy_id, asset, &value);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Asset quantity: %ld\n", value);+ *   // Process the retrieved asset quantity+ * }+ * else+ * {+ *   printf("Failed to retrieve asset quantity: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Cleanup resources+ * cardano_blake2b_hash_unref(&policy_id);+ * cardano_asset_name_unref(&asset);+ * cardano_multi_asset_unref(&multi_asset);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_get(+  const cardano_multi_asset_t* multi_asset,+  cardano_blake2b_hash_t*      policy_id,+  cardano_asset_name_t*        asset,+  int64_t*                     value);++/**+ * \brief Retrieves the amount associated with a specific asset ID from a multi-asset object.+ *+ * The `cardano_multi_asset_get_with_id` function allows you to retrieve the amount of a specific asset within+ * a \ref cardano_multi_asset_t object by providing the asset’s unique identifier.+ *+ * \param[in] multi_asset A pointer to the \ref cardano_multi_asset_t object from which to retrieve the asset amount.+ * \param[in] id A pointer to the \ref cardano_asset_id_t representing the unique identifier of the asset.+ * \param[out] value A pointer to an int64_t where the amount of the specified asset will be stored if it exists.+ *                   If the asset is not present, the function will store zero in this location.+ *+ * \return \ref CARDANO_SUCCESS if the amount was successfully retrieved or zeroed out if the asset is absent,+ *         or an appropriate error code indicating failure (e.g., if the asset ID is invalid).+ *+ * \note This function does not modify the `multi_asset` object but requires a valid, non-null `id` and `value` pointer.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_multi_asset_t* multi_asset = ...;  // Multi-asset object containing various assets+ * cardano_asset_id_t* asset_id = ...;              // The asset ID of the asset to retrieve+ * int64_t amount = 0;+ *+ * cardano_error_t result = cardano_multi_asset_get_with_id(multi_asset, asset_id, &amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // 'amount' now holds the quantity of the specified asset, or zero if not present+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_get_with_id(+  const cardano_multi_asset_t* multi_asset,+  cardano_asset_id_t*          id,+  int64_t*                     value);++/**+ * \brief Sets the quantity of a specific asset identified by a policy ID and asset name in a multi-asset container.+ *+ * This function sets or updates the quantity of an asset within a \ref cardano_multi_asset_t object based on its policy ID and asset name.+ * It allows the manipulation of asset quantities, such as issuing new assets or adjusting existing quantities.+ *+ * \param[in] multi_asset A constant pointer to an initialized \ref cardano_multi_asset_t object to which the asset's quantity will be set or updated.+ *                        The pointer must not be NULL.+ * \param[in] policy_id A pointer to an initialized \ref cardano_blake2b_hash_t object representing the policy ID under which the asset is grouped.+ *                      The pointer must not be NULL.+ * \param[in] asset A pointer to an initialized \ref cardano_asset_name_t object representing the name of the asset.+ *                  The pointer must not be NULL.+ * \param[in] value The new quantity for the asset. This is a signed 64-bit integer, allowing for the subtraction or addition of asset quantities.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the asset quantity was successfully set,+ *         or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL,+ *         or \ref CARDANO_ERROR_ELEMENT_NOT_FOUND if either the specified policy ID or asset name does not exist within the multi-asset container.+ *+ * Usage Example:+ * \code{.c}+ * cardano_multi_asset_t* multi_asset = ...; // Assume multi_asset is already initialized+ * cardano_blake2b_hash_t* policy_id = cardano_blake2b_hash_new(...); // Assume policy_id is initialized+ * cardano_asset_name_t* asset = cardano_asset_name_new(...); // Assume asset is initialized+ * int64_t new_quantity = 1000; // Define a new quantity for the asset+ *+ * cardano_error_t result = cardano_multi_asset_set(multi_asset, policy_id, asset, new_quantity);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Asset quantity set successfully.\n");+ *   // Continue processing with the updated asset quantity+ * }+ * else+ * {+ *   printf("Failed to set asset quantity: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Cleanup resources+ * cardano_blake2b_hash_unref(&policy_id);+ * cardano_asset_name_unref(&asset);+ * cardano_multi_asset_unref(&multi_asset);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_set(+  cardano_multi_asset_t*  multi_asset,+  cardano_blake2b_hash_t* policy_id,+  cardano_asset_name_t*   asset,+  int64_t                 value);++/**+ * \brief Retrieves a list of all policy IDs from a multi-asset container.+ *+ * This function extracts all policy IDs (keys) from a given \ref cardano_multi_asset_t object and stores them in a list.+ * Each policy ID corresponds to a distinct set of assets grouped under that policy within the multi-asset structure.+ *+ * \param[in] multi_asset A constant pointer to an initialized \ref cardano_multi_asset_t object from which the policy IDs are to be retrieved.+ *                        The pointer must not be NULL.+ * \param[out] keys On successful execution, this will point to a newly created \ref cardano_policy_id_list_t object containing all the policy IDs.+ *                  The list is dynamically allocated and must be freed by the caller using \ref cardano_policy_id_list_unref when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the policy IDs were successfully retrieved,+ *         or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if the multi_asset pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_multi_asset_t* multi_asset = ...; // Assume multi_asset is already initialized+ * cardano_policy_id_list_t* policy_ids = NULL;+ *+ * cardano_error_t result = cardano_multi_asset_get_keys(multi_asset, &policy_ids);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Policy IDs retrieved successfully.\n");+ *   // Process the list of policy IDs+ *   cardano_policy_id_list_unref(&policy_ids);+ * }+ * else+ * {+ *   printf("Failed to retrieve policy IDs: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_get_keys(+  const cardano_multi_asset_t* multi_asset,+  cardano_policy_id_list_t**   keys);++/**+ * \brief Combines two multi-asset containers by adding the quantities of assets under each policy.+ *+ * This function adds the assets from two \ref cardano_multi_asset_t objects. It combines the quantities+ * of assets under each policy ID. If a policy ID exists in both objects, the assets under that policy are summed.+ * If a policy ID exists in only one of the objects, the assets under that policy are copied to the result.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_multi_asset_t object.+ * \param[in] rhs A constant pointer to the second \ref cardano_multi_asset_t object.+ * \param[out] result On successful execution, this will point to a newly created \ref cardano_multi_asset_t object+ *             that represents the combined result of both input multi-asset containers.+ *             The result is dynamically allocated and must be freed by the caller using \ref cardano_multi_asset_unref+ *             when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the assets were+ *         successfully combined, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_multi_asset_t* lhs = ...; // Assume lhs is already initialized with some assets+ * const cardano_multi_asset_t* rhs = ...; // Assume rhs is also initialized with some assets+ * cardano_multi_asset_t* result = NULL;+ *+ * cardano_error_t add_result = cardano_multi_asset_add(lhs, rhs, &result);+ * if (add_result == CARDANO_SUCCESS)+ * {+ *   // The assets have been successfully combined+ *   // Use the result+ *   cardano_multi_asset_unref(&result);+ * }+ * else+ * {+ *   printf("Failed to combine assets: %s\n", cardano_error_to_string(add_result));+ * }+ *+ * cardano_multi_asset_unref(&lhs);+ * cardano_multi_asset_unref(&rhs);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_add(+  const cardano_multi_asset_t* lhs,+  const cardano_multi_asset_t* rhs,+  cardano_multi_asset_t**      result);++/**+ * \brief Subtracts the quantities of assets under each policy from one multi-asset container to another.+ *+ * This function subtracts the assets from the second \ref cardano_multi_asset_t object (rhs) from the first+ * \ref cardano_multi_asset_t object (lhs). It subtracts the quantities of assets under each policy ID present+ * in both objects. If a policy ID exists only in the rhs, the value is copied as negative, effectively subtracting+ * it from the lhs. If a policy ID exists only in the lhs, the value is copied as is to the result.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_multi_asset_t object from which assets will be subtracted.+ * \param[in] rhs A constant pointer to the second \ref cardano_multi_asset_t object that provides the quantities to subtract.+ * \param[out] result On successful execution, this will point to a newly created \ref cardano_multi_asset_t object+ *             that represents the result of the subtraction.+ *             The result is dynamically allocated and must be freed by the caller using \ref cardano_multi_asset_unref+ *             when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the assets were+ *         successfully subtracted, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_multi_asset_t* lhs = ...; // Assume lhs is already initialized with some assets+ * const cardano_multi_asset_t* rhs = ...; // Assume rhs is also initialized with some assets to subtract+ * cardano_multi_asset_t* result = NULL;+ *+ * cardano_error_t subtract_result = cardano_multi_asset_subtract(lhs, rhs, &result);+ * if (subtract_result == CARDANO_SUCCESS)+ * {+ *   // The assets have been successfully subtracted+ *   // Use the result+ *   cardano_multi_asset_unref(&result);+ * }+ * else+ * {+ *   printf("Failed to subtract assets: %s\n", cardano_error_to_string(subtract_result));+ * }+ *+ * cardano_multi_asset_unref(&lhs);+ * cardano_multi_asset_unref(&rhs);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_subtract(+  const cardano_multi_asset_t* lhs,+  const cardano_multi_asset_t* rhs,+  cardano_multi_asset_t**      result);++/**+ * \brief Retrieves a multi-asset containing only assets with positive quantities from the given multi-asset.+ *+ * This function filters the provided \ref cardano_multi_asset_t object and creates a new multi-asset that includes+ * only those assets whose quantities are positive (greater than zero). Assets with zero or negative quantities are+ * excluded from the result.+ *+ * \param[in] multi_asset A pointer to an initialized \ref cardano_multi_asset_t object from which to extract assets with positive quantities.+ *                The pointer must not be NULL.+ * \param[out] result On successful execution, this will point to a newly created \ref cardano_multi_asset_t object+ *             containing only the assets with positive quantities from the input multi-asset.+ *             The result is dynamically allocated and must be freed by the caller using \ref cardano_multi_asset_unref+ *             when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the operation was+ *         successful, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_multi_asset_t* multi_asset = ...; // Assume lhs is already initialized with some assets+ * cardano_multi_asset_t* positive_assets = NULL;+ *+ * cardano_error_t result = cardano_multi_asset_get_positive(multi_asset, &positive_assets);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // positive_assets now contains only assets with positive quantities+ *   // Use positive_assets as needed+ *+ *   // When done, release the positive_assets+ *   cardano_multi_asset_unref(&positive_assets);+ * }+ * else+ * {+ *   printf("Failed to retrieve positive assets: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_get_positive(+  cardano_multi_asset_t*  multi_asset,+  cardano_multi_asset_t** result);++/**+ * \brief Retrieves a multi-asset containing only assets with negative quantities from the given multi-asset.+ *+ * This function filters the provided \ref cardano_multi_asset_t object and creates a new multi-asset that includes+ * only those assets whose quantities are negative (less than zero). Assets with zero or positive quantities are+ * excluded from the result.+ *+ * \param[in] multi_asset A pointer to an initialized \ref cardano_multi_asset_t object from which to extract assets with negative quantities.+ *                        The pointer must not be NULL.+ * \param[out] result On successful execution, this will point to a newly created \ref cardano_multi_asset_t object+ *             containing only the assets with negative quantities from the input multi-asset.+ *             The result is dynamically allocated and must be freed by the caller using \ref cardano_multi_asset_unref+ *             when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the operation was+ *         successful, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_multi_asset_t* multi_asset = ...; // Assume multi_asset is already initialized with some assets+ * cardano_multi_asset_t* negative_assets = NULL;+ *+ * cardano_error_t result = cardano_multi_asset_get_negative(multi_asset, &negative_assets);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // negative_assets now contains only assets with negative quantities+ *   // Use negative_assets as needed+ *+ *   // When done, release the negative_assets+ *   cardano_multi_asset_unref(&negative_assets);+ * }+ * else+ * {+ *   printf("Failed to retrieve negative assets: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_multi_asset_get_negative(+  cardano_multi_asset_t*  multi_asset,+  cardano_multi_asset_t** result);++/**+ * \brief Compares two multi asset objects for equality.+ *+ * This function compares two multi_asset objects to determine if they are equal.+ *+ * \param[in] lhs Pointer to the first multi asset object.+ * \param[in] rhs Pointer to the second multi asset object.+ *+ * \return \c true if the multi asset objects are equal, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_multi_asset_t* multi_asset1 = NULL;+ * cardano_multi_asset_t* multi_asset2 = NULL;+ *+ * // Assume multi_asset1 and multi_asset2 are initialized properly+ *+ * bool are_equal = cardano_multi_asset_equals(multi_asset1, multi_asset2);+ *+ * if (are_equal)+ * {+ *   printf("The multi_asset objects are equal.\n");+ * }+ * else+ * {+ *   printf("The multi_asset objects are not equal.\n");+ * }+ *+ * // Clean up+ * cardano_multi_asset_unref(&multi_asset1);+ * cardano_multi_asset_unref(&multi_asset2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool+cardano_multi_asset_equals(const cardano_multi_asset_t* lhs, const cardano_multi_asset_t* rhs);++/**+ * \brief Decrements the reference count of a cardano_multi_asset_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_multi_asset_t object+ * by decreasing its reference count. When the reference count reaches zero, the multi_asset is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] multi_asset A pointer to the pointer of the multi_asset object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_multi_asset_t* multi_asset = cardano_multi_asset_new(major, minor);+ *+ * // Perform operations with the multi_asset...+ *+ * cardano_multi_asset_unref(&multi_asset);+ * // At this point, multi_asset is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_multi_asset_unref, the pointer to the \ref cardano_multi_asset_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_multi_asset_unref(cardano_multi_asset_t** multi_asset);++/**+ * \brief Increases the reference count of the cardano_multi_asset_t object.+ *+ * This function is used to manually increment the reference count of an cardano_multi_asset_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_multi_asset_unref.+ *+ * \param multi_asset A pointer to the cardano_multi_asset_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming multi_asset is a previously created multi_asset object+ *+ * cardano_multi_asset_ref(multi_asset);+ *+ * // Now multi_asset can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_multi_asset_ref there is a corresponding+ * call to \ref cardano_multi_asset_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_multi_asset_ref(cardano_multi_asset_t* multi_asset);++/**+ * \brief Retrieves the current reference count of the cardano_multi_asset_t object.+ *+ * This function returns the number of active references to an cardano_multi_asset_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_multi_asset_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param multi_asset A pointer to the cardano_multi_asset_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_multi_asset_t object. If the object+ * is properly managed (i.e., every \ref cardano_multi_asset_ref call is matched with a+ * \ref cardano_multi_asset_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming multi_asset is a previously created multi_asset object+ *+ * size_t ref_count = cardano_multi_asset_refcount(multi_asset);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_multi_asset_refcount(const cardano_multi_asset_t* multi_asset);++/**+ * \brief Sets the last error message for a given cardano_multi_asset_t object.+ *+ * Records an error message in the multi_asset's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] multi_asset A pointer to the \ref cardano_multi_asset_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the multi_asset's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_multi_asset_set_last_error(+  cardano_multi_asset_t* multi_asset,+  const char*            message);++/**+ * \brief Retrieves the last error message recorded for a specific multi_asset.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_multi_asset_set_last_error for the given+ * multi_asset. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] multi_asset A pointer to the \ref cardano_multi_asset_t instance whose last error+ *                   message is to be retrieved. If the multi_asset is NULL, the function+ *                   returns a generic error message indicating the null multi_asset.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified multi_asset. If the multi_asset is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_multi_asset_set_last_error for the same multi_asset, or until+ *       the multi_asset is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_multi_asset_get_last_error(+  const cardano_multi_asset_t* multi_asset);++/**+ * \brief Creates an independent deep copy of a \ref cardano_multi_asset_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_multi_asset_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_multi_asset_deep_clone(const cardano_multi_asset_t* source, cardano_multi_asset_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_MULTI_ASSET_H
+ vendor/include/cardano/assets/policy_id_list.h view
@@ -0,0 +1,333 @@+/**+ * \file policy_id_list.h+ *+ * \author angel.castillo+ * \date   Aug 08, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_POLICY_ID_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_POLICY_ID_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a script hash.+ */+typedef struct cardano_blake2b_hash_t cardano_blake2b_hash_t;++/**+ * \brief Represents a list of reward address.+ */+typedef struct cardano_policy_id_list_t cardano_policy_id_list_t;++/**+ * \brief Creates and initializes a new instance of a policy_id_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_policy_id_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] policy_id_list On successful initialization, this will point to a newly created+ *             \ref cardano_policy_id_list_t object. This object represents a "strong reference"+ *             to the policy_id_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the policy_id_list is no longer needed, the caller must release it+ *             by calling \ref cardano_policy_id_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the policy_id_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_policy_id_list_t* policy_id_list = NULL;+ *+ * // Attempt to create a new policy_id_list+ * cardano_error_t result = cardano_policy_id_list_new(&policy_id_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the policy_id_list+ *+ *   // Once done, ensure to clean up and release the policy_id_list+ *   cardano_policy_id_list_unref(&policy_id_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_policy_id_list_new(cardano_policy_id_list_t** policy_id_list);++/**+ * \brief Retrieves the length of a policy id list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_policy_id_list_t object.+ *+ * \param[in] policy_id_list A constant pointer to the \ref cardano_policy_id_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the policy_id_list. Return 0 if the policy_id_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_policy_id_list_t* policy_id_list = cardano_policy_id_list_new();+ *+ * // Populate policy_id_list with elements+ *+ * size_t length = cardano_policy_id_list_get_length(policy_id_list);+ * printf("Length of the policy_id_list: %zu\n", length);+ *+ * // Clean up the policy_id_list object once done+ * cardano_policy_id_list_unref(&policy_id_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_policy_id_list_get_length(const cardano_policy_id_list_t* policy_id_list);++/**+ * \brief Retrieves an element from a policy id list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_policy_id_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] policy_id_list A constant pointer to the \ref cardano_policy_id_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the policy id list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_blake2b_hash_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_blake2b_hash_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_policy_id_list_t* policy_id_list = cardano_policy_id_list_new();+ *+ * // Populate policy_id_list with elements+ *+ * cardano_blake2b_hash_t* element = NULL;+ * cardano_error_t result = cardano_policy_id_list_get(policy_id_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_blake2b_hash_unref(&element);+ * }+ *+ * // Clean up the policy_id_list object once done+ * cardano_policy_id_list_unref(&policy_id_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_policy_id_list_get(const cardano_policy_id_list_t* policy_id_list, size_t index, cardano_blake2b_hash_t** element);++/**+ * \brief Adds an element to a policy id list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_policy_id_list_t object.+ *+ * \param[in] policy_id_list A constant pointer to the \ref cardano_policy_id_list_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_blake2b_hash_t object that is to be added to the policy_id_list.+ *                    The element will be referenced by the policy_id_list after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the policy_id_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_policy_id_list_t* policy_id_list = cardano_policy_id_list_new();+ *+ * // Create and initialize a new reward address element+ * cardano_blake2b_hash_t* element = { ... };+ *+ * // Add the element to the policy_id_list+ * cardano_error_t result = cardano_policy_id_list_add(policy_id_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the policy_id_list object once done+ * cardano_policy_id_list_unref(&policy_id_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_policy_id_list_add(cardano_policy_id_list_t* policy_id_list, cardano_blake2b_hash_t* element);++/**+ * \brief Decrements the reference count of a policy_id_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_policy_id_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the policy_id_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] policy_id_list A pointer to the pointer of the policy_id_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_policy_id_list_t* policy_id_list = cardano_policy_id_list_new();+ *+ * // Perform operations with the policy_id_list...+ *+ * cardano_policy_id_list_unref(&policy_id_list);+ * // At this point, policy_id_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_policy_id_list_unref, the pointer to the \ref cardano_policy_id_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_policy_id_list_unref(cardano_policy_id_list_t** policy_id_list);++/**+ * \brief Increases the reference count of the cardano_policy_id_list_t object.+ *+ * This function is used to manually increment the reference count of a policy_id_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_policy_id_list_unref.+ *+ * \param policy_id_list A pointer to the policy_id_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming policy_id_list is a previously created policy_id_list object+ *+ * cardano_policy_id_list_ref(policy_id_list);+ *+ * // Now policy_id_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_policy_id_list_ref there is a corresponding+ * call to \ref cardano_policy_id_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_policy_id_list_ref(cardano_policy_id_list_t* policy_id_list);++/**+ * \brief Retrieves the current reference count of the cardano_policy_id_list_t object.+ *+ * This function returns the number of active references to a policy_id_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_policy_id_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param policy_id_list A pointer to the policy_id_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified policy_id_list object. If the object+ * is properly managed (i.e., every \ref cardano_policy_id_list_ref call is matched with a+ * \ref cardano_policy_id_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming policy_id_list is a previously created policy_id_list object+ *+ * size_t ref_count = cardano_policy_id_list_refcount(policy_id_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_policy_id_list_refcount(const cardano_policy_id_list_t* policy_id_list);++/**+ * \brief Sets the last error message for a given policy_id_list object.+ *+ * Records an error message in the policy_id_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] policy_id_list A pointer to the \ref cardano_policy_id_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the policy_id_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_policy_id_list_set_last_error(cardano_policy_id_list_t* policy_id_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific policy_id_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_policy_id_list_set_last_error for the given+ * policy_id_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] policy_id_list A pointer to the \ref cardano_policy_id_list_t instance whose last error+ *                   message is to be retrieved. If the policy_id_list is NULL, the function+ *                   returns a generic error message indicating the null policy_id_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified policy_id_list. If the policy_id_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_policy_id_list_set_last_error for the same policy_id_list, or until+ *       the policy_id_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_policy_id_list_get_last_error(const cardano_policy_id_list_t* policy_id_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_policy_id_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_policy_id_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_policy_id_list_deep_clone(const cardano_policy_id_list_t* source, cardano_policy_id_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_POLICY_ID_LIST_H
+ vendor/include/cardano/auxiliary_data/auxiliary_data.h view
@@ -0,0 +1,953 @@+/**+ * \file auxiliary_data.h+ *+ * \author angel.castillo+ * \date   Sep 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_AUXILIARY_DATA_H+#define BIGLUP_LABS_INCLUDE_CARDANO_AUXILIARY_DATA_H++/* INCLUDES ******************************************************************/++#include <cardano/auxiliary_data/plutus_v1_script_list.h>+#include <cardano/auxiliary_data/plutus_v2_script_list.h>+#include <cardano/auxiliary_data/plutus_v3_script_list.h>+#include <cardano/auxiliary_data/plutus_v4_script_list.h>+#include <cardano/auxiliary_data/transaction_metadata.h>+#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/scripts/native_scripts/native_script_list.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Auxiliary Data encapsulate certain optional information that can be attached+ * to a transaction. This data includes transaction metadata and scripts.+ *+ * The Auxiliary Data is hashed and referenced in the transaction body.+ */+typedef struct cardano_auxiliary_data_t cardano_auxiliary_data_t;++/**+ * \brief Creates a new, empty auxiliary data object.+ *+ * This function allocates and initializes a new \ref cardano_auxiliary_data_t object, which can be used to+ * hold transaction metadata or scripts that are included as auxiliary data in a Cardano transaction.+ *+ * \param[out] auxiliary_data A pointer to a location where the newly created \ref cardano_auxiliary_data_t+ *                            object will be stored. This parameter must not be NULL. On success, \p *auxiliary_data+ *                            will point to the newly created auxiliary data object.+ *+ * \return \ref CARDANO_SUCCESS if the auxiliary data object was successfully created, or an appropriate+ *         error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if the+ *         \p auxiliary_data pointer is NULL, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if memory allocation failed.+ *+ * \note The caller is responsible for managing the lifecycle of the created auxiliary data object.+ *       When the auxiliary data object is no longer needed, the caller must release it by calling+ *       \ref cardano_auxiliary_data_unref.+ *+ * Usage Example:+ * \code{.c}+ *+ * cardano_auxiliary_data_t* auxiliary_data = NULL;+ * cardano_error_t result = cardano_auxiliary_data_new(&transaction_output);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the auxiliary data+ *   // Free resources when done+ *   cardano_auxiliary_data_unref(&transaction_output);+ * }+ * else+ * {+ *   printf("Failed to create the auxiliary data: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_new(cardano_auxiliary_data_t** auxiliary_data);++/**+ * \brief Creates a \ref cardano_auxiliary_data_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_auxiliary_data_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a auxiliary_data.+ *+ * Tagged auxiliary-data maps must not contain duplicate field keys.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] auxiliary_data A pointer to a pointer of \ref cardano_auxiliary_data_t that will be set to the address+ *                        of the newly created auxiliary_data object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the auxiliary data were successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_auxiliary_data_t object by calling+ *       \ref cardano_auxiliary_data_unref when it is no longer needed.+ *+ * \remark In Cardano, transactions are encoded in CBOR, but CBOR allows multiple valid ways to encode the same data. The Cardano blockchain+ *         does not enforce a canonical transaction representation, meaning that if you decode a transaction from CBOR and then re-encode it,+ *         the resulting encoding could be different. This would change the auxiliary data hash and invalidate any existing signatures.+ *         To prevent this, when a transaction auxiliary data object is created using \ref cardano_auxiliary_data_from_cbor, it caches the original+ *         CBOR representation internally. When \ref cardano_auxiliary_data_to_cbor is called, it will output the cached CBOR.+ *         If the cached CBOR representation is not needed, the client can call \ref cardano_auxiliary_data_clear_cbor_cache after the object has been created.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_auxiliary_data_t* auxiliary_data = NULL;+ *+ * cardano_error_t result = cardano_auxiliary_data_from_cbor(reader, &auxiliary_data);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the auxiliary_data+ *+ *   // Once done, ensure to clean up and release the auxiliary_data+ *   cardano_auxiliary_data_unref(&auxiliary_data);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode auxiliary_data: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_from_cbor(cardano_cbor_reader_t* reader, cardano_auxiliary_data_t** auxiliary_data);++/**+ * \brief Serializes auxiliary data into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_auxiliary_data_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] auxiliary_data A constant pointer to the \ref cardano_auxiliary_data_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p auxiliary_data or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * \remark If the auxiliary data object was created by \ref cardano_auxiliary_data_from_cbor, the original CBOR encoding+ *         will be cached and reused by this function to prevent round-trip encoding issues that can change the auxiliary data hash+ *         and invalidate signatures.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_auxiliary_data_to_cbor(auxiliary_data, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_auxiliary_data_unref(&auxiliary_data);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_auxiliary_data_to_cbor(+  const cardano_auxiliary_data_t* auxiliary_data,+  cardano_cbor_writer_t*          writer);++/**+ * \brief Serializes auxiliary data to CIP-116 JSON.+ *+ * This function writes a JSON object representing the auxiliary data using the+ * CIP-116 shapes for each component:+ *+ * - **metadata**: an array of `{ "key": "<decimal label>", "value": <TransactionMetadatum> }`+ *   entries, where each value is encoded via \ref cardano_metadatum_to_cip116_json.+ * - **native_scripts**: an array of CIP-116 NativeScript objects, encoded via+ *   \ref cardano_native_script_list_to_cip116_json.+ * - **plutus_scripts**: an array of Plutus script objects, each shaped as+ *   `{ "language": "plutus_v1", "bytes": "<hex>" }` for Plutus v1 scripts+ *   (encoded via \ref cardano_plutus_v1_script_list_to_cip116_json).+ *+ * The function writes the enclosing `{}` object. Properties that are not present+ * (i.e., corresponding list or map is NULL or empty) are omitted.+ *+ * \param[in] auxiliary_data A valid pointer to a \ref cardano_auxiliary_data_t instance.+ * \param[in] writer         A valid pointer to a \ref cardano_json_writer_t positioned+ *                           where a JSON value is expected.+ *+ * \return \ref CARDANO_SUCCESS on success; an appropriate error code otherwise (e.g.,+ *         \ref CARDANO_ERROR_POINTER_IS_NULL for invalid arguments, or a downstream+ *         serialization error).+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_to_cip116_json(+  const cardano_auxiliary_data_t* auxiliary_data,+  cardano_json_writer_t*          writer);++/**+ * \brief Retrieves the transaction metadata from an auxiliary data object.+ *+ * This function extracts the transaction metadata from a given \ref cardano_auxiliary_data_t object.+ *+ * \param[in] auxiliary_data A pointer to an initialized \ref cardano_auxiliary_data_t object from which to retrieve the transaction metadata.+ *                           This parameter must not be NULL.+ *+ * \return A pointer to a \ref cardano_transaction_metadata_t object containing the transaction metadata.+ *         If the auxiliary data does not contain any transaction metadata, the function returns \c NULL.+ *         The returned object is a new reference, and the caller is responsible for managing its lifecycle.+ *         Specifically, the caller must release it by calling \ref cardano_transaction_metadata_unref when it is no longer needed.+ *+ * \note The transaction metadata is optional in an auxiliary data object. Always check the returned pointer for \c NULL before using it.+ *+ * Usage Example:+ * \code{.c}+ * // Assume auxiliary_data is already initialized and may contain metadata+ * cardano_auxiliary_data_t* auxiliary_data = ...;+ *+ * // Retrieve the transaction metadata+ * cardano_transaction_metadata_t* metadata = cardano_auxiliary_data_get_transaction_metadata(auxiliary_data);+ *+ * if (metadata != NULL)+ * {+ *   // Process the metadata+ *   // Release the metadata object when done+ *   cardano_transaction_metadata_unref(&metadata);+ * }+ * else+ * {+ *   printf("No transaction metadata present in the auxiliary data.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_transaction_metadata_t* cardano_auxiliary_data_get_transaction_metadata(cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Sets or unsets the transaction metadata for an auxiliary data object.+ *+ * This function assigns the specified transaction metadata to a given \ref cardano_auxiliary_data_t object.+ * If the \p metadata parameter is `NULL`, it will remove any existing transaction metadata from the auxiliary data.+ *+ * \param[in,out] auxiliary_data A pointer to an initialized \ref cardano_auxiliary_data_t object+ *                               to which the transaction metadata will be set or unset. This parameter must not be `NULL`.+ * \param[in] metadata A pointer to an initialized \ref cardano_transaction_metadata_t object containing the metadata+ *                     to be associated with the auxiliary data, or `NULL` to unset the metadata.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the metadata+ *         was successfully set or unset, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p auxiliary_data pointer is `NULL`.+ *+ * \note If \p metadata is not `NULL`, this function increases the reference count of the \p metadata object, meaning that the caller retains+ *       ownership of their reference and is responsible for managing its lifecycle. The caller must ensure that+ *       the \ref cardano_transaction_metadata_unref function is called when the \p metadata object is no longer needed.+ *       If \p metadata is `NULL`, any existing metadata in the auxiliary data will be removed.+ *+ * Usage Example:+ * \code{.c}+ * // Assume auxiliary_data and metadata are already initialized+ * cardano_auxiliary_data_t* auxiliary_data = ...;+ * cardano_transaction_metadata_t* metadata = ...;+ *+ * // Set the transaction metadata for the auxiliary data object+ * cardano_error_t result = cardano_auxiliary_data_set_transaction_metadata(auxiliary_data, metadata);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Transaction metadata successfully set.\n");+ * }+ * else+ * {+ *   printf("Failed to set transaction metadata: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Unset the transaction metadata by passing NULL+ * result = cardano_auxiliary_data_set_transaction_metadata(auxiliary_data, NULL);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Transaction metadata successfully unset.\n");+ * }+ * else+ * {+ *   printf("Failed to unset transaction metadata: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_set_transaction_metadata(cardano_auxiliary_data_t* auxiliary_data, cardano_transaction_metadata_t* metadata);++/**+ * \brief Retrieves the list of native scripts from auxiliary data.+ *+ * This function extracts and returns a list of native scripts from the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in] auxiliary_data A pointer of an initialized \ref cardano_auxiliary_data_t object from which+ *                           the native scripts will be retrieved. This parameter must not be `NULL`.+ *+ * \return A pointer to a \ref cardano_native_script_list_t object representing the list of native scripts. If the auxiliary data+ *         does not contain any native scripts, this function returns `NULL`. The returned list is a new reference,+ *         and the caller is responsible for managing its lifecycle. Specifically, the caller must release the list by calling+ *         \ref cardano_native_script_list_unref when it is no longer needed.+ *+ * \note The returned native script list, if present, is a new reference, meaning the caller must manage the memory for this object.+ *       If the auxiliary data contains no native scripts, the function will return `NULL`, and the caller should handle this case appropriately.+ *+ * \return Returns \ref CARDANO_SUCCESS if the native scripts were successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_native_script_list_t* native_scripts = cardano_auxiliary_data_get_native_scripts(auxiliary_data);+ *+ * if (native_scripts != NULL)+ * {+ *   // Use the native scripts+ *+ *   // Ensure to release the native script list when done+ *   cardano_native_script_list_unref(&native_scripts);+ * }+ * else+ * {+ *   printf("No native scripts found in auxiliary data.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_native_script_list_t* cardano_auxiliary_data_get_native_scripts(cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Sets the list of native scripts in auxiliary data.+ *+ * This function assigns a list of native scripts to the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in,out] auxiliary_data A pointer to an initialized \ref cardano_auxiliary_data_t object where the native scripts will be set.+ * \param[in] scripts A pointer to a \ref cardano_native_script_list_t object representing the list of native scripts to be added.+ *                    This parameter can be `NULL` to unset the native scripts in the auxiliary data.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the native scripts were+ *         successfully set, or an appropriate error code if an error occurred, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any+ *         required pointers are `NULL`.+ *+ * \note If the `scripts` parameter is `NULL`, any existing native scripts in the auxiliary data will be removed.+ *       The caller is responsible for managing the memory for the `scripts` object; this function will increment+ *       the reference count of the `scripts` object if provided.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_native_script_list_t* native_scripts = ...; // Assume native_scripts is initialized+ *+ * cardano_error_t result = cardano_auxiliary_data_set_native_scripts(auxiliary_data, native_scripts);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Native scripts successfully set in auxiliary data.\n");+ * }+ * else+ * {+ *   printf("Failed to set native scripts: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up resources when done+ * cardano_native_script_list_unref(&native_scripts);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_set_native_scripts(cardano_auxiliary_data_t* auxiliary_data, cardano_native_script_list_t* scripts);++/**+ * \brief Retrieves the list of plutus v1 scripts from auxiliary data.+ *+ * This function extracts and returns a list of plutus v1 scripts from the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in] auxiliary_data A pointer of an initialized \ref cardano_auxiliary_data_t object from which+ *                           the plutus v1 scripts will be retrieved. This parameter must not be `NULL`.+ *+ * \return A pointer to a \ref cardano_plutus_v1_script_list_t object representing the list of plutus v1 scripts. If the auxiliary data+ *         does not contain any plutus v1 scripts, this function returns `NULL`. The returned list is a new reference,+ *         and the caller is responsible for managing its lifecycle. Specifically, the caller must release the list by calling+ *         \ref cardano_plutus_v1_script_list_unref when it is no longer needed.+ *+ * \note The returned plutus v1 script list, if present, is a new reference, meaning the caller must manage the memory for this object.+ *       If the auxiliary data contains no plutus v1 scripts, the function will return `NULL`, and the caller should handle this case appropriately.+ *+ * \return Returns \ref CARDANO_SUCCESS if the plutus v1 scripts were successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_plutus_v1_script_list_t* plutus_v1_scripts = cardano_auxiliary_data_get_plutus_v1_scripts(auxiliary_data);+ *+ * if (plutus_v1_scripts != NULL)+ * {+ *   // Use the plutus v1 scripts+ *+ *   // Ensure to release the plutus v1 script list when done+ *   cardano_plutus_v1_script_list_unref(&plutus_v1_scripts);+ * }+ * else+ * {+ *   printf("No plutus v1 scripts found in auxiliary data.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_plutus_v1_script_list_t* cardano_auxiliary_data_get_plutus_v1_scripts(cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Sets the list of plutus v1 scripts in auxiliary data.+ *+ * This function assigns a list of plutus v1 scripts to the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in,out] auxiliary_data A pointer to an initialized \ref cardano_auxiliary_data_t object where the plutus v1 scripts will be set.+ * \param[in] scripts A pointer to a \ref cardano_plutus_v1_script_list_t object representing the list of plutus v1 scripts to be added.+ *                    This parameter can be `NULL` to unset the plutus v1 scripts in the auxiliary data.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the plutus v1 scripts were+ *         successfully set, or an appropriate error code if an error occurred, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any+ *         required pointers are `NULL`.+ *+ * \note If the `scripts` parameter is `NULL`, any existing plutus v1 scripts in the auxiliary data will be removed.+ *       The caller is responsible for managing the memory for the `scripts` object; this function will increment+ *       the reference count of the `scripts` object if provided.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_plutus_v1_script_list_t* plutus_v1_scripts = ...; // Assume plutus_v1_scripts is initialized+ *+ * cardano_error_t result = cardano_auxiliary_data_set_plutus_v1_scripts(auxiliary_data, plutus_v1_scripts);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Native scripts successfully set in auxiliary data.\n");+ * }+ * else+ * {+ *   printf("Failed to set plutus v1 scripts: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up resources when done+ * cardano_plutus_v1_script_list_unref(&plutus_v1_scripts);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_set_plutus_v1_scripts(cardano_auxiliary_data_t* auxiliary_data, cardano_plutus_v1_script_list_t* scripts);++/**+ * \brief Retrieves the list of plutus v2 scripts from auxiliary data.+ *+ * This function extracts and returns a list of plutus v2 scripts from the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in] auxiliary_data A pointer of an initialized \ref cardano_auxiliary_data_t object from which+ *                           the plutus v2 scripts will be retrieved. This parameter must not be `NULL`.+ *+ * \return A pointer to a \ref cardano_plutus_v2_script_list_t object representing the list of plutus v2 scripts. If the auxiliary data+ *         does not contain any plutus v2 scripts, this function returns `NULL`. The returned list is a new reference,+ *         and the caller is responsible for managing its lifecycle. Specifically, the caller must release the list by calling+ *         \ref cardano_plutus_v2_script_list_unref when it is no longer needed.+ *+ * \note The returned plutus v2 script list, if present, is a new reference, meaning the caller must manage the memory for this object.+ *       If the auxiliary data contains no plutus v2 scripts, the function will return `NULL`, and the caller should handle this case appropriately.+ *+ * \return Returns \ref CARDANO_SUCCESS if the plutus v2 scripts were successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_plutus_v2_script_list_t* plutus_v2_scripts = cardano_auxiliary_data_get_plutus_v2_scripts(auxiliary_data);+ *+ * if (plutus_v2_scripts != NULL)+ * {+ *   // Use the plutus v2 scripts+ *+ *   // Ensure to release the plutus v2 script list when done+ *   cardano_plutus_v2_script_list_unref(&plutus_v2_scripts);+ * }+ * else+ * {+ *   printf("No plutus v2 scripts found in auxiliary data.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_plutus_v2_script_list_t* cardano_auxiliary_data_get_plutus_v2_scripts(cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Sets the list of plutus v2 scripts in auxiliary data.+ *+ * This function assigns a list of plutus v2 scripts to the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in,out] auxiliary_data A pointer to an initialized \ref cardano_auxiliary_data_t object where the plutus v2 scripts will be set.+ * \param[in] scripts A pointer to a \ref cardano_plutus_v2_script_list_t object representing the list of plutus v2 scripts to be added.+ *                    This parameter can be `NULL` to unset the plutus v2 scripts in the auxiliary data.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the plutus v2 scripts were+ *         successfully set, or an appropriate error code if an error occurred, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any+ *         required pointers are `NULL`.+ *+ * \note If the `scripts` parameter is `NULL`, any existing plutus v2 scripts in the auxiliary data will be removed.+ *       The caller is responsible for managing the memory for the `scripts` object; this function will increment+ *       the reference count of the `scripts` object if provided.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_plutus_v2_script_list_t* plutus_v2_scripts = ...; // Assume plutus_v2_scripts is initialized+ *+ * cardano_error_t result = cardano_auxiliary_data_set_plutus_v2_scripts(auxiliary_data, plutus_v2_scripts);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Native scripts successfully set in auxiliary data.\n");+ * }+ * else+ * {+ *   printf("Failed to set plutus v2 scripts: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up resources when done+ * cardano_plutus_v2_script_list_unref(&plutus_v2_scripts);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_set_plutus_v2_scripts(cardano_auxiliary_data_t* auxiliary_data, cardano_plutus_v2_script_list_t* scripts);++/**+ * \brief Retrieves the list of plutus v3 scripts from auxiliary data.+ *+ * This function extracts and returns a list of plutus v3 scripts from the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in] auxiliary_data A pointer of an initialized \ref cardano_auxiliary_data_t object from which+ *                           the plutus v3 scripts will be retrieved. This parameter must not be `NULL`.+ *+ * \return A pointer to a \ref cardano_plutus_v3_script_list_t object representing the list of plutus v3 scripts. If the auxiliary data+ *         does not contain any plutus v3 scripts, this function returns `NULL`. The returned list is a new reference,+ *         and the caller is responsible for managing its lifecycle. Specifically, the caller must release the list by calling+ *         \ref cardano_plutus_v3_script_list_unref when it is no longer needed.+ *+ * \note The returned plutus v3 script list, if present, is a new reference, meaning the caller must manage the memory for this object.+ *       If the auxiliary data contains no plutus v3 scripts, the function will return `NULL`, and the caller should handle this case appropriately.+ *+ * \return Returns \ref CARDANO_SUCCESS if the plutus v3 scripts were successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_plutus_v3_script_list_t* plutus_v3_scripts = cardano_auxiliary_data_get_plutus_v3_scripts(auxiliary_data);+ *+ * if (plutus_v3_scripts != NULL)+ * {+ *   // Use the plutus v3 scripts+ *+ *   // Ensure to release the plutus v3 script list when done+ *   cardano_plutus_v3_script_list_unref(&plutus_v3_scripts);+ * }+ * else+ * {+ *   printf("No plutus v3 scripts found in auxiliary data.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_plutus_v3_script_list_t* cardano_auxiliary_data_get_plutus_v3_scripts(cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Sets the list of plutus v3 scripts in auxiliary data.+ *+ * This function assigns a list of plutus v3 scripts to the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in,out] auxiliary_data A pointer to an initialized \ref cardano_auxiliary_data_t object where the plutus v3 scripts will be set.+ * \param[in] scripts A pointer to a \ref cardano_plutus_v3_script_list_t object representing the list of plutus v3 scripts to be added.+ *                    This parameter can be `NULL` to unset the plutus v3 scripts in the auxiliary data.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the plutus v3 scripts were+ *         successfully set, or an appropriate error code if an error occurred, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any+ *         required pointers are `NULL`.+ *+ * \note If the `scripts` parameter is `NULL`, any existing plutus v3 scripts in the auxiliary data will be removed.+ *       The caller is responsible for managing the memory for the `scripts` object; this function will increment+ *       the reference count of the `scripts` object if provided.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_plutus_v3_script_list_t* plutus_v3_scripts = ...; // Assume plutus_v3_scripts is initialized+ *+ * cardano_error_t result = cardano_auxiliary_data_set_plutus_v3_scripts(auxiliary_data, plutus_v3_scripts);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Native scripts successfully set in auxiliary data.\n");+ * }+ * else+ * {+ *   printf("Failed to set plutus v3 scripts: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up resources when done+ * cardano_plutus_v3_script_list_unref(&plutus_v3_scripts);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_set_plutus_v3_scripts(cardano_auxiliary_data_t* auxiliary_data, cardano_plutus_v3_script_list_t* scripts);++/**+ * \brief Retrieves the list of plutus v4 scripts from auxiliary data.+ *+ * This function extracts and returns a list of plutus v4 scripts from the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in] auxiliary_data A pointer of an initialized \ref cardano_auxiliary_data_t object from which+ *                           the plutus v4 scripts will be retrieved. This parameter must not be `NULL`.+ *+ * \return A pointer to a \ref cardano_plutus_v4_script_list_t object representing the list of plutus v4 scripts. If the auxiliary data+ *         does not contain any plutus v4 scripts, this function returns `NULL`. The returned list is a new reference,+ *         and the caller is responsible for managing its lifecycle. Specifically, the caller must release the list by calling+ *         \ref cardano_plutus_v4_script_list_unref when it is no longer needed.+ *+ * \note The returned plutus v4 script list, if present, is a new reference, meaning the caller must manage the memory for this object.+ *       If the auxiliary data contains no plutus v4 scripts, the function will return `NULL`, and the caller should handle this case appropriately.+ *+ * \return Returns \ref CARDANO_SUCCESS if the plutus v4 scripts were successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_plutus_v4_script_list_t* plutus_v4_scripts = cardano_auxiliary_data_get_plutus_v4_scripts(auxiliary_data);+ *+ * if (plutus_v4_scripts != NULL)+ * {+ *   // Use the plutus v4 scripts+ *+ *   // Ensure to release the plutus v4 script list when done+ *   cardano_plutus_v4_script_list_unref(&plutus_v4_scripts);+ * }+ * else+ * {+ *   printf("No plutus v4 scripts found in auxiliary data.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_plutus_v4_script_list_t* cardano_auxiliary_data_get_plutus_v4_scripts(cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Sets the list of plutus v4 scripts in auxiliary data.+ *+ * This function assigns a list of plutus v4 scripts to the specified \ref cardano_auxiliary_data_t object.+ *+ * \param[in,out] auxiliary_data A pointer to an initialized \ref cardano_auxiliary_data_t object where the plutus v4 scripts will be set.+ * \param[in] scripts A pointer to a \ref cardano_plutus_v4_script_list_t object representing the list of plutus v4 scripts to be added.+ *                    This parameter can be `NULL` to unset the plutus v4 scripts in the auxiliary data.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the plutus v4 scripts were+ *         successfully set, or an appropriate error code if an error occurred, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any+ *         required pointers are `NULL`.+ *+ * \note If the `scripts` parameter is `NULL`, any existing plutus v4 scripts in the auxiliary data will be removed.+ *       The caller is responsible for managing the memory for the `scripts` object; this function will increment+ *       the reference count of the `scripts` object if provided.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume initialized+ * cardano_plutus_v4_script_list_t* plutus_v4_scripts = ...; // Assume plutus_v4_scripts is initialized+ *+ * cardano_error_t result = cardano_auxiliary_data_set_plutus_v4_scripts(auxiliary_data, plutus_v4_scripts);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Native scripts successfully set in auxiliary data.\n");+ * }+ * else+ * {+ *   printf("Failed to set plutus v4 scripts: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up resources when done+ * cardano_plutus_v4_script_list_unref(&plutus_v4_scripts);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_set_plutus_v4_scripts(cardano_auxiliary_data_t* auxiliary_data, cardano_plutus_v4_script_list_t* scripts);++/**+ * \brief Retrieves the hash of a auxiliary data.+ *+ * This function computes and returns the hash of the given \ref cardano_auxiliary_data_t object. The hash is a unique identifier for the auxiliary data.+ *+ * \param[in] auxiliary_data A pointer to an initialized \ref cardano_auxiliary_data_t object. The object must be valid and not NULL.+ *+ * \return A pointer to a \ref cardano_blake2b_hash_t object representing the auxiliary data hash. The returned object is a new reference, and+ *         the caller is responsible for releasing it by calling \ref cardano_blake2b_hash_unref when it is no longer needed.+ *         If the input is NULL, the function will return NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = ...; // Assume auxiliary_data is already initialized+ * cardano_blake2b_hash_t* tx_body_hash = cardano_auxiliary_data_get_hash(auxiliary_data);+ *+ * if (tx_body_hash != NULL)+ * {+ *   // Use the auxiliary data hash for signing or verification+ *+ *   // Clean up when done+ *   cardano_blake2b_hash_unref(&tx_body_hash);+ * }+ * else+ * {+ *   printf("Failed to retrieve the auxiliary data hash.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_auxiliary_data_get_hash(cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Clears the cached CBOR representation from a auxiliary data.+ *+ * This function removes the internally cached CBOR data from a \ref cardano_auxiliary_data_t object.+ * It is useful when you have modified the auxiliary data after it was created from CBOR using+ * \ref cardano_auxiliary_data_from_cbor and you want to ensure that the next serialization reflects+ * the current state of the auxiliary data, rather than using the original cached CBOR.+ *+ * \param[in,out] auxiliary_data A pointer to an initialized \ref cardano_auxiliary_data_t object+ *                                 from which the CBOR cache will be cleared.+ *+ * \warning Clearing the CBOR cache may change the binary representation of the auxiliary data when+ *          serialized, which can alter the auxiliary data hash and invalidate any existing signatures.+ *          Use this function with caution, especially if the transaction has already been signed or+ *          if preserving the exact CBOR encoding is important for your application.+ *+ * Usage Example:+ * \code{.c}+ * // Assume auxiliary_data was created using cardano_auxiliary_data_from_cbor+ * cardano_auxiliary_data_t* auxiliary_data = ...;+ *+ * // Modify the auxiliary data as needed+ *+ * // Clear the CBOR cache to ensure serialization uses the updated auxiliary data+ * cardano_auxiliary_data_clear_cbor_cache(auxiliary_data);+ *+ * // Serialize the auxiliary data to CBOR+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * result = cardano_auxiliary_data_to_cbor(auxiliary_data, writer);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Process the CBOR data as needed+ * }+ * else+ * {+ *   const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *   printf("Serialization failed: %s\n", error_message);+ * }+ *+ * // Clean up resources+ * cardano_cbor_writer_unref(&writer);+ * cardano_auxiliary_data_unref(&auxiliary_data);+ * \endcode+ */+CARDANO_EXPORT void cardano_auxiliary_data_clear_cbor_cache(cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Decrements the reference count of a cardano_auxiliary_data_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_auxiliary_data_t object+ * by decreasing its reference count. When the reference count reaches zero, the auxiliary_data is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] auxiliary_data A pointer to the pointer of the auxiliary_data object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auxiliary_data_t* auxiliary_data = cardano_auxiliary_data_new(major, minor);+ *+ * // Perform operations with the auxiliary_data...+ *+ * cardano_auxiliary_data_unref(&auxiliary_data);+ * // At this point, auxiliary_data is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_auxiliary_data_unref, the pointer to the \ref cardano_auxiliary_data_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_auxiliary_data_unref(cardano_auxiliary_data_t** auxiliary_data);++/**+ * \brief Increases the reference count of the cardano_auxiliary_data_t object.+ *+ * This function is used to manually increment the reference count of an cardano_auxiliary_data_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_auxiliary_data_unref.+ *+ * \param auxiliary_data A pointer to the cardano_auxiliary_data_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming auxiliary_data is a previously created auxiliary_data object+ *+ * cardano_auxiliary_data_ref(auxiliary_data);+ *+ * // Now auxiliary_data can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_auxiliary_data_ref there is a corresponding+ * call to \ref cardano_auxiliary_data_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_auxiliary_data_ref(cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Retrieves the current reference count of the cardano_auxiliary_data_t object.+ *+ * This function returns the number of active references to an cardano_auxiliary_data_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_auxiliary_data_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param auxiliary_data A pointer to the cardano_auxiliary_data_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_auxiliary_data_t object. If the object+ * is properly managed (i.e., every \ref cardano_auxiliary_data_ref call is matched with a+ * \ref cardano_auxiliary_data_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming auxiliary_data is a previously created auxiliary_data object+ *+ * size_t ref_count = cardano_auxiliary_data_refcount(auxiliary_data);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_auxiliary_data_refcount(const cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Sets the last error message for a given cardano_auxiliary_data_t object.+ *+ * Records an error message in the auxiliary_data's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] auxiliary_data A pointer to the \ref cardano_auxiliary_data_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the auxiliary_data's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_auxiliary_data_set_last_error(+  cardano_auxiliary_data_t* auxiliary_data,+  const char*               message);++/**+ * \brief Retrieves the last error message recorded for a specific auxiliary_data.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_auxiliary_data_set_last_error for the given+ * auxiliary_data. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] auxiliary_data A pointer to the \ref cardano_auxiliary_data_t instance whose last error+ *                   message is to be retrieved. If the auxiliary_data is NULL, the function+ *                   returns a generic error message indicating the null auxiliary_data.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified auxiliary_data. If the auxiliary_data is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_auxiliary_data_set_last_error for the same auxiliary_data, or until+ *       the auxiliary_data is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_auxiliary_data_get_last_error(+  const cardano_auxiliary_data_t* auxiliary_data);++/**+ * \brief Creates an independent deep copy of a \ref cardano_auxiliary_data_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_auxiliary_data_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_auxiliary_data_deep_clone(const cardano_auxiliary_data_t* source, cardano_auxiliary_data_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_AUXILIARY_DATA_H
+ vendor/include/cardano/auxiliary_data/metadatum.h view
@@ -0,0 +1,1227 @@+/**+ * \file metadatum.h+ *+ * \author angel.castillo+ * \date   Sep 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_H+#define BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_H++/* INCLUDES ******************************************************************/++#include <cardano/auxiliary_data/metadatum_kind.h>+#include <cardano/buffer.h>+#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/bigint.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a map of metadatum.+ */+typedef struct cardano_metadatum_map_t cardano_metadatum_map_t;++/**+ * \brief Represents a list of metadatum.+ */+typedef struct cardano_metadatum_list_t cardano_metadatum_list_t;++/**+ * \brief A type corresponding to the metadatum type.+ *+ * Use this type to build metadata structures that you want to be representable on-chain.+ */+typedef struct cardano_metadatum_t cardano_metadatum_t;++/**+ * \brief Creates and initializes a new instance of a metadatum from a metadatum_map.+ *+ * This function creates and initializes a new instance of a \ref cardano_metadatum_t object+ * from a given \ref cardano_metadatum_map_t object. It essentially converts a metadatum map+ * into a metadatum. It returns an error code to indicate the success or failure of the operation.+ *+ * \param[in] map A pointer to the \ref cardano_metadatum_map_t object from which+ *                the metadatum will be created.+ * \param[out] metadatum On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_t object. This object represents a "strong reference"+ *             to the metadatum, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* map = cardano_metadatum_map_new(...);+ * cardano_metadatum_t* metadatum = NULL;+ *+ * // Attempt to create a new metadatum from a metadatum_map+ * cardano_error_t result = cardano_metadatum_new_map(map, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ *+ * // Clean up the metadatum_map object once done+ * cardano_metadatum_map_unref(&map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_new_map(+  cardano_metadatum_map_t* map,+  cardano_metadatum_t**    metadatum);++/**+ * \brief Creates and initializes a new instance of a metadatum from a metadatum list.+ *+ * This function creates and initializes a new instance of a \ref cardano_metadatum_t object+ * from a given \ref cardano_metadatum_list_t object. It essentially converts a metadatum list+ * into a metadatum. It returns an error code to indicate the success or failure of the operation.+ *+ * \param[in] list A pointer to the \ref cardano_metadatum_list_t object from which+ *                 the metadatum will be created. The object must not be NULL.+ * \param[out] metadatum On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_t object. This object represents a "strong reference"+ *             to the metadatum, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_list_t* list = cardano_metadatum_list_new(...);+ * cardano_metadatum_t* metadatum = NULL;+ *+ * // Attempt to create a new metadatum from a metadatum_list+ * cardano_error_t result = cardano_metadatum_new_list(list, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ *+ * // Clean up the metadatum_list object once done+ * cardano_metadatum_list_unref(&list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_new_list(+  cardano_metadatum_list_t* list,+  cardano_metadatum_t**     metadatum);++/**+ * \brief Creates and initializes a new instance of metadatum from a bigint object.+ *+ * This function creates and initializes a new instance of a \ref cardano_metadatum_t object+ * from a given bigint object.+ *+ * \param[in] bigint A constant pointer to the \ref cardano_bigint_t object from which the metadatum will be created.+ * \param[out] metadatum On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_t object. This object represents a "strong reference"+ *             to the metadatum, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * // Assume bigint is already initialized and set to a value+ * cardano_bigint_t* bigint = ...;+ * cardano_metadatum_t* metadatum = NULL;+ *+ * // Attempt to create a new metadatum from a bigint+ * cardano_error_t result = cardano_metadatum_new_integer(bigint, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_new_integer(+  const cardano_bigint_t* bigint,+  cardano_metadatum_t**   metadatum);++/**+ * \brief Creates and initializes a new instance of metadatum from an integer value.+ *+ * This function creates and initializes a new instance of a \ref cardano_metadatum_t object+ * from a given `int64_t` integer. It converts an integer into a metadatum object, suitable+ * for transactions and other blockchain-related operations. It returns an error code to indicate+ * the success or failure of the operation.+ *+ * \param[in] integer The `int64_t` integer value from which the metadatum will be created.+ * \param[out] metadatum On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_t object. This object represents a "strong reference"+ *             to the metadatum, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * int64_t integer_value = 42; // Example integer value+ * cardano_metadatum_t* metadatum = NULL;+ *+ * // Attempt to create a new metadatum from an integer value+ * cardano_error_t result = cardano_metadatum_new_integer_from_int(integer_value, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_new_integer_from_int(+  int64_t               integer,+  cardano_metadatum_t** metadatum);++/**+ * \brief Creates and initializes a new instance of metadatum from an unsigned integer value.+ *+ * This function creates and initializes a new instance of a \ref cardano_metadatum_t object+ * from a given `uint64_t` integer.+ *+ * \param[in] integer The `uint64_t` integer value from which the metadatum will be created.+ * \param[out] metadatum On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_t object. This object represents a "strong reference"+ *             to the metadatum, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * uint64_t integer_value = 18446744073709551615u; // Example unsigned integer value+ * cardano_metadatum_t* metadatum = NULL;+ *+ * // Attempt to create a new metadatum from an unsigned integer value+ * cardano_error_t result = cardano_metadatum_new_integer_from_uint(integer_value, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_new_integer_from_uint(+  uint64_t              integer,+  cardano_metadatum_t** metadatum);++/**+ * \brief Creates and initializes a new instance of Plutus data from a string representation of an integer in a specified base.+ *+ * This function creates and initializes a new instance of a \ref cardano_metadatum_t object from a given string+ * representing an integer, interpreted according to the specified base (e.g., 10 for decimal, 16 for hexadecimal).+ *+ * \param[in] string A pointer to the character string containing the numeric representation of the integer.+ * \param[in] size The number of characters in the string, excluding the null terminator.+ * \param[in] base The numerical base in which the string representation is expressed. Valid values are between 2 and 36.+ * \param[out] metadatum On successful initialization, this will point to a newly created+ *                         \ref cardano_metadatum_t object. This object represents a "strong reference"+ *                         to the metadatum, meaning that it is fully initialized and ready for use.+ *                         The caller is responsible for managing the lifecycle of this object.+ *                         Specifically, once the metadatum is no longer needed, the caller must release it+ *                         by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * const char* integer_str = "12345678901234567890"; // Example large integer value in string form+ * cardano_metadatum_t* metadatum = NULL;+ * int32_t base = 10; // Decimal base+ *+ * // Attempt to create a new metadatum from a string representation of an integer in decimal+ * cardano_error_t result = cardano_metadatum_new_integer_from_string(integer_str, strlen(integer_str), base, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_new_integer_from_string(+  const char*           string,+  size_t                size,+  int32_t               base,+  cardano_metadatum_t** metadatum);++/**+ * \brief Creates and initializes a new instance of a metadatum from a byte array.+ *+ * This function creates and initializes a new instance of a \ref cardano_metadatum_t object+ * from a given byte array. It essentially converts a byte array into a metadatum.+ * It returns an error code to indicate the success or failure of the operation.+ *+ * \param[in] bytes A pointer to the byte array from which the metadatum will be created.+ *                  The byte array must not be NULL.+ * \param[in] size The size of the byte array.+ * \param[out] metadatum On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_t object. This object represents a "strong reference"+ *             to the metadatum, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * const byte_t bytes[] = {0x01, 0x02, 0x03, 0x04}; // Example byte array+ * size_t size = sizeof(bytes) / sizeof(byte_t); // Calculate the size of the byte array+ * cardano_metadatum_t* metadatum = NULL;+ *+ * // Attempt to create a new metadatum from a byte array+ * cardano_error_t result = cardano_metadatum_new_bytes(bytes, size, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_new_bytes(+  const byte_t*         bytes,+  size_t                size,+  cardano_metadatum_t** metadatum);++/**+ * \brief Creates and initializes a new instance of a metadatum from a hexadecimal string.+ *+ * This function creates and initializes a new instance of a \ref cardano_metadatum_t object+ * from a given hexadecimal string. It essentially converts a hexadecimal string into a metadatum,+ * treating each pair of characters as a byte. It returns an error code to indicate the success or+ * failure of the operation.+ *+ * \param[in] hex A pointer to the hexadecimal string from which the metadatum will be created.+ *                The hexadecimal string must not be NULL.+ * \param[in] size The size of the hexadecimal string.+ * \param[out] metadatum On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_t object. This object represents a "strong reference"+ *             to the metadatum, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * const char* hex_string = "0123456789abcdef"; // Example hexadecimal string+ * size_t size = strlen(hex_string); // Calculate the size of the string+ * cardano_metadatum_t* metadatum = NULL;+ *+ * // Attempt to create a new metadatum from a hexadecimal string+ * cardano_error_t result = cardano_metadatum_new_bytes_from_hex(hex_string, size, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_new_bytes_from_hex(+  const char*           hex,+  size_t                size,+  cardano_metadatum_t** metadatum);++/**+ * \brief Creates and initializes a new instance of a metadatum from a string.+ *+ * This function creates and initializes a new instance of a \ref cardano_metadatum_t object+ * from a given string.+ *+ * \param[in] string A pointer to the string from which the metadatum will be created.+ *                The string must not be NULL.+ * \param[in] size The size of the string.+ * \param[out] metadatum On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_t object. This object represents a "strong reference"+ *             to the metadatum, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * const char* string = "hello world"; // Example string+ * size_t size = strlen(string); // Calculate the size of the string+ * cardano_metadatum_t* metadatum = NULL;+ *+ * // Attempt to create a new metadatum from a string+ * cardano_error_t result = cardano_metadatum_new_string(string, size, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_new_string(+  const char*           string,+  size_t                size,+  cardano_metadatum_t** metadatum);++/**+ * \brief Creates a metadatum from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_metadatum_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a metadatum.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded metadatum.+ * \param[out] metadatum A pointer to a pointer of \ref cardano_metadatum_t that will be set to the address+ *                        of the newly created metadatum object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the metadatum was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_metadatum_t object by calling+ *       \ref cardano_metadatum_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_metadatum_t* metadatum = NULL;+ *+ * cardano_error_t result = cardano_metadatum_from_cbor(reader, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode metadatum: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_from_cbor(cardano_cbor_reader_t* reader, cardano_metadatum_t** metadatum);++/**+ * \brief Creates a metadatum from a JSON string.+ *+ * This function parses JSON data using a provided JSON string and constructs a \ref cardano_metadatum_t object.+ * It assumes that the JSON data corresponds to the structure expected for a metadatum.+ *+ * \param[in] json A pointer to a character array containing the JSON-encoded metadatum data.+ * \param[in] json_size The size of the JSON data in bytes.+ * \param[out] metadatum A pointer to a pointer of \ref cardano_metadatum_t that will be set to the address+ *                           of the newly created metadatum object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the metadatum was successfully created, or an appropriate error code if an error occurred.+ *+ * Usage Example:+ * \code{.c}+ * const char* json_data = "{...}"; // Assume this contains valid JSON-encoded metadatum data+ * size_t data_size = strlen(json_data);+ * cardano_metadatum_t* metadatum = NULL;+ *+ * cardano_error_t result = cardano_metadatum_from_json(json_data, data_size, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *+ *   // Once done, ensure to clean up and release the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * else+ * {+ *   // Handle error+ *   printf("Failed to decode metadatum: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_from_json(const char* json, size_t json_size, cardano_metadatum_t** metadatum);++/**+ * \brief Computes the size needed for the JSON string representation of a metadatum.+ *+ * This function calculates the size in bytes required to represent a \ref cardano_metadatum_t+ * as a null-terminated JSON string, including the null terminator. This is useful for allocating+ * an appropriately sized buffer before converting the metadatum to JSON using+ * \ref cardano_metadatum_to_json.+ *+ * \param[in] metadatum A pointer to the \ref cardano_metadatum_t instance whose JSON size is being queried.+ *                      This parameter must not be NULL.+ *+ * \return The size in bytes required to represent the metadatum as a null-terminated JSON string,+ *         including the null terminator. Returns 0 if \p metadatum is NULL or if an error occurs.+ *+ * \note The size returned includes space for the null terminator.+ *+ * Usage Example:+ * \code{.c}+ * // Assume metadatum is already initialized+ * cardano_metadatum_t* metadatum = ...;+ *+ * size_t json_size = cardano_metadatum_get_json_size(metadatum);+ *+ * if (json_size > 0)+ * {+ *   // json_size now contains the size needed to store the JSON string, including null terminator+ *   // You can allocate a buffer of this size for conversion+ * }+ * else+ * {+ *   printf("Failed to get the JSON size.\n");+ *   // Handle error+ * }+ * \endcode+ *+ * \see cardano_metadatum_to_json+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_metadatum_get_json_size(cardano_metadatum_t* metadatum);++/**+ * \brief Converts a metadatum object to a JSON string.+ *+ * This function converts a \ref cardano_metadatum_t object to its JSON representation.+ * The resulting JSON string is stored in the provided buffer, which must be pre-allocated by the caller.+ * The buffer must be large enough to hold the entire JSON string, including the null terminator.+ *+ * To determine the required buffer size (including the null terminator), use+ * \ref cardano_metadatum_get_json_size before calling this function.+ *+ * \param[in] metadatum A pointer to the \ref cardano_metadatum_t object to be converted.+ *                      This parameter must not be NULL.+ * \param[out] json A pointer to a character array where the null-terminated JSON string will be stored.+ *                  The buffer must be allocated by the caller and have a size of at least \p json_size bytes.+ *                  This parameter must not be NULL.+ * \param[in] json_size The size of the \p json buffer in bytes, including space for the null terminator.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if \p metadatum or \p json is NULL.+ *         Returns \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if \p json_size is insufficient to hold the JSON string.+ *+ * \note The JSON string will be encoded in UTF-8.+ *+ * Usage Example:+ * \code{.c}+ * // Assume metadatum is already initialized+ * cardano_metadatum_t* metadatum = ...;+ *+ * // Get the size needed for the JSON string (including null terminator)+ * size_t json_size = cardano_metadatum_get_json_size(metadatum);+ * if (json_size == 0)+ * {+ *   printf("Failed to get the JSON size.\n");+ *   // Handle error+ * }+ * else+ * {+ *   // Allocate buffer for the JSON string+ *   char* json_buffer = (char*)malloc(json_size);+ *   if (json_buffer == NULL)+ *   {+ *     printf("Memory allocation failed.\n");+ *     // Handle memory allocation failure+ *   }+ *   else+ *   {+ *     // Convert the metadatum to JSON+ *     cardano_error_t result = cardano_metadatum_to_json(metadatum, json_buffer, json_size);+ *     if (result == CARDANO_SUCCESS)+ *     {+ *       printf("Metadatum as JSON: %s\n", json_buffer);+ *     }+ *     else+ *     {+ *       printf("Failed to convert metadatum to JSON: %s\n", cardano_error_to_string(result));+ *     }+ *     // Free the buffer when done+ *     free(json_buffer);+ *   }+ * }+ *+ * // Clean up the metadatum object once done+ * cardano_metadatum_unref(&metadatum);+ * \endcode+ *+ * \see cardano_metadatum_get_json_size+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_to_json(+  cardano_metadatum_t* metadatum,+  char*                json,+  size_t               json_size);++/**+ * \brief Serializes a metadatum into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_metadatum_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] metadatum A constant pointer to the \ref cardano_metadatum_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p metadatum or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_t* metadatum = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_metadatum_to_cbor(metadatum, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_metadatum_unref(&metadatum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_to_cbor(+  const cardano_metadatum_t* metadatum,+  cardano_cbor_writer_t*     writer);++/**+ * \brief Serializes a \ref cardano_metadatum_t to CIP-116 JSON.+ *+ * This function emits a single JSON object representing a Cardano transaction metadatum+ * using the CIP-116 JSON shape.+ *+ * The function always writes a complete JSON object (it begins with `{` and ends with `}`).+ * It assumes \p writer is positioned where a value is valid (root, array element, or after a+ * property name).+ *+ * \note Unlike on-chain CBOR encoding constraints, this JSON encoder does **not** enforce the+ *  64-byte bounds on bytes/text metadata. It emits the full content as provided.+ *+ * \param[in] metadatum A valid pointer to the metadatum to serialize.+ * \param[in,out] writer A valid JSON writer.+ *+ * \return CARDANO_SUCCESS on success.+ * \return CARDANO_ERROR_POINTER_IS_NULL if any pointer parameter is NULL.+ * \return CARDANO_ERROR_ENCODING on encoding errors (e.g., allocation failure or conversion failure).+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_to_cip116_json(+  const cardano_metadatum_t* metadatum,+  cardano_json_writer_t*     writer);++/**+ * \brief Retrieves the kind of the metadatum.+ *+ * This function retrieves the kind of a given \ref cardano_metadatum_t object and stores it in the provided+ * output parameter. The metadatum kind is defined in the \ref cardano_metadatum_kind_t enumeration, which+ * specifies whether the metadatum represents an integer, byte array, or other types.+ *+ * \param[in] metadatum A constant pointer to the \ref cardano_metadatum_t object from which+ *                        the kind is to be retrieved. The object must not be NULL.+ * \param[out] kind Pointer to a variable where the metadatum kind will be stored. This variable will+ *                  be set to the value from the \ref cardano_metadatum_kind_t enumeration.+ *+ * \return \ref CARDANO_SUCCESS if the kind was successfully retrieved, or an appropriate error code if the+ *         input is NULL or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_t* metadatum = cardano_metadatum_new_bytes_from_hex(...);+ * cardano_metadatum_kind_t kind;+ * cardano_error_t result = cardano_metadatum_get_kind(metadatum, &kind);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   if (kind == CARDANO_METADATUM_KIND_INTEGER)+ *   {+ *     // Handle integer type metadatum+ *   }+ *   else if (kind == CARDANO_METADATUM_KIND_BYTES)+ *   {+ *     // Handle byte array type metadatum+ *   }+ *   // Add more cases as needed for other kinds+ * }+ *+ * // Clean up the metadatum object once done+ * cardano_metadatum_unref(&metadatum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_get_kind(+  const cardano_metadatum_t* metadatum,+  cardano_metadatum_kind_t*  kind);++/**+ * \brief Converts a metadatum object to a metadatum map object.+ *+ * This function converts a \ref cardano_metadatum_t object to a \ref cardano_metadatum_map_t object.+ * It essentially creates a metadatum map object from the given metadatum, allowing the conversion+ * between different types of metadatum. It returns an error code to indicate the success or failure of+ * the operation.+ *+ * \param[in] metadatum A constant pointer to the \ref cardano_metadatum_t object to be converted.+ *                        The object must not be NULL.+ * \param[out] map On successful conversion, this will point to a newly created+ *                 \ref cardano_metadatum_map_t object. This object represents a "strong reference"+ *                 to the metadatum_map, meaning that it is fully initialized and ready for use.+ *                 The caller is responsible for managing the lifecycle of this object.+ *                 Specifically, once the metadatum_map is no longer needed, the caller must release it+ *                 by calling \ref cardano_metadatum_map_unref.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_t* metadatum = ...; // Assume metadatum is a valid metadatum map object+ * cardano_metadatum_map_t* map = NULL;+ * cardano_error_t result = cardano_metadatum_to_map(metadatum, &map);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum_map+ *+ *   // Once done, ensure to clean up and release the metadatum_map+ *   cardano_metadatum_map_unref(&map);+ * }+ *+ * // Clean up the metadatum object once done+ * cardano_metadatum_unref(&metadatum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_to_map(+  cardano_metadatum_t*      metadatum,+  cardano_metadatum_map_t** map);++/**+ * \brief Converts a metadatum object to a metadatum list object.+ *+ * This function converts a \ref cardano_metadatum_t object to a \ref cardano_metadatum_list_t object.+ * It essentially creates a metadatum list object from the given metadatum, allowing the conversion+ * between different types of metadatum. It returns an error code to indicate the success or failure of+ * the operation.+ *+ * \param[in] metadatum A constant pointer to the \ref cardano_metadatum_t object to be converted.+ * \param[out] list On successful conversion, this will point to a newly created+ *                  \ref cardano_metadatum_list_t object. This object represents a "strong reference"+ *                  to the metadatum_list, meaning that it is fully initialized and ready for use.+ *                  The caller is responsible for managing the lifecycle of this object.+ *                  Specifically, once the metadatum_list is no longer needed, the caller must release it+ *                  by calling \ref cardano_metadatum_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_t* metadatum = ...; // Assume metadatum is a valid metadatum list object+ * cardano_metadatum_list_t* list = NULL;+ * cardano_error_t result = cardano_metadatum_to_list(metadatum, &list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum_list+ *+ *   // Once done, ensure to clean up and release the metadatum_list+ *   cardano_metadatum_list_unref(&list);+ * }+ *+ * // Clean up the metadatum object once done+ * cardano_metadatum_unref(&metadatum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_to_list(+  cardano_metadatum_t*       metadatum,+  cardano_metadatum_list_t** list);++/**+ * \brief Converts a metadatum object to a bigint object.+ *+ * This function converts a \ref cardano_metadatum_t object to a \ref cardano_bigint_t object.+ *+ * \param[in] metadatum A constant pointer to the \ref cardano_metadatum_t object to be converted.+ * \param[out] integer On successful conversion, this will point to a newly created \ref cardano_bigint_t object+ *                     representing the extracted integer value. The caller is responsible for managing the memory+ *                     of this object, including releasing it when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_t* metadatum = cardano_metadatum_new_integer_from_string("987456321478523698745");+ * cardano_bigint_t* bigint = NULL;+ * cardano_error_t result = cardano_metadatum_to_integer(metadatum, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the bigint object+ *   const size_t size = cardano_bigint_get_string_size(bigint, 10);+ *   char* buffer = (char*)malloc(size);+ *+ *   if (cardano_bigint_to_string(bigint, buffer, size, 10) == CARDANO_SUCCESS)+ *   {+ *     printf("Extracted bigint value: %s\n", buffer);+ *   }+ * }+ *+ * // Clean up+ * cardano_metadatum_unref(&metadatum);+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_to_integer(+  const cardano_metadatum_t* metadatum,+  cardano_bigint_t**         integer);++/**+ * \brief Converts a metadatum object to bounded bytes.+ *+ * This function converts a \ref cardano_metadatum_t object to bounded bytes.+ * It extracts the bytes from the given metadatum, allowing the conversion+ * between different types of metadatum. The resulting bytes are stored in a bounded bytes buffer.+ * It returns an error code to indicate the success or failure of the operation.+ *+ * \param[in] metadatum A constant pointer to the \ref cardano_metadatum_t object to be converted.+ * \param[out] bounded_bytes On successful conversion, this will point to a newly created+ *                           \ref cardano_buffer_t object containing the extracted bytes.+ *                           This object represents a "strong reference" to the bounded bytes,+ *                           meaning that it is fully initialized and ready for use.+ *                           The caller is responsible for managing the lifecycle of this object.+ *                           Specifically, once the bounded bytes are no longer needed, the caller must release it+ *                           by calling \ref cardano_buffer_unref.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_t* metadatum = cardano_metadatum_new_bytes_from_hex("DEADBEEF", 8);+ * cardano_buffer_t* bounded_bytes = NULL;+ * cardano_error_t result = cardano_metadatum_to_bounded_bytes(metadatum, &bounded_bytes);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the bounded bytes+ *   printf("Extracted bounded bytes: ");+ *+ *   for (size_t i = 0; i < cardano_buffer_get_size(bounded_bytes); ++i)+ *   {+ *     printf("%02X ", cardano_buffer_get_data(bounded_bytes)[i]);+ *   }+ *+ *   printf("\n");+ *+ *   // Once done, ensure to clean up and release the bounded bytes+ *   cardano_buffer_unref(&bounded_bytes);+ * }+ *+ * // Clean up the metadatum object once done+ * cardano_metadatum_unref(&metadatum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_to_bounded_bytes(+  cardano_metadatum_t* metadatum,+  cardano_buffer_t**   bounded_bytes);++/**+ * \brief Computes the size needed for the null-terminated string representation of a metadatum.+ *+ * This function calculates the size in bytes required to represent a \ref cardano_metadatum_t+ * as a null-terminated string, including the null terminator. This is useful for allocating+ * an appropriately sized buffer before converting the metadatum to a string using+ * \ref cardano_metadatum_to_string.+ *+ * \param[in] metadatum A pointer to the \ref cardano_metadatum_t instance whose string size is being queried.+ *                      This parameter must not be NULL.+ *+ * \return The size in bytes required to represent the metadatum as a null-terminated string,+ *         including the null terminator. Returns 0 if \p metadatum is NULL or if an error occurs.+ *+ * Usage Example:+ * \code{.c}+ * // Assume metadatum is already initialized+ * cardano_metadatum_t* metadatum = ...;+ *+ * size_t size = cardano_metadatum_get_string_size(metadatum);+ *+ * if (size > 0)+ * {+ *     // size now contains the size needed to store the string, including null terminator+ *     // You can allocate a buffer of this size for conversion+ * }+ * else+ * {+ *     printf("Failed to get the string size.\n");+ *     // Handle error+ * }+ * \endcode+ *+ * \see cardano_metadatum_to_string+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_metadatum_get_string_size(cardano_metadatum_t* metadatum);++/**+ * \brief Converts a metadatum object to a null-terminated C string.+ *+ * This function converts a \ref cardano_metadatum_t object to its string representation.+ * The resulting string is stored in the provided buffer, which must be pre-allocated by the caller.+ * The buffer must be large enough to hold the entire string, including the null terminator.+ *+ * To determine the required buffer size (including the null terminator), use+ * \ref cardano_metadatum_get_string_size before calling this function.+ *+ * \param[in] metadatum A pointer to the \ref cardano_metadatum_t object to be converted.+ *                      This parameter must not be NULL.+ * \param[out] buffer A pointer to a character array where the null-terminated string will be stored.+ *                    The buffer must be allocated by the caller and have a size of at least \p buffer_size bytes.+ *                    This parameter must not be NULL.+ * \param[in] buffer_size The size of the \p buffer in bytes, including space for the null terminator.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful.+ *         Returns \ref CARDANO_ERROR_POINTER_IS_NULL if \p metadatum or \p buffer is NULL.+ *         Returns \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if \p buffer_size is insufficient to hold the string.+ *+ * Usage Example:+ * \code{.c}+ * // Assume metadatum is already initialized+ * cardano_metadatum_t* metadatum = ...;+ *+ * // Get the size needed for the string (including null terminator)+ * size_t string_size = cardano_metadatum_get_string_size(metadatum);+ * if (string_size == 0)+ * {+ *     printf("Failed to get the string size.\n");+ *     // Handle error+ * }+ * else+ * {+ *     // Allocate buffer for the string+ *     char* buffer = (char*)malloc(string_size);+ *     if (buffer == NULL)+ *     {+ *         printf("Memory allocation failed.\n");+ *         // Handle memory allocation failure+ *     }+ *     else+ *     {+ *         // Convert the metadatum to string+ *         cardano_error_t result = cardano_metadatum_to_string(metadatum, buffer, string_size);+ *         if (result == CARDANO_SUCCESS)+ *         {+ *             printf("Metadatum as string: %s\n", buffer);+ *         }+ *         else+ *         {+ *             printf("Failed to convert metadatum to string: %s\n", cardano_error_to_string(result));+ *         }+ *         // Free the buffer when done+ *         free(buffer);+ *     }+ * }+ *+ * // Clean up the metadatum object once done+ * cardano_metadatum_unref(&metadatum);+ * \endcode+ *+ * \see cardano_metadatum_get_string_size+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_to_string(+  cardano_metadatum_t* metadatum,+  char*                buffer,+  size_t               buffer_size);++/**+ * \brief Checks if two metadatum objects are equal.+ *+ * This function compares two \ref cardano_metadatum_t objects for equality.+ * It checks if the contents of the two metadatum objects are identical.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_metadatum_t object to be compared.+ * \param[in] rhs A constant pointer to the second \ref cardano_metadatum_t object to be compared.+ *+ * \return \c true if the two metadatum objects are equal (have the same contents), \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_t* metadatum1 = cardano_metadatum_new_bytes_from_hex("DEADBEEF", 8);+ * cardano_metadatum_t* metadatum2 = cardano_metadatum_new_bytes_from_hex("DEADBEEF", 8);+ *+ * if (cardano_metadatum_equals(metadatum1, metadatum2))+ * {+ *   printf("metadatum1 is equal to metadatum2\n");+ * }+ * else+ * {+ *   printf("metadatum1 is not equal to metadatum2\n");+ * }+ *+ * // Clean up the metadatum objects once done+ * cardano_metadatum_unref(&metadatum1);+ * cardano_metadatum_unref(&metadatum2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_metadatum_equals(const cardano_metadatum_t* lhs, const cardano_metadatum_t* rhs);++/**+ * \brief Decrements the reference count of a metadatum object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_metadatum_t object+ * by decreasing its reference count. When the reference count reaches zero, the metadatum is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] metadatum A pointer to the pointer of the metadatum object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_t* metadatum = cardano_metadatum_new();+ *+ * // Perform operations with the metadatum...+ *+ * cardano_metadatum_unref(&metadatum);+ * // At this point, metadatum is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_metadatum_unref, the pointer to the \ref cardano_metadatum_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_metadatum_unref(cardano_metadatum_t** metadatum);++/**+ * \brief Increases the reference count of the cardano_metadatum_t object.+ *+ * This function is used to manually increment the reference count of a metadatum+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_metadatum_unref.+ *+ * \param metadatum A pointer to the metadatum object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming metadatum is a previously created metadatum object+ *+ * cardano_metadatum_ref(metadatum);+ *+ * // Now metadatum can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_metadatum_ref there is a corresponding+ * call to \ref cardano_metadatum_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_metadatum_ref(cardano_metadatum_t* metadatum);++/**+ * \brief Retrieves the current reference count of the cardano_metadatum_t object.+ *+ * This function returns the number of active references to a metadatum object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_metadatum_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param metadatum A pointer to the metadatum object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified metadatum object. If the object+ * is properly managed (i.e., every \ref cardano_metadatum_ref call is matched with a+ * \ref cardano_metadatum_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming metadatum is a previously created metadatum object+ *+ * size_t ref_count = cardano_metadatum_refcount(metadatum);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_metadatum_refcount(const cardano_metadatum_t* metadatum);++/**+ * \brief Sets the last error message for a given metadatum object.+ *+ * Records an error message in the metadatum's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] metadatum A pointer to the \ref cardano_metadatum_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the metadatum's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_metadatum_set_last_error(cardano_metadatum_t* metadatum, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific metadatum.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_metadatum_set_last_error for the given+ * metadatum. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] metadatum A pointer to the \ref cardano_metadatum_t instance whose last error+ *                   message is to be retrieved. If the metadatum is NULL, the function+ *                   returns a generic error message indicating the null metadatum.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified metadatum. If the metadatum is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_metadatum_set_last_error for the same metadatum, or until+ *       the metadatum is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_metadatum_get_last_error(const cardano_metadatum_t* metadatum);++/**+ * \brief Creates an independent deep copy of a \ref cardano_metadatum_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_metadatum_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_metadatum_deep_clone(const cardano_metadatum_t* source, cardano_metadatum_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_H
+ vendor/include/cardano/auxiliary_data/metadatum_kind.h view
@@ -0,0 +1,73 @@+/**+ * \file metadatum_kind.h+ *+ * \author angel.castillo+ * \date   Sep 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_KIND_H+#define BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_KIND_H++/* INCLUDES ******************************************************************/++#include <cardano/error.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \enum cardano_metadatum_kind_t+ * \brief The metadatum type kind.+ */+typedef enum+{+  /**+   * \brief A map of PlutusData as both key and values.+   */+  CARDANO_METADATUM_KIND_MAP,++  /**+   * \brief A list of PlutusData.+   */+  CARDANO_METADATUM_KIND_LIST,++  /**+   * \brief An integer.+   */+  CARDANO_METADATUM_KIND_INTEGER,++  /**+   * \brief Bounded bytes.+   */+  CARDANO_METADATUM_KIND_BYTES,++  /**+   * \brief Text string.+   */+  CARDANO_METADATUM_KIND_TEXT++} cardano_metadatum_kind_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_KIND_H
+ vendor/include/cardano/auxiliary_data/metadatum_label_list.h view
@@ -0,0 +1,322 @@+/**+ * \file metadatum_label_list.h+ *+ * \author angel.castillo+ * \date   Sep 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_LABEL_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_LABEL_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a list of metadatum labels.+ */+typedef struct cardano_metadatum_label_list_t cardano_metadatum_label_list_t;++/**+ * \brief Creates and initializes a new instance of a metadatum_label_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_metadatum_label_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] metadatum_label_list On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_label_list_t object. This object represents a "strong reference"+ *             to the metadatum_label_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum_label_list is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_label_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum_label_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_label_list_t* metadatum_label_list = NULL;+ *+ * // Attempt to create a new metadatum_label_list+ * cardano_error_t result = cardano_metadatum_label_list_new(&metadatum_label_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum_label_list+ *+ *   // Once done, ensure to clean up and release the metadatum_label_list+ *   cardano_metadatum_label_list_unref(&metadatum_label_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_label_list_new(cardano_metadatum_label_list_t** metadatum_label_list);++/**+ * \brief Retrieves the length of a metadatum label list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_metadatum_label_list_t object.+ *+ * \param[in] metadatum_label_list A constant pointer to the \ref cardano_metadatum_label_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the metadatum_label_list. Return 0 if the metadatum_label_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_label_list_t* metadatum_label_list = cardano_metadatum_label_list_new();+ *+ * // Populate metadatum_label_list with elements+ *+ * size_t length = cardano_metadatum_label_list_get_length(metadatum_label_list);+ * printf("Length of the metadatum_label_list: %zu\n", length);+ *+ * // Clean up the metadatum_label_list object once done+ * cardano_metadatum_label_list_unref(&metadatum_label_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_metadatum_label_list_get_length(const cardano_metadatum_label_list_t* metadatum_label_list);++/**+ * \brief Retrieves an element from a metadatum label list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_metadatum_label_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] metadatum_label_list A constant pointer to the \ref cardano_metadatum_label_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the metadatum label list. Indexing starts at 0.+ * \param[out] element The label as an \c uint64_t.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_label_list_t* metadatum_label_list = cardano_metadatum_label_list_new();+ *+ * // Populate metadatum_label_list with elements+ *+ * uint64_t element = 0;+ * cardano_error_t result = cardano_metadatum_label_list_get(metadatum_label_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ * }+ *+ * // Clean up the metadatum_label_list object once done+ * cardano_metadatum_label_list_unref(&metadatum_label_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_label_list_get(const cardano_metadatum_label_list_t* metadatum_label_list, size_t index, uint64_t* element);++/**+ * \brief Adds an element to a metadatum label list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_metadatum_label_list_t object.+ *+ * \param[in] metadatum_label_list A constant pointer to the \ref cardano_metadatum_label_list_t object to which+ *                        the element is to be added.+ * \param[in] element The metadatum label to be added.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the metadatum_label_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_label_list_t* metadatum_label_list = cardano_metadatum_label_list_new();+ *+ * // Create and initialize a new metadatum label element+ * uint64_t element = 755;+ *+ * // Add the element to the metadatum_label_list+ * cardano_error_t result = cardano_metadatum_label_list_add(metadatum_label_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the metadatum_label_list object once done+ * cardano_metadatum_label_list_unref(&metadatum_label_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_label_list_add(cardano_metadatum_label_list_t* metadatum_label_list, uint64_t element);++/**+ * \brief Decrements the reference count of a metadatum_label_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_metadatum_label_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the metadatum_label_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] metadatum_label_list A pointer to the pointer of the metadatum_label_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_label_list_t* metadatum_label_list = cardano_metadatum_label_list_new();+ *+ * // Perform operations with the metadatum_label_list...+ *+ * cardano_metadatum_label_list_unref(&metadatum_label_list);+ * // At this point, metadatum_label_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_metadatum_label_list_unref, the pointer to the \ref cardano_metadatum_label_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_metadatum_label_list_unref(cardano_metadatum_label_list_t** metadatum_label_list);++/**+ * \brief Increases the reference count of the cardano_metadatum_label_list_t object.+ *+ * This function is used to manually increment the reference count of a metadatum_label_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_metadatum_label_list_unref.+ *+ * \param metadatum_label_list A pointer to the metadatum_label_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming metadatum_label_list is a previously created metadatum_label_list object+ *+ * cardano_metadatum_label_list_ref(metadatum_label_list);+ *+ * // Now metadatum_label_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_metadatum_label_list_ref there is a corresponding+ * call to \ref cardano_metadatum_label_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_metadatum_label_list_ref(cardano_metadatum_label_list_t* metadatum_label_list);++/**+ * \brief Retrieves the current reference count of the cardano_metadatum_label_list_t object.+ *+ * This function returns the number of active references to a metadatum_label_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_metadatum_label_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param metadatum_label_list A pointer to the metadatum_label_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified metadatum_label_list object. If the object+ * is properly managed (i.e., every \ref cardano_metadatum_label_list_ref call is matched with a+ * \ref cardano_metadatum_label_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming metadatum_label_list is a previously created metadatum_label_list object+ *+ * size_t ref_count = cardano_metadatum_label_list_refcount(metadatum_label_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_metadatum_label_list_refcount(const cardano_metadatum_label_list_t* metadatum_label_list);++/**+ * \brief Sets the last error message for a given metadatum_label_list object.+ *+ * Records an error message in the metadatum_label_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] metadatum_label_list A pointer to the \ref cardano_metadatum_label_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the metadatum_label_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_metadatum_label_list_set_last_error(cardano_metadatum_label_list_t* metadatum_label_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific metadatum_label_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_metadatum_label_list_set_last_error for the given+ * metadatum_label_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] metadatum_label_list A pointer to the \ref cardano_metadatum_label_list_t instance whose last error+ *                   message is to be retrieved. If the metadatum_label_list is NULL, the function+ *                   returns a generic error message indicating the null metadatum_label_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified metadatum_label_list. If the metadatum_label_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_metadatum_label_list_set_last_error for the same metadatum_label_list, or until+ *       the metadatum_label_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_metadatum_label_list_get_last_error(const cardano_metadatum_label_list_t* metadatum_label_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_metadatum_label_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_metadatum_label_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_metadatum_label_list_deep_clone(const cardano_metadatum_label_list_t* source, cardano_metadatum_label_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_LABEL_LIST_H
+ vendor/include/cardano/auxiliary_data/metadatum_list.h view
@@ -0,0 +1,480 @@+/**+ * \file metadatum_list.h+ *+ * \author angel.castillo+ * \date   Sep 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief A type corresponding to the metadatum type.+ *+ * Use this type to build metadata structures that you want to be representable on-chain.+ */+typedef struct cardano_metadatum_t cardano_metadatum_t;++/**+ * \brief Represents a list of metadatum.+ */+typedef struct cardano_metadatum_list_t cardano_metadatum_list_t;++/**+ * \brief Creates and initializes a new instance of a metadatum_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_metadatum_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] metadatum_list On successful initialization, this will point to a newly created+ *             \ref cardano_metadatum_list_t object. This object represents a "strong reference"+ *             to the metadatum_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the metadatum_list is no longer needed, the caller must release it+ *             by calling \ref cardano_metadatum_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_list_t* metadatum_list = NULL;+ *+ * // Attempt to create a new metadatum_list+ * cardano_error_t result = cardano_metadatum_list_new(&metadatum_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum_list+ *+ *   // Once done, ensure to clean up and release the metadatum_list+ *   cardano_metadatum_list_unref(&metadatum_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_list_new(cardano_metadatum_list_t** metadatum_list);++/**+ * \brief Creates a metadatum_list from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_metadatum_list_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a metadatum_list.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded metadatum_list data.+ * \param[out] metadatum_list A pointer to a pointer of \ref cardano_metadatum_list_t that will be set to the address+ *                        of the newly created metadatum_list object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the metadatum_list was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_metadatum_list_t object by calling+ *       \ref cardano_metadatum_list_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_metadatum_list_t* metadatum_list = NULL;+ *+ * cardano_error_t result = cardano_metadatum_list_from_cbor(reader, &metadatum_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum_list+ *+ *   // Once done, ensure to clean up and release the metadatum_list+ *   cardano_metadatum_list_unref(&metadatum_list);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode metadatum_list: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_list_from_cbor(cardano_cbor_reader_t* reader, cardano_metadatum_list_t** metadatum_list);++/**+ * \brief Serializes a metadatum_list into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_metadatum_list_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] metadatum_list A constant pointer to the \ref cardano_metadatum_list_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p metadatum_list or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_list_t* metadatum_list = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_metadatum_list_to_cbor(metadatum_list, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_metadatum_list_unref(&metadatum_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_list_to_cbor(+  const cardano_metadatum_list_t* metadatum_list,+  cardano_cbor_writer_t*          writer);++/**+ * \brief Serializes a \ref cardano_metadatum_list_t to CIP-116 JSON.+ *+ * Produces a single JSON object.+ *+ * Each element in \c contents is itself a full CIP-116 metadatum object as+ * written by \ref cardano_metadatum_to_cip116_json.+ *+ * The function always writes a complete JSON object (it begins with \c { and ends with \c }).+ * It assumes \p writer is positioned where a value is valid (root, array element, or after+ * a property name).+ *+ * \note Property order ("tag" then "contents") is stable for readability, but not required by CIP-116.+ *+ * \param[in]  list A valid metadatum list to serialize.+ * \param[in]  writer             A valid JSON writer.+ *+ * \return CARDANO_SUCCESS on success.+ * \return CARDANO_ERROR_POINTER_IS_NULL if any pointer parameter is \c NULL.+ * \return CARDANO_ERROR_ENCODING if an element cannot be retrieved or serialized.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_list_to_cip116_json(+  const cardano_metadatum_list_t* list,+  cardano_json_writer_t*          writer);++/**+ * \brief Retrieves the length of a metadatum list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_metadatum_list_t object.+ *+ * \param[in] metadatum_list A constant pointer to the \ref cardano_metadatum_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the metadatum_list. Return 0 if the metadatum_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_list_t* metadatum_list = cardano_metadatum_list_new();+ *+ * // Populate metadatum_list with elements+ *+ * size_t length = cardano_metadatum_list_get_length(metadatum_list);+ * printf("Length of the metadatum_list: %zu\n", length);+ *+ * // Clean up the metadatum_list object once done+ * cardano_metadatum_list_unref(&metadatum_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_metadatum_list_get_length(const cardano_metadatum_list_t* metadatum_list);++/**+ * \brief Retrieves an element from a metadatum list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_metadatum_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] metadatum_list A constant pointer to the \ref cardano_metadatum_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the metadatum list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_metadatum_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_metadatum_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_list_t* metadatum_list = cardano_metadatum_list_new();+ *+ * // Populate metadatum_list with elements+ *+ * cardano_metadatum_t* element = NULL;+ * cardano_error_t result = cardano_metadatum_list_get(metadatum_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_metadatum_unref(&element);+ * }+ *+ * // Clean up the metadatum_list object once done+ * cardano_metadatum_list_unref(&metadatum_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_list_get(const cardano_metadatum_list_t* metadatum_list, size_t index, cardano_metadatum_t** element);++/**+ * \brief Adds an element to a metadatum list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_metadatum_list_t object.+ *+ * \param[in] metadatum_list A constant pointer to the \ref cardano_metadatum_list_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_metadatum_t object that is to be added to the metadatum_list.+ *                    The element will be referenced by the metadatum_list after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the metadatum_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_list_t* metadatum_list = cardano_metadatum_list_new();+ *+ * // Create and initialize a new metadatum element+ * cardano_metadatum_t* element = { ... };+ *+ * // Add the element to the metadatum_list+ * cardano_error_t result = cardano_metadatum_list_add(metadatum_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the metadatum_list object once done+ * cardano_metadatum_list_unref(&metadatum_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_list_add(cardano_metadatum_list_t* metadatum_list, cardano_metadatum_t* element);++/**+ * \brief Checks if two metadatum lists are equal.+ *+ * This function compares two \ref cardano_metadatum_list_t objects to determine if they are equal. Two metadatum lists+ * are considered equal if they have the same number of elements and each corresponding pair of elements+ * is equal according to the \ref cardano_metadatum_equals function.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_metadatum_list_t object to be compared.+ * \param[in] rhs A constant pointer to the second \ref cardano_metadatum_list_t object to be compared.+ *+ * \return \c true if the two metadatum_lists are equal, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_list_t* list1 = { ... };  // Assume list1 is initialized here+ * cardano_metadatum_list_t* list2 = { ... };  // Assume list2 is initialized here+ *+ * if (cardano_metadatum_list_equals(list1, list2))+ * {+ *   // The two metadatum_lists are equal+ * }+ * else+ * {+ *   // The two metadatum_lists are not equal+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_metadatum_list_equals(const cardano_metadatum_list_t* lhs, const cardano_metadatum_list_t* rhs);++/**+ * \brief Decrements the reference count of a metadatum_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_metadatum_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the metadatum_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] metadatum_list A pointer to the pointer of the metadatum_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_list_t* metadatum_list = cardano_metadatum_list_new();+ *+ * // Perform operations with the metadatum_list...+ *+ * cardano_metadatum_list_unref(&metadatum_list);+ * // At this point, metadatum_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_metadatum_list_unref, the pointer to the \ref cardano_metadatum_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_metadatum_list_unref(cardano_metadatum_list_t** metadatum_list);++/**+ * \brief Increases the reference count of the cardano_metadatum_list_t object.+ *+ * This function is used to manually increment the reference count of a metadatum_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_metadatum_list_unref.+ *+ * \param metadatum_list A pointer to the metadatum_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming metadatum_list is a previously created metadatum_list object+ *+ * cardano_metadatum_list_ref(metadatum_list);+ *+ * // Now metadatum_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_metadatum_list_ref there is a corresponding+ * call to \ref cardano_metadatum_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_metadatum_list_ref(cardano_metadatum_list_t* metadatum_list);++/**+ * \brief Retrieves the current reference count of the cardano_metadatum_list_t object.+ *+ * This function returns the number of active references to a metadatum_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_metadatum_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param metadatum_list A pointer to the metadatum_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified metadatum_list object. If the object+ * is properly managed (i.e., every \ref cardano_metadatum_list_ref call is matched with a+ * \ref cardano_metadatum_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming metadatum_list is a previously created metadatum_list object+ *+ * size_t ref_count = cardano_metadatum_list_refcount(metadatum_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_metadatum_list_refcount(const cardano_metadatum_list_t* metadatum_list);++/**+ * \brief Sets the last error message for a given metadatum_list object.+ *+ * Records an error message in the metadatum_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] metadatum_list A pointer to the \ref cardano_metadatum_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the metadatum_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_metadatum_list_set_last_error(cardano_metadatum_list_t* metadatum_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific metadatum_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_metadatum_list_set_last_error for the given+ * metadatum_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] metadatum_list A pointer to the \ref cardano_metadatum_list_t instance whose last error+ *                   message is to be retrieved. If the metadatum_list is NULL, the function+ *                   returns a generic error message indicating the null metadatum_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified metadatum_list. If the metadatum_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_metadatum_list_set_last_error for the same metadatum_list, or until+ *       the metadatum_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_metadatum_list_get_last_error(const cardano_metadatum_list_t* metadatum_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_metadatum_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_metadatum_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_metadatum_list_deep_clone(const cardano_metadatum_list_t* source, cardano_metadatum_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_LIST_H
+ vendor/include/cardano/auxiliary_data/metadatum_map.h view
@@ -0,0 +1,641 @@+/**+ * \file metadatum_map.h+ *+ * \author angel.castillo+ * \date   Sep 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_MAP_H+#define BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_MAP_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a map of metadatum.+ */+typedef struct cardano_metadatum_map_t cardano_metadatum_map_t;++/**+ * \brief A type corresponding to the metadatum type.+ *+ * Use this type to build metadata structures that you want to be representable on-chain.+ */+typedef struct cardano_metadatum_t cardano_metadatum_t;++/**+ * \brief Represents a list of metadatum.+ */+typedef struct cardano_metadatum_list_t cardano_metadatum_list_t;++/**+ * \brief Creates and initializes a new instance of a metadatum map.+ *+ * This function allocates and initializes a new instance of \ref cardano_metadatum_map_t,+ * representing a map structure. It returns an error code+ * to indicate the success or failure of the operation.+ *+ * \param[out] metadatum_map A pointer to a pointer to a \ref cardano_metadatum_map_t object. Upon successful+ *                        initialization, this will point to a newly created \ref cardano_metadatum_map_t+ *                        object. This object represents a "strong reference" to the metadatum_map,+ *                        fully initialized and ready for use. The caller is responsible for managing+ *                        the lifecycle of this object. Specifically, once the metadatum_map is no longer+ *                        needed, the caller must release it by calling \ref cardano_metadatum_map_unref.+ *+ * \return \ref CARDANO_SUCCESS if the metadatum_map was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* metadatum_map = NULL;+ *+ * // Attempt to create a new metadatum_map+ * cardano_error_t result = cardano_metadatum_map_new(&metadatum_map);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum_map+ *+ *   // Once done, ensure to clean up and release the metadatum_map+ *   cardano_metadatum_map_unref(&metadatum_map);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_map_new(cardano_metadatum_map_t** metadatum_map);++/**+ * \brief Creates a metadatum map from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_metadatum_map_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a metadatum_map.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded metadatum_map data.+ * \param[out] metadatum_map A pointer to a pointer of \ref cardano_metadatum_map_t that will be set to the address+ *                        of the newly created metadatum_map object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the metadatum_map was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_metadatum_map_t object by calling+ *       \ref cardano_metadatum_map_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_metadatum_map_t* metadatum_map = NULL;+ *+ * cardano_error_t result = cardano_metadatum_map_from_cbor(reader, &metadatum_map);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum_map+ *+ *   // Once done, ensure to clean up and release the metadatum_map+ *   cardano_metadatum_map_unref(&metadatum_map);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode metadatum_map: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_map_from_cbor(cardano_cbor_reader_t* reader, cardano_metadatum_map_t** metadatum_map);++/**+ * \brief Serializes a metadatum map into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_metadatum_map_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] metadatum_map A constant pointer to the \ref cardano_metadatum_map_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p metadatum_map or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* metadatum_map = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_metadatum_map_to_cbor(metadatum_map, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_metadatum_map_unref(&metadatum_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_map_to_cbor(+  const cardano_metadatum_map_t* metadatum_map,+  cardano_cbor_writer_t*         writer);++/**+ * \brief Serializes a \ref cardano_metadatum_map_t to CIP-116 JSON.+ *+ * Writes a single JSON object.+ *+ * Each \c key and \c value is serialized using+ * \ref cardano_metadatum_to_cip116_json, so any valid metadatum type+ * (map, list, int, bytes, string) is supported recursively.+ *+ * The function always writes a complete JSON object (enclosed in \c { } ).+ *+ * \param[in] map    A valid metadatum map to serialize.+ * \param[in] writer A valid JSON writer positioned where a value is expected.+ *+ * \return CARDANO_SUCCESS on success.+ * \return CARDANO_ERROR_POINTER_IS_NULL if \p map or \p writer is \c NULL.+ * \return CARDANO_ERROR_ENCODING if a pair cannot be retrieved or an element+ *         fails to serialize; a descriptive error is set on \p writer.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_metadatum_map_to_cip116_json(+  const cardano_metadatum_map_t* map,+  cardano_json_writer_t*         writer);++/**+ * \brief Retrieves the length of the metadatum_map.+ *+ * This function returns the number of key-value pairs contained in the specified metadatum_map.+ *+ * \param[in] metadatum_map A constant pointer to the \ref cardano_metadatum_map_t object for which+ *                       the length is to be retrieved.+ *+ * \return The number of key-value pairs in the metadatum_map. Returns 0 if the metadatum_map is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* metadatum_map = cardano_metadatum_map_new();+ *+ * // Populate the metadatum_map with key-value pairs+ *+ * size_t length = cardano_metadatum_map_get_length(metadatum_map);+ * printf("The length of the metadatum_map is: %zu\n", length);+ *+ * cardano_metadatum_map_unref(&metadatum_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_metadatum_map_get_length(const cardano_metadatum_map_t* metadatum_map);++/**+ * \brief Retrieves the value associated with a given key in the metadatum map.+ *+ * This function retrieves the value associated with the specified key in the provided metadatum map.+ * It returns the value through the output parameter `element`. If the key is not found in the metadatum map,+ * the output parameter `element` will be set to NULL.+ *+ * \param[in] metadatum_map A constant pointer to the \ref cardano_metadatum_map_t object from which+ *                       the value is to be retrieved.+ * \param[in] key The key whose associated value is to be retrieved from the metadatum_map.+ * \param[out] element A pointer to a variable where the retrieved value will be stored. If the key+ *                     is found in the metadatum map, this variable will be set to the associated value.+ *                     If the key is not found, this variable will be set to NULL. The caller is+ *                     responsible for releasing the value by calling \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the value associated with the key was successfully retrieved, or+ *         an appropriate error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* metadatum_map = cardano_metadatum_map_new();+ *+ * // Populate the metadatum_map with key-value pairs+ *+ * cardano_metadatum_t* key = ...; // Create a metadatum object representing the key+ * cardano_metadatum_t* value = NULL;+ * cardano_error_t result = cardano_metadatum_map_get(metadatum_map, key, &value);+ *+ * if (result == CARDANO_SUCCESS && value != NULL)+ * {+ *   // Use the retrieved value+ *   // ...+ *   cardano_metadatum_unref(&value); // Clean up the value resource+ * }+ * else+ * {+ *   // Handle error or key not found+ * }+ *+ * cardano_metadatum_unref(&key); // Clean up the key resource+ * cardano_metadatum_map_unref(&metadatum_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_map_get(cardano_metadatum_map_t* metadatum_map, cardano_metadatum_t* key, cardano_metadatum_t** element);++/**+ * \brief Retrieves the key/value pair at the given index from a metadatum map.+ *+ * Returns the \a index-th entry of \p metadatum_map, providing both the key and the+ * associated value via output parameters. The index is zero-based and must be+ * less than the number of entries in the map.+ *+ * On success, \p *key and \p *element receive strong references to the key and value+ * at the requested position. The caller becomes responsible for releasing both by+ * calling \ref cardano_metadatum_unref on each.+ *+ * \param[in]  metadatum_map A pointer to the \ref cardano_metadatum_map_t to query.+ * \param[in]  index         Zero-based index of the entry to retrieve.+ * \param[out] key           Receives the key metadatum at \p index. Must not be NULL.+ *                           On success, \p *key is non-NULL and must be released with+ *                           \ref cardano_metadatum_unref.+ * \param[out] element       Receives the value metadatum at \p index. Must not be NULL.+ *                           On success, \p *element is non-NULL and must be released with+ *                           \ref cardano_metadatum_unref.+ *+ * \return \ref CARDANO_SUCCESS on success; an appropriate error code otherwise, e.g.:+ *         - \ref CARDANO_ERROR_POINTER_IS_NULL if any required pointer is NULL;+ *         - \ref CARDANO_ERROR_INDEX_OUT_OF_BOUNDS (or equivalent) if \p index is invalid;+ *         - \ref CARDANO_ERROR_ENCODING (or equivalent) if retrieval fails unexpectedly.+ *+ * \note The iteration order is the map’s internal order and may not correspond to insertion order.+ *+ * \par Usage Example+ * \code{.c}+ * size_t len = cardano_metadatum_map_get_length(map);+ *+ * for (size_t i = 0; i < len; ++i)+ * {+ *   cardano_metadatum_t* key = NULL;+ *   cardano_metadatum_t* val = NULL;+ *+ *   cardano_error_t rc = cardano_metadatum_map_get_at(map, i, &key, &val);+ *   if (rc != CARDANO_SUCCESS) {+ *     // handle error...+ *     break;+ *   }+ *+ *   // Use key/val...+ *+ *   cardano_metadatum_unref(&key);+ *   cardano_metadatum_unref(&val);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_map_get_at(+  cardano_metadatum_map_t* metadatum_map,+  size_t                   index,+  cardano_metadatum_t**    key,+  cardano_metadatum_t**    element);++/**+ * \brief Inserts a key-value pair into the metadatum map.+ *+ * This function inserts the specified key-value pair into the provided metadatum map.+ *+ * \param[in] metadatum_map A constant pointer to the \ref cardano_metadatum_map_t object where+ *                       the key-value pair is to be inserted.+ * \param[in] key The key to be inserted into the metadatum map. The caller is responsible for managing+ *                the lifecycle of the key object.+ * \param[in] value The value to be associated with the key and inserted into the metadatum_map.+ *                  The caller is responsible for managing the lifecycle of the value object.+ *+ * \return \ref CARDANO_SUCCESS if the key-value pair was successfully inserted, or an appropriate+ *         error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* metadatum_map = cardano_metadatum_map_new();+ *+ * // Create key and value objects+ * cardano_metadatum_t* key = ...; // Create a metadatum object representing the key+ * cardano_metadatum_t* value = ...; // Create a metadatum object representing the value+ *+ * // Insert the key-value pair into the metadatum_map+ * cardano_error_t result = cardano_metadatum_map_insert(metadatum_map, key, value);+ *+ * if (result != CARDANO_SUCCESS)+ * {+ *   // Handle insertion failure+ * }+ *+ * // Clean up key and value objects+ * cardano_metadatum_unref(&key);+ * cardano_metadatum_unref(&value);+ *+ * cardano_metadatum_map_unref(&metadatum_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_map_insert(cardano_metadatum_map_t* metadatum_map, cardano_metadatum_t* key, cardano_metadatum_t* value);++/**+ * \brief Retrieves the keys from the metadatum map.+ *+ * This function retrieves all the keys from the provided metadatum map and returns them as a list.+ * The caller is responsible for managing the lifecycle of the returned list by calling+ * \ref cardano_metadatum_list_unref when it is no longer needed.+ *+ * \param[in] metadatum_map A constant pointer to the \ref cardano_metadatum_map_t object from which+ *                       the keys are to be retrieved.+ * \param[out] keys A pointer to a variable where the retrieved keys will be stored as a list.+ *                  If successful, this variable will be set to point to the list of keys.+ *                  The caller is responsible for managing the lifecycle of this list.+ *                  It must be released by calling \ref cardano_metadatum_list_unref when no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the keys were successfully retrieved, or an appropriate+ *         error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* metadatum_map = cardano_metadatum_map_new();+ *+ * // Populate the metadatum_map with key-value pairs+ *+ * cardano_metadatum_list_t* keys = NULL;+ * cardano_error_t result = cardano_metadatum_map_get_keys(metadatum_map, &keys);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the list of keys+ *   // Keys must also be freed if retrieved from the list+ *+ *   // Once done, ensure to clean up and release the keys list+ *   cardano_metadatum_list_unref(&keys);+ * }+ * else+ * {+ *   // Handle error+ * }+ *+ * cardano_metadatum_map_unref(&metadatum_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_map_get_keys(cardano_metadatum_map_t* metadatum_map, cardano_metadatum_list_t** keys);++/**+ * \brief Retrieves the values from the metadatum map.+ *+ * This function retrieves all the values from the provided metadatum map and returns them as a list.+ * The caller is responsible for managing the lifecycle of the returned list by calling+ * \ref cardano_metadatum_list_unref when it is no longer needed.+ *+ * \param[in] metadatum_map A constant pointer to the \ref cardano_metadatum_map_t object from which+ *                       the values are to be retrieved.+ * \param[out] values A pointer to a variable where the retrieved values will be stored as a list.+ *                    If successful, this variable will be set to point to the list of values.+ *                    The caller is responsible for managing the lifecycle of this list.+ *                    It must be released by calling \ref cardano_metadatum_list_unref when no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the values were successfully retrieved, or an appropriate+ *         error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* metadatum_map = cardano_metadatum_map_new();+ *+ * // Populate the metadatum_map with key-value pairs+ *+ * cardano_metadatum_list_t* values = NULL;+ * cardano_error_t result = cardano_metadatum_map_get_values(metadatum_map, &values);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the list of values+ *+ *   // Once done, ensure to clean up and release the values list+ *   // Values must also be freed if retrieved from the list+ *   cardano_metadatum_list_unref(&values);+ * }+ * else+ * {+ *   // Handle error+ * }+ *+ * cardano_metadatum_map_unref(&metadatum_map);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_metadatum_map_get_values(cardano_metadatum_map_t* metadatum_map, cardano_metadatum_list_t** values);++/**+ * \brief Checks if two metadatum maps are equal.+ *+ * This function compares two metadatum maps for equality. Two metadatum maps are considered equal if they+ * have the same keys and associated values.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_metadatum_map_t object to be compared.+ * \param[in] rhs A constant pointer to the second \ref cardano_metadatum_map_t object to be compared.+ *+ * \return \c true if the two metadatum maps are equal, otherwise \c false.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* map1 = ...; // Populate the first metadatum map+ * cardano_metadatum_map_t* map2 = ...; // Populate the second metadatum map+ *+ * if (cardano_metadatum_map_equals(map1, map2))+ * {+ *   // The two metadatum maps are equal+ * }+ * else+ * {+ *   // The two metadatum maps are not equal+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_metadatum_map_equals(const cardano_metadatum_map_t* lhs, const cardano_metadatum_map_t* rhs);++/**+ * \brief Decrements the reference count of a metadatum_map object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_metadatum_map_t object+ * by decreasing its reference count. When the reference count reaches zero, the metadatum_map is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] metadatum_map A pointer to the pointer of the metadatum_map object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_metadatum_map_t* metadatum_map = cardano_metadatum_map_new();+ *+ * // Perform operations with the metadatum_map...+ *+ * cardano_metadatum_map_unref(&metadatum_map);+ * // At this point, metadatum_map is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_metadatum_map_unref, the pointer to the \ref cardano_metadatum_map_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_metadatum_map_unref(cardano_metadatum_map_t** metadatum_map);++/**+ * \brief Increases the reference count of the cardano_metadatum_map_t object.+ *+ * This function is used to manually increment the reference count of a metadatum_map+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_metadatum_map_unref.+ *+ * \param metadatum_map A pointer to the metadatum_map object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming metadatum_map is a previously created metadatum_map object+ *+ * cardano_metadatum_map_ref(metadatum_map);+ *+ * // Now metadatum_map can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_metadatum_map_ref there is a corresponding+ * call to \ref cardano_metadatum_map_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_metadatum_map_ref(cardano_metadatum_map_t* metadatum_map);++/**+ * \brief Retrieves the current reference count of the cardano_metadatum_map_t object.+ *+ * This function returns the number of active references to a metadatum_map object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_metadatum_map_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param metadatum_map A pointer to the metadatum_map object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified metadatum_map object. If the object+ * is properly managed (i.e., every \ref cardano_metadatum_map_ref call is matched with a+ * \ref cardano_metadatum_map_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming metadatum_map is a previously created metadatum_map object+ *+ * size_t ref_count = cardano_metadatum_map_refcount(metadatum_map);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_metadatum_map_refcount(const cardano_metadatum_map_t* metadatum_map);++/**+ * \brief Sets the last error message for a given metadatum_map object.+ *+ * Records an error message in the metadatum_map's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] metadatum_map A pointer to the \ref cardano_metadatum_map_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the metadatum_map's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_metadatum_map_set_last_error(cardano_metadatum_map_t* metadatum_map, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific metadatum_map.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_metadatum_map_set_last_error for the given+ * metadatum_map. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] metadatum_map A pointer to the \ref cardano_metadatum_map_t instance whose last error+ *                   message is to be retrieved. If the metadatum_map is NULL, the function+ *                   returns a generic error message indicating the null metadatum_map.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified metadatum_map. If the metadatum_map is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_metadatum_map_set_last_error for the same metadatum_map, or until+ *       the metadatum_map is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_metadatum_map_get_last_error(const cardano_metadatum_map_t* metadatum_map);++/**+ * \brief Creates an independent deep copy of a \ref cardano_metadatum_map_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_metadatum_map_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_metadatum_map_deep_clone(const cardano_metadatum_map_t* source, cardano_metadatum_map_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_METADATUM_MAP_H
+ vendor/include/cardano/auxiliary_data/plutus_v1_script_list.h view
@@ -0,0 +1,455 @@+/**+ * \file plutus_v1_script_list.h+ *+ * \author angel.castillo+ * \date   Sep 17, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V1_SCRIPT_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V1_SCRIPT_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Plutus' scripts are pieces of code that implement pure functions with True or False outputs. These functions take+ * several inputs such as Datum, Redeemer and the transaction context to decide whether an output can be spent or not.+ *+ * V1 was the initial version of Plutus, introduced in the Alonzo hard fork.+ */+typedef struct cardano_plutus_v1_script_t cardano_plutus_v1_script_t;++/**+ * \brief Represents a list of plutus v1 scripts.+ */+typedef struct cardano_plutus_v1_script_list_t cardano_plutus_v1_script_list_t;++/**+ * \brief Creates and initializes a new instance of a plutus_v1_script_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_plutus_v1_script_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] plutus_v1_script_list On successful initialization, this will point to a newly created+ *             \ref cardano_plutus_v1_script_list_t object. This object represents a "strong reference"+ *             to the plutus_v1_script_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the plutus_v1_script_list is no longer needed, the caller must release it+ *             by calling \ref cardano_plutus_v1_script_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the plutus_v1_script_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v1_script_list_t* plutus_v1_script_list = NULL;+ *+ * // Attempt to create a new plutus_v1_script_list+ * cardano_error_t result = cardano_plutus_v1_script_list_new(&plutus_v1_script_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the plutus_v1_script_list+ *+ *   // Once done, ensure to clean up and release the plutus_v1_script_list+ *   cardano_plutus_v1_script_list_unref(&plutus_v1_script_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v1_script_list_new(cardano_plutus_v1_script_list_t** plutus_v1_script_list);++/**+ * \brief Creates a plutus v1 script list from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_plutus_v1_script_list_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a plutus_v1_script.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded plutus_v1_script data.+ * \param[out] plutus_v1_scripts A pointer to a pointer of \ref cardano_plutus_v1_script_list_t that will be set to the address+ *                        of the newly created plutus_v1_script object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the plutus_v1_script was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_plutus_v1_script_list_t object by calling+ *       \ref cardano_plutus_v1_script_list_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_plutus_v1_script_list_t* plutus_v1_script = NULL;+ *+ * cardano_error_t result = cardano_plutus_v1_script_list_from_cbor(reader, &plutus_v1_script);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the plutus_v1_script+ *+ *   // Once done, ensure to clean up and release the plutus_v1_script+ *   cardano_plutus_v1_script_list_unref(&plutus_v1_script);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode plutus_v1_script: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v1_script_list_from_cbor(cardano_cbor_reader_t* reader, cardano_plutus_v1_script_list_t** plutus_v1_scripts);++/**+ * \brief Serializes a plutus_v1_script into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_plutus_v1_script_list_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] plutus_v1_scripts A constant pointer to the \ref cardano_plutus_v1_script_list_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p plutus_v1_script or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v1_script_list_t* plutus_v1_script = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_plutus_v1_script_list_to_cbor(plutus_v1_script, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_plutus_v1_script_list_unref(&plutus_v1_script);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v1_script_list_to_cbor(+  const cardano_plutus_v1_script_list_t* plutus_v1_scripts,+  cardano_cbor_writer_t*                 writer);++/**+ * \brief Serializes a list of Plutus v1 scripts to CIP-116 JSON.+ *+ * Writes a JSON array where each element is a Plutus v1 script object with the shape:+ *+ * \code{.json}+ * [+ *   { "language": "plutus_v1", "bytes": "<hex-bytes>" },+ *   { "language": "plutus_v1", "bytes": "<hex-bytes>" }+ * ]+ * \endcode+ *+ * This function emits the surrounding array brackets (`[` and `]`). It does not write a+ * property name; if you need this list as a field value inside another object, write the+ * property name first (via \ref cardano_json_writer_write_property_name) and then call+ * this function.+ *+ * Keys in each element are emitted in a stable order: `"language"`, then `"bytes"`.+ *+ * \param[in] plutus_v1_scripts A valid pointer to a list of Plutus v1 scripts.+ * \param[in,out] writer        A valid JSON writer. The function writes exactly one JSON array.+ *+ * \return \ref CARDANO_SUCCESS on success, or:+ *         - \ref CARDANO_ERROR_POINTER_IS_NULL if \p plutus_v1_scripts or \p writer is NULL.+ *         - Any error propagated from underlying list accessors or element serialization.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v1_script_list_to_cip116_json(+  const cardano_plutus_v1_script_list_t* plutus_v1_scripts,+  cardano_json_writer_t*                 writer);++/**+ * \brief Retrieves the length of a plutus v1 script list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_plutus_v1_script_list_t object.+ *+ * \param[in] plutus_v1_script_list A constant pointer to the \ref cardano_plutus_v1_script_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the plutus_v1_script_list. Return 0 if the plutus_v1_script_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v1_script_list_t* plutus_v1_script_list = cardano_plutus_v1_script_list_new();+ *+ * // Populate plutus_v1_script_list with elements+ *+ * size_t length = cardano_plutus_v1_script_list_get_length(plutus_v1_script_list);+ * printf("Length of the plutus_v1_script_list: %zu\n", length);+ *+ * // Clean up the plutus_v1_script_list object once done+ * cardano_plutus_v1_script_list_unref(&plutus_v1_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_plutus_v1_script_list_get_length(const cardano_plutus_v1_script_list_t* plutus_v1_script_list);++/**+ * \brief Retrieves an element from a plutus v1 script list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_plutus_v1_script_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] plutus_v1_script_list A constant pointer to the \ref cardano_plutus_v1_script_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the plutus v1 script list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_plutus_v1_script_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_plutus_v1_script_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v1_script_list_t* plutus_v1_script_list = cardano_plutus_v1_script_list_new();+ *+ * // Populate plutus_v1_script_list with elements+ *+ * cardano_plutus_v1_script_t* element = NULL;+ * cardano_error_t result = cardano_plutus_v1_script_list_get(plutus_v1_script_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_plutus_v1_script_unref(&element);+ * }+ *+ * // Clean up the plutus_v1_script_list object once done+ * cardano_plutus_v1_script_list_unref(&plutus_v1_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v1_script_list_get(const cardano_plutus_v1_script_list_t* plutus_v1_script_list, size_t index, cardano_plutus_v1_script_t** element);++/**+ * \brief Adds an element to a plutus v1 script list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_plutus_v1_script_list_t object.+ *+ * \param[in] plutus_v1_script_list A constant pointer to the \ref cardano_plutus_v1_script_list_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_plutus_v1_script_t object that is to be added to the plutus_v1_script_list.+ *                    The element will be referenced by the plutus_v1_script_list after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the plutus_v1_script_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v1_script_list_t* plutus_v1_script_list = cardano_plutus_v1_script_list_new();+ *+ * // Create and initialize a new plutus v1 script element+ * cardano_plutus_v1_script_t* element = { ... };+ *+ * // Add the element to the plutus_v1_script_list+ * cardano_error_t result = cardano_plutus_v1_script_list_add(plutus_v1_script_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the plutus_v1_script_list object once done+ * cardano_plutus_v1_script_list_unref(&plutus_v1_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v1_script_list_add(cardano_plutus_v1_script_list_t* plutus_v1_script_list, cardano_plutus_v1_script_t* element);++/**+ * \brief Decrements the reference count of a plutus_v1_script_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_plutus_v1_script_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the plutus_v1_script_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] plutus_v1_script_list A pointer to the pointer of the plutus_v1_script_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v1_script_list_t* plutus_v1_script_list = cardano_plutus_v1_script_list_new();+ *+ * // Perform operations with the plutus_v1_script_list...+ *+ * cardano_plutus_v1_script_list_unref(&plutus_v1_script_list);+ * // At this point, plutus_v1_script_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_plutus_v1_script_list_unref, the pointer to the \ref cardano_plutus_v1_script_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_plutus_v1_script_list_unref(cardano_plutus_v1_script_list_t** plutus_v1_script_list);++/**+ * \brief Increases the reference count of the cardano_plutus_v1_script_list_t object.+ *+ * This function is used to manually increment the reference count of a plutus_v1_script_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_plutus_v1_script_list_unref.+ *+ * \param plutus_v1_script_list A pointer to the plutus_v1_script_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming plutus_v1_script_list is a previously created plutus_v1_script_list object+ *+ * cardano_plutus_v1_script_list_ref(plutus_v1_script_list);+ *+ * // Now plutus_v1_script_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_plutus_v1_script_list_ref there is a corresponding+ * call to \ref cardano_plutus_v1_script_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_plutus_v1_script_list_ref(cardano_plutus_v1_script_list_t* plutus_v1_script_list);++/**+ * \brief Retrieves the current reference count of the cardano_plutus_v1_script_list_t object.+ *+ * This function returns the number of active references to a plutus_v1_script_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_plutus_v1_script_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param plutus_v1_script_list A pointer to the plutus_v1_script_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified plutus_v1_script_list object. If the object+ * is properly managed (i.e., every \ref cardano_plutus_v1_script_list_ref call is matched with a+ * \ref cardano_plutus_v1_script_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming plutus_v1_script_list is a previously created plutus_v1_script_list object+ *+ * size_t ref_count = cardano_plutus_v1_script_list_refcount(plutus_v1_script_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_plutus_v1_script_list_refcount(const cardano_plutus_v1_script_list_t* plutus_v1_script_list);++/**+ * \brief Sets the last error message for a given plutus_v1_script_list object.+ *+ * Records an error message in the plutus_v1_script_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] plutus_v1_script_list A pointer to the \ref cardano_plutus_v1_script_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the plutus_v1_script_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_plutus_v1_script_list_set_last_error(cardano_plutus_v1_script_list_t* plutus_v1_script_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific plutus_v1_script_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_plutus_v1_script_list_set_last_error for the given+ * plutus_v1_script_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] plutus_v1_script_list A pointer to the \ref cardano_plutus_v1_script_list_t instance whose last error+ *                   message is to be retrieved. If the plutus_v1_script_list is NULL, the function+ *                   returns a generic error message indicating the null plutus_v1_script_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified plutus_v1_script_list. If the plutus_v1_script_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_plutus_v1_script_list_set_last_error for the same plutus_v1_script_list, or until+ *       the plutus_v1_script_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_plutus_v1_script_list_get_last_error(const cardano_plutus_v1_script_list_t* plutus_v1_script_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_plutus_v1_script_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_plutus_v1_script_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_plutus_v1_script_list_deep_clone(const cardano_plutus_v1_script_list_t* source, cardano_plutus_v1_script_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V1_SCRIPT_LIST_H
+ vendor/include/cardano/auxiliary_data/plutus_v2_script_list.h view
@@ -0,0 +1,463 @@+/**+ * \file plutus_v2_script_list.h+ *+ * \author angel.castillo+ * \date   Sep 17, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V2_SCRIPT_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V2_SCRIPT_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Plutus' scripts are pieces of code that implement pure functions with True or False outputs. These functions take+ * several inputs such as Datum, Redeemer and the transaction context to decide whether an output can be spent or not.+ *+ * V2 was introduced in the Vasil hard fork.+ *+ * The main changes in V2 of Plutus were to the interface to scripts. The ScriptContext was extended+ * to include the following information:+ *+ *  - The full “redeemers” structure, which contains all the redeemers used in the transaction+ *  - Reference inputs in the transaction (proposed in CIP-31)+ *  - Inline datums in the transaction (proposed in CIP-32)+ *  - Reference scripts in the transaction (proposed in CIP-33)+ */+typedef struct cardano_plutus_v2_script_t cardano_plutus_v2_script_t;++/**+ * \brief Represents a list of plutus v2 scripts.+ */+typedef struct cardano_plutus_v2_script_list_t cardano_plutus_v2_script_list_t;++/**+ * \brief Creates and initializes a new instance of a plutus_v2_script_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_plutus_v2_script_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] plutus_v2_script_list On successful initialization, this will point to a newly created+ *             \ref cardano_plutus_v2_script_list_t object. This object represents a "strong reference"+ *             to the plutus_v2_script_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the plutus_v2_script_list is no longer needed, the caller must release it+ *             by calling \ref cardano_plutus_v2_script_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the plutus_v2_script_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v2_script_list_t* plutus_v2_script_list = NULL;+ *+ * // Attempt to create a new plutus_v2_script_list+ * cardano_error_t result = cardano_plutus_v2_script_list_new(&plutus_v2_script_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the plutus_v2_script_list+ *+ *   // Once done, ensure to clean up and release the plutus_v2_script_list+ *   cardano_plutus_v2_script_list_unref(&plutus_v2_script_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v2_script_list_new(cardano_plutus_v2_script_list_t** plutus_v2_script_list);++/**+ * \brief Creates a plutus v2 script list from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_plutus_v2_script_list_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a plutus_v2_script.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded plutus_v2_script data.+ * \param[out] plutus_v2_scripts A pointer to a pointer of \ref cardano_plutus_v2_script_list_t that will be set to the address+ *                        of the newly created plutus_v2_script object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the plutus_v2_script was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_plutus_v2_script_list_t object by calling+ *       \ref cardano_plutus_v2_script_list_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_plutus_v2_script_list_t* plutus_v2_script = NULL;+ *+ * cardano_error_t result = cardano_plutus_v2_script_list_from_cbor(reader, &plutus_v2_script);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the plutus_v2_script+ *+ *   // Once done, ensure to clean up and release the plutus_v2_script+ *   cardano_plutus_v2_script_list_unref(&plutus_v2_script);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode plutus_v2_script: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v2_script_list_from_cbor(cardano_cbor_reader_t* reader, cardano_plutus_v2_script_list_t** plutus_v2_scripts);++/**+ * \brief Serializes a plutus_v2_script into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_plutus_v2_script_list_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] plutus_v2_scripts A constant pointer to the \ref cardano_plutus_v2_script_list_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p plutus_v2_script or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v2_script_list_t* plutus_v2_script = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_plutus_v2_script_list_to_cbor(plutus_v2_script, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_plutus_v2_script_list_unref(&plutus_v2_script);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v2_script_list_to_cbor(+  const cardano_plutus_v2_script_list_t* plutus_v2_scripts,+  cardano_cbor_writer_t*                 writer);++/**+ * \brief Serializes a list of Plutus v2 scripts to CIP-116 JSON.+ *+ * Writes a JSON array where each element is a Plutus v2 script object with the shape:+ *+ * \code{.json}+ * [+ *   { "language": "plutus_v2", "bytes": "<hex-bytes>" },+ *   { "language": "plutus_v2", "bytes": "<hex-bytes>" }+ * ]+ * \endcode+ *+ * This function emits the surrounding array brackets (`[` and `]`). It does not write a+ * property name; if you need this list as a field value inside another object, write the+ * property name first (via \ref cardano_json_writer_write_property_name) and then call+ * this function.+ *+ * Keys in each element are emitted in a stable order: `"language"`, then `"bytes"`.+ *+ * \param[in] plutus_v2_scripts A valid pointer to a list of Plutus v2 scripts.+ * \param[in,out] writer        A valid JSON writer. The function writes exactly one JSON array.+ *+ * \return \ref CARDANO_SUCCESS on success, or:+ *         - \ref CARDANO_ERROR_POINTER_IS_NULL if \p plutus_v2_scripts or \p writer is NULL.+ *         - Any error propagated from underlying list accessors or element serialization.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v2_script_list_to_cip116_json(+  const cardano_plutus_v2_script_list_t* plutus_v2_scripts,+  cardano_json_writer_t*                 writer);++/**+ * \brief Retrieves the length of a plutus v2 script list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_plutus_v2_script_list_t object.+ *+ * \param[in] plutus_v2_script_list A constant pointer to the \ref cardano_plutus_v2_script_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the plutus_v2_script_list. Return 0 if the plutus_v2_script_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v2_script_list_t* plutus_v2_script_list = cardano_plutus_v2_script_list_new();+ *+ * // Populate plutus_v2_script_list with elements+ *+ * size_t length = cardano_plutus_v2_script_list_get_length(plutus_v2_script_list);+ * printf("Length of the plutus_v2_script_list: %zu\n", length);+ *+ * // Clean up the plutus_v2_script_list object once done+ * cardano_plutus_v2_script_list_unref(&plutus_v2_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_plutus_v2_script_list_get_length(const cardano_plutus_v2_script_list_t* plutus_v2_script_list);++/**+ * \brief Retrieves an element from a plutus v2 script list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_plutus_v2_script_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] plutus_v2_script_list A constant pointer to the \ref cardano_plutus_v2_script_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the plutus v2 script list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_plutus_v2_script_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_plutus_v2_script_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v2_script_list_t* plutus_v2_script_list = cardano_plutus_v2_script_list_new();+ *+ * // Populate plutus_v2_script_list with elements+ *+ * cardano_plutus_v2_script_t* element = NULL;+ * cardano_error_t result = cardano_plutus_v2_script_list_get(plutus_v2_script_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_plutus_v2_script_unref(&element);+ * }+ *+ * // Clean up the plutus_v2_script_list object once done+ * cardano_plutus_v2_script_list_unref(&plutus_v2_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v2_script_list_get(const cardano_plutus_v2_script_list_t* plutus_v2_script_list, size_t index, cardano_plutus_v2_script_t** element);++/**+ * \brief Adds an element to a plutus v2 script list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_plutus_v2_script_list_t object.+ *+ * \param[in] plutus_v2_script_list A constant pointer to the \ref cardano_plutus_v2_script_list_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_plutus_v2_script_t object that is to be added to the plutus_v2_script_list.+ *                    The element will be referenced by the plutus_v2_script_list after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the plutus_v2_script_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v2_script_list_t* plutus_v2_script_list = cardano_plutus_v2_script_list_new();+ *+ * // Create and initialize a new plutus v2 script element+ * cardano_plutus_v2_script_t* element = { ... };+ *+ * // Add the element to the plutus_v2_script_list+ * cardano_error_t result = cardano_plutus_v2_script_list_add(plutus_v2_script_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the plutus_v2_script_list object once done+ * cardano_plutus_v2_script_list_unref(&plutus_v2_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v2_script_list_add(cardano_plutus_v2_script_list_t* plutus_v2_script_list, cardano_plutus_v2_script_t* element);++/**+ * \brief Decrements the reference count of a plutus_v2_script_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_plutus_v2_script_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the plutus_v2_script_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] plutus_v2_script_list A pointer to the pointer of the plutus_v2_script_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v2_script_list_t* plutus_v2_script_list = cardano_plutus_v2_script_list_new();+ *+ * // Perform operations with the plutus_v2_script_list...+ *+ * cardano_plutus_v2_script_list_unref(&plutus_v2_script_list);+ * // At this point, plutus_v2_script_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_plutus_v2_script_list_unref, the pointer to the \ref cardano_plutus_v2_script_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_plutus_v2_script_list_unref(cardano_plutus_v2_script_list_t** plutus_v2_script_list);++/**+ * \brief Increases the reference count of the cardano_plutus_v2_script_list_t object.+ *+ * This function is used to manually increment the reference count of a plutus_v2_script_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_plutus_v2_script_list_unref.+ *+ * \param plutus_v2_script_list A pointer to the plutus_v2_script_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming plutus_v2_script_list is a previously created plutus_v2_script_list object+ *+ * cardano_plutus_v2_script_list_ref(plutus_v2_script_list);+ *+ * // Now plutus_v2_script_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_plutus_v2_script_list_ref there is a corresponding+ * call to \ref cardano_plutus_v2_script_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_plutus_v2_script_list_ref(cardano_plutus_v2_script_list_t* plutus_v2_script_list);++/**+ * \brief Retrieves the current reference count of the cardano_plutus_v2_script_list_t object.+ *+ * This function returns the number of active references to a plutus_v2_script_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_plutus_v2_script_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param plutus_v2_script_list A pointer to the plutus_v2_script_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified plutus_v2_script_list object. If the object+ * is properly managed (i.e., every \ref cardano_plutus_v2_script_list_ref call is matched with a+ * \ref cardano_plutus_v2_script_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming plutus_v2_script_list is a previously created plutus_v2_script_list object+ *+ * size_t ref_count = cardano_plutus_v2_script_list_refcount(plutus_v2_script_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_plutus_v2_script_list_refcount(const cardano_plutus_v2_script_list_t* plutus_v2_script_list);++/**+ * \brief Sets the last error message for a given plutus_v2_script_list object.+ *+ * Records an error message in the plutus_v2_script_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] plutus_v2_script_list A pointer to the \ref cardano_plutus_v2_script_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the plutus_v2_script_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_plutus_v2_script_list_set_last_error(cardano_plutus_v2_script_list_t* plutus_v2_script_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific plutus_v2_script_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_plutus_v2_script_list_set_last_error for the given+ * plutus_v2_script_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] plutus_v2_script_list A pointer to the \ref cardano_plutus_v2_script_list_t instance whose last error+ *                   message is to be retrieved. If the plutus_v2_script_list is NULL, the function+ *                   returns a generic error message indicating the null plutus_v2_script_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified plutus_v2_script_list. If the plutus_v2_script_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_plutus_v2_script_list_set_last_error for the same plutus_v2_script_list, or until+ *       the plutus_v2_script_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_plutus_v2_script_list_get_last_error(const cardano_plutus_v2_script_list_t* plutus_v2_script_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_plutus_v2_script_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_plutus_v2_script_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_plutus_v2_script_list_deep_clone(const cardano_plutus_v2_script_list_t* source, cardano_plutus_v2_script_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V2_SCRIPT_LIST_H
+ vendor/include/cardano/auxiliary_data/plutus_v3_script_list.h view
@@ -0,0 +1,463 @@+/**+ * \file plutus_v3_script_list.h+ *+ * \author angel.castillo+ * \date   Sep 17, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V3_SCRIPT_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V3_SCRIPT_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Plutus' scripts are pieces of code that implement pure functions with True or False outputs. These functions take+ * several inputs such as Datum, Redeemer and the transaction context to decide whether an output can be spent or not.+ *+ * V3 was introduced in the Conway hard fork.+ *+ * The main changes in V3 of Plutus were to the interface to scripts. The ScriptContext was extended+ * to include the following information:+ *+ *  - A Map with all the votes that were included in the transaction.+ *  - A list with Proposals that will be turned into GovernanceActions, that everyone can vote on+ *  - Optional amount for the current treasury. If included it will be checked to be equal the current amount in the treasury.+ *  - Optional amount for donating to the current treasury. If included, specified amount will go into the treasury.+ */+typedef struct cardano_plutus_v3_script_t cardano_plutus_v3_script_t;++/**+ * \brief Represents a list of plutus v3 scripts.+ */+typedef struct cardano_plutus_v3_script_list_t cardano_plutus_v3_script_list_t;++/**+ * \brief Creates and initializes a new instance of a plutus_v3_script_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_plutus_v3_script_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] plutus_v3_script_list On successful initialization, this will point to a newly created+ *             \ref cardano_plutus_v3_script_list_t object. This object represents a "strong reference"+ *             to the plutus_v3_script_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the plutus_v3_script_list is no longer needed, the caller must release it+ *             by calling \ref cardano_plutus_v3_script_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the plutus_v3_script_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v3_script_list_t* plutus_v3_script_list = NULL;+ *+ * // Attempt to create a new plutus_v3_script_list+ * cardano_error_t result = cardano_plutus_v3_script_list_new(&plutus_v3_script_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the plutus_v3_script_list+ *+ *   // Once done, ensure to clean up and release the plutus_v3_script_list+ *   cardano_plutus_v3_script_list_unref(&plutus_v3_script_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v3_script_list_new(cardano_plutus_v3_script_list_t** plutus_v3_script_list);++/**+ * \brief Creates a plutus v3 script list from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_plutus_v3_script_list_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a plutus_v3_script.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded plutus_v3_script data.+ * \param[out] plutus_v3_scripts A pointer to a pointer of \ref cardano_plutus_v3_script_list_t that will be set to the address+ *                        of the newly created plutus_v3_script object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the plutus_v3_script was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_plutus_v3_script_list_t object by calling+ *       \ref cardano_plutus_v3_script_list_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_plutus_v3_script_list_t* plutus_v3_script = NULL;+ *+ * cardano_error_t result = cardano_plutus_v3_script_list_from_cbor(reader, &plutus_v3_script);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the plutus_v3_script+ *+ *   // Once done, ensure to clean up and release the plutus_v3_script+ *   cardano_plutus_v3_script_list_unref(&plutus_v3_script);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode plutus_v3_script: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v3_script_list_from_cbor(cardano_cbor_reader_t* reader, cardano_plutus_v3_script_list_t** plutus_v3_scripts);++/**+ * \brief Serializes a plutus_v3_script into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_plutus_v3_script_list_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] plutus_v3_scripts A constant pointer to the \ref cardano_plutus_v3_script_list_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p plutus_v3_script or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v3_script_list_t* plutus_v3_script = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_plutus_v3_script_list_to_cbor(plutus_v3_script, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_plutus_v3_script_list_unref(&plutus_v3_script);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v3_script_list_to_cbor(+  const cardano_plutus_v3_script_list_t* plutus_v3_scripts,+  cardano_cbor_writer_t*                 writer);++/**+ * \brief Serializes a list of Plutus v3 scripts to CIP-116 JSON.+ *+ * Writes a JSON array where each element is a Plutus v3 script object with the shape:+ *+ * \code{.json}+ * [+ *   { "language": "plutus_v3", "bytes": "<hex-bytes>" },+ *   { "language": "plutus_v3", "bytes": "<hex-bytes>" }+ * ]+ * \endcode+ *+ * This function emits the surrounding array brackets (`[` and `]`). It does not write a+ * property name; if you need this list as a field value inside another object, write the+ * property name first (via \ref cardano_json_writer_write_property_name) and then call+ * this function.+ *+ * Keys in each element are emitted in a stable order: `"language"`, then `"bytes"`.+ *+ * \param[in] plutus_v3_scripts A valid pointer to a list of Plutus v3 scripts.+ * \param[in,out] writer        A valid JSON writer. The function writes exactly one JSON array.+ *+ * \return \ref CARDANO_SUCCESS on success, or:+ *         - \ref CARDANO_ERROR_POINTER_IS_NULL if \p plutus_v3_scripts or \p writer is NULL.+ *         - Any error propagated from underlying list accessors or element serialization.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v3_script_list_to_cip116_json(+  const cardano_plutus_v3_script_list_t* plutus_v3_scripts,+  cardano_json_writer_t*                 writer);++/**+ * \brief Retrieves the length of a plutus v3 script list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_plutus_v3_script_list_t object.+ *+ * \param[in] plutus_v3_script_list A constant pointer to the \ref cardano_plutus_v3_script_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the plutus_v3_script_list. Return 0 if the plutus_v3_script_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v3_script_list_t* plutus_v3_script_list = cardano_plutus_v3_script_list_new();+ *+ * // Populate plutus_v3_script_list with elements+ *+ * size_t length = cardano_plutus_v3_script_list_get_length(plutus_v3_script_list);+ * printf("Length of the plutus_v3_script_list: %zu\n", length);+ *+ * // Clean up the plutus_v3_script_list object once done+ * cardano_plutus_v3_script_list_unref(&plutus_v3_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_plutus_v3_script_list_get_length(const cardano_plutus_v3_script_list_t* plutus_v3_script_list);++/**+ * \brief Retrieves an element from a plutus v3 script list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_plutus_v3_script_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] plutus_v3_script_list A constant pointer to the \ref cardano_plutus_v3_script_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the plutus v3 script list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_plutus_v3_script_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_plutus_v3_script_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v3_script_list_t* plutus_v3_script_list = cardano_plutus_v3_script_list_new();+ *+ * // Populate plutus_v3_script_list with elements+ *+ * cardano_plutus_v3_script_t* element = NULL;+ * cardano_error_t result = cardano_plutus_v3_script_list_get(plutus_v3_script_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_plutus_v3_script_unref(&element);+ * }+ *+ * // Clean up the plutus_v3_script_list object once done+ * cardano_plutus_v3_script_list_unref(&plutus_v3_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v3_script_list_get(const cardano_plutus_v3_script_list_t* plutus_v3_script_list, size_t index, cardano_plutus_v3_script_t** element);++/**+ * \brief Adds an element to a plutus v3 script list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_plutus_v3_script_list_t object.+ *+ * \param[in] plutus_v3_script_list A constant pointer to the \ref cardano_plutus_v3_script_list_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_plutus_v3_script_t object that is to be added to the plutus_v3_script_list.+ *                    The element will be referenced by the plutus_v3_script_list after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the plutus_v3_script_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v3_script_list_t* plutus_v3_script_list = cardano_plutus_v3_script_list_new();+ *+ * // Create and initialize a new plutus v3 script element+ * cardano_plutus_v3_script_t* element = { ... };+ *+ * // Add the element to the plutus_v3_script_list+ * cardano_error_t result = cardano_plutus_v3_script_list_add(plutus_v3_script_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the plutus_v3_script_list object once done+ * cardano_plutus_v3_script_list_unref(&plutus_v3_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v3_script_list_add(cardano_plutus_v3_script_list_t* plutus_v3_script_list, cardano_plutus_v3_script_t* element);++/**+ * \brief Decrements the reference count of a plutus_v3_script_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_plutus_v3_script_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the plutus_v3_script_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] plutus_v3_script_list A pointer to the pointer of the plutus_v3_script_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v3_script_list_t* plutus_v3_script_list = cardano_plutus_v3_script_list_new();+ *+ * // Perform operations with the plutus_v3_script_list...+ *+ * cardano_plutus_v3_script_list_unref(&plutus_v3_script_list);+ * // At this point, plutus_v3_script_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_plutus_v3_script_list_unref, the pointer to the \ref cardano_plutus_v3_script_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_plutus_v3_script_list_unref(cardano_plutus_v3_script_list_t** plutus_v3_script_list);++/**+ * \brief Increases the reference count of the cardano_plutus_v3_script_list_t object.+ *+ * This function is used to manually increment the reference count of a plutus_v3_script_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_plutus_v3_script_list_unref.+ *+ * \param plutus_v3_script_list A pointer to the plutus_v3_script_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming plutus_v3_script_list is a previously created plutus_v3_script_list object+ *+ * cardano_plutus_v3_script_list_ref(plutus_v3_script_list);+ *+ * // Now plutus_v3_script_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_plutus_v3_script_list_ref there is a corresponding+ * call to \ref cardano_plutus_v3_script_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_plutus_v3_script_list_ref(cardano_plutus_v3_script_list_t* plutus_v3_script_list);++/**+ * \brief Retrieves the current reference count of the cardano_plutus_v3_script_list_t object.+ *+ * This function returns the number of active references to a plutus_v3_script_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_plutus_v3_script_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param plutus_v3_script_list A pointer to the plutus_v3_script_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified plutus_v3_script_list object. If the object+ * is properly managed (i.e., every \ref cardano_plutus_v3_script_list_ref call is matched with a+ * \ref cardano_plutus_v3_script_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming plutus_v3_script_list is a previously created plutus_v3_script_list object+ *+ * size_t ref_count = cardano_plutus_v3_script_list_refcount(plutus_v3_script_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_plutus_v3_script_list_refcount(const cardano_plutus_v3_script_list_t* plutus_v3_script_list);++/**+ * \brief Sets the last error message for a given plutus_v3_script_list object.+ *+ * Records an error message in the plutus_v3_script_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] plutus_v3_script_list A pointer to the \ref cardano_plutus_v3_script_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the plutus_v3_script_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_plutus_v3_script_list_set_last_error(cardano_plutus_v3_script_list_t* plutus_v3_script_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific plutus_v3_script_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_plutus_v3_script_list_set_last_error for the given+ * plutus_v3_script_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] plutus_v3_script_list A pointer to the \ref cardano_plutus_v3_script_list_t instance whose last error+ *                   message is to be retrieved. If the plutus_v3_script_list is NULL, the function+ *                   returns a generic error message indicating the null plutus_v3_script_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified plutus_v3_script_list. If the plutus_v3_script_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_plutus_v3_script_list_set_last_error for the same plutus_v3_script_list, or until+ *       the plutus_v3_script_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_plutus_v3_script_list_get_last_error(const cardano_plutus_v3_script_list_t* plutus_v3_script_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_plutus_v3_script_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_plutus_v3_script_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_plutus_v3_script_list_deep_clone(const cardano_plutus_v3_script_list_t* source, cardano_plutus_v3_script_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V3_SCRIPT_LIST_H
+ vendor/include/cardano/auxiliary_data/plutus_v4_script_list.h view
@@ -0,0 +1,459 @@+/**+ * \file plutus_v4_script_list.h+ *+ * \author angel.castillo+ * \date   Jul 17, 2026+ *+ * Copyright 2026 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V4_SCRIPT_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V4_SCRIPT_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Plutus' scripts are pieces of code that implement pure functions with True or False outputs. These functions take+ * several inputs such as Datum, Redeemer and the transaction context to decide whether an output can be spent or not.+ *+ * V4 was introduced in the Dijkstra hard fork.+ *+ * V4 scripts run from protocol version 12. They can be serialized in transactions as witness set+ * scripts, reference scripts or auxiliary data scripts, and they are the only Plutus scripts that+ * run inside a sub transaction.+ */+typedef struct cardano_plutus_v4_script_t cardano_plutus_v4_script_t;++/**+ * \brief Represents a list of plutus v4 scripts.+ */+typedef struct cardano_plutus_v4_script_list_t cardano_plutus_v4_script_list_t;++/**+ * \brief Creates and initializes a new instance of a plutus_v4_script_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_plutus_v4_script_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] plutus_v4_script_list On successful initialization, this will point to a newly created+ *             \ref cardano_plutus_v4_script_list_t object. This object represents a "strong reference"+ *             to the plutus_v4_script_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the plutus_v4_script_list is no longer needed, the caller must release it+ *             by calling \ref cardano_plutus_v4_script_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the plutus_v4_script_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v4_script_list_t* plutus_v4_script_list = NULL;+ *+ * // Attempt to create a new plutus_v4_script_list+ * cardano_error_t result = cardano_plutus_v4_script_list_new(&plutus_v4_script_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the plutus_v4_script_list+ *+ *   // Once done, ensure to clean up and release the plutus_v4_script_list+ *   cardano_plutus_v4_script_list_unref(&plutus_v4_script_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v4_script_list_new(cardano_plutus_v4_script_list_t** plutus_v4_script_list);++/**+ * \brief Creates a plutus v4 script list from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_plutus_v4_script_list_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a plutus_v4_script.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded plutus_v4_script data.+ * \param[out] plutus_v4_scripts A pointer to a pointer of \ref cardano_plutus_v4_script_list_t that will be set to the address+ *                        of the newly created plutus_v4_script object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the plutus_v4_script was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_plutus_v4_script_list_t object by calling+ *       \ref cardano_plutus_v4_script_list_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_plutus_v4_script_list_t* plutus_v4_script = NULL;+ *+ * cardano_error_t result = cardano_plutus_v4_script_list_from_cbor(reader, &plutus_v4_script);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the plutus_v4_script+ *+ *   // Once done, ensure to clean up and release the plutus_v4_script+ *   cardano_plutus_v4_script_list_unref(&plutus_v4_script);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode plutus_v4_script: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v4_script_list_from_cbor(cardano_cbor_reader_t* reader, cardano_plutus_v4_script_list_t** plutus_v4_scripts);++/**+ * \brief Serializes a plutus_v4_script into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_plutus_v4_script_list_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] plutus_v4_scripts A constant pointer to the \ref cardano_plutus_v4_script_list_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p plutus_v4_script or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v4_script_list_t* plutus_v4_script = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_plutus_v4_script_list_to_cbor(plutus_v4_script, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_plutus_v4_script_list_unref(&plutus_v4_script);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v4_script_list_to_cbor(+  const cardano_plutus_v4_script_list_t* plutus_v4_scripts,+  cardano_cbor_writer_t*                 writer);++/**+ * \brief Serializes a list of Plutus v4 scripts to CIP-116 JSON.+ *+ * Writes a JSON array where each element is a Plutus v4 script object with the shape:+ *+ * \code{.json}+ * [+ *   { "language": "plutus_v4", "bytes": "<hex-bytes>" },+ *   { "language": "plutus_v4", "bytes": "<hex-bytes>" }+ * ]+ * \endcode+ *+ * This function emits the surrounding array brackets (`[` and `]`). It does not write a+ * property name; if you need this list as a field value inside another object, write the+ * property name first (via \ref cardano_json_writer_write_property_name) and then call+ * this function.+ *+ * Keys in each element are emitted in a stable order: `"language"`, then `"bytes"`.+ *+ * \param[in] plutus_v4_scripts A valid pointer to a list of Plutus v4 scripts.+ * \param[in,out] writer        A valid JSON writer. The function writes exactly one JSON array.+ *+ * \return \ref CARDANO_SUCCESS on success, or:+ *         - \ref CARDANO_ERROR_POINTER_IS_NULL if \p plutus_v4_scripts or \p writer is NULL.+ *         - Any error propagated from underlying list accessors or element serialization.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_plutus_v4_script_list_to_cip116_json(+  const cardano_plutus_v4_script_list_t* plutus_v4_scripts,+  cardano_json_writer_t*                 writer);++/**+ * \brief Retrieves the length of a plutus v4 script list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_plutus_v4_script_list_t object.+ *+ * \param[in] plutus_v4_script_list A constant pointer to the \ref cardano_plutus_v4_script_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the plutus_v4_script_list. Return 0 if the plutus_v4_script_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v4_script_list_t* plutus_v4_script_list = cardano_plutus_v4_script_list_new();+ *+ * // Populate plutus_v4_script_list with elements+ *+ * size_t length = cardano_plutus_v4_script_list_get_length(plutus_v4_script_list);+ * printf("Length of the plutus_v4_script_list: %zu\n", length);+ *+ * // Clean up the plutus_v4_script_list object once done+ * cardano_plutus_v4_script_list_unref(&plutus_v4_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_plutus_v4_script_list_get_length(const cardano_plutus_v4_script_list_t* plutus_v4_script_list);++/**+ * \brief Retrieves an element from a plutus v4 script list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_plutus_v4_script_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] plutus_v4_script_list A constant pointer to the \ref cardano_plutus_v4_script_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the plutus v4 script list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_plutus_v4_script_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_plutus_v4_script_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v4_script_list_t* plutus_v4_script_list = cardano_plutus_v4_script_list_new();+ *+ * // Populate plutus_v4_script_list with elements+ *+ * cardano_plutus_v4_script_t* element = NULL;+ * cardano_error_t result = cardano_plutus_v4_script_list_get(plutus_v4_script_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_plutus_v4_script_unref(&element);+ * }+ *+ * // Clean up the plutus_v4_script_list object once done+ * cardano_plutus_v4_script_list_unref(&plutus_v4_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v4_script_list_get(const cardano_plutus_v4_script_list_t* plutus_v4_script_list, size_t index, cardano_plutus_v4_script_t** element);++/**+ * \brief Adds an element to a plutus v4 script list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_plutus_v4_script_list_t object.+ *+ * \param[in] plutus_v4_script_list A constant pointer to the \ref cardano_plutus_v4_script_list_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_plutus_v4_script_t object that is to be added to the plutus_v4_script_list.+ *                    The element will be referenced by the plutus_v4_script_list after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the plutus_v4_script_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v4_script_list_t* plutus_v4_script_list = cardano_plutus_v4_script_list_new();+ *+ * // Create and initialize a new plutus v4 script element+ * cardano_plutus_v4_script_t* element = { ... };+ *+ * // Add the element to the plutus_v4_script_list+ * cardano_error_t result = cardano_plutus_v4_script_list_add(plutus_v4_script_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the plutus_v4_script_list object once done+ * cardano_plutus_v4_script_list_unref(&plutus_v4_script_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_plutus_v4_script_list_add(cardano_plutus_v4_script_list_t* plutus_v4_script_list, cardano_plutus_v4_script_t* element);++/**+ * \brief Decrements the reference count of a plutus_v4_script_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_plutus_v4_script_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the plutus_v4_script_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] plutus_v4_script_list A pointer to the pointer of the plutus_v4_script_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_v4_script_list_t* plutus_v4_script_list = cardano_plutus_v4_script_list_new();+ *+ * // Perform operations with the plutus_v4_script_list...+ *+ * cardano_plutus_v4_script_list_unref(&plutus_v4_script_list);+ * // At this point, plutus_v4_script_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_plutus_v4_script_list_unref, the pointer to the \ref cardano_plutus_v4_script_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_plutus_v4_script_list_unref(cardano_plutus_v4_script_list_t** plutus_v4_script_list);++/**+ * \brief Increases the reference count of the cardano_plutus_v4_script_list_t object.+ *+ * This function is used to manually increment the reference count of a plutus_v4_script_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_plutus_v4_script_list_unref.+ *+ * \param plutus_v4_script_list A pointer to the plutus_v4_script_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming plutus_v4_script_list is a previously created plutus_v4_script_list object+ *+ * cardano_plutus_v4_script_list_ref(plutus_v4_script_list);+ *+ * // Now plutus_v4_script_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_plutus_v4_script_list_ref there is a corresponding+ * call to \ref cardano_plutus_v4_script_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_plutus_v4_script_list_ref(cardano_plutus_v4_script_list_t* plutus_v4_script_list);++/**+ * \brief Retrieves the current reference count of the cardano_plutus_v4_script_list_t object.+ *+ * This function returns the number of active references to a plutus_v4_script_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_plutus_v4_script_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param plutus_v4_script_list A pointer to the plutus_v4_script_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified plutus_v4_script_list object. If the object+ * is properly managed (i.e., every \ref cardano_plutus_v4_script_list_ref call is matched with a+ * \ref cardano_plutus_v4_script_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming plutus_v4_script_list is a previously created plutus_v4_script_list object+ *+ * size_t ref_count = cardano_plutus_v4_script_list_refcount(plutus_v4_script_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_plutus_v4_script_list_refcount(const cardano_plutus_v4_script_list_t* plutus_v4_script_list);++/**+ * \brief Sets the last error message for a given plutus_v4_script_list object.+ *+ * Records an error message in the plutus_v4_script_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] plutus_v4_script_list A pointer to the \ref cardano_plutus_v4_script_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the plutus_v4_script_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_plutus_v4_script_list_set_last_error(cardano_plutus_v4_script_list_t* plutus_v4_script_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific plutus_v4_script_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_plutus_v4_script_list_set_last_error for the given+ * plutus_v4_script_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] plutus_v4_script_list A pointer to the \ref cardano_plutus_v4_script_list_t instance whose last error+ *                   message is to be retrieved. If the plutus_v4_script_list is NULL, the function+ *                   returns a generic error message indicating the null plutus_v4_script_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified plutus_v4_script_list. If the plutus_v4_script_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_plutus_v4_script_list_set_last_error for the same plutus_v4_script_list, or until+ *       the plutus_v4_script_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_plutus_v4_script_list_get_last_error(const cardano_plutus_v4_script_list_t* plutus_v4_script_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_plutus_v4_script_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_plutus_v4_script_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_plutus_v4_script_list_deep_clone(const cardano_plutus_v4_script_list_t* source, cardano_plutus_v4_script_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_PLUTUS_V4_SCRIPT_LIST_H
+ vendor/include/cardano/auxiliary_data/transaction_metadata.h view
@@ -0,0 +1,626 @@+/**+ * \file transaction_metadata.h+ *+ * \author angel.castillo+ * \date   Sep 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_TRANSACTION_METADATA_H+#define BIGLUP_LABS_INCLUDE_CARDANO_TRANSACTION_METADATA_H++/* INCLUDES ******************************************************************/++#include <cardano/auxiliary_data/metadatum.h>+#include <cardano/auxiliary_data/metadatum_label_list.h>+#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a map of metadatum_label to metadatum.+ */+typedef struct cardano_transaction_metadata_t cardano_transaction_metadata_t;++/**+ * \brief Creates and initializes a new instance of a transaction_metadata.+ *+ * This function allocates and initializes a new instance of \ref cardano_transaction_metadata_t.+ * It returns an error code to indicate the success or failure of the operation.+ *+ * \param[out] transaction_metadata A pointer to a pointer to a \ref cardano_transaction_metadata_t object. Upon successful+ *                        initialization, this will point to a newly created \ref cardano_transaction_metadata_t+ *                        object. This object represents a "strong reference" to the transaction_metadata,+ *                        fully initialized and ready for use. The caller is responsible for managing+ *                        the lifecycle of this object. Specifically, once the transaction_metadata is no longer+ *                        needed, the caller must release it by calling \ref cardano_transaction_metadata_unref.+ *+ * \return \ref CARDANO_SUCCESS if the transaction_metadata was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = NULL;+ *+ * // Attempt to create a new transaction_metadata+ * cardano_error_t result = cardano_transaction_metadata_new(&transaction_metadata);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the transaction_metadata+ *+ *   // Once done, ensure to clean up and release the transaction_metadata+ *   cardano_transaction_metadata_unref(&transaction_metadata);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_transaction_metadata_new(cardano_transaction_metadata_t** transaction_metadata);++/**+ * \brief Creates a transaction_metadata from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_transaction_metadata_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a transaction_metadata.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded transaction_metadata data.+ * \param[out] transaction_metadata A pointer to a pointer of \ref cardano_transaction_metadata_t that will be set to the address+ *                        of the newly created transaction_metadata object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the transaction_metadata was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_transaction_metadata_t object by calling+ *       \ref cardano_transaction_metadata_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_transaction_metadata_t* transaction_metadata = NULL;+ *+ * cardano_error_t result = cardano_transaction_metadata_from_cbor(reader, &transaction_metadata);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the transaction_metadata+ *+ *   // Once done, ensure to clean up and release the transaction_metadata+ *   cardano_transaction_metadata_unref(&transaction_metadata);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode transaction_metadata: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_transaction_metadata_from_cbor(cardano_cbor_reader_t* reader, cardano_transaction_metadata_t** transaction_metadata);++/**+ * \brief Serializes a transaction_metadata into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_transaction_metadata_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] transaction_metadata A constant pointer to the \ref cardano_transaction_metadata_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p transaction_metadata or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_transaction_metadata_to_cbor(transaction_metadata, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_transaction_metadata_unref(&transaction_metadata);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_transaction_metadata_to_cbor(+  const cardano_transaction_metadata_t* transaction_metadata,+  cardano_cbor_writer_t*                writer);++/**+ * \brief Serializes transaction metadata to CIP-116 JSON.+ *+ * This function writes the transaction metadata (a map of metadatum labels to values)+ * as a JSON array of key/value entries using the CIP-116 shape.+ *+ * Notes:+ * - The \c key is the metadatum label serialized as a **decimal string**.+ * - The \c value is produced by \ref cardano_metadatum_to_cip116_json.+ * - The function writes both the opening `[` and closing `]` of the array.+ * - The writer must be in a context where a JSON value is valid.+ *+ * \param[in]  metadata A valid pointer to a \ref cardano_transaction_metadata_t instance.+ * \param[in]  writer   A valid pointer to a \ref cardano_json_writer_t positioned where a value is expected.+ *+ * \return \ref CARDANO_SUCCESS on success;+ *         \ref CARDANO_ERROR_POINTER_IS_NULL if any pointer parameter is \c NULL;+ *         \ref CARDANO_ERROR_ENCODING if an element cannot be retrieved or serialized.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_transaction_metadata_to_cip116_json(+  const cardano_transaction_metadata_t* metadata,+  cardano_json_writer_t*                writer);++/**+ * \brief Retrieves the length of the transaction metadata.+ *+ * This function returns the number of key-value pairs contained in the specified transaction metadata.+ *+ * \param[in] transaction_metadata A constant pointer to the \ref cardano_transaction_metadata_t object for which+ *                       the length is to be retrieved.+ *+ * \return The number of key-value pairs in the transaction_metadata. Returns 0 if the transaction_metadata is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = cardano_transaction_metadata_new();+ *+ * // Populate the transaction_metadata with key-value pairs+ *+ * size_t length = cardano_transaction_metadata_get_length(transaction_metadata);+ * printf("The length of the transaction_metadata is: %zu\n", length);+ *+ * cardano_transaction_metadata_unref(&transaction_metadata);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_transaction_metadata_get_length(const cardano_transaction_metadata_t* transaction_metadata);++/**+ * \brief Retrieves the value associated with a given key in the transaction_metadata.+ *+ * This function retrieves the value associated with the specified key in the provided transaction_metadata.+ * It returns the value through the output parameter `element`. If the key is not found in the transaction_metadata,+ * the output parameter `element` will be set to NULL.+ *+ * \param[in] transaction_metadata A constant pointer to the \ref cardano_transaction_metadata_t object from which+ *                       the value is to be retrieved.+ * \param[in] key The key whose associated value is to be retrieved from the transaction_metadata.+ * \param[out] element A pointer to a variable where the retrieved value will be stored. If the key+ *                     is found in the transaction_metadata, this variable will be set to the associated value.+ *                     If the key is not found, this variable will be set to NULL.+ *+ * \return \ref CARDANO_SUCCESS if the value associated with the key was successfully retrieved, or+ *         an appropriate error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = cardano_transaction_metadata_new();+ *+ * // Populate the transaction_metadata with key-value pairs+ *+ * uint64_t key = 0;+ * cardano_metadatum_t* value = NULL;+ * cardano_error_t result = cardano_transaction_metadata_get(transaction_metadata, key, &value);+ *+ * if (result == CARDANO_SUCCESS && value != NULL)+ * {+ *   // Use the retrieved value+ *   // ...+ * }+ * else+ * {+ *   // Handle error or key not found+ * }+ *+ * cardano_metadatum_unref(&value); // Clean up the value resource+ * cardano_transaction_metadata_unref(&transaction_metadata);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_transaction_metadata_get(cardano_transaction_metadata_t* transaction_metadata, uint64_t key, cardano_metadatum_t** element);++/**+ * \brief Inserts a key-value pair into the transaction_metadata.+ *+ * This function inserts the specified key-value pair into the provided transaction_metadata.+ *+ * \param[in] transaction_metadata A constant pointer to the \ref cardano_transaction_metadata_t object where+ *                       the key-value pair is to be inserted.+ * \param[in] key The key to be inserted into the transaction_metadata.+ * \param[in] value The value to be associated with the key and inserted into the transaction_metadata.+ *                  The caller is responsible for managing the lifecycle of the value object.+ *+ * \return \ref CARDANO_SUCCESS if the key-value pair was successfully inserted, or an appropriate+ *         error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = cardano_transaction_metadata_new();+ *+ * // Create key and value objects+ * uint64_t key = 755;+ * cardano_metadatum_t* value = {...}; // Assume value is properly initialized+ *+ * // Insert the key-value pair into the transaction_metadata+ * cardano_error_t result = cardano_transaction_metadata_insert(transaction_metadata, key, value);+ *+ * if (result != CARDANO_SUCCESS)+ * {+ *   // Handle insertion failure+ * }+ *+ * // Clean up key and value objects+ * cardano_metadatum_unref(&value);+ * cardano_transaction_metadata_unref(&transaction_metadata);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_transaction_metadata_insert(cardano_transaction_metadata_t* transaction_metadata, uint64_t key, cardano_metadatum_t* value);++/**+ * \brief Retrieves the keys from the transaction_metadata.+ *+ * This function retrieves all the keys from the provided transaction_metadata and returns them as a list.+ * The caller is responsible for managing the lifecycle of the returned list by calling+ * \ref cardano_metadatum_label_list_t when it is no longer needed.+ *+ * \param[in] transaction_metadata A constant pointer to the \ref cardano_transaction_metadata_t object from which+ *                       the keys are to be retrieved.+ * \param[out] keys A pointer to a variable where the retrieved keys will be stored as a list.+ *                  If successful, this variable will be set to point to the list of keys.+ *                  The caller is responsible for managing the lifecycle of this list.+ *                  It must be released by calling \ref cardano_metadatum_label_list_unref when no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the keys were successfully retrieved, or an appropriate+ *         error code if the input parameters are invalid or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = cardano_transaction_metadata_new();+ *+ * // Populate the transaction_metadata with key-value pairs+ *+ * cardano_metadatum_label_list_t* keys = NULL;+ * cardano_error_t result = cardano_transaction_metadata_get_keys(transaction_metadata, &keys);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the list of keys+ *   // Keys must also be freed if retrieved from the list+ *+ *   // Once done, ensure to clean up and release the keys list+ *   cardano_metadatum_label_list_unref(&keys);+ * }+ * else+ * {+ *   // Handle error+ * }+ *+ * cardano_transaction_metadata_unref(&transaction_metadata);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_transaction_metadata_get_keys(cardano_transaction_metadata_t* transaction_metadata, cardano_metadatum_label_list_t** keys);++/**+ * \brief Retrieves the metadatum label at a specific index from the transaction metadata.+ *+ * This function retrieves the metadatum label at the specified index from the transaction_metadata.+ *+ * \param[in] transaction_metadata Pointer to the transaction_metadata object.+ * \param[in] index The index of the metadatum label to retrieve.+ * \param[out] metadatum_label The metadatum label as \c uint64_t.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the metadatum label was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = NULL;+ * uint64_t metadatum_label = 0;+ * size_t index = 0; // Index of the key hash to retrieve+ *+ * // Assume transaction_metadata is initialized properly+ *+ * cardano_error_t result = cardano_transaction_metadata_get_key_at(transaction_metadata, index, &metadatum_label);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum_label+ * }+ * else+ * {+ *   // Handle the error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_transaction_metadata_get_key_at(+  const cardano_transaction_metadata_t* transaction_metadata,+  size_t                                index,+  uint64_t*                             metadatum_label);++/**+ * \brief Retrieves the metadatum at a specific index from the transaction_metadata.+ *+ * This function retrieves the metadatum at the specified index from the transaction_metadata.+ *+ * \param[in] transaction_metadata Pointer to the transaction_metadata object.+ * \param[in] index The index of the metadatum to retrieve.+ * \param[out] metadatum On successful retrieval, this will point to the metadatum+ *                    at the specified index.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the metadatum was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = NULL;+ * cardano_metadatum_t* metadatum = 0;+ * size_t index = 0; // Index of the metadatum to retrieve+ *+ * // Assume transaction_metadata is initialized properly+ *+ * cardano_error_t result = cardano_transaction_metadata_get_value_at(transaction_metadata, index, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the metadatum+ *   cardano_metadatum_unref(&metadatum);+ * }+ * else+ * {+ *   // Handle the error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_transaction_metadata_get_value_at(+  const cardano_transaction_metadata_t* transaction_metadata,+  size_t                                index,+  cardano_metadatum_t**                 metadatum);++/**+ * \brief Retrieves the metadatum label and metadatum at the specified index.+ *+ * This function retrieves the metadatum label and metadatum from the metadata at the specified index.+ *+ * \param[in]  transaction_metadata Pointer to the proposed metadata object.+ * \param[in]  index                The index at which to retrieve the key-value pair.+ * \param[out] metadatum_label On successful retrieval, this will point to the metadatum label at the specified index.+ * \param[out] metadatum On successful retrieval, this will point to the metadatum at the specified index.+ *                            The caller is responsible for managing the lifecycle of this object and should release it using+ *                            \ref cardano_metadatum_unref when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the key-value pair was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = NULL;+ * // Assume transaction_metadata is initialized properly+ *+ * size_t index = 0;+ * uint64_t metadatum_label = 0;+ * cardano_metadatum_t* metadatum = NULL;+ *+ * cardano_error_t result = cardano_transaction_metadata_get_key_value_at(transaction_metadata, index, &metadatum_label, &metadatum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   if (metadatum != NULL)+ *   {+ *     // Use the metadatum label and metadatum+ *   }+ *   else+ *   {+ *     printf("Key-value pair not set at index %zu.\n", index);+ *   }+ * }+ * else+ * {+ *   // Handle error+ *   printf("Failed to get key-value pair at index %zu.\n", index);+ * }+ *+ * // Clean up+ * cardano_transaction_metadata_unref(&transaction_metadata);+ * cardano_metadatum_unref(&metadatum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_transaction_metadata_get_key_value_at(+  const cardano_transaction_metadata_t* transaction_metadata,+  size_t                                index,+  uint64_t*                             metadatum_label,+  cardano_metadatum_t**                 metadatum);++/**+ * \brief Decrements the reference count of a transaction_metadata object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_transaction_metadata_t object+ * by decreasing its reference count. When the reference count reaches zero, the transaction_metadata is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] transaction_metadata A pointer to the pointer of the transaction_metadata object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_metadata_t* transaction_metadata = cardano_transaction_metadata_new();+ *+ * // Perform operations with the transaction_metadata...+ *+ * cardano_transaction_metadata_unref(&transaction_metadata);+ * // At this point, transaction_metadata is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_transaction_metadata_unref, the pointer to the \ref cardano_transaction_metadata_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_transaction_metadata_unref(cardano_transaction_metadata_t** transaction_metadata);++/**+ * \brief Increases the reference count of the cardano_transaction_metadata_t object.+ *+ * This function is used to manually increment the reference count of a transaction_metadata+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_transaction_metadata_unref.+ *+ * \param transaction_metadata A pointer to the transaction_metadata object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming transaction_metadata is a previously created transaction_metadata object+ *+ * cardano_transaction_metadata_ref(transaction_metadata);+ *+ * // Now transaction_metadata can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_transaction_metadata_ref there is a corresponding+ * call to \ref cardano_transaction_metadata_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_transaction_metadata_ref(cardano_transaction_metadata_t* transaction_metadata);++/**+ * \brief Retrieves the current reference count of the cardano_transaction_metadata_t object.+ *+ * This function returns the number of active references to a transaction_metadata object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_transaction_metadata_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param transaction_metadata A pointer to the transaction_metadata object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified transaction_metadata object. If the object+ * is properly managed (i.e., every \ref cardano_transaction_metadata_ref call is matched with a+ * \ref cardano_transaction_metadata_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming transaction_metadata is a previously created transaction_metadata object+ *+ * size_t ref_count = cardano_transaction_metadata_refcount(transaction_metadata);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_transaction_metadata_refcount(const cardano_transaction_metadata_t* transaction_metadata);++/**+ * \brief Sets the last error message for a given transaction_metadata object.+ *+ * Records an error message in the transaction_metadata's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] transaction_metadata A pointer to the \ref cardano_transaction_metadata_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the transaction_metadata's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_transaction_metadata_set_last_error(cardano_transaction_metadata_t* transaction_metadata, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific transaction_metadata.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_transaction_metadata_set_last_error for the given+ * transaction_metadata. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] transaction_metadata A pointer to the \ref cardano_transaction_metadata_t instance whose last error+ *                   message is to be retrieved. If the transaction_metadata is NULL, the function+ *                   returns a generic error message indicating the null transaction_metadata.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified transaction_metadata. If the transaction_metadata is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_transaction_metadata_set_last_error for the same transaction_metadata, or until+ *       the transaction_metadata is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_transaction_metadata_get_last_error(const cardano_transaction_metadata_t* transaction_metadata);++/**+ * \brief Creates an independent deep copy of a \ref cardano_transaction_metadata_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_transaction_metadata_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_transaction_metadata_deep_clone(const cardano_transaction_metadata_t* source, cardano_transaction_metadata_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_TRANSACTION_METADATA_H
+ vendor/include/cardano/bip39.h view
@@ -0,0 +1,177 @@+/**+ * \file bip39.h+ *+ * \author angel.castillo+ * \date   Nov 22, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_BIP39S_H+#define BIGLUP_LABS_INCLUDE_CARDANO_BIP39S_H++/* INCLUDES ******************************************************************/++#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Converts entropy into a BIP-39 mnemonic word sequence.+ *+ * This function takes entropy (a binary sequence) and converts it into a corresponding+ * BIP-39 mnemonic sequence of words. The mnemonic words are pointers to a static,+ * preloaded wordlist and do not require dynamic memory management. The caller must+ * not attempt to free the returned pointers.+ *+ * \param[in] entropy        Pointer to the entropy buffer. Must not be NULL.+ * \param[in] entropy_size   Size of the entropy in bytes. Supported sizes are 16, 20, 24, 28, or 32 bytes.+ * \param[out] words         Array of pointers to char* where the mnemonic words will be stored.+ *                           The caller must provide an array of size 24 to hold the maximum possible words.+ *                           Each element in the array will point to a statically allocated string.+ * \param[out] word_count    Pointer to a size_t where the number of words in the mnemonic will be stored.+ *                           The number of words depends on the entropy size:+ *                             - 16 bytes (128 bits) → 12 words+ *                             - 20 bytes (160 bits) → 15 words+ *                             - 24 bytes (192 bits) → 18 words+ *                             - 28 bytes (224 bits) → 21 words+ *                             - 32 bytes (256 bits) → 24 words+ *+ * \return On success, returns CARDANO_SUCCESS. On failure, returns an error code indicating the+ * reason for failure.+ *+ * \note+ * - This function only supports the **English BIP-39 wordlist**.+ * - The function does not allocate memory for the words; it simply assigns pointers+ *   to statically allocated strings from the preloaded English wordlist.+ * - The caller must not free the pointers in the `words` array as they point to+ *   static memory.+ *+ * \code{.c}+ * byte_t entropy[32] = { 256 bits of entropy  };+ * char* words[24] = { 0 };+ * size_t word_count = 0U;+ *+ * cardano_error_t result = cardano_bip39_entropy_to_mnemonic_words(entropy, sizeof(entropy), words, &word_count);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Mnemonic words:\n");+ *+ *   for (size_t i = 0; i < word_count; ++i)+ *   {+ *     printf("%s ", words[i]);+ *   }+ *+ *   printf("\n");+ * }+ * else+ * {+ *    printf("Failed to create mnemonic words: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_bip39_entropy_to_mnemonic_words(+  const byte_t* entropy,+  size_t        entropy_size,+  const char**  words,+  size_t*       word_count);++/**+ * \brief Converts a BIP-39 mnemonic word sequence back into entropy.+ *+ * This function takes a mnemonic sequence of BIP-39 words and converts it back+ * into the corresponding binary entropy. The provided mnemonic words must belong+ * to the English BIP-39 wordlist. The resulting entropy will be written to the+ * provided buffer.+ *+ * \param[in] words            Array of pointers to the mnemonic words. Each word must be a valid+ *                             BIP-39 English word. Must not be NULL.+ * \param[in] word_count       Number of words in the mnemonic sequence. Supported values are:+ *                               - 12 words (128-bit entropy)+ *                               - 15 words (160-bit entropy)+ *                               - 18 words (192-bit entropy)+ *                               - 21 words (224-bit entropy)+ *                               - 24 words (256-bit entropy)+ * \param[out] entropy         Pointer to the buffer where the resulting entropy will be stored.+ *                             Must not be NULL.+ * \param[in] entropy_buf_size Size of the entropy buffer provided (in bytes). Must be at least+ *                             the size of the expected entropy corresponding to the word count+ *                             (16–32 bytes).+ * \param[out] entropy_size    Pointer to a size_t where the actual size of the resulting entropy+ *                             (in bytes) will be stored. Must not be NULL.+ *+ * \return On success, returns `CARDANO_SUCCESS`. On failure, returns an error code indicating the+ * reason for failure.+ *+ * \note+ * - This function only supports the **English BIP-39 wordlist**.+ * - The provided mnemonic words must be valid and match the BIP-39 specification.+ * - The caller must ensure the entropy buffer is large enough to accommodate the resulting entropy.+ *+ * \code{.c}+ * const char* words[12] = {+ *   "abandon", "abandon", "abandon", "abandon", "abandon", "abandon",+ *   "abandon", "abandon", "abandon", "abandon", "abandon", "about"+ * };+ * uint8_t entropy[32] = { 0 };+ * size_t entropy_size = 0U;+ *+ * cardano_error_t result = cardano_bip39_mnemonic_words_to_entropy(+ *     words,+ *     12,+ *     entropy,+ *     sizeof(entropy),  // Provide the size of the buffer+ *     &entropy_size     // Output parameter for the actual entropy size+ * );+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Entropy (size: %zu bytes): ", entropy_size);+ *+ *   for (size_t i = 0; i < entropy_size; ++i)+ *   {+ *     printf("%02x", entropy[i]);+ *   }+ *+ *   printf("\n");+ * }+ * else+ * {+ *   printf("Failed to convert mnemonic words to entropy: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_bip39_mnemonic_words_to_entropy(+  const char** words,+  size_t       word_count,+  byte_t*      entropy,+  size_t       entropy_buf_size,+  size_t*      entropy_size);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_BIP39S_H
+ vendor/include/cardano/buffer.h view
@@ -0,0 +1,1324 @@+/**+ * \file buffer.h+ *+ * \author angel.castillo+ * \date   Sep 12, 2023+ *+ * Copyright 2023 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_BUFFER_H+#define BIGLUP_LABS_INCLUDE_CARDANO_BUFFER_H++/* INCLUDES ******************************************************************/++#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief A dynamic, reference-counted buffer with configurable exponential growth.+ *+ * This structure represents a dynamically sized buffer that uses reference counting for memory management and+ * employs an exponential growth strategy to manage its capacity.+ *+ * The buffer's capacity automatically increases by a default growth factor of 1.5 whenever it becomes full. This+ * approach to resizing is intended to balance between memory usage and the number of reallocations needed, as+ * excessive reallocations can degrade performance.+ *+ * \note The default growth factor is chosen based on a <a href="http://groups.google.com/group/comp.lang.c++.moderated/msg/ba558b4924758e2e">recommendation from Andrew Koenig</a>, suggesting that it should+ * be less than the golden ratio ((1+sqrt(5))/2, approximately 1.6) to ensure optimal performance. Users can+ * configure the growth factor at compilation time by setting the `COLLECTION_GROW_FACTOR` environment variable,+ * allowing for customization of the buffer's resizing behavior according to their needs.+ */+typedef struct cardano_buffer_t cardano_buffer_t;++/**+ * \brief Creates a new dynamic buffer with the specified initial capacity.+ *+ * This function allocates a new dynamic buffer with the given initial capacity. The buffer's capacity will+ * automatically increase in an exponential manner as needed.+ *+ * \param[in] capacity Initial capacity of the buffer. Must be greater than 0. If 0 is provided, this function+ * returns NULL, indicating an error in buffer creation due to invalid capacity.+ *+ * \return A pointer to the newly created \ref cardano_buffer_t instance, or NULL if memory allocation fails.+ * The caller assumes ownership of the returned buffer and is responsible for its lifecycle management.+ * To release the buffer when it is no longer needed, the caller must call \ref cardano_buffer_unref.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_buffer_t* cardano_buffer_new(size_t capacity);++/**+ * \brief Creates a new dynamic buffer and initializes it with a copy of the given data.+ *+ * This function allocates a new dynamic buffer and copies the provided data into it. The size of the buffer is+ * automatically set to accommodate the specified data.+ *+ * \param[in] array A pointer to the data to initialize the buffer with. The data is copied into the new buffer.+ * \param[in] size The size of the data to copy. Specifies how many bytes from \c array should be copied into+ * the newly created buffer.+ *+ * \return A pointer to the newly created \ref cardano_buffer_t instance, or NULL if memory allocation fails.+ * The caller assumes ownership of the returned buffer and is responsible for managing its lifecycle. When+ * the buffer is no longer needed, it must be released by calling \ref cardano_buffer_unref.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_buffer_t* cardano_buffer_new_from(const byte_t* array, size_t size);++/**+ * \brief Concatenates two buffers into a new one, containing the combined data.+ *+ * This function creates a new dynamic buffer that contains the concatenated contents of two given buffers.+ * The new buffer will first include the data from the first buffer (\c lhs), followed by the data from the+ * second buffer (\c rhs). The resulting buffer's capacity is automatically adjusted to accommodate the total+ * combined data size of both source buffers.+ *+ * \param[in] lhs A pointer to the first buffer to concatenate.+ * \param[in] rhs A pointer to the second buffer to concatenate.+ *+ * \return A pointer to a new \ref cardano_buffer_t instance containing the concatenated data of both input buffers,+ * or NULL if memory allocation fails. The caller assumes ownership of the returned buffer and is responsible for its+ * lifecycle management. To properly release the buffer when it is no longer needed, the caller must call+ * \ref cardano_buffer_unref.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_buffer_t* cardano_buffer_concat(const cardano_buffer_t* lhs, const cardano_buffer_t* rhs);++/**+ * \brief Extracts a portion of the buffer between specified indices, creating a new buffer with the slice.+ *+ * This function creates a new dynamic buffer that contains a specific slice of the source buffer, defined by the+ * provided start and end indices. The start index is inclusive, meaning the slice will start from the element+ * at this index, while the end index is exclusive, indicating the slice ends at the element before this index.+ * This operation allows for selective copying of segments from a larger buffer into a new, smaller buffer.+ *+ * \param[in] buffer The source buffer from which the slice is to be extracted.+ * \param[in] start The starting index of the slice, inclusive. Must be less than the size of the source buffer.+ * \param[in] end The ending index of the slice, exclusive. Must be greater than or equal to the start index and+ *                less than or equal to the size of the source buffer.+ *+ * \return A pointer to a new \ref cardano_buffer_t instance containing the specified slice of the source buffer,+ * or NULL if the input is invalid or memory allocation fails. The caller assumes ownership of the returned buffer+ * and is responsible for its lifecycle management. To properly release the buffer when it is no longer needed, the+ * caller must call \ref cardano_buffer_unref.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_buffer_t* cardano_buffer_slice(const cardano_buffer_t* buffer, size_t start, size_t end);++/**+ * \brief Creates a new buffer by decoding a given hex string.+ *+ * This function allocates a new dynamic buffer and initializes its content by decoding the provided hex string.+ * The hex string must represent binary data in hexadecimal format. Each pair of hex digits (two characters) is+ * converted into a single byte, and the resulting bytes are stored in the new buffer. The size parameter+ * indicates the number of characters in the hex string and should be even to ensure a complete byte representation.+ *+ * \param[in] hex_string A pointer to the hex string to be decoded.+ * \param[in] size The number of characters in the hex string, excluding the null terminator.+ *+ * \return A pointer to a new \ref cardano_buffer_t instance containing the decoded data from the hex string,+ * or NULL if memory allocation fails or the hex string format is invalid. The caller assumes ownership of the+ * returned buffer and is responsible for its lifecycle management. To properly release the buffer when it is no+ * longer needed, the caller must call \ref cardano_buffer_unref.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_buffer_t* cardano_buffer_from_hex(const char* hex_string, size_t size);++/**+ * \brief Calculates the size needed for a buffer's hexadecimal string representation,+ * including the null terminator.+ *+ * This function determines the size of the buffer required to hold the hexadecimal string+ * representation of a buffer's contents, including space for the null terminator. This size+ * can be used to allocate memory for storing the hexadecimal string generated by \ref cardano_buffer_to_hex.+ *+ * \param[in] buffer The source buffer for which the hexadecimal string size is being calculated.+ *+ * \return The size in bytes required to store the buffer's contents as a hexadecimal string,+ * including the null terminator. If the buffer is NULL or empty, returns 1 for+ * the null terminator alone.+ *+ * Example usage:+ * \code{.c}+ * cardano_buffer_t* buffer = cardano_buffer_new_from_data(someData, dataSize);+ * size_t hex_string_size = cardano_buffer_get_hex_size(buffer);+ * char* hex_string = (char*)malloc(hex_string_size);+ * cardano_error_t result = cardano_buffer_to_hex(buffer, hex_string, hex_string_size);+ *+ * if (hex_string != NULL && result == CARDANO_SUCCESS)+ * {+ *   printf("Hex representation: %s\n", hex_string);+ * }+ *+ * free(hex_string);+ *+ * cardano_buffer_unref(&buffer);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_buffer_get_hex_size(const cardano_buffer_t* buffer);++/**+ * \brief Converts the contents of a buffer into a hexadecimal string representation and writes it+ * to the provided buffer.+ *+ * This function takes a source buffer and generates a hexadecimal string representation of its contents,+ * writing the result to a user-provided buffer. The size of the destination buffer must be sufficient to+ * hold the hexadecimal string and the null terminator. The required size can be determined using the+ * \ref cardano_buffer_get_hex_size function.+ *+ * \param[in] buffer The source buffer from which the hex string will be generated.+ * \param[out] dest The destination buffer where the null-terminated hexadecimal string will be written.+ * \param[in] dest_size The size of the destination buffer. This size must include space for the null terminator.+ *+ * \return On success, returns CARDANO_SUCCESS. On failure, returns an error code indicating the+ * reason for failure, such as insufficient buffer size.+ *+ * Example usage:+ * \code{.c}+ * cardano_buffer_t* buffer = cardano_buffer_new_from_data(someData, dataSize);+ * size_t hex_string_size = cardano_buffer_get_hex_size(buffer);+ * char* hex_string = (char*)malloc(hex_string_size);+ * cardano_error_t result = cardano_buffer_to_hex(buffer, hex_string, hex_string_size);+ *+ * if (hex_string != NULL && result == CARDANO_SUCCESS)+ * {+ *     printf("Hex representation: %s\n", hex_string);+ * }+ *+ * free(hex_string);+ *+ * cardano_buffer_unref(&buffer);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_to_hex(const cardano_buffer_t* buffer, char* dest, size_t dest_size);++/**+ * \brief Computes the size needed for a null-terminated string representation of the buffer's contents.+ *+ * This function calculates the size of the buffer's content when represented as a null-terminated string.+ * The calculated size includes space for the null terminator. This is useful for allocating an appropriately sized+ * buffer before converting the buffer's binary data into a string with `cardano_buffer_to_str`.+ *+ * \param[in] buffer A pointer to the cardano_buffer_t instance whose string size is being queried.+ *+ * \return The size in bytes required to represent the buffer's content as a null-terminated string, including the null terminator.+ *         Returns 0 if the buffer is NULL or contains no data.+ *+ * Example usage:+ * \code{.c}+ * cardano_buffer_t* myBuffer = // assume this is initialized and contains data+ *+ * size_t strSize = cardano_buffer_get_str_size(myBuffer);+ *+ * // strSize now contains the size needed to store the buffer's data as a string+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_buffer_get_str_size(const cardano_buffer_t* buffer);++/**+ * \brief Converts the content of a buffer to a UTF-8 string.+ *+ * This function takes the binary content of the specified buffer and+ * converts it to a null-terminated string. The caller must ensure+ * that the destination buffer (\c dest) is large enough to hold the resulting+ * string, including the null terminator.+ *+ * The size required for the destination buffer can be determined using+ * \ref cardano_buffer_get_str_size.+ *+ * \param[in] buffer The source buffer containing the binary data to be converted.+ * \param[out] dest The destination buffer where the resulting string will be stored.+ * \param[in] dest_size The size of the destination buffer in bytes.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful and the string was+ *         copied to \c dest. If the destination buffer is not large enough to hold the string,+ *         an error code will be returned. Refer to \c cardano_error_t documentation+ *         for details on possible error codes.+ *+ * Example usage:+ * \code{.c}+ * size_t needed_size = cardano_buffer_get_str_size(buffer);+ * char* dest = (char*)malloc(needed_size);+ *+ * if (dest != NULL)+ * {+ *   if (cardano_buffer_to_str(buffer, dest, needed_size) == CARDANO_SUCCESS)+ *   {+ *     printf("Buffer content as string: %s\n", dest);+ *   }+ *   else+ *   {+ *     printf("Failed to convert buffer to string.\n");+ *   }+ *+ *   free(dest);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_to_str(const cardano_buffer_t* buffer, char* dest, size_t dest_size);++/**+ * \brief Checks if two cardano_buffer_t objects are equal.+ *+ * This function compares the contents of two cardano_buffer_t objects, lhs and rhs, to determine if they are equal.+ * If the contents of both buffers are identical in size and content, the function returns true. Otherwise, it returns false.+ *+ * \param[in] lhs A constant pointer to the first cardano_buffer_t object to be compared.+ * \param[in] rhs A constant pointer to the second cardano_buffer_t object to be compared.+ *+ * \return true if the contents of the buffers are equal, false otherwise.+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_buffer_equals(const cardano_buffer_t* lhs, const cardano_buffer_t* rhs);++/**+ * \brief Compares two buffer objects lexicographically.+ *+ * This function compares two buffer objects lexicographically and returns an integer indicating+ * their relative order. The comparison is performed byte-by-byte.+ *+ * \param[in] lhs Pointer to the first buffer object.+ * \param[in] rhs Pointer to the second buffer object.+ *+ * \return A negative value if lhs is less than rhs, zero if they are equal, and a positive value if lhs is greater than rhs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_buffer_t* buffer1 = NULL;+ * cardano_buffer_t* buffer2 = NULL;+ *+ * // Assume buffer1 and buffer2 are initialized properly+ *+ * int32_t comparison = cardano_buffer_compare(buffer1, buffer2);+ *+ * if (comparison < 0)+ * {+ *   printf("buffer1 is less than buffer2.\n");+ * }+ * else if (comparison == 0)+ * {+ * {+ *   printf("buffer1 is equal to buffer2.\n");+ * }+ * else+ * {+ *   printf("buffer1 is greater than buffer2.\n");+ * }+ *+ * // Clean up+ * cardano_buffer_unref(&buffer1);+ * cardano_buffer_unref(&buffer2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT int32_t cardano_buffer_compare(const cardano_buffer_t* lhs, const cardano_buffer_t* rhs);++/**+ * \brief Decrements the buffer's reference count.+ *+ * This function is used to decrement the reference count of a `cardano_buffer_t` instance.+ * When the reference count reaches zero, the memory allocated for the buffer is automatically+ * deallocated. It is important to ensure that `cardano_buffer_unref` is called for each+ * `cardano_buffer_new`, `cardano_buffer_new_from`, `cardano_buffer_concat`, or any other+ * function that returns a new buffer reference to prevent memory leaks.+ *+ * \param[in,out] buffer A double pointer to the buffer whose reference count is to be decremented.+ *                       On invocation, `buffer` should point to a valid `cardano_buffer_t*`.+ *                       After execution, the pointer is set to NULL to prevent further use.+ *+ * Example usage:+ * \code{.c}+ * cardano_buffer_t* my_buffer = cardano_buffer_new(256);+ *+ * // Use the buffer...+ * cardano_buffer_unref(&my_buffer); // Decrement ref count and possibly free the buffer+ * assert(my_buffer == NULL); // myBuffer is now NULL+ *+ * \endcode+ */+CARDANO_EXPORT void cardano_buffer_unref(cardano_buffer_t** buffer);++/**+ * \brief Increments the buffer's reference count.+ *+ * This function is used to increment the reference count of a `cardano_buffer_t` instance,+ * indicating that there is an additional owner of the buffer. This ensures that the buffer+ * remains allocated until the last reference is released. It is essential to match each call+ * to `cardano_buffer_ref` with a corresponding call to `cardano_buffer_unref` to prevent memory+ * leaks by ensuring that the buffer is deallocated when it is no longer in use.+ *+ * \param[in] buffer A pointer to the buffer whose reference count is to be incremented.+ *                   `buffer` must point to a valid `cardano_buffer_t` instance.+ *+ * Example usage:+ * \code{.c}+ * cardano_buffer_t* shared_buffer = cardano_buffer_new(128);+ * cardano_buffer_ref(shared_buffer); // Increment ref count because buffer will be shared+ *+ * // Share the buffer. The receiver should also call cardano_buffer_ref when its done+ * // with the buffer.+ *+ * cardano_buffer_unref(&shared_buffer); // Decrement our own reference when done with the buffer+ *+ * \endcode+ */+CARDANO_EXPORT void cardano_buffer_ref(cardano_buffer_t* buffer);++/**+ * \brief Retrieves the buffer's current reference count.+ *+ * This function returns the current reference count of a `cardano_buffer_t` instance.+ * The reference count indicates how many owners or references to the buffer exist.+ * It is essential for managing the buffer's lifecycle, ensuring it remains allocated+ * until the last reference is released. Note that this function does not account for+ * transitive references, which means it only counts direct references to this buffer+ * instance.+ *+ * \param[in] buffer A pointer to the target buffer. `buffer` must point to a valid+ *                   `cardano_buffer_t` instance.+ * \return The current reference count of the buffer.+ *+ * Example usage:+ * \code{.c}+ * cardano_buffer_t* my_buffer = cardano_buffer_new(256);+ * size_t ref_count = cardano_buffer_refcount(my_buffer);+ *+ * printf("Reference count: %zu\n", ref_count);+ *+ * cardano_buffer_unref(&my_buffer);+ * \endcode+ */+CARDANO_EXPORT size_t cardano_buffer_refcount(const cardano_buffer_t* buffer);++/**+ * \brief Retrieves a direct pointer to the internal data of a buffer.+ *+ * This function provides access to the internal storage of the buffer, allowing for read-only operations on its contents.+ * It is intended for situations where direct access to the data is necessary for performance or interoperability reasons.+ *+ * \warning The returned pointer provides raw, direct access to the buffer's internal data. It must not be used to+ * deallocate it using free or similar memory management functions. The lifecycle of the data pointed to by the returned+ * pointer is managed by the buffer's reference counting mechanism; therefore, the data remains valid as long as the+ * buffer object exists and has not been deallocated.+ *+ * \param[in] buffer The buffer instance from which to retrieve the internal data pointer. The buffer must have been previously+ * created and not yet deallocated.+ *+ * \return Returns a pointer to the internal data of the buffer. If the buffer is empty or if the buffer instance is invalid,+ * returns NULL. The returned pointer provides direct access to the buffer's contents and must be used in accordance with the+ * warning above to avoid unintended consequences.+ */+CARDANO_NODISCARD+CARDANO_EXPORT byte_t* cardano_buffer_get_data(const cardano_buffer_t* buffer);++/**+ * \brief Sets the logical size of the buffer to a specified value.+ *+ * This function updates the internal marker of the buffer to reflect a new logical size,+ * indicating how much of the preallocated memory is considered "used" or contains valid data.+ * It is important to note that this function does not allocate, deallocate, or initialize memory;+ * it merely updates the buffer's state to reflect that a certain portion of its already allocated+ * memory is now in use. This is particularly useful when data is written to the buffer in a manner+ * where the exact amount of data written is known and does not need to be sequentially written or tracked.+ *+ * \warning This function should be used with caution as it directly affects how much of the buffer+ *          is considered valid data.+ *+ * \param buffer A pointer to the `cardano_buffer_t` object whose size is to be set. The buffer+ *               must have been properly initialized and should have enough memory allocated to+ *               accommodate the new size.+ * \param size The new logical size of the buffer. This value must not exceed the buffer's current+ *             allocated memory size.+ *+ * \return Returns `CARDANO_SUCCESS` if the buffer's size was successfully updated. If the function+ *         fails (e.g., due to an invalid buffer pointer, or the specified `size` exceeding the+ *         buffer's allocated memory), a non-zero error code is returned.+ *+ * Example Usage:+ * \code+ * cardano_buffer_t* buffer = cardano_buffer_new(1024);+ *+ * // Write data to the buffer in a non-standard manner, or track written data externally+ *+ * // Artificially set the buffer's size after data has been written or manipulated+ * size_t data_written = 512; // Assume 512 bytes of data are now considered "used"+ * cardano_error_t error = cardano_buffer_set_size(&buffer, data_written);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // The buffer now considers 512 bytes of its allocated memory as "used"+ * }+ *+ * // Clean up+ * cardano_buffer_unref(&buffer);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_set_size(cardano_buffer_t* buffer, size_t size);++/**+ * \brief Securely wipes the contents of a buffer from memory.+ *+ * The `cardano_buffer_memzero` function is used to securely erase the sensitive data stored in the provided \p buffer.+ * This ensures that the data is no longer recoverable from memory after it has been used.+ *+ * After use, sensitive data should be overwritten. However, traditional approaches like `memset()` or hand-written+ * memory clearing routines can be stripped away by optimizing compilers or linkers, potentially leaving sensitive+ * information exposed.+ *+ * The `cardano_buffer_memzero` function guarantees that the memory is cleared, even in the presence of compiler optimizations.+ * It is especially important to call this function before freeing memory that contains sensitive information, such as+ * cryptographic keys or decrypted data, to prevent the data from remaining in memory.+ *+ * \param[in] buffer A pointer to the buffer whose contents should be securely erased.+ *+ * \see cardano_buffer_unref() for releasing the buffer after calling this function.+ *+ * \example+ * \code+ * // Example usage after processing sensitive data+ * cardano_buffer_t* sensitive_data = ...; // Buffer containing sensitive data+ *+ * // Wipe the buffer contents securely before releasing it+ * cardano_buffer_memzero(sensitive_data);+ * cardano_buffer_unref(sensitive_data);+ * \endcode+ */+CARDANO_EXPORT void cardano_buffer_memzero(cardano_buffer_t* buffer);++/**+ * \brief Retrieves the current size of the buffer, indicating how much data it currently holds.+ *+ * This function provides the actual used space within the buffer, reflecting the amount of data it currently contains.+ * It is useful for understanding the buffer's occupancy and managing data operations, such as reading or processing the buffer's contents.+ *+ * \note The returned size represents the amount of data currently stored in the buffer, which may be less than or equal to+ * the buffer's total capacity. A return value of 0 indicates either that the buffer is empty or that the provided buffer reference+ * is NULL.+ *+ * \param[in] buffer The buffer instance for which to retrieve the used space.+ *+ * \return The size of the used space within the buffer, in bytes. This value ranges from 0 to the buffer's total capacity.+ * Returns 0 if the buffer is NULL, indicating an error condition or uninitialized buffer instance.+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_buffer_get_size(const cardano_buffer_t* buffer);++/**+ * \brief Copies data from a Cardano buffer to a specified destination array.+ *+ * This function safely transfers bytes from a `cardano_buffer_t` object to a provided+ * destination array.+ *+ * \param buffer A pointer to the `cardano_buffer_t` object from which data will be copied.+ *               The buffer must be initialized and contain the data to be copied.+ * \param dest A pointer to the destination array where the data will be copied. This array+ *             must be allocated and have a size large enough to hold the data being copied.+ * \param dest_size The size of the destination array in bytes. This value determines the+ *                  maximum amount of data that can be safely copied to `dest`.+ *+ * \return cardano_error_t Returns `CARDANO_SUCCESS` if the data was successfully copied to the+ *         destination array. If the function fails, a non-zero error code is returned,+ *         indicating issues such as null pointers for `buffer` or `dest`, or an insufficient+ *         `dest_size` to hold the buffer's data. In cases of failure, the content of `dest`+ *         may be partially updated or left unchanged.+ *+ * Example Usage:+ * \code+ * const cardano_buffer_t* source_buffer = ...; // Assume source_buffer is initialized and filled with data+ * byte_t destination_array[1024];+ * const size_t destination_size = sizeof(destination_array);+ *+ * cardano_error_t error = cardano_buffer_copy_bytes(source_buffer, destination_array, destination_size);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Data has been successfully copied to destination_array+ *   // Proceed with using the data in destination_array as needed+ * }+ * else+ * {+ *   // Handle the error (e.g., log it, attempt recovery, etc.)+ * }+ * \endcode+ *+ * \note The caller is responsible for ensuring that the destination array is properly allocated+ *       and sized to accommodate the data being copied.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_copy_bytes(const cardano_buffer_t* buffer, byte_t* dest, size_t dest_size);++/**+ * \brief Retrieves the total capacity of the buffer.+ *+ * This function returns the total amount of space allocated for the buffer, indicating how much data+ * it can hold before needing to expand. The capacity of a buffer is managed automatically, growing+ * as needed to accommodate new data added to the buffer. This function provides a way to inspect+ * the current capacity without affecting the buffer's state.+ *+ * \param[in] buffer The buffer instance whose total capacity is being queried. It must have been previously+ * created using one of the buffer creation functions. If the buffer is NULL, indicating an invalid or+ * uninitialized buffer instance, the function returns 0.+ *+ * \return The total capacity of the buffer in bytes, representing the maximum amount of data the buffer+ * can currently hold. If the buffer is NULL, the function returns 0.+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_buffer_get_capacity(const cardano_buffer_t* buffer);++/**+ * \brief Repositions the current position within a buffer to a specified offset.+ *+ * This function adjusts the current pointer position within the given `cardano_buffer_t`+ * object to the specified `position`. It is used to set the read/write position within the+ * buffer, allowing subsequent operations to start from the new location. This can be particularly+ * useful for parsing structured data or for resetting the position to rewrite or reread portions+ * of the buffer.+ *+ * \param buffer A pointer to the `cardano_buffer_t` object whose position is to be adjusted.+ * \param position The new position within the buffer where the current pointer should be set.+ *                 This value must be within the bounds of the buffer's current size.+ *+ * \return cardano_error_t Returns `CARDANO_SUCCESS` if the position within the buffer was+ *         successfully updated. If the function fails, a non-zero error code is returned,+ *         indicating an invalid `buffer`, an out-of-bounds `position`, or other errors+ *         related to manipulating the buffer's position.+ *+ * Example Usage:+ * \code+ * cardano_buffer_t* buffer = ...; // Assume buffer is previously initialized and populated+ * size_t new_position = 10; // Desired position to seek to within the buffer+ *+ * cardano_error_t error = cardano_buffer_seek(buffer, new_position);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // The buffer's current position is now set to `new_position`+ *   // Subsequent operations will start from this position+ * }+ *+ * // Continue with further operations on `buffer`+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_seek(cardano_buffer_t* buffer, size_t position);++/**+ * \brief Appends data to the end of the buffer, expanding its capacity if necessary.+ *+ * This function allows for the addition of arbitrary data to the end of a dynamically sized buffer. If the+ * buffer does not have enough capacity to accommodate the new data, it is automatically expanded.+ *+ * \param[in] buffer The buffer to which data will be appended. It must be a valid, previously allocated+ * buffer instance. The buffer's capacity will be expanded if there is not enough space for the new data.+ * \param[in] data A pointer to the byte array containing the data to be appended to the buffer. The function+ * copies the specified number of bytes from this array into the buffer.+ * \param[in] size The size of the data in bytes to be appended. This specifies how much of the data+ * pointed to by `data` should be copied into the buffer.+ *+ * \return Returns \ref CARDANO_SUCCESS if the append operation was successful. If the operation encounters an error,+ *        such as invalid parameters or issues with writing to the buffer, an appropriate error code is returned+ *        indicating the reason for the failure. Consult the \ref cardano_error_t documentation for details on possible+ *        error codes and their meanings.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write(cardano_buffer_t* buffer, const byte_t* data, size_t size);++/**+ * \brief Reads a specified amount of data from the buffer into a provided output array.+ *+ * This function attempts to copy a given number of bytes from the source buffer into the specified output+ * array. If the buffer does not contain enough data to fulfill the requested read operation, an error is+ * returned.+ *+ * \param[in] buffer The source buffer from which data will be read.+ * \param[out] data An output array where the read data will be copied. The array must have sufficient space+ * to store the number of bytes specified by `bytes_to_read`. It is the caller's responsibility to ensure+ * that the size of `data` is at least as large as `bytes_to_read`.+ * \param[in] bytes_to_read The number of bytes to read from the buffer and copy into the `data` output array.+ * This specifies how much data the function should attempt to transfer from the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. \ref CARDANO_SUCCESS+ * is returned if the specified amount of data was successfully read from the buffer and copied into the+ * output array. If the operation fails, for example, because the buffer contains less data than requested,+ * an appropriate error code is returned to indicate the specific reason for failure.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read(cardano_buffer_t* buffer, byte_t* data, size_t bytes_to_read);++/**+ * \brief Writes a 16-bit unsigned integer to the specified buffer, encoding the integer in little-endian byte order.+ *+ * This function takes a 16-bit unsigned integer and writes it to the target buffer in little-endian format.+ *+ * \param[in] buffer The buffer into which the 16-bit unsigned integer will be written.+ * \param[in] value The 16-bit unsigned integer value to be written to the buffer. The function will+ * split the integer into bytes according to little-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_uint16_le(cardano_buffer_t* buffer, uint16_t value);++/**+ * \brief Writes a 32-bit unsigned integer to the specified buffer, encoding the integer in little-endian byte order.+ *+ * This function takes a 32-bit unsigned integer and writes it to the target buffer in little-endian format.+ *+ * \param[in] buffer The buffer into which the 32-bit unsigned integer will be written.+ * \param[in] value The 32-bit unsigned integer value to be encoded and written to the buffer. The function will+ * split the integer into bytes according to little-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer value is+ * successfully encoded and stored in the buffer, \ref CARDANO_SUCCESS is returned. In the event of an error, such+ * as failure to expand the buffer's capacity, an error code will be returned that details the specific cause of+ * the failure. Clients are encouraged to check this return value to verify that the write operation was successful+ * and to handle any errors that may have occurred.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_uint32_le(cardano_buffer_t* buffer, uint32_t value);++/**+ * \brief Writes a 64-bit unsigned integer to the specified buffer, encoding the integer in little-endian byte order.+ *+ * This function takes a 64-bit unsigned integer and writes it to the target buffer in little-endian format.+ *+ * \param[in] buffer The buffer into which the 64-bit unsigned integer will be written.+ * \param[in] value The 64-bit unsigned integer value to be encoded and written to the buffer. The function will+ * split the integer into bytes according to little-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer value is+ * successfully encoded and stored in the buffer, \ref CARDANO_SUCCESS is returned. In the event of an error, such+ * as failure to expand the buffer's capacity, an error code will be returned that details the specific cause of+ * the failure. Clients are encouraged to check this return value to verify that the write operation was successful+ * and to handle any errors that may have occurred.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_uint64_le(cardano_buffer_t* buffer, uint64_t value);++/**+ * \brief Writes a 16-bit signed integer to the specified buffer, encoding the integer in little-endian byte order.+ *+ * This function takes a 16-bit signed integer and writes it to the target buffer in little-endian format.+ *+ * \param[in] buffer The buffer into which the 16-bit signed integer will be written.+ * \param[in] value The 16-bit signed integer value to be written to the buffer. The function will+ * split the integer into bytes according to little-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_int16_le(cardano_buffer_t* buffer, int16_t value);++/**+ * \brief Writes a 32-bit signed integer to the specified buffer, encoding the integer in little-endian byte order.+ *+ * This function takes a 32-bit signed integer and writes it to the target buffer in little-endian format.+ *+ * \param[in] buffer The buffer into which the 32-bit signed integer will be written.+ * \param[in] value The 32-bit signed integer value to be written to the buffer. The function will+ * split the integer into bytes according to little-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_int32_le(cardano_buffer_t* buffer, int32_t value);++/**+ * \brief Writes a 64-bit signed integer to the specified buffer, encoding the integer in little-endian byte order.+ *+ * This function takes a 64-bit signed integer and writes it to the target buffer in little-endian format.+ *+ * \param[in] buffer The buffer into which the 64-bit signed integer will be written.+ * \param[in] value The 64-bit signed integer value to be written to the buffer. The function will+ * split the integer into bytes according to little-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_int64_le(cardano_buffer_t* buffer, int64_t value);++/**+ * \brief Writes a floating-point number to the specified buffer, encoding the number in little-endian byte order.+ *+ * This function takes a floating-point number (float) and writes it to the target buffer in little-endian format.+ *+ * \param[in] buffer The buffer into which the floating-point number will be written.+ * \param[in] value The floating-point number (float) to be written to the buffer. The function will+ * split the float into bytes according to little-endian order and then store these bytes sequentially in+ * the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the float is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_float_le(cardano_buffer_t* buffer, float value);++/**+ * \brief Writes a double number to the specified buffer, encoding the number in little-endian byte order.+ *+ * This function takes a double number and writes it to the target buffer in little-endian format.+ *+ * \param[in] buffer The buffer into which the double number will be written.+ * \param[in] value The double number to be written to the buffer. The function will+ * split the double into bytes according to little-endian order and then store these bytes sequentially in+ * the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the double is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_double_le(cardano_buffer_t* buffer, double value);++/**+ * \brief Writes a 16-bit unsigned integer to the specified buffer, encoding the integer in big-endian byte order.+ *+ * This function takes a 16-bit unsigned integer and writes it to the target buffer in big-endian format.+ *+ * \param[in] buffer The buffer into which the 16-bit unsigned integer will be written.+ * \param[in] value The 16-bit unsigned integer value to be written to the buffer. The function will+ * split the integer into bytes according to big-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_uint16_be(cardano_buffer_t* buffer, uint16_t value);++/**+ * \brief Writes a 32-bit unsigned integer to the specified buffer, encoding the integer in big-endian byte order.+ *+ * This function takes a 32-bit unsigned integer and writes it to the target buffer in big-endian format.+ *+ * \param[in] buffer The buffer into which the 32-bit unsigned integer will be written.+ * \param[in] value The 32-bit unsigned integer value to be written to the buffer. The function will+ * split the integer into bytes according to big-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_uint32_be(cardano_buffer_t* buffer, uint32_t value);++/**+ * \brief Writes a 64-bit unsigned integer to the specified buffer, encoding the integer in big-endian byte order.+ *+ * This function takes a 64-bit unsigned integer and writes it to the target buffer in big-endian format.+ *+ * \param[in] buffer The buffer into which the 64-bit unsigned integer will be written.+ * \param[in] value The 64-bit unsigned integer value to be written to the buffer. The function will+ * split the integer into bytes according to big-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_uint64_be(cardano_buffer_t* buffer, uint64_t value);++/**+ * \brief Writes a 16-bit signed integer to the specified buffer, encoding the integer in big-endian byte order.+ *+ * This function takes a 16-bit signed integer and writes it to the target buffer in big-endian format.+ *+ * \param[in] buffer The buffer into which the 16-bit signed integer will be written.+ * \param[in] value The 16-bit signed integer value to be written to the buffer. The function will+ * split the integer into bytes according to big-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_int16_be(cardano_buffer_t* buffer, int16_t value);++/**+ * \brief Writes a 32-bit signed integer to the specified buffer, encoding the integer in big-endian byte order.+ *+ * This function takes a 32-bit signed integer and writes it to the target buffer in big-endian format.+ *+ * \param[in] buffer The buffer into which the 32-bit signed integer will be written.+ * \param[in] value The 32-bit signed integer value to be written to the buffer. The function will+ * split the integer into bytes according to big-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_int32_be(cardano_buffer_t* buffer, int32_t value);++/**+ * \brief Writes a 64-bit signed integer to the specified buffer, encoding the integer in big-endian byte order.+ *+ * This function takes a 64-bit signed integer and writes it to the target buffer in big-endian format.+ *+ * \param[in] buffer The buffer into which the 64-bit signed integer will be written.+ * \param[in] value The 64-bit signed integer value to be written to the buffer. The function will+ * split the integer into bytes according to big-endian order and then store these bytes sequentially in the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the integer is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_int64_be(cardano_buffer_t* buffer, int64_t value);++/**+ * \brief Writes a floating-point number to the specified buffer, encoding the number in big-endian byte order.+ *+ * This function takes a floating-point number (float) and writes it to the target buffer in big-endian format.+ *+ * \param[in] buffer The buffer into which the floating-point number will be written.+ * \param[in] value The floating-point number (float) to be written to the buffer. The function will+ * split the float into bytes according to big-endian order and then store these bytes sequentially in+ * the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the float is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_float_be(cardano_buffer_t* buffer, float value);++/**+ * \brief Writes a double number to the specified buffer, encoding the number in big-endian byte order.+ *+ * This function takes a double number and writes it to the target buffer in big-endian format.+ *+ * \param[in] buffer The buffer into which the double number will be written.+ * \param[in] value The double number to be written to the buffer. The function will+ * split the double into bytes according to big-endian order and then store these bytes sequentially in+ * the buffer.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the write operation. If the double is+ * successfully written to the buffer, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ * error, such as an issue with expanding the buffer's capacity, an error code is returned that identifies+ * the failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_write_double_be(cardano_buffer_t* buffer, double value);++/**+ * \brief Reads a 16-bit unsigned integer from the specified buffer, decoding it from little-endian byte order.+ *+ * This function extracts a 16-bit unsigned integer from the buffer, assuming the number is stored in little-endian format.+ *+ * \param[in] buffer The buffer from which the 16-bit unsigned integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 16-bit unsigned integer variable where the decoded value will be stored.+ * The value is converted from little-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 16-bit unsigned+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_uint16_le(cardano_buffer_t* buffer, uint16_t* value);++/**+ * \brief Reads a 32-bit unsigned integer from the specified buffer, decoding it from little-endian byte order.+ *+ * This function extracts a 32-bit unsigned integer from the buffer, assuming the number is stored in little-endian format.+ *+ * \param[in] buffer The buffer from which the 32-bit unsigned integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 32-bit unsigned integer variable where the decoded value will be stored.+ * The value is converted from little-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 32-bit unsigned+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_uint32_le(cardano_buffer_t* buffer, uint32_t* value);++/**+ * \brief Reads a 64-bit unsigned integer from the specified buffer, decoding it from little-endian byte order.+ *+ * This function extracts a 64-bit unsigned integer from the buffer, assuming the number is stored in little-endian format.+ *+ * \param[in] buffer The buffer from which the 64-bit unsigned integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 64-bit unsigned integer variable where the decoded value will be stored.+ * The value is converted from little-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 64-bit unsigned+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_uint64_le(cardano_buffer_t* buffer, uint64_t* value);++/**+ * \brief Reads a 16-bit signed integer from the specified buffer, decoding it from little-endian byte order.+ *+ * This function extracts a 16-bit signed integer from the buffer, assuming the number is stored in little-endian format.+ *+ * \param[in] buffer The buffer from which the 16-bit signed integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 16-bit signed integer variable where the decoded value will be stored.+ * The value is converted from little-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 16-bit signed+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_int16_le(cardano_buffer_t* buffer, int16_t* value);++/**+ * \brief Reads a 32-bit signed integer from the specified buffer, decoding it from little-endian byte order.+ *+ * This function extracts a 32-bit signed integer from the buffer, assuming the number is stored in little-endian format.+ *+ * \param[in] buffer The buffer from which the 32-bit signed integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 32-bit signed integer variable where the decoded value will be stored.+ * The value is converted from little-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 32-bit signed+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_int32_le(cardano_buffer_t* buffer, int32_t* value);++/**+ * \brief Reads a 64-bit signed integer from the specified buffer, decoding it from little-endian byte order.+ *+ * This function extracts a 64-bit signed integer from the buffer, assuming the number is stored in little-endian format.+ *+ * \param[in] buffer The buffer from which the 64-bit signed integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 64-bit signed integer variable where the decoded value will be stored.+ * The value is converted from little-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 64-bit signed+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_int64_le(cardano_buffer_t* buffer, int64_t* value);++/**+ * \brief Reads a floating-point number from the specified buffer, decoding it from little-endian byte order.+ *+ * This function extracts a floating-point number (float) from the buffer, assuming the number is stored in+ * little-endian format.+ *+ * \param[in] buffer The buffer from which the floating-point number will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a floating-point number variable where the decoded value will be stored.+ * The value is converted from little-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the floating-point+ * number is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_float_le(cardano_buffer_t* buffer, float* value);++/**+ * \brief Reads a double number from the specified buffer, decoding it from little-endian byte order.+ *+ * This function extracts a double number from the buffer, assuming the number is stored in+ * little-endian format.+ *+ * \param[in] buffer The buffer from which the double number will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a double number variable where the decoded value will be stored.+ * The value is converted from little-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the double+ * number is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_double_le(cardano_buffer_t* buffer, double* value);++/**+ * \brief Reads a 16-bit unsigned integer from the specified buffer, decoding it from big-endian byte order.+ *+ * This function extracts a 16-bit unsigned integer from the buffer, assuming the number is stored in big-endian format.+ *+ * \param[in] buffer The buffer from which the 16-bit unsigned integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 16-bit unsigned integer variable where the decoded value will be stored.+ * The value is converted from big-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 16-bit unsigned+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_uint16_be(cardano_buffer_t* buffer, uint16_t* value);++/**+ * \brief Reads a 32-bit unsigned integer from the specified buffer, decoding it from big-endian byte order.+ *+ * This function extracts a 32-bit unsigned integer from the buffer, assuming the number is stored in big-endian format.+ *+ * \param[in] buffer The buffer from which the 32-bit unsigned integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 32-bit unsigned integer variable where the decoded value will be stored.+ * The value is converted from big-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 32-bit unsigned+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_uint32_be(cardano_buffer_t* buffer, uint32_t* value);++/**+ * \brief Reads a 64-bit unsigned integer from the specified buffer, decoding it from big-endian byte order.+ *+ * This function extracts a 64-bit unsigned integer from the buffer, assuming the number is stored in big-endian format.+ *+ * \param[in] buffer The buffer from which the 64-bit unsigned integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 64-bit unsigned integer variable where the decoded value will be stored.+ * The value is converted from big-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 64-bit unsigned+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_uint64_be(cardano_buffer_t* buffer, uint64_t* value);++/**+ * \brief Reads a 16-bit signed integer from the specified buffer, decoding it from big-endian byte order.+ *+ * This function extracts a 16-bit signed integer from the buffer, assuming the number is stored in big-endian format.+ *+ * \param[in] buffer The buffer from which the 16-bit signed integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 16-bit signed integer variable where the decoded value will be stored.+ * The value is converted from big-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 16-bit signed+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_int16_be(cardano_buffer_t* buffer, int16_t* value);++/**+ * \brief Reads a 32-bit signed integer from the specified buffer, decoding it from big-endian byte order.+ *+ * This function extracts a 32-bit signed integer from the buffer, assuming the number is stored in big-endian format.+ *+ * \param[in] buffer The buffer from which the 32-bit signed integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 32-bit signed integer variable where the decoded value will be stored.+ * The value is converted from big-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 32-bit signed+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_int32_be(cardano_buffer_t* buffer, int32_t* value);++/**+ * \brief Reads a 64-bit signed integer from the specified buffer, decoding it from big-endian byte order.+ *+ * This function extracts a 64-bit signed integer from the buffer, assuming the number is stored in big-endian format.+ *+ * \param[in] buffer The buffer from which the 64-bit signed integer will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a 64-bit signed integer variable where the decoded value will be stored.+ * The value is converted from big-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the 64-bit signed+ * integer is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_int64_be(cardano_buffer_t* buffer, int64_t* value);++/**+ * \brief Reads a floating-point number from the specified buffer, decoding it from big-endian byte order.+ *+ * This function extracts a floating-point number (float) from the buffer, assuming the number is stored in+ * big-endian format.+ *+ * \param[in] buffer The buffer from which the floating-point number will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a floating-point number variable where the decoded value will be stored.+ * The value is converted from big-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the floating-point+ * number is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_float_be(cardano_buffer_t* buffer, float* value);++/**+ * \brief Reads a double number from the specified buffer, decoding it from big-endian byte order.+ *+ * This function extracts a double number from the buffer, assuming the number is stored in+ * big-endian format.+ *+ * \param[in] buffer The buffer from which the double number will be read. The buffer's current read position+ * determines the starting point for reading the value.+ * \param[out] value A pointer to a double number variable where the decoded value will be stored.+ * The value is converted from big-endian byte order to the native byte order of the executing platform+ * before being stored.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the read operation. If the double+ * number is successfully read and decoded from the buffer, \ref CARDANO_SUCCESS is returned. If the operation+ * encounters an error, such as attempting to read beyond the available data in the buffer, an error code+ * is returned that identifies the specific failure reason.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_buffer_read_double_be(cardano_buffer_t* buffer, double* value);++/**+ * \brief Sets the last error message for a given buffer object.+ *+ * Records an error message in the buffer's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] buffer A pointer to the \ref cardano_buffer_t instance whose last error message is+ *                   to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the buffer's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_buffer_set_last_error(cardano_buffer_t* buffer, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific object.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_buffer_set_last_error for the given+ * object. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] buffer A pointer to the \ref cardano_buffer_t instance whose last error+ *                   message is to be retrieved. If the object is NULL, the function+ *                   returns a generic error message indicating the null object.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified object. If the object is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_buffer_set_last_error for the same object, or until+ *       the object is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_buffer_get_last_error(const cardano_buffer_t* buffer);++/**+ * \brief Creates an independent deep copy of a \ref cardano_buffer_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_buffer_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_buffer_deep_clone(const cardano_buffer_t* source, cardano_buffer_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_BUFFER_H
+ vendor/include/cardano/cardano.h view
@@ -0,0 +1,305 @@+/**+ * \file cardano.h+ *+ * \author angel.castillo+ * \date   Mar 13, 2024+ *+ * \section LICENSE+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_H+#define BIGLUP_LABS_INCLUDE_CARDANO_H++/* INCLUDES ******************************************************************/++#include <cardano/address/address.h>+#include <cardano/address/address_type.h>+#include <cardano/address/base_address.h>+#include <cardano/address/byron_address.h>+#include <cardano/address/byron_address_attributes.h>+#include <cardano/address/byron_address_type.h>+#include <cardano/address/enterprise_address.h>+#include <cardano/address/pointer_address.h>+#include <cardano/address/reward_address.h>+#include <cardano/address/stake_pointer.h>+#include <cardano/assets/asset_id.h>+#include <cardano/assets/asset_id_list.h>+#include <cardano/assets/asset_id_map.h>+#include <cardano/assets/asset_name.h>+#include <cardano/assets/asset_name_list.h>+#include <cardano/assets/asset_name_map.h>+#include <cardano/assets/multi_asset.h>+#include <cardano/assets/policy_id_list.h>+#include <cardano/auxiliary_data/auxiliary_data.h>+#include <cardano/auxiliary_data/metadatum.h>+#include <cardano/auxiliary_data/metadatum_kind.h>+#include <cardano/auxiliary_data/metadatum_label_list.h>+#include <cardano/auxiliary_data/metadatum_list.h>+#include <cardano/auxiliary_data/metadatum_map.h>+#include <cardano/auxiliary_data/plutus_v1_script_list.h>+#include <cardano/auxiliary_data/plutus_v2_script_list.h>+#include <cardano/auxiliary_data/plutus_v3_script_list.h>+#include <cardano/auxiliary_data/plutus_v4_script_list.h>+#include <cardano/auxiliary_data/transaction_metadata.h>+#include <cardano/bip39.h>+#include <cardano/buffer.h>+#include <cardano/cbor/cbor_major_type.h>+#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_reader_state.h>+#include <cardano/cbor/cbor_simple_value.h>+#include <cardano/cbor/cbor_tag.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/certs/auth_committee_hot_cert.h>+#include <cardano/certs/cert_type.h>+#include <cardano/certs/certificate.h>+#include <cardano/certs/certificate_set.h>+#include <cardano/certs/genesis_key_delegation_cert.h>+#include <cardano/certs/mir_cert.h>+#include <cardano/certs/mir_cert_pot_type.h>+#include <cardano/certs/mir_cert_type.h>+#include <cardano/certs/mir_to_pot_cert.h>+#include <cardano/certs/mir_to_stake_creds_cert.h>+#include <cardano/certs/pool_registration_cert.h>+#include <cardano/certs/pool_retirement_cert.h>+#include <cardano/certs/register_drep_cert.h>+#include <cardano/certs/registration_cert.h>+#include <cardano/certs/resign_committee_cold_cert.h>+#include <cardano/certs/stake_delegation_cert.h>+#include <cardano/certs/stake_deregistration_cert.h>+#include <cardano/certs/stake_registration_cert.h>+#include <cardano/certs/stake_registration_delegation_cert.h>+#include <cardano/certs/stake_vote_delegation_cert.h>+#include <cardano/certs/stake_vote_registration_delegation_cert.h>+#include <cardano/certs/unregister_drep_cert.h>+#include <cardano/certs/unregistration_cert.h>+#include <cardano/certs/update_drep_cert.h>+#include <cardano/certs/vote_delegation_cert.h>+#include <cardano/certs/vote_registration_delegation_cert.h>+#include <cardano/common/anchor.h>+#include <cardano/common/bigint.h>+#include <cardano/common/byte_order.h>+#include <cardano/common/credential.h>+#include <cardano/common/credential_type.h>+#include <cardano/common/datum.h>+#include <cardano/common/datum_type.h>+#include <cardano/common/drep.h>+#include <cardano/common/drep_type.h>+#include <cardano/common/ex_units.h>+#include <cardano/common/governance_action_id.h>+#include <cardano/common/governance_key_type.h>+#include <cardano/common/guard_set.h>+#include <cardano/common/network_id.h>+#include <cardano/common/protocol_version.h>+#include <cardano/common/reward_address_list.h>+#include <cardano/common/unit_interval.h>+#include <cardano/common/utxo.h>+#include <cardano/common/withdrawal_map.h>+#include <cardano/crypto/bip32_private_key.h>+#include <cardano/crypto/bip32_public_key.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/crypto/blake2b_hash_set.h>+#include <cardano/crypto/blake2b_hash_size.h>+#include <cardano/crypto/crc32.h>+#include <cardano/crypto/ed25519_private_key.h>+#include <cardano/crypto/ed25519_public_key.h>+#include <cardano/crypto/ed25519_signature.h>+#include <cardano/crypto/emip3.h>+#include <cardano/crypto/pbkdf2.h>+#include <cardano/encoding/base58.h>+#include <cardano/encoding/bech32.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_context.h>+#include <cardano/json/json_format.h>+#include <cardano/json/json_object.h>+#include <cardano/json/json_object_type.h>+#include <cardano/json/json_writer.h>+#include <cardano/key_handlers/account_derivation_path.h>+#include <cardano/key_handlers/cip_1852_constants.h>+#include <cardano/key_handlers/derivation_path.h>+#include <cardano/key_handlers/secure_key_handler.h>+#include <cardano/key_handlers/secure_key_handler_impl.h>+#include <cardano/key_handlers/secure_key_handler_type.h>+#include <cardano/key_handlers/software_secure_key_handler.h>+#include <cardano/message_signing/cip8.h>+#include <cardano/object.h>+#include <cardano/plutus_data/constr_plutus_data.h>+#include <cardano/plutus_data/plutus_data.h>+#include <cardano/plutus_data/plutus_data_kind.h>+#include <cardano/plutus_data/plutus_list.h>+#include <cardano/plutus_data/plutus_map.h>+#include <cardano/pool_params/bls_key.h>+#include <cardano/pool_params/ipv4.h>+#include <cardano/pool_params/ipv6.h>+#include <cardano/pool_params/multi_host_name_relay.h>+#include <cardano/pool_params/pool_metadata.h>+#include <cardano/pool_params/pool_owners.h>+#include <cardano/pool_params/pool_params.h>+#include <cardano/pool_params/relay.h>+#include <cardano/pool_params/relay_type.h>+#include <cardano/pool_params/relays.h>+#include <cardano/pool_params/single_host_addr_relay.h>+#include <cardano/pool_params/single_host_name_relay.h>+#include <cardano/proposal_procedures/committee.h>+#include <cardano/proposal_procedures/committee_members_map.h>+#include <cardano/proposal_procedures/constitution.h>+#include <cardano/proposal_procedures/credential_set.h>+#include <cardano/proposal_procedures/governance_action_type.h>+#include <cardano/proposal_procedures/hard_fork_initiation_action.h>+#include <cardano/proposal_procedures/info_action.h>+#include <cardano/proposal_procedures/new_constitution_action.h>+#include <cardano/proposal_procedures/no_confidence_action.h>+#include <cardano/proposal_procedures/parameter_change_action.h>+#include <cardano/proposal_procedures/proposal_procedure.h>+#include <cardano/proposal_procedures/proposal_procedure_set.h>+#include <cardano/proposal_procedures/treasury_withdrawals_action.h>+#include <cardano/proposal_procedures/update_committee_action.h>+#include <cardano/protocol_params/cost_model.h>+#include <cardano/protocol_params/costmdls.h>+#include <cardano/protocol_params/drep_voting_thresholds.h>+#include <cardano/protocol_params/ex_unit_prices.h>+#include <cardano/protocol_params/pool_voting_thresholds.h>+#include <cardano/protocol_params/proposed_param_updates.h>+#include <cardano/protocol_params/protocol_param_update.h>+#include <cardano/protocol_params/update.h>+#include <cardano/scripts/native_scripts/native_script.h>+#include <cardano/scripts/native_scripts/native_script_list.h>+#include <cardano/scripts/native_scripts/native_script_type.h>+#include <cardano/scripts/native_scripts/script_all.h>+#include <cardano/scripts/native_scripts/script_any.h>+#include <cardano/scripts/native_scripts/script_invalid_after.h>+#include <cardano/scripts/native_scripts/script_invalid_before.h>+#include <cardano/scripts/native_scripts/script_n_of_k.h>+#include <cardano/scripts/native_scripts/script_pubkey.h>+#include <cardano/scripts/native_scripts/script_require_guard.h>+#include <cardano/scripts/plutus_scripts/plutus_language_version.h>+#include <cardano/scripts/plutus_scripts/plutus_v1_script.h>+#include <cardano/scripts/plutus_scripts/plutus_v2_script.h>+#include <cardano/scripts/plutus_scripts/plutus_v3_script.h>+#include <cardano/scripts/plutus_scripts/plutus_v4_script.h>+#include <cardano/scripts/script.h>+#include <cardano/scripts/script_language.h>+#include <cardano/slot_config.h>+#include <cardano/time.h>+#include <cardano/transaction/sub_transaction.h>+#include <cardano/transaction/transaction.h>+#include <cardano/transaction_body/account_balance_interval.h>+#include <cardano/transaction_body/account_balance_intervals_map.h>+#include <cardano/transaction_body/direct_deposit_map.h>+#include <cardano/transaction_body/required_guards_map.h>+#include <cardano/transaction_body/sub_transaction_body.h>+#include <cardano/transaction_body/sub_transaction_set.h>+#include <cardano/transaction_body/transaction_body.h>+#include <cardano/transaction_body/transaction_input.h>+#include <cardano/transaction_body/transaction_input_set.h>+#include <cardano/transaction_body/transaction_output.h>+#include <cardano/transaction_body/transaction_output_list.h>+#include <cardano/transaction_body/value.h>+#include <cardano/transaction_builder/balancing/deferred_redeemer_list.h>+#include <cardano/transaction_builder/balancing/implicit_coin.h>+#include <cardano/transaction_builder/balancing/input_to_redeemer_map.h>+#include <cardano/transaction_builder/balancing/transaction_balancing.h>+#include <cardano/transaction_builder/coin_selection/coin_selection_request.h>+#include <cardano/transaction_builder/coin_selection/coin_selection_strategy.h>+#include <cardano/transaction_builder/coin_selection/coin_selector.h>+#include <cardano/transaction_builder/coin_selection/coin_selector_impl.h>+#include <cardano/transaction_builder/coin_selection/large_first_coin_selector.h>+#include <cardano/transaction_builder/coin_selection/random_improve_coin_selector.h>+#include <cardano/transaction_builder/evaluation/native_tx_evaluator.h>+#include <cardano/transaction_builder/evaluation/provider_tx_evaluator.h>+#include <cardano/transaction_builder/evaluation/tx_evaluator.h>+#include <cardano/transaction_builder/evaluation/tx_evaluator_impl.h>+#include <cardano/transaction_builder/fee.h>+#include <cardano/transaction_builder/script_data_hash.h>+#include <cardano/transaction_builder/sub_transaction_builder.h>+#include <cardano/transaction_builder/transaction_builder.h>+#include <cardano/typedefs.h>+#include <cardano/uplc/uplc_apply_params.h>+#include <cardano/voting_procedures/governance_action_id_list.h>+#include <cardano/voting_procedures/vote.h>+#include <cardano/voting_procedures/voter.h>+#include <cardano/voting_procedures/voter_list.h>+#include <cardano/voting_procedures/voter_type.h>+#include <cardano/voting_procedures/voting_procedure.h>+#include <cardano/voting_procedures/voting_procedures.h>+#include <cardano/witness_set/bootstrap_witness.h>+#include <cardano/witness_set/bootstrap_witness_set.h>+#include <cardano/witness_set/native_script_set.h>+#include <cardano/witness_set/plutus_data_set.h>+#include <cardano/witness_set/plutus_v1_script_set.h>+#include <cardano/witness_set/plutus_v2_script_set.h>+#include <cardano/witness_set/plutus_v3_script_set.h>+#include <cardano/witness_set/plutus_v4_script_set.h>+#include <cardano/witness_set/redeemer.h>+#include <cardano/witness_set/redeemer_list.h>+#include <cardano/witness_set/redeemer_tag.h>+#include <cardano/witness_set/vkey_witness.h>+#include <cardano/witness_set/vkey_witness_set.h>+#include <cardano/witness_set/witness_set.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Retrieves the version of the Cardano C library.+ *+ * This function returns a string representing the version of the Cardano C library. The string+ * is statically allocated and should not be freed by the caller. The version string follows the+ * Semantic Versioning (SemVer) format, which consists of three segments: MAJOR.MINOR.PATCH+ * (e.g., "1.0.3").+ *+ * \return A pointer to a statically allocated string containing the library's version. This string+ * is located in read-only memory and must not be modified or freed by the caller.+ */+CARDANO_EXPORT const char* cardano_get_lib_version(void);++/**+ * \brief Securely wipes the contents of a buffer from memory.+ *+ * The `cardano_memzero` function is used to securely erase the sensitive data stored in the provided \p buffer.+ * This ensures that the data is no longer recoverable from memory after it has been used.+ *+ * After use, sensitive data should be overwritten. However, traditional approaches like `memset()` or hand-written+ * memory clearing routines can be stripped away by optimizing compilers or linkers, potentially leaving sensitive+ * information exposed.+ *+ * The `cardano_memzero` function guarantees that the memory is cleared, even in the presence of compiler optimizations.+ * It is especially important to call this function before freeing memory that contains sensitive information, such as+ * cryptographic keys or decrypted data, to prevent the data from remaining in memory.+ *+ * \param[in] buffer A pointer to the buffer whose contents should be securely erased.+ * \param[in] size The size of the buffer in bytes.+ *+ * \example+ * \code+ * // Example usage after processing sensitive data+ * char sensitive_data[64] = ...; // Buffer containing sensitive data+ *+ * // Wipe the buffer contents securely+ * cardano_memzero(sensitive_data, 64);+ * \endcode+ */+CARDANO_EXPORT void cardano_memzero(void* buffer, size_t size);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_H
+ vendor/include/cardano/cbor/cbor_major_type.h view
@@ -0,0 +1,117 @@+/**+ * \file cbor_major_type.h+ *+ * \author angel.castillo+ * \date   Sep 12, 2023+ *+ * Copyright 2023 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CBOR_MAJOR_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CBOR_MAJOR_TYPE_H++/* INCLUDES ******************************************************************/++#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents CBOR Major Types as defined in RFC 7049 section 2.1.+ *+ * These major types are used to identify the type of data in a CBOR data item.+ */+typedef enum+{+  /**+   * \brief An unsigned integer.+   *+   * Range: 0 to 2^64-1 inclusive. The value of the encoded item is the argument itself.+   */+  CARDANO_CBOR_MAJOR_TYPE_UNSIGNED_INTEGER = 0,++  /**+   * \brief A negative integer.+   *+   * Range: -2^64 to -1 inclusive. The value of the item is -1 minus the argument.+   */+  CARDANO_CBOR_MAJOR_TYPE_NEGATIVE_INTEGER = 1,++  /**+   * \brief A byte string.+   *+   * The number of bytes in the string is equal to the argument.+   */+  CARDANO_CBOR_MAJOR_TYPE_BYTE_STRING = 2,++  /**+   * \brief A text string encoded as UTF-8.+   *+   * Refer to Section 2 and RFC 3629. The number of bytes in the string is equal to the argument.+   */+  CARDANO_CBOR_MAJOR_TYPE_UTF8_STRING = 3,++  /**+   * \brief An array of data items.+   *+   * Also known as lists, sequences, or tuples. A "CBOR sequence" is slightly different (see RFC 8742).+   * The argument specifies the number of data items in the array.+   */+  CARDANO_CBOR_MAJOR_TYPE_ARRAY = 4,++  /**+   * \brief A map of pairs of data items.+   *+   * Also known as tables, dictionaries, hashes, or objects (in JSON).+   */+  CARDANO_CBOR_MAJOR_TYPE_MAP = 5,++  /**+   * \brief A tagged data item ("tag").+   *+   * Tag number ranges from 0 to 2^64-1 inclusive. The enclosed data item (tag content) follows the head.+   */+  CARDANO_CBOR_MAJOR_TYPE_TAG = 6,++  /**+   * \brief Simple values, floating-point numbers, and the "break" stop code.+   */+  CARDANO_CBOR_MAJOR_TYPE_SIMPLE = 7,++  /**+   * \brief Undefined major type.+   */+  CARDANO_CBOR_MAJOR_TYPE_UNDEFINED = 0xFFFFFFFF+} cardano_cbor_major_type_t;++/**+ * \brief Converts CBOR major type to their human readable form if possible.+ *+ * \param[in] major_type The major type to get the string representation for.+ * \return Human readable form of the given major type. If the major type is unknown,+ * returns "Major Type: Unknown".+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_cbor_major_type_to_string(cardano_cbor_major_type_t major_type);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CBOR_MAJOR_TYPE_H
+ vendor/include/cardano/cbor/cbor_reader.h view
@@ -0,0 +1,1036 @@+/**+ * \file cbor_reader.h+ *+ * \author luisd.bianchi+ * \date   Mar 14, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CBOR_READER_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CBOR_READER_H++/* INCLUDES ******************************************************************/++#include <cardano/buffer.h>+#include <cardano/cbor/cbor_reader_state.h>+#include <cardano/cbor/cbor_simple_value.h>+#include <cardano/cbor/cbor_tag.h>+#include <cardano/common/bigint.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a reader for parsing Concise Binary Object Representation (CBOR) encoded data.+ */+typedef struct cardano_cbor_reader_t cardano_cbor_reader_t;++/**+ * \brief Creates a new instance of a cardano_cbor_reader_t object for reading CBOR encoded data.+ *+ * This function initializes a new CBOR reader object with a given buffer containing CBOR data.+ * The created reader is capable of parsing the CBOR data, allowing for the extraction and+ * interpretation of the encoded information.+ *+ * \param[in] cbor_data Pointer to the buffer containing the CBOR encoded data to be read.+ * \param[in] size The size of the buffer in bytes.+ *+ * \return A pointer to the newly created \ref cardano_cbor_reader_t object. This object+ * represents a "strong reference" to the CBOR reader, meaning that it is fully initialized+ * and ready for use. The caller is responsible for managing the lifecycle of this object.+ * Specifically, once the CBOR reader is no longer needed, the caller must release it by+ * calling \ref cardano_cbor_reader_unref.+ *+ *+ * Usage Example:+ * \code{.c}+ * // Create a new CBOR reader+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(data, size_size);+ *+ * if (reader)+ * {+ *   // Use the reader for CBOR decoding tasks+ *+ *   // Once done, ensure to clean up and release the reader+ *   cardano_cbor_reader_unref(&reader);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_cbor_reader_t* cardano_cbor_reader_new(const byte_t* cbor_data, size_t size);++/**+ * \brief Creates a new instance of a cardano_cbor_reader_t object for reading CBOR data from a hexadecimal string.+ *+ * \param[in] hex_string Pointer to the null-terminated string containing the hexadecimal representation of CBOR encoded data.+ * \param[in] size The size of the hex string in bytes, not including the null terminator.+ *+ * \return On success, a pointer to the newly created \ref cardano_cbor_reader_t object. This object+ * represents a "strong reference" to the CBOR reader, indicating that it is fully initialized+ * and ready to parse the decoded CBOR data. The caller is responsible for managing the lifecycle+ * of this object. Specifically, the object must be released by calling \ref cardano_cbor_reader_unref+ * once it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming `hex_data` is a null-terminated string containing hexadecimal CBOR data+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_from_hex(hex_data, strlen(hex_data));+ *+ * if (reader)+ * {+ *   // Use the reader for CBOR decoding tasks+ *+ *   // Once done, ensure to clean up and release the reader+ *   cardano_cbor_reader_unref(&reader);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_cbor_reader_t* cardano_cbor_reader_from_hex(const char* hex_string, size_t size);++/**+ * \brief Decrements the reference count of a CBOR reader object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_cbor_reader_t object+ * by decreasing its reference count. When the reference count reaches zero, the CBOR reader is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] cbor_reader A pointer to the pointer of the CBOR reader object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new();+ *+ * // Perform operations with the reader...+ *+ * cardano_cbor_reader_unref(&reader);+ * // At this point, reader is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_cbor_reader_unref, the pointer to the \ref cardano_cbor_reader_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_cbor_reader_unref(cardano_cbor_reader_t** cbor_reader);++/**+ * \brief Increases the reference count of the cardano_cbor_reader_t object.+ *+ * This function is used to manually increment the reference count of a CBOR reader+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_cbor_reader_unref.+ *+ * \param cbor_reader A pointer to the CBOR reader object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming reader is a previously created CBOR reader object+ *+ * cardano_cbor_reader_ref(reader);+ *+ * // Now reader can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_cbor_reader_ref there is a corresponding+ * call to \ref cardano_cbor_reader_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_cbor_reader_ref(cardano_cbor_reader_t* cbor_reader);++/**+ * \brief Retrieves the current reference count of the cardano_cbor_reader_t object.+ *+ * This function returns the number of active references to a CBOR reader object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_cbor_reader_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param cbor_reader A pointer to the CBOR reader object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified CBOR reader object. If the object+ * is properly managed (i.e., every \ref cardano_cbor_reader_ref call is matched with a+ * \ref cardano_cbor_reader_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming reader is a previously created CBOR reader object+ *+ * size_t ref_count = cardano_cbor_reader_refcount(reader);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_cbor_reader_refcount(const cardano_cbor_reader_t* cbor_reader);++/**+ * \brief Reads the next CBOR token from the reader without advancing the reader's internal position.+ *+ * This function examines the next CBOR token in the data stream, allowing the caller to inspect+ * the type and structure of the upcoming data without actually consuming it. This is particularly+ * useful for conditional parsing based on the upcoming data type or for implementing look-ahead+ * parsing strategies in more complex CBOR structures.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the next CBOR token+ * is to be examined.+ * \param[out] state Pointer to a \ref cardano_cbor_reader_state_t variable where the current state of the+ * CBOR reader will be stored.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on successful+ * examination of the next CBOR token, or an appropriate error code indicating the reason for failure.+ * Refer to \ref cardano_error_t documentation for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_state_t state;+ * cardano_error_t error = cardano_cbor_reader_peek_state(&state);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Analyze `state` to decide how to proceed+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_peek_state(cardano_cbor_reader_t* reader, cardano_cbor_reader_state_t* state);++/**+ * \brief Retrieves the total number of unread bytes remaining in the CBOR reader's buffer.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the number of unread bytes is to be retrieved.+ * \param[out] bytes_remaining A pointer to a size_t variable where the number of unread bytes+ * remaining in the buffer will be stored. This value represents how much data is available+ * for reading and processing before the end of the buffer is reached.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * size_t bytes_remaining;+ * cardano_error_t error = cardano_cbor_reader_get_bytes_remaining(&bytes_remaining);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   printf("Bytes remaining: %zu\n", bytes_remaining);+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_get_bytes_remaining(cardano_cbor_reader_t* reader, size_t* bytes_remaining);++/**+ * \brief Retrieves the remaining bytes from the CBOR reader.+ *+ * This function copies the remainder of the bytes from the CBOR reader that have not yet been parsed.+ * It's useful for scenarios where the parsing process is either partial or selective, and the caller+ * needs access to the unparsed portion of the data.+ *+ * \param[in] reader The CBOR reader instance from which the remainder bytes are to be retrieved.+ * \param[out] remainder_bytes A buffer with a copy of the remainder bytes. The caller+ * is responsible for releasing this buffer using \ref cardano_buffer_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the remainder bytes were successfully retrieved and copied into+ *         the provided buffer. If the operation fails due to an insufficient buffer size or+ *         other issues, an appropriate error code is returned. Refer to \c cardano_error_t+ *         documentation for details on possible error codes.+ *+ * Example usage:+ * \code{.c}+ * cardano_buffer_t* remainder_bytes_buffer = NULL;+ *+ * if (cardano_cbor_reader_get_remainder_bytes(reader, buffer) == CARDANO_SUCCESS)+ * {+ *   // Use remainder_bytes_buffer as needed+ *   cardano_buffer_unref(&remainder_bytes_buffer);+ * }+ *+ * cardano_cbor_reader_unref(&reader);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_get_remainder_bytes(cardano_cbor_reader_t* reader, cardano_buffer_t** remainder_bytes);++/**+ * \brief Clones a CBOR reader.+ *+ * This function creates a duplicate of the given \ref cardano_cbor_reader_t object.+ * It allocates a new \ref cardano_cbor_reader_t object that is a clone of the provided reader.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t object to be cloned.+ * \param[out] clone On successful cloning, this will point to a newly created+ *                   \ref cardano_cbor_reader_t object. This object represents a "strong reference"+ *                   to the cloned reader, meaning that it is fully initialized and ready for use.+ *                   The caller is responsible for managing the lifecycle of this object.+ *                   Specifically, once the cloned reader is no longer needed, the caller must release it+ *                   by calling \ref cardano_cbor_reader_unref.+ *+ * \return \ref CARDANO_SUCCESS if the reader was successfully cloned, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* original_reader = cardano_cbor_reader_new(...); // Assume original_reader is initialized+ * cardano_cbor_reader_t* cloned_reader = NULL;+ *+ * // Attempt to clone the original reader+ * cardano_error_t result = cardano_cbor_reader_clone(original_reader, &cloned_reader);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the cloned reader+ *+ *   // Once done, ensure to clean up and release the cloned reader+ *   cardano_cbor_reader_unref(&cloned_reader);+ * }+ *+ * // Clean up the original reader object once done+ * cardano_cbor_reader_unref(&original_reader);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_clone(cardano_cbor_reader_t* reader, cardano_cbor_reader_t** clone);++/**+ * \brief Skips the next CBOR data item and advances the reader.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the next CBOR data item+ * is to be skipped.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming `reader` is a previously initialized CBOR reader+ * cardano_error_t error = cardano_cbor_reader_skip_value(reader);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // The reader has successfully skipped the next CBOR data item+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_skip_value(cardano_cbor_reader_t* reader);++/**+ * \brief Reads the next CBOR data item, returning a subarray with the encoded value.+ *+ * This function reads the next CBOR data item from the reader and returns a subarray+ * representing the encoded value as a contiguous region of memory. The subarray is+ * returned as a pointer to a \ref cardano_buffer_t object, which contains the encoded+ * data. For data items encoded with indefinite length, the returned subarray includes+ * the "break" byte that marks the end of the data item.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the next+ * CBOR data item is to be read.+ * \param[out] encoded_value A pointer to a pointer to \ref cardano_buffer_t, which will be+ * allocated and populated with the encoded value. The caller is responsible for releasing+ * this buffer using \ref cardano_buffer_unref when it is no longer needed.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * cardano_buffer_t* encoded_value = NULL;+ * cardano_error_t error = cardano_cbor_reader_read_encoded_value(reader, &encoded_value);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Use `encoded_value` for further processing+ *   cardano_buffer_unref(&encoded_value); // Clean up after use+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_encoded_value(cardano_cbor_reader_t* reader, cardano_buffer_t** encoded_value);++/**+ * \brief Reads the next data item as the start of an array (major type 4).+ *+ * This function attempts to read the next data item from the reader as the start of a CBOR array.+ * It decodes the length of the array and provides this information through the size parameter.+ * If the array is of indefinite length, the function returns a negative size value.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the start of the array is to be read.+ * \param[out] size A pointer to an int64_t variable where the size of the array will be stored.+ * If the array is of definite length, size will be set to the number of elements in the array.+ * If the array is of indefinite length, size will be set to a negative value.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * int64_t array_size = 0;+ * cardano_error_t error = cardano_cbor_reader_read_start_array(reader, &array_size);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   if (arraySize >= 0)+ *   {+ *     printf("Definite-length array with %lld elements.\n", array_size);+ *   }+ *   else+ *   {+ *     printf("Indefinite-length array.\n");+ *   }+ *   // Proceed with reading array items+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ *+ * \note The caller should check if the array is of indefinite length by examining+ * if the size is negative, and should handle array items accordingly.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_start_array(cardano_cbor_reader_t* reader, int64_t* size);++/**+ * \brief Reads the end of an array (major type 4).+ *+ * This function is used to read the end marker of an array in CBOR format. For arrays of definite length,+ * this function confirms the end of the array has been reached according to the previously read length.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the end of the array is to be read.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming the start of an array has been read, and items processed+ * cardano_error_t error = cardano_cbor_reader_read_end_array(reader);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   printf("End of array reached.\n");+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ *+ * \note This function should be called after reading all elements of an array to ensure that+ * the array is correctly terminated, especially in the case of indefinite length arrays.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_end_array(cardano_cbor_reader_t* reader);++/**+ * \brief Reads the next data item as a signed integer (major types 0,1).+ *+ * This function decodes and reads the next CBOR data item from the stream as a signed integer.+ * It handles both positive and negative integers according to CBOR's major types 0 and 1 encoding rules.+ * The decoded integer is stored in the provided `value` parameter.+ * Values outside the int64_t range return \ref CARDANO_ERROR_INTEGER_OVERFLOW.+ * On overflow, the output value and reader position remain unchanged.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the signed integer+ * is to be read.+ * \param[out] value Pointer to an `int64_t` variable where the decoded integer value will be stored.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * int64_t value;+ * cardano_error_t error = cardano_cbor_reader_read_int(reader, &value);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   printf("Decoded integer: %lld\n", (long long)value);+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_int(cardano_cbor_reader_t* reader, int64_t* value);++/**+ * \brief Reads the next data item as an unsigned integer (major type 0).+ *+ * This function decodes and reads the next CBOR data item from the stream as an unsigned integer,+ * following the CBOR major type 0 encoding rules. The decoded unsigned integer is stored in the+ * provided `value` parameter.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the unsigned integer+ * is to be read.+ * \param[out] value Pointer to a `uint64_t` variable where the decoded unsigned integer value will+ * be stored.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * uint64_t value;+ *+ * cardano_error_t error = cardano_cbor_reader_read_uint(reader, &value);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   printf("Decoded unsigned integer: %llu\n", (unsigned long long)value);+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_uint(cardano_cbor_reader_t* reader, uint64_t* value);++/**+ * \brief Reads the next data item as a negative integer (major type 1) and returns its raw argument.+ *+ * A CBOR negative integer carries an unsigned argument \c n and represents the value \c -1 - n.+ * This function returns \c n unchanged, so every negative integer the encoding allows, down to+ * \c -2^64, can be read without overflowing a signed 64-bit integer.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the negative integer+ * is to be read.+ * \param[out] argument Pointer to a `uint64_t` variable where the argument \c n will be stored.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure, such as \ref CARDANO_ERROR_DECODING when+ * the next data item is not a negative integer.+ *+ * Usage Example:+ * \code{.c}+ * uint64_t argument = 0;+ *+ * cardano_error_t error = cardano_cbor_reader_read_negative_int(reader, &argument);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   printf("Decoded negative integer: -1 - %llu\n", (unsigned long long)argument);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_negative_int(cardano_cbor_reader_t* reader, uint64_t* argument);++/**+ * \brief Decodes and reads a big integer (bignum) from CBOR format.+ *+ * This function reads and decodes a bignum from a provided CBOR reader, following the+ * encoding format specified in RFC 7049, section 2.4.2. Bignums are used to represent+ * integers that are too large to be represented directly in the available integer types+ * of CBOR. The function interprets the appropriate tag and decodes the integer value: tag 2+ * (unsigned bignum) yields the byte string magnitude \c n, and tag 3 (negative bignum) yields+ * \c -1 - n, as defined in RFC 8949, section 3.4.3.+ *+ * \param[in] reader The \ref cardano_cbor_reader_t instance from which the bignum will be read.+ * \param[out] bigint A pointer to a pointer that will be set to the address of the newly created \ref cardano_bigint_t object+ *                    representing the decoded big integer value. The caller is responsible for managing the memory of this object.+ *+ * \return Returns \ref CARDANO_SUCCESS if the bignum value was successfully decoded and read from the+ *         CBOR stream. If the operation encounters an error, such as invalid parameters or issues with+ *         reading from the stream, an appropriate error code is returned indicating the reason for the failure.+ *         Consult the \ref cardano_error_t documentation for details on possible error codes and their meanings.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, cbor_data_size);+ * if (reader)+ * {+ *   cardano_bigint_t* bigint = NULL;+ *   cardano_error_t result = cardano_cbor_reader_read_bigint(reader, &bigint);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Successfully read bignum from the reader+ *     // Use the bigint+ *   }+ *+ *   // Clean up+ *   cardano_bigint_unref(&bigint);+ *   cardano_cbor_reader_unref(&reader);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_bigint(cardano_cbor_reader_t* reader, cardano_bigint_t** bigint);++/**+ * \brief Reads the next data item as a double-precision floating point number (major type 7).+ *+ * This function decodes and reads the next CBOR data item from the stream as a double-precision floating point number.+ * It handles the floating-point numbers according to CBOR's major type 7 encoding rules.+ * The decoded double is stored in the provided `value` parameter.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the double-precision+ * floating point number is to be read.+ * \param[out] value Pointer to a `double` variable where the decoded floating point value will be stored.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * double value;+ *+ * cardano_error_t error = cardano_cbor_reader_read_double(reader, &value);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   printf("Decoded double: %f\n", value);+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_double(cardano_cbor_reader_t* reader, double* value);++/**+ * \brief Reads the next data item as a CBOR simple value (major type 7).+ *+ * This function decodes and reads the next CBOR data item from the stream as a CBOR simple value,+ * according to CBOR's major type 7 encoding rules for simple values (e.g., true, false, null, undefined).+ * The decoded simple value is stored in the provided `value` parameter.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the simple value is to be read.+ * \param[out] value Pointer to a `cardano_cbor_simple_value_t` variable where the decoded simple value will be stored.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_simple_value_t value;+ *+ * cardano_error_t error = cardano_cbor_reader_read_simple_value(reader, &value);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Process the decoded simple value+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_simple_value(cardano_cbor_reader_t* reader, cardano_cbor_simple_value_t* value);++/**+ * \brief Reads the next data item as the start of a map (major type 5).+ *+ * This function decodes and reads the next CBOR data item from the stream as the start of a map,+ * following CBOR's major type 5 encoding rules for maps. Maps are collections of key-value pairs.+ * The number of key-value pairs is stored in the provided `size` parameter. A `size` of -1 indicates+ * an indefinite-length map, while a non-negative value indicates a definite-length map with that many+ * key-value pairs.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the start of the map is to be read.+ * \param[out] size Pointer to an `int64_t` variable where the size of the map (number of key-value pairs)+ *                  will be stored. A value of -1 indicates an indefinite-length map.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on success,+ * or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * \remark Map contents are consumed as if they were arrays twice the length of the map's declared size.+ * For example, a map of size 1 containing a key of type int with a value of type string+ * must be consumed by successive calls to readInt32 and readTextString.+ *+ * Usage Example:+ * \code{.c}+ * int64_t map_size;+ *+ * cardano_error_t error = cardano_cbor_reader_read_start_map(reader, &map_size);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Process the start of the map, prepare to read key-value pairs+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_start_map(cardano_cbor_reader_t* reader, int64_t* size);++/**+ * \brief Reads the end of a map (major type 5).+ *+ * This function is used to signify the end of reading a map encoded in CBOR format. It is applicable for+ * maps that were started with \ref cardano_cbor_reader_read_start_map, especially for indefinite-length maps+ * where an explicit end marker is needed. For definite-length maps, this function can be used as a validation+ * step to ensure that the expected number of key-value pairs has been read.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the end of the map is to be read.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on successful+ * reading of the map's end marker, or an appropriate error code indicating the reason for failure. Refer+ * to \ref cardano_error_t documentation for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * // After reading all key-value pairs of the map+ * cardano_error_t error = cardano_cbor_reader_read_end_map(reader);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Successfully read the end of the map+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_end_map(cardano_cbor_reader_t* reader);++/**+ * \brief Reads the next data item as a boolean value (major type 7).+ *+ * This function reads and decodes the next data item from the CBOR stream as a boolean value.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the boolean value is to be read.+ * \param[out] value Pointer to a boolean variable where the decoded value will be stored. The+ * value is set to `true` if the CBOR data item represents true, and `false` if it represents false.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS on successful+ * reading and decoding of the boolean value, or an appropriate error code indicating the reason for failure.+ * Refer to \ref cardano_error_t documentation for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * bool value;+ * cardano_error_t error = cardano_cbor_reader_read_bool(reader, &value);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Successfully read the boolean value+ *   if (value)+ *   {+ *     printf("The boolean value is true.\n");+ *   }+ *   else+ *   {+ *     printf("The boolean value is false.\n");+ *   }+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_bool(cardano_cbor_reader_t* reader, bool* value);++/**+ * \brief Reads the next data item as a null value (major type 7).+ *+ * This function is used to read a null value from the CBOR stream, indicating the absence of a value.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the null value is to be read.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS if the next+ * data item in the stream is correctly identified as a null value, or an appropriate error code indicating+ * the reason for failure. Refer to \ref cardano_error_t documentation for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * cardano_error_t error = cardano_cbor_reader_read_null(reader);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Successfully read a null value+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ *+ * \note This function advances the reader to the next item in the CBOR stream after successfully reading+ * a null value. If the current data item is not a null value, an error will be returned.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_null(cardano_cbor_reader_t* reader);++/**+ * \brief Reads the next data item as a byte string (major type 2).+ *+ * This function reads a byte string from the CBOR stream. This function is capable of handling both+ * definite-length byte strings and indefinite-length byte strings. In the case of indefinite-length+ * strings, the function concatenates all segments into a single contiguous byte string.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the byte string is to be read.+ * \param[out] byte_string A pointer to a pointer to a \ref cardano_buffer_t structure where the decoded byte+ *                         string will be stored. The caller is responsible for freeing this buffer using+ *                         \ref cardano_buffer_unref when it is no longer needed.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS if the byte string+ * is successfully read from the CBOR stream, or an appropriate error code indicating the reason for failure.+ * Refer to \ref cardano_error_t documentation for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * cardano_buffer_t* byte_string = NULL;+ *+ * cardano_error_t error = cardano_cbor_reader_read_bytestring(reader, &byte_string);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Successfully read a byte string, byte_string contains the data+ *   // Process byte_string as needed+ *   cardano_buffer_unref(&byte_string); // Clean up when done+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ *+ * \note This function allocates a new \ref cardano_buffer_t to hold the byte string's data. It is the caller's+ * responsibility to release this memory by calling \ref cardano_buffer_unref on the buffer pointer.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_bytestring(cardano_cbor_reader_t* reader, cardano_buffer_t** byte_string);++/**+ * \brief Reads the next data item as a text string (major type 3) from the CBOR stream.+ *+ * This function parses the next CBOR data item, expecting it to be a text string (major type 3),+ * and returns its value as a newly created `cardano_buffer_t` instance containing the text string+ * encoded as UTF-8. The function supports both definite-length strings and indefinite-length strings,+ * seamlessly handling the concatenation of string fragments in the case of the latter.+ *+ * \param[in] reader A pointer to the `cardano_cbor_reader_t` instance responsible for reading the CBOR data.+ * \param[out] text_string A pointer to a pointer of `cardano_buffer_t` where the text string will be stored.+ *                On successful execution, this points to a newly allocated buffer containing the text string.+ *                The caller assumes ownership of this buffer and is responsible for deallocating it using the+ *                appropriate function (e.g., `cardano_buffer_unref`) when it is no longer needed.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS if the text string+ * is successfully read from the CBOR stream, or an appropriate error code indicating the reason for failure.+ * Refer to \ref cardano_error_t documentation for details on possible error codes.+ *+ * Usage example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_buffer_t* text_string = NULL;+ *+ * if (cardano_cbor_reader_read_textstring(reader, &text_string) == CARDANO_SUCCESS)+ * {+ *   // Use the text_string for your application logic+ *+ *   // Cleanup+ *   cardano_buffer_unref(&text_string);+ * }+ * else+ * {+ *   printf("Failed to read text string from CBOR data.\n");+ * }+ *+ * cardano_cbor_reader_unref(&reader);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_textstring(cardano_cbor_reader_t* reader, cardano_buffer_t** text_string);++/**+ * \brief Reads the next data item as a semantic tag (major type 6), advancing the reader.+ *+ * Tag values greater than INT32_MAX return \ref CARDANO_ERROR_INTEGER_OVERFLOW without+ * changing the output or consuming input. Use \ref cardano_cbor_reader_skip_value or+ * \ref cardano_cbor_reader_read_encoded_value to handle arbitrary unsigned 64-bit tags.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the tag is to be read.+ * \param[out] tag A pointer to a \ref cardano_cbor_tag_t variable where the decoded tag value will be stored.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS if the tag is+ * successfully read from the CBOR stream, or an appropriate error code indicating the reason for failure.+ * Refer to \ref cardano_error_t documentation for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_tag_t tag;+ *+ * cardano_error_t error = cardano_cbor_reader_read_tag(reader, &tag);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Successfully read a semantic tag, tag contains the value+ *   // Process the tag as needed+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_read_tag(cardano_cbor_reader_t* reader, cardano_cbor_tag_t* tag);++/**+ * \brief Peeks at the next semantic tag (major type 6) in the CBOR stream without consuming it.+ *+ * Tag values greater than INT32_MAX return \ref CARDANO_ERROR_INTEGER_OVERFLOW without+ * changing the output or consuming input. Use \ref cardano_cbor_reader_skip_value or+ * \ref cardano_cbor_reader_read_encoded_value to handle arbitrary unsigned 64-bit tags.+ *+ * This function peeks at the semantic tag ahead in the CBOR data stream. Semantic tags provide additional context+ * to the subsequent data item, according to the CBOR specification (major type 6). This peek operation allows+ * the application to inspect the tag without advancing the reader's position, enabling decisions based on the tag+ * value before fully processing the associated data item.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance from which the tag is to be peeked.+ * \param[out] tag A pointer to a \ref cardano_cbor_tag_t variable where the tag value will be stored if a tag is present.+ *+ * \return A \ref cardano_error_t indicating the result of the operation: \ref CARDANO_SUCCESS if a tag is successfully+ * peeked at, or an appropriate error code indicating the reason for failure. Refer to \ref cardano_error_t+ * documentation for details on possible error codes.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_tag_t tag;+ *+ * cardano_error_t error = cardano_cbor_reader_peek_tag(reader, &tag);+ *+ * if (error == CARDANO_SUCCESS)+ * {+ *   // Successfully peeked at the next semantic tag, tag contains the value+ *   // Decision making based on the peeked tag+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ *+ * \note This function does not modify the reader's current position, allowing subsequent operations to+ * process or skip the tag as needed.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_reader_peek_tag(cardano_cbor_reader_t* reader, cardano_cbor_tag_t* tag);++/**+ * \brief Sets the last error message for a given CBOR reader object.+ *+ * Records an error message in the CBOR reader's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance whose last error message is+ *                   to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the reader's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_cbor_reader_set_last_error(cardano_cbor_reader_t* reader, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific reader.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_cbor_reader_set_last_error for the given+ * reader. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] reader A pointer to the \ref cardano_cbor_reader_t instance whose last error+ *                   message is to be retrieved. If the reader is NULL, the function+ *                   returns a generic error message indicating the null reader.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified reader. If the reader is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_cbor_reader_set_last_error for the same reader, or until+ *       the reader is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_cbor_reader_get_last_error(const cardano_cbor_reader_t* reader);++/**+ * \brief Deep copies the reader buffer, position, and nested parsing state.+ * \param[in] reader Reader to copy. Must not be NULL.+ * \param[out] clone Receives one owned reference, or NULL on failure. Must not be NULL.+ * \return CARDANO_SUCCESS, CARDANO_ERROR_POINTER_IS_NULL, or CARDANO_ERROR_MEMORY_ALLOCATION_FAILED.+ * \note Release the result with cardano_cbor_reader_unref. Advancing either reader does not advance the other.+ */+CARDANO_EXPORT cardano_error_t+cardano_cbor_reader_deep_clone(const cardano_cbor_reader_t* reader, cardano_cbor_reader_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CBOR_READER_H
+ vendor/include/cardano/cbor/cbor_reader_state.h view
@@ -0,0 +1,169 @@+/**+ * \file cbor_reader_state.h+ *+ * \author angel.castillo+ * \date   Sep 12, 2023+ *+ * Copyright 2023 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CBOR_READER_STATE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CBOR_READER_STATE_H++/* INCLUDES ******************************************************************/++#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Specifies the state of a CborReader instance.+ *+ * This enumeration outlines the possible states of a CborReader as it processes+ * CBOR data items.+ */+typedef enum+{+  /**+   * \brief Indicates the undefined state.+   *+   * This state is used when the CborReader has not yet begun processing+   * or the state is otherwise unknown.+   */+  CARDANO_CBOR_READER_STATE_UNDEFINED = 0,++  /**+   * \brief Indicates that the next CBOR data item is an unsigned integer (major type 0).+   */+  CARDANO_CBOR_READER_STATE_UNSIGNED_INTEGER,++  /**+   * \brief Indicates that the next CBOR data item is a negative integer (major type 1).+   */+  CARDANO_CBOR_READER_STATE_NEGATIVE_INTEGER,++  /**+   * \brief Indicates that the next CBOR data item is a byte string (major type 2).+   */+  CARDANO_CBOR_READER_STATE_BYTESTRING,++  /**+   * \brief Indicates the start of an indefinite-length byte string (major type 2).+   */+  CARDANO_CBOR_READER_STATE_START_INDEFINITE_LENGTH_BYTESTRING,++  /**+   * \brief Indicates the end of an indefinite-length byte string (major type 2).+   */+  CARDANO_CBOR_READER_STATE_END_INDEFINITE_LENGTH_BYTESTRING,++  /**+   * \brief Indicates that the next CBOR data item is a UTF-8 string (major type 3).+   */+  CARDANO_CBOR_READER_STATE_TEXTSTRING,++  /**+   * \brief Indicates the start of an indefinite-length UTF-8 text string (major type 3).+   */+  CARDANO_CBOR_READER_STATE_START_INDEFINITE_LENGTH_TEXTSTRING,++  /**+   * \brief Indicates the end of an indefinite-length UTF-8 text string (major type 3).+   */+  CARDANO_CBOR_READER_STATE_END_INDEFINITE_LENGTH_TEXTSTRING,++  /**+   * \brief Indicates the start of an array (major type 4).+   */+  CARDANO_CBOR_READER_STATE_START_ARRAY,++  /**+   * \brief Indicates the end of an array (major type 4).+   */+  CARDANO_CBOR_READER_STATE_END_ARRAY,++  /**+   * \brief Indicates the start of a map (major type 5).+   */+  CARDANO_CBOR_READER_STATE_START_MAP,++  /**+   * \brief Indicates the end of a map (major type 5).+   */+  CARDANO_CBOR_READER_STATE_END_MAP,++  /**+   * \brief Indicates that the next CBOR data item is a semantic reader_state (major type 6).+   */+  CARDANO_CBOR_READER_STATE_TAG,++  /**+   * \brief Indicates that the next CBOR data item is a simple value (major type 7).+   */+  CARDANO_CBOR_READER_STATE_SIMPLE_VALUE,++  /**+   * \brief Indicates an IEEE 754 Half-Precision float (major type 7).+   */+  CARDANO_CBOR_READER_STATE_HALF_PRECISION_FLOAT,++  /**+   * \brief Indicates an IEEE 754 Single-Precision float (major type 7).+   */+  CARDANO_CBOR_READER_STATE_SINGLE_PRECISION_FLOAT,++  /**+   * \brief Indicates an IEEE 754 Double-Precision float (major type 7).+   */+  CARDANO_CBOR_READER_STATE_DOUBLE_PRECISION_FLOAT,++  /**+   * \brief Indicates a null literal (major type 7).+   */+  CARDANO_CBOR_READER_STATE_NULL,++  /**+   * \brief Indicates a bool value (major type 7).+   */+  CARDANO_CBOR_READER_STATE_BOOLEAN,++  /**+   * \brief Indicates the completion of reading a full CBOR document.+   *+   * This state is reached when the CborReader has successfully processed+   * an entire CBOR document and there are no more data items to read.+   */+  CARDANO_CBOR_READER_STATE_FINISHED+} cardano_cbor_reader_state_t;++/**+ * \brief Converts CBOR reader states to their human readable form if possible.+ *+ * \param[in] reader_state The reader state to get the string representation for.+ * \return Human readable form of the given reader state. If the reader state is unknown,+ * returns "Reader State: Unknown".+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_cbor_reader_state_to_string(cardano_cbor_reader_state_t reader_state);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CBOR_READER_STATE_H
+ vendor/include/cardano/cbor/cbor_simple_value.h view
@@ -0,0 +1,89 @@+/**+ * \file cbor_simple_value.h+ *+ * \author angel.castillo+ * \date   Sep 12, 2023+ *+ * Copyright 2023 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CBOR_SIMPLE_VALUE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CBOR_SIMPLE_VALUE_H++/* INCLUDES ******************************************************************/++#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a CBOR simple value (major type 7).+ *+ * These simple values are part of the CBOR data format as defined in RFC 7049, section 2.3,+ * representing commonly used simple data items. This enumeration includes the simple values+ * for 'false', 'true', 'null', and 'undefined', each of which has a specific role in the CBOR encoding+ * and interpretation process.+ */+typedef enum+{+  /**+   * \brief Represents the value 'false'.+   *+   * This value is used to represent the boolean false in CBOR-encoded data.+   */+  CARDANO_CBOR_SIMPLE_VALUE_FALSE = 20,++  /**+   * \brief Represents the value 'true'.+   *+   * This value is used to represent the boolean true in CBOR-encoded data.+   */+  CARDANO_CBOR_SIMPLE_VALUE_TRUE = 21,++  /**+   * \brief Represents the value 'null'.+   *+   * This value signifies a null reference or the absence of data in CBOR-encoded data.+   */+  CARDANO_CBOR_SIMPLE_VALUE_NULL = 22,++  /**+   * \brief Represents an undefined value.+   *+   * This value is used by an encoder as a substitute for a data item with an encoding problem,+   * indicating the absence of meaningful or correct data.+   */+  CARDANO_CBOR_SIMPLE_VALUE_UNDEFINED = 23+} cardano_cbor_simple_value_t;++/**+ * \brief Converts CBOR simple value to their human readable form.+ *+ * \param[in] simple_value The simple value to get the string representation for.+ * \return Human readable form of the given simple value. If the simple value is unknown,+ * returns "Simple Value: Unknown".+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_cbor_simple_value_to_string(cardano_cbor_simple_value_t simple_value);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CBOR_SIMPLE_VALUE_H
+ vendor/include/cardano/cbor/cbor_tag.h view
@@ -0,0 +1,131 @@+/**+ * \file cbor_tag.h+ *+ * \author angel.castillo+ * \date   Sep 12, 2023+ *+ * Copyright 2023 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CBOR_TAG_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CBOR_TAG_H++/* INCLUDES ******************************************************************/++#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a CBOR semantic tag (major type 6).+ *+ * Semantic tags in CBOR (Concise Binary Object Representation) provide additional context+ * to the data items that follow them, as defined in the CBOR standard (RFC 7049). These tags+ * indicate how the subsequent data should be interpreted, ranging from date/time formats+ * to various encoding schemes and specialized data types.+ */+typedef enum+{+  /**+   * \brief Tag value for RFC3339 date/time strings.+   *+   * Indicates that the following string data item is formatted according+   * to the RFC3339 specification for date and time.+   */+  CARDANO_CBOR_TAG_DATE_TIME_STRING = 0,++  /**+   * \brief Tag value for Epoch-based date/time in seconds.+   *+   * Denotes that the following integer data item represents a date and time as+   * the number of seconds elapsed since the Unix epoch (1970-01-01T00:00Z).+   */+  CARDANO_CBOR_TAG_UNIX_TIME_SECONDS = 1,++  /**+   * \brief Tag value for unsigned bignum encodings.+   *+   * Used to encode arbitrarily large unsigned integers that cannot fit within+   * the standard integer data item types.+   */+  CARDANO_CBOR_TAG_UNSIGNED_BIG_NUM = 2,++  /**+   * \brief Tag value for negative bignum encodings.+   *+   * Represents arbitrarily large negative integers, complementing the unsigned+   * bignum encoding for handling integers beyond the built-in integer types.+   */+  CARDANO_CBOR_TAG_NEGATIVE_BIG_NUM = 3,++  /**+   * \brief Tag value for decimal fraction encodings.+   *+   * Allows for the precise representation of decimal numbers using a base-10+   * exponent notation. Followed by an array of two integers: the exponent and+   * the significand.+   */+  CARDANO_CBOR_TAG_DECIMAL_FRACTION = 4,++  /**+   * \brief Tag value for big float encodings.+   *+   * Encodes floating-point numbers with arbitrary precision. Followed by an+   * array of two integers representing the base-2 exponent and significand.+   */+  CARDANO_CBOR_TAG_BIG_FLOAT = 5,++  /**+   * \brief Tag value for byte strings containing embedded CBOR data item encodings.+   */+  CARDANO_ENCODED_CBOR_DATA_ITEM = 24,++  /**+   * \brief Tag value for Rational numbers, as defined in http://peteroupc.github.io/CBOR/rational.html.+   */+  CARDANO_ENCODED_CBOR_RATIONAL_NUMBER = 30,++  /**+   * \brief Tag value for `set<a> = #6.258([* a]) / [* a]`, `nonempty_set<a> = #6.258([+ a]) / [+ a]`, `nonempty_oset<a> = #6.258([+ a]) / [+ a]`+   */+  CARDANO_CBOR_TAG_SET = 258,++  /**+   * \brief Tag value for the Self-Describe CBOR header (0xd9d9f7).+   *+   * When placed at the beginning of a CBOR document, this tag signals that the+   * document is encoded in CBOR, facilitating content type detection.+   */+  CARDANO_CBOR_TAG_SELF_DESCRIBE_CBOR = 55799+} cardano_cbor_tag_t;++/**+ * \brief Converts CBOR tags to their human readable form if possible.+ *+ * \param[in] tag The tag to get the string representation for.+ * \return Human readable form of the given tag. If the tag is unknown, returns "Tag: Custom".+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_cbor_tag_to_string(cardano_cbor_tag_t tag);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CBOR_TAG_H
+ vendor/include/cardano/cbor/cbor_writer.h view
@@ -0,0 +1,1044 @@+/**+ * \file cbor_writer.h+ *+ * \author angel.castillo+ * \date   Sep 12, 2023+ *+ * Copyright 2023 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CBOR_WRITER_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CBOR_WRITER_H++/* INCLUDES ******************************************************************/++#include <cardano/buffer.h>+#include <cardano/cbor/cbor_tag.h>+#include <cardano/common/bigint.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief A simple writer for Concise Binary Object Representation (CBOR) encoded data.+ *+ * This structure represents a writer that facilitates encoding data into the CBOR format.+ * It abstracts the complexities involved in CBOR encoding, providing a simple interface+ * for creating CBOR data streams. The writer maintains internal state to track the encoding+ * process, ensuring efficient and accurate representation of various data types as per+ * CBOR standards (RFC 7049).+ */+typedef struct cardano_cbor_writer_t cardano_cbor_writer_t;++/**+ * \brief Creates and initializes a new instance of a CBOR writer.+ *+ * This function allocates and returns a new instance of \ref cardano_cbor_writer_t,+ * setting up its internal state for encoding CBOR data.+ *+ * \return A pointer to the newly created \ref cardano_cbor_writer_t object. This object+ * represents a "strong reference" to the CBOR writer, meaning that it is fully initialized+ * and ready for use. The caller is responsible for managing the lifecycle of this object.+ * Specifically, once the CBOR writer is no longer needed, the caller must release it by+ * calling \ref cardano_cbor_writer_unref.+ *+ * Usage Example:+ * \code{.c}+ * // Create a new CBOR writer+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   // Use the writer for CBOR encoding tasks+ *+ *   // Once done, ensure to clean up and release the writer+ *   cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_cbor_writer_t* cardano_cbor_writer_new(void);++/**+ * \brief Decrements the reference count of a CBOR writer object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_cbor_writer_t object+ * by decreasing its reference count. When the reference count reaches zero, the CBOR writer is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] cbor_writer A pointer to the pointer of the CBOR writer object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * // Perform operations with the writer...+ *+ * cardano_cbor_writer_unref(&writer);+ * // At this point, writer is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_cbor_writer_unref, the pointer to the \ref cardano_cbor_writer_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_cbor_writer_unref(cardano_cbor_writer_t** cbor_writer);++/**+ * \brief Increases the reference count of the cardano_cbor_writer_t object.+ *+ * This function is used to manually increment the reference count of a CBOR writer+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_cbor_writer_unref.+ *+ * \param cbor_writer A pointer to the CBOR writer object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming writer is a previously created CBOR writer object+ *+ * cardano_cbor_writer_ref(writer);+ *+ * // Now writer can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_cbor_writer_ref there is a corresponding+ * call to \ref cardano_cbor_writer_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_cbor_writer_ref(cardano_cbor_writer_t* cbor_writer);++/**+ * \brief Retrieves the current reference count of the cardano_cbor_writer_t object.+ *+ * This function returns the number of active references to a CBOR writer object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_cbor_writer_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param cbor_writer A pointer to the CBOR writer object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified CBOR writer object. If the object+ * is properly managed (i.e., every \ref cardano_cbor_writer_ref call is matched with a+ * \ref cardano_cbor_writer_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming writer is a previously created CBOR writer object+ *+ * size_t ref_count = cardano_cbor_writer_refcount(writer);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_cbor_writer_refcount(const cardano_cbor_writer_t* cbor_writer);++/**+ * \brief Encodes and writes a big integer (bignum) in CBOR format.+ *+ * This function writes a provided big integer value as a bignum, following the+ * encoding format specified in RFC 7049, section 2.4.2. Bignums are used to represent+ * integers that are too large to be represented directly in the available integer types+ * of CBOR. The function applies the appropriate tag before encoding the integer value: a value+ * \c v >= 0 is written as tag 2 (unsigned bignum) with magnitude \c v, and a value \c v < 0 is+ * written as tag 3 (negative bignum) with magnitude \c -1 - v, as defined in RFC 8949, section 3.4.3.+ *+ * \param[in] writer The \ref cardano_cbor_writer_t instance to which the bignum will be written.+ * \param[in] bigint The \ref cardano_bigint_t object representing the big integer value to be encoded as a bignum.+ *+ * \return Returns \ref CARDANO_SUCCESS if the bignum value was successfully encoded and written to the+ *         CBOR stream. If the operation encounters an error, such as invalid parameters or issues with+ *         writing to the stream, an appropriate error code is returned indicating the reason for the failure.+ *         Consult the \ref cardano_error_t documentation for details on possible error codes and their meanings.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   // Example large value to encode as bignum+ *   cardano_bigint_t* bigint = NULL;+ *   cardano_bigint_from_string("123456789123456789123456789", strln("123456789123456789123456789"), 10, &bigint);+ *+ *   cardano_error_t result = cardano_cbor_writer_write_bigint(writer, bigint);+ *+ *   ...+ *+ *   cardano_bigint_unref(&bigint);+ *   cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_bigint(cardano_cbor_writer_t* writer, const cardano_bigint_t* bigint);++/**+ * \brief Encodes and writes a boolean value in CBOR format as per RFC 7049, section 2.3.+ *+ * This function is responsible for encoding a boolean value (`true` or `false`) and writing it+ * to the CBOR stream managed by the specified \ref cardano_cbor_writer_t instance. Boolean values+ * are encoded in CBOR as major type 7, with specific additional information values to denote+ * `true` (21) or `false` (20).+ *+ * \param[in] writer The \ref cardano_cbor_writer_t instance to which the boolean value will be written.+ * \param[in] value The boolean value to write. A value of \c true will be encoded as a CBOR `true` value,+ *                  and \c false as a CBOR `false` value.+ *+ * \return Returns \ref CARDANO_SUCCESS if the boolean value was successfully encoded and written to the+ *         CBOR stream. If the operation encounters an error, such as invalid parameters or issues with+ *         writing to the stream, an appropriate error code is returned indicating the reason for the failure.+ *         Consult the \ref cardano_error_t documentation for details on possible error codes and their meanings.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_cbor_writer_write_bool(writer, true);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *   // The boolean value 'true' was successfully written as CBOR to the writer+ *   }+ *   else+ *   {+ *   // Handle error+ *   }+ *+     cardano_cbor_writer_unref(&writer);+ * }+ *+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_bool(cardano_cbor_writer_t* writer, bool value);++/**+ * \brief Encodes and writes a byte buffer as a CBOR byte string (major type 2).+ *+ * This function takes a byte buffer and writes it to the specified CBOR writer as a byte string,+ * following the CBOR encoding rules for byte strings (major type 2). This is used to serialize+ * raw binary data in CBOR format.+ *+ * \param[in] writer The \ref cardano_cbor_writer_t instance to which the byte string will be written.+ * \param[in] data A pointer to the byte buffer containing the data to be written as a CBOR byte string.+ *                 The data in this buffer will be copied exactly as it is into the CBOR stream, encoded+ *                 as a byte string.+ * \param[in] size The number of bytes in the \c data buffer that will be written as part of the CBOR+ *                 byte string. This value determines the length of the resulting byte string in the+ *                 CBOR stream.+ *+ * \return Returns \ref CARDANO_SUCCESS if the byte buffer was successfully serialized and written to the+ *         CBOR stream as a byte string. If the function fails to perform the serialization or write operation,+ *         it returns an error code that specifies the nature of the failure. For detailed information on+ *         error codes and their meanings, refer to the \ref cardano_error_t documentation.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ * byte_t data[] = {0xde, 0xad, 0xbe, 0xef}; // Example binary data+ * size_t data_size = sizeof(data);+ *+ * cardano_error_t result = cardano_cbor_writer_write_bytestring(writer, data, data_size);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The binary data was successfully written as a CBOR byte string+ * }+ * else+ * {+ *   // Handle error+ * }+ *+ * cardano_cbor_writer_unref(&writer);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_bytestring(cardano_cbor_writer_t* writer, const byte_t* data, size_t size);++/**+ * \brief Encodes and writes a UTF-8 encoded text string as a CBOR text string (major type 3).+ *+ * This function serializes a given text string, provided as a UTF-8 encoded `char` array, and writes it+ * into the specified CBOR stream. Text strings are encoded in CBOR as major type 3, following the format+ * outlined in the CBOR specification (RFC 7049).+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t structure that represents the CBOR stream+ *                   where the text string will be written.+ * \param[in] data A pointer to the `char` array containing the UTF-8 encoded text string to be serialized+ *                 and written to the CBOR stream.+ * \param[in] size The length of the text string in bytes (characters), excluding any null terminator.+ *                 This specifies the exact number of bytes to be written from the \c data array to the+ *                 CBOR stream as the text string content.+ *+ * \return Returns \ref CARDANO_SUCCESS if the text string was successfully encoded and written to the+ *         CBOR stream. If the function encounters an error, such as an issue with the parameters provided+ *         or a problem with the CBOR stream, an appropriate error code is returned, indicating the reason+ *         for the failure. Refer to the \ref cardano_error_t documentation for an exhaustive list of error+ *         codes and their respective meanings.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   const char* text = "Hello, CBOR!";+ *   size_t text_length = strlen(text);+ *   cardano_error_t result = cardano_cbor_writer_write_textstring(writer, text, text_length);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Text string successfully written to CBOR stream+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_textstring(cardano_cbor_writer_t* writer, const char* data, size_t size);++/**+ * \brief Writes a buffer containing a pre-encoded CBOR data item into a CBOR stream.+ *+ * This function facilitates the insertion of a CBOR data item that has already been encoded+ * into a CBOR stream. It is particularly useful in scenarios where the data item to be added+ * to the stream exists in its final encoded form and needs to be included without alteration.+ * The function ensures that the pre-encoded data is integrated into the stream seamlessly,+ * maintaining the integrity and structure of the CBOR encoding.+ *+ * \param writer A pointer to the \ref cardano_cbor_writer_t structure representing the CBOR stream+ *               to which the pre-encoded data item is to be added.+ *+ * \param data A pointer to the byte buffer that contains the pre-encoded CBOR data item. This+ *             buffer should contain the data item in a format that complies with CBOR encoding+ *             specifications. The function does not modify the content of this buffer; it simply+ *             adds it to the CBOR stream as-is.+ *+ * \param size The size, in bytes, of the pre-encoded data buffer. This value specifies the number+ *             of bytes to be written from the \c data buffer to the CBOR stream. It is the caller's+ *             responsibility to ensure that this size accurately reflects the length of the pre-encoded+ *             data item and that the data itself adheres to the correct CBOR encoding standards.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. If the pre-encoded data+ *         item is successfully added to the CBOR stream, the function returns \ref CARDANO_SUCCESS. If+ *         an error occurs during the operation, the function returns an error code identifying the+ *         specific failure reason. Consult the documentation for \ref cardano_error_t for a detailed+ *         list of potential error codes and their respective meanings.+ *+ * Example usage:+ * \code{.c}+ * // Assume writer is a previously initialized CBOR writer object+ * byte_t pre_encoded_data[] = { ... }; // Pre-encoded CBOR data+ * size_t data_size = sizeof(pre_encoded_data);+ *+ * cardano_error_t result = cardano_cbor_writer_write_encoded(writer, pre_encoded_data, data_size);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Pre-encoded data was successfully added to the CBOR stream+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_encoded(cardano_cbor_writer_t* writer, const byte_t* data, size_t size);++/**+ * \brief Initiates the writing of an array in the CBOR stream, supporting both definite and indefinite lengths.+ *+ * This function marks the start of an array within the CBOR data stream being constructed. CBOR arrays can be of+ * definite length, where the total number of elements is known ahead of time, or of indefinite length, where the+ * total number of elements is not predetermined. This function allows the caller to specify which type of array+ * is being started by setting the \c size parameter accordingly.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t instance that is being used to construct the CBOR stream.+ * \param[in] size   The total number of elements expected in the array for definite-length arrays, or -1 for starting an+ *                   indefinite-length array. In the case of an indefinite-length array, the writing process is open-ended+ *                   until the \ref cardano_cbor_writer_write_end_array function is called to signal the end of the array.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the array+ *         start marker is successfully written to the stream. If an error occurs (e.g., due to an invalid \c writer pointer,+ *         or if \c writer is not in a ready state), an error code corresponding to the specific failure reason is returned.+ *         Consult the \ref cardano_error_t enumeration for a detailed list of error codes.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   // Start a definite-length array with 3 elements+ *   cardano_error_t result = cardano_cbor_writer_write_start_array(writer, 3);+ *+ *   if (result != CARDANO_SUCCESS)+ *   {+ *       // Handle error+ *   }+ *+ *   // Alternatively, start an indefinite-length array+ *   result = cardano_cbor_writer_write_start_array(writer, -1);+ *+ *   if (result != CARDANO_SUCCESS)+ *   {+ *     // Handle error+ *   }+ *+ *   // Proceed with writing array elements...+ *   cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ *+ * \note For indefinite-length arrays, you must call \ref cardano_cbor_writer_write_end_array after writing all+ *       array elements to properly close the array in the CBOR stream.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_start_array(cardano_cbor_writer_t* writer, int64_t size);++/**+ * \brief Concludes the encoding of an indefinite-length array in the CBOR stream.+ *+ * This function marks the end of an indefinite-length array that was initiated with+ * \ref cardano_cbor_writer_write_start_array using a length parameter of 0. It writes an+ * end-of-array marker to the CBOR stream, signaling the closure of the array structure.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t instance representing the CBOR stream+ *                   to which the end-of-array marker is to be added. It is imperative that this function+ *                   is called only after a corresponding call to \ref cardano_cbor_writer_write_start_array+ *                   with a length of 0.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. On successful addition+ *         of the end-of-array marker, \ref CARDANO_SUCCESS is returned. If the operation encounters an+ *         error, an error code specifying the nature of the issue is returned. Refer to the \ref cardano_error_t+ *         enumeration for an exhaustive list of error codes and their corresponding meanings.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_cbor_writer_write_start_array(writer, 0); // Start indefinite-length array+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Write array elements...+ *     result = cardano_cbor_writer_write_end_array(writer); // End the indefinite-length array+ *+ *     if (result != CARDANO_SUCCESS)+ *     {+ *       // Handle error+ *     }+ *   }+ *+ *     cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ *+ * \note The function is specifically designed for arrays of indefinite length. Attempting to use this+ *       function without a preceding call to \ref cardano_cbor_writer_write_start_array with a length+ *       parameter of 0 may result in incorrect CBOR stream formation and should be avoided.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_end_array(cardano_cbor_writer_t* writer);++/**+ * \brief Starts the writing of a map (key-value pairs) in the CBOR stream.+ *+ * This function is used to begin the encoding of a CBOR map, which consists of key-value pairs. It supports+ * the creation of both definite-length maps, where the number of key-value pairs is known upfront, and+ * indefinite-length maps, where the number of pairs is determined as the map is being written. The+ * definite-length map is initiated by specifying the exact number of pairs, while the indefinite-length+ * map is started by passing -1 as the length parameter.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t structure that represents the CBOR stream+ *                   where the map will be encoded.+ * \param[in] size   The number of key-value pairs for a definite-length map, or -1 to indicate the start+ *                   of an indefinite-length map. For indefinite-length maps, the end must be explicitly+ *                   marked using \ref cardano_cbor_writer_write_end_map to complete the map encoding.+ *+ * \return A \ref cardano_error_t indicating the result of the operation. Returns \ref CARDANO_SUCCESS if the+ *         map's initiation is successfully written to the stream. If the operation encounters an error, an+ *         error code is returned specifying the failure reason. Refer to the \ref cardano_error_t enumeration+ *         for details on the possible error codes and their meanings.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   // Start a definite-length map with 2 key-value pairs+ *   cardano_error_t result = cardano_cbor_writer_write_start_map(writer, 2);+ *+ *   if (result != CARDANO_SUCCESS)+ *   {+ *     // Handle error+ *   }+ *+ *   // Alternatively, start an indefinite-length map+ *   result = cardano_cbor_writer_write_start_map(writer, -1);+ *   if (result != CARDANO_SUCCESS)+ *   {+ *     // Handle error+ *   }+ *+ *   // Proceed with writing key-value pairs...+ *   cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ *+ * \note For indefinite-length maps, you must call \ref cardano_cbor_writer_write_end_map after adding+ *       all key-value pairs to correctly close the map structure in the CBOR stream.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_start_map(cardano_cbor_writer_t* writer, int64_t size);++/**+ * \brief Concludes the writing of an indefinite-length map (major type 5) in CBOR format.+ *+ * This function is used to signify the end of an indefinite-length map in a CBOR stream. It is specifically+ * applicable when a map was started with cardano_cbor_writer_write_start_map() with a length parameter of 0,+ * indicating an indefinite-length map. Definite-length maps, where the total number of key-value pairs is known+ * and specified at the start, do not require this function to mark their end, as their boundaries are implicitly+ * defined by the length parameter.+ *+ * It is important to ensure that all key-value pairs intended for the map have been written before calling this+ * function, as it marks the map's closure in the CBOR encoding. After calling this function, new data items written+ * to the stream will not be considered part of the map.+ *+ * \param writer A pointer to the \ref cardano_cbor_writer_t structure representing the CBOR stream+ *               where the end-of-map marker will be written. The writer must have been previously+ *               initialized and must be in a valid state for writing.+ *+ * \return A \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         upon successfully marking the end of the map in the CBOR stream. If the operation fails, an+ *         appropriate error code is returned indicating the reason for failure. Refer to the+ *         \ref cardano_error_t documentation for details on possible error codes.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_end_map(cardano_cbor_writer_t* writer);++/**+ * \brief Encodes an unsigned integer as a CBOR data item and writes it to the CBOR stream.+ *+ * This function is designed to encode an unsigned integer value, following CBOR's major type 0+ * specification, and then write this encoded value to the specified CBOR stream. It automatically+ * optimizes the encoding based on the integer's value to ensure efficient representation within the+ * CBOR format. This function supports encoding of the full range of unsigned 64-bit integers, from 0+ * up to and including 2^64-1.+ *+ * \param[in] writer A pointer to a \ref cardano_cbor_writer_t instance representing the CBOR stream to+ *                   which the encoded unsigned integer will be written.+ * \param[in] value The unsigned 64-bit integer value to be encoded and written to the CBOR stream. This+ *                  value is encoded according to the CBOR major type 0 rules.+ *+ * \return Returns \ref CARDANO_SUCCESS if the unsigned integer is successfully encoded and written to+ *         the stream. If an error occurs during the process, a specific error code from the \ref cardano_error_t+ *         enumeration is returned to indicate the failure reason.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   uint64_t value = 12345; // Example unsigned integer+ *   cardano_error_t result = cardano_cbor_writer_write_uint(writer, value);+ *+ *   if (result != CARDANO_SUCCESS)+ *   {+ *     // Handle error+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_uint(cardano_cbor_writer_t* writer, uint64_t value);++/**+ * \brief Encodes and writes a negative integer (major type 1) from its raw argument.+ *+ * A CBOR negative integer carries an unsigned argument \c n and represents the value \c -1 - n.+ * This function writes \c n unchanged, so every negative integer the encoding allows, down to+ * \c -2^64, can be written, including those that do not fit in a signed 64-bit integer.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t instance tasked with constructing the CBOR stream.+ * \param[in] argument The argument \c n of the negative integer \c -1 - n to be written.+ *+ * \return Returns \ref CARDANO_SUCCESS upon successful encoding and writing of the negative integer to the+ *         CBOR stream. In the event of an error, a specific error code from the \ref cardano_error_t enumeration+ *         is returned to detail the cause of the problem.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_cbor_writer_write_negative_int(writer, UINT64_MAX);+ *+ *   if (result != CARDANO_SUCCESS)+ *   {+ *     printf("Error: %s\n", cardano_error_to_string(result));+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_negative_int(cardano_cbor_writer_t* writer, uint64_t argument);++/**+ * \brief Encodes and writes a signed integer value to the CBOR stream, using CBOR major types 0 or 1.+ *+ * This function takes a signed integer value as input and encodes it into the CBOR format, automatically+ * choosing between major type 0 for positive integers (including zero) and major type 1 for negative integers.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t instance tasked with constructing the CBOR stream.+ * \param[in] value The signed 64-bit integer to be encoded and written to the stream. The function handles both+ *                  positive and negative integers, automatically applying the correct CBOR major type based on+ *                  the value's sign.+ *+ * \return Returns \ref CARDANO_SUCCESS upon successful encoding and writing of the signed integer value to the+ *         CBOR stream. In the event of an error, a specific error code from the \ref cardano_error_t enumeration+ *         is returned to detail the cause of the problem.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   int64_t value = -42; // Example negative integer+ *   cardano_error_t result = cardano_cbor_writer_write_signed_int(writer, value);+ *+ *   if (result != CARDANO_SUCCESS)+ *   {+ *     // Handle error+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_signed_int(cardano_cbor_writer_t* writer, int64_t value);++/**+ * \brief Encodes a null value and writes it to the CBOR stream.+ *+ * This function is responsible for encoding a null value as per the CBOR specification+ * (major type 7, additional information 22) and writing it to the specified CBOR stream.+ * Null values are used to represent the absence of any meaningful value in CBOR data.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t structure representing the CBOR stream+ *                   where the null value will be written.+ *+ * \return Returns \ref CARDANO_SUCCESS if the null value is successfully encoded and written to+ *         the stream. If an error occurs, an error code from the \ref cardano_error_t enumeration+ *         is returned, indicating the failure reason.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_cbor_writer_write_null(writer);+ *+ *   if (result != CARDANO_SUCCESS)+ *   {+ *     // Handle error+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ * \endcode+ *+ * \note+ *   It is crucial that the writer is correctly initialized and in a state that permits+ *   the addition of new encoded data to ensure the successful writing of the null value.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_null(cardano_cbor_writer_t* writer);++/**+ * \brief Writes an undefined value to the CBOR stream (major type 7).+ *+ * In CBOR encoding, the "undefined" value is used to represent data that is explicitly unspecified.+ *+ * \param writer A pointer to the \ref cardano_cbor_writer_t structure representing the CBOR stream+ *               to which the undefined value will be written. The writer should have been previously+ *               initialized and must be in a valid state for writing. Using this function correctly+ *               maintains the integrity of the CBOR stream by ensuring the undefined value is+ *               properly encoded according to CBOR standards.+ *+ * \return A \ref cardano_error_t indicating the outcome of the operation. If the undefined value is+ *         successfully encoded into the CBOR stream, \ref CARDANO_SUCCESS is returned. Should there be+ *         a failure in writing the value, an appropriate error code is returned, providing insight+ *         into the failure reason. Refer to the \ref cardano_error_t documentation for an exhaustive+ *         list of potential error codes and their meanings.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_undefined(cardano_cbor_writer_t* writer);++/**+ * \brief Assigns a semantic tag to the next data item in the CBOR stream.+ *+ * This function is used to give additional meaning or context to the succeeding data item by assigning a semantic tag to it,+ * according to the CBOR specification. It's useful for indicating the type or purpose of the data that follows the tag,+ * such as date-time strings, big numbers, or other specific data types.+ *+ * \param[in] writer The CBOR writer instance to which the tag will be written.+ *+ * \param[in] tag The semantic tag to assign to the next data item. It's an integer that represents the specific meaning+ * or data type according to the predefined set of CBOR tags or potentially application-defined tags.+ *+ * \return A \ref cardano_error_t indicating the result of the operation. Returns \ref CARDANO_SUCCESS if the tag is successfully+ * written to the CBOR stream. If the operation fails, an appropriate error code is returned to indicate the failure reason.+ * See the documentation for \ref cardano_error_t for a list of error codes.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_write_tag(cardano_cbor_writer_t* writer, cardano_cbor_tag_t tag);++/**+ * \brief Calculates the required buffer size for the encoded data.+ *+ * This function determines the size of the buffer needed to store the  data encoded by the writer.+ * It is intended to be used before calling `cardano_cbor_writer_encode` to allocate a buffer of appropriate size.+ *+ * \param[in] writer The source writer whose encoded data size is being calculated.+ *+ * \return The size of the buffer required to store the writer's encoded data. Returns 0 if the writer is NULL+ * or contains no data.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * // Assume writer has been used to encode some CBOR data here+ *+ * size_t required_size = cardano_cbor_writer_get_encode_size(writer);+ *+ * // Now required_size can be used to allocate a buffer of appropriate size+ * byte_t* data = (byte_t*)malloc(required_size);+ *+ * if (byte_t != NULL)+ * {+ *   if (cardano_cbor_writer_encode(writer, data, required_size) == CARDANO_SUCCESS)+ *   {+ *     // Operate on the encoded data+ *   }+ *+ *   free(data); // Free the allocated string after use+ * }+ *+ * cardano_cbor_writer_unref(&writer); // Properly dispose of the writer after use+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_cbor_writer_get_encode_size(cardano_cbor_writer_t* writer);++/**+ * \brief Encodes data from the writer's context into CBOR format and outputs it to a provided buffer.+ *+ * This function encodes data prepared in the writer's internal context into CBOR format and writes it into an output+ * buffer specified by the caller.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t structure representing the context and state for the CBOR encoding+ *                   operation.+ * \param[in] data A pointer to a byte array where the encoded data will be written. The function will fill this buffer with+ *                 the CBOR-encoded data.+ * \param[in] size The size of the data byte array, indicating how much space is available for writing the encoded data.+ *+ * \return A cardano_error_t indicating the outcome of the operation. Returns CARDANO_SUCCESS if the data is successfully+ *         encoded into CBOR format and stored in the provided buffer. If the operation fails, an error code is returned indicating+ *         the specific reason for failure. Detailed information on possible error codes and their meanings can be found in the+ *         cardano_error_t documentation.+ *+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * byte_t buffer[256]; // Pre-allocated buffer with sufficient space for the encoded data+ *+ * cardano_error_t result = cardano_cbor_writer_encode(writer, buffer, sizeof(buffer));+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Encoded CBOR data successfully. Bytes written: %zu\n", sizeof(buffer));+ * }+ * else+ * {+ *   printf("Failed to encode CBOR data. Error code: %d\n", result);+ * }+ *+ * cardano_cbor_writer_unref(&writer); // Properly dispose of the writer after use+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_encode(cardano_cbor_writer_t* writer, byte_t* data, size_t size);++/**+ * \brief Encodes data from the writer's context into CBOR format and outputs it into a new buffer.+ *+ * This function encodes data prepared in the writer's internal context into CBOR format and writes it into a+ * buffer. The function will create a new buffer instance to store the encoded data.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t structure representing the context and state for the CBOR encoding+ *                   operation.+ * \param[out] buffer A pointer to a \ref cardano_buffer_t object where the encoded data will be stored. The function will allocate+ *                    and fill this buffer with the CBOR-encoded data. It is best to initialize this pointer as NULL. The caller is+ *                    responsible for managing the lifecycle of the buffer, specifically releasing it by calling \ref cardano_buffer_unref+ *                    when it is no longer needed.+ *+ * \return A cardano_error_t indicating the outcome of the operation. Returns CARDANO_SUCCESS if the data is successfully+ *         encoded into CBOR format and stored in the provided buffer. If the operation fails, an error code is returned indicating+ *         the specific reason for failure. Detailed information on possible error codes and their meanings can be found in the+ *         cardano_error_t documentation.+ *+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ * cardano_buffer_t* buffer = NULL; // Buffer will be allocated by the function+ *+ * cardano_error_t result = cardano_cbor_writer_encode_in_buffer(writer, &buffer);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Encoded CBOR data successfully. Bytes written: %zu\n", cardano_buffer_get_size(buffer));+ * }+ * else+ * {+ *   printf("Failed to encode CBOR data. Error code: %d\n", result);+ * }+ *+ * cardano_buffer_unref(&buffer); // Properly dispose of the buffer after use+ * cardano_cbor_writer_unref(&writer); // Properly dispose of the writer after use+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_encode_in_buffer(cardano_cbor_writer_t* writer, cardano_buffer_t** buffer);++/**+ * \brief Calculates the required buffer size for the hex string representation of the encoded data.+ *+ * This function determines the size of the buffer needed to store the hexadecimal string representation+ * of the data encoded by the writer. This size includes space for the null terminator. It is intended to+ * be used before calling `cardano_cbor_writer_encode_hex` to allocate a buffer of appropriate size.+ *+ * \param[in] writer The source writer whose encoded data's hex string size is being calculated.+ *+ * \return The size of the buffer required to store the hex string representation of the writer's+ * encoded data, including the null terminator. Returns 0 if the writer is NULL or contains no data.+ *+ * Example usage:+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * // Assume writer has been used to encode some CBOR data here+ *+ * // Calculate the required size for the hex string, including the null terminator+ * size_t required_size = cardano_cbor_writer_get_hex_size(writer);+ *+ * // Now required_size can be used to allocate a buffer of appropriate size+ * char* hex_string = (char*)malloc(required_size);+ *+ * if (hex_string != NULL)+ * {+ *   if (cardano_cbor_writer_encode_hex(writer, hex_string, required_size) == CARDANO_SUCCESS)+ *   {+ *     printf("Encoded CBOR data as hex: %s\n", hex_string);+ *   }+ *+ *   free(hex_string); // Free the allocated string after use+ * }+ *+ * cardano_cbor_writer_unref(&writer); // Properly dispose of the writer after use+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_cbor_writer_get_hex_size(const cardano_cbor_writer_t* writer);++/**+ * \brief Writes the encoded data from the writer into a provided buffer as a hex string.+ *+ * This function converts the encoded data prepared in the writer's internal context into a+ * hexadecimal string representation and writes it into the provided buffer. This approach+ * is useful for debugging, logging, or any scenario where viewing the encoded data as a+ * hex string is beneficial. The function requires the caller to allocate a buffer of+ * appropriate size beforehand, based on the size obtained from \ref cardano_cbor_writer_get_hex_size.+ *+ * \param[in] writer The source writer whose data will be encoded into a hex string.+ * \param[out] dest The destination buffer where the hex string will be written.+ * \param[in] dest_size The size of the destination buffer, including space for the null terminator.+ * The required size can be obtained using \ref cardano_cbor_writer_get_hex_size.+ *+ * \return A `cardano_error_t` indicating the result of the operation: `CARDANO_SUCCESS` on success,+ * or an appropriate error code indicating the failure reason. Refer to \ref cardano_error_t documentation+ * for details on possible error codes.+ *+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * // Assume writer has been used to encode some CBOR data here+ *+ * size_t hex_size = cardano_cbor_writer_get_hex_size(writer);+ * char* hex_string = (char*)malloc(hex_size);+ * cardano_error_t result = cardano_cbor_writer_encode_hex(writer, hex_string, hex_size);+ *+ * if (hex_string != NULL && result == CARDANO_SUCCESS)+ * {+ *   printf("Encoded CBOR data as hex: %s\n", hex_string);+ * }+ * else+ * {+ *   printf("Failed to encode CBOR data as hex or allocate memory.\n");+ * }+ *+ * free(hex_string); // Free the allocated string after use+ *+ * cardano_cbor_writer_unref(&writer); // Properly dispose of the writer after use+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_encode_hex(const cardano_cbor_writer_t* writer, char* dest, size_t dest_size);++/**+ * \brief Resets the writer, clearing all written data.+ *+ * This function resets the internal state of the CBOR writer, effectively removing any data that has been written to it.+ * This is useful for reusing a writer instance without needing to create a new one, especially when working with+ * sequences of data encoding tasks.+ *+ * \param[in] writer The CBOR writer instance to reset.+ *+ * \return A cardano_error_t indicating the outcome of the operation. CARDANO_SUCCESS is returned if the writer is+ *         successfully reset. Returns \ref CARDANO_ERROR_POINTER_IS_NULL if \p writer is NULL. Returns+ *         \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if the new internal buffer could not be allocated; in that case the+ *         writer keeps its previously written data and remains usable.+ *+ * \code{.c}+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * // Write some data to the writer here+ *+ * cardano_error_t reset_result = cardano_cbor_writer_reset(writer);+ *+ * if (reset_result == CARDANO_SUCCESS)+ * {+ *     printf("Writer reset successfully.\n");+ * }+ * else+ * {+ *     printf("Failed to reset writer. Error code: %d\n", reset_result);+ * }+ * // The writer can now be reused for new data without creating a new instance+ *+ * cardano_cbor_writer_unref(&writer); // Clean up when done using the writer+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_cbor_writer_reset(cardano_cbor_writer_t* writer);++/**+ * \brief Sets the last error message for a given CBOR writer object.+ *+ * Records an error message in the CBOR writer's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t instance whose last error message is+ *                   to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the writer's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_cbor_writer_set_last_error(cardano_cbor_writer_t* writer, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific writer.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_cbor_writer_set_last_error for the given+ * writer. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] writer A pointer to the \ref cardano_cbor_writer_t instance whose last error+ *                   message is to be retrieved. If the writer is NULL, the function+ *                   returns a generic error message indicating the null writer.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified writer. If the writer is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_cbor_writer_set_last_error for the same writer, or until+ *       the writer is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_cbor_writer_get_last_error(const cardano_cbor_writer_t* writer);++/**+ * \brief Creates an independent deep copy of a \ref cardano_cbor_writer_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_cbor_writer_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_cbor_writer_deep_clone(const cardano_cbor_writer_t* source, cardano_cbor_writer_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CBOR_WRITER_H
+ vendor/include/cardano/certs/auth_committee_hot_cert.h view
@@ -0,0 +1,503 @@+/**+ * \file auth_committee_hot_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef AUTH_COMMITTEE_HOT_CERT_H+#define AUTH_COMMITTEE_HOT_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Constitutional Committee members maintain operational integrity by managing two credentials: a cold credential and a hot credential.+ *+ * One of the purposes of this credential management system is to provide multiple layers of security to help committee members prevent losing control+ * over a cold credential and to give good options for recovery if necessary.+ *+ * This certificates registers the Hot credentials of a committee member and requires a signature from the CC member Cold key.+ */+typedef struct cardano_auth_committee_hot_cert_t cardano_auth_committee_hot_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates and initializes a new instance of an authorization committee hot certificate.+ *+ * This function allocates and initializes a new instance of \ref cardano_auth_committee_hot_cert_t.+ *+ * \param[in] committee_cold_cred A \ref cardano_credential_t object representing the committee cold credential.+ * \param[in] committee_hot_cred A \ref cardano_credential_t object representing the committee hot credential.+ * \param[out] auth_committee_hot_cert On successful initialization, this will point to a newly created+ *                                             \ref cardano_auth_committee_hot_cert_t object. The caller is responsible+ *                                             for managing the lifecycle of this object. Specifically, once the authorization+ *                                             committee hot certificate is no longer needed, the caller must release it+ *                                             by calling \ref cardano_auth_committee_hot_cert_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the authorization committee hot certificate was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t committee_cold_cred = ...; // Assume committee_cold_cred is initialized+ * cardano_credential_t committee_hot_cred = ...; // Assume committee_hot_cred is initialized+ * cardano_auth_committee_hot_cert_t* auth_committee_hot_cert = NULL;+ *+ * // Attempt to create a new authorization committee hot certificate+ * cardano_error_t result = cardano_auth_committee_hot_cert_new(committee_cold_cred, committee_hot_cred, &auth_committee_hot_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the auth_committee_hot_cert+ *+ *   // Once done, ensure to clean up and release the auth_committee_hot_cert+ *   cardano_auth_committee_hot_cert_unref(&auth_committee_hot_cert);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auth_committee_hot_cert_new(+  cardano_credential_t*               committee_cold_cred,+  cardano_credential_t*               committee_hot_cred,+  cardano_auth_committee_hot_cert_t** auth_committee_hot_cert);++/**+ * \brief Creates a \ref cardano_auth_committee_hot_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_auth_committee_hot_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a auth_committee_hot.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] auth_committee_hot A pointer to a pointer of \ref cardano_auth_committee_hot_cert_t that will be set to the address+ *                        of the newly created auth_committee_hot object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_auth_committee_hot_cert_t object by calling+ *       \ref cardano_auth_committee_hot_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_auth_committee_hot_cert_t* auth_committee_hot = NULL;+ *+ * cardano_error_t result = cardano_auth_committee_hot_cert_from_cbor(reader, &auth_committee_hot);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the auth_committee_hot+ *+ *   // Once done, ensure to clean up and release the auth_committee_hot+ *   cardano_auth_committee_hot_cert_unref(&auth_committee_hot);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode auth_committee_hot: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auth_committee_hot_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_auth_committee_hot_cert_t** auth_committee_hot);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_auth_committee_hot_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] auth_committee_hot A constant pointer to the \ref cardano_auth_committee_hot_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p auth_committee_hot or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auth_committee_hot_cert_t* auth_committee_hot = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_auth_committee_hot_cert_to_cbor(auth_committee_hot, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_auth_committee_hot_cert_unref(&auth_committee_hot);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_auth_committee_hot_cert_to_cbor(+  const cardano_auth_committee_hot_cert_t* auth_committee_hot,+  cardano_cbor_writer_t*                   writer);++/**+ * \brief Serializes an auth-committee-hot certificate to CIP-116 JSON.+ *+ * Keys are written in deterministic order: "tag", "committee_cold_credential", "committee_hot_credential".+ * The function writes the full JSON object, including surrounding braces.+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_auth_committee_hot_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ *         CARDANO_ERROR_POINTER_IS_NULL  If \p cert or \p writer is NULL.+ *         CARDANO_ERROR_ENCODING         If required fields are missing/invalid.+ *         Other                          Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_auth_committee_hot_cert_to_cip116_json(+  const cardano_auth_committee_hot_cert_t* cert,+  cardano_json_writer_t*                   writer);++/**+ * \brief Sets the cold credential for an authorization committee hot certificate.+ *+ * This function assigns a new cold credential to a given \ref cardano_auth_committee_hot_cert_t object.+ *+ * \param[in] auth_committee_hot A pointer to an initialized \ref cardano_auth_committee_hot_cert_t object to which the cold credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the new cold credential.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the cold credential was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auth_committee_hot_cert_t* auth_committee_hot = ...; // Assume auth_committee_hot is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_auth_committee_hot_cert_set_cold_cred(auth_committee_hot, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The cold credential is now set for the auth_committee_hot+ * }+ * else+ * {+ *   printf("Failed to set the cold credential.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_auth_committee_hot_cert_set_cold_cred(+  cardano_auth_committee_hot_cert_t* auth_committee_hot,+  cardano_credential_t*              credential);++/**+ * \brief Retrieves the cold credential from an authorization committee hot certificate.+ *+ * This function retrieves the cold credential from a given \ref cardano_auth_committee_hot_cert_t object.+ *+ * \param[in] auth_committee_hot A pointer to an initialized \ref cardano_auth_committee_hot_cert_t object.+ * \param[out] credential On successful retrieval, this will point to the cold credential of the auth_committee_hot.+ *                        The caller is responsible for managing the lifecycle of this object and must call the appropriate+ *                        unref function to release it when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the cold credential was successfully retrieved, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * \note This function returns a new reference to the cold credential. Both the source auth_committee_hot object+ *       and the retrieved credential must be unreferenced appropriately.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auth_committee_hot_cert_t* auth_committee_hot = ...; // Assume auth_committee_hot is already initialized+ * cardano_credential_t* credential = NULL;+ *+ * cardano_error_t result = cardano_auth_committee_hot_cert_get_cold_cred(auth_committee_hot, &credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the credential+ *   // Once done, ensure to clean up and release the credential+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   printf("Failed to retrieve the cold credential.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_auth_committee_hot_cert_get_cold_cred(+  cardano_auth_committee_hot_cert_t* auth_committee_hot,+  cardano_credential_t**             credential);++/**+ * \brief Sets the hot credential for an authorization committee hot certificate.+ *+ * This function assigns a new hot credential to a given \ref cardano_auth_committee_hot_cert_t object.+ *+ * \param[in] auth_committee_hot A pointer to an initialized \ref cardano_auth_committee_hot_cert_t object.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the hot credential.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the hot credential was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auth_committee_hot_cert_t* auth_committee_hot = ...; // Assume auth_committee_hot is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_auth_committee_hot_cert_set_hot_cred(auth_committee_hot, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The hot credential is now set for the auth_committee_hot+ * }+ * else+ * {+ *   printf("Failed to set the hot credential.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_auth_committee_hot_cert_set_hot_cred(+  cardano_auth_committee_hot_cert_t* auth_committee_hot,+  cardano_credential_t*              credential);++/**+ * \brief Retrieves the hot credential from an authorization committee hot certificate.+ *+ * This function retrieves the hot credential from a given \ref cardano_auth_committee_hot_cert_t object.+ *+ * \param[in] auth_committee_hot A pointer to an initialized \ref cardano_auth_committee_hot_cert_t object.+ * \param[out] credential On successful retrieval, this will point to the hot credential of the auth_committee_hot object.+ *                        The function returns a new reference to the credential, and the caller is responsible for managing+ *                        its lifecycle, including calling \ref cardano_credential_unref when the credential is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the hot credential was successfully retrieved, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * \note This function returns a new reference to the hot credential. Both the caller and the auth_committee_hot object+ *       must unreference the credential appropriately to avoid memory leaks.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auth_committee_hot_cert_t* auth_committee_hot = ...; // Assume auth_committee_hot is already initialized+ * cardano_credential_t* credential = NULL;+ *+ * cardano_error_t result = cardano_auth_committee_hot_cert_get_hot_cred(auth_committee_hot, &credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the hot credential+ *+ *   // Once done, ensure to clean up and release the credential+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   printf("Failed to retrieve the hot credential.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_auth_committee_hot_cert_get_hot_cred(+  cardano_auth_committee_hot_cert_t* auth_committee_hot,+  cardano_credential_t**             credential);++/**+ * \brief Decrements the reference count of a cardano_auth_committee_hot_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_auth_committee_hot_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the auth_committee_hot is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] auth_committee_hot A pointer to the pointer of the auth_committee_hot object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_auth_committee_hot_cert_t* auth_committee_hot = cardano_auth_committee_hot_cert_new(major, minor);+ *+ * // Perform operations with the auth_committee_hot...+ *+ * cardano_auth_committee_hot_cert_unref(&auth_committee_hot);+ * // At this point, auth_committee_hot is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_auth_committee_hot_cert_unref, the pointer to the \ref cardano_auth_committee_hot_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_auth_committee_hot_cert_unref(cardano_auth_committee_hot_cert_t** auth_committee_hot);++/**+ * \brief Increases the reference count of the cardano_auth_committee_hot_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_auth_committee_hot_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_auth_committee_hot_cert_unref.+ *+ * \param auth_committee_hot A pointer to the cardano_auth_committee_hot_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming auth_committee_hot is a previously created auth_committee_hot object+ *+ * cardano_auth_committee_hot_cert_ref(auth_committee_hot);+ *+ * // Now auth_committee_hot can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_auth_committee_hot_cert_ref there is a corresponding+ * call to \ref cardano_auth_committee_hot_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_auth_committee_hot_cert_ref(cardano_auth_committee_hot_cert_t* auth_committee_hot);++/**+ * \brief Retrieves the current reference count of the cardano_auth_committee_hot_cert_t object.+ *+ * This function returns the number of active references to an cardano_auth_committee_hot_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_auth_committee_hot_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param auth_committee_hot A pointer to the cardano_auth_committee_hot_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_auth_committee_hot_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_auth_committee_hot_cert_ref call is matched with a+ * \ref cardano_auth_committee_hot_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming auth_committee_hot is a previously created auth_committee_hot object+ *+ * size_t ref_count = cardano_auth_committee_hot_cert_refcount(auth_committee_hot);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_auth_committee_hot_cert_refcount(const cardano_auth_committee_hot_cert_t* auth_committee_hot);++/**+ * \brief Sets the last error message for a given cardano_auth_committee_hot_cert_t object.+ *+ * Records an error message in the auth_committee_hot's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] auth_committee_hot A pointer to the \ref cardano_auth_committee_hot_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the auth_committee_hot's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_auth_committee_hot_cert_set_last_error(+  cardano_auth_committee_hot_cert_t* auth_committee_hot,+  const char*                        message);++/**+ * \brief Retrieves the last error message recorded for a specific auth_committee_hot.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_auth_committee_hot_cert_set_last_error for the given+ * auth_committee_hot. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] auth_committee_hot A pointer to the \ref cardano_auth_committee_hot_cert_t instance whose last error+ *                   message is to be retrieved. If the auth_committee_hot is NULL, the function+ *                   returns a generic error message indicating the null auth_committee_hot.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified auth_committee_hot. If the auth_committee_hot is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_auth_committee_hot_cert_set_last_error for the same auth_committee_hot, or until+ *       the auth_committee_hot is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_auth_committee_hot_cert_get_last_error(+  const cardano_auth_committee_hot_cert_t* auth_committee_hot);++/**+ * \brief Creates an independent deep copy of a \ref cardano_auth_committee_hot_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_auth_committee_hot_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_auth_committee_hot_cert_deep_clone(const cardano_auth_committee_hot_cert_t* source, cardano_auth_committee_hot_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // AUTH_COMMITTEE_HOT_CERT_H
+ vendor/include/cardano/certs/cert_type.h view
@@ -0,0 +1,182 @@+/**+ * \file cert_type.h+ *+ * \author angel.castillo+ * \date   Jun 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CERT_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CERT_TYPE_H++/* INCLUDES ******************************************************************/++#include <cardano/export.h>++/* DECLARATIONS *************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Certificates are used to register, update, or deregister stake pools, and delegate stake.+ */+typedef enum+{+  /**+   * \brief This certificate is used when an individual wants to register as a stakeholder.+   * It allows the holder to participate in the staking process by delegating their+   * stake or creating a stake pool.+   */+  CARDANO_CERT_TYPE_STAKE_REGISTRATION = 0,++  /**+   * \brief This certificate is used when a stakeholder no longer wants to participate in+   * staking. It revokes the stake registration and the associated stake is no+   * longer counted when calculating stake pool rewards.+   */+  CARDANO_CERT_TYPE_STAKE_DEREGISTRATION = 1,++  /**+   * \brief This certificate is used when a stakeholder wants to delegate their stake to a+   * specific stake pool. It includes the stake pool id to which the stake is delegated.+   */+  CARDANO_CERT_TYPE_STAKE_DELEGATION = 2,++  /**+   * \brief This certificate is used to register a new stake pool. It includes various details+   * about the pool such as the pledge, costs, margin, reward account, and the pool's owners and relays.+   */+  CARDANO_CERT_TYPE_POOL_REGISTRATION = 3,++  /**+   * \brief This certificate is used to retire a stake pool. It includes an epoch number indicating when the pool will be retired.+   */+  CARDANO_CERT_TYPE_POOL_RETIREMENT = 4,++  /**+   * \brief This certificate is used to delegate from a Genesis key to a set of keys. This was primarily used in the early+   * phases of the Cardano network's existence during the transition from the Byron to the Shelley era.+   */+  CARDANO_CERT_TYPE_GENESIS_KEY_DELEGATION = 5,++  /**+   * \brief Certificate used to facilitate an instantaneous transfer of rewards within the system.+   */+  CARDANO_CERT_TYPE_MOVE_INSTANTANEOUS_REWARDS = 6,++  /**+   * \brief This certificate is used when an individual wants to register as a stakeholder.+   * It allows the holder to participate in the staking process by delegating their+   * stake or creating a stake pool.+   *+   * Deposit must match the expected deposit amount specified by `ppKeyDepositL` in+   * the protocol parameters.+   *+   * Remark: Replaces the deprecated `StakeRegistration` in after Conway era.+   */+  CARDANO_CERT_TYPE_REGISTRATION = 7,++  /**+   * \brief This certificate is used when a stakeholder no longer wants to participate in+   * staking. It revokes the stake registration and the associated stake is no+   * longer counted when calculating stake pool rewards.+   *+   * Deposit must match the expected deposit amount specified by `ppKeyDepositL` in+   * the protocol parameters.+   *+   * Remark: Replaces the deprecated `StakeDeregistration` in after Conway era.+   */+  CARDANO_CERT_TYPE_UNREGISTRATION = 8,++  /**+   * \brief This certificate is used when an individual wants to delegate their voting rights to any other DRep.+   */+  CARDANO_CERT_TYPE_VOTE_DELEGATION = 9,++  /**+   * \brief This certificate is used when an individual wants to delegate their voting+   * rights to any other DRep and simultaneously wants to delegate their stake to a+   * specific stake pool.+   */+  CARDANO_CERT_TYPE_STAKE_VOTE_DELEGATION = 10,++  /**+   * \brief This certificate Register the stake key and delegate with a single certificate to a stake pool.+   */+  CARDANO_CERT_TYPE_STAKE_REGISTRATION_DELEGATION = 11,++  /**+   * \brief This certificate Register the stake key and delegate with a single certificate to a DRep.+   */+  CARDANO_CERT_TYPE_VOTE_REGISTRATION_DELEGATION = 12,++  /**+   * \brief This certificate is used when an individual wants to register its stake key,+   * delegate their voting rights to any other DRep and simultaneously wants to delegate+   * their stake to a specific stake pool.+   */+  CARDANO_CERT_TYPE_STAKE_VOTE_REGISTRATION_DELEGATION = 13,++  /**+   * \brief This certificate registers the Hot and Cold credentials of a committee member.+   */+  CARDANO_CERT_TYPE_AUTH_COMMITTEE_HOT = 14,++  /**+   * \brief This certificate is used then a committee member wants to resign early (will be marked on-chain as an expired member).+   */+  CARDANO_CERT_TYPE_RESIGN_COMMITTEE_COLD = 15,++  /**+   * \brief In Voltaire, existing stake credentials will be able to delegate their stake to DReps for voting+   * purposes, in addition to the current delegation to stake pools for block production.+   * DRep delegation will mimic the existing stake delegation mechanisms (via on-chain certificates).+   *+   * This certificate register a stake key as a DRep.+   */+  CARDANO_CERT_TYPE_DREP_REGISTRATION = 16,++  /**+   * \brief This certificate unregister an individual as a DRep.+   *+   * Note that a DRep is retired immediately upon the chain accepting a retirement certificate, and+   * the deposit is returned as part of the transaction that submits the retirement certificate+   * (the same way that stake credential registration deposits are returned).+   */+  CARDANO_CERT_TYPE_DREP_UNREGISTRATION = 17,++  /**+   * \brief Updates the DRep anchored metadata.+   */+  CARDANO_CERT_TYPE_UPDATE_DREP = 18+} cardano_cert_type_t;++/**+ * \brief Converts certificate types to their human readable form.+ *+ * \param[in] type The certificate type to get the string representation for.+ * \return Human readable form of the given certificate type.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_cert_type_to_string(cardano_cert_type_t type);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CERT_TYPE_H
+ vendor/include/cardano/certs/certificate.h view
@@ -0,0 +1,1959 @@+/**+ * \file certificate.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef CERTIFICATE_H+#define CERTIFICATE_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/certs/cert_type.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief This certificate registers the Hot and Cold credentials of a committee member.+ */+typedef struct cardano_auth_committee_hot_cert_t cardano_auth_committee_hot_cert_t;++/**+ * \brief This certificate is used to delegate from a Genesis key to a set of keys. This was primarily used in the early+ * phases of the Cardano network's existence during the transition from the Byron to the Shelley era.+ */+typedef struct cardano_genesis_key_delegation_cert_t cardano_genesis_key_delegation_cert_t;++/**+ * \brief Certificate used to facilitate an instantaneous transfer of rewards within the system.+ */+typedef struct cardano_mir_cert_t cardano_mir_cert_t;++/**+ * \brief This certificate is used to register a new stake pool. It includes various details+ * about the pool such as the pledge, costs, margin, reward account, and the pool's owners and relays.+ */+typedef struct cardano_pool_registration_cert_t cardano_pool_registration_cert_t;++/**+ * \brief This certificate is used to retire a stake pool. It includes an epoch number indicating when the pool will be retired.+ */+typedef struct cardano_pool_retirement_cert_t cardano_pool_retirement_cert_t;++/**+ * \brief In Voltaire, existing stake credentials will be able to delegate their stake to DReps for voting+ * purposes, in addition to the current delegation to stake pools for block production.+ * DRep delegation will mimic the existing stake delegation mechanisms (via on-chain certificates).+ *+ * This certificate register a stake key as a DRep.+ */+typedef struct cardano_register_drep_cert_t cardano_register_drep_cert_t;++/**+ * \brief This certificate is used when an individual wants to register as a stakeholder.+ * It allows the holder to participate in the staking process by delegating their+ * stake or creating a stake pool.+ */+typedef struct cardano_registration_cert_t cardano_registration_cert_t;++/**+ * \brief This certificate is used then a committee member wants to resign early (will be marked on-chain as an expired member).+ */+typedef struct cardano_resign_committee_cold_cert_t cardano_resign_committee_cold_cert_t;++/**+ * \brief This certificate is used when a stakeholder wants to delegate their stake to a+ * specific stake pool. It includes the stake pool id to which the stake is delegated.+ */+typedef struct cardano_stake_delegation_cert_t cardano_stake_delegation_cert_t;++/**+ * \brief This certificate is used when a stakeholder no longer wants to participate in+ * staking. It revokes the stake registration and the associated stake is no+ * longer counted when calculating stake pool rewards.+ */+typedef struct cardano_stake_deregistration_cert_t cardano_stake_deregistration_cert_t;++/**+ * \brief This certificate is used when an individual wants to register as a stakeholder.+ * It allows the holder to participate in the stake process by delegating their+ * stake or creating a stake pool.+ */+typedef struct cardano_stake_registration_cert_t cardano_stake_registration_cert_t;++/**+ * \brief This certificate Register the stake key and delegate with a single certificate to a stake pool.+ */+typedef struct cardano_stake_registration_delegation_cert_t cardano_stake_registration_delegation_cert_t;++/**+ * \brief This certificate is used when an individual wants to delegate their voting+ * rights to any other DRep and simultaneously wants to delegate their stake to a+ * specific stake pool.+ */+typedef struct cardano_stake_vote_delegation_cert_t cardano_stake_vote_delegation_cert_t;++/**+ * \brief This certificate is used when an individual wants to register its stake key,+ * delegate their voting rights to any other DRep and simultaneously wants to delegate+ * their stake to a specific stake pool.+ */+typedef struct cardano_stake_vote_registration_delegation_cert_t cardano_stake_vote_registration_delegation_cert_t;++/**+ * \brief This certificate unregister an individual as a DRep.+ *+ * Note that a DRep is retired immediately upon the chain accepting a retirement certificate, and+ * the deposit is returned as part of the transaction that submits the retirement certificate+ * (the same way that stake credential registration deposits are returned).+ */+typedef struct cardano_unregister_drep_cert_t cardano_unregister_drep_cert_t;++/**+ * \brief This certificate is used when a stakeholder no longer wants to participate in+ * staking. It revokes the stake Unregistration and the associated stake is no+ * longer counted when calculating stake pool rewards.+ */+typedef struct cardano_unregistration_cert_t cardano_unregistration_cert_t;++/**+ * \brief Updates the DRep anchored metadata.+ */+typedef struct cardano_update_drep_cert_t cardano_update_drep_cert_t;++/**+ * \brief This certificate is used when an individual wants to delegate their voting rights to any other DRep.+ */+typedef struct cardano_vote_delegation_cert_t cardano_vote_delegation_cert_t;++/**+ * \brief This certificate Register the stake key and delegate with a single certificate to a DRep.+ */+typedef struct cardano_vote_registration_delegation_cert_t cardano_vote_registration_delegation_cert_t;++/**+ * \brief Creates a new Cardano certificate based on an authorization committee hot certificate.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_auth_committee_hot_cert_t object.+ *+ * \param[in] auth_committee_hot_cert A pointer to an initialized \ref cardano_auth_committee_hot_cert_t object that defines+ *                                    the committee's hot certificate details.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_auth_committee_hot_cert_t* auth_cert = ...;  // Assume auth_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_auth_committee_hot(auth_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for authorization purposes in committee operations+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create authorization certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_auth_committee_hot_cert_unref(&auth_cert); // Cleanup the auth_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_auth_committee_hot(+  cardano_auth_committee_hot_cert_t* auth_committee_hot_cert,+  cardano_certificate_t**            certificate);++/**+ * \brief Creates a new Cardano certificate for genesis key delegation.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object for the purpose of genesis key delegation,+ * using the provided \ref cardano_genesis_key_delegation_cert_t object which contains the delegation details.+ *+ * \param[in] genesis_key_delegation A pointer to an initialized \ref cardano_genesis_key_delegation_cert_t object that+ *                                   specifies the genesis key delegation parameters.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_genesis_key_delegation_cert_t* genesis_cert = ...;  // Assume genesis_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_genesis_key_delegation(genesis_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for genesis key delegation operations+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create genesis key delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_genesis_key_delegation_cert_unref(&genesis_cert); // Cleanup the genesis_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_genesis_key_delegation(+  cardano_genesis_key_delegation_cert_t* genesis_key_delegation,+  cardano_certificate_t**                certificate);++/**+ * \brief Creates a new Cardano certificate for Move Instantaneous Rewards (MIR).+ *+ * This function allocates and initializes a \ref cardano_certificate_t object for the purpose of managing+ * Move Instantaneous Rewards, using the provided \ref cardano_mir_cert_t object which contains the MIR details.+ *+ * \param[in] mir A pointer to an initialized \ref cardano_mir_cert_t object that specifies the MIR parameters.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_cert_t* mir_cert = ...;  // Assume mir_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_mir(mir_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for MIR operations+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create MIR certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_mir_cert_unref(&mir_cert); // Cleanup the mir_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_mir(+  cardano_mir_cert_t*     mir,+  cardano_certificate_t** certificate);++/**+ * \brief Creates a new Cardano certificate for pool registration.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object specifically for registering+ * a staking pool, using the provided \ref cardano_pool_registration_cert_t object which contains all the necessary+ * parameters for pool registration.+ *+ * \param[in] pool_registration A pointer to an initialized \ref cardano_pool_registration_cert_t object that defines+ *                              the staking pool's registration details.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_registration_cert_t* registration_cert = ...;  // Assume registration_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_pool_registration(registration_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for pool registration purposes+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create pool registration certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_pool_registration_cert_unref(&registration_cert); // Cleanup the registration_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_pool_registration(+  cardano_pool_registration_cert_t* pool_registration,+  cardano_certificate_t**           certificate);++/**+ * \brief Creates a new Cardano certificate for pool retirement.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object specifically for the retirement+ * of a staking pool, using the provided \ref cardano_pool_retirement_cert_t object which contains all the necessary+ * parameters for pool retirement.+ *+ * \param[in] pool_retirement A pointer to an initialized \ref cardano_pool_retirement_cert_t object that defines+ *                            the staking pool's retirement details.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_retirement_cert_t* retirement_cert = ...;  // Assume retirement_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_pool_retirement(retirement_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for pool retirement purposes+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create pool retirement certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_pool_retirement_cert_unref(&retirement_cert); // Cleanup the retirement_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_pool_retirement(+  cardano_pool_retirement_cert_t* pool_retirement,+  cardano_certificate_t**         certificate);++/**+ * \brief Creates a new Cardano certificate for registering a decentralized representation (drep).+ *+ * This function allocates and initializes a \ref cardano_certificate_t object for registering a drep,+ * using the provided \ref cardano_register_drep_cert_t object which contains all necessary details+ * for the registration.+ *+ * \param[in] register_drep A pointer to an initialized \ref cardano_register_drep_cert_t object that defines+ *                          the details of the drep to be registered.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_register_drep_cert_t* drep_cert = ...;  // Assume drep_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_register_drep(drep_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for registering the drep+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create register drep certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_register_drep_cert_unref(&drep_cert); // Cleanup the drep_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_register_drep(+  cardano_register_drep_cert_t* register_drep,+  cardano_certificate_t**       certificate);++/**+ * \brief Creates a new Cardano certificate for registration.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_registration_cert_t object, which contains the registration details.+ *+ * \param[in] registration A pointer to an initialized \ref cardano_registration_cert_t object that specifies+ *                         the registration details.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_registration_cert_t* registration_cert = ...;  // Assume registration_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_registration(registration_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for the intended registration purpose+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create registration certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_registration_cert_unref(&registration_cert); // Cleanup the registration_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_registration(+  cardano_registration_cert_t* registration,+  cardano_certificate_t**      certificate);++/**+ * \brief Creates a new Cardano certificate for resigning a committee's cold key.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_resign_committee_cold_cert_t object, which contains the details for resigning a committee's cold key.+ *+ * \param[in] resign_committee_cold A pointer to an initialized \ref cardano_resign_committee_cold_cert_t object that specifies+ *                                  the details for the resignation of the committee's cold key.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_resign_committee_cold_cert_t* resign_cert = ...;  // Assume resign_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_resign_committee_cold(resign_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for committee cold key resignation+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create resignation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_resign_committee_cold_cert_unref(&resign_cert); // Cleanup the resign_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_resign_committee_cold(+  cardano_resign_committee_cold_cert_t* resign_committee_cold,+  cardano_certificate_t**               certificate);++/**+ * \brief Creates a new Cardano certificate for stake delegation.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_stake_delegation_cert_t object, which contains the details necessary for delegating stake in the Cardano network.+ *+ * \param[in] stake_delegation A pointer to an initialized \ref cardano_stake_delegation_cert_t object that specifies+ *                             the delegation details, including the delegator's stake key and the target stake pool.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_delegation_cert_t* delegation_cert = ...;  // Assume delegation_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_stake_delegation(delegation_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for stake delegation purposes+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create stake delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_stake_delegation_cert_unref(&delegation_cert); // Cleanup the delegation_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_stake_delegation(+  cardano_stake_delegation_cert_t* stake_delegation,+  cardano_certificate_t**          certificate);++/**+ * \brief Creates a new Cardano certificate for stake deregistration.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_stake_deregistration_cert_t object.+ *+ * \param[in] stake_deregistration A pointer to an initialized \ref cardano_stake_deregistration_cert_t object that specifies+ *                                 the stake key to be deregistered.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_deregistration_cert_t* deregistration_cert = ...;  // Assume deregistration_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_stake_deregistration(deregistration_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for stake deregistration purposes+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create stake deregistration certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_stake_deregistration_cert_unref(&deregistration_cert); // Cleanup the deregistration_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_stake_deregistration(+  cardano_stake_deregistration_cert_t* stake_deregistration,+  cardano_certificate_t**              certificate);++/**+ * \brief Creates a new Cardano certificate for stake registration.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_stake_registration_cert_t object.+ *+ * \param[in] stake_registration A pointer to an initialized \ref cardano_stake_registration_cert_t object that specifies+ *                               the stake key to be registered.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_cert_t* registration_cert = ...;  // Assume registration_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_stake_registration(registration_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for stake registration purposes+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create stake registration certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_stake_registration_cert_unref(&registration_cert); // Cleanup the registration_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_stake_registration(+  cardano_stake_registration_cert_t* stake_registration,+  cardano_certificate_t**            certificate);++/**+ * \brief Creates a new Cardano certificate for stake registration with delegation.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_stake_registration_delegation_cert_t object.+ *+ * \param[in] stake_registration_delegation A pointer to an initialized \ref cardano_stake_registration_delegation_cert_t object+ *                                          that specifies the stake key to be registered and the pool to which it will be delegated.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_delegation_cert_t* reg_del_cert = ...;  // Assume reg_del_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_stake_registration_delegation(reg_del_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for stake registration and delegation purposes+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create stake registration and delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_stake_registration_delegation_cert_unref(&reg_del_cert); // Cleanup the reg_del_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_stake_registration_delegation(+  cardano_stake_registration_delegation_cert_t* stake_registration_delegation,+  cardano_certificate_t**                       certificate);++/**+ * \brief Creates a new Cardano certificate for stake vote delegation.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_stake_vote_delegation_cert_t object.+ *+ * \param[in] stake_vote_delegation A pointer to an initialized \ref cardano_stake_vote_delegation_cert_t object+ *                                  that specifies the stake key and the party to whom the voting rights are delegated.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_delegation_cert_t* vote_del_cert = ...;  // Assume vote_del_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_stake_vote_delegation(vote_del_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for delegating voting rights+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create stake vote delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_stake_vote_delegation_cert_unref(&vote_del_cert); // Cleanup the vote_del_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_stake_vote_delegation(+  cardano_stake_vote_delegation_cert_t* stake_vote_delegation,+  cardano_certificate_t**               certificate);++/**+ * \brief Creates a new Cardano certificate for stake vote registration delegation.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \param[in] stake_vote_registration_delegation A pointer to an initialized \ref cardano_stake_vote_registration_delegation_cert_t object+ *                                                that specifies the stake key and the details necessary for registering and delegating+ *                                                the voting rights.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_registration_delegation_cert_t* reg_del_cert = ...;  // Assume reg_del_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_stake_vote_registration_delegation(reg_del_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for registering and delegating voting rights+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create stake vote registration delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_stake_vote_registration_delegation_cert_unref(&reg_del_cert); // Cleanup the reg_del_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_stake_vote_registration_delegation(+  cardano_stake_vote_registration_delegation_cert_t* stake_vote_registration_delegation,+  cardano_certificate_t**                            certificate);++/**+ * \brief Creates a new Cardano certificate for unregistering a DRep.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_unregister_drep_cert_t object.+ *+ * \param[in] unregister_drep A pointer to an initialized \ref cardano_unregister_drep_cert_t object+ *                             that specifies the details necessary for unregistering the DRep.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregister_drep_cert_t* unregister_drep_cert = ...;  // Assume unregister_drep_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_unregister_drep(unregister_drep_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for unregistering the DRep+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create unregister DRep certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_unregister_drep_cert_unref(&unregister_drep_cert); // Cleanup the unregister_drep_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_unregister_drep(+  cardano_unregister_drep_cert_t* unregister_drep,+  cardano_certificate_t**         certificate);++/**+ * \brief Creates a new Cardano certificate for unregistration.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_unregistration_cert_t object.+ *+ * \param[in] unregistration A pointer to an initialized \ref cardano_unregistration_cert_t object+ *                           that specifies the details necessary for the unregistration process.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregistration_cert_t* unregistration_cert = ...;  // Assume unregistration_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_unregistration(unregistration_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for unregistration purposes+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create unregistration certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_unregistration_cert_unref(&unregistration_cert); // Cleanup the unregistration_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_unregistration(+  cardano_unregistration_cert_t* unregistration,+  cardano_certificate_t**        certificate);++/**+ * \brief Creates a new Cardano certificate for updating a delegation representation (Drep).+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_update_drep_cert_t object.+ *+ * \param[in] update_drep A pointer to an initialized \ref cardano_update_drep_cert_t object+ *                        that specifies the details necessary for the update process.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_update_drep_cert_t* update_drep_cert = ...;  // Assume update_drep_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_update_drep(update_drep_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for updating delegation representation+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create update Drep certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_update_drep_cert_unref(&update_drep_cert); // Cleanup the update_drep_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_update_drep(+  cardano_update_drep_cert_t* update_drep,+  cardano_certificate_t**     certificate);++/**+ * \brief Creates a new Cardano certificate for vote delegation.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_vote_delegation_cert_t object.+ *+ * \param[in] vote_delegation A pointer to an initialized \ref cardano_vote_delegation_cert_t object+ *                            that specifies the details necessary for the delegation of voting rights.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_delegation_cert_t* vote_delegation_cert = ...;  // Assume vote_delegation_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_vote_delegation(vote_delegation_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for voting delegation purposes+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create vote delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_vote_delegation_cert_unref(&vote_delegation_cert); // Cleanup the vote_delegation_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_vote_delegation(+  cardano_vote_delegation_cert_t* vote_delegation,+  cardano_certificate_t**         certificate);++/**+ * \brief Creates a new Cardano certificate for vote registration and delegation.+ *+ * This function allocates and initializes a \ref cardano_certificate_t object based on the provided+ * \ref cardano_vote_registration_delegation_cert_t object.+ *+ * \param[in] vote_registration_delegation A pointer to an initialized \ref cardano_vote_registration_delegation_cert_t object+ *                                         that specifies the details necessary for the registration and delegation of voting rights.+ * \param[out] certificate On successful execution, this will point to a newly created \ref cardano_certificate_t object.+ *                         The caller is responsible for releasing this resource using \ref cardano_certificate_unref when it+ *                         is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_registration_delegation_cert_t* vote_reg_del_cert = ...;  // Assume vote_reg_del_cert is already initialized+ * cardano_certificate_t* certificate = NULL;+ * cardano_error_t result = cardano_certificate_new_vote_registration_delegation(vote_reg_del_cert, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used for both registration and delegation of voting rights+ *   // Remember to free the certificate when done+ *   cardano_certificate_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create vote registration and delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_vote_registration_delegation_cert_unref(&vote_reg_del_cert); // Cleanup the vote_reg_del_cert+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_new_vote_registration_delegation(+  cardano_vote_registration_delegation_cert_t* vote_registration_delegation,+  cardano_certificate_t**                      certificate);++/**+ * \brief Creates a \ref cardano_certificate_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_certificate_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a auth_committee_hot.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] auth_committee_hot A pointer to a pointer of \ref cardano_certificate_t that will be set to the address+ *                        of the newly created auth_committee_hot object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_certificate_t object by calling+ *       \ref cardano_certificate_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_certificate_t* auth_committee_hot = NULL;+ *+ * cardano_error_t result = cardano_certificate_from_cbor(reader, &auth_committee_hot);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the auth_committee_hot+ *+ *   // Once done, ensure to clean up and release the auth_committee_hot+ *   cardano_certificate_unref(&auth_committee_hot);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode auth_committee_hot: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_from_cbor(cardano_cbor_reader_t* reader, cardano_certificate_t** auth_committee_hot);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_certificate_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] auth_committee_hot A constant pointer to the \ref cardano_certificate_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p auth_committee_hot or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* auth_committee_hot = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_certificate_to_cbor(auth_committee_hot, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_certificate_unref(&auth_committee_hot);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_certificate_to_cbor(+  const cardano_certificate_t* auth_committee_hot,+  cardano_cbor_writer_t*       writer);++/**+ * \brief Serializes a certificate to CIP-116 JSON.+ *+ * This function acts as a dispatcher, identifying the specific type of the certificate+ * and calling the appropriate serialization function.+ *+ * \param[in]  certificate Pointer to a valid \ref cardano_certificate_t.+ * \param[in]  writer      Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p certificate or \p writer is NULL.+ * CARDANO_ERROR_INVALID_CERTIFICATE_TYPE If the certificate type is unknown or unsupported.+ * Other                                     Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_cip116_json(+  const cardano_certificate_t* certificate,+  cardano_json_writer_t*       writer);++/**+ * \brief Retrieves the type of a Cardano certificate.+ *+ * This function determines the type of a given \ref cardano_certificate_t object, which indicates the specific kind+ * of operations or permissions the certificate represents within the Cardano blockchain ecosystem.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_certificate_t object whose type is to be determined.+ * \param[out] type A pointer to a \ref cardano_cert_type_t variable where the type of the certificate will be stored upon successful execution.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the type was successfully retrieved,+ *         or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if either input pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_cert_type_t type;+ *+ * cardano_error_t result = cardano_cert_get_type(certificate, &type);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Certificate type: %d\n", type);+ * }+ * else+ * {+ *   printf("Failed to retrieve certificate type.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_cert_get_type(const cardano_certificate_t* certificate, cardano_cert_type_t* type);++/**+ * \brief Converts a certificate to an authorization committee hot certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_auth_committee_hot_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] auth_committee_hot_cert On successful conversion, this will point to the \ref cardano_auth_committee_hot_cert_t object derived from the certificate.+ *                                     If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_auth_committee_hot_cert_t* auth_committee_hot_cert = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_auth_committee_hot(certificate, &auth_committee_hot_cert);+ * if (result == CARDANO_SUCCESS && auth_committee_hot_cert != NULL)+ * {+ *   // Successfully converted certificate to auth committee hot certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, auth_committee_hot_cert will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_auth_committee_hot(+  cardano_certificate_t*              certificate,+  cardano_auth_committee_hot_cert_t** auth_committee_hot_cert);++/**+ * \brief Converts a certificate to a genesis key delegation certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_genesis_key_delegation_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] genesis_key_delegation On successful conversion, this will point to the \ref cardano_genesis_key_delegation_cert_t object derived from the certificate.+ *                                    If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_genesis_key_delegation_cert_t* genesis_key_delegation = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_genesis_key_delegation(certificate, &genesis_key_delegation);+ * if (result == CARDANO_SUCCESS && genesis_key_delegation != NULL)+ * {+ *   // Successfully converted certificate to genesis key delegation certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, genesis_key_delegation will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_genesis_key_delegation(+  cardano_certificate_t*                  certificate,+  cardano_genesis_key_delegation_cert_t** genesis_key_delegation);++/**+ * \brief Converts a certificate to an MIR certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_mir_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] mir On successful conversion, this will point to the \ref cardano_mir_cert_t object derived from the certificate.+ *                 If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_mir_cert_t* mir = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_mir(certificate, &mir);+ * if (result == CARDANO_SUCCESS && mir != NULL)+ * {+ *   // Successfully converted certificate to MIR certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, mir will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_mir(+  cardano_certificate_t* certificate,+  cardano_mir_cert_t**   mir);++/**+ * \brief Converts a certificate to a pool registration certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_pool_registration_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] pool_registration On successful conversion, this will point to the \ref cardano_pool_registration_cert_t object derived from the certificate.+ *                               If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_pool_registration_cert_t* pool_registration = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_pool_registration(certificate, &pool_registration);+ * if (result == CARDANO_SUCCESS && pool_registration != NULL)+ * {+ *   // Successfully converted certificate to pool registration certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, pool_registration will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_pool_registration(+  cardano_certificate_t*             certificate,+  cardano_pool_registration_cert_t** pool_registration);++/**+ * \brief Converts a certificate to a pool retirement certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_pool_retirement_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] pool_retirement On successful conversion, this will point to the \ref cardano_pool_retirement_cert_t object derived from the certificate.+ *                             If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_pool_retirement_cert_t* pool_retirement = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_pool_retirement(certificate, &pool_retirement);+ * if (result == CARDANO_SUCCESS && pool_retirement != NULL)+ * {+ *   // Successfully converted certificate to pool retirement certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, pool_retirement will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_pool_retirement(+  cardano_certificate_t*           certificate,+  cardano_pool_retirement_cert_t** pool_retirement);++/**+ * \brief Converts a certificate to a register drep certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_register_drep_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] register_drep On successful conversion, this will point to the \ref cardano_register_drep_cert_t object derived from the certificate.+ *                           If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_register_drep_cert_t* register_drep = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_register_drep(certificate, &register_drep);+ * if (result == CARDANO_SUCCESS && register_drep != NULL)+ * {+ *   // Successfully converted certificate to register drep certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, register_drep will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_register_drep(+  cardano_certificate_t*         certificate,+  cardano_register_drep_cert_t** register_drep);++/**+ * \brief Converts a certificate to a registration certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_registration_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] registration On successful conversion, this will point to the \ref cardano_registration_cert_t object derived from the certificate.+ *                          If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_registration_cert_t* registration = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_registration(certificate, &registration);+ * if (result == CARDANO_SUCCESS && registration != NULL)+ * {+ *   // Successfully converted certificate to registration certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, registration will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_registration(+  cardano_certificate_t*        certificate,+  cardano_registration_cert_t** registration);++/**+ * \brief Converts a certificate to a resign committee cold certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_resign_committee_cold_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] resign_committee_cold On successful conversion, this will point to the \ref cardano_resign_committee_cold_cert_t object derived from the certificate.+ *                                   If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_resign_committee_cold_cert_t* resign_committee_cold = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_resign_committee_cold(certificate, &resign_committee_cold);+ * if (result == CARDANO_SUCCESS && resign_committee_cold != NULL)+ * {+ *   // Successfully converted certificate to resign committee cold certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, resign_committee_cold will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_resign_committee_cold(+  cardano_certificate_t*                 certificate,+  cardano_resign_committee_cold_cert_t** resign_committee_cold);++/**+ * \brief Converts a certificate to a stake delegation certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_stake_delegation_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] stake_delegation On successful conversion, this will point to the \ref cardano_stake_delegation_cert_t object derived from the certificate.+ *                              If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_stake_delegation_cert_t* stake_delegation = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_stake_delegation(certificate, &stake_delegation);+ * if (result == CARDANO_SUCCESS && stake_delegation != NULL)+ * {+ *   // Successfully converted certificate to stake delegation certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, stake_delegation will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_stake_delegation(+  cardano_certificate_t*            certificate,+  cardano_stake_delegation_cert_t** stake_delegation);++/**+ * \brief Converts a certificate to a stake deregistration certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_stake_deregistration_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] stake_deregistration On successful conversion, this will point to the \ref cardano_stake_deregistration_cert_t object derived from the certificate.+ *                                  If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_stake_deregistration_cert_t* stake_deregistration = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_stake_deregistration(certificate, &stake_deregistration);+ * if (result == CARDANO_SUCCESS && stake_deregistration != NULL)+ * {+ *   // Successfully converted certificate to stake deregistration certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, stake_deregistration will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_stake_deregistration(+  cardano_certificate_t*                certificate,+  cardano_stake_deregistration_cert_t** stake_deregistration);++/**+ * \brief Converts a certificate to a stake registration certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_stake_registration_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] stake_registration On successful conversion, this will point to the \ref cardano_stake_registration_cert_t object derived from the certificate.+ *                                If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_stake_registration_cert_t* stake_registration = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_stake_registration(certificate, &stake_registration);+ * if (result == CARDANO_SUCCESS && stake_registration != NULL)+ * {+ *   // Successfully converted certificate to stake registration certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, stake_registration will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_stake_registration(+  cardano_certificate_t*              certificate,+  cardano_stake_registration_cert_t** stake_registration);++/**+ * \brief Converts a certificate to a stake registration delegation certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_stake_registration_delegation_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] stake_registration_delegation On successful conversion, this will point to the \ref cardano_stake_registration_delegation_cert_t object derived from the certificate.+ *                                           If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_stake_registration_delegation_cert_t* stake_registration_delegation = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_stake_registration_delegation(certificate, &stake_registration_delegation);+ * if (result == CARDANO_SUCCESS && stake_registration_delegation != NULL)+ * {+ *   // Successfully converted certificate to stake registration delegation certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, stake_registration_delegation will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_stake_registration_delegation(+  cardano_certificate_t*                         certificate,+  cardano_stake_registration_delegation_cert_t** stake_registration_delegation);++/**+ * \brief Converts a certificate to a stake vote delegation certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_stake_vote_delegation_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] stake_vote_delegation On successful conversion, this will point to the \ref cardano_stake_vote_delegation_cert_t object derived from the certificate.+ *                                   If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_stake_vote_delegation_cert_t* stake_vote_delegation = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_stake_vote_delegation(certificate, &stake_vote_delegation);+ * if (result == CARDANO_SUCCESS && stake_vote_delegation != NULL)+ * {+ *   // Successfully converted certificate to stake vote delegation certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, stake_vote_delegation will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_stake_vote_delegation(+  cardano_certificate_t*                 certificate,+  cardano_stake_vote_delegation_cert_t** stake_vote_delegation);++/**+ * \brief Converts a certificate to a stake vote registration delegation certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] stake_vote_registration_delegation On successful conversion, this will point to the \ref cardano_stake_vote_registration_delegation_cert_t object derived from the certificate.+ *                                                 If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_stake_vote_registration_delegation_cert_t* stake_vote_registration_delegation = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_stake_vote_registration_delegation(certificate, &stake_vote_registration_delegation);+ * if (result == CARDANO_SUCCESS && stake_vote_registration_delegation != NULL)+ * {+ *   // Successfully converted certificate to stake vote registration delegation certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, stake_vote_registration_delegation will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_stake_vote_registration_delegation(+  cardano_certificate_t*                              certificate,+  cardano_stake_vote_registration_delegation_cert_t** stake_vote_registration_delegation);++/**+ * \brief Converts a certificate to an unregister DREP certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_unregister_drep_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] unregister_drep On successful conversion, this will point to the \ref cardano_unregister_drep_cert_t object derived from the certificate.+ *                             If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_unregister_drep_cert_t* unregister_drep = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_unregister_drep(certificate, &unregister_drep);+ * if (result == CARDANO_SUCCESS && unregister_drep != NULL)+ * {+ *   // Successfully converted certificate to unregister DREP certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, unregister_drep will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_unregister_drep(+  cardano_certificate_t*           certificate,+  cardano_unregister_drep_cert_t** unregister_drep);++/**+ * \brief Converts a certificate to an unregistration certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_unregistration_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] unregistration On successful conversion, this will point to the \ref cardano_unregistration_cert_t object derived from the certificate.+ *                            If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_unregistration_cert_t* unregistration = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_unregistration(certificate, &unregistration);+ * if (result == CARDANO_SUCCESS && unregistration != NULL)+ * {+ *   // Successfully converted certificate to unregistration certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, unregistration will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_unregistration(+  cardano_certificate_t*          certificate,+  cardano_unregistration_cert_t** unregistration);++/**+ * \brief Converts a certificate to an update drep certificate type.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_update_drep_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] update_drep On successful conversion, this will point to the \ref cardano_update_drep_cert_t object derived from the certificate.+ *                         If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_update_drep_cert_t* update_drep = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_update_drep(certificate, &update_drep);+ * if (result == CARDANO_SUCCESS && update_drep != NULL)+ * {+ *   // Successfully converted certificate to update drep certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, update_drep will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_update_drep(+  cardano_certificate_t*       certificate,+  cardano_update_drep_cert_t** update_drep);++/**+ * \brief Converts a certificate to a vote delegation certificate.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_vote_delegation_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] vote_delegation On successful conversion, this will point to the \ref cardano_vote_delegation_cert_t object derived from the certificate.+ *                             If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_vote_delegation_cert_t* vote_delegation = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_vote_delegation(certificate, &vote_delegation);+ * if (result == CARDANO_SUCCESS && vote_delegation != NULL)+ * {+ *   // Successfully converted certificate to vote delegation certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, vote_delegation will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_vote_delegation(+  cardano_certificate_t*           certificate,+  cardano_vote_delegation_cert_t** vote_delegation);++/**+ * \brief Converts a certificate to a vote registration delegation certificate.+ *+ * This function attempts to convert a \ref cardano_certificate_t object into a \ref cardano_vote_registration_delegation_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_certificate_t object.+ * \param[out] vote_registration_delegation On successful conversion, this will point to the \ref cardano_vote_registration_delegation_cert_t object derived from the certificate.+ *                                          If the certificate is not of the correct type, this will be set to NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the conversion was successful,+ *         or an appropriate error code indicating the failure reason. If the certificate type does not match, the function will return+ *         \ref CARDANO_ERROR_INVALID_CERTIFICATE_TYPE.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* certificate = ...; // Assume certificate is already initialized+ * cardano_vote_registration_delegation_cert_t* vote_registration_delegation = NULL;+ *+ * cardano_error_t result = cardano_certificate_to_vote_registration_delegation(certificate, &vote_registration_delegation);+ * if (result == CARDANO_SUCCESS && vote_registration_delegation != NULL)+ * {+ *   // Successfully converted certificate to vote registration delegation certificate+ * }+ * else+ * {+ *   // Handle failure or incorrect certificate type+ * }+ * \endcode+ *+ * \note If the conversion fails or the certificate type is incorrect, vote_registration_delegation will be set to NULL.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_to_vote_registration_delegation(+  cardano_certificate_t*                        certificate,+  cardano_vote_registration_delegation_cert_t** vote_registration_delegation);++/**+ * \brief Decrements the reference count of a cardano_certificate_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_certificate_t object+ * by decreasing its reference count. When the reference count reaches zero, the auth_committee_hot is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] auth_committee_hot A pointer to the pointer of the auth_committee_hot object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_t* auth_committee_hot = cardano_certificate_new(major, minor);+ *+ * // Perform operations with the auth_committee_hot...+ *+ * cardano_certificate_unref(&auth_committee_hot);+ * // At this point, auth_committee_hot is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_certificate_unref, the pointer to the \ref cardano_certificate_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_certificate_unref(cardano_certificate_t** auth_committee_hot);++/**+ * \brief Increases the reference count of the cardano_certificate_t object.+ *+ * This function is used to manually increment the reference count of an cardano_certificate_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_certificate_unref.+ *+ * \param auth_committee_hot A pointer to the cardano_certificate_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming auth_committee_hot is a previously created auth_committee_hot object+ *+ * cardano_certificate_ref(auth_committee_hot);+ *+ * // Now auth_committee_hot can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_certificate_ref there is a corresponding+ * call to \ref cardano_certificate_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_certificate_ref(cardano_certificate_t* auth_committee_hot);++/**+ * \brief Retrieves the current reference count of the cardano_certificate_t object.+ *+ * This function returns the number of active references to an cardano_certificate_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_certificate_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param auth_committee_hot A pointer to the cardano_certificate_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_certificate_t object. If the object+ * is properly managed (i.e., every \ref cardano_certificate_ref call is matched with a+ * \ref cardano_certificate_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming auth_committee_hot is a previously created auth_committee_hot object+ *+ * size_t ref_count = cardano_certificate_refcount(auth_committee_hot);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_certificate_refcount(const cardano_certificate_t* auth_committee_hot);++/**+ * \brief Sets the last error message for a given cardano_certificate_t object.+ *+ * Records an error message in the auth_committee_hot's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] auth_committee_hot A pointer to the \ref cardano_certificate_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the auth_committee_hot's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_certificate_set_last_error(+  cardano_certificate_t* auth_committee_hot,+  const char*            message);++/**+ * \brief Retrieves the last error message recorded for a specific auth_committee_hot.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_certificate_set_last_error for the given+ * auth_committee_hot. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] auth_committee_hot A pointer to the \ref cardano_certificate_t instance whose last error+ *                   message is to be retrieved. If the auth_committee_hot is NULL, the function+ *                   returns a generic error message indicating the null auth_committee_hot.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified auth_committee_hot. If the auth_committee_hot is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_certificate_set_last_error for the same auth_committee_hot, or until+ *       the auth_committee_hot is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_certificate_get_last_error(+  const cardano_certificate_t* auth_committee_hot);++/**+ * \brief Creates an independent deep copy of a \ref cardano_certificate_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_certificate_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_certificate_deep_clone(const cardano_certificate_t* source, cardano_certificate_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // CERTIFICATE_H
+ vendor/include/cardano/certs/certificate_set.h view
@@ -0,0 +1,441 @@+/**+ * \file certificate_set.h+ *+ * \author angel.castillo+ * \date   Sep 17, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CERTIFICATE_SET_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CERTIFICATE_SET_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/certs/certificate.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Represents a set of certificates.+ */+typedef struct cardano_certificate_set_t cardano_certificate_set_t;++/**+ * \brief Creates and initializes a new instance of a certificate_set.+ *+ * This function allocates and initializes a new instance of \ref cardano_certificate_set_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] certificate_set On successful initialization, this will point to a newly created+ *             \ref cardano_certificate_set_t object. This object represents a "strong reference"+ *             to the certificate_set, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the certificate_set is no longer needed, the caller must release it+ *             by calling \ref cardano_certificate_set_unref.+ *+ * \return \ref CARDANO_SUCCESS if the certificate_set was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_set_t* certificate_set = NULL;+ *+ * // Attempt to create a new certificate_set+ * cardano_error_t result = cardano_certificate_set_new(&certificate_set);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the certificate_set+ *+ *   // Once done, ensure to clean up and release the certificate_set+ *   cardano_certificate_set_unref(&certificate_set);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_set_new(cardano_certificate_set_t** certificate_set);++/**+ * \brief Creates a certificate set from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_certificate_set_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a certificate.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded certificate data.+ * \param[out] certificates A pointer to a pointer of \ref cardano_certificate_set_t that will be set to the address+ *                        of the newly created certificate object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the certificate was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_certificate_set_t object by calling+ *       \ref cardano_certificate_set_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_certificate_set_t* certificate = NULL;+ *+ * cardano_error_t result = cardano_certificate_set_from_cbor(reader, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the certificate+ *+ *   // Once done, ensure to clean up and release the certificate+ *   cardano_certificate_set_unref(&certificate);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode certificate: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_set_from_cbor(cardano_cbor_reader_t* reader, cardano_certificate_set_t** certificates);++/**+ * \brief Serializes a certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_certificate_set_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] certificates A constant pointer to the \ref cardano_certificate_set_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p certificate or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_set_t* certificate = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_certificate_set_to_cbor(certificate, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_certificate_set_unref(&certificate);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_certificate_set_to_cbor(+  const cardano_certificate_set_t* certificates,+  cardano_cbor_writer_t*           writer);++/**+ * \brief Serializes a set of certificates to CIP-116 JSON.+ *+ * The function writes a JSON array containing the serialized certificates.+ *+ * \param[in]  certs   Pointer to a valid \ref cardano_certificate_set_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p certs or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_certificate_set_to_cip116_json(+  const cardano_certificate_set_t* certs,+  cardano_json_writer_t*           writer);++/**+ * \brief Retrieves the length of a certificate list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_certificate_set_t object.+ *+ * \param[in] certificate_set A constant pointer to the \ref cardano_certificate_set_t object whose length is to be retrieved.+ *+ * \return The number of elements in the certificate_set. Return 0 if the certificate_set is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_set_t* certificate_set = cardano_certificate_set_new();+ *+ * // Populate certificate_set with elements+ *+ * size_t length = cardano_certificate_set_get_length(certificate_set);+ * printf("Length of the certificate_set: %zu\n", length);+ *+ * // Clean up the certificate_set object once done+ * cardano_certificate_set_unref(&certificate_set);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_certificate_set_get_length(const cardano_certificate_set_t* certificate_set);++/**+ * \brief Retrieves an element from a certificate list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_certificate_set_t object+ * and stores it in the output parameter.+ *+ * \param[in] certificate_set A constant pointer to the \ref cardano_certificate_set_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the certificate list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_certificate_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_certificate_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_set_t* certificate_set = cardano_certificate_set_new();+ *+ * // Populate certificate_set with elements+ *+ * cardano_certificate_t* element = NULL;+ * cardano_error_t result = cardano_certificate_set_get(certificate_set, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_certificate_unref(&element);+ * }+ *+ * // Clean up the certificate_set object once done+ * cardano_certificate_set_unref(&certificate_set);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_certificate_set_get(const cardano_certificate_set_t* certificate_set, size_t index, cardano_certificate_t** element);++/**+ * \brief Adds an element to a certificate list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_certificate_set_t object.+ *+ * \param[in] certificate_set A constant pointer to the \ref cardano_certificate_set_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_certificate_t object that is to be added to the certificate_set.+ *                    The element will be referenced by the certificate_set after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the certificate_set, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_set_t* certificate_set = cardano_certificate_set_new();+ *+ * // Create and initialize a new certificate element+ * cardano_certificate_t* element = { ... };+ *+ * // Add the element to the certificate_set+ * cardano_error_t result = cardano_certificate_set_add(certificate_set, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the certificate_set object once done+ * cardano_certificate_set_unref(&certificate_set);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_certificate_set_add(cardano_certificate_set_t* certificate_set, cardano_certificate_t* element);++/**+ * \brief Decrements the reference count of a certificate_set object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_certificate_set_t object+ * by decreasing its reference count. When the reference count reaches zero, the certificate_set is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] certificate_set A pointer to the pointer of the certificate_set object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_certificate_set_t* certificate_set = cardano_certificate_set_new();+ *+ * // Perform operations with the certificate_set...+ *+ * cardano_certificate_set_unref(&certificate_set);+ * // At this point, certificate_set is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_certificate_set_unref, the pointer to the \ref cardano_certificate_set_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_certificate_set_unref(cardano_certificate_set_t** certificate_set);++/**+ * \brief Increases the reference count of the cardano_certificate_set_t object.+ *+ * This function is used to manually increment the reference count of a certificate_set+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_certificate_set_unref.+ *+ * \param certificate_set A pointer to the certificate_set object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming certificate_set is a previously created certificate_set object+ *+ * cardano_certificate_set_ref(certificate_set);+ *+ * // Now certificate_set can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_certificate_set_ref there is a corresponding+ * call to \ref cardano_certificate_set_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_certificate_set_ref(cardano_certificate_set_t* certificate_set);++/**+ * \brief Retrieves the current reference count of the cardano_certificate_set_t object.+ *+ * This function returns the number of active references to a certificate_set object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_certificate_set_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param certificate_set A pointer to the certificate_set object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified certificate_set object. If the object+ * is properly managed (i.e., every \ref cardano_certificate_set_ref call is matched with a+ * \ref cardano_certificate_set_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming certificate_set is a previously created certificate_set object+ *+ * size_t ref_count = cardano_certificate_set_refcount(certificate_set);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_certificate_set_refcount(const cardano_certificate_set_t* certificate_set);++/**+ * \brief Sets the last error message for a given certificate_set object.+ *+ * Records an error message in the certificate_set's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] certificate_set A pointer to the \ref cardano_certificate_set_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the certificate_set's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_certificate_set_set_last_error(cardano_certificate_set_t* certificate_set, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific certificate_set.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_certificate_set_set_last_error for the given+ * certificate_set. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] certificate_set A pointer to the \ref cardano_certificate_set_t instance whose last error+ *                   message is to be retrieved. If the certificate_set is NULL, the function+ *                   returns a generic error message indicating the null certificate_set.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified certificate_set. If the certificate_set is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_certificate_set_set_last_error for the same certificate_set, or until+ *       the certificate_set is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_certificate_set_get_last_error(const cardano_certificate_set_t* certificate_set);++/**+ * \brief Creates an independent deep copy of a \ref cardano_certificate_set_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_certificate_set_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_certificate_set_deep_clone(const cardano_certificate_set_t* source, cardano_certificate_set_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CERTIFICATE_SET_H
+ vendor/include/cardano/certs/genesis_key_delegation_cert.h view
@@ -0,0 +1,571 @@+/**+ * \file genesis_key_delegation_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef genesis_key_delegation_cert_H+#define genesis_key_delegation_cert_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used to delegate from a Genesis key to a set of keys. This was primarily used in the early+ * phases of the Cardano network's existence during the transition from the Byron to the Shelley era.+ */+typedef struct cardano_genesis_key_delegation_cert_t cardano_genesis_key_delegation_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new Genesis Key Delegation certificate.+ *+ * This function allocates and initializes a new instance of \ref cardano_genesis_key_delegation_cert_t.+ *+ * \param[in] genesis_hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the hash of the genesis block.+ *                         This hash uniquely identifies the blockchain and ensures that the delegation occurs on the intended chain.+ * \param[in] genesis_delegate_hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the hash of the delegate's public key.+ *                                  This delegate is the new recipient of the block production rights originally held by the genesis key.+ * \param[in] vrf_key_hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the hash of the VRF key belonging to the delegate.+ * \param[out] cert On successful initialization, this parameter will point to the newly created \ref cardano_genesis_key_delegation_cert_t object.+ *                  The caller is responsible for managing the lifecycle of this object, including its deallocation through the appropriate unref function.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was successfully created,+ *         or an appropriate error code indicating the reason for failure, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_blake2b_hash_t* genesis_hash = ...; // Assume genesis_hash is already initialized+ * cardano_blake2b_hash_t* genesis_delegate_hash = ...; // Assume genesis_delegate_hash is initialized+ * cardano_blake2b_hash_t* vrf_key_hash = ...; // Assume vrf_key_hash is initialized+ * cardano_genesis_key_delegation_cert_t* cert = NULL;+ *+ * cardano_error_t result = cardano_genesis_key_delegation_cert_new(genesis_hash, genesis_delegate_hash, vrf_key_hash, &cert);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The Genesis Key Delegation certificate is now ready to be used+ *   // Remember to free the certificate when done+ *   cardano_genesis_key_delegation_cert_unref(&cert);+ * }+ * else+ * {+ *   printf("Failed to create Genesis Key Delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_blake2b_hash_unref(&genesis_hash);+ * cardano_blake2b_hash_unref(&genesis_delegate_hash);+ * cardano_blake2b_hash_unref(&vrf_key_hash);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_genesis_key_delegation_cert_new(+  cardano_blake2b_hash_t*                 genesis_hash,+  cardano_blake2b_hash_t*                 genesis_delegate_hash,+  cardano_blake2b_hash_t*                 vrf_key_hash,+  cardano_genesis_key_delegation_cert_t** cert);++/**+ * \brief Creates a \ref cardano_genesis_key_delegation_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_genesis_key_delegation_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a genesis_key_delegation_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] genesis_key_delegation_cert A pointer to a pointer of \ref cardano_genesis_key_delegation_cert_t that will be set to the address+ *                        of the newly created genesis_key_delegation_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_genesis_key_delegation_cert_t object by calling+ *       \ref cardano_genesis_key_delegation_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_genesis_key_delegation_cert_t* genesis_key_delegation_cert = NULL;+ *+ * cardano_error_t result = cardano_genesis_key_delegation_cert_from_cbor(reader, &genesis_key_delegation_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the genesis_key_delegation_cert+ *+ *   // Once done, ensure to clean up and release the genesis_key_delegation_cert+ *   cardano_genesis_key_delegation_cert_unref(&genesis_key_delegation_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode genesis_key_delegation_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_genesis_key_delegation_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_genesis_key_delegation_cert_t** genesis_key_delegation_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_genesis_key_delegation_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] genesis_key_delegation_cert A constant pointer to the \ref cardano_genesis_key_delegation_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p genesis_key_delegation_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_genesis_key_delegation_cert_t* genesis_key_delegation_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_genesis_key_delegation_cert_to_cbor(genesis_key_delegation_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_genesis_key_delegation_cert_unref(&genesis_key_delegation_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_genesis_key_delegation_cert_to_cbor(+  const cardano_genesis_key_delegation_cert_t* genesis_key_delegation_cert,+  cardano_cbor_writer_t*                       writer);++/**+ * \brief Serializes a genesis-key-delegation certificate to CIP-116 JSON.+ *+ * Keys are written in deterministic order: "tag", "genesis_hash", "genesis_delegate_hash", "vrf_keyhash".+ * The function writes the full JSON object, including surrounding braces.+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_genesis_key_delegation_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ *         CARDANO_ERROR_POINTER_IS_NULL  If \p cert or \p writer is NULL.+ *         CARDANO_ERROR_ENCODING         If required fields are missing/invalid.+ *         Other                          Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_genesis_key_delegation_cert_to_cip116_json(+  const cardano_genesis_key_delegation_cert_t* cert,+  cardano_json_writer_t*                       writer);++/**+ * \brief Retrieves the genesis hash from a genesis key delegation certificate.+ *+ * This function extracts the genesis hash from the specified \ref cardano_genesis_key_delegation_cert_t object.+ * The genesis hash uniquely identifies the blockchain network and is used to confirm that the delegation occurs on the intended blockchain.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_genesis_key_delegation_cert_t object.+ *+ * \return A pointer to the \ref cardano_blake2b_hash_t object containing the genesis hash. If the certificate is NULL or+ *         if the genesis hash is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_genesis_key_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* genesis_hash = cardano_genesis_key_delegation_cert_get_genesis_hash(certificate);+ *+ * if (genesis_hash != NULL)+ * {+ *   // Process the genesis hash+ *   cardano_blake2b_hash_unref(&genesis_hash);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_genesis_key_delegation_cert_get_genesis_hash(+  cardano_genesis_key_delegation_cert_t* certificate);++/**+ * \brief Sets the genesis hash in a genesis key delegation certificate.+ *+ * This function assigns a new genesis hash to the specified \ref cardano_genesis_key_delegation_cert_t object.+ * The genesis hash uniquely identifies the blockchain network and is used to confirm that the delegation occurs on the intended blockchain.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_genesis_key_delegation_cert_t object.+ * \param[in] hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the genesis hash.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the genesis hash+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_genesis_key_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* hash = ...; // Assume hash is initialized+ * cardano_error_t result = cardano_genesis_key_delegation_cert_set_genesis_hash(certificate, hash);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Genesis hash set successfully.\n");+ *+ *  cardano_blake2b_hash_unref(&hash);+ * }+ * else+ * {+ *   printf("Failed to set genesis hash.\n");+ * }+ * \endcode+ *+ * \note This function does not take ownership of the hash; the caller is responsible for managing the lifecycle of the hash object.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_genesis_key_delegation_cert_set_genesis_hash(+  cardano_genesis_key_delegation_cert_t* certificate,+  cardano_blake2b_hash_t*                hash);++/**+ * \brief Retrieves the genesis delegate hash from a genesis key delegation certificate.+ *+ * This function extracts the genesis delegate hash from the specified \ref cardano_genesis_key_delegation_cert_t object.+ * The genesis delegate hash is the public key hash of the delegate to whom the power of the genesis key is being delegated.+ * This delegation is crucial during the transitional phase from the Byron era to the Shelley era, allowing specified delegates+ * the rights to produce blocks.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_genesis_key_delegation_cert_t object.+ *+ * \return A pointer to the \ref cardano_blake2b_hash_t object containing the genesis delegate hash. If the certificate is NULL or+ *         if the genesis delegate hash is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_genesis_key_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* delegate_hash = cardano_genesis_key_delegation_cert_get_genesis_delegate_hash(certificate);+ *+ * if (delegate_hash != NULL)+ * {+ *   // Process the genesis delegate hash+ *   cardano_blake2b_hash_unref(&delegate_hash);+ * }+ * \endcode+ *+ * \note This function returns a new reference that must be managed by the caller.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_genesis_key_delegation_cert_get_genesis_delegate_hash(+  cardano_genesis_key_delegation_cert_t* certificate);++/**+ * \brief Sets the genesis delegate hash for a genesis key delegation certificate.+ *+ * This function assigns a new genesis delegate hash to the specified \ref cardano_genesis_key_delegation_cert_t object.+ * The genesis delegate hash is the public key hash of the delegate to whom the power of the genesis key is being delegated,+ * crucial during the transitional phase from the Byron era to the Shelley era.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_genesis_key_delegation_cert_t object.+ * \param[in] hash A constant pointer to an initialized \ref cardano_blake2b_hash_t object containing the new genesis delegate hash.+ *                 The certificate object will hold a reference to this hash object, so it must remain valid for the duration of+ *                 the certificate's lifecycle or until a different hash is set.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the genesis delegate hash+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any+ *         of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_genesis_key_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* delegate_hash = ...; // Assume delegate_hash is already initialized+ *+ * cardano_error_t result = cardano_genesis_key_delegation_cert_set_genesis_delegate_hash(certificate, delegate_hash);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Genesis delegate hash updated successfully.\n");+ *   cardano_blake2b_hash_unref(&delegate_hash);+ * }+ * else+ * {+ *   printf("Failed to set the genesis delegate hash.\n");+ * }+ * \endcode+ *+ * \note This function does not take ownership of the hash; the caller is responsible for managing the lifecycle of the hash object.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_genesis_key_delegation_cert_set_genesis_delegate_hash(+  cardano_genesis_key_delegation_cert_t* certificate,+  cardano_blake2b_hash_t*                hash);++/**+ * \brief Retrieves the VRF key hash from a genesis key delegation certificate.+ *+ * This function extracts the VRF (Verifiable Random Function) key hash from the specified+ * \ref cardano_genesis_key_delegation_cert_t object. The VRF key hash is critical for ensuring the integrity+ * and security of the random selection process in the blockchain's consensus mechanism.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_genesis_key_delegation_cert_t object.+ *+ * \return A pointer to the \ref cardano_blake2b_hash_t object containing the VRF key hash. If the certificate is NULL or+ *         if the VRF key hash is not set, this function returns NULL. The returned hash object is a new reference, and+ *         the caller is responsible for releasing it using \ref cardano_blake2b_hash_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_genesis_key_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* vrf_key_hash = cardano_genesis_key_delegation_cert_get_vrf_key_hash(certificate);+ *+ * if (vrf_key_hash != NULL)+ * {+ *   // Process the VRF key hash+ *   cardano_blake2b_hash_unref(&vrf_key_hash);+ * }+ * else+ * {+ *   printf("Failed to retrieve VRF key hash.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_genesis_key_delegation_cert_get_vrf_key_hash(+  cardano_genesis_key_delegation_cert_t* certificate);++/**+ * \brief Sets the VRF key hash for a genesis key delegation certificate.+ *+ * This function assigns a VRF (Verifiable Random Function) key hash to a given \ref cardano_genesis_key_delegation_cert_t object.+ * The VRF key hash is crucial for the secure and random selection process in the blockchain's consensus mechanism.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_genesis_key_delegation_cert_t object to which the VRF key hash will be set.+ * \param[in] hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the VRF key hash.+ *                 The certificate takes a reference to this hash, ensuring it remains valid for the duration of the certificate's usage.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the VRF key hash was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_genesis_key_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_blake2b_hash_t* vrf_key_hash = ...; // Assume vrf_key_hash is already initialized+ *+ * cardano_error_t result = cardano_genesis_key_delegation_cert_set_vrf_key_hash(certificate, vrf_key_hash);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("VRF key hash successfully set.\n");+ *   cardano_blake2b_hash_unref(&vrf_key_hash);+ * }+ * else+ * {+ *   printf("Failed to set VRF key hash.\n");+ * }+ * \endcode+ *+ * \note This function does not take ownership of the hash; the caller is responsible for managing the lifecycle of the hash object.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_genesis_key_delegation_cert_set_vrf_key_hash(+  cardano_genesis_key_delegation_cert_t* certificate,+  cardano_blake2b_hash_t*                hash);++/**+ * \brief Decrements the reference count of a cardano_genesis_key_delegation_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_genesis_key_delegation_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the genesis_key_delegation_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] genesis_key_delegation_cert A pointer to the pointer of the genesis_key_delegation_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_genesis_key_delegation_cert_t* genesis_key_delegation_cert = cardano_genesis_key_delegation_cert_new(major, minor);+ *+ * // Perform operations with the genesis_key_delegation_cert...+ *+ * cardano_genesis_key_delegation_cert_unref(&genesis_key_delegation_cert);+ * // At this point, genesis_key_delegation_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_genesis_key_delegation_cert_unref, the pointer to the \ref cardano_genesis_key_delegation_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_genesis_key_delegation_cert_unref(+  cardano_genesis_key_delegation_cert_t** genesis_key_delegation_cert);++/**+ * \brief Increases the reference count of the cardano_genesis_key_delegation_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_genesis_key_delegation_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_genesis_key_delegation_cert_unref.+ *+ * \param genesis_key_delegation_cert A pointer to the cardano_genesis_key_delegation_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming genesis_key_delegation_cert is a previously created genesis_key_delegation_cert object+ *+ * cardano_genesis_key_delegation_cert_ref(genesis_key_delegation_cert);+ *+ * // Now genesis_key_delegation_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_genesis_key_delegation_cert_ref there is a corresponding+ * call to \ref cardano_genesis_key_delegation_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_genesis_key_delegation_cert_ref(+  cardano_genesis_key_delegation_cert_t* genesis_key_delegation_cert);++/**+ * \brief Retrieves the current reference count of the cardano_genesis_key_delegation_cert_t object.+ *+ * This function returns the number of active references to an cardano_genesis_key_delegation_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_genesis_key_delegation_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param genesis_key_delegation_cert A pointer to the cardano_genesis_key_delegation_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_genesis_key_delegation_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_genesis_key_delegation_cert_ref call is matched with a+ * \ref cardano_genesis_key_delegation_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming genesis_key_delegation_cert is a previously created genesis_key_delegation_cert object+ *+ * size_t ref_count = cardano_genesis_key_delegation_cert_refcount(genesis_key_delegation_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_genesis_key_delegation_cert_refcount(+  const cardano_genesis_key_delegation_cert_t* genesis_key_delegation_cert);++/**+ * \brief Sets the last error message for a given cardano_genesis_key_delegation_cert_t object.+ *+ * Records an error message in the genesis_key_delegation_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] genesis_key_delegation_cert A pointer to the \ref cardano_genesis_key_delegation_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the genesis_key_delegation_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_genesis_key_delegation_cert_set_last_error(+  cardano_genesis_key_delegation_cert_t* genesis_key_delegation_cert,+  const char*                            message);++/**+ * \brief Retrieves the last error message recorded for a specific genesis_key_delegation_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_genesis_key_delegation_cert_set_last_error for the given+ * genesis_key_delegation_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] genesis_key_delegation_cert A pointer to the \ref cardano_genesis_key_delegation_cert_t instance whose last error+ *                   message is to be retrieved. If the genesis_key_delegation_cert is NULL, the function+ *                   returns a generic error message indicating the null genesis_key_delegation_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified genesis_key_delegation_cert. If the genesis_key_delegation_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_genesis_key_delegation_cert_set_last_error for the same genesis_key_delegation_cert, or until+ *       the genesis_key_delegation_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_genesis_key_delegation_cert_get_last_error(+  const cardano_genesis_key_delegation_cert_t* genesis_key_delegation_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_genesis_key_delegation_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_genesis_key_delegation_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_genesis_key_delegation_cert_deep_clone(const cardano_genesis_key_delegation_cert_t* source, cardano_genesis_key_delegation_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // genesis_key_delegation_cert_H
+ vendor/include/cardano/certs/mir_cert.h view
@@ -0,0 +1,512 @@+/**+ * \file mir_cert.h+ *+ * \author angel.castillo+ * \date   Jun 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_MIR_CERT_H+#define BIGLUP_LABS_INCLUDE_CARDANO_MIR_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/certs/mir_cert_type.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Certificate used to facilitate an instantaneous transfer of rewards within the system.+ *+ * Typically, rewards in Cardano are accumulated and distributed through a carefully designed+ * process aligned with the staking and delegation mechanics. However, certain situations may+ * require a more immediate or specialized handling of rewards, and that's where this type of+ * certificate comes into play.+ *+ * The MoveInstantaneousReward certificate allows for immediate redistribution of rewards+ * within pots, or to a specified se of stake addresses.+ */+typedef struct cardano_mir_cert_t cardano_mir_cert_t;++/**+ * \brief This certificate move instantaneous rewards funds between accounting pots.+ */+typedef struct cardano_mir_to_pot_cert_t cardano_mir_to_pot_cert_t;++/**+ * \brief Creates a move instantaneous rewards certificate that transfers funds to the given set of reward accounts.+ */+typedef struct cardano_mir_to_stake_creds_cert_t cardano_mir_to_stake_creds_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a Move Instantaneous Rewards (MIR) certificate for transferring funds to another accounting pot.+ *+ * This function initializes a new instance of \ref cardano_mir_cert_t that represents a certificate for moving+ * instantaneous rewards between different accounting pots within the Cardano system.+ *+ * \param[in] to_other_pot_cert A pointer to the \ref cardano_mir_to_pot_cert_t object to cast as a \ref cardano_mir_cert_t.+ * \param[out] mir_cert A pointer to a pointer that will be set to the address of the newly created \ref cardano_mir_cert_t object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate+ *         was successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_pot_cert_t* to_other_pot_cert = NULL;+ * cardano_mir_cert_t* mir_cert = NULL;+ *+ * cardano_error_t result = cardano_mir_cert_new_to_other_pot(&to_other_pot_cert, &mir_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the MIR certificate+ *+ *   // Clean up+ *   cardano_mir_to_pot_cert_unref(&to_other_pot_cert);+ *   cardano_mir_cert_unref(&mir_cert);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_cert_new_to_other_pot(+  cardano_mir_to_pot_cert_t* to_other_pot_cert,+  cardano_mir_cert_t**       mir_cert);++/**+ * \brief Creates a Move Instantaneous Rewards (MIR) certificate for transferring funds to a set of reward accounts.+ *+ * This function initializes a new instance of \ref cardano_mir_cert_t that represents a certificate for moving+ * instantaneous rewards to specified stake credentials within the Cardano system.+ *+ * \param[in] to_stake_creds_cert A pointer to a \ref cardano_mir_to_stake_creds_cert_t object representing the target stake credentials.+ * \param[out] mir_cert A pointer to a pointer that will be set to the address of the newly created \ref cardano_mir_cert_t object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate+ *         was successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_stake_creds_cert_t* to_stake_creds_cert = ...; // Assume this is initialized+ * cardano_mir_cert_t* mir_cert = NULL;+ *+ * cardano_error_t result = cardano_mir_cert_new_to_stake_creds(to_stake_creds_cert, &mir_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the MIR certificate+ *+ *   // Clean up+ *   cardano_mir_to_stake_creds_cert_unref(&to_stake_creds_cert);+ *   cardano_mir_cert_unref(&mir_cert);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_cert_new_to_stake_creds(+  cardano_mir_to_stake_creds_cert_t* to_stake_creds_cert,+  cardano_mir_cert_t**               mir_cert);++/**+ * \brief Creates a \ref cardano_mir_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_mir_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a mir_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] mir_cert A pointer to a pointer of \ref cardano_mir_cert_t that will be set to the address+ *                        of the newly created mir_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_mir_cert_t object by calling+ *       \ref cardano_mir_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_mir_cert_t* mir_cert = NULL;+ *+ * cardano_error_t result = cardano_mir_cert_from_cbor(reader, &mir_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the mir_cert+ *+ *   // Once done, ensure to clean up and release the mir_cert+ *   cardano_mir_cert_unref(&mir_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode mir_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_mir_cert_t** mir_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_mir_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] mir_cert A constant pointer to the \ref cardano_mir_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p mir_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_cert_t* mir_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_mir_cert_to_cbor(mir_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_mir_cert_unref(&mir_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_mir_cert_to_cbor(+  const cardano_mir_cert_t* mir_cert,+  cardano_cbor_writer_t*    writer);++/**+ * \brief Serializes a Move Instantaneous Rewards (MIR) certificate to CIP-116 JSON.+ *+ * This function dispatches based on the MIR certificate variant and emits the+ * corresponding CIP-116 JSON object exactly as produced by the concrete helpers:+ *+ * - \ref cardano_mir_to_pot_cert_to_cip116_json for MIR-to-pot certificates+ * - \ref cardano_mir_to_stake_creds_cert_to_cip116_json for MIR-to-stake-creds+ *+ * \param[in]  cert   Pointer to a valid \ref cardano_mir_cert_t.+ * \param[in]  writer Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ *         CARDANO_ERROR_POINTER_IS_NULL  If \p cert or \p writer is NULL.+ *         CARDANO_ERROR_INVALID_CERTIFICATE_TYPE If the MIR variant is unknown.+ *         Other                          Any error propagated from nested serializers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_cert_to_cip116_json(+  const cardano_mir_cert_t* cert,+  cardano_json_writer_t*    writer);++/**+ * \brief Retrieves the type of a Move Instantaneous Rewards (MIR) certificate.+ *+ * This function extracts the type of the specified \ref cardano_mir_cert_t object, which indicates+ * whether the certificate moves funds between accounting pots or transfers funds to specified+ * reward accounts.+ *+ * \param[in] mir_cert A constant pointer to the \ref cardano_mir_cert_t object whose type is to be retrieved.+ * \param[out] type A pointer to a \ref cardano_mir_cert_type_t variable where the type of the MIR certificate will be stored.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the type+ *         was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_cert_t* mir_cert = ...; // Assume this is initialized+ * cardano_mir_cert_type_t type;+ *+ * cardano_error_t result = cardano_mir_cert_get_type(mir_cert, &type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the MIR certificate type+ *   if (type == CARDANO_MIR_CERT_TYPE_TO_POT)+ *   {+ *     // Handle pot type+ *   }+ *   else if (type == CARDANO_MIR_CERT_TYPE_TO_STAKE_CREDS)+ *   {+ *     // Handle stake credentials type+ *   }+ * }+ *+ * // Clean up+ * cardano_mir_cert_unref(&mir_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_cert_get_type(const cardano_mir_cert_t* mir_cert, cardano_mir_cert_type_t* type);++/**+ * \brief Retrieves the Move Instantaneous Rewards (MIR) certificate as a 'to other pot' certificate.+ *+ * This function extracts the \ref cardano_mir_to_pot_cert_t object from the specified+ * \ref cardano_mir_cert_t object if the MIR certificate type is \ref CARDANO_MIR_CERT_TYPE_TO_POT.+ *+ * \param[in] mir_cert A pointer to the \ref cardano_mir_cert_t object to be converted.+ * \param[out] to_other_pot_cert A pointer to a pointer that will be set to the address of the+ *             \ref cardano_mir_to_pot_cert_t object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the conversion was successful, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_cert_t* mir_cert = ...; // Assume this is initialized+ * cardano_mir_to_pot_cert_t* to_other_pot_cert = NULL;+ *+ * cardano_error_t result = cardano_mir_cert_as_to_other_pot(mir_cert, &to_other_pot_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the to_other_pot_cert+ * }+ *+ * // Clean up+ * cardano_mir_cert_unref(&mir_cert);+ * cardano_mir_to_pot_cert_unref(&to_other_pot_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_mir_cert_as_to_other_pot(+  cardano_mir_cert_t*         mir_cert,+  cardano_mir_to_pot_cert_t** to_other_pot_cert);++/**+ * \brief Retrieves the Move Instantaneous Rewards (MIR) certificate as a 'to stake credentials' certificate.+ *+ * This function extracts the \ref cardano_mir_to_stake_creds_cert_t object from the specified+ * \ref cardano_mir_cert_t object if the MIR certificate type is \ref CARDANO_MIR_CERT_TYPE_TO_STAKE_CREDS.+ *+ * \param[in] mir_cert A pointer to the \ref cardano_mir_cert_t object to be converted.+ * \param[out] to_stake_creds_cert A pointer to a pointer that will be set to the address of the+ *             \ref cardano_mir_to_stake_creds_cert_t object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the conversion was successful, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_cert_t* mir_cert = ...; // Assume this is initialized+ * cardano_mir_to_stake_creds_cert_t* to_stake_creds_cert = NULL;+ *+ * cardano_error_t result = cardano_mir_cert_as_to_stake_creds(mir_cert, &to_stake_creds_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the to_stake_creds_cert+ * }+ *+ * // Clean up+ * cardano_mir_cert_unref(&mir_cert);+ * cardano_mir_to_stake_creds_cert_unref(&to_stake_creds_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_mir_cert_as_to_stake_creds(+  cardano_mir_cert_t*                 mir_cert,+  cardano_mir_to_stake_creds_cert_t** to_stake_creds_cert);++/**+ * \brief Decrements the reference count of a cardano_mir_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_mir_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the mir_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] mir_cert A pointer to the pointer of the mir_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_cert_t* mir_cert = cardano_mir_cert_new(major, minor);+ *+ * // Perform operations with the mir_cert...+ *+ * cardano_mir_cert_unref(&mir_cert);+ * // At this point, mir_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_mir_cert_unref, the pointer to the \ref cardano_mir_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_mir_cert_unref(cardano_mir_cert_t** mir_cert);++/**+ * \brief Increases the reference count of the cardano_mir_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_mir_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_mir_cert_unref.+ *+ * \param mir_cert A pointer to the cardano_mir_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming mir_cert is a previously created mir_cert object+ *+ * cardano_mir_cert_ref(mir_cert);+ *+ * // Now mir_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_mir_cert_ref there is a corresponding+ * call to \ref cardano_mir_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_mir_cert_ref(cardano_mir_cert_t* mir_cert);++/**+ * \brief Retrieves the current reference count of the cardano_mir_cert_t object.+ *+ * This function returns the number of active references to an cardano_mir_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_mir_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param mir_cert A pointer to the cardano_mir_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_mir_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_mir_cert_ref call is matched with a+ * \ref cardano_mir_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming mir_cert is a previously created mir_cert object+ *+ * size_t ref_count = cardano_mir_cert_refcount(mir_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_mir_cert_refcount(const cardano_mir_cert_t* mir_cert);++/**+ * \brief Sets the last error message for a given cardano_mir_cert_t object.+ *+ * Records an error message in the mir_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] mir_cert A pointer to the \ref cardano_mir_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the mir_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_mir_cert_set_last_error(+  cardano_mir_cert_t* mir_cert,+  const char*         message);++/**+ * \brief Retrieves the last error message recorded for a specific mir_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_mir_cert_set_last_error for the given+ * mir_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] mir_cert A pointer to the \ref cardano_mir_cert_t instance whose last error+ *                   message is to be retrieved. If the mir_cert is NULL, the function+ *                   returns a generic error message indicating the null mir_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified mir_cert. If the mir_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_mir_cert_set_last_error for the same mir_cert, or until+ *       the mir_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_mir_cert_get_last_error(+  const cardano_mir_cert_t* mir_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_mir_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_mir_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_mir_cert_deep_clone(const cardano_mir_cert_t* source, cardano_mir_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_MIR_CERT_H
+ vendor/include/cardano/certs/mir_cert_pot_type.h view
@@ -0,0 +1,64 @@+/**+ * \file mir_cert_pot_type.h+ *+ * \author angel.castillo+ * \date   jun 19, 2024+ *+ * copyright 2024 biglup labs+ *+ * licensed under the apache license, version 2.0 (the "license");+ * you may not use this file except in compliance with the license.+ * you may obtain a copy of the license at+ *+ *     www.apache.org/licenses/license-2.0+ *+ * unless required by applicable law or agreed to in writing, software+ * distributed under the license is distributed on an "as is" basis,+ * without warranties or conditions of any kind, either express or implied.+ * see the license for the specific language governing permissions and+ * limitations under the license.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_MIR_CERT_POT_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_MIR_CERT_POT_TYPE_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Enumerates the target pots for Move Instantaneous Reward (MIR) certificates.+ *+ * MIR certificates in Cardano can move funds between different accounting pots.+ * This enumeration defines the types of pots to which funds can be transferred.+ */+typedef enum+{+  /**+   * \brief Indicates that the MIR certificate moves funds to the reserve pot.+   *+   * The reserve pot in Cardano is a pool of ADA coins that are gradually released into+   * circulation. This reserve is used to provide a continuous supply of ADA for staking+   * rewards and other incentives. The reserve helps ensure the long-term sustainability+   * of the Cardano network by maintaining a steady flow of rewards for network participants.+   */+  CARDANO_MIR_CERT_POT_TYPE_RESERVE = 0,++  /**+   * \brief Indicates that the MIR certificate moves funds to the treasury pot.+   *+   * The treasury pot in Cardano is a fund allocated for the development and improvement+   * of the Cardano ecosystem. For example, it is used to finance projects, proposals, and initiatives+   * through the Project Catalyst governance system. The treasury is filled by a portion+   * of transaction fees and monetary expansion.+   */+  CARDANO_MIR_CERT_POT_TYPE_TREASURY = 1+} cardano_mir_cert_pot_type_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_MIR_CERT_POT_TYPE_H
+ vendor/include/cardano/certs/mir_cert_type.h view
@@ -0,0 +1,53 @@+/**+ * \file mir_cert_type.h+ *+ * \author angel.castillo+ * \date   Jun 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_MIR_CERT_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_MIR_CERT_TYPE_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Enumerates the types of MIR certificates.+ *+ * This enumeration defines the possible types of Move Instantaneous Rewards (MIR) certificates in the Cardano system.+ */+typedef enum+{+  /**+   * \brief This MIR certificate moves instantaneous rewards funds between accounting pots.+   */+  CARDANO_MIR_CERT_TYPE_TO_POT = 0,++  /**+   * \brief This MIR certificate transfers funds to the given set of reward accounts.+   */+  CARDANO_MIR_CERT_TYPE_TO_STAKE_CREDS = 1+} cardano_mir_cert_type_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_MIR_CERT_TYPE_H
+ vendor/include/cardano/certs/mir_to_pot_cert.h view
@@ -0,0 +1,463 @@+/**+ * \file mir_to_pot_cert.h+ *+ * \author angel.castillo+ * \date   Jun 19, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_MIR_TO_POD_CERT_H+#define BIGLUP_LABS_INCLUDE_CARDANO_MIR_TO_POD_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/certs/mir_cert_pot_type.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate move instantaneous rewards funds between accounting pots.+ */+typedef struct cardano_mir_to_pot_cert_t cardano_mir_to_pot_cert_t;++/**+ * \brief Certificate used to facilitate an instantaneous transfer of rewards within the system.+ *+ * Typically, rewards in Cardano are accumulated and distributed through a carefully designed+ * process aligned with the staking and delegation mechanics. However, certain situations may+ * require a more immediate or specialized handling of rewards, and that's where this type of+ * certificate comes into play.+ *+ * The MoveInstantaneousReward certificate allows for immediate redistribution of rewards+ * within pots, or to a specified se of stake addresses.+ */+typedef struct cardano_mir_cert_t cardano_mir_cert_t;++/**+ * \brief Initializes a new instance of the Move Instantaneous Reward (MIR) certificate for transferring funds between pots.+ *+ * This function initializes a new \ref cardano_mir_to_pot_cert_t object, which represents a MIR certificate+ * designed to transfer a specified amount of ADA from one accounting pot to another within the Cardano ecosystem.+ *+ * \param[in] pot_type Determines the accounting pot from which the funds will be drawn. This is specified by the+ *                     \ref cardano_mir_to_pot_cert_t enumeration, which includes options for the reserve pot or the treasury pot.+ * \param[in] amount The amount of ADA to be transferred by this MIR certificate.+ * \param[out] mir_to_pot_cert On successful creation, this will point to a newly created \ref cardano_mir_to_pot_cert_t object.+ *                             The caller is responsible for managing the lifecycle of this object. Specifically,+ *                             once the MIR certificate is no longer needed, the caller must release it by calling+ *                             the appropriate deallocation function.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the MIR certificate was successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_pot_cert_t* mir_to_pot_cert = NULL;+ * cardano_error_t result = cardano_mir_to_pot_cert_new(CARDANO_MIR_CERT_POT_TYPE_RESERVE, 1000, &mir_to_pot_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the MIR certificate+ *+ *   // Once done, ensure to clean up and release the MIR certificate+ *   cardano_mir_to_pot_cert_unref(&mir_to_pot_cert);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_pot_cert_new(+  cardano_mir_cert_pot_type_t pot_type,+  uint64_t                    amount,+  cardano_mir_to_pot_cert_t** mir_to_pot_cert);++/**+ * \brief Creates a \ref cardano_mir_to_pot_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_mir_to_pot_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a mir_to_pot_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] mir_to_pot_cert A pointer to a pointer of \ref cardano_mir_to_pot_cert_t that will be set to the address+ *                        of the newly created mir_to_pot_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_mir_to_pot_cert_t object by calling+ *       \ref cardano_mir_to_pot_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_mir_to_pot_cert_t* mir_to_pot_cert = NULL;+ *+ * cardano_error_t result = cardano_mir_to_pot_cert_from_cbor(reader, &mir_to_pot_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the mir_to_pot_cert+ *+ *   // Once done, ensure to clean up and release the mir_to_pot_cert+ *   cardano_mir_to_pot_cert_unref(&mir_to_pot_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode mir_to_pot_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_pot_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_mir_to_pot_cert_t** mir_to_pot_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_mir_to_pot_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] mir_to_pot_cert A constant pointer to the \ref cardano_mir_to_pot_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p mir_to_pot_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_pot_cert_t* mir_to_pot_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_mir_to_pot_cert_to_cbor(mir_to_pot_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_mir_to_pot_cert_unref(&mir_to_pot_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_mir_to_pot_cert_to_cbor(+  const cardano_mir_to_pot_cert_t* mir_to_pot_cert,+  cardano_cbor_writer_t*           writer);++/**+ * \brief Serializes a MIR-to-pot certificate to CIP-116 JSON.+ *+ * Keys are written in deterministic order: "tag", "pot", "amount".+ * The function writes the full JSON object, including surrounding braces.+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_mir_to_pot_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ *         CARDANO_ERROR_POINTER_IS_NULL  If \p cert or \p writer is NULL.+ *         CARDANO_ERROR_ENCODING         If required fields are missing/invalid.+ *         Other                          Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_pot_cert_to_cip116_json(+  const cardano_mir_to_pot_cert_t* cert,+  cardano_json_writer_t*           writer);++/**+ * \brief Retrieves the pot type from a Move Instantaneous Reward (MIR) certificate.+ *+ * This function extracts the pot type from the given \ref cardano_mir_to_pot_cert_t object, indicating whether the funds+ * are drawn from the reserve or the treasury.+ *+ * \param[in] mir_cert A constant pointer to the \ref cardano_mir_to_pot_cert_t object.+ * \param[out] type A pointer to a \ref cardano_mir_cert_pot_type_t variable where the pot type will be stored.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the pot type was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_pot_cert_t* mir_cert = ...; // Assume this is initialized+ * cardano_mir_cert_pot_type_t pot_type;+ * cardano_error_t result = cardano_mir_to_pot_cert_get_pot(mir_cert, &pot_type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the pot type+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_pot_cert_get_pot(const cardano_mir_to_pot_cert_t* mir_cert, cardano_mir_cert_pot_type_t* type);++/**+ * \brief Sets the pot type for a Move Instantaneous Reward (MIR) certificate.+ *+ * This function assigns the specified pot type to the given \ref cardano_mir_to_pot_cert_t object, indicating whether the funds+ * are drawn from the reserve or the treasury.+ *+ * \param[in,out] mir_cert A pointer to the \ref cardano_mir_to_pot_cert_t object.+ * \param[in] type The pot type to be set, represented by \ref cardano_mir_cert_pot_type_t.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the pot type was successfully set, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_pot_cert_t* mir_cert = ...; // Assume this is initialized+ * cardano_mir_cert_pot_type_t pot_type = CARDANO_MIR_CERT_POT_TYPE_RESERVE;+ * cardano_error_t result = cardano_mir_to_pot_cert_set_pot(mir_cert, pot_type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Pot type was successfully set+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_pot_cert_set_pot(cardano_mir_to_pot_cert_t* mir_cert, cardano_mir_cert_pot_type_t type);++/**+ * \brief Retrieves the amount specified in a Move Instantaneous Reward (MIR) certificate.+ *+ * This function gets the amount to be transferred as specified in the given \ref cardano_mir_to_pot_cert_t object.+ *+ * \param[in] mir_cert A constant pointer to the \ref cardano_mir_to_pot_cert_t object.+ * \param[out] amount A pointer to a uint64_t where the amount will be stored.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the amount was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_mir_to_pot_cert_t* mir_cert = ...; // Assume this is initialized+ * uint64_t amount = 0;+ * cardano_error_t result = cardano_mir_to_pot_cert_get_amount(mir_cert, &amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Amount was successfully retrieved+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_pot_cert_get_amount(const cardano_mir_to_pot_cert_t* mir_cert, uint64_t* amount);++/**+ * \brief Sets the amount in a Move Instantaneous Reward (MIR) certificate.+ *+ * This function sets the amount to be transferred in the given \ref cardano_mir_to_pot_cert_t object.+ *+ * \param[in,out] mir_cert A pointer to the \ref cardano_mir_to_pot_cert_t object.+ * \param[in] amount The amount to be set in the MIR certificate.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the amount was successfully set, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_pot_cert_t* mir_cert = ...; // Assume this is initialized+ * uint64_t amount = 1000;+ * cardano_error_t result = cardano_mir_to_pot_cert_set_amount(mir_cert, amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Amount was successfully set+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_pot_cert_set_amount(cardano_mir_to_pot_cert_t* mir_cert, uint64_t amount);++/**+ * \brief Decrements the reference count of a cardano_mir_to_pot_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_mir_to_pot_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the mir_to_pot_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] mir_to_pot_cert A pointer to the pointer of the mir_to_pot_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_pot_cert_t* mir_to_pot_cert = cardano_mir_to_pot_cert_new(major, minor);+ *+ * // Perform operations with the mir_to_pot_cert...+ *+ * cardano_mir_to_pot_cert_unref(&mir_to_pot_cert);+ * // At this point, mir_to_pot_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_mir_to_pot_cert_unref, the pointer to the \ref cardano_mir_to_pot_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_mir_to_pot_cert_unref(cardano_mir_to_pot_cert_t** mir_to_pot_cert);++/**+ * \brief Increases the reference count of the cardano_mir_to_pot_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_mir_to_pot_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_mir_to_pot_cert_unref.+ *+ * \param mir_to_pot_cert A pointer to the cardano_mir_to_pot_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming mir_to_pot_cert is a previously created mir_to_pot_cert object+ *+ * cardano_mir_to_pot_cert_ref(mir_to_pot_cert);+ *+ * // Now mir_to_pot_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_mir_to_pot_cert_ref there is a corresponding+ * call to \ref cardano_mir_to_pot_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_mir_to_pot_cert_ref(cardano_mir_to_pot_cert_t* mir_to_pot_cert);++/**+ * \brief Retrieves the current reference count of the cardano_mir_to_pot_cert_t object.+ *+ * This function returns the number of active references to an cardano_mir_to_pot_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_mir_to_pot_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param mir_to_pot_cert A pointer to the cardano_mir_to_pot_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_mir_to_pot_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_mir_to_pot_cert_ref call is matched with a+ * \ref cardano_mir_to_pot_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming mir_to_pot_cert is a previously created mir_to_pot_cert object+ *+ * size_t ref_count = cardano_mir_to_pot_cert_refcount(mir_to_pot_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_mir_to_pot_cert_refcount(const cardano_mir_to_pot_cert_t* mir_to_pot_cert);++/**+ * \brief Sets the last error message for a given cardano_mir_to_pot_cert_t object.+ *+ * Records an error message in the mir_to_pot_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] mir_to_pot_cert A pointer to the \ref cardano_mir_to_pot_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the mir_to_pot_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_mir_to_pot_cert_set_last_error(+  cardano_mir_to_pot_cert_t* mir_to_pot_cert,+  const char*                message);++/**+ * \brief Retrieves the last error message recorded for a specific mir_to_pot_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_mir_to_pot_cert_set_last_error for the given+ * mir_to_pot_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] mir_to_pot_cert A pointer to the \ref cardano_mir_to_pot_cert_t instance whose last error+ *                   message is to be retrieved. If the mir_to_pot_cert is NULL, the function+ *                   returns a generic error message indicating the null mir_to_pot_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified mir_to_pot_cert. If the mir_to_pot_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_mir_to_pot_cert_set_last_error for the same mir_to_pot_cert, or until+ *       the mir_to_pot_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_mir_to_pot_cert_get_last_error(+  const cardano_mir_to_pot_cert_t* mir_to_pot_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_mir_to_pot_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_mir_to_pot_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_mir_to_pot_cert_deep_clone(const cardano_mir_to_pot_cert_t* source, cardano_mir_to_pot_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_MIR_TO_POD_CERT_H
+ vendor/include/cardano/certs/mir_to_stake_creds_cert.h view
@@ -0,0 +1,593 @@+/**+ * \file mir_to_stake_creds_cert.h+ *+ * \author angel.castillo+ * \date   Jun 09, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_MIR_TO_STAKE_CREDS_CERT_H+#define BIGLUP_LABS_INCLUDE_CARDANO_MIR_TO_STAKE_CREDS_CERT_H++/* INCLUDES ******************************************************************/++#include "mir_cert_pot_type.h"+#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Certificate used to facilitate an instantaneous transfer of rewards within the system.+ *+ * Typically, rewards in Cardano are accumulated and distributed through a carefully designed+ * process aligned with the staking and delegation mechanics. However, certain situations may+ * require a more immediate or specialized handling of rewards, and that's where this type of+ * certificate comes into play.+ *+ * The MoveInstantaneousReward certificate allows for immediate redistribution of rewards+ * within pots, or to a specified se of stake addresses.+ */+typedef struct cardano_mir_cert_t cardano_mir_cert_t;++/**+ * \brief Creates a move instantaneous rewards certificate that transfers funds to the given set of reward accounts.+ */+typedef struct cardano_mir_to_stake_creds_cert_t cardano_mir_to_stake_creds_cert_t;++/**+ * \brief Creates a new Move Instantaneous Rewards to Stake Credentials certificate.+ *+ * This function allocates and initializes a new instance of a \ref cardano_mir_to_stake_creds_cert_t,+ * which is used to facilitate the transfer of rewards to a set of stake credentials directly.+ * The newly created certificate is capable of storing mappings from stake credentials to the amount+ * of ADA to be transferred.+ *+ * \param[in] pot_type Determines the accounting pot from which the funds will be drawn. This is specified by the+ *                     \ref cardano_mir_to_pot_cert_t enumeration, which includes options for the reserve pot or the treasury pot.+ * \param[out] mir_to_stake_creds_cert On successful execution, this will point to the newly created+ *            \ref cardano_mir_to_stake_creds_cert_t object. The caller is responsible for managing+ *            the lifecycle of this object, including freeing it with the appropriate function when+ *            it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the certificate was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_stake_creds_cert_t* cert = NULL;+ * cardano_error_t result = cardano_mir_to_stake_creds_cert_new(CARDANO_MIR_CERT_POT_TYPE_RESERVE, &cert);+ *+ * if (result == CARDANO_SUCCESS) {+ *   // Use the cert+ *+ *   // Once done, ensure to clean up and release the certificate+ *   cardano_mir_to_stake_creds_cert_unref(&cert);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_stake_creds_cert_new(cardano_mir_cert_pot_type_t pot_type, cardano_mir_to_stake_creds_cert_t** mir_to_stake_creds_cert);++/**+ * \brief Creates a \ref cardano_mir_to_stake_creds_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_mir_to_stake_creds_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a mir_to_stake_creds_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] mir_to_stake_creds_cert A pointer to a pointer of \ref cardano_mir_to_stake_creds_cert_t that will be set to the address+ *                        of the newly created mir_to_stake_creds_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_mir_to_stake_creds_cert_t object by calling+ *       \ref cardano_mir_to_stake_creds_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert = NULL;+ *+ * cardano_error_t result = cardano_mir_to_stake_creds_cert_from_cbor(reader, &mir_to_stake_creds_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the mir_to_stake_creds_cert+ *+ *   // Once done, ensure to clean up and release the mir_to_stake_creds_cert+ *   cardano_mir_to_stake_creds_cert_unref(&mir_to_stake_creds_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode mir_to_stake_creds_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_stake_creds_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_mir_to_stake_creds_cert_t** mir_to_stake_creds_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_mir_to_stake_creds_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] mir_to_stake_creds_cert A constant pointer to the \ref cardano_mir_to_stake_creds_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p mir_to_stake_creds_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_mir_to_stake_creds_cert_to_cbor(mir_to_stake_creds_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_mir_to_stake_creds_cert_unref(&mir_to_stake_creds_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_mir_to_stake_creds_cert_to_cbor(+  const cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert,+  cardano_cbor_writer_t*                   writer);++/**+ * \brief Serializes a MIR-to-stake-credentials certificate to CIP-116 JSON.+ *+ * Keys are written in deterministic order: "tag", "pot", then "rewards".+ * The function writes the full JSON object, including surrounding braces.+ *+ * \param[in]  cert   Pointer to a valid \ref cardano_mir_to_stake_creds_cert_t.+ * \param[in]  writer Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ *         CARDANO_ERROR_POINTER_IS_NULL  If \p cert or \p writer is NULL.+ *         CARDANO_ERROR_ENCODING         If required fields are missing/invalid.+ *         Other                          Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_stake_creds_cert_to_cip116_json(+  const cardano_mir_to_stake_creds_cert_t* cert,+  cardano_json_writer_t*                   writer);++/**+ * \brief Retrieves the source pot type from a Move Instantaneous Reward (MIR) certificate to stake credentials.+ *+ * This function gets the type of pot from which the funds are drawn in the given \ref cardano_mir_to_stake_creds_cert_t object.+ *+ * \param[in] mir_cert A constant pointer to the \ref cardano_mir_to_stake_creds_cert_t object.+ * \param[out] type A pointer to the \ref cardano_mir_cert_pot_type_t where the type will be stored.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the pot type was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_stake_creds_cert_t* mir_cert = ...; // Assume this is initialized+ * cardano_mir_cert_pot_type_t type;+ * cardano_error_t result = cardano_mir_to_stake_creds_cert_get_pot(mir_cert, &type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Type was successfully retrieved+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_stake_creds_cert_get_pot(const cardano_mir_to_stake_creds_cert_t* mir_cert, cardano_mir_cert_pot_type_t* type);++/**+ * \brief Sets the source pot type in a Move Instantaneous Reward (MIR) certificate to stake credentials.+ *+ * This function sets the type of pot from which the funds are drawn in the given \ref cardano_mir_to_stake_creds_cert_t object.+ *+ * \param[in] mir_cert A pointer to the \ref cardano_mir_to_stake_creds_cert_t object.+ * \param[in] type The \ref cardano_mir_cert_pot_type_t value representing the source pot type to be set.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the pot type was successfully set, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_stake_creds_cert_t* mir_cert = ...; // Assume this is initialized+ * cardano_mir_cert_pot_type_t type = CARDANO_MIR_CERT_POT_TYPE_TREASURY;+ * cardano_error_t result = cardano_mir_to_stake_creds_cert_set_pot(mir_cert, type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Type was successfully set+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_mir_to_stake_creds_cert_set_pot(cardano_mir_to_stake_creds_cert_t* mir_cert, cardano_mir_cert_pot_type_t type);++/**+ * \brief Gets the size of the credential-to-amount map in a Move Instantaneous Reward (MIR) certificate to stake credentials.+ *+ * This function retrieves the number of entries in the map from credential to amount within the given \ref cardano_mir_to_stake_creds_cert_t object.+ *+ * \param[in] mir_to_stake_creds_cert A constant pointer to the \ref cardano_mir_to_stake_creds_cert_t object.+ *+ * \return The number of entries in the credential-to-amount map.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_mir_to_stake_creds_cert_t* mir_cert = ...; // Assume this is initialized+ * size_t map_size = cardano_mir_to_stake_creds_cert_get_size(mir_cert);+ * printf("Number of entries in the credential-to-amount map: %zu\n", map_size);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_mir_to_stake_creds_cert_get_size(const cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert);++/**+ * \brief Inserts a credential-to-amount mapping into a Move Instantaneous Reward (MIR) certificate to stake credentials.+ *+ * This function inserts a new entry into the map from credential to amount within the given+ * \ref cardano_mir_to_stake_creds_cert_t object. The specified amount will be transferred+ * as a reward to the provided credential from the selected pot.+ *+ * \param[in,out] mir_to_stake_creds_cert A pointer to the \ref cardano_mir_to_stake_creds_cert_t object.+ * \param[in] credential A pointer to the \ref cardano_credential_t object representing the credential.+ * \param[in] amount The amount associated with the credential to be inserted into the map.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the+ *         entry was successfully inserted, or an appropriate error code indicating the failure reason.+ *+ * \note The certificate does not take ownership of the \p credential. It only stores a reference to it.+ *       The caller is responsible for freeing its own \ref cardano_credential_t instance and the+ *       \ref cardano_mir_to_stake_creds_cert_t instance when they are no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_stake_creds_cert_t* mir_cert = ...; // Assume this is initialized+ * cardano_credential_t* credential = ...; // Assume this is initialized+ * uint64_t amount = 1000;+ * cardano_error_t result = cardano_mir_to_stake_creds_cert_insert(mir_cert, credential, amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Entry was successfully inserted, and the specified amount will be transferred+ *   // as a reward to the credential from the selected pot.+ * }+ * else+ * {+ *   // Handle the error+ * }+ *+ * // Free resources+ * cardano_credential_unref(&credential);+ * cardano_mir_to_stake_creds_cert_unref(&mir_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_mir_to_stake_creds_cert_insert(+  cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert,+  cardano_credential_t*              credential,+  uint64_t                           amount);++/**+ * \brief Retrieves the credential key at a specified index from the Move Instantaneous Reward (MIR) certificate to stake credentials.+ *+ * This function retrieves the credential key at the specified index within the given+ * \ref cardano_mir_to_stake_creds_cert_t object. The credential represents a specific+ * entry in the map from credential to amount.+ *+ * \param[in] mir_to_stake_creds_cert A constant pointer to the \ref cardano_mir_to_stake_creds_cert_t object.+ * \param[in] index The index of the entry to retrieve.+ * \param[out] credential A pointer to a pointer that will be set to the address of a newly created+ *                        \ref cardano_credential_t object, representing the retrieved credential.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the+ *         credential was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * \note The returned credential is a new reference, and the caller is responsible for managing its lifecycle.+ *       Once the credential is no longer needed, the caller must release it by calling \ref cardano_credential_unref.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_mir_to_stake_creds_cert_t* mir_cert = ...; // Assume this is initialized+ * size_t index = 0;+ * cardano_credential_t* credential = NULL;+ * cardano_error_t result = cardano_mir_to_stake_creds_cert_get_key_at(mir_cert, index, &credential);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved credential+ *+ *   // Once done, ensure to clean up and release the credential+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   // Handle the error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_mir_to_stake_creds_cert_get_key_at(+  cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert,+  size_t                             index,+  cardano_credential_t**             credential);++/**+ * \brief Retrieves the amount associated with a credential at a specified index in a Move Instantaneous Reward (MIR) to stake credentials certificate.+ *+ * This function fetches the amount of ADA to be transferred as a reward to the stake credential at the specified index within the MIR certificate.+ * The amount is intended for redistribution from the selected pot to the specified credential.+ *+ * \param[in] mir_to_stake_creds_cert A constant pointer to the \ref cardano_mir_to_stake_creds_cert_t object containing the mapping of credentials to amounts.+ * \param[in] index The index of the credential within the certificate whose associated amount is to be retrieved.+ * \param[out] amount A pointer to a uint64_t variable where the retrieved amount will be stored.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the amount was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_mir_to_stake_creds_cert_t* mir_cert = ...; // Assume this is initialized+ * size_t index = 0;+ * uint64_t amount = 0;+ * cardano_error_t result = cardano_mir_to_stake_creds_cert_get_value_at(mir_cert, index, &amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Amount for credential at index %zu is %llu.\n", index, amount);+ *   // Further processing...+ * }+ * else+ * {+ *   // Handle the error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_mir_to_stake_creds_cert_get_value_at(+  const cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert,+  size_t                                   index,+  uint64_t*                                amount);++/**+ * \brief Retrieves both the credential and the amount associated with it at a specified index in a Move Instantaneous Reward (MIR) to stake credentials certificate.+ *+ * This function provides access to the mapping at a given index within the MIR to stake credentials certificate, allowing the caller to retrieve the credential and the corresponding amount of ADA that is to be transferred as a reward. The credential and amount are used in the certificate's internal representation of transfers from the treasury or reserve to stake addresses.+ *+ * \param[in] mir_to_stake_creds_cert A constant pointer to the \ref cardano_mir_to_stake_creds_cert_t object.+ * \param[in] index The index within the certificate's internal map from which to retrieve the credential and associated amount.+ * \param[out] credential A pointer to a pointer of \ref cardano_credential_t that will be set to point to a newly created reference of the credential. The caller is responsible for managing the lifecycle of this credential reference by calling \ref cardano_credential_unref.+ * \param[out] amount A pointer to a uint64_t where the amount of ADA to be transferred is stored.+ *+ * \return \ref cardano_error_t indicating the success or failure of the operation. Returns \ref CARDANO_SUCCESS if the data was successfully retrieved, or an appropriate error code indicating the reason for failure.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_mir_to_stake_creds_cert_t* mir_cert = ...; // Assume this is initialized+ * size_t index = 0;+ * cardano_credential_t* credential = NULL;+ * uint64_t amount = 0;+ *+ * cardano_error_t result = cardano_mir_to_stake_creds_cert_get_key_value_at(mir_cert, index, &credential, &amount);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Credential at index %zu will receive %llu ADA.\n", index, amount);+ *   // Further processing...+ *+ *   // Don't forget to free the credential+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   // Handle the error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_mir_to_stake_creds_cert_get_key_value_at(+  cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert,+  size_t                             index,+  cardano_credential_t**             credential,+  uint64_t*                          amount);++/**+ * \brief Decrements the reference count of a cardano_mir_to_stake_creds_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_mir_to_stake_creds_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the mir_to_stake_creds_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] mir_to_stake_creds_cert A pointer to the pointer of the mir_to_stake_creds_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert = cardano_mir_to_stake_creds_cert_new(major, minor);+ *+ * // Perform operations with the mir_to_stake_creds_cert...+ *+ * cardano_mir_to_stake_creds_cert_unref(&mir_to_stake_creds_cert);+ * // At this point, mir_to_stake_creds_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_mir_to_stake_creds_cert_unref, the pointer to the \ref cardano_mir_to_stake_creds_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_mir_to_stake_creds_cert_unref(cardano_mir_to_stake_creds_cert_t** mir_to_stake_creds_cert);++/**+ * \brief Increases the reference count of the cardano_mir_to_stake_creds_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_mir_to_stake_creds_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_mir_to_stake_creds_cert_unref.+ *+ * \param mir_to_stake_creds_cert A pointer to the cardano_mir_to_stake_creds_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming mir_to_stake_creds_cert is a previously created mir_to_stake_creds_cert object+ *+ * cardano_mir_to_stake_creds_cert_ref(mir_to_stake_creds_cert);+ *+ * // Now mir_to_stake_creds_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_mir_to_stake_creds_cert_ref there is a corresponding+ * call to \ref cardano_mir_to_stake_creds_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_mir_to_stake_creds_cert_ref(cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert);++/**+ * \brief Retrieves the current reference count of the cardano_mir_to_stake_creds_cert_t object.+ *+ * This function returns the number of active references to an cardano_mir_to_stake_creds_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_mir_to_stake_creds_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param mir_to_stake_creds_cert A pointer to the cardano_mir_to_stake_creds_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_mir_to_stake_creds_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_mir_to_stake_creds_cert_ref call is matched with a+ * \ref cardano_mir_to_stake_creds_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming mir_to_stake_creds_cert is a previously created mir_to_stake_creds_cert object+ *+ * size_t ref_count = cardano_mir_to_stake_creds_cert_refcount(mir_to_stake_creds_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_mir_to_stake_creds_cert_refcount(const cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert);++/**+ * \brief Sets the last error message for a given cardano_mir_to_stake_creds_cert_t object.+ *+ * Records an error message in the mir_to_stake_creds_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] mir_to_stake_creds_cert A pointer to the \ref cardano_mir_to_stake_creds_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the mir_to_stake_creds_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_mir_to_stake_creds_cert_set_last_error(+  cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert,+  const char*                        message);++/**+ * \brief Retrieves the last error message recorded for a specific mir_to_stake_creds_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_mir_to_stake_creds_cert_set_last_error for the given+ * mir_to_stake_creds_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] mir_to_stake_creds_cert A pointer to the \ref cardano_mir_to_stake_creds_cert_t instance whose last error+ *                   message is to be retrieved. If the mir_to_stake_creds_cert is NULL, the function+ *                   returns a generic error message indicating the null mir_to_stake_creds_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified mir_to_stake_creds_cert. If the mir_to_stake_creds_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_mir_to_stake_creds_cert_set_last_error for the same mir_to_stake_creds_cert, or until+ *       the mir_to_stake_creds_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_mir_to_stake_creds_cert_get_last_error(+  const cardano_mir_to_stake_creds_cert_t* mir_to_stake_creds_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_mir_to_stake_creds_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_mir_to_stake_creds_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_mir_to_stake_creds_cert_deep_clone(const cardano_mir_to_stake_creds_cert_t* source, cardano_mir_to_stake_creds_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_MIR_TO_STAKE_CREDS_CERT_H
+ vendor/include/cardano/certs/pool_registration_cert.h view
@@ -0,0 +1,413 @@+/**+ * \file pool_registration_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef POOL_REGISTRATION_CERT_H+#define POOL_REGISTRATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/pool_params/pool_params.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used to register a new stake pool. It includes various details+ * about the pool such as the pledge, costs, margin, reward account, and the pool's owners and relays.+ */+typedef struct cardano_pool_registration_cert_t cardano_pool_registration_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new pool registration certificate.+ *+ * This function allocates and initializes a new \ref cardano_pool_registration_cert_t object based on the provided pool parameters.+ * A pool registration certificate is used in the Cardano network to register a new stake pool.+ *+ * \param[in] params A pointer to an initialized \ref cardano_pool_params_t object containing the parameters of the pool being registered.+ * \param[out] cardano_pool_registration_cert On successful execution, this will point to a newly created \ref cardano_pool_registration_cert_t object.+ *                                            The caller is responsible for managing the lifecycle of this object using \ref cardano_pool_registration_cert_unref+ *                                            when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the pool registration certificate was+ *         successfully created, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_params_t* params = ...; // Assume params is already initialized+ * cardano_pool_registration_cert_t* registration_cert = NULL;+ *+ * cardano_error_t result = cardano_pool_registration_cert_new(params, &registration_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The pool registration certificate can now be used for pool registration+ *   // Remember to free the certificate when done+ *   cardano_pool_registration_cert_unref(&registration_cert);+ * }+ * else+ * {+ *   printf("Failed to create pool registration certificate: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_pool_registration_cert_new(+  cardano_pool_params_t*             params,+  cardano_pool_registration_cert_t** cardano_pool_registration_cert);++/**+ * \brief Creates a \ref cardano_pool_registration_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_pool_registration_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a pool_registration_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] pool_registration_cert A pointer to a pointer of \ref cardano_pool_registration_cert_t that will be set to the address+ *                        of the newly created pool_registration_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_pool_registration_cert_t object by calling+ *       \ref cardano_pool_registration_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_pool_registration_cert_t* pool_registration_cert = NULL;+ *+ * cardano_error_t result = cardano_pool_registration_cert_from_cbor(reader, &pool_registration_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the pool_registration_cert+ *+ *   // Once done, ensure to clean up and release the pool_registration_cert+ *   cardano_pool_registration_cert_unref(&pool_registration_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode pool_registration_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_pool_registration_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_pool_registration_cert_t** pool_registration_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_pool_registration_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] pool_registration_cert A constant pointer to the \ref cardano_pool_registration_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p pool_registration_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_registration_cert_t* pool_registration_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_pool_registration_cert_to_cbor(pool_registration_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_pool_registration_cert_unref(&pool_registration_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pool_registration_cert_to_cbor(+  const cardano_pool_registration_cert_t* pool_registration_cert,+  cardano_cbor_writer_t*                  writer);++/**+ * \brief Serializes a pool registration certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "pool_params".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_pool_registration_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_pool_registration_cert_to_cip116_json(+  const cardano_pool_registration_cert_t* cert,+  cardano_json_writer_t*                  writer);++/**+ * \brief Retrieves the pool parameters from a pool registration certificate.+ *+ * This function extracts the pool parameters from the specified \ref cardano_pool_registration_cert_t object.+ * These parameters define the configurations of the stake pool being registered.+ *+ * \param[in] cert A pointer to an initialized \ref cardano_pool_registration_cert_t object from which the pool parameters are to be retrieved.+ * \param[out] params On successful execution, this will point to the \ref cardano_pool_params_t object associated with the pool registration certificate.+ *                    This output provides a reference to the pool parameters, which the caller must manage using \ref cardano_pool_params_unref when no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the pool parameters were successfully retrieved,+ *         or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_registration_cert_t* registration_cert = ...; // Assume registration_cert is already initialized+ * cardano_pool_params_t* params = NULL;+ *+ * cardano_error_t result = cardano_pool_registration_cert_get_params(registration_cert, &params);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Process the pool parameters+ *   // Remember to free the params when done+ *   cardano_pool_params_unref(&params);+ * }+ * else+ * {+ *   printf("Failed to retrieve pool parameters: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pool_registration_cert_get_params(+  cardano_pool_registration_cert_t* cert,+  cardano_pool_params_t**           params);++/**+ * \brief Sets the parameters for a pool registration certificate.+ *+ * This function sets the pool parameters for an existing pool registration certificate. It updates the certificate+ * to use the provided pool parameters.+ *+ * \param[in] cert A pointer to an initialized cardano_pool_registration_cert_t object representing the pool registration certificate.+ * \param[in] params A pointer to an initialized cardano_pool_params_t object representing the pool parameters to set.+ *+ * \return cardano_error_t indicating the outcome of the operation. Returns CARDANO_SUCCESS if the parameters were successfully set.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_registration_cert_t* cert = ...; // Assume initialized+ * cardano_pool_params_t* params = ...; // Assume initialized+ * cardano_error_t result = cardano_pool_registration_cert_set_params(cert, params);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The pool registration certificate now has the updated parameters+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pool_registration_cert_set_params(+  cardano_pool_registration_cert_t* cert,+  cardano_pool_params_t*            params);++/**+ * \brief Decrements the reference count of a cardano_pool_registration_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_pool_registration_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the pool_registration_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] pool_registration_cert A pointer to the pointer of the pool_registration_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_registration_cert_t* pool_registration_cert = cardano_pool_registration_cert_new(major, minor);+ *+ * // Perform operations with the pool_registration_cert...+ *+ * cardano_pool_registration_cert_unref(&pool_registration_cert);+ * // At this point, pool_registration_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_pool_registration_cert_unref, the pointer to the \ref cardano_pool_registration_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_pool_registration_cert_unref(cardano_pool_registration_cert_t** pool_registration_cert);++/**+ * \brief Increases the reference count of the cardano_pool_registration_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_pool_registration_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_pool_registration_cert_unref.+ *+ * \param pool_registration_cert A pointer to the cardano_pool_registration_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming pool_registration_cert is a previously created pool_registration_cert object+ *+ * cardano_pool_registration_cert_ref(pool_registration_cert);+ *+ * // Now pool_registration_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_pool_registration_cert_ref there is a corresponding+ * call to \ref cardano_pool_registration_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_pool_registration_cert_ref(cardano_pool_registration_cert_t* pool_registration_cert);++/**+ * \brief Retrieves the current reference count of the cardano_pool_registration_cert_t object.+ *+ * This function returns the number of active references to an cardano_pool_registration_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_pool_registration_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param pool_registration_cert A pointer to the cardano_pool_registration_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_pool_registration_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_pool_registration_cert_ref call is matched with a+ * \ref cardano_pool_registration_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming pool_registration_cert is a previously created pool_registration_cert object+ *+ * size_t ref_count = cardano_pool_registration_cert_refcount(pool_registration_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_pool_registration_cert_refcount(const cardano_pool_registration_cert_t* pool_registration_cert);++/**+ * \brief Sets the last error message for a given cardano_pool_registration_cert_t object.+ *+ * Records an error message in the pool_registration_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] pool_registration_cert A pointer to the \ref cardano_pool_registration_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the pool_registration_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_pool_registration_cert_set_last_error(+  cardano_pool_registration_cert_t* pool_registration_cert,+  const char*                       message);++/**+ * \brief Retrieves the last error message recorded for a specific pool_registration_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_pool_registration_cert_set_last_error for the given+ * pool_registration_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] pool_registration_cert A pointer to the \ref cardano_pool_registration_cert_t instance whose last error+ *                   message is to be retrieved. If the pool_registration_cert is NULL, the function+ *                   returns a generic error message indicating the null pool_registration_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified pool_registration_cert. If the pool_registration_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_pool_registration_cert_set_last_error for the same pool_registration_cert, or until+ *       the pool_registration_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_pool_registration_cert_get_last_error(+  const cardano_pool_registration_cert_t* pool_registration_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_pool_registration_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_pool_registration_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_pool_registration_cert_deep_clone(const cardano_pool_registration_cert_t* source, cardano_pool_registration_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // POOL_REGISTRATION_CERT_H
+ vendor/include/cardano/certs/pool_retirement_cert.h view
@@ -0,0 +1,475 @@+/**+ * \file pool_retirement_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef POOL_RETIREMENT_CERT_H+#define POOL_RETIREMENT_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used to retire a stake pool. It includes an epoch number indicating when the pool will be retired.+ */+typedef struct cardano_pool_retirement_cert_t cardano_pool_retirement_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new pool retirement certificate.+ *+ * This function allocates and initializes a new \ref cardano_pool_retirement_cert_t object, which signifies+ * the intent to retire a stake pool at a specified epoch. The retirement certificate includes the stake pool's+ * operator key hash and the epoch at which the pool is scheduled to retire.+ *+ * \param[in] pool_key_hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the hash of the pool's operator key.+ * \param[in] epoch The epoch number at which the pool is scheduled to retire.+ * \param[out] pool_retirement_cert On successful execution, this will point to the newly created \ref cardano_pool_retirement_cert_t object.+ *                                           The caller is responsible for releasing this resource using \ref cardano_pool_retirement_cert_unref when it+ *                                           is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the pool retirement certificate was+ *         successfully created, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_blake2b_hash_t* pool_key_hash = ...;  // Assume pool_key_hash is already initialized+ * uint64_t epoch = 250;  // Specify the epoch for retirement+ * cardano_pool_retirement_cert_t* retirement_cert = NULL;+ *+ * cardano_error_t result = cardano_pool_retirement_cert_new(pool_key_hash, epoch, &retirement_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The retirement certificate can now be used for scheduling pool retirement+ *   // Remember to free the retirement certificate when done+ *   cardano_pool_retirement_cert_unref(&retirement_cert);+ * }+ * else+ * {+ *   printf("Failed to create pool retirement certificate: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_pool_retirement_cert_new(+  cardano_blake2b_hash_t*          pool_key_hash,+  uint64_t                         epoch,+  cardano_pool_retirement_cert_t** pool_retirement_cert);++/**+ * \brief Creates a \ref cardano_pool_retirement_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_pool_retirement_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a pool_retirement_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] pool_retirement_cert A pointer to a pointer of \ref cardano_pool_retirement_cert_t that will be set to the address+ *                        of the newly created pool_retirement_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_pool_retirement_cert_t object by calling+ *       \ref cardano_pool_retirement_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_pool_retirement_cert_t* pool_retirement_cert = NULL;+ *+ * cardano_error_t result = cardano_pool_retirement_cert_from_cbor(reader, &pool_retirement_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the pool_retirement_cert+ *+ *   // Once done, ensure to clean up and release the pool_retirement_cert+ *   cardano_pool_retirement_cert_unref(&pool_retirement_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode pool_retirement_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_pool_retirement_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_pool_retirement_cert_t** pool_retirement_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_pool_retirement_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] pool_retirement_cert A constant pointer to the \ref cardano_pool_retirement_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p pool_retirement_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_retirement_cert_t* pool_retirement_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_pool_retirement_cert_to_cbor(pool_retirement_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_pool_retirement_cert_unref(&pool_retirement_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_pool_retirement_cert_to_cbor(+  const cardano_pool_retirement_cert_t* pool_retirement_cert,+  cardano_cbor_writer_t*                writer);++/**+ * \brief Serializes a pool retirement certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "pool_keyhash", "epoch".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_pool_retirement_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p cert or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_pool_retirement_cert_to_cip116_json(+  const cardano_pool_retirement_cert_t* cert,+  cardano_json_writer_t*                writer);++/**+ * \brief Retrieves the pool key hash from a pool retirement certificate.+ *+ * This function extracts the pool key hash from the specified \ref cardano_pool_retirement_cert_t object.+ * The pool key hash is the unique identifier for the stake pool.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_pool_retirement_cert_t object.+ *+ * \return A pointer to the \ref cardano_blake2b_hash_t object containing the pool key hash. If the certificate+ *         is NULL or if the pool key hash is not set, this function returns NULL. This function returns a reference+ *         to the internal hash object, which should not be modified or freed by the caller. Use \ref cardano_blake2b_hash_unref+ *         to safely reduce the reference count when the hash is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_pool_retirement_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* pool_key_hash = cardano_pool_retirement_cert_get_pool_key_hash(certificate);+ *+ * if (pool_key_hash != NULL)+ * {+ *   // Process the pool key hash+ *   // No need to unref this specific reference since it is managed internally+ * }+ * else+ * {+ *   printf("Failed to retrieve the pool key hash or certificate is not valid.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_pool_retirement_cert_get_pool_key_hash(cardano_pool_retirement_cert_t* certificate);++/**+ * \brief Sets the pool key hash for a pool retirement certificate.+ *+ * This function assigns a new pool key hash to a given \ref cardano_pool_retirement_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_pool_retirement_cert_t object to which the key hash will be set.+ * \param[in] hash A pointer to a constant \ref cardano_blake2b_hash_t object representing the new pool key hash.+ *                 This function increments the reference count of the hash object; it is the caller's responsibility to manage+ *                 the lifecycle of the hash and decrement the reference count when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the pool key hash was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_retirement_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* new_pool_key_hash = ...; // Assume new_pool_key_hash is already initialized+ *+ * cardano_error_t result = cardano_pool_retirement_cert_set_pool_key_hash(certificate, new_pool_key_hash);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Pool key hash set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the pool key hash.\n");+ * }+ *+ * // Remember to manage the reference count of new_pool_key_hash appropriately+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_pool_retirement_cert_set_pool_key_hash(cardano_pool_retirement_cert_t* certificate, cardano_blake2b_hash_t* hash);++/**+ * \brief Retrieves the retirement epoch for a pool retirement certificate.+ *+ * This function extracts the epoch number from a given \ref cardano_pool_retirement_cert_t object.+ * The epoch number specifies when the retirement of the stake pool will take effect on the Cardano blockchain.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_pool_retirement_cert_t object.+ *+ * \return The epoch number as a uint64_t at which the stake pool is scheduled to retire. If the certificate+ *         is NULL or does not have an epoch set, this function returns 0 as a default value, which should be+ *         handled appropriately by the caller.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_pool_retirement_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t retirement_epoch = cardano_pool_retirement_cert_get_epoch(certificate);+ *+ * printf("Stake pool scheduled to retire at epoch: %lu\n", retirement_epoch);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_pool_retirement_cert_get_epoch(const cardano_pool_retirement_cert_t* certificate);++/**+ * \brief Sets the retirement epoch for a pool retirement certificate.+ *+ * This function assigns a new retirement epoch to a given \ref cardano_pool_retirement_cert_t object.+ * The epoch number specifies when the retirement of the stake pool will take effect on the Cardano blockchain.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_pool_retirement_cert_t object where the retirement epoch will be set.+ * \param[in] epoch The epoch number at which the stake pool is scheduled to retire.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the epoch number was successfully set, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_retirement_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t retirement_epoch = 250; // Example epoch number for retirement+ *+ * cardano_error_t result = cardano_pool_retirement_cert_set_epoch(certificate, retirement_epoch);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Retirement epoch set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the retirement epoch.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_pool_retirement_cert_set_epoch(cardano_pool_retirement_cert_t* certificate, uint64_t epoch);++/**+ * \brief Decrements the reference count of a cardano_pool_retirement_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_pool_retirement_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the pool_retirement_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] pool_retirement_cert A pointer to the pointer of the pool_retirement_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_pool_retirement_cert_t* pool_retirement_cert = cardano_pool_retirement_cert_new(major, minor);+ *+ * // Perform operations with the pool_retirement_cert...+ *+ * cardano_pool_retirement_cert_unref(&pool_retirement_cert);+ * // At this point, pool_retirement_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_pool_retirement_cert_unref, the pointer to the \ref cardano_pool_retirement_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_pool_retirement_cert_unref(cardano_pool_retirement_cert_t** pool_retirement_cert);++/**+ * \brief Increases the reference count of the cardano_pool_retirement_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_pool_retirement_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_pool_retirement_cert_unref.+ *+ * \param pool_retirement_cert A pointer to the cardano_pool_retirement_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming pool_retirement_cert is a previously created pool_retirement_cert object+ *+ * cardano_pool_retirement_cert_ref(pool_retirement_cert);+ *+ * // Now pool_retirement_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_pool_retirement_cert_ref there is a corresponding+ * call to \ref cardano_pool_retirement_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_pool_retirement_cert_ref(cardano_pool_retirement_cert_t* pool_retirement_cert);++/**+ * \brief Retrieves the current reference count of the cardano_pool_retirement_cert_t object.+ *+ * This function returns the number of active references to an cardano_pool_retirement_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_pool_retirement_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param pool_retirement_cert A pointer to the cardano_pool_retirement_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_pool_retirement_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_pool_retirement_cert_ref call is matched with a+ * \ref cardano_pool_retirement_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming pool_retirement_cert is a previously created pool_retirement_cert object+ *+ * size_t ref_count = cardano_pool_retirement_cert_refcount(pool_retirement_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_pool_retirement_cert_refcount(const cardano_pool_retirement_cert_t* pool_retirement_cert);++/**+ * \brief Sets the last error message for a given cardano_pool_retirement_cert_t object.+ *+ * Records an error message in the pool_retirement_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] pool_retirement_cert A pointer to the \ref cardano_pool_retirement_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the pool_retirement_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_pool_retirement_cert_set_last_error(+  cardano_pool_retirement_cert_t* pool_retirement_cert,+  const char*                     message);++/**+ * \brief Retrieves the last error message recorded for a specific pool_retirement_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_pool_retirement_cert_set_last_error for the given+ * pool_retirement_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] pool_retirement_cert A pointer to the \ref cardano_pool_retirement_cert_t instance whose last error+ *                   message is to be retrieved. If the pool_retirement_cert is NULL, the function+ *                   returns a generic error message indicating the null pool_retirement_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified pool_retirement_cert. If the pool_retirement_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_pool_retirement_cert_set_last_error for the same pool_retirement_cert, or until+ *       the pool_retirement_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_pool_retirement_cert_get_last_error(+  const cardano_pool_retirement_cert_t* pool_retirement_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_pool_retirement_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_pool_retirement_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_pool_retirement_cert_deep_clone(const cardano_pool_retirement_cert_t* source, cardano_pool_retirement_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // POOL_RETIREMENT_CERT_H
+ vendor/include/cardano/certs/register_drep_cert.h view
@@ -0,0 +1,550 @@+/**+ * \file register_drep_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef REGISTER_DREP_CERT_H+#define REGISTER_DREP_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/anchor.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief In Voltaire, existing stake credentials will be able to delegate their stake to DReps for voting+ * purposes, in addition to the current delegation to stake pools for block production.+ * DRep delegation will mimic the existing stake delegation mechanisms (via on-chain certificates).+ *+ * This certificate register a stake key as a DRep.+ */+typedef struct cardano_register_drep_cert_t cardano_register_drep_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new DRep registration certificate.+ *+ * This function allocates and initializes a \ref cardano_register_drep_cert_t object,+ * which represents a certificate for registering a DRep in the Cardano network.+ *+ * \param[in] drep_credential A pointer to an initialized \ref cardano_credential_t object representing+ *                            the credential of the decentralized representative.+ * \param[in] deposit The deposit amount required for registration.+ * \param[in] anchor An instance of \ref cardano_anchor_t representing the anchor of the metadata linked to this DRep. This is optional.+ * \param[out] register_drep_cert On successful execution, this will point to a newly created \ref cardano_register_drep_cert_t object.+ *                                The caller is responsible for releasing this resource using \ref cardano_register_drep_cert_unref when it+ *                                is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the DRep registration certificate was successfully created, or an appropriate error code indicating+ *         the failure reason (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* drep_credential = ...; // Assume drep_credential is already initialized+ * uint64_t deposit = 5000000; // Example deposit amount in lovelace+ * cardano_anchor_t anchor = ...; // Assume anchor is initialized+ * cardano_register_drep_cert_t* register_drep_cert = NULL;+ *+ * cardano_error_t result = cardano_register_drep_cert_new(drep_credential, deposit, anchor, &register_drep_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The DRep registration certificate can now be used+ *   // Remember to free the register_drep_cert when done+ *   cardano_register_drep_cert_unref(&register_drep_cert);+ * }+ * else+ * {+ *   printf("Failed to create DRep registration certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_credential_unref(&drep_credential); // Cleanup the drep_credential+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_register_drep_cert_new(+  cardano_credential_t*          drep_credential,+  uint64_t                       deposit,+  cardano_anchor_t*              anchor,+  cardano_register_drep_cert_t** register_drep_cert);++/**+ * \brief Creates a \ref cardano_register_drep_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_register_drep_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a register_drep_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] register_drep_cert A pointer to a pointer of \ref cardano_register_drep_cert_t that will be set to the address+ *                        of the newly created register_drep_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_register_drep_cert_t object by calling+ *       \ref cardano_register_drep_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_register_drep_cert_t* register_drep_cert = NULL;+ *+ * cardano_error_t result = cardano_register_drep_cert_from_cbor(reader, &register_drep_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the register_drep_cert+ *+ *   // Once done, ensure to clean up and release the register_drep_cert+ *   cardano_register_drep_cert_unref(&register_drep_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode register_drep_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_register_drep_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_register_drep_cert_t** register_drep_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_register_drep_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] register_drep_cert A constant pointer to the \ref cardano_register_drep_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p register_drep_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_register_drep_cert_t* register_drep_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_register_drep_cert_to_cbor(register_drep_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_register_drep_cert_unref(&register_drep_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_register_drep_cert_to_cbor(+  const cardano_register_drep_cert_t* register_drep_cert,+  cardano_cbor_writer_t*              writer);++/**+ * \brief Serializes a register DRep certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "drep_credential", "coin", "anchor".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_register_drep_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                 On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED  If memory allocation fails.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_register_drep_cert_to_cip116_json(+  const cardano_register_drep_cert_t* cert,+  cardano_json_writer_t*              writer);++/**+ * \brief Retrieves the DRep credential from a DRep registration certificate.+ *+ * This function extracts the decentralized representative's credential from the specified+ * \ref cardano_register_drep_cert_t object. This credential is used to identify the DRep+ * within the Cardano network.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_register_drep_cert_t object.+ *+ * \return A pointer to the \ref cardano_credential_t object containing the DRep credential. If the certificate+ *         is NULL or does not contain a DRep credential, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_register_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_credential_t* drep_credential = cardano_register_drep_cert_get_credential(certificate);+ *+ * if (drep_credential != NULL)+ * {+ *   // Process the DRep credential+ *   // Note: The credential does not need to be freed; it is managed within the certificate object+ * }+ * else+ * {+ *   printf("No DRep credential is set for this certificate.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_register_drep_cert_get_credential(cardano_register_drep_cert_t* certificate);++/**+ * \brief Sets the DRep credential for a DRep registration certificate.+ *+ * This function updates the DRep credential in a \ref cardano_register_drep_cert_t object with the provided+ * \ref cardano_credential_t. The DRep credential identifies the decentralized representative within the Cardano network.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_register_drep_cert_t object to which the credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the new DRep credential.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the DRep credential+ *         was successfully updated, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if+ *         any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_register_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_register_drep_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("DRep credential updated successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to update DRep credential.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_register_drep_cert_set_credential(cardano_register_drep_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the deposit amount from a DRep registration certificate.+ *+ * This function fetches the deposit amount specified in a \ref cardano_register_drep_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_register_drep_cert_t object.+ *+ * \return The deposit amount in lovelace (1 ADA = 1,000,000 lovelace). If the certificate is NULL, this function will+ *         return 0.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_register_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = cardano_register_drep_cert_get_deposit(certificate);+ *+ * if (deposit > 0)+ * {+ *   printf("Deposit amount: %lu lovelace\n", deposit);+ * }+ * else+ * {+ *   printf("Failed to retrieve deposit amount.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_register_drep_cert_get_deposit(const cardano_register_drep_cert_t* certificate);++/**+ * \brief Sets the deposit amount in a DRep registration certificate.+ *+ * This function assigns a new deposit amount to a \ref cardano_register_drep_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_register_drep_cert_t object which will have its deposit updated.+ * \param[in] deposit The deposit amount in lovelace (1 ADA = 1,000,000 lovelace) to be set in the certificate.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the deposit was+ *         successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if the+ *         certificate pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_register_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = 1000000; // Set deposit to 1 ADA+ *+ * cardano_error_t result = cardano_register_drep_cert_set_deposit(certificate, deposit);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Deposit amount set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the deposit amount.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_register_drep_cert_set_deposit(cardano_register_drep_cert_t* certificate, uint64_t deposit);++/**+ * \brief Retrieves the anchor from a DRep registration certificate.+ *+ * This function extracts the anchor from the specified \ref cardano_register_drep_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_register_drep_cert_t object.+ *+ * \return A pointer to the \ref cardano_anchor_t object containing the anchor. If the certificate is NULL or+ *         if the anchor is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_register_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_anchor_t* anchor = cardano_register_drep_cert_get_anchor(certificate);+ *+ * if (anchor != NULL)+ * {+ *   // Process the anchor+ *   printf("Anchor retrieved successfully.\n");+ * }+ * else+ * {+ *   printf("No anchor set for this certificate.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_anchor_t* cardano_register_drep_cert_get_anchor(cardano_register_drep_cert_t* certificate);++/**+ * \brief Sets the anchor for a DRep registration certificate.+ *+ * This function updates the anchor in the specified \ref cardano_register_drep_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_register_drep_cert_t object+ *                        which will receive the updated anchor.+ * \param[in] anchor A pointer to an initialized \ref cardano_anchor_t object that represents+ *                   the new anchor. This function copies the anchor into the certificate.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the anchor was successfully updated, or an appropriate error code indicating the+ *         failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_register_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_anchor_t* anchor = ...; // Assume anchor is already initialized+ *+ * cardano_error_t result = cardano_register_drep_cert_set_anchor(certificate, anchor);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Anchor set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the anchor.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_register_drep_cert_set_anchor(cardano_register_drep_cert_t* certificate, cardano_anchor_t* anchor);++/**+ * \brief Decrements the reference count of a cardano_register_drep_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_register_drep_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the register_drep_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] register_drep_cert A pointer to the pointer of the register_drep_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_register_drep_cert_t* register_drep_cert = cardano_register_drep_cert_new(major, minor);+ *+ * // Perform operations with the register_drep_cert...+ *+ * cardano_register_drep_cert_unref(&register_drep_cert);+ * // At this point, register_drep_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_register_drep_cert_unref, the pointer to the \ref cardano_register_drep_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_register_drep_cert_unref(cardano_register_drep_cert_t** register_drep_cert);++/**+ * \brief Increases the reference count of the cardano_register_drep_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_register_drep_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_register_drep_cert_unref.+ *+ * \param register_drep_cert A pointer to the cardano_register_drep_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming register_drep_cert is a previously created register_drep_cert object+ *+ * cardano_register_drep_cert_ref(register_drep_cert);+ *+ * // Now register_drep_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_register_drep_cert_ref there is a corresponding+ * call to \ref cardano_register_drep_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_register_drep_cert_ref(cardano_register_drep_cert_t* register_drep_cert);++/**+ * \brief Retrieves the current reference count of the cardano_register_drep_cert_t object.+ *+ * This function returns the number of active references to an cardano_register_drep_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_register_drep_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param register_drep_cert A pointer to the cardano_register_drep_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_register_drep_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_register_drep_cert_ref call is matched with a+ * \ref cardano_register_drep_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming register_drep_cert is a previously created register_drep_cert object+ *+ * size_t ref_count = cardano_register_drep_cert_refcount(register_drep_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_register_drep_cert_refcount(const cardano_register_drep_cert_t* register_drep_cert);++/**+ * \brief Sets the last error message for a given cardano_register_drep_cert_t object.+ *+ * Records an error message in the register_drep_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] register_drep_cert A pointer to the \ref cardano_register_drep_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the register_drep_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_register_drep_cert_set_last_error(+  cardano_register_drep_cert_t* register_drep_cert,+  const char*                   message);++/**+ * \brief Retrieves the last error message recorded for a specific register_drep_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_register_drep_cert_set_last_error for the given+ * register_drep_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] register_drep_cert A pointer to the \ref cardano_register_drep_cert_t instance whose last error+ *                   message is to be retrieved. If the register_drep_cert is NULL, the function+ *                   returns a generic error message indicating the null register_drep_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified register_drep_cert. If the register_drep_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_register_drep_cert_set_last_error for the same register_drep_cert, or until+ *       the register_drep_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_register_drep_cert_get_last_error(+  const cardano_register_drep_cert_t* register_drep_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_register_drep_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_register_drep_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_register_drep_cert_deep_clone(const cardano_register_drep_cert_t* source, cardano_register_drep_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // REGISTER_DREP_CERT_H
+ vendor/include/cardano/certs/registration_cert.h view
@@ -0,0 +1,485 @@+/**+ * \file registration_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef REGISTRATION_CERT_H+#define REGISTRATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used when an individual wants to register as a stakeholder.+ * It allows the holder to participate in the staking process by delegating their+ * stake or creating a stake pool.+ *+ * This certificate also provides the ability to specify the deposit amount.+ *+ * Deposit must match the expected deposit amount specified by `ppKeyDepositL` in+ * the protocol parameters.+ *+ * \remark Replaces the deprecated `StakeRegistration` in after Conway era.+ */+typedef struct cardano_registration_cert_t cardano_registration_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new registration certificate.+ *+ * This function allocates and initializes a new instance of \ref cardano_registration_cert_t,+ * which represents a registration certificate in the Cardano blockchain. This certificate is used+ * to register a stake credential, along with specifying the required deposit.+ *+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stake credential.+ * \param[in] deposit The amount of the deposit that must match the expected deposit amount specified by the+ *                    protocol parameters (ppKeyDepositL).+ * \param[out] registration_cert On successful initialization, this will point to a newly created+ *                               \ref cardano_registration_cert_t object. The caller is responsible for managing+ *                               the lifecycle of this object. Specifically, once the registration certificate+ *                               is no longer needed, the caller must release it by calling \ref cardano_registration_cert_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the registration certificate was successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ * uint64_t deposit = 5000000; // Deposit amount in lovelace+ *+ * cardano_registration_cert_t* registration_cert = NULL;+ * cardano_error_t result = cardano_registration_cert_new(credential, deposit, &registration_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The registration certificate is now ready to be used+ *   // Remember to free the certificate when done+ *   cardano_registration_cert_unref(&registration_cert);+ * }+ * else+ * {+ *   printf("Failed to create registration certificate: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_registration_cert_new(+  cardano_credential_t*         credential,+  uint64_t                      deposit,+  cardano_registration_cert_t** registration_cert);++/**+ * \brief Creates a \ref cardano_registration_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_registration_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a registration_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] registration_cert A pointer to a pointer of \ref cardano_registration_cert_t that will be set to the address+ *                        of the newly created registration_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_registration_cert_t object by calling+ *       \ref cardano_registration_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_registration_cert_t* registration_cert = NULL;+ *+ * cardano_error_t result = cardano_registration_cert_from_cbor(reader, &registration_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the registration_cert+ *+ *   // Once done, ensure to clean up and release the registration_cert+ *   cardano_registration_cert_unref(&registration_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode registration_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_registration_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_registration_cert_t** registration_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_registration_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] registration_cert A constant pointer to the \ref cardano_registration_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p registration_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_registration_cert_t* registration_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_registration_cert_to_cbor(registration_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_registration_cert_unref(&registration_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_registration_cert_to_cbor(+  const cardano_registration_cert_t* registration_cert,+  cardano_cbor_writer_t*             writer);++/**+ * \brief Serializes a registration certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "credential", "coin".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_registration_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_registration_cert_to_cip116_json(+  const cardano_registration_cert_t* cert,+  cardano_json_writer_t*             writer);++/**+ * \brief Retrieves the stake credential from a registration certificate.+ *+ * This function extracts the stake credential associated with a given \ref cardano_registration_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_registration_cert_t object from which+ *                        the stake credential will be retrieved.+ *+ * \return A pointer to the \ref cardano_credential_t object containing the stake credential. If the input+ *         certificate is NULL, or if the stake credential is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_registration_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_credential_t* credential = cardano_registration_cert_get_stake_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the stake credential+ * }+ * else+ * {+ *   printf("No stake credential is set in the certificate.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_registration_cert_get_stake_credential(cardano_registration_cert_t* certificate);++/**+ * \brief Sets the stake credential for a registration certificate.+ *+ * This function assigns a stake credential to a given \ref cardano_registration_cert_t object.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_registration_cert_t object to which the stake credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stake credential.+ *                        This function increments the reference count of the credential, so it remains valid even after the caller releases its own reference.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the stake credential was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_registration_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_registration_cert_set_stake_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The stake credential is now set for the certificate+ * }+ * else+ * {+ *   printf("Failed to set the stake credential: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up: Release references when they are no longer needed+ * cardano_credential_unref(&credential);+ * \endcode+ *+ * \note The caller must manage the lifecycle of both the certificate and the newly referenced credential.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_registration_cert_set_stake_credential(cardano_registration_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the deposit amount from a registration certificate.+ *+ * This function extracts the deposit amount specified in a \ref cardano_registration_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_registration_cert_t object.+ *+ * \return The deposit amount associated with the registration certificate. If the certificate pointer is NULL,+ *         the behavior is undefined, and it may cause a crash. It is the caller's responsibility to ensure+ *         that the certificate is properly initialized.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_registration_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = cardano_registration_cert_get_deposit(certificate);+ *+ * printf("The registration deposit is: %llu ADA\n", deposit);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_registration_cert_get_deposit(const cardano_registration_cert_t* certificate);++/**+ * \brief Sets the deposit amount for a registration certificate.+ *+ * This function updates the deposit amount in a \ref cardano_registration_cert_t object. The deposit is required when+ * registering a new stake credential and is specified by the protocol parameters.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_registration_cert_t object to which the deposit will be set.+ * \param[in] deposit The deposit amount to be set in lovelaces (1 ADA = 1,000,000 lovelaces).+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the deposit was+ *         successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the certificate pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_registration_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = 2000000; // Example deposit amount+ *+ * cardano_error_t result = cardano_registration_cert_set_deposit(certificate, deposit);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Deposit successfully set.\n");+ * }+ * else+ * {+ *   printf("Failed to set deposit.\n");+ * }+ * \endcode+ *+ * \note It is the caller's responsibility to ensure that the certificate is properly initialized before calling this function.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_registration_cert_set_deposit(cardano_registration_cert_t* certificate, uint64_t deposit);++/**+ * \brief Decrements the reference count of a cardano_registration_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_registration_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the registration_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] registration_cert A pointer to the pointer of the registration_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_registration_cert_t* registration_cert = cardano_registration_cert_new(major, minor);+ *+ * // Perform operations with the registration_cert...+ *+ * cardano_registration_cert_unref(&registration_cert);+ * // At this point, registration_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_registration_cert_unref, the pointer to the \ref cardano_registration_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_registration_cert_unref(cardano_registration_cert_t** registration_cert);++/**+ * \brief Increases the reference count of the cardano_registration_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_registration_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_registration_cert_unref.+ *+ * \param registration_cert A pointer to the cardano_registration_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming registration_cert is a previously created registration_cert object+ *+ * cardano_registration_cert_ref(registration_cert);+ *+ * // Now registration_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_registration_cert_ref there is a corresponding+ * call to \ref cardano_registration_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_registration_cert_ref(cardano_registration_cert_t* registration_cert);++/**+ * \brief Retrieves the current reference count of the cardano_registration_cert_t object.+ *+ * This function returns the number of active references to an cardano_registration_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_registration_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param registration_cert A pointer to the cardano_registration_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_registration_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_registration_cert_ref call is matched with a+ * \ref cardano_registration_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming registration_cert is a previously created registration_cert object+ *+ * size_t ref_count = cardano_registration_cert_refcount(registration_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_registration_cert_refcount(const cardano_registration_cert_t* registration_cert);++/**+ * \brief Sets the last error message for a given cardano_registration_cert_t object.+ *+ * Records an error message in the registration_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] registration_cert A pointer to the \ref cardano_registration_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the registration_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_registration_cert_set_last_error(+  cardano_registration_cert_t* registration_cert,+  const char*                  message);++/**+ * \brief Retrieves the last error message recorded for a specific registration_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_registration_cert_set_last_error for the given+ * registration_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] registration_cert A pointer to the \ref cardano_registration_cert_t instance whose last error+ *                   message is to be retrieved. If the registration_cert is NULL, the function+ *                   returns a generic error message indicating the null registration_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified registration_cert. If the registration_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_registration_cert_set_last_error for the same registration_cert, or until+ *       the registration_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_registration_cert_get_last_error(+  const cardano_registration_cert_t* registration_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_registration_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_registration_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_registration_cert_deep_clone(const cardano_registration_cert_t* source, cardano_registration_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // REGISTRATION_CERT_H
+ vendor/include/cardano/certs/resign_committee_cold_cert.h view
@@ -0,0 +1,484 @@+/**+ * \file resign_committee_cold_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef RESIGN_COMMITTEE_COLD_CERT_H+#define RESIGN_COMMITTEE_COLD_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/anchor.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used then a committee member wants to resign early (will be marked on-chain as an expired member).+ */+typedef struct cardano_resign_committee_cold_cert_t cardano_resign_committee_cold_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new resignation certificate for a committee cold key.+ *+ * This function allocates and initializes a new instance of \ref cardano_resign_committee_cold_cert_t.+ *+ * \param[in] committee_cold_cred A pointer to an initialized \ref cardano_credential_t object representing the committee's cold credential.+ * \param[in] anchor A pointer to an initialized \ref cardano_anchor_t object associated with the resignation.+ * \param[out] resign_committee_cold_cert On successful execution, this will point to a newly created \ref cardano_resign_committee_cold_cert_t object.+ *                                        The caller is responsible for managing the lifecycle of this object, including releasing it+ *                                        when it is no longer needed using the appropriate unref function.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* committee_cold_cred = ...; // Assume committee_cold_cred is already initialized+ * cardano_anchor_t* anchor = ...; // Assume anchor is already initialized+ * cardano_resign_committee_cold_cert_t* resign_committee_cold_cert = NULL;+ *+ * cardano_error_t result = cardano_resign_committee_cold_cert_new(committee_cold_cred, anchor, &resign_committee_cold_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The resign committee cold certificate can now be used for transaction signing or other purposes+ *   // Remember to free the certificate when done+ *   cardano_resign_committee_cold_cert_unref(&resign_committee_cold_cert);+ * }+ * else+ * {+ *   printf("Failed to create resign committee cold certificate: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_resign_committee_cold_cert_new(+  cardano_credential_t*                  committee_cold_cred,+  cardano_anchor_t*                      anchor,+  cardano_resign_committee_cold_cert_t** resign_committee_cold_cert);++/**+ * \brief Creates a \ref cardano_resign_committee_cold_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_resign_committee_cold_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a resign_committee_cold.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] resign_committee_cold A pointer to a pointer of \ref cardano_resign_committee_cold_cert_t that will be set to the address+ *                        of the newly created resign_committee_cold object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_resign_committee_cold_cert_t object by calling+ *       \ref cardano_resign_committee_cold_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_resign_committee_cold_cert_t* resign_committee_cold = NULL;+ *+ * cardano_error_t result = cardano_resign_committee_cold_cert_from_cbor(reader, &resign_committee_cold);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the resign_committee_cold+ *+ *   // Once done, ensure to clean up and release the resign_committee_cold+ *   cardano_resign_committee_cold_cert_unref(&resign_committee_cold);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode resign_committee_cold: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_resign_committee_cold_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_resign_committee_cold_cert_t** resign_committee_cold);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_resign_committee_cold_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] resign_committee_cold A constant pointer to the \ref cardano_resign_committee_cold_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p resign_committee_cold or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_resign_committee_cold_cert_t* resign_committee_cold = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_resign_committee_cold_cert_to_cbor(resign_committee_cold, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_resign_committee_cold_cert_unref(&resign_committee_cold);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_resign_committee_cold_cert_to_cbor(+  const cardano_resign_committee_cold_cert_t* resign_committee_cold,+  cardano_cbor_writer_t*                      writer);++/**+ * \brief Serializes a committee cold resignation certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "committee_cold_credential", "anchor".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_resign_committee_cold_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                 On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_resign_committee_cold_cert_to_cip116_json(+  const cardano_resign_committee_cold_cert_t* cert,+  cardano_json_writer_t*                      writer);++/**+ * \brief Retrieves the committee cold credential from a resignation certificate.+ *+ * This function extracts the committee's cold credential from a \ref cardano_resign_committee_cold_cert_t object.+ * The returned credential is a reference counted object, and the caller is responsible for releasing it+ * using \ref cardano_credential_unref when it is no longer needed.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_resign_committee_cold_cert_t object.+ *+ * \return A pointer to the \ref cardano_credential_t object containing the committee's cold credential.+ *         If the certificate is NULL or if the credential is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_resign_committee_cold_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = cardano_resign_committee_cold_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   cardano_credential_unref(&credential); // Remember to unref the credential when done+ * }+ * else+ * {+ *   printf("No credential is set for this certificate.\n");+ * }+ * \endcode+ *+ * \note This function increments the reference count of the returned credential. The caller must ensure to unref it to avoid memory leaks.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_resign_committee_cold_cert_get_credential(cardano_resign_committee_cold_cert_t* certificate);++/**+ * \brief Sets the committee cold credential in a resignation certificate.+ *+ * This function assigns a new committee cold credential to a given \ref cardano_resign_committee_cold_cert_t object.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_resign_committee_cold_cert_t object to which the credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the committee's cold credential.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the committee cold credential was+ *         successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the+ *         input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_resign_committee_cold_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_resign_committee_cold_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The credential is now set for the certificate+ * }+ * else+ * {+ *   printf("Failed to set the committee's cold credential.\n");+ * }+ * // Both objects need to be managed and eventually unreferenced by the caller+ * cardano_credential_unref(&credential);+ * cardano_resign_committee_cold_cert_unref(&certificate);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_resign_committee_cold_cert_set_credential(cardano_resign_committee_cold_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the anchor associated with a resignation committee cold certificate.+ *+ * This function returns the anchor used in a \ref cardano_resign_committee_cold_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_resign_committee_cold_cert_t object.+ *+ * \return A pointer to a \ref cardano_anchor_t object representing the anchor. If the certificate is NULL or does not have an anchor set,+ *         this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_resign_committee_cold_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_anchor_t* anchor = cardano_resign_committee_cold_cert_get_anchor(certificate);+ *+ * if (anchor != NULL)+ * {+ *   // Process the anchor information+ * }+ * else+ * {+ *   printf("No anchor is set for this certificate.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_anchor_t* cardano_resign_committee_cold_cert_get_anchor(cardano_resign_committee_cold_cert_t* certificate);++/**+ * \brief Sets the anchor for a resignation committee cold certificate.+ *+ * This function assigns a new anchor to a given \ref cardano_resign_committee_cold_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_resign_committee_cold_cert_t object to which the anchor will be set.+ * \param[in] anchor A pointer to an initialized \ref cardano_anchor_t object representing the new anchor. This function+ *                    increases the reference count on the anchor, and the certificate will maintain its own reference+ *                    to the anchor.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the anchor+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_resign_committee_cold_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_anchor_t* new_anchor = ...; // Assume new_anchor is already initialized+ *+ * cardano_error_t result = cardano_resign_committee_cold_cert_set_anchor(certificate, new_anchor);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Anchor set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the anchor.\n");+ * }+ *+ * // Both certificate and new_anchor need their own unref calls when no longer needed+ * \endcode+ *+ * \note This function increments the reference count of the anchor object passed to it. It is the caller's responsibility+ *       to manage the lifecycle of both the certificate and the anchor.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_resign_committee_cold_cert_set_anchor(cardano_resign_committee_cold_cert_t* certificate, cardano_anchor_t* anchor);++/**+ * \brief Decrements the reference count of a cardano_resign_committee_cold_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_resign_committee_cold_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the resign_committee_cold is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] resign_committee_cold A pointer to the pointer of the resign_committee_cold object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_resign_committee_cold_cert_t* resign_committee_cold = cardano_resign_committee_cold_cert_new(major, minor);+ *+ * // Perform operations with the resign_committee_cold...+ *+ * cardano_resign_committee_cold_cert_unref(&resign_committee_cold);+ * // At this point, resign_committee_cold is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_resign_committee_cold_cert_unref, the pointer to the \ref cardano_resign_committee_cold_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_resign_committee_cold_cert_unref(cardano_resign_committee_cold_cert_t** resign_committee_cold);++/**+ * \brief Increases the reference count of the cardano_resign_committee_cold_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_resign_committee_cold_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_resign_committee_cold_cert_unref.+ *+ * \param resign_committee_cold A pointer to the cardano_resign_committee_cold_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming resign_committee_cold is a previously created resign_committee_cold object+ *+ * cardano_resign_committee_cold_cert_ref(resign_committee_cold);+ *+ * // Now resign_committee_cold can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_resign_committee_cold_cert_ref there is a corresponding+ * call to \ref cardano_resign_committee_cold_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_resign_committee_cold_cert_ref(cardano_resign_committee_cold_cert_t* resign_committee_cold);++/**+ * \brief Retrieves the current reference count of the cardano_resign_committee_cold_cert_t object.+ *+ * This function returns the number of active references to an cardano_resign_committee_cold_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_resign_committee_cold_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param resign_committee_cold A pointer to the cardano_resign_committee_cold_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_resign_committee_cold_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_resign_committee_cold_cert_ref call is matched with a+ * \ref cardano_resign_committee_cold_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming resign_committee_cold is a previously created resign_committee_cold object+ *+ * size_t ref_count = cardano_resign_committee_cold_cert_refcount(resign_committee_cold);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_resign_committee_cold_cert_refcount(const cardano_resign_committee_cold_cert_t* resign_committee_cold);++/**+ * \brief Sets the last error message for a given cardano_resign_committee_cold_cert_t object.+ *+ * Records an error message in the resign_committee_cold's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] resign_committee_cold A pointer to the \ref cardano_resign_committee_cold_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the resign_committee_cold's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_resign_committee_cold_cert_set_last_error(+  cardano_resign_committee_cold_cert_t* resign_committee_cold,+  const char*                           message);++/**+ * \brief Retrieves the last error message recorded for a specific resign_committee_cold.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_resign_committee_cold_cert_set_last_error for the given+ * resign_committee_cold. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] resign_committee_cold A pointer to the \ref cardano_resign_committee_cold_cert_t instance whose last error+ *                   message is to be retrieved. If the resign_committee_cold is NULL, the function+ *                   returns a generic error message indicating the null resign_committee_cold.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified resign_committee_cold. If the resign_committee_cold is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_resign_committee_cold_cert_set_last_error for the same resign_committee_cold, or until+ *       the resign_committee_cold is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_resign_committee_cold_cert_get_last_error(+  const cardano_resign_committee_cold_cert_t* resign_committee_cold);++/**+ * \brief Creates an independent deep copy of a \ref cardano_resign_committee_cold_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_resign_committee_cold_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_resign_committee_cold_cert_deep_clone(const cardano_resign_committee_cold_cert_t* source, cardano_resign_committee_cold_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // RESIGN_COMMITTEE_COLD_CERT_H
+ vendor/include/cardano/certs/stake_delegation_cert.h view
@@ -0,0 +1,496 @@+/**+ * \file stake_delegation_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef STAKE_DELEGATION_CERT_H+#define STAKE_DELEGATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used when a stakeholder wants to delegate their stake to a+ * specific stake pool. It includes the stake pool id to which the stake is delegated.+ */+typedef struct cardano_stake_delegation_cert_t cardano_stake_delegation_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new stake delegation certificate.+ *+ * This function allocates and initializes a new \ref cardano_stake_delegation_cert_t object that represents+ * a stake delegation from a given credential to a specified staking pool.+ *+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the staker's credential.+ * \param[in] pool_key_hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the hash of the pool's+ *                          public key to which the stake is being delegated.+ * \param[out] stake_delegation On successful execution, this will point to a newly created \ref cardano_stake_delegation_cert_t+ *                              object. The caller is responsible for releasing this resource using \ref cardano_stake_delegation_cert_unref+ *                              when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the stake delegation+ *         certificate was successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ * cardano_blake2b_hash_t* pool_key_hash = ...; // Assume pool_key_hash is already initialized+ * cardano_stake_delegation_cert_t* stake_delegation = NULL;+ *+ * cardano_error_t result = cardano_stake_delegation_cert_new(credential, pool_key_hash, &stake_delegation);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The stake delegation certificate can now be used for delegation operations+ *   // Remember to free the certificate when done+ *   cardano_stake_delegation_cert_unref(&stake_delegation);+ * }+ * else+ * {+ *   printf("Failed to create stake delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * cardano_credential_unref(&credential); // Cleanup the credential+ * cardano_blake2b_hash_unref(&pool_key_hash); // Cleanup the pool key hash+ * \endcode+ *+ * \note This function increments the reference count of the credential and pool key hash objects passed to it.+ *       It is the caller's responsibility to manage the lifecycle of both the certificate and the input objects,+ *       ensuring that each is released when no longer needed.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_delegation_cert_new(+  cardano_credential_t*             credential,+  cardano_blake2b_hash_t*           pool_key_hash,+  cardano_stake_delegation_cert_t** stake_delegation);++/**+ * \brief Creates a \ref cardano_stake_delegation_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_stake_delegation_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a stake_delegation_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] stake_delegation_cert A pointer to a pointer of \ref cardano_stake_delegation_cert_t that will be set to the address+ *                        of the newly created stake_delegation_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_stake_delegation_cert_t object by calling+ *       \ref cardano_stake_delegation_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_stake_delegation_cert_t* stake_delegation_cert = NULL;+ *+ * cardano_error_t result = cardano_stake_delegation_cert_from_cbor(reader, &stake_delegation_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the stake_delegation_cert+ *+ *   // Once done, ensure to clean up and release the stake_delegation_cert+ *   cardano_stake_delegation_cert_unref(&stake_delegation_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode stake_delegation_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_delegation_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_stake_delegation_cert_t** stake_delegation_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_stake_delegation_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] stake_delegation_cert A constant pointer to the \ref cardano_stake_delegation_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p stake_delegation_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_delegation_cert_t* stake_delegation_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_stake_delegation_cert_to_cbor(stake_delegation_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_stake_delegation_cert_unref(&stake_delegation_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_stake_delegation_cert_to_cbor(+  const cardano_stake_delegation_cert_t* stake_delegation_cert,+  cardano_cbor_writer_t*                 writer);++/**+ * \brief Serializes a stake delegation certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "credential", "pool_keyhash".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_stake_delegation_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p cert or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_delegation_cert_to_cip116_json(+  const cardano_stake_delegation_cert_t* cert,+  cardano_json_writer_t*                 writer);++/**+ * \brief Retrieves the credential from a stake delegation certificate.+ *+ * This function fetches the credential associated with a given \ref cardano_stake_delegation_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_delegation_cert_t object from which the+ *                        credential is to be retrieved.+ *+ * \return A pointer to the \ref cardano_credential_t object containing the staker's credential. If the certificate is NULL+ *         or does not contain a valid credential, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_credential_t* credential = cardano_stake_delegation_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the retrieved credential+ *   // No need to unref the returned credential, as it is managed by the certificate+ * }+ * else+ * {+ *   printf("Failed to retrieve credential from stake delegation certificate.\n");+ * }+ * \endcode+ *+ * \note This function increments the reference count of the credential passed to it.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_stake_delegation_cert_get_credential(cardano_stake_delegation_cert_t* certificate);++/**+ * \brief Sets the credential for a stake delegation certificate.+ *+ * This function assigns a new credential to a given \ref cardano_stake_delegation_cert_t object.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_stake_delegation_cert_t object to which the credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the staker's credential.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the credential was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_stake_delegation_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Credential successfully set.\n");+ * }+ * else+ * {+ *   printf("Failed to set the credential.\n");+ * }+ *+ * \endcode+ *+ * \note This function increments the reference count of the credential. The caller is responsible for maintaining+ *       the original credential and releasing its reference appropriately. The certificate will maintain its own+ *       reference to the credential once set.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_delegation_cert_set_credential(cardano_stake_delegation_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the pool key hash from a stake delegation certificate.+ *+ * This function extracts the pool key hash from the specified \ref cardano_stake_delegation_cert_t object.+ * The pool key hash uniquely identifies the staking pool to which the stake rights are delegated.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_delegation_cert_t object.+ *+ * \return A pointer to the \ref cardano_blake2b_hash_t object containing the pool key hash. If the certificate is NULL or+ *         if the pool key hash is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* pool_key_hash = cardano_stake_delegation_cert_get_pool_key_hash(certificate);+ *+ * if (pool_key_hash != NULL)+ * {+ *   // Process the pool key hash+ *   cardano_blake2b_hash_unref(&pool_key_hash);+ * }+ * \endcode+ *+ * \note Since this function returns a reference, it must be unreferenced by the caller to prevent memory leaks.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_stake_delegation_cert_get_pool_key_hash(cardano_stake_delegation_cert_t* certificate);++/**+ * \brief Sets the pool key hash for a stake delegation certificate.+ *+ * This function assigns a new pool key hash to a given \ref cardano_stake_delegation_cert_t object.+ * The pool key hash uniquely identifies the staking pool to which the stake rights are delegated.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_stake_delegation_cert_t object to which the pool key hash will be set.+ * \param[in] hash A constant pointer to an initialized \ref cardano_blake2b_hash_t object representing the new pool key hash.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the pool key hash was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_blake2b_hash_t* pool_key_hash = ...; // Assume pool_key_hash is already initialized+ *+ * cardano_error_t result = cardano_stake_delegation_cert_set_pool_key_hash(certificate, pool_key_hash);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The pool key hash is now set for the stake delegation certificate+ * }+ * else+ * {+ *   printf("Failed to set the pool key hash.\n");+ * }+ * \endcode+ *+ * \note This function takes a reference of the pool key hash; therefore, the caller must ensure+ *       that the hash remains valid and manage its lifecycle appropriately. The certificate+ *       will internally manage its own reference to the hash.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_delegation_cert_set_pool_key_hash(cardano_stake_delegation_cert_t* certificate, cardano_blake2b_hash_t* hash);++/**+ * \brief Decrements the reference count of a cardano_stake_delegation_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_stake_delegation_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the stake_delegation_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] stake_delegation_cert A pointer to the pointer of the stake_delegation_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_delegation_cert_t* stake_delegation_cert = cardano_stake_delegation_cert_new(major, minor);+ *+ * // Perform operations with the stake_delegation_cert...+ *+ * cardano_stake_delegation_cert_unref(&stake_delegation_cert);+ * // At this point, stake_delegation_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_stake_delegation_cert_unref, the pointer to the \ref cardano_stake_delegation_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_stake_delegation_cert_unref(cardano_stake_delegation_cert_t** stake_delegation_cert);++/**+ * \brief Increases the reference count of the cardano_stake_delegation_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_stake_delegation_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_stake_delegation_cert_unref.+ *+ * \param stake_delegation_cert A pointer to the cardano_stake_delegation_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_delegation_cert is a previously created stake_delegation_cert object+ *+ * cardano_stake_delegation_cert_ref(stake_delegation_cert);+ *+ * // Now stake_delegation_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_stake_delegation_cert_ref there is a corresponding+ * call to \ref cardano_stake_delegation_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_stake_delegation_cert_ref(cardano_stake_delegation_cert_t* stake_delegation_cert);++/**+ * \brief Retrieves the current reference count of the cardano_stake_delegation_cert_t object.+ *+ * This function returns the number of active references to an cardano_stake_delegation_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_stake_delegation_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param stake_delegation_cert A pointer to the cardano_stake_delegation_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_stake_delegation_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_stake_delegation_cert_ref call is matched with a+ * \ref cardano_stake_delegation_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_delegation_cert is a previously created stake_delegation_cert object+ *+ * size_t ref_count = cardano_stake_delegation_cert_refcount(stake_delegation_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_stake_delegation_cert_refcount(const cardano_stake_delegation_cert_t* stake_delegation_cert);++/**+ * \brief Sets the last error message for a given cardano_stake_delegation_cert_t object.+ *+ * Records an error message in the stake_delegation_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] stake_delegation_cert A pointer to the \ref cardano_stake_delegation_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the stake_delegation_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_stake_delegation_cert_set_last_error(+  cardano_stake_delegation_cert_t* stake_delegation_cert,+  const char*                      message);++/**+ * \brief Retrieves the last error message recorded for a specific stake_delegation_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_stake_delegation_cert_set_last_error for the given+ * stake_delegation_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] stake_delegation_cert A pointer to the \ref cardano_stake_delegation_cert_t instance whose last error+ *                   message is to be retrieved. If the stake_delegation_cert is NULL, the function+ *                   returns a generic error message indicating the null stake_delegation_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified stake_delegation_cert. If the stake_delegation_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_stake_delegation_cert_set_last_error for the same stake_delegation_cert, or until+ *       the stake_delegation_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_stake_delegation_cert_get_last_error(+  const cardano_stake_delegation_cert_t* stake_delegation_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_stake_delegation_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_stake_delegation_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_stake_delegation_cert_deep_clone(const cardano_stake_delegation_cert_t* source, cardano_stake_delegation_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // STAKE_DELEGATION_CERT_H
+ vendor/include/cardano/certs/stake_deregistration_cert.h view
@@ -0,0 +1,420 @@+/**+ * \file stake_deregistration_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef STAKE_DEREGISTRATION_CERT_H+#define STAKE_DEREGISTRATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used when a stakeholder no longer wants to participate in+ * staking. It revokes the stake registration and the associated stake is no+ * longer counted when calculating stake pool rewards.+ */+typedef struct cardano_stake_deregistration_cert_t cardano_stake_deregistration_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new stake deregistration certificate.+ *+ * This function allocates and initializes a new \ref cardano_stake_deregistration_cert_t object.+ * Stake deregistration certificates are used to deregister a staking credential from the Cardano network.+ *+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object that represents+ *                       the staking credential to be deregistered.+ * \param[out] stake_deregistration On successful execution, this will point to a newly created+ *                                  \ref cardano_stake_deregistration_cert_t object. The caller is responsible+ *                                  for releasing this resource using \ref cardano_stake_deregistration_cert_unref+ *                                  when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate+ *         was successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any input pointers are NULL).+ *+ * \note This function increments the reference count of the credential passed to it.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...;  // Assume credential is already initialized+ * cardano_stake_deregistration_cert_t* stake_deregistration = NULL;+ * cardano_error_t result = cardano_stake_deregistration_cert_new(credential, &stake_deregistration);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The stake deregistration certificate can now be used for deregistering the stake+ *   // Remember to free the stake_deregistration when done+ *   cardano_stake_deregistration_cert_unref(&stake_deregistration);+ * }+ * else+ * {+ *   printf("Failed to create stake deregistration certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_deregistration_cert_new(+  cardano_credential_t*                 credential,+  cardano_stake_deregistration_cert_t** stake_deregistration);++/**+ * \brief Creates a \ref cardano_stake_deregistration_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_stake_deregistration_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a stake_deregistration.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] stake_deregistration A pointer to a pointer of \ref cardano_stake_deregistration_cert_t that will be set to the address+ *                        of the newly created stake_deregistration object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_stake_deregistration_cert_t object by calling+ *       \ref cardano_stake_deregistration_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_stake_deregistration_cert_t* stake_deregistration = NULL;+ *+ * cardano_error_t result = cardano_stake_deregistration_cert_from_cbor(reader, &stake_deregistration);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the stake_deregistration+ *+ *   // Once done, ensure to clean up and release the stake_deregistration+ *   cardano_stake_deregistration_cert_unref(&stake_deregistration);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode stake_deregistration: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_deregistration_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_stake_deregistration_cert_t** stake_deregistration);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_stake_deregistration_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] stake_deregistration A constant pointer to the \ref cardano_stake_deregistration_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p stake_deregistration or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_deregistration_cert_t* stake_deregistration = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_stake_deregistration_cert_to_cbor(stake_deregistration, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_stake_deregistration_cert_unref(&stake_deregistration);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_stake_deregistration_cert_to_cbor(+  const cardano_stake_deregistration_cert_t* stake_deregistration,+  cardano_cbor_writer_t*                     writer);++/**+ * \brief Serializes a stake deregistration certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "credential".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_stake_deregistration_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_stake_deregistration_cert_to_cip116_json(+  const cardano_stake_deregistration_cert_t* cert,+  cardano_json_writer_t*                     writer);++/**+ * \brief Retrieves the credential associated with a stake deregistration certificate.+ *+ * This function extracts the credential from the specified \ref cardano_stake_deregistration_cert_t object.+ * The credential represents the staking identifier that was intended to be deregistered from the Cardano network.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_deregistration_cert_t object.+ *+ * \return A pointer to the \ref cardano_credential_t object containing the credential. If the certificate is NULL,+ *         this function returns NULL. The returned credential object has its reference count increased and it is+ *         the caller's responsibility to release this reference using \ref cardano_credential_unref when it is+ *         no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_deregistration_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_credential_t* credential = cardano_stake_deregistration_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   cardano_credential_unref(&credential);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_stake_deregistration_cert_get_credential(cardano_stake_deregistration_cert_t* certificate);++/**+ * \brief Sets the credential for a stake deregistration certificate.+ *+ * This function assigns a new credential to a given \ref cardano_stake_deregistration_cert_t object. The credential+ * represents the staking identifier that is intended to be deregistered from the Cardano network.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_stake_deregistration_cert_t object to which the credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the new credential.+ *                       This function increments the reference count of the credential, and it will be managed by the+ *                       certificate object thereafter.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the credential+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_deregistration_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_stake_deregistration_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The credential is now set for the stake deregistration certificate+ * }+ * else+ * {+ *   printf("Failed to set the credential.\n");+ * }+ *+ * // Remember to manage the lifecycle of the objects properly+ * cardano_credential_unref(&credential);+ * cardano_stake_deregistration_cert_unref(&certificate);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_deregistration_cert_set_credential(cardano_stake_deregistration_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Decrements the reference count of a cardano_stake_deregistration_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_stake_deregistration_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the stake_deregistration is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] stake_deregistration A pointer to the pointer of the stake_deregistration object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_deregistration_cert_t* stake_deregistration = cardano_stake_deregistration_cert_new(major, minor);+ *+ * // Perform operations with the stake_deregistration...+ *+ * cardano_stake_deregistration_cert_unref(&stake_deregistration);+ * // At this point, stake_deregistration is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_stake_deregistration_cert_unref, the pointer to the \ref cardano_stake_deregistration_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_stake_deregistration_cert_unref(cardano_stake_deregistration_cert_t** stake_deregistration);++/**+ * \brief Increases the reference count of the cardano_stake_deregistration_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_stake_deregistration_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_stake_deregistration_cert_unref.+ *+ * \param stake_deregistration A pointer to the cardano_stake_deregistration_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_deregistration is a previously created stake_deregistration object+ *+ * cardano_stake_deregistration_cert_ref(stake_deregistration);+ *+ * // Now stake_deregistration can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_stake_deregistration_cert_ref there is a corresponding+ * call to \ref cardano_stake_deregistration_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_stake_deregistration_cert_ref(cardano_stake_deregistration_cert_t* stake_deregistration);++/**+ * \brief Retrieves the current reference count of the cardano_stake_deregistration_cert_t object.+ *+ * This function returns the number of active references to an cardano_stake_deregistration_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_stake_deregistration_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param stake_deregistration A pointer to the cardano_stake_deregistration_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_stake_deregistration_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_stake_deregistration_cert_ref call is matched with a+ * \ref cardano_stake_deregistration_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_deregistration is a previously created stake_deregistration object+ *+ * size_t ref_count = cardano_stake_deregistration_cert_refcount(stake_deregistration);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_stake_deregistration_cert_refcount(const cardano_stake_deregistration_cert_t* stake_deregistration);++/**+ * \brief Sets the last error message for a given cardano_stake_deregistration_cert_t object.+ *+ * Records an error message in the stake_deregistration's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] stake_deregistration A pointer to the \ref cardano_stake_deregistration_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the stake_deregistration's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_stake_deregistration_cert_set_last_error(+  cardano_stake_deregistration_cert_t* stake_deregistration,+  const char*                          message);++/**+ * \brief Retrieves the last error message recorded for a specific stake_deregistration.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_stake_deregistration_cert_set_last_error for the given+ * stake_deregistration. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] stake_deregistration A pointer to the \ref cardano_stake_deregistration_cert_t instance whose last error+ *                   message is to be retrieved. If the stake_deregistration is NULL, the function+ *                   returns a generic error message indicating the null stake_deregistration.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified stake_deregistration. If the stake_deregistration is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_stake_deregistration_cert_set_last_error for the same stake_deregistration, or until+ *       the stake_deregistration is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_stake_deregistration_cert_get_last_error(+  const cardano_stake_deregistration_cert_t* stake_deregistration);++/**+ * \brief Creates an independent deep copy of a \ref cardano_stake_deregistration_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_stake_deregistration_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_stake_deregistration_cert_deep_clone(const cardano_stake_deregistration_cert_t* source, cardano_stake_deregistration_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // STAKE_DEREGISTRATION_CERT_H
+ vendor/include/cardano/certs/stake_registration_cert.h view
@@ -0,0 +1,422 @@+/**+ * \file stake_registration_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef STAKE_REGISTRATION_CERT_H+#define STAKE_REGISTRATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used when an individual wants to register as a stakeholder.+ * It allows the holder to participate in the stake process by delegating their+ * stake or creating a stake pool.+ */+typedef struct cardano_stake_registration_cert_t cardano_stake_registration_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new stake registration certificate.+ *+ * This function allocates and initializes a new \ref cardano_stake_registration_cert_t object.+ * Stake registration certificates are used to register a staking credential from the Cardano network.+ *+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object that represents+ *                       the staking credential to be registered.+ * \param[out] stake_registration On successful execution, this will point to a newly created+ *                                  \ref cardano_stake_registration_cert_t object. The caller is responsible+ *                                  for releasing this resource using \ref cardano_stake_registration_cert_unref+ *                                  when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate+ *         was successfully created, or an error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any input pointers are NULL).+ *+ * \note This function increments the reference count of the credential passed to it.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...;  // Assume credential is already initialized+ * cardano_stake_registration_cert_t* stake_registration = NULL;+ * cardano_error_t result = cardano_stake_registration_cert_new(credential, &stake_registration);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The stake registration certificate can now be used for registering the stake+ *   // Remember to free the stake_registration when done+ *   cardano_stake_registration_cert_unref(&stake_registration);+ * }+ * else+ * {+ *   printf("Failed to create stake registration certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_cert_new(+  cardano_credential_t*               credential,+  cardano_stake_registration_cert_t** stake_registration);++/**+ * \brief Creates a \ref cardano_stake_registration_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_stake_registration_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a stake_registration.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] stake_registration A pointer to a pointer of \ref cardano_stake_registration_cert_t that will be set to the address+ *                        of the newly created stake_registration object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_stake_registration_cert_t object by calling+ *       \ref cardano_stake_registration_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_stake_registration_cert_t* stake_registration = NULL;+ *+ * cardano_error_t result = cardano_stake_registration_cert_from_cbor(reader, &stake_registration);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the stake_registration+ *+ *   // Once done, ensure to clean up and release the stake_registration+ *   cardano_stake_registration_cert_unref(&stake_registration);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode stake_registration: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_stake_registration_cert_t** stake_registration);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_stake_registration_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] stake_registration A constant pointer to the \ref cardano_stake_registration_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p stake_registration or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_cert_t* stake_registration = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_stake_registration_cert_to_cbor(stake_registration, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_stake_registration_cert_unref(&stake_registration);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_stake_registration_cert_to_cbor(+  const cardano_stake_registration_cert_t* stake_registration,+  cardano_cbor_writer_t*                   writer);++/**+ * \brief Serializes a stake registration certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", then "credential".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_stake_registration_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ *         CARDANO_ERROR_POINTER_IS_NULL  If \p cert or \p writer is NULL.+ *         CARDANO_ERROR_ENCODING         If the certificate is malformed (e.g., missing credential).+ *         Other                          Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_cert_to_cip116_json(+  const cardano_stake_registration_cert_t* cert,+  cardano_json_writer_t*                   writer);++/**+ * \brief Retrieves the credential associated with a stake registration certificate.+ *+ * This function extracts the credential from the specified \ref cardano_stake_registration_cert_t object.+ * The credential represents the staking identifier that was intended to be registered from the Cardano network.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_registration_cert_t object.+ *+ * \return A pointer to the \ref cardano_credential_t object containing the credential. If the certificate is NULL,+ *         this function returns NULL. The returned credential object has its reference count increased and it is+ *         the caller's responsibility to release this reference using \ref cardano_credential_unref when it is+ *         no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_registration_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_credential_t* credential = cardano_stake_registration_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   cardano_credential_unref(&credential);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_stake_registration_cert_get_credential(cardano_stake_registration_cert_t* certificate);++/**+ * \brief Sets the credential for a stake registration certificate.+ *+ * This function assigns a new credential to a given \ref cardano_stake_registration_cert_t object. The credential+ * represents the staking identifier that is intended to be registered from the Cardano network.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_stake_registration_cert_t object to which the credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the new credential.+ *                       This function increments the reference count of the credential, and it will be managed by the+ *                       certificate object thereafter.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the credential+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_stake_registration_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The credential is now set for the stake registration certificate+ * }+ * else+ * {+ *   printf("Failed to set the credential.\n");+ * }+ *+ * // Remember to manage the lifecycle of the objects properly+ * cardano_credential_unref(&credential);+ * cardano_stake_registration_cert_unref(&certificate);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_cert_set_credential(cardano_stake_registration_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Decrements the reference count of a cardano_stake_registration_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_stake_registration_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the stake_registration is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] stake_registration A pointer to the pointer of the stake_registration object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_cert_t* stake_registration = cardano_stake_registration_cert_new(major, minor);+ *+ * // Perform operations with the stake_registration...+ *+ * cardano_stake_registration_cert_unref(&stake_registration);+ * // At this point, stake_registration is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_stake_registration_cert_unref, the pointer to the \ref cardano_stake_registration_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_stake_registration_cert_unref(cardano_stake_registration_cert_t** stake_registration);++/**+ * \brief Increases the reference count of the cardano_stake_registration_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_stake_registration_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_stake_registration_cert_unref.+ *+ * \param stake_registration A pointer to the cardano_stake_registration_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_registration is a previously created stake_registration object+ *+ * cardano_stake_registration_cert_ref(stake_registration);+ *+ * // Now stake_registration can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_stake_registration_cert_ref there is a corresponding+ * call to \ref cardano_stake_registration_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_stake_registration_cert_ref(cardano_stake_registration_cert_t* stake_registration);++/**+ * \brief Retrieves the current reference count of the cardano_stake_registration_cert_t object.+ *+ * This function returns the number of active references to an cardano_stake_registration_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_stake_registration_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param stake_registration A pointer to the cardano_stake_registration_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_stake_registration_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_stake_registration_cert_ref call is matched with a+ * \ref cardano_stake_registration_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_registration is a previously created stake_registration object+ *+ * size_t ref_count = cardano_stake_registration_cert_refcount(stake_registration);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_stake_registration_cert_refcount(const cardano_stake_registration_cert_t* stake_registration);++/**+ * \brief Sets the last error message for a given cardano_stake_registration_cert_t object.+ *+ * Records an error message in the stake_registration's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] stake_registration A pointer to the \ref cardano_stake_registration_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the stake_registration's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_stake_registration_cert_set_last_error(+  cardano_stake_registration_cert_t* stake_registration,+  const char*                        message);++/**+ * \brief Retrieves the last error message recorded for a specific stake_registration.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_stake_registration_cert_set_last_error for the given+ * stake_registration. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] stake_registration A pointer to the \ref cardano_stake_registration_cert_t instance whose last error+ *                   message is to be retrieved. If the stake_registration is NULL, the function+ *                   returns a generic error message indicating the null stake_registration.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified stake_registration. If the stake_registration is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_stake_registration_cert_set_last_error for the same stake_registration, or until+ *       the stake_registration is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_stake_registration_cert_get_last_error(+  const cardano_stake_registration_cert_t* stake_registration);++/**+ * \brief Creates an independent deep copy of a \ref cardano_stake_registration_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_stake_registration_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_cert_deep_clone(const cardano_stake_registration_cert_t* source, cardano_stake_registration_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // STAKE_REGISTRATION_CERT_H
+ vendor/include/cardano/certs/stake_registration_delegation_cert.h view
@@ -0,0 +1,540 @@+/**+ * \file stake_registration_delegation_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef STAKE_REGISTRATION_DELEGATION_CERT_H+#define STAKE_REGISTRATION_DELEGATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate Register the stake key and delegate with a single certificate to a stake pool.+ */+typedef struct cardano_stake_registration_delegation_cert_t cardano_stake_registration_delegation_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new stake registration and delegation certificate.+ *+ * This function allocates and initializes a \ref cardano_stake_registration_delegation_cert_t object, which represents+ * a certificate that both registers a new staking credential and delegates it to a specified staking pool.+ *+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stake credential to be registered.+ * \param[in] pool_key_hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the pool's key hash to which the stake will be delegated.+ * \param[in] deposit The amount of ADA deposited for registering the stake, required as per network protocol rules.+ * \param[out] stake_registration_delegation On successful initialization, this will point to a newly created \ref cardano_stake_registration_delegation_cert_t object.+ *                                            The caller is responsible for managing the lifecycle of this object, including releasing it when no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was successfully created, or an error code+ *         indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ * cardano_blake2b_hash_t* pool_key_hash = ...; // Assume pool_key_hash is initialized+ * uint64_t deposit = 2000000; // Example deposit amount+ *+ * cardano_stake_registration_delegation_cert_t* certificate = NULL;+ * cardano_error_t result = cardano_stake_registration_delegation_cert_new(credential, pool_key_hash, deposit, &certificate);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate is now ready to use+ *   // Once done, ensure to clean up and release the certificate+ *   cardano_stake_registration_delegation_cert_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create stake registration and delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_delegation_cert_new(+  cardano_credential_t*                          credential,+  cardano_blake2b_hash_t*                        pool_key_hash,+  uint64_t                                       deposit,+  cardano_stake_registration_delegation_cert_t** stake_registration_delegation);++/**+ * \brief Creates a \ref cardano_stake_registration_delegation_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_stake_registration_delegation_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a stake_registration.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] stake_registration A pointer to a pointer of \ref cardano_stake_registration_delegation_cert_t that will be set to the address+ *                        of the newly created stake_registration object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_stake_registration_delegation_cert_t object by calling+ *       \ref cardano_stake_registration_delegation_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_stake_registration_delegation_cert_t* stake_registration = NULL;+ *+ * cardano_error_t result = cardano_stake_registration_delegation_cert_from_cbor(reader, &stake_registration);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the stake_registration+ *+ *   // Once done, ensure to clean up and release the stake_registration+ *   cardano_stake_registration_delegation_cert_unref(&stake_registration);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode stake_registration: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_delegation_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_stake_registration_delegation_cert_t** stake_registration);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_stake_registration_delegation_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] stake_registration A constant pointer to the \ref cardano_stake_registration_delegation_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p stake_registration or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_delegation_cert_t* stake_registration = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_stake_registration_delegation_cert_to_cbor(stake_registration, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_stake_registration_delegation_cert_unref(&stake_registration);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_stake_registration_delegation_cert_to_cbor(+  const cardano_stake_registration_delegation_cert_t* stake_registration,+  cardano_cbor_writer_t*                              writer);++/**+ * \brief Serializes a stake registration and delegation certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "credential", "pool_keyhash", "coin".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_stake_registration_delegation_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * CARDANO_ERROR_ENCODING        If the certificate is malformed or serialization fails.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_delegation_cert_to_cip116_json(+  const cardano_stake_registration_delegation_cert_t* cert,+  cardano_json_writer_t*                              writer);++/**+ * \brief Retrieves the stake credential from a stake registration and delegation certificate.+ *+ * This function extracts the stake credential from a given \ref cardano_stake_registration_delegation_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_registration_delegation_cert_t object.+ *+ * \return A pointer to the \ref cardano_credential_t object containing the stake credential. If the certificate is NULL,+ *         this function returns NULL. The returned credential is reference counted and must be unreferenced by the caller+ *         when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_credential_t* credential = cardano_stake_registration_delegation_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   printf("Failed to retrieve the credential.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_stake_registration_delegation_cert_get_credential(cardano_stake_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the stake credential for a stake registration and delegation certificate.+ *+ * This function assigns a stake credential to a given \ref cardano_stake_registration_delegation_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_stake_registration_delegation_cert_t object which will+ *                        receive the new stake credential.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object containing the stake credential to be+ *                       set. This function increases the reference count of the credential, so it remains managed and must+ *                       be properly unreferenced after it is no longer needed by the caller.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the stake credential+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_stake_registration_delegation_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Stake credential set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the stake credential.\n");+ * }+ *+ * // Both objects should be unreferenced when no longer needed+ * cardano_credential_unref(&credential);+ * cardano_stake_registration_delegation_cert_unref(&certificate);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_delegation_cert_set_credential(cardano_stake_registration_delegation_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the pool key hash from a stake registration and delegation certificate.+ *+ * This function extracts the pool key hash from the specified \ref cardano_stake_registration_delegation_cert_t object.+ * The pool key hash identifies the staking pool to which the stake rights are being delegated.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_registration_delegation_cert_t object.+ *+ * \return A pointer to the \ref cardano_blake2b_hash_t object containing the pool key hash. If the certificate is NULL,+ *         or if the pool key hash has not been set, this function returns NULL. The returned hash is a new reference and+ *         must be managed by the caller. It must be unreferenced when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* pool_key_hash = cardano_stake_registration_delegation_cert_get_pool_key_hash(certificate);+ *+ * if (pool_key_hash != NULL)+ * {+ *   // Process the pool key hash+ *   cardano_blake2b_hash_unref(&pool_key_hash);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_stake_registration_delegation_cert_get_pool_key_hash(cardano_stake_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the pool key hash for a stake registration and delegation certificate.+ *+ * This function assigns a pool key hash to the specified \ref cardano_stake_registration_delegation_cert_t object.+ * The pool key hash identifies the staking pool to which the stake rights are being delegated.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_stake_registration_delegation_cert_t object to which the pool key hash will be set.+ * \param[in] hash A constant pointer to an initialized \ref cardano_blake2b_hash_t object representing the pool key hash.+ *                  The pool parameters object will take a reference to this hash, so it must remain valid as long as it is in use by the certificate.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the pool key hash was successfully set,+ *         or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_blake2b_hash_t* hash = ...; // Assume hash is already initialized+ *+ * cardano_error_t result = cardano_stake_registration_delegation_cert_set_pool_key_hash(certificate, hash);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The pool key hash has been set successfully+ * }+ * else+ * {+ *   printf("Failed to set the pool key hash.\n");+ * }+ * \endcode+ *+ * \note This function increments the reference count of the hash passed to it, as the certificate will maintain a reference to it.+ *       The caller must manage their own reference to the hash and release it when it is no longer needed.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_delegation_cert_set_pool_key_hash(cardano_stake_registration_delegation_cert_t* certificate, cardano_blake2b_hash_t* hash);++/**+ * \brief Retrieves the deposit amount from a stake registration and delegation certificate.+ *+ * This function extracts the deposit amount from the specified \ref cardano_stake_registration_delegation_cert_t object.+ * The deposit is required when registering stake rights and delegating them to a staking pool, as specified by the protocol parameters.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_registration_delegation_cert_t object.+ *+ * \return The deposit amount in lovelaces. If the certificate is NULL, returns 0.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = cardano_stake_registration_delegation_cert_get_deposit(certificate);+ * printf("Deposit amount: %llu lovelaces\n", deposit);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_stake_registration_delegation_cert_get_deposit(const cardano_stake_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the deposit amount for a stake registration and delegation certificate.+ *+ * This function assigns a new deposit amount to a given \ref cardano_stake_registration_delegation_cert_t object.+ * The deposit is a required amount of ADA that must be locked when registering stake rights and delegating them to a staking pool,+ * according to the protocol parameters.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_stake_registration_delegation_cert_t object to which the deposit will be set.+ * \param[in] deposit The deposit amount in lovelaces to be set.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the deposit amount was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if the input certificate pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = 2000000; // Deposit of 2 ADA+ *+ * cardano_error_t result = cardano_stake_registration_delegation_cert_set_deposit(certificate, deposit);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Deposit amount set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the deposit amount.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_delegation_cert_set_deposit(cardano_stake_registration_delegation_cert_t* certificate, uint64_t deposit);++/**+ * \brief Decrements the reference count of a cardano_stake_registration_delegation_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_stake_registration_delegation_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the stake_registration is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] stake_registration A pointer to the pointer of the stake_registration object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_registration_delegation_cert_t* stake_registration = cardano_stake_registration_delegation_cert_new(major, minor);+ *+ * // Perform operations with the stake_registration...+ *+ * cardano_stake_registration_delegation_cert_unref(&stake_registration);+ * // At this point, stake_registration is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_stake_registration_delegation_cert_unref, the pointer to the \ref cardano_stake_registration_delegation_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_stake_registration_delegation_cert_unref(cardano_stake_registration_delegation_cert_t** stake_registration);++/**+ * \brief Increases the reference count of the cardano_stake_registration_delegation_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_stake_registration_delegation_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_stake_registration_delegation_cert_unref.+ *+ * \param stake_registration A pointer to the cardano_stake_registration_delegation_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_registration is a previously created stake_registration object+ *+ * cardano_stake_registration_delegation_cert_ref(stake_registration);+ *+ * // Now stake_registration can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_stake_registration_delegation_cert_ref there is a corresponding+ * call to \ref cardano_stake_registration_delegation_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_stake_registration_delegation_cert_ref(cardano_stake_registration_delegation_cert_t* stake_registration);++/**+ * \brief Retrieves the current reference count of the cardano_stake_registration_delegation_cert_t object.+ *+ * This function returns the number of active references to an cardano_stake_registration_delegation_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_stake_registration_delegation_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param stake_registration A pointer to the cardano_stake_registration_delegation_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_stake_registration_delegation_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_stake_registration_delegation_cert_ref call is matched with a+ * \ref cardano_stake_registration_delegation_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_registration is a previously created stake_registration object+ *+ * size_t ref_count = cardano_stake_registration_delegation_cert_refcount(stake_registration);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_stake_registration_delegation_cert_refcount(const cardano_stake_registration_delegation_cert_t* stake_registration);++/**+ * \brief Sets the last error message for a given cardano_stake_registration_delegation_cert_t object.+ *+ * Records an error message in the stake_registration's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] stake_registration A pointer to the \ref cardano_stake_registration_delegation_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the stake_registration's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_stake_registration_delegation_cert_set_last_error(+  cardano_stake_registration_delegation_cert_t* stake_registration,+  const char*                                   message);++/**+ * \brief Retrieves the last error message recorded for a specific stake_registration.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_stake_registration_delegation_cert_set_last_error for the given+ * stake_registration. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] stake_registration A pointer to the \ref cardano_stake_registration_delegation_cert_t instance whose last error+ *                   message is to be retrieved. If the stake_registration is NULL, the function+ *                   returns a generic error message indicating the null stake_registration.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified stake_registration. If the stake_registration is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_stake_registration_delegation_cert_set_last_error for the same stake_registration, or until+ *       the stake_registration is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_stake_registration_delegation_cert_get_last_error(+  const cardano_stake_registration_delegation_cert_t* stake_registration);++/**+ * \brief Creates an independent deep copy of a \ref cardano_stake_registration_delegation_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_stake_registration_delegation_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_stake_registration_delegation_cert_deep_clone(const cardano_stake_registration_delegation_cert_t* source, cardano_stake_registration_delegation_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // STAKE_REGISTRATION_DELEGATION_CERT_H
+ vendor/include/cardano/certs/stake_vote_delegation_cert.h view
@@ -0,0 +1,575 @@+/**+ * \file stake_vote_delegation_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef STAKE_VOTE_DELEGATION_CERT_H+#define STAKE_VOTE_DELEGATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/common/drep.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used when an individual wants to delegate their voting+ * rights to any other DRep and simultaneously wants to delegate their stake to a+ * specific stake pool.+ */+typedef struct cardano_stake_vote_delegation_cert_t cardano_stake_vote_delegation_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new stake vote delegation certificate.+ *+ * This function allocates and initializes a new \ref cardano_stake_vote_delegation_cert_t object. It represents a certificate+ * where a stakeholder delegates their voting rights along with their staking activity to a pool and a drep.+ *+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stakeholder's credential.+ * \param[in] pool_key_hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the pool's key hash to which the stake is delegated.+ * \param[in] drep A pointer to an initialized \ref cardano_drep_t object representing the drep to which the voting rights are delegated.+ * \param[out] stake_vote_delegation On successful initialization, this will point to a newly created \ref cardano_stake_vote_delegation_cert_t object.+ *                                            The caller is responsible for managing the lifecycle of this object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ * cardano_blake2b_hash_t* pool_key_hash = ...; // Assume pool_key_hash is initialized+ * cardano_drep_t* drep = ...; // Assume drep is initialized+ * cardano_stake_vote_delegation_cert_t* certificate = NULL;+ *+ * cardano_error_t result = cardano_stake_vote_delegation_cert_new(credential, pool_key_hash, drep, &certificate);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The certificate can now be used in voting and staking operations+ *   // Remember to free the certificate when done+ *   cardano_stake_vote_delegation_cert_unref(&certificate);+ * }+ * else+ * {+ *   printf("Failed to create stake vote delegation certificate: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up resources+ * cardano_credential_unref(&credential);+ * cardano_blake2b_hash_unref(&pool_key_hash);+ * cardano_drep_unref(&drep);+ * \endcode+ *+ * \note This function increases the reference count of all input objects. The caller is responsible for releasing their references when they are no longer needed.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_delegation_cert_new(+  cardano_credential_t*                  credential,+  cardano_blake2b_hash_t*                pool_key_hash,+  cardano_drep_t*                        drep,+  cardano_stake_vote_delegation_cert_t** stake_vote_delegation);++/**+ * \brief Creates a \ref cardano_stake_vote_delegation_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_stake_vote_delegation_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a stake_registration.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] stake_registration A pointer to a pointer of \ref cardano_stake_vote_delegation_cert_t that will be set to the address+ *                        of the newly created stake_registration object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_stake_vote_delegation_cert_t object by calling+ *       \ref cardano_stake_vote_delegation_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_stake_vote_delegation_cert_t* stake_registration = NULL;+ *+ * cardano_error_t result = cardano_stake_vote_delegation_cert_from_cbor(reader, &stake_registration);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the stake_registration+ *+ *   // Once done, ensure to clean up and release the stake_registration+ *   cardano_stake_vote_delegation_cert_unref(&stake_registration);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode stake_registration: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_delegation_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_stake_vote_delegation_cert_t** stake_registration);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_stake_vote_delegation_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] stake_registration A constant pointer to the \ref cardano_stake_vote_delegation_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p stake_registration or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_delegation_cert_t* stake_registration = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_stake_vote_delegation_cert_to_cbor(stake_registration, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_stake_vote_delegation_cert_unref(&stake_registration);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_stake_vote_delegation_cert_to_cbor(+  const cardano_stake_vote_delegation_cert_t* stake_registration,+  cardano_cbor_writer_t*                      writer);++/**+ * \brief Serializes a stake vote delegation certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "credential", "pool_keyhash", "drep".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_stake_vote_delegation_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p cert or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_delegation_cert_to_cip116_json(+  const cardano_stake_vote_delegation_cert_t* cert,+  cardano_json_writer_t*                      writer);++/**+ * \brief Retrieves the credential from a stake vote delegation certificate.+ *+ * This function extracts the credential from the specified \ref cardano_stake_vote_delegation_cert_t object. The credential+ * identifies the stakeholder whose voting rights are being delegated.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_vote_delegation_cert_t object from which the credential will be retrieved.+ *+ * \return A pointer to the \ref cardano_credential_t object containing the credential. If the certificate is NULL or+ *         if the credential is not set, this function returns NULL. This returned object is a new reference and must be+ *         unreferenced by the caller when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = cardano_stake_vote_delegation_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   cardano_credential_unref(&credential); // When done, release the credential+ * }+ * else+ * {+ *   printf("Failed to retrieve credential.\n");+ * }+ * \endcode+ *+ * \note The caller is responsible for managing the lifecycle of the returned credential, including releasing it+ *       when it is no longer needed.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_stake_vote_delegation_cert_get_credential(cardano_stake_vote_delegation_cert_t* certificate);++/**+ * \brief Sets the credential for a stake vote delegation certificate.+ *+ * This function assigns a new credential to a given \ref cardano_stake_vote_delegation_cert_t object.+ * The credential specifies the stakeholder whose voting rights are being delegated.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_stake_vote_delegation_cert_t object to which the credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the new credential. This function+ *                       increments the reference count of the credential, so it remains managed by the caller.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the credential was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_stake_vote_delegation_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The credential is now set for the certificate+ * }+ * else+ * {+ *   printf("Failed to set the credential.\n");+ * }+ *+ * // Both certificate and credential should be unreferenced when no longer needed+ * cardano_credential_unref(&credential);+ * cardano_stake_vote_delegation_cert_unref(&certificate);+ * \endcode+ *+ * \note This function takes a reference to the provided credential object. The caller must ensure+ *       that the credential remains valid for as long as it is associated with the certificate and+ *       is responsible for releasing its own reference when it is no longer needed.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_delegation_cert_set_credential(cardano_stake_vote_delegation_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the pool key hash from a stake vote delegation certificate.+ *+ * This function extracts the pool key hash from the specified \ref cardano_stake_vote_delegation_cert_t object.+ * The pool key hash identifies the stake pool to which the voting rights are delegated.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_vote_delegation_cert_t object.+ *+ * \return A pointer to the \ref cardano_blake2b_hash_t object containing the pool key hash. If the certificate is NULL or+ *         if the pool key hash is not set, this function returns NULL. The returned object is a new reference and must be+ *         unreferenced by the caller when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* pool_key_hash = cardano_stake_vote_delegation_cert_get_pool_key_hash(certificate);+ *+ * if (pool_key_hash != NULL)+ * {+ *   // Process the pool key hash+ *   // Display or use the hash as needed+ *   cardano_blake2b_hash_unref(&pool_key_hash);+ * }+ * \endcode+ *+ * \note This function returns a new reference to the pool key hash. It is the responsibility of the caller to manage+ *       this reference and ensure that it is unreferenced when no longer needed.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_stake_vote_delegation_cert_get_pool_key_hash(cardano_stake_vote_delegation_cert_t* certificate);++/**+ * \brief Sets the pool key hash for a stake vote delegation certificate.+ *+ * This function updates the pool key hash in the specified \ref cardano_stake_vote_delegation_cert_t object.+ * The pool key hash identifies the stake pool to which the voting rights are to be delegated.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_stake_vote_delegation_cert_t object to which the pool key hash will be set.+ * \param[in] hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the pool key hash.+ *                 The function increases the reference count of the hash object; it is the responsibility of the caller+ *                 to manage the lifecycle of their own reference to the hash.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the pool key hash was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_blake2b_hash_t* pool_key_hash = ...; // Assume pool_key_hash is already initialized+ *+ * cardano_error_t result = cardano_stake_vote_delegation_cert_set_pool_key_hash(certificate, pool_key_hash);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Pool key hash set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the pool key hash.\n");+ * }+ *+ * // Remember to unreference the hash if it's no longer used elsewhere in your application+ * cardano_blake2b_hash_unref(&pool_key_hash);+ * \endcode+ *+ * \note This function increments the reference count of the hash object. It is important for the caller+ *       to manage the reference correctly to avoid memory leaks.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_delegation_cert_set_pool_key_hash(cardano_stake_vote_delegation_cert_t* certificate, cardano_blake2b_hash_t* hash);++/**+ * \brief Retrieves the DREP from a stake vote delegation certificate.+ *+ * This function extracts the DREP associated with the specified \ref cardano_stake_vote_delegation_cert_t object.+ * The DREP object represents the delegated representative to which voting rights are assigned.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_vote_delegation_cert_t object.+ *+ * \return A pointer to the \ref cardano_drep_t object containing the DREP information. If the certificate is NULL or+ *         if the DREP is not set, this function returns NULL. The returned DREP object is a new reference and must be+ *         managed by the caller, who is responsible for releasing it using \ref cardano_drep_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_drep_t* drep = cardano_stake_vote_delegation_cert_get_drep(certificate);+ *+ * if (drep != NULL)+ * {+ *   // Process the DREP information+ *   cardano_drep_unref(&drep);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_drep_t* cardano_stake_vote_delegation_cert_get_drep(cardano_stake_vote_delegation_cert_t* certificate);++/**+ * \brief Sets the DREP for a stake vote delegation certificate.+ *+ * This function assigns a new DREP to the specified \ref cardano_stake_vote_delegation_cert_t object.+ * The DREP object represents the delegated representative to which voting rights are being assigned.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_stake_vote_delegation_cert_t object where the DREP will be set.+ * \param[in] drep A pointer to an initialized \ref cardano_drep_t object to be assigned to the certificate.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the DREP was successfully set,+ *         or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * \note This function increments the reference count of the \p drep object, so it remains managed by both the caller and the certificate.+ *       It is the caller's responsibility to unreference their own copy of \p drep when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_drep_t* drep = ...; // Assume drep is already initialized+ *+ * cardano_error_t result = cardano_stake_vote_delegation_cert_set_drep(certificate, drep);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The drep is now set for the certificate+ * }+ * else+ * {+ *   printf("Failed to set the drep.\n");+ * }+ *+ * cardano_drep_unref(&drep); // Cleanup the drep reference owned by the caller+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_delegation_cert_set_drep(cardano_stake_vote_delegation_cert_t* certificate, cardano_drep_t* drep);++/**+ * \brief Decrements the reference count of a cardano_stake_vote_delegation_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_stake_vote_delegation_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the stake_registration is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] stake_registration A pointer to the pointer of the stake_registration object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_delegation_cert_t* stake_registration = cardano_stake_vote_delegation_cert_new(major, minor);+ *+ * // Perform operations with the stake_registration...+ *+ * cardano_stake_vote_delegation_cert_unref(&stake_registration);+ * // At this point, stake_registration is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_stake_vote_delegation_cert_unref, the pointer to the \ref cardano_stake_vote_delegation_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_stake_vote_delegation_cert_unref(cardano_stake_vote_delegation_cert_t** stake_registration);++/**+ * \brief Increases the reference count of the cardano_stake_vote_delegation_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_stake_vote_delegation_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_stake_vote_delegation_cert_unref.+ *+ * \param stake_registration A pointer to the cardano_stake_vote_delegation_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_registration is a previously created stake_registration object+ *+ * cardano_stake_vote_delegation_cert_ref(stake_registration);+ *+ * // Now stake_registration can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_stake_vote_delegation_cert_ref there is a corresponding+ * call to \ref cardano_stake_vote_delegation_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_stake_vote_delegation_cert_ref(cardano_stake_vote_delegation_cert_t* stake_registration);++/**+ * \brief Retrieves the current reference count of the cardano_stake_vote_delegation_cert_t object.+ *+ * This function returns the number of active references to an cardano_stake_vote_delegation_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_stake_vote_delegation_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param stake_registration A pointer to the cardano_stake_vote_delegation_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_stake_vote_delegation_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_stake_vote_delegation_cert_ref call is matched with a+ * \ref cardano_stake_vote_delegation_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_registration is a previously created stake_registration object+ *+ * size_t ref_count = cardano_stake_vote_delegation_cert_refcount(stake_registration);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_stake_vote_delegation_cert_refcount(const cardano_stake_vote_delegation_cert_t* stake_registration);++/**+ * \brief Sets the last error message for a given cardano_stake_vote_delegation_cert_t object.+ *+ * Records an error message in the stake_registration's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] stake_registration A pointer to the \ref cardano_stake_vote_delegation_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the stake_registration's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_stake_vote_delegation_cert_set_last_error(+  cardano_stake_vote_delegation_cert_t* stake_registration,+  const char*                           message);++/**+ * \brief Retrieves the last error message recorded for a specific stake_registration.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_stake_vote_delegation_cert_set_last_error for the given+ * stake_registration. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] stake_registration A pointer to the \ref cardano_stake_vote_delegation_cert_t instance whose last error+ *                   message is to be retrieved. If the stake_registration is NULL, the function+ *                   returns a generic error message indicating the null stake_registration.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified stake_registration. If the stake_registration is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_stake_vote_delegation_cert_set_last_error for the same stake_registration, or until+ *       the stake_registration is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_stake_vote_delegation_cert_get_last_error(+  const cardano_stake_vote_delegation_cert_t* stake_registration);++/**+ * \brief Creates an independent deep copy of a \ref cardano_stake_vote_delegation_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_stake_vote_delegation_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_delegation_cert_deep_clone(const cardano_stake_vote_delegation_cert_t* source, cardano_stake_vote_delegation_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // STAKE_VOTE_DELEGATION_CERT_H
+ vendor/include/cardano/certs/stake_vote_registration_delegation_cert.h view
@@ -0,0 +1,627 @@+/**+ * \file stake_vote_registration_delegation_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef STAKE_VOTE_REGISTRATION_DELEGATION_CERT_H+#define STAKE_VOTE_REGISTRATION_DELEGATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/common/drep.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used when an individual wants to register its stake key,+ * delegate their voting rights to any other DRep and simultaneously wants to delegate+ * their stake to a specific stake pool.+ */+typedef struct cardano_stake_vote_registration_delegation_cert_t cardano_stake_vote_registration_delegation_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new stake vote registration delegation certificate.+ *+ * This function allocates and initializes a new instance of \ref cardano_stake_vote_registration_delegation_cert_t.+ * This certificate combines stake registration with a delegation of voting rights to a delegated representative (DREP)+ * and a specific staking pool, setting the groundwork for participation in governance and staking rewards.+ *+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stake credential.+ * \param[in] deposit The deposit amount required for registration, which is specified by network protocol parameters.+ * \param[in] drep A pointer to an initialized \ref cardano_drep_t object representing the delegated representative.+ * \param[in] pool_key_hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the pool's key hash.+ * \param[out] vote_registration_delegation On successful execution, this will point to a newly created+ *                                          \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate+ *         was successfully created, or an appropriate error code indicating the reason for failure+ *         (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume credential is initialized+ * uint64_t deposit = ...; // Deposit required for registration+ * cardano_drep_t* drep = ...; // Assume drep is initialized+ * cardano_blake2b_hash_t* pool_key_hash = ...; // Assume pool key hash is initialized+ * cardano_stake_vote_registration_delegation_cert_t* vote_registration_delegation = NULL;+ *+ * cardano_error_t result = cardano_stake_vote_registration_delegation_cert_new(+ *     credential, deposit, drep, pool_key_hash, &vote_registration_delegation);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the vote registration delegation certificate+ *   // Remember to free the certificate when done+ *   cardano_stake_vote_registration_delegation_cert_unref(&vote_registration_delegation);+ * }+ * else+ * {+ *   printf("Failed to create stake vote registration delegation certificate: %s\n",+ *          cardano_error_to_string(result));+ * }+ * \endcode+ *+ * \note This function increments the reference count for the credential, drep, and pool_key_hash objects.+ *       It is the responsibility of the caller to manage these references and release them when they are no longer needed.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_registration_delegation_cert_new(+  cardano_credential_t*                               credential,+  uint64_t                                            deposit,+  cardano_drep_t*                                     drep,+  cardano_blake2b_hash_t*                             pool_key_hash,+  cardano_stake_vote_registration_delegation_cert_t** vote_registration_delegation);++/**+ * \brief Creates a \ref cardano_stake_vote_registration_delegation_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_stake_vote_registration_delegation_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a stake_registration.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] stake_registration A pointer to a pointer of \ref cardano_stake_vote_registration_delegation_cert_t that will be set to the address+ *                        of the newly created stake_registration object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_stake_vote_registration_delegation_cert_t object by calling+ *       \ref cardano_stake_vote_registration_delegation_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_stake_vote_registration_delegation_cert_t* stake_registration = NULL;+ *+ * cardano_error_t result = cardano_stake_vote_registration_delegation_cert_from_cbor(reader, &stake_registration);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the stake_registration+ *+ *   // Once done, ensure to clean up and release the stake_registration+ *   cardano_stake_vote_registration_delegation_cert_unref(&stake_registration);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode stake_registration: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_registration_delegation_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_stake_vote_registration_delegation_cert_t** stake_registration);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_stake_vote_registration_delegation_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] stake_registration A constant pointer to the \ref cardano_stake_vote_registration_delegation_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p stake_registration or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_registration_delegation_cert_t* stake_registration = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_stake_vote_registration_delegation_cert_to_cbor(stake_registration, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_stake_vote_registration_delegation_cert_unref(&stake_registration);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_stake_vote_registration_delegation_cert_to_cbor(+  const cardano_stake_vote_registration_delegation_cert_t* stake_registration,+  cardano_cbor_writer_t*                                   writer);++/**+ * \brief Serializes a stake vote registration delegation certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "credential", "pool_keyhash", "drep", "coin".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_stake_vote_registration_delegation_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p cert or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_registration_delegation_cert_to_cip116_json(+  const cardano_stake_vote_registration_delegation_cert_t* cert,+  cardano_json_writer_t*                                   writer);++/**+ * \brief Retrieves the stake credential from a stake vote registration delegation certificate.+ *+ * This function extracts the stake credential from a given \ref cardano_stake_vote_registration_delegation_cert_t object.+ * The credential identifies the stakeholder in the context of the Cardano network.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \return A pointer to a \ref cardano_credential_t object containing the stake credential. If the input certificate is NULL,+ *         or if the credential is not set, this function returns NULL.+ *+ * \note The returned \ref cardano_credential_t object is a new reference and must be managed by the caller.+ *       It should be released using \ref cardano_credential_unref when no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = cardano_stake_vote_registration_delegation_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   // Remember to release the credential reference when done+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   printf("Failed to retrieve credential or certificate is not initialized properly.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_stake_vote_registration_delegation_cert_get_credential(cardano_stake_vote_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the stake credential for a stake vote registration delegation certificate.+ *+ * This function assigns a stake credential to a given \ref cardano_stake_vote_registration_delegation_cert_t object.+ * The credential identifies the stakeholder in the context of the Cardano network.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_stake_vote_registration_delegation_cert_t object+ *                            where the stake credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stake credential.+ *                       This function increments the reference count of the credential, and the caller remains responsible+ *                       for releasing their own reference.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the stake credential+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_stake_vote_registration_delegation_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Credential successfully set.\n");+ * }+ * else+ * {+ *   printf("Failed to set the credential: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Cleanup performed elsewhere for credential+ * \endcode+ *+ * \note After setting, the certificate holds its own reference to the credential. The caller+ *       must manage and release its own references to the credential object.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_registration_delegation_cert_set_credential(cardano_stake_vote_registration_delegation_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the pool key hash from a stake vote registration delegation certificate.+ *+ * This function extracts the pool key hash from the specified \ref cardano_stake_vote_registration_delegation_cert_t object.+ * The pool key hash is used to identify the stake pool to which the delegation is directed in the Cardano network.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \return A pointer to the \ref cardano_blake2b_hash_t object containing the pool key hash. If the certificate is NULL or+ *         if the pool key hash is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_blake2b_hash_t* pool_key_hash = cardano_stake_vote_registration_delegation_cert_get_pool_key_hash(certificate);+ *+ * if (pool_key_hash != NULL)+ * {+ *   // Process the pool key hash+ *   cardano_blake2b_hash_unref(&pool_key_hash); // Clean up the reference when done+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_stake_vote_registration_delegation_cert_get_pool_key_hash(cardano_stake_vote_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the pool key hash for a stake vote registration delegation certificate.+ *+ * This function assigns a pool key hash to the specified \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_stake_vote_registration_delegation_cert_t object where the pool key hash will be set.+ * \param[in] hash A pointer to an initialized \ref cardano_blake2b_hash_t object representing the pool key hash. This function increments the reference+ *                 count of the hash, and the caller is responsible for releasing their reference to the hash object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the pool key hash+ *         was successfully set, or an appropriate error code indicating the reason for failure, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_blake2b_hash_t* hash = ...; // Assume hash is already initialized+ *+ * cardano_error_t result = cardano_stake_vote_registration_delegation_cert_set_pool_key_hash(certificate, hash);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Pool key hash set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the pool key hash.\n");+ * }+ *+ * // Cleanup+ * cardano_blake2b_hash_unref(&pool_key_hash); // Clean up the reference when done+ * \endcode+ *+ * \note After setting, the certificate holds its own reference to the hash. The caller+ *       must manage and release its own references to the hash object.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_registration_delegation_cert_set_pool_key_hash(cardano_stake_vote_registration_delegation_cert_t* certificate, cardano_blake2b_hash_t* hash);++/**+ * \brief Retrieves the DRep associated with a stake vote registration delegation certificate.+ *+ * This function extracts the DRep from the specified \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \return A pointer to a new \ref cardano_drep_t object containing the DRep. The caller is responsible+ *         for managing the lifecycle of this returned DRep object, including releasing it using \ref cardano_drep_unref+ *         when it is no longer needed. If the certificate is NULL or if the DRep is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_stake_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_drep_t* drep = cardano_stake_vote_registration_delegation_cert_get_drep(certificate);+ *+ * if (drep != NULL)+ * {+ *   // Process the DRep+ *   // Remember to free the DRep when done+ *   cardano_drep_unref(&drep);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_drep_t* cardano_stake_vote_registration_delegation_cert_get_drep(cardano_stake_vote_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the DRep for a stake vote registration delegation certificate.+ *+ * This function assigns a DRep to the specified \ref cardano_stake_vote_registration_delegation_cert_t object.+ * The DRep is essential for representing delegate participation in the governance process within the Cardano network.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_stake_vote_registration_delegation_cert_t object which will receive the DRep.+ * \param[in] drep A pointer to an initialized \ref cardano_drep_t object to be set on the certificate. This function increments the reference+ *                 count of the DRep, and the caller is still responsible for releasing their reference to the DRep object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the DRep was successfully set,+ *         or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_drep_t* drep = ...; // Assume drep is already initialized+ *+ * cardano_error_t result = cardano_stake_vote_registration_delegation_cert_set_drep(certificate, drep);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The DRep is now set for the certificate+ * }+ * else+ * {+ *   printf("Failed to set the DRep.\n");+ * }+ *+ * // Both certificate and drep need their references managed appropriately+ * cardano_drep_unref(&drep);+ * \endcode+ *+ * \note This function increments the reference count of the drep argument, the caller must manage their own reference to it.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_registration_delegation_cert_set_drep(cardano_stake_vote_registration_delegation_cert_t* certificate, cardano_drep_t* drep);++/**+ * \brief Retrieves the deposit amount from a stake vote registration delegation certificate.+ *+ * This function fetches the deposit amount that has been set on a \ref cardano_stake_vote_registration_delegation_cert_t object.+ * The deposit is a fixed amount required as part of the registration process, acting as a security measure within the Cardano network.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \return The deposit amount set on the certificate. If the certificate is NULL, the function returns 0,+ *         which should be checked against possible error returns in real scenarios.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ *+ * uint64_t deposit = cardano_stake_vote_registration_delegation_cert_get_deposit(certificate);+ * printf("Deposit amount: %llu ADA\n", deposit);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_stake_vote_registration_delegation_cert_get_deposit(const cardano_stake_vote_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the deposit amount on a stake vote registration delegation certificate.+ *+ * This function updates the deposit amount for a \ref cardano_stake_vote_registration_delegation_cert_t object.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_stake_vote_registration_delegation_cert_t object on which+ *                            the deposit amount will be set.+ * \param[in] deposit The deposit amount to be set on the certificate. This amount should align with the protocol's current requirements.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the deposit amount+ *         was successfully updated, or an appropriate error code indicating the reason for failure, such as+ *         \ref CARDANO_ERROR_POINTER_IS_NULL if the certificate pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = 1000000; // 1 ADA, example deposit amount+ *+ * cardano_error_t result = cardano_stake_vote_registration_delegation_cert_set_deposit(certificate, deposit);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Deposit amount updated successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set deposit amount.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_registration_delegation_cert_set_deposit(cardano_stake_vote_registration_delegation_cert_t* certificate, uint64_t deposit);++/**+ * \brief Decrements the reference count of a cardano_stake_vote_registration_delegation_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_stake_vote_registration_delegation_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the stake_registration is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] stake_registration A pointer to the pointer of the stake_registration object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_stake_vote_registration_delegation_cert_t* stake_registration = cardano_stake_vote_registration_delegation_cert_new(major, minor);+ *+ * // Perform operations with the stake_registration...+ *+ * cardano_stake_vote_registration_delegation_cert_unref(&stake_registration);+ * // At this point, stake_registration is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_stake_vote_registration_delegation_cert_unref, the pointer to the \ref cardano_stake_vote_registration_delegation_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_stake_vote_registration_delegation_cert_unref(cardano_stake_vote_registration_delegation_cert_t** stake_registration);++/**+ * \brief Increases the reference count of the cardano_stake_vote_registration_delegation_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_stake_vote_registration_delegation_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_stake_vote_registration_delegation_cert_unref.+ *+ * \param stake_registration A pointer to the cardano_stake_vote_registration_delegation_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_registration is a previously created stake_registration object+ *+ * cardano_stake_vote_registration_delegation_cert_ref(stake_registration);+ *+ * // Now stake_registration can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_stake_vote_registration_delegation_cert_ref there is a corresponding+ * call to \ref cardano_stake_vote_registration_delegation_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_stake_vote_registration_delegation_cert_ref(cardano_stake_vote_registration_delegation_cert_t* stake_registration);++/**+ * \brief Retrieves the current reference count of the cardano_stake_vote_registration_delegation_cert_t object.+ *+ * This function returns the number of active references to an cardano_stake_vote_registration_delegation_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_stake_vote_registration_delegation_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param stake_registration A pointer to the cardano_stake_vote_registration_delegation_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_stake_vote_registration_delegation_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_stake_vote_registration_delegation_cert_ref call is matched with a+ * \ref cardano_stake_vote_registration_delegation_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming stake_registration is a previously created stake_registration object+ *+ * size_t ref_count = cardano_stake_vote_registration_delegation_cert_refcount(stake_registration);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_stake_vote_registration_delegation_cert_refcount(const cardano_stake_vote_registration_delegation_cert_t* stake_registration);++/**+ * \brief Sets the last error message for a given cardano_stake_vote_registration_delegation_cert_t object.+ *+ * Records an error message in the stake_registration's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] stake_registration A pointer to the \ref cardano_stake_vote_registration_delegation_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the stake_registration's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_stake_vote_registration_delegation_cert_set_last_error(+  cardano_stake_vote_registration_delegation_cert_t* stake_registration,+  const char*                                        message);++/**+ * \brief Retrieves the last error message recorded for a specific stake_registration.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_stake_vote_registration_delegation_cert_set_last_error for the given+ * stake_registration. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] stake_registration A pointer to the \ref cardano_stake_vote_registration_delegation_cert_t instance whose last error+ *                   message is to be retrieved. If the stake_registration is NULL, the function+ *                   returns a generic error message indicating the null stake_registration.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified stake_registration. If the stake_registration is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_stake_vote_registration_delegation_cert_set_last_error for the same stake_registration, or until+ *       the stake_registration is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_stake_vote_registration_delegation_cert_get_last_error(+  const cardano_stake_vote_registration_delegation_cert_t* stake_registration);++/**+ * \brief Creates an independent deep copy of a \ref cardano_stake_vote_registration_delegation_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_stake_vote_registration_delegation_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_stake_vote_registration_delegation_cert_deep_clone(const cardano_stake_vote_registration_delegation_cert_t* source, cardano_stake_vote_registration_delegation_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // STAKE_VOTE_REGISTRATION_DELEGATION_CERT_H
+ vendor/include/cardano/certs/unregister_drep_cert.h view
@@ -0,0 +1,482 @@+/**+ * \file unregister_drep_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef UNREGISTER_DREP_CERT_H+#define UNREGISTER_DREP_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate unregister an individual as a DRep.+ *+ * Note that a DRep is retired immediately upon the chain accepting a retirement certificate, and+ * the deposit is returned as part of the transaction that submits the retirement certificate+ * (the same way that stake credential registration deposits are returned).+ */+typedef struct cardano_unregister_drep_cert_t cardano_unregister_drep_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new unregistration certificate for a DRep in the Cardano blockchain.+ *+ * This function allocates and initializes a new \ref cardano_unregister_drep_cert_t object, which is used+ * to unregister a DRep. The certificate includes the stake credential associated with the DRep and+ * a deposit amount that might be refunded upon successful unregistration.+ *+ * \param[in] credential A pointer to a \ref cardano_credential_t object representing the stake credential+ *                       of the DRep. This credential must have been previously registered.+ * \param[in] deposit The deposit amount that was originally paid during the registration of the DRep.+ *                    This deposit may be refunded upon successful unregistration.+ * \param[out] unregister_drep On successful execution, this will point to a newly created+ *                             \ref cardano_unregister_drep_cert_t object. The caller is responsible for+ *                             managing the lifecycle of this object, which includes freeing it when it's+ *                             no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the+ *         unregistration certificate was successfully created, or an appropriate error code indicating+ *         the failure reason (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL if any input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ * uint64_t deposit = 1000000; // Example deposit amount+ *+ * cardano_unregister_drep_cert_t* unregister_cert = NULL;+ * cardano_error_t result = cardano_unregister_drep_cert_new(credential, deposit, &unregister_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The unregistration certificate can now be used to unregister the DRep+ *   // Remember to free the unregister_cert when done+ *   cardano_unregister_drep_cert_unref(&unregister_cert);+ * }+ * else+ * {+ *   printf("Failed to create DRep unregistration certificate: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregister_drep_cert_new(+  cardano_credential_t*            credential,+  uint64_t                         deposit,+  cardano_unregister_drep_cert_t** unregister_drep);++/**+ * \brief Creates a \ref cardano_unregister_drep_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_unregister_drep_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a unregister_drep_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] unregister_drep_cert A pointer to a pointer of \ref cardano_unregister_drep_cert_t that will be set to the address+ *                        of the newly created unregister_drep_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_unregister_drep_cert_t object by calling+ *       \ref cardano_unregister_drep_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_unregister_drep_cert_t* unregister_drep_cert = NULL;+ *+ * cardano_error_t result = cardano_unregister_drep_cert_from_cbor(reader, &unregister_drep_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the unregister_drep_cert+ *+ *   // Once done, ensure to clean up and release the unregister_drep_cert+ *   cardano_unregister_drep_cert_unref(&unregister_drep_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode unregister_drep_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregister_drep_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_unregister_drep_cert_t** unregister_drep_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_unregister_drep_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] unregister_drep_cert A constant pointer to the \ref cardano_unregister_drep_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p unregister_drep_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregister_drep_cert_t* unregister_drep_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_unregister_drep_cert_to_cbor(unregister_drep_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_unregister_drep_cert_unref(&unregister_drep_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_unregister_drep_cert_to_cbor(+  const cardano_unregister_drep_cert_t* unregister_drep_cert,+  cardano_cbor_writer_t*                writer);++/**+ * \brief Serializes an unregister DRep certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "drep_credential", "coin".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_unregister_drep_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                 On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregister_drep_cert_to_cip116_json(+  const cardano_unregister_drep_cert_t* cert,+  cardano_json_writer_t*                writer);++/**+ * \brief Retrieves the stake credential associated with a DRep unregistration certificate.+ *+ * This function extracts the stake credential from a given \ref cardano_unregister_drep_cert_t object.+ * The credential is used to identify the DRep that is being unregistered.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_unregister_drep_cert_t object.+ *+ * \return A pointer to the \ref cardano_credential_t object containing the stake credential. If the+ *         certificate is NULL or if the credential is not set, this function returns NULL. This returned+ *         object is a new reference and must be released with \ref cardano_credential_unref by the caller when+ *         it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_unregister_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_credential_t* credential = cardano_unregister_drep_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   cardano_credential_unref(&credential);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_unregister_drep_cert_get_credential(cardano_unregister_drep_cert_t* certificate);++/**+ * \brief Sets the stake credential for a DRep unregistration certificate.+ *+ * This function assigns a new stake credential to a specified \ref cardano_unregister_drep_cert_t object.+ * The credential is crucial for identifying the DRep that is to be unregistered.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_unregister_drep_cert_t object.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object. This function increments+ *                       the reference count of the credential, and it will be decremented when the certificate+ *                       no longer uses it or when the certificate is freed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the+ *         credential was successfully set, or an appropriate error code indicating the failure reason, such as+ *         \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregister_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_unregister_drep_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Credential set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the credential.\n");+ * }+ *+ * // Cleanup resources as necessary+ * cardano_credential_unref(&credential); // If no longer needed elsewhere+ * cardano_unregister_drep_cert_unref(&certificate); // After use+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregister_drep_cert_set_credential(cardano_unregister_drep_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the deposit amount from an unregistration DRep certificate.+ *+ * This function gets the deposit amount that was associated with the DRep unregistration. This amount+ * represents the funds that were originally locked during the registration and are now subject to refund+ * upon successful unregistration.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_unregister_drep_cert_t object.+ *+ * \return The deposit amount as a uint64_t. Returns 0 if the certificate pointer is NULL or if no deposit+ *         was recorded.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_unregister_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = cardano_unregister_drep_cert_get_deposit(certificate);+ * printf("Deposit amount: %llu ADA\n", deposit);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_unregister_drep_cert_get_deposit(const cardano_unregister_drep_cert_t* certificate);++/**+ * \brief Sets the deposit amount for an unregistration DRep certificate.+ *+ * This function sets the deposit amount in the specified \ref cardano_unregister_drep_cert_t object.+ * The deposit is the amount of funds that will be locked until the unregistration process is completed.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_unregister_drep_cert_t object.+ * \param[in] deposit The deposit amount to be set, expressed in lovelace (1 ADA = 1,000,000 lovelace).+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the deposit was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if the certificate pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregister_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = 1500000; // 1.5 ADA in lovelace+ *+ * cardano_error_t result = cardano_unregister_drep_cert_set_deposit(certificate, deposit);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Deposit set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set deposit: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregister_drep_cert_set_deposit(cardano_unregister_drep_cert_t* certificate, uint64_t deposit);++/**+ * \brief Decrements the reference count of a cardano_unregister_drep_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_unregister_drep_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the unregister_drep_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] unregister_drep_cert A pointer to the pointer of the unregister_drep_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregister_drep_cert_t* unregister_drep_cert = cardano_unregister_drep_cert_new(major, minor);+ *+ * // Perform operations with the unregister_drep_cert...+ *+ * cardano_unregister_drep_cert_unref(&unregister_drep_cert);+ * // At this point, unregister_drep_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_unregister_drep_cert_unref, the pointer to the \ref cardano_unregister_drep_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_unregister_drep_cert_unref(cardano_unregister_drep_cert_t** unregister_drep_cert);++/**+ * \brief Increases the reference count of the cardano_unregister_drep_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_unregister_drep_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_unregister_drep_cert_unref.+ *+ * \param unregister_drep_cert A pointer to the cardano_unregister_drep_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming unregister_drep_cert is a previously created unregister_drep_cert object+ *+ * cardano_unregister_drep_cert_ref(unregister_drep_cert);+ *+ * // Now unregister_drep_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_unregister_drep_cert_ref there is a corresponding+ * call to \ref cardano_unregister_drep_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_unregister_drep_cert_ref(cardano_unregister_drep_cert_t* unregister_drep_cert);++/**+ * \brief Retrieves the current reference count of the cardano_unregister_drep_cert_t object.+ *+ * This function returns the number of active references to an cardano_unregister_drep_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_unregister_drep_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param unregister_drep_cert A pointer to the cardano_unregister_drep_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_unregister_drep_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_unregister_drep_cert_ref call is matched with a+ * \ref cardano_unregister_drep_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming unregister_drep_cert is a previously created unregister_drep_cert object+ *+ * size_t ref_count = cardano_unregister_drep_cert_refcount(unregister_drep_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_unregister_drep_cert_refcount(const cardano_unregister_drep_cert_t* unregister_drep_cert);++/**+ * \brief Sets the last error message for a given cardano_unregister_drep_cert_t object.+ *+ * Records an error message in the unregister_drep_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] unregister_drep_cert A pointer to the \ref cardano_unregister_drep_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the unregister_drep_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_unregister_drep_cert_set_last_error(+  cardano_unregister_drep_cert_t* unregister_drep_cert,+  const char*                     message);++/**+ * \brief Retrieves the last error message recorded for a specific unregister_drep_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_unregister_drep_cert_set_last_error for the given+ * unregister_drep_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] unregister_drep_cert A pointer to the \ref cardano_unregister_drep_cert_t instance whose last error+ *                   message is to be retrieved. If the unregister_drep_cert is NULL, the function+ *                   returns a generic error message indicating the null unregister_drep_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified unregister_drep_cert. If the unregister_drep_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_unregister_drep_cert_set_last_error for the same unregister_drep_cert, or until+ *       the unregister_drep_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_unregister_drep_cert_get_last_error(+  const cardano_unregister_drep_cert_t* unregister_drep_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_unregister_drep_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_unregister_drep_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_unregister_drep_cert_deep_clone(const cardano_unregister_drep_cert_t* source, cardano_unregister_drep_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // UNREGISTER_DREP_CERT_H
+ vendor/include/cardano/certs/unregistration_cert.h view
@@ -0,0 +1,482 @@+/**+ * \file unregistration_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef UNREGISTRATION_CERT_H+#define UNREGISTRATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used when a stakeholder no longer wants to participate in+ * staking. It revokes the stake Unregistration and the associated stake is no+ * longer counted when calculating stake pool rewards.+ *+ * Deposit must match the expected deposit amount specified by `ppKeyDepositL` in+ * the protocol parameters.+ *+ * \remark Replaces the deprecated \c cardano_stake_registration_cert_t after Conway era.+ */+typedef struct cardano_unregistration_cert_t cardano_unregistration_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new unregistration certificate.+ *+ * This function allocates and initializes a new unregistration certificate. The certificate is used to unregister a stake key,+ * removing it from the blockchain and reclaiming any deposits associated with it.+ *+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stake credential.+ * \param[in] deposit The amount of deposit to be refunded upon successful unregistration, expressed in lovelace (1 ADA = 1,000,000 lovelace).+ * \param[out] unregistration On successful execution, this will point to a newly created \ref cardano_unregistration_cert_t object.+ *                             The caller is responsible for managing the lifecycle of this object and must release it using+ *                             \ref cardano_unregistration_cert_unref when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was+ *         successfully created, or an appropriate error code indicating the reason for failure (e.g., \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL).+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ * uint64_t deposit = 2000000; // 2 ADA in lovelace+ * cardano_unregistration_cert_t* unregistration = NULL;+ *+ * cardano_error_t result = cardano_unregistration_cert_new(credential, deposit, &unregistration);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The unregistration certificate can now be used for blockchain transactions+ *   // Remember to free the unregistration certificate when done+ *   cardano_unregistration_cert_unref(&unregistration);+ * }+ * else+ * {+ *   printf("Failed to create unregistration certificate: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregistration_cert_new(+  cardano_credential_t*           credential,+  uint64_t                        deposit,+  cardano_unregistration_cert_t** unregistration);++/**+ * \brief Creates a \ref cardano_unregistration_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_unregistration_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a unregistration_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] unregistration_cert A pointer to a pointer of \ref cardano_unregistration_cert_t that will be set to the address+ *                        of the newly created unregistration_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_unregistration_cert_t object by calling+ *       \ref cardano_unregistration_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_unregistration_cert_t* unregistration_cert = NULL;+ *+ * cardano_error_t result = cardano_unregistration_cert_from_cbor(reader, &unregistration_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the unregistration_cert+ *+ *   // Once done, ensure to clean up and release the unregistration_cert+ *   cardano_unregistration_cert_unref(&unregistration_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode unregistration_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregistration_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_unregistration_cert_t** unregistration_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_unregistration_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] unregistration_cert A constant pointer to the \ref cardano_unregistration_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p unregistration_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregistration_cert_t* unregistration_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_unregistration_cert_to_cbor(unregistration_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_unregistration_cert_unref(&unregistration_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_unregistration_cert_to_cbor(+  const cardano_unregistration_cert_t* unregistration_cert,+  cardano_cbor_writer_t*               writer);++/**+ * \brief Serializes an unregistration certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "credential", "coin".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_unregistration_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregistration_cert_to_cip116_json(+  const cardano_unregistration_cert_t* cert,+  cardano_json_writer_t*               writer);++/**+ * \brief Retrieves the credential associated with an unregistration certificate.+ *+ * This function fetches the credential from a given \ref cardano_unregistration_cert_t object. The credential indicates+ * the stake key being unregistered.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_unregistration_cert_t object.+ *+ * \return A pointer to the \ref cardano_credential_t object representing the stake credential. If the input certificate+ *         pointer is NULL or the certificate does not contain a credential, this function returns NULL.+ *         Note that the returned credential is a new reference and must be released using \ref cardano_credential_unref+ *         when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_unregistration_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = cardano_unregistration_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   printf("No credential found or invalid certificate.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_unregistration_cert_get_credential(cardano_unregistration_cert_t* certificate);++/**+ * \brief Sets the credential for an unregistration certificate.+ *+ * This function assigns a new stake credential to a \ref cardano_unregistration_cert_t object.+ * The credential specifies the stake key to be unregistered.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_unregistration_cert_t object to which the credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stake credential to be unregistered.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the credential+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * \note This function increases the reference count of the credential object; therefore, the caller retain ownership of their respective references.+ *       It is the caller's responsibility to release their reference to the credential when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregistration_cert_t* unregistration_cert = ...; // Assume unregistration_cert is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is initialized+ *+ * cardano_error_t result = cardano_unregistration_cert_set_credential(unregistration_cert, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The credential is now set for the unregistration_cert+ * }+ * else+ * {+ *   printf("Failed to set the credential.\n");+ * }+ *+ * // Clean up resources+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregistration_cert_set_credential(cardano_unregistration_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the deposit amount from an unregistration certificate.+ *+ * This function retrieves the deposit amount that was associated with the unregistration certificate+ * at the time of its creation.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_unregistration_cert_t object.+ *+ * \return The deposit amount in lovelaces. If the certificate is NULL, the function will return 0, which should be+ *         handled appropriately by the caller to distinguish from a genuine deposit of 0 lovelaces.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_unregistration_cert_t* unregistration_cert = ...; // Assume unregistration_cert is already initialized+ *+ * uint64_t deposit = cardano_unregistration_cert_get_deposit(unregistration_cert);+ * printf("Deposit for unregistration: %llu lovelaces\n", deposit);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_unregistration_cert_get_deposit(const cardano_unregistration_cert_t* certificate);++/**+ * \brief Sets the deposit amount for an unregistration certificate.+ *+ * This function sets the deposit amount required for unregistration of a stake credential.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_unregistration_cert_t object to which the deposit amount will be set.+ * \param[in] deposit The deposit amount in lovelaces to set for the unregistration.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the deposit amount was successfully set, or an appropriate error code indicating the failure reason,+ *         such as \ref CARDANO_ERROR_POINTER_IS_NULL if the input certificate pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregistration_cert_t* unregistration_cert = ...; // Assume unregistration_cert is already initialized+ * uint64_t deposit = 2000000;+ *+ * cardano_error_t result = cardano_unregistration_cert_set_deposit(unregistration_cert, deposit);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Deposit set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set deposit.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unregistration_cert_set_deposit(cardano_unregistration_cert_t* certificate, uint64_t deposit);++/**+ * \brief Decrements the reference count of a cardano_unregistration_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_unregistration_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the unregistration_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] unregistration_cert A pointer to the pointer of the unregistration_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unregistration_cert_t* unregistration_cert = cardano_unregistration_cert_new(major, minor);+ *+ * // Perform operations with the unregistration_cert...+ *+ * cardano_unregistration_cert_unref(&unregistration_cert);+ * // At this point, unregistration_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_unregistration_cert_unref, the pointer to the \ref cardano_unregistration_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_unregistration_cert_unref(cardano_unregistration_cert_t** unregistration_cert);++/**+ * \brief Increases the reference count of the cardano_unregistration_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_unregistration_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_unregistration_cert_unref.+ *+ * \param unregistration_cert A pointer to the cardano_unregistration_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming unregistration_cert is a previously created unregistration_cert object+ *+ * cardano_unregistration_cert_ref(unregistration_cert);+ *+ * // Now unregistration_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_unregistration_cert_ref there is a corresponding+ * call to \ref cardano_unregistration_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_unregistration_cert_ref(cardano_unregistration_cert_t* unregistration_cert);++/**+ * \brief Retrieves the current reference count of the cardano_unregistration_cert_t object.+ *+ * This function returns the number of active references to an cardano_unregistration_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_unregistration_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param unregistration_cert A pointer to the cardano_unregistration_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_unregistration_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_unregistration_cert_ref call is matched with a+ * \ref cardano_unregistration_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming unregistration_cert is a previously created unregistration_cert object+ *+ * size_t ref_count = cardano_unregistration_cert_refcount(unregistration_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_unregistration_cert_refcount(const cardano_unregistration_cert_t* unregistration_cert);++/**+ * \brief Sets the last error message for a given cardano_unregistration_cert_t object.+ *+ * Records an error message in the unregistration_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] unregistration_cert A pointer to the \ref cardano_unregistration_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the unregistration_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_unregistration_cert_set_last_error(+  cardano_unregistration_cert_t* unregistration_cert,+  const char*                    message);++/**+ * \brief Retrieves the last error message recorded for a specific unregistration_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_unregistration_cert_set_last_error for the given+ * unregistration_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] unregistration_cert A pointer to the \ref cardano_unregistration_cert_t instance whose last error+ *                   message is to be retrieved. If the unregistration_cert is NULL, the function+ *                   returns a generic error message indicating the null unregistration_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified unregistration_cert. If the unregistration_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_unregistration_cert_set_last_error for the same unregistration_cert, or until+ *       the unregistration_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_unregistration_cert_get_last_error(+  const cardano_unregistration_cert_t* unregistration_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_unregistration_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_unregistration_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_unregistration_cert_deep_clone(const cardano_unregistration_cert_t* source, cardano_unregistration_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // UNREGISTRATION_CERT_H
+ vendor/include/cardano/certs/update_drep_cert.h view
@@ -0,0 +1,468 @@+/**+ * \file update_drep_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef UPDATE_DREP_CERT_H+#define UPDATE_DREP_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/anchor.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Updates the DRep anchored metadata.+ */+typedef struct cardano_update_drep_cert_t cardano_update_drep_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new update drep certificate.+ *+ * This function allocates and initializes a new update drep certificate, which is used to propose updates to the drep.+ *+ * \param[in] credential A pointer to an initialized cardano_credential_t object representing the credential.+ * \param[in] anchor A pointer to an initialized cardano_anchor_t object that specifies the context or the anchor point for this update.+ * \param[out] update_drep_cert A pointer to a pointer where the newly created cardano_update_drep_cert_t object will be stored.+ *+ * \return \c cardano_error_t indicating the outcome of the operation. Returns \c CARDANO_SUCCESS if the certificate was successfully created.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume initialized+ * cardano_anchor_t* anchor = ...; // Assume initialized+ * cardano_update_drep_cert_t* update_drep_cert = NULL;+ * cardano_error_t result = cardano_update_drep_cert_new(credential, anchor, &update_drep_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the update_drep_cert+ *   // Free resources when done+ *   cardano_update_drep_cert_unref(&update_drep_cert);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_update_drep_cert_new(+  cardano_credential_t*        credential,+  cardano_anchor_t*            anchor,+  cardano_update_drep_cert_t** update_drep_cert);++/**+ * \brief Creates a \ref cardano_update_drep_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_update_drep_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a update_drep_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] update_drep_cert A pointer to a pointer of \ref cardano_update_drep_cert_t that will be set to the address+ *                        of the newly created update_drep_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_update_drep_cert_t object by calling+ *       \ref cardano_update_drep_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_update_drep_cert_t* update_drep_cert = NULL;+ *+ * cardano_error_t result = cardano_update_drep_cert_from_cbor(reader, &update_drep_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the update_drep_cert+ *+ *   // Once done, ensure to clean up and release the update_drep_cert+ *   cardano_update_drep_cert_unref(&update_drep_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode update_drep_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_update_drep_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_update_drep_cert_t** update_drep_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_update_drep_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] update_drep_cert A constant pointer to the \ref cardano_update_drep_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p update_drep_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_update_drep_cert_t* update_drep_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_update_drep_cert_to_cbor(update_drep_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_update_drep_cert_unref(&update_drep_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_update_drep_cert_to_cbor(+  const cardano_update_drep_cert_t* update_drep_cert,+  cardano_cbor_writer_t*            writer);++/**+ * \brief Serializes an update DRep certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "drep_credential", "anchor".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_update_drep_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_update_drep_cert_to_cip116_json(const cardano_update_drep_cert_t* cert, cardano_json_writer_t* writer);++/**+ * \brief Sets the drep credential in the certificate.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_update_drep_cert_t object to which the credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the credential.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the credential was+ *         successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the+ *         input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_update_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_update_drep_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The credential is now set for the certificate+ * }+ * else+ * {+ *   printf("Failed to set the credential.\n");+ * }+ * // Both objects need to be managed and eventually unreferenced by the caller+ * cardano_credential_unref(&credential);+ * cardano_update_drep_cert_unref(&certificate);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_update_drep_cert_set_credential(cardano_update_drep_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Gets the credential from an update DRep certificate.+ *+ * This function retrieves the credential from a given update DRep certificate. The caller is responsible for+ * unreferencing the credential object after use.+ *+ * \param[in] certificate A pointer to an initialized cardano_update_drep_cert_t object representing the update DRep certificate.+ *+ * \return A pointer to the retrieved cardano_credential_t object. This will be a new reference.+ *+ * Usage Example:+ * \code{.c}+ * cardano_update_drep_cert_t* certificate = ...; // Assume initialized+ * cardano_credential_t* credential = cardano_update_drep_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Use the credential+ *+ *   // When done, release the credential+ *   cardano_credential_unref(credential);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t*+cardano_update_drep_cert_get_credential(cardano_update_drep_cert_t* certificate);++/**+ * \brief Retrieves the anchor associated with the certificate.+ *+ * This function returns the anchor used in a \ref cardano_update_drep_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_update_drep_cert_t object.+ *+ * \return A pointer to a \ref cardano_anchor_t object representing the anchor. If the certificate is NULL or does not have an anchor set,+ *         this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_update_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * const cardano_anchor_t* anchor = cardano_update_drep_cert_get_anchor(certificate);+ *+ * if (anchor != NULL)+ * {+ *   // Process the anchor information+ * }+ * else+ * {+ *   printf("No anchor is set for this certificate.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_anchor_t* cardano_update_drep_cert_get_anchor(cardano_update_drep_cert_t* certificate);++/**+ * \brief Sets the anchor for the certificate.+ *+ * This function assigns a new anchor to a given \ref cardano_update_drep_cert_t object.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_update_drep_cert_t object to which the anchor will be set.+ * \param[in] anchor A pointer to an initialized \ref cardano_anchor_t object representing the new anchor. This function+ *                    increases the reference count on the anchor, and the certificate will maintain its own reference+ *                    to the anchor.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the anchor+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_update_drep_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_anchor_t* new_anchor = ...; // Assume new_anchor is already initialized+ *+ * cardano_error_t result = cardano_update_drep_cert_set_anchor(certificate, new_anchor);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Anchor set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set the anchor.\n");+ * }+ *+ * // Both certificate and new_anchor need their own unref calls when no longer needed+ * \endcode+ *+ * \note This function increments the reference count of the anchor object passed to it. It is the caller's responsibility+ *       to manage the lifecycle of both the certificate and the anchor.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_update_drep_cert_set_anchor(cardano_update_drep_cert_t* certificate, cardano_anchor_t* anchor);++/**+ * \brief Decrements the reference count of a cardano_update_drep_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_update_drep_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the update_drep_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] update_drep_cert A pointer to the pointer of the update_drep_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_update_drep_cert_t* update_drep_cert = cardano_update_drep_cert_new(major, minor);+ *+ * // Perform operations with the update_drep_cert...+ *+ * cardano_update_drep_cert_unref(&update_drep_cert);+ * // At this point, update_drep_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_update_drep_cert_unref, the pointer to the \ref cardano_update_drep_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_update_drep_cert_unref(cardano_update_drep_cert_t** update_drep_cert);++/**+ * \brief Increases the reference count of the cardano_update_drep_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_update_drep_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_update_drep_cert_unref.+ *+ * \param update_drep_cert A pointer to the cardano_update_drep_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming update_drep_cert is a previously created update_drep_cert object+ *+ * cardano_update_drep_cert_ref(update_drep_cert);+ *+ * // Now update_drep_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_update_drep_cert_ref there is a corresponding+ * call to \ref cardano_update_drep_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_update_drep_cert_ref(cardano_update_drep_cert_t* update_drep_cert);++/**+ * \brief Retrieves the current reference count of the cardano_update_drep_cert_t object.+ *+ * This function returns the number of active references to an cardano_update_drep_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_update_drep_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param update_drep_cert A pointer to the cardano_update_drep_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_update_drep_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_update_drep_cert_ref call is matched with a+ * \ref cardano_update_drep_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming update_drep_cert is a previously created update_drep_cert object+ *+ * size_t ref_count = cardano_update_drep_cert_refcount(update_drep_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_update_drep_cert_refcount(const cardano_update_drep_cert_t* update_drep_cert);++/**+ * \brief Sets the last error message for a given cardano_update_drep_cert_t object.+ *+ * Records an error message in the update_drep_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] update_drep_cert A pointer to the \ref cardano_update_drep_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the update_drep_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_update_drep_cert_set_last_error(+  cardano_update_drep_cert_t* update_drep_cert,+  const char*                 message);++/**+ * \brief Retrieves the last error message recorded for a specific update_drep_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_update_drep_cert_set_last_error for the given+ * update_drep_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] update_drep_cert A pointer to the \ref cardano_update_drep_cert_t instance whose last error+ *                   message is to be retrieved. If the update_drep_cert is NULL, the function+ *                   returns a generic error message indicating the null update_drep_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified update_drep_cert. If the update_drep_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_update_drep_cert_set_last_error for the same update_drep_cert, or until+ *       the update_drep_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_update_drep_cert_get_last_error(+  const cardano_update_drep_cert_t* update_drep_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_update_drep_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_update_drep_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_update_drep_cert_deep_clone(const cardano_update_drep_cert_t* source, cardano_update_drep_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // UPDATE_DREP_CERT_H
+ vendor/include/cardano/certs/vote_delegation_cert.h view
@@ -0,0 +1,481 @@+/**+ * \file vote_delegation_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef VOTE_DELEGATION_CERT_H+#define VOTE_DELEGATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/common/drep.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate is used when an individual wants to delegate their voting rights to any other DRep.+ */+typedef struct cardano_vote_delegation_cert_t cardano_vote_delegation_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new vote delegation certificate.+ *+ * This function allocates and initializes a new vote delegation certificate, which is used to delegate the voting power+ * of a stakeholder to a drep.+ *+ * \param[in] credential A pointer to an initialized cardano_credential_t object representing the stakeholder's credential.+ * \param[in] drep A pointer to an initialized cardano_drep_t object representing the delegation representative.+ * \param[out] vote_delegation A pointer to a pointer where the newly created cardano_vote_delegation_cert_t object will be stored.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was successfully created.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume initialized+ * cardano_drep_t* drep = ...; // Assume initialized+ * cardano_vote_delegation_cert_t* vote_delegation = NULL;+ * cardano_error_t result = cardano_vote_delegation_cert_new(credential, drep, &vote_delegation);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *     // Use the vote_delegation+ *     // Free resources when done+ *     cardano_vote_delegation_cert_unref(&vote_delegation);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_vote_delegation_cert_new(+  cardano_credential_t*            credential,+  cardano_drep_t*                  drep,+  cardano_vote_delegation_cert_t** vote_delegation);++/**+ * \brief Creates a \ref cardano_vote_delegation_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_vote_delegation_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a vote_delegation_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] vote_delegation_cert A pointer to a pointer of \ref cardano_vote_delegation_cert_t that will be set to the address+ *                        of the newly created vote_delegation_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_vote_delegation_cert_t object by calling+ *       \ref cardano_vote_delegation_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_vote_delegation_cert_t* vote_delegation_cert = NULL;+ *+ * cardano_error_t result = cardano_vote_delegation_cert_from_cbor(reader, &vote_delegation_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the vote_delegation_cert+ *+ *   // Once done, ensure to clean up and release the vote_delegation_cert+ *   cardano_vote_delegation_cert_unref(&vote_delegation_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode vote_delegation_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_vote_delegation_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_vote_delegation_cert_t** vote_delegation_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_vote_delegation_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] vote_delegation_cert A constant pointer to the \ref cardano_vote_delegation_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p vote_delegation_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_delegation_cert_t* vote_delegation_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_vote_delegation_cert_to_cbor(vote_delegation_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_vote_delegation_cert_unref(&vote_delegation_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_vote_delegation_cert_to_cbor(+  const cardano_vote_delegation_cert_t* vote_delegation_cert,+  cardano_cbor_writer_t*                writer);++/**+ * \brief Serializes a vote delegation certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "credential", "drep".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_vote_delegation_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_vote_delegation_cert_to_cip116_json(+  const cardano_vote_delegation_cert_t* cert,+  cardano_json_writer_t*                writer);++/**+ * \brief Retrieves the stake credential from a vote delegation certificate.+ *+ * This function extracts the stake credential from a given \ref cardano_vote_delegation_cert_t object.+ * The credential identifies the stakeholder in the context of the Cardano network.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_vote_delegation_cert_t object.+ *+ * \return A pointer to a \ref cardano_credential_t object containing the stake credential. If the input certificate is NULL,+ *         or if the credential is not set, this function returns NULL.+ *+ * \note The returned \ref cardano_credential_t object is a new reference and must be managed by the caller.+ *       It should be released using \ref cardano_credential_unref when no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = cardano_vote_delegation_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   // Remember to release the credential reference when done+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   printf("Failed to retrieve credential or certificate is not initialized properly.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_vote_delegation_cert_get_credential(cardano_vote_delegation_cert_t* certificate);++/**+ * \brief Sets the stake credential for a vote delegation certificate.+ *+ * This function assigns a stake credential to a given \ref cardano_vote_delegation_cert_t object.+ * The credential identifies the stakeholder in the context of the Cardano network.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_vote_delegation_cert_t object+ *                            where the stake credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stake credential.+ *                       This function increments the reference count of the credential, and the caller remains responsible+ *                       for releasing their own reference.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the stake credential+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_vote_delegation_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Credential successfully set.\n");+ * }+ * else+ * {+ *   printf("Failed to set the credential: %s\n", cardano_error_to_string(result));+ * }+ *+ * \endcode+ *+ * \note After setting, the certificate holds its own reference to the credential. The caller+ *       must manage and release its own references to the credential object.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_vote_delegation_cert_set_credential(cardano_vote_delegation_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the DRep associated with a vote delegation certificate.+ *+ * This function extracts the DRep from the specified \ref cardano_vote_delegation_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_vote_delegation_cert_t object.+ *+ * \return A pointer to a new \ref cardano_drep_t object containing the DRep. The caller is responsible+ *         for managing the lifecycle of this returned DRep object, including releasing it using \ref cardano_drep_unref+ *         when it is no longer needed. If the certificate is NULL or if the DRep is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_drep_t* drep = cardano_vote_delegation_cert_get_drep(certificate);+ *+ * if (drep != NULL)+ * {+ *   // Process the DRep+ *   // Remember to free the DRep when done+ *   cardano_drep_unref(&drep);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_drep_t* cardano_vote_delegation_cert_get_drep(cardano_vote_delegation_cert_t* certificate);++/**+ * \brief Sets the DRep for a vote delegation certificate.+ *+ * This function assigns a DRep to the specified \ref cardano_vote_delegation_cert_t object.+ * The DRep is essential for representing delegate participation in the governance process within the Cardano network.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_vote_delegation_cert_t object which will receive the DRep.+ * \param[in] drep A pointer to an initialized \ref cardano_drep_t object to be set on the certificate. This function increments the reference+ *                 count of the DRep, and the caller is still responsible for releasing their reference to the DRep object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the DRep was successfully set,+ *         or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_drep_t* drep = ...; // Assume drep is already initialized+ *+ * cardano_error_t result = cardano_vote_delegation_cert_set_drep(certificate, drep);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The DRep is now set for the certificate+ * }+ * else+ * {+ *   printf("Failed to set the DRep.\n");+ * }+ *+ * // Both certificate and drep need their references managed appropriately+ * cardano_drep_unref(&drep);+ * \endcode+ *+ * \note This function increments the reference count of the drep argument, the caller must manage their own reference to it.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_vote_delegation_cert_set_drep(cardano_vote_delegation_cert_t* certificate, cardano_drep_t* drep);++/**+ * \brief Decrements the reference count of a cardano_vote_delegation_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_vote_delegation_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the vote_delegation_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] vote_delegation_cert A pointer to the pointer of the vote_delegation_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_delegation_cert_t* vote_delegation_cert = cardano_vote_delegation_cert_new(major, minor);+ *+ * // Perform operations with the vote_delegation_cert...+ *+ * cardano_vote_delegation_cert_unref(&vote_delegation_cert);+ * // At this point, vote_delegation_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_vote_delegation_cert_unref, the pointer to the \ref cardano_vote_delegation_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_vote_delegation_cert_unref(cardano_vote_delegation_cert_t** vote_delegation_cert);++/**+ * \brief Increases the reference count of the cardano_vote_delegation_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_vote_delegation_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_vote_delegation_cert_unref.+ *+ * \param vote_delegation_cert A pointer to the cardano_vote_delegation_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming vote_delegation_cert is a previously created vote_delegation_cert object+ *+ * cardano_vote_delegation_cert_ref(vote_delegation_cert);+ *+ * // Now vote_delegation_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_vote_delegation_cert_ref there is a corresponding+ * call to \ref cardano_vote_delegation_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_vote_delegation_cert_ref(cardano_vote_delegation_cert_t* vote_delegation_cert);++/**+ * \brief Retrieves the current reference count of the cardano_vote_delegation_cert_t object.+ *+ * This function returns the number of active references to an cardano_vote_delegation_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_vote_delegation_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param vote_delegation_cert A pointer to the cardano_vote_delegation_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_vote_delegation_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_vote_delegation_cert_ref call is matched with a+ * \ref cardano_vote_delegation_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming vote_delegation_cert is a previously created vote_delegation_cert object+ *+ * size_t ref_count = cardano_vote_delegation_cert_refcount(vote_delegation_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_vote_delegation_cert_refcount(const cardano_vote_delegation_cert_t* vote_delegation_cert);++/**+ * \brief Sets the last error message for a given cardano_vote_delegation_cert_t object.+ *+ * Records an error message in the vote_delegation_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] vote_delegation_cert A pointer to the \ref cardano_vote_delegation_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the vote_delegation_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_vote_delegation_cert_set_last_error(+  cardano_vote_delegation_cert_t* vote_delegation_cert,+  const char*                     message);++/**+ * \brief Retrieves the last error message recorded for a specific vote_delegation_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_vote_delegation_cert_set_last_error for the given+ * vote_delegation_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] vote_delegation_cert A pointer to the \ref cardano_vote_delegation_cert_t instance whose last error+ *                   message is to be retrieved. If the vote_delegation_cert is NULL, the function+ *                   returns a generic error message indicating the null vote_delegation_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified vote_delegation_cert. If the vote_delegation_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_vote_delegation_cert_set_last_error for the same vote_delegation_cert, or until+ *       the vote_delegation_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_vote_delegation_cert_get_last_error(+  const cardano_vote_delegation_cert_t* vote_delegation_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_vote_delegation_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_vote_delegation_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_vote_delegation_cert_deep_clone(const cardano_vote_delegation_cert_t* source, cardano_vote_delegation_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // VOTE_DELEGATION_CERT_H
+ vendor/include/cardano/certs/vote_registration_delegation_cert.h view
@@ -0,0 +1,540 @@+/**+ * \file vote_registration_delegation_cert.h+ *+ * \author angel.castillo+ * \date   Jul 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef VOTE_REGISTRATION_DELEGATION_CERT_H+#define VOTE_REGISTRATION_DELEGATION_CERT_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/common/drep.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief This certificate Register the stake key and delegate with a single certificate to a DRep.+ */+typedef struct cardano_vote_registration_delegation_cert_t cardano_vote_registration_delegation_cert_t;++/**+ * \brief Certificates are a means to encode various essential operations related to stake+ * delegation and stake pool management. Certificates are embedded in transactions and+ * included in blocks. They're a vital aspect of Cardano's proof-of-stake mechanism,+ * ensuring that stakeholders can participate in the protocol and its governance.+ */+typedef struct cardano_certificate_t cardano_certificate_t;++/**+ * \brief Creates a new vote registration delegation certificate.+ *+ * This function allocates and initializes a new vote registration delegation certificate, which combines stake registration+ * with a delegation of voting power to a drep.+ *+ * \param[in] credential A pointer to an initialized cardano_credential_t object representing the stakeholder's credential.+ * \param[in] deposit The deposit amount required for the registration, which must be specified according to protocol parameters.+ * \param[in] drep A pointer to an initialized cardano_drep_t object representing the delegation representative.+ * \param[out] vote_registration_delegation A pointer to a pointer where the newly created cardano_vote_registration_delegation_cert_t object will be stored.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the certificate was successfully created.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...; // Assume initialized+ * uint64_t deposit = 500000; // Specified deposit amount+ * cardano_drep_t* drep = ...; // Assume initialized+ * cardano_vote_registration_delegation_cert_t* vote_registration_delegation = NULL;+ * cardano_error_t result = cardano_vote_registration_delegation_cert_new(credential, deposit, drep, &vote_registration_delegation);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *     // Use the vote_registration_delegation+ *     // Free resources when done+ *     cardano_vote_registration_delegation_cert_unref(&vote_registration_delegation);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_vote_registration_delegation_cert_new(+  cardano_credential_t*                         credential,+  uint64_t                                      deposit,+  cardano_drep_t*                               drep,+  cardano_vote_registration_delegation_cert_t** vote_registration_delegation);++/**+ * \brief Creates a \ref cardano_vote_registration_delegation_cert_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_vote_registration_delegation_cert_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a vote_registration_delegation_cert.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] vote_registration_delegation_cert A pointer to a pointer of \ref cardano_vote_registration_delegation_cert_t that will be set to the address+ *                        of the newly created vote_registration_delegation_cert object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_vote_registration_delegation_cert_t object by calling+ *       \ref cardano_vote_registration_delegation_cert_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_vote_registration_delegation_cert_t* vote_registration_delegation_cert = NULL;+ *+ * cardano_error_t result = cardano_vote_registration_delegation_cert_from_cbor(reader, &vote_registration_delegation_cert);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the vote_registration_delegation_cert+ *+ *   // Once done, ensure to clean up and release the vote_registration_delegation_cert+ *   cardano_vote_registration_delegation_cert_unref(&vote_registration_delegation_cert);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode vote_registration_delegation_cert: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_vote_registration_delegation_cert_from_cbor(cardano_cbor_reader_t* reader, cardano_vote_registration_delegation_cert_t** vote_registration_delegation_cert);++/**+ * \brief Serializes the certificate into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_vote_registration_delegation_cert_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] vote_registration_delegation_cert A constant pointer to the \ref cardano_vote_registration_delegation_cert_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p vote_registration_delegation_cert or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_registration_delegation_cert_t* vote_registration_delegation_cert = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_vote_registration_delegation_cert_to_cbor(vote_registration_delegation_cert, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_vote_registration_delegation_cert_unref(&vote_registration_delegation_cert);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_vote_registration_delegation_cert_to_cbor(+  const cardano_vote_registration_delegation_cert_t* vote_registration_delegation_cert,+  cardano_cbor_writer_t*                             writer);++/**+ * \brief Serializes a vote registration delegation certificate to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "tag", "credential", "drep", "coin".+ *+ * \param[in]  cert    Pointer to a valid \ref cardano_vote_registration_delegation_cert_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p cert or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_vote_registration_delegation_cert_to_cip116_json(+  const cardano_vote_registration_delegation_cert_t* cert,+  cardano_json_writer_t*                             writer);++/**+ * \brief Retrieves the stake credential from a vote registration delegation certificate.+ *+ * This function extracts the stake credential from a given \ref cardano_vote_registration_delegation_cert_t object.+ * The credential identifies the stakeholder in the context of the Cardano network.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_vote_registration_delegation_cert_t object.+ *+ * \return A pointer to a \ref cardano_credential_t object containing the stake credential. If the input certificate is NULL,+ *         or if the credential is not set, this function returns NULL.+ *+ * \note The returned \ref cardano_credential_t object is a new reference and must be managed by the caller.+ *       It should be released using \ref cardano_credential_unref when no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = cardano_vote_registration_delegation_cert_get_credential(certificate);+ *+ * if (credential != NULL)+ * {+ *   // Process the credential+ *   // Remember to release the credential reference when done+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   printf("Failed to retrieve credential or certificate is not initialized properly.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_credential_t* cardano_vote_registration_delegation_cert_get_credential(cardano_vote_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the stake credential for a vote registration delegation certificate.+ *+ * This function assigns a stake credential to a given \ref cardano_vote_registration_delegation_cert_t object.+ * The credential identifies the stakeholder in the context of the Cardano network.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_vote_registration_delegation_cert_t object+ *                            where the stake credential will be set.+ * \param[in] credential A pointer to an initialized \ref cardano_credential_t object representing the stake credential.+ *                       This function increments the reference count of the credential, and the caller remains responsible+ *                       for releasing their own reference.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the stake credential+ *         was successfully set, or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_credential_t* credential = ...; // Assume credential is already initialized+ *+ * cardano_error_t result = cardano_vote_registration_delegation_cert_set_credential(certificate, credential);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Credential successfully set.\n");+ * }+ * else+ * {+ *   printf("Failed to set the credential: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Cleanup performed elsewhere for credential+ * \endcode+ *+ * \note After setting, the certificate holds its own reference to the credential. The caller+ *       must manage and release its own references to the credential object.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_vote_registration_delegation_cert_set_credential(cardano_vote_registration_delegation_cert_t* certificate, cardano_credential_t* credential);++/**+ * \brief Retrieves the DRep associated with a vote registration delegation certificate.+ *+ * This function extracts the DRep from the specified \ref cardano_vote_registration_delegation_cert_t object.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_vote_registration_delegation_cert_t object.+ *+ * \return A pointer to a new \ref cardano_drep_t object containing the DRep. The caller is responsible+ *         for managing the lifecycle of this returned DRep object, including releasing it using \ref cardano_drep_unref+ *         when it is no longer needed. If the certificate is NULL or if the DRep is not set, this function returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * const cardano_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_drep_t* drep = cardano_vote_registration_delegation_cert_get_drep(certificate);+ *+ * if (drep != NULL)+ * {+ *   // Process the DRep+ *   // Remember to free the DRep when done+ *   cardano_drep_unref(&drep);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_drep_t* cardano_vote_registration_delegation_cert_get_drep(cardano_vote_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the DRep for a vote registration delegation certificate.+ *+ * This function assigns a DRep to the specified \ref cardano_vote_registration_delegation_cert_t object.+ * The DRep is essential for representing delegate participation in the governance process within the Cardano network.+ *+ * \param[in] certificate A pointer to an initialized \ref cardano_vote_registration_delegation_cert_t object which will receive the DRep.+ * \param[in] drep A pointer to an initialized \ref cardano_drep_t object to be set on the certificate. This function increments the reference+ *                 count of the DRep, and the caller is still responsible for releasing their reference to the DRep object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the DRep was successfully set,+ *         or an appropriate error code indicating the failure reason, such as \ref CARDANO_ERROR_POINTER_IS_NULL if any of the input pointers are NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * cardano_drep_t* drep = ...; // Assume drep is already initialized+ *+ * cardano_error_t result = cardano_vote_registration_delegation_cert_set_drep(certificate, drep);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The DRep is now set for the certificate+ * }+ * else+ * {+ *   printf("Failed to set the DRep.\n");+ * }+ *+ * // Both certificate and drep need their references managed appropriately+ * cardano_drep_unref(&drep);+ * \endcode+ *+ * \note This function increments the reference count of the drep argument, the caller must manage their own reference to it.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_vote_registration_delegation_cert_set_drep(cardano_vote_registration_delegation_cert_t* certificate, cardano_drep_t* drep);++/**+ * \brief Retrieves the deposit amount from a vote registration delegation certificate.+ *+ * This function fetches the deposit amount that has been set on a \ref cardano_vote_registration_delegation_cert_t object.+ * The deposit is a fixed amount required as part of the registration process, acting as a security measure within the Cardano network.+ *+ * \param[in] certificate A constant pointer to an initialized \ref cardano_vote_registration_delegation_cert_t object.+ *+ * \return The deposit amount set on the certificate. If the certificate is NULL, the function returns 0,+ *         which should be checked against possible error returns in real scenarios.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ *+ * uint64_t deposit = cardano_vote_registration_delegation_cert_get_deposit(certificate);+ * printf("Deposit amount: %llu ADA\n", deposit);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_vote_registration_delegation_cert_get_deposit(const cardano_vote_registration_delegation_cert_t* certificate);++/**+ * \brief Sets the deposit amount on a vote registration delegation certificate.+ *+ * This function updates the deposit amount for a \ref cardano_vote_registration_delegation_cert_t object.+ *+ * \param[in,out] certificate A pointer to an initialized \ref cardano_vote_registration_delegation_cert_t object on which+ *                            the deposit amount will be set.+ * \param[in] deposit The deposit amount to be set on the certificate. This amount should align with the protocol's current requirements.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the deposit amount+ *         was successfully updated, or an appropriate error code indicating the reason for failure, such as+ *         \ref CARDANO_ERROR_POINTER_IS_NULL if the certificate pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_registration_delegation_cert_t* certificate = ...; // Assume certificate is already initialized+ * uint64_t deposit = 1000000; // 1 ADA, example deposit amount+ *+ * cardano_error_t result = cardano_vote_registration_delegation_cert_set_deposit(certificate, deposit);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Deposit amount updated successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set deposit amount.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_vote_registration_delegation_cert_set_deposit(cardano_vote_registration_delegation_cert_t* certificate, uint64_t deposit);++/**+ * \brief Decrements the reference count of a cardano_vote_registration_delegation_cert_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_vote_registration_delegation_cert_t object+ * by decreasing its reference count. When the reference count reaches zero, the vote_registration_delegation_cert is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] vote_registration_delegation_cert A pointer to the pointer of the vote_registration_delegation_cert object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_vote_registration_delegation_cert_t* vote_registration_delegation_cert = cardano_vote_registration_delegation_cert_new(major, minor);+ *+ * // Perform operations with the vote_registration_delegation_cert...+ *+ * cardano_vote_registration_delegation_cert_unref(&vote_registration_delegation_cert);+ * // At this point, vote_registration_delegation_cert is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_vote_registration_delegation_cert_unref, the pointer to the \ref cardano_vote_registration_delegation_cert_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_vote_registration_delegation_cert_unref(cardano_vote_registration_delegation_cert_t** vote_registration_delegation_cert);++/**+ * \brief Increases the reference count of the cardano_vote_registration_delegation_cert_t object.+ *+ * This function is used to manually increment the reference count of an cardano_vote_registration_delegation_cert_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_vote_registration_delegation_cert_unref.+ *+ * \param vote_registration_delegation_cert A pointer to the cardano_vote_registration_delegation_cert_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming vote_registration_delegation_cert is a previously created vote_registration_delegation_cert object+ *+ * cardano_vote_registration_delegation_cert_ref(vote_registration_delegation_cert);+ *+ * // Now vote_registration_delegation_cert can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_vote_registration_delegation_cert_ref there is a corresponding+ * call to \ref cardano_vote_registration_delegation_cert_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_vote_registration_delegation_cert_ref(cardano_vote_registration_delegation_cert_t* vote_registration_delegation_cert);++/**+ * \brief Retrieves the current reference count of the cardano_vote_registration_delegation_cert_t object.+ *+ * This function returns the number of active references to an cardano_vote_registration_delegation_cert_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_vote_registration_delegation_cert_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param vote_registration_delegation_cert A pointer to the cardano_vote_registration_delegation_cert_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_vote_registration_delegation_cert_t object. If the object+ * is properly managed (i.e., every \ref cardano_vote_registration_delegation_cert_ref call is matched with a+ * \ref cardano_vote_registration_delegation_cert_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming vote_registration_delegation_cert is a previously created vote_registration_delegation_cert object+ *+ * size_t ref_count = cardano_vote_registration_delegation_cert_refcount(vote_registration_delegation_cert);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_vote_registration_delegation_cert_refcount(const cardano_vote_registration_delegation_cert_t* vote_registration_delegation_cert);++/**+ * \brief Sets the last error message for a given cardano_vote_registration_delegation_cert_t object.+ *+ * Records an error message in the vote_registration_delegation_cert's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] vote_registration_delegation_cert A pointer to the \ref cardano_vote_registration_delegation_cert_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the vote_registration_delegation_cert's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_vote_registration_delegation_cert_set_last_error(+  cardano_vote_registration_delegation_cert_t* vote_registration_delegation_cert,+  const char*                                  message);++/**+ * \brief Retrieves the last error message recorded for a specific vote_registration_delegation_cert.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_vote_registration_delegation_cert_set_last_error for the given+ * vote_registration_delegation_cert. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] vote_registration_delegation_cert A pointer to the \ref cardano_vote_registration_delegation_cert_t instance whose last error+ *                   message is to be retrieved. If the vote_registration_delegation_cert is NULL, the function+ *                   returns a generic error message indicating the null vote_registration_delegation_cert.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified vote_registration_delegation_cert. If the vote_registration_delegation_cert is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_vote_registration_delegation_cert_set_last_error for the same vote_registration_delegation_cert, or until+ *       the vote_registration_delegation_cert is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_vote_registration_delegation_cert_get_last_error(+  const cardano_vote_registration_delegation_cert_t* vote_registration_delegation_cert);++/**+ * \brief Creates an independent deep copy of a \ref cardano_vote_registration_delegation_cert_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_vote_registration_delegation_cert_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_vote_registration_delegation_cert_deep_clone(const cardano_vote_registration_delegation_cert_t* source, cardano_vote_registration_delegation_cert_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // VOTE_REGISTRATION_DELEGATION_CERT_H
+ vendor/include/cardano/common/anchor.h view
@@ -0,0 +1,753 @@+/**+ * \file anchor.h+ *+ * \author angel.castillo+ * \date   Mar 03, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_ANCHOR_H+#define BIGLUP_LABS_INCLUDE_CARDANO_ANCHOR_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief An anchor is a pair of:+ *+ * - a URL to a JSON payload of metadata.+ * - a hash of the contents of the metadata URL.+ *+ * The on-chain rules will not check either the URL or the hash. Client applications should,+ * however, perform the usual sanity checks when fetching content from the provided URL.+ */+typedef struct cardano_anchor_t cardano_anchor_t;++/**+ * \brief Creates and initializes a new instance of an anchor.+ *+ * This function allocates and initializes a new instance of \ref cardano_anchor_t,+ * using the provided URL and associated hash. It returns an error code to indicate the+ * success or failure of the operation.+ *+ * \param[in] url A pointer to a character array containing the URL associated with the anchor.+ * \param[in] url_size The size of the URL character array in bytes.+ * \param[in] hash A pointer to \ref cardano_blake2b_hash_t representing the hash associated+ *            with this anchor. The hash must be properly initialized before being+ *            passed to this function.+ * \param[out] anchor On successful initialization, this will point to a newly created+ *            \ref cardano_anchor_t object. This object represents a "strong reference"+ *            to the anchor, meaning that it is fully initialized and ready for use.+ *            The caller is responsible for managing the lifecycle of this object.+ *            Specifically, once the anchor is no longer needed, the caller must release it+ *            by calling \ref cardano_anchor_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the anchor was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * const char* url = "https://example.com/anchor";+ * size_t url_size = strlen(url);+ * cardano_blake2b_hash_t* hash = ...;  // Assume hash is initialized here+ * cardano_anchor_t* anchor = NULL;+ *+ * // Attempt to create a new anchor+ * cardano_error_t result = cardano_anchor_new(url, url_size, hash, &anchor);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the anchor+ *+ *   // Once done, ensure to clean up and release the anchor+ *   cardano_anchor_unref(&anchor);+ * }+ *+ * cardano_blake2b_hash_unref(&hash);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_anchor_new(+  const char*                   url,+  size_t                        url_size,+  const cardano_blake2b_hash_t* hash,+  cardano_anchor_t**            anchor);++/**+ * \brief Creates an anchor from a hexadecimal hash string.+ *+ * This function constructs a \ref cardano_anchor_t object by interpreting the provided+ * hexadecimal string as a hash value. It returns an error code indicating the success+ * or failure of the operation.+ *+ * \param[in] url A pointer to a character array containing the URL associated with the anchor.+ * \param[in] url_size The size of the URL string in bytes.+ * \param[in] hex A pointer to a character array containing the hexadecimal representation of the hash.+ * \param[in] hex_size The size of the hexadecimal string in bytes.+ * \param[out] anchor On successful initialization, this will point to a newly created+ *             \ref cardano_anchor_t object. This object represents a "strong reference"+ *             to the anchor, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object,+ *             specifically, once the anchor is no longer needed, the caller must release it+ *             by calling \ref cardano_anchor_unref.+ *+ * \return \ref CARDANO_SUCCESS if the anchor was successfully created, or an appropriate error code+ *         indicating the reason for failure.+ *+ * Usage Example:+ * \code{.c}+ * const char* url = "https://example.com";+ * size_t url_size = strlen(url);+ * const char* hash_hex = "abcdef1234567890abcdef1234567890abcdef12...";+ * size_t hex_size = strlen(hash_hex);+ * cardano_anchor_t* anchor = NULL;+ *+ * // Attempt to create a new anchor from a hexadecimal hash+ * cardano_error_t result = cardano_anchor_from_hash_hex(url, url_size, hash_hex, hex_size, &anchor);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the anchor+ *+ *   // Once done, ensure to clean up and release the anchor+ *   cardano_anchor_unref(&anchor);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_anchor_from_hash_hex(+  const char*        url,+  size_t             url_size,+  const char*        hex,+  size_t             hex_size,+  cardano_anchor_t** anchor);++/**+ * \brief Creates an anchor from a byte array representing a hash.+ *+ * This function constructs a \ref cardano_anchor_t object by using the provided+ * byte array as a hash value and associating it with a specified URL. It returns an error+ * code indicating the success or failure of the operation.+ *+ * \param[in] url A pointer to the character array containing the URL associated with the anchor.+ * \param[in] url_size The size of the URL string in bytes.+ * \param[in] data A pointer to the byte array containing the hash data.+ * \param[in] data_size The size of the byte array in bytes.+ * \param[out] anchor On successful initialization, this pointer is set to the newly created+ *                    \ref cardano_anchor_t object. This object represents a "strong reference"+ *                    to the anchor, meaning that it is fully initialized and ready for use.+ *                    The caller is responsible for managing the lifecycle of this object,+ *                    specifically, once the anchor is no longer needed, the caller must release it+ *                    by calling \ref cardano_anchor_unref.+ *+ * \return \ref CARDANO_SUCCESS if the anchor was successfully created, or an appropriate error code+ *         indicating the reason for failure.+ *+ * \note This function assumes that the byte array and URL are correctly formatted and valid.+ *       Malformed or incorrect input may lead to errors or undefined behavior.+ *+ * Usage Example:+ * \code{.c}+ * const char* url = "https://example.com";+ * size_t url_size = strlen(url);+ * const byte_t hash_data[] = { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef ... };+ * size_t data_size = sizeof(hash_data);+ * cardano_anchor_t* anchor = NULL;+ *+ * // Attempt to create a new anchor from byte array hash+ * cardano_error_t result = cardano_anchor_from_hash_bytes(url, url_size, hash_data, data_size, &anchor);+ *+ * if (result == CARDANO_SUCCESS && anchor)+ * {+ *   // Use the anchor+ *+ *   // Once done, ensure to clean up and release the anchor+ *   cardano_anchor_unref(&anchor);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_anchor_from_hash_bytes(+  const char*        url,+  size_t             url_size,+  const byte_t*      data,+  size_t             data_size,+  cardano_anchor_t** anchor);++/**+ * \brief Creates a anchor from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_anchor_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a anchor.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded anchor data.+ * \param[out] anchor A pointer to a pointer of \ref cardano_anchor_t that will be set to the address+ *                        of the newly created anchor object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the anchor was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_anchor_t object by calling+ *       \ref cardano_anchor_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_anchor_t* anchor = NULL;+ *+ * cardano_error_t result = cardano_anchor_from_cbor(reader, &anchor);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the anchor+ *+ *   // Once done, ensure to clean up and release the anchor+ *   cardano_anchor_unref(&anchor);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode anchor: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_anchor_from_cbor(cardano_cbor_reader_t* reader, cardano_anchor_t** anchor);++/**+ * \brief Serializes a anchor into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_anchor_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] anchor A constant pointer to the \ref cardano_anchor_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p anchor or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_anchor_to_cbor(anchor, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_anchor_unref(&anchor);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_anchor_to_cbor(+  const cardano_anchor_t* anchor,+  cardano_cbor_writer_t*  writer);++/**+ * \brief Serializes an anchor to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "url", "data_hash".+ *+ * \param[in]  anchor  Pointer to a valid \ref cardano_anchor_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p anchor or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_anchor_to_cip116_json(+  const cardano_anchor_t* anchor,+  cardano_json_writer_t*  writer);++/**+ * \brief Retrieves the hash associated with a anchor.+ *+ * This function provides access to the hash part of a \ref cardano_anchor_t object.+ * It returns a new reference to a \ref cardano_blake2b_hash_t object representing the hash.+ * This allows the hash to be used independently of the original anchor object. The+ * reference count of the hash object is increased by one, making it the caller's responsibility+ * to release it by calling \ref cardano_blake2b_hash_unref when it is no longer needed.+ *+ * \param anchor A constant pointer to the \ref cardano_anchor_t object from which+ *                   the hash is to be retrieved.+ *+ * \return A pointer to a new \ref cardano_blake2b_hash_t object containing the hash.+ *         If the input anchor is NULL, returns NULL. The caller is responsible for+ *         managing the lifecycle of this object, including releasing it with+ *         \ref cardano_blake2b_hash_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* original_anchor = cardano_anchor_new(...);+ * cardano_blake2b_hash_t* hash_anchor = cardano_anchor_get_hash(original_anchor);+ *+ * if (hash_anchor)+ * {+ *   // Use the hash anchor+ *+ *   // Once done, ensure to clean up and release the hash anchor+ *   cardano_blake2b_hash_unref(&hash_anchor);+ * }+ * // Release the original anchor after use+ * cardano_anchor_unref(&original_anchor);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_anchor_get_hash(const cardano_anchor_t* anchor);++/**+ * \brief Retrieves the size of the hash bytes stored in the anchor.+ *+ * This function computes the size of the hash bytes stored within a \ref cardano_anchor_t object.+ * It is particularly useful for determining the buffer size needed to store the hash bytes when+ * retrieving them via \ref cardano_anchor_get_hash_bytes.+ *+ * \param[in] anchor A constant pointer to the \ref cardano_anchor_t object from which+ *                       the size of the hash bytes is to be retrieved.+ *+ * \return The size of the hash bytes. If the anchor is NULL the function returns zero.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = cardano_anchor_new(...);+ * size_t hash_size = cardano_anchor_get_hash_bytes_size(anchor);+ *+ * if (hash_size > 0)+ * {+ *   byte_t* hash_bytes = malloc(hash_size);+ *   if (hash_bytes)+ *   {+ *     // Proceed to get the hash bytes+ *   }+ * }+ * cardano_anchor_unref(&anchor);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_anchor_get_hash_bytes_size(const cardano_anchor_t* anchor);++/**+ * \brief Retrieves the byte array representation of the hash from a anchor.+ *+ * This function accesses the byte representation of the hash associated with a given+ * \ref cardano_anchor_t object. It provides a direct pointer to the internal byte array+ * representing the hash, which should not be modified or freed by the caller.+ *+ * \param anchor A constant pointer to the \ref cardano_anchor_t object from which+ *                   the hash bytes are to be retrieved.+ *+ * \return A pointer to a constant byte array containing the hash data. If the input anchor+ *         is NULL, returns NULL. The data remains valid as long as the anchor object is not+ *         freed or modified.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = cardano_anchor_new(...);+ * const byte_t* hash_bytes = cardano_anchor_get_hash_bytes(anchor);+ *+ * if (hash_bytes)+ * {+ *   // Use the hash bytes for operations like comparison or display+ * }+ *+ * // Clean up the anchor object once done+ * cardano_anchor_unref(&anchor);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_anchor_get_hash_bytes(const cardano_anchor_t* anchor);++/**+ * \brief Retrieves the size needed for the hexadecimal string representation of the anchor's hash.+ *+ * This function calculates the size required to store the hexadecimal string representation of the hash+ * associated with a \ref cardano_anchor_t object. This size includes the space needed for the null-terminator.+ *+ * \param[in] anchor A constant pointer to the \ref cardano_anchor_t object whose hash size is to be determined.+ *+ * \return The size in bytes required to store the hexadecimal representation of the hash, including the null terminator.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = cardano_anchor_new(...);+ * size_t hex_size = cardano_anchor_get_hash_hex_size(anchor);+ * char* hex_string = malloc(hex_size);+ *+ * if (hex_string)+ * {+ *   // Now use hex_string to get the hash or do other operations+ *   free(hex_string);+ * }+ *+ * cardano_anchor_unref(&anchor);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_anchor_get_hash_hex_size(const cardano_anchor_t* anchor);++/**+ * \brief Retrieves the hexadecimal string representation of the hash from a anchor.+ *+ * This function provides access to the hexadecimal (hex) string representation of the hash+ * associated with a given \ref cardano_anchor_t object. It returns a direct pointer to the+ * internal hex string which should not be modified or freed by the caller.+ *+ * \param anchor A constant pointer to the \ref cardano_anchor_t object from which+ *                   the hex string of the hash is to be retrieved. The object must not be NULL.+ *+ * \return A pointer to a constant character array containing the hex representation of the hash.+ *         If the input anchor is NULL, returns NULL. The data remains valid as long as the+ *         anchor object is not freed or modified.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = cardano_anchor_new(...);+ * const char* hash_hex = cardano_anchor_get_hash_hex(anchor);+ *+ * if (hash_hex)+ * {+ *   // Use the hash hex for operations like logging, display, or comparison+ * }+ *+ * // Clean up the anchor object once done+ * cardano_anchor_unref(&anchor);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_anchor_get_hash_hex(const cardano_anchor_t* anchor);++/**+ * \brief Retrieves the size of the URL string stored in the anchor.+ *+ * This function calculates the size of the URL string, including the null terminator,+ * associated with the provided \ref cardano_anchor_t object. This size is necessary+ * to allocate a buffer large enough to store the URL string.+ *+ * \param[in] anchor A constant pointer to the \ref cardano_anchor_t object from which+ *                   the URL size is to be retrieved.+ *+ * \return The size in bytes of the URL string including the null terminator. If the anchor+ *         is NULL or if there is no URL assigned, returns 0.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = ...; // Assume this is initialized+ * size_t url_size = cardano_anchor_get_url_size(anchor);+ *+ * if (url_size > 0)+ * {+ *   char* url = malloc(url_size); // Allocate space for the URL+ *   if (url)+ *   {+ *     // Further operations such as fetching the URL can be performed here+ *     free(url);+ *   }+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_anchor_get_url_size(const cardano_anchor_t* anchor);++/**+ * \brief Retrieves the URL from an anchor.+ *+ * This function returns the URL associated with a \ref cardano_anchor_t object. The URL is returned+ * as a pointer to a null-terminated string. This pointer points to internal memory managed by the+ * anchor object, and therefore should not be modified or freed by the caller.+ *+ * \param[in] anchor A constant pointer to the \ref cardano_anchor_t object from which+ *                   the URL is to be retrieved.+ *+ * \return A constant pointer to a null-terminated string containing the URL. If the anchor is NULL+ *         or if the anchor does not have a URL, returns NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = ...; // Assume this is initialized+ * const char* url = cardano_anchor_get_url(anchor);+ *+ * if (url)+ * {+ *   printf("Anchor URL: %s\n", url);+ * }+ * else+ * {+ *   printf("Failed to retrieve URL from anchor\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char*+cardano_anchor_get_url(const cardano_anchor_t* anchor);++/**+ * \brief Sets the URL for an anchor.+ *+ * This function assigns a new URL to an existing \ref cardano_anchor_t object. The URL is specified as a character+ * array and its size. The function copies the URL into the anchor object.+ *+ * \param[in,out] anchor A pointer to the \ref cardano_anchor_t object whose URL is to be set.+ * \param[in] url A pointer to a character array containing the new URL to be set for the anchor.+ * \param[in] url_size The size of the URL character array in bytes, excluding any null-terminator.+ *+ * \return \ref CARDANO_SUCCESS if the URL was successfully set. Returns \ref CARDANO_ERROR_POINTER_IS_NULL if any of the+ *         inputs are NULL, \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE if the URL size exceeds internal limits, or+ *         other error codes as appropriate for other failure reasons.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = ...;+ * const char* url = "https://example.com/new-anchor-url";+ * size_t url_size = strlen(url);+ *+ * cardano_error_t result = cardano_anchor_set_url(anchor, url, url_size);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *     // URL is successfully updated+ * }+ *+ * cardano_anchor_unref(&anchor);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_anchor_set_url(cardano_anchor_t* anchor, const char* url, size_t url_size);++/**+ * \brief Sets the hash for a anchor.+ *+ * This function assigns a new hash to an existing \ref cardano_anchor_t object. The hash+ * represents the identifying data for the anchor.The function copies the provided hash into+ * the anchor, so the original hash object may be modified or freed after this operation without+ * affecting the anchor's hash.+ *+ * \param[in,out] anchor A pointer to the \ref cardano_anchor_t object whose hash is to be set.+ *                           This object must have been previously created and not yet freed.+ * \param[in] hash A pointer to a \ref cardano_blake2b_hash_t object containing the new hash to be set.+ *                 This parameter must not be NULL.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the hash was successfully set. If the \p anchor or \p hash is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = ...;+ * cardano_blake2b_hash_t* new_hash = cardano_blake2b_compute_hash(...);+ *+ * cardano_error_t result = cardano_anchor_set_hash(anchor, new_hash);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *     // The hash was successfully set+ * }+ *+ * // Clean up+ * cardano_anchor_unref(&anchor);+ * cardano_blake2b_hash_unref(&new_hash);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_anchor_set_hash(cardano_anchor_t* anchor, const cardano_blake2b_hash_t* hash);++/**+ * \brief Decrements the reference count of a anchor object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_anchor_t object+ * by decreasing its reference count. When the reference count reaches zero, the anchor is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] anchor A pointer to the pointer of the anchor object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_anchor_t* anchor = cardano_anchor_new();+ *+ * // Perform operations with the anchor...+ *+ * cardano_anchor_unref(&anchor);+ * // At this point, anchor is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_anchor_unref, the pointer to the \ref cardano_anchor_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_anchor_unref(cardano_anchor_t** anchor);++/**+ * \brief Increases the reference count of the cardano_anchor_t object.+ *+ * This function is used to manually increment the reference count of a anchor+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_anchor_unref.+ *+ * \param anchor A pointer to the anchor object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming anchor is a previously created anchor object+ *+ * cardano_anchor_ref(anchor);+ *+ * // Now anchor can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_anchor_ref there is a corresponding+ * call to \ref cardano_anchor_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_anchor_ref(cardano_anchor_t* anchor);++/**+ * \brief Retrieves the current reference count of the cardano_anchor_t object.+ *+ * This function returns the number of active references to a anchor object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_anchor_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param anchor A pointer to the anchor object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified anchor object. If the object+ * is properly managed (i.e., every \ref cardano_anchor_ref call is matched with a+ * \ref cardano_anchor_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming anchor is a previously created anchor object+ *+ * size_t ref_count = cardano_anchor_refcount(anchor);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_anchor_refcount(const cardano_anchor_t* anchor);++/**+ * \brief Sets the last error message for a given anchor object.+ *+ * Records an error message in the anchor's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] anchor A pointer to the \ref cardano_anchor_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the anchor's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_anchor_set_last_error(cardano_anchor_t* anchor, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific anchor.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_anchor_set_last_error for the given+ * anchor. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] anchor A pointer to the \ref cardano_anchor_t instance whose last error+ *                   message is to be retrieved. If the anchor is NULL, the function+ *                   returns a generic error message indicating the null anchor.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified anchor. If the anchor is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_anchor_set_last_error for the same anchor, or until+ *       the anchor is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_anchor_get_last_error(const cardano_anchor_t* anchor);++/**+ * \brief Creates an independent deep copy of a \ref cardano_anchor_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_anchor_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_anchor_deep_clone(const cardano_anchor_t* source, cardano_anchor_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_ANCHOR_H
+ vendor/include/cardano/common/bigint.h view
@@ -0,0 +1,2001 @@+/**+ * \file bigint.h+ *+ * \author luisd.bianchi+ * \date   Jun 05, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_BIGINT_H+#define BIGLUP_LABS_INCLUDE_CARDANO_BIGINT_H++/* INCLUDES ******************************************************************/++#include <cardano/common/byte_order.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a large numeric value.+ *+ * The \ref cardano_bigint_t type is used for representing numeric values that are too large to be+ * represented by the standard numeric primitive types, such as int64_t or uint64_t.+ */+typedef struct cardano_bigint_t cardano_bigint_t;++/**+ * \brief Creates a copy of the given bigint object.+ *+ * This function duplicates the provided \ref cardano_bigint_t object.+ *+ * \param[in] bigint A constant pointer to the original \ref cardano_bigint_t object.+ * \param[out] clone A pointer to a pointer that will be set to the address of the newly created \ref cardano_bigint_t copy.+ *+ * \return \ref CARDANO_SUCCESS if the copy was successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized+ * cardano_bigint_t* clone = NULL;+ * cardano_error_t result = cardano_bigint_from(original, &clone);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the clone+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&clone);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_bigint_clone(const cardano_bigint_t* bigint, cardano_bigint_t** clone);++/**+ * \brief Creates a bigint from a string representation.+ *+ * This function initializes a \ref cardano_bigint_t object from the given string.+ *+ * \param[in] string A pointer to the string containing the representation of the bigint.+ * \param[in] size The maximum number of bytes to read. Parsing stops at the first null+ * character within this span, if present. A span without a null terminator is also accepted.+ * \param[in] base The base of the string representation (e.g., 10 for decimal, 16 for hexadecimal).+ * \param[out] bigint A pointer to a pointer that will be set to the address of the newly created \ref cardano_bigint_t object.+ *+ * \return \ref CARDANO_SUCCESS if the bigint was successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * const char* str = "1234567892356760";+ * cardano_bigint_t* bigint = NULL;+ * cardano_error_t result = cardano_bigint_from_string(str, strlen(str), 10, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the bigint+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_bigint_from_string(const char* string, size_t size, int32_t base, cardano_bigint_t** bigint);++/**+ * \brief Calculates the size of the string representation of the bigint.+ *+ * This function calculates the size of the string needed to represent the given \ref cardano_bigint_t object+ * in the specified base. The size includes space for the null terminator.+ *+ * \param[in] bigint A pointer to the \ref cardano_bigint_t object.+ * \param[in] base The base to use for the string representation (e.g., 10 for decimal, 16 for hexadecimal).+ *+ * \return The size of the string representation, including the null terminator.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = NULL;+ * cardano_error_t result = cardano_bigint_from_string("1234567892356760", 16, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   size_t str_size = cardano_bigint_get_string_size(bigint, 16);+ *   char* str = (char*)malloc(str_size);+ *+ *   if (str != NULL)+ *   {+ *     result = cardano_bigint_to_string(bigint, str, str_size);+ *+ *     if (result == CARDANO_SUCCESS)+ *     {+ *       printf("Bigint string: %s\n", str);+ *     }+ *+ *     free(str);+ *   }+ *+ *   cardano_bigint_unref(&bigint);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_bigint_get_string_size(const cardano_bigint_t* bigint, int32_t base);++/**+ * \brief Creates a bigint from an integer value.+ *+ * This function initializes a \ref cardano_bigint_t object from the given integer value.+ *+ * \param[in] value The integer value to convert to a bigint.+ * \param[out] bigint A pointer to a pointer that will be set to the address of the newly created \ref cardano_bigint_t object.+ *+ * \return \ref CARDANO_SUCCESS if the bigint was successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * int64_t value = 12345;+ * cardano_bigint_t* bigint = NULL;+ * cardano_error_t result = cardano_bigint_from_int(value, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the bigint+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_bigint_from_int(int64_t value, cardano_bigint_t** bigint);++/**+ * \brief Creates a bigint from an unsigned integer value.+ *+ * This function initializes a \ref cardano_bigint_t object from the given unsigned integer value.+ *+ * \param[in] value The unsigned integer value to convert to a bigint.+ * \param[out] bigint A pointer to a pointer that will be set to the address of the newly created \ref cardano_bigint_t object.+ *+ * \return \ref CARDANO_SUCCESS if the bigint was successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * uint64_t value = 12345;+ * cardano_bigint_t* bigint = NULL;+ *+ * cardano_error_t result = cardano_bigint_from_unsigned_int(value, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the bigint+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_bigint_from_unsigned_int(uint64_t value, cardano_bigint_t** bigint);++/**+ * \brief Creates a bigint from a byte array.+ *+ * This function initializes a \ref cardano_bigint_t object from the given byte array.+ * The function also allows specifying the byte order of the input data (big-endian or little-endian).+ *+ * \param[in] data A pointer to the byte array containing the representation of the bigint.+ * \param[in] size The size of the byte array.+ * \param[in] byte_order An enum value indicating the byte order of the input data.+ *                       Use \ref CARDANO_BYTE_ORDER_BIG_ENDIAN for big-endian and \ref CARDANO_BYTE_ORDER_LITTLE_ENDIAN for little-endian.+ * \param[out] bigint A pointer to a pointer that will be set to the address of the newly created \ref cardano_bigint_t object.+ *+ * \return \ref CARDANO_SUCCESS if the bigint was successfully created, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * byte_t bytes[] = { 0x01, 0x02, 0x03 };+ * cardano_bigint_t* bigint = NULL;+ * cardano_byte_order_t byte_order = CARDANO_BYTE_ORDER_LITTLE_ENDIAN;+ *+ * cardano_error_t result = cardano_bigint_from_bytes(bytes, sizeof(bytes), byte_order, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the bigint+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_bigint_from_bytes(+  const byte_t*        data,+  size_t               size,+  cardano_byte_order_t byte_order,+  cardano_bigint_t**   bigint);++/**+ * \brief Converts a bigint to its string representation.+ *+ * This function converts a \ref cardano_bigint_t object to a string.+ *+ * \param[in] bigint A constant pointer to the \ref cardano_bigint_t object.+ * \param[out] string A pointer to the buffer where the string representation will be stored.+ * \param[in] size The size of the buffer.+ * \param[in] base The numerical base for the string representation. Valid values are from 2 to 36.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful, or an appropriate error code indicating the failure reason.+ *+ * \note It is recommended to use \ref cardano_bigint_get_string_size to get the actual size of the string needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized with a value+ * size_t str_size = cardano_bigint_get_string_size(bigint, 10);+ * char* buffer = (char*)malloc(str_size);+ *+ * cardano_error_t result = cardano_bigint_to_string(bigint, buffer, str_size, 10);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("BigInt as string: %s\n", buffer);+ * }+ *+ * // Clean up+ * free(buffer);+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_bigint_to_string(+  const cardano_bigint_t* bigint,+  char*                   string,+  size_t                  size,+  int32_t                 base);++/**+ * \brief Converts a bigint to an integer value.+ *+ * This function converts a \ref cardano_bigint_t object to an integer value.+ *+ * \param[in] bigint A constant pointer to the \ref cardano_bigint_t object.+ *+ * \return The integer value, reduced modulo 2^64 and interpreted as a signed 64-bit+ * two's-complement value. Returns zero if \p bigint is NULL. Values in the int64_t+ * range, including INT64_MIN, are returned exactly.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized+ * int64_t value = cardano_bigint_to_int(bigint);+ *+ * // Use the integer value+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT int64_t+cardano_bigint_to_int(const cardano_bigint_t* bigint);++/**+ * \brief Converts a bigint to an unsigned integer value.+ *+ * This function converts a \ref cardano_bigint_t object to an unsigned integer value.+ *+ * \param[in] bigint A constant pointer to the \ref cardano_bigint_t object.+ *+ * \return The unsigned integer representation of the \ref cardano_bigint_t object. Only the+ *         low 64 bits of the magnitude are kept when the value does not fit in an uint64_t.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized+ * uint64_t value = cardano_bigint_to_unsigned_int(bigint);+ *+ * // Use the unsigned integer value+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t+cardano_bigint_to_unsigned_int(const cardano_bigint_t* bigint);++/**+ * \brief Gets the size of the byte array needed to represent a bigint.+ *+ * This function calculates the size of the byte array required to represent the given \ref cardano_bigint_t object.+ *+ * \param[in] bigint A constant pointer to the \ref cardano_bigint_t object.+ *+ * \return The size of the byte array needed to represent the bigint.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized+ * size_t byte_size = cardano_bigint_get_bytes_size(bigint);+ *+ * // Use the byte size value+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_bigint_get_bytes_size(const cardano_bigint_t* bigint);++/**+ * \brief Converts a bigint to its byte array representation.+ *+ * This function exports the absolute magnitude as an unsigned byte array. Zero is+ * encoded as one zero byte in either byte order.+ *+ * \param[in] bigint A constant pointer to the \ref cardano_bigint_t object.+ * \param[in] byte_order The byte order for the byte array (big-endian or little-endian).+ * \param[out] data A pointer to the buffer where the byte array will be stored.+ * \param[in] size The size of the buffer.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful, or an appropriate error code indicating the failure reason.+ *+ * \note It is recommended to use \ref cardano_bigint_get_bytes_size to get the exact size of the byte array needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized with a value+ * size_t byte_size = cardano_bigint_get_bytes_size(bigint);+ * byte_t* buffer = (byte_t*)malloc(byte_size);+ *+ * cardano_error_t result = cardano_bigint_to_bytes(bigint, CARDANO_BYTE_ORDER_LITTLE_ENDIAN, buffer, byte_size);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the byte array representation+ * }+ *+ * // Clean up+ * free(buffer);+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_bigint_to_bytes(+  const cardano_bigint_t* bigint,+  cardano_byte_order_t    byte_order,+  byte_t*                 data,+  size_t                  size);++/**+ * \brief Adds two bigint objects.+ *+ * This function performs addition of two \ref cardano_bigint_t objects and stores the result in a third bigint.+ *+ * \param[in] lhs A constant pointer to the first operand.+ * \param[in] rhs A constant pointer to the second operand.+ * \param[out] result A pointer to the pre-initialized \ref cardano_bigint_t object where the result will be stored.+ *                    This is not a factory method; \p result must be pre-initialized and cannot be NULL.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * const char* lhs_str = "123456789012345678901234567890";+ * const char* rhs_str = "987654321098765432109876543210";+ *+ * cardano_bigint_t* lhs = NULL;+ * cardano_bigint_t* rhs = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t lhs_result = cardano_bigint_from_string(lhs_str, strlen(lhs_str), 10, &lhs);+ * cardano_error_t rhs_result = cardano_bigint_from_string(rhs_str, strlen(rhs_str), 10, &rhs);+ * cardano_error_t res_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (lhs_result == CARDANO_SUCCESS && rhs_result == CARDANO_SUCCESS && res_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_add(lhs, rhs, result);+ *+ *   size_t result_size = cardano_bigint_get_string_size(result, 10);+ *   char* result_str = (char*)malloc(result_size);+ *+ *   cardano_error_t str_result = cardano_bigint_to_string(result, result_str, result_size, 10);+ *+ *   if (str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Result of addition: %s\n", result_str); // Should print "1111111110111111111011111111100"+ *   }+ *+ *   free(result_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_add(+  const cardano_bigint_t* lhs,+  const cardano_bigint_t* rhs,+  cardano_bigint_t*       result);++/**+ * \brief Subtracts one bigint object from another.+ *+ * This function performs subtraction of two \ref cardano_bigint_t objects and stores the result in a third bigint.+ *+ * \param[in] lhs A constant pointer to the minuend.+ * \param[in] rhs A constant pointer to the subtrahend.+ * \param[out] result A pointer to the pre-initialized \ref cardano_bigint_t object where the result will be stored.+ *                    This is not a factory method; \p result must be pre-initialized and cannot be NULL.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * const char* lhs_str = "987654321098765432109876543210";+ * const char* rhs_str = "123456789012345678901234567890";+ *+ * cardano_bigint_t* lhs = NULL;+ * cardano_bigint_t* rhs = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t lhs_result = cardano_bigint_from_string(lhs_str, strlen(lhs_str), 10, &lhs);+ * cardano_error_t rhs_result = cardano_bigint_from_string(rhs_str, strlen(rhs_str), 10, &rhs);+ * cardano_error_t res_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (lhs_result == CARDANO_SUCCESS && rhs_result == CARDANO_SUCCESS && res_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_subtract(lhs, rhs, result);+ *+ *   size_t result_size = cardano_bigint_get_string_size(result, 10);+ *   char* result_str = (char*)malloc(result_size);+ *+ *   cardano_error_t str_result = cardano_bigint_to_string(result, result_str, result_size, 10);+ *+ *   if (str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Result of subtraction: %s\n", result_str); // Should print "864197532086419753208641975320"+ *   }+ *+ *   free(result_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_subtract(+  const cardano_bigint_t* lhs,+  const cardano_bigint_t* rhs,+  cardano_bigint_t*       result);++/**+ * \brief Multiplies two bigint objects.+ *+ * This function performs multiplication of two \ref cardano_bigint_t objects and stores the result in a third bigint.+ *+ * \param[in] lhs A constant pointer to the first operand.+ * \param[in] rhs A constant pointer to the second operand.+ * \param[out] result A pointer to the pre-initialized \ref cardano_bigint_t object where the result will be stored.+ *                    This is not a factory method; \p result must be pre-initialized and cannot be NULL.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * const char* lhs_str = "123456789";+ * const char* rhs_str = "987654321";+ *+ * cardano_bigint_t* lhs = NULL;+ * cardano_bigint_t* rhs = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t lhs_result = cardano_bigint_from_string(lhs_str, strlen(lhs_str), 10, &lhs);+ * cardano_error_t rhs_result = cardano_bigint_from_string(rhs_str, strlen(rhs_str), 10, &rhs);+ * cardano_error_t res_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (lhs_result == CARDANO_SUCCESS && rhs_result == CARDANO_SUCCESS && res_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_multiply(lhs, rhs, result);+ *+ *   size_t result_size = cardano_bigint_get_string_size(result, 10);+ *   char* result_str = (char*)malloc(result_size);+ *+ *   cardano_error_t str_result = cardano_bigint_to_string(result, result_str, result_size, 10);+ *+ *   if (str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Result of multiplication: %s\n", result_str); // Should print "121932631112635269"+ *   }+ *+ *   free(result_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_multiply(+  const cardano_bigint_t* lhs,+  const cardano_bigint_t* rhs,+  cardano_bigint_t*       result);++/**+ * \brief Divides one bigint object by another.+ *+ * This function performs division of two \ref cardano_bigint_t objects and stores the result in a third bigint.+ *+ * \param[in] dividend A constant pointer to the dividend.+ * \param[in] divisor A constant pointer to the divisor.+ * \param[out] result A pointer to the pre-initialized \ref cardano_bigint_t object where the result will be stored.+ *                    This is not a factory method; \p result must be pre-initialized and cannot be NULL.+ *+ * \remark If any of the pointers (\p dividend, \p divisor, or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * const char* dividend_str = "987654321";+ * const char* divisor_str = "123456789";+ *+ * cardano_bigint_t* dividend = NULL;+ * cardano_bigint_t* divisor = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t div_result = cardano_bigint_from_string(dividend_str, strlen(dividend_str), 10, &dividend);+ * cardano_error_t divs_result = cardano_bigint_from_string(divisor_str, strlen(divisor_str), 10, &divisor);+ * cardano_error_t res_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (div_result == CARDANO_SUCCESS && divs_result == CARDANO_SUCCESS && res_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_divide(dividend, divisor, result);+ *+ *   size_t result_size = cardano_bigint_get_string_size(result, 10);+ *   char* result_str = (char*)malloc(result_size);+ *+ *   cardano_error_t str_result = cardano_bigint_to_string(result, result_str, result_size, 10);+ *+ *   if (str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Result of division: %s\n", result_str); // Should print "8"+ *   }+ *+ *   free(result_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&dividend);+ * cardano_bigint_unref(&divisor);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_divide(+  const cardano_bigint_t* dividend,+  const cardano_bigint_t* divisor,+  cardano_bigint_t*       result);++/**+ * \brief Divides one bigint object by another and computes the remainder.+ *+ * This function performs division of two \ref cardano_bigint_t objects and stores the quotient in one bigint and the remainder in another bigint.+ *+ * \param[in] dividend A constant pointer to the dividend.+ * \param[in] divisor A constant pointer to the divisor.+ * \param[out] quotient A pointer to the pre-initialized \ref cardano_bigint_t object where the quotient will be stored.+ *                      This is not a factory method; \p quotient must be pre-initialized and cannot be NULL.+ * \param[out] reminder A pointer to the pre-initialized \ref cardano_bigint_t object where the remainder will be stored.+ *                      This is not a factory method; \p reminder must be pre-initialized and cannot be NULL.+ *+ * \remark If any of the pointers (\p dividend, \p divisor, \p quotient, or \p reminder) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * const char* dividend_str = "987654321";+ * const char* divisor_str = "123456789";+ *+ * cardano_bigint_t* dividend = NULL;+ * cardano_bigint_t* divisor = NULL;+ * cardano_bigint_t* quotient = NULL;+ * cardano_bigint_t* reminder = NULL;+ *+ * cardano_error_t div_result = cardano_bigint_from_string(dividend_str, strlen(dividend_str), 10, &dividend);+ * cardano_error_t divs_result = cardano_bigint_from_string(divisor_str, strlen(divisor_str), 10, &divisor);+ * cardano_error_t quo_result = cardano_bigint_from_int(0, &quotient); // Initialize quotient with 0+ * cardano_error_t rem_result = cardano_bigint_from_int(0, &reminder); // Initialize reminder with 0+ *+ * if (div_result == CARDANO_SUCCESS && divs_result == CARDANO_SUCCESS && quo_result == CARDANO_SUCCESS && rem_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_divide_and_reminder(dividend, divisor, quotient, reminder);+ *+ *   size_t quotient_size = cardano_bigint_get_string_size(quotient, 10);+ *   char* quotient_str = (char*)malloc(quotient_size);+ *+ *   cardano_error_t quo_str_result = cardano_bigint_to_string(quotient, quotient_str, quotient_size, 10);+ *+ *   size_t reminder_size = cardano_bigint_get_string_size(reminder, 10);+ *   char* reminder_str = (char*)malloc(reminder_size);+ *+ *   cardano_error_t rem_str_result = cardano_bigint_to_string(reminder, reminder_str, reminder_size, 10);+ *+ *   if (quo_str_result == CARDANO_SUCCESS && rem_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Quotient: %s\n", quotient_str); // Should print "8"+ *     printf("Reminder: %s\n", reminder_str); // Should print "9"+ *   }+ *+ *   free(quotient_str);+ *   free(reminder_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&dividend);+ * cardano_bigint_unref(&divisor);+ * cardano_bigint_unref(&quotient);+ * cardano_bigint_unref(&reminder);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_divide_and_reminder(+  const cardano_bigint_t* dividend,+  const cardano_bigint_t* divisor,+  cardano_bigint_t*       quotient,+  cardano_bigint_t*       reminder);++/**+ * \brief Computes the remainder of dividing one bigint object by another.+ *+ * This function performs modulo operation on two \ref cardano_bigint_t objects and stores the remainder in a third bigint.+ *+ * \param[in] dividend A constant pointer to the dividend.+ * \param[in] divisor A constant pointer to the divisor.+ * \param[out] reminder A pointer to the pre-initialized \ref cardano_bigint_t object where the remainder will be stored.+ *                      This is not a factory method; \p reminder must be pre-initialized and cannot be NULL.+ *+ * \remark If any of the pointers (\p dividend, \p divisor, or \p reminder) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * const char* dividend_str = "987654321";+ * const char* divisor_str = "123456789";+ *+ * cardano_bigint_t* dividend = NULL;+ * cardano_bigint_t* divisor = NULL;+ * cardano_bigint_t* reminder = NULL;+ *+ * cardano_error_t div_result = cardano_bigint_from_string(dividend_str, strlen(dividend_str), 10, &dividend);+ * cardano_error_t divs_result = cardano_bigint_from_string(divisor_str, strlen(divisor_str), 10, &divisor);+ * cardano_error_t rem_result = cardano_bigint_from_int(0, &reminder); // Initialize reminder with 0+ *+ * if (div_result == CARDANO_SUCCESS && divs_result == CARDANO_SUCCESS && rem_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_reminder(dividend, divisor, reminder);+ *+ *   size_t reminder_size = cardano_bigint_get_string_size(reminder, 10);+ *   char* reminder_str = (char*)malloc(reminder_size);+ *+ *   cardano_error_t rem_str_result = cardano_bigint_to_string(reminder, reminder_str, reminder_size, 10);+ *+ *   if (rem_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Reminder: %s\n", reminder_str); // Should print "9"+ *   }+ *+ *   free(reminder_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&dividend);+ * cardano_bigint_unref(&divisor);+ * cardano_bigint_unref(&reminder);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_reminder(+  const cardano_bigint_t* dividend,+  const cardano_bigint_t* divisor,+  cardano_bigint_t*       reminder);++/**+ * \brief Computes the absolute value of a bigint.+ *+ * This function computes the absolute value of the given \ref cardano_bigint_t object and stores the result in another bigint.+ *+ * \param[in] bignum A constant pointer to the bigint object.+ * \param[out] result A pointer to the pre-initialized \ref cardano_bigint_t object where the result will be stored.+ *                    This is not a factory method; \p result must be pre-initialized and cannot be NULL.+ *+ * \remark If any of the pointers (\p bignum or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * const char* bignum_str = "-123456789";+ *+ * cardano_bigint_t* bignum = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t bignum_result = cardano_bigint_from_string(bignum_str, strlen(bignum_str), 10, &bignum);+ * cardano_error_t abs_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (bignum_result == CARDANO_SUCCESS && abs_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_abs(bignum, result);+ *+ *   size_t abs_size = cardano_bigint_get_string_size(result, 10);+ *   char* abs_str = (char*)malloc(abs_size);+ *+ *   cardano_error_t abs_str_result = cardano_bigint_to_string(result, abs_str, abs_size, 10);+ *+ *   if (abs_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Absolute value: %s\n", abs_str); // Should print "123456789"+ *   }+ *+ *   free(abs_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bignum);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_abs(const cardano_bigint_t* bignum, cardano_bigint_t* result);++/**+ * \brief Computes the greatest common divisor (GCD) of two bigints.+ *+ * This function computes the GCD of the given \ref cardano_bigint_t objects and stores the result in another bigint.+ *+ * \param[in] lhs A constant pointer to the first bigint object.+ * \param[in] rhs A constant pointer to the second bigint object.+ * \param[out] result A pointer to the pre-initialized \ref cardano_bigint_t object where the result will be stored.+ *                    This is not a factory method; \p result must be pre-initialized and cannot be NULL.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * const char* lhs_str = "48";+ * const char* rhs_str = "18";+ *+ * cardano_bigint_t* lhs = NULL;+ * cardano_bigint_t* rhs = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t lhs_result = cardano_bigint_from_string(lhs_str, strlen(lhs_str), 10, &lhs);+ * cardano_error_t rhs_result = cardano_bigint_from_string(rhs_str, strlen(rhs_str), 10, &rhs);+ * cardano_error_t gcd_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (lhs_result == CARDANO_SUCCESS && rhs_result == CARDANO_SUCCESS && gcd_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_gcd(lhs, rhs, result);+ *+ *   size_t gcd_size = cardano_bigint_get_string_size(result, 10);+ *   char* gcd_str = (char*)malloc(gcd_size);+ *+ *   cardano_error_t gcd_str_result = cardano_bigint_to_string(result, gcd_str, gcd_size, 10);+ *+ *   if (gcd_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("GCD: %s\n", gcd_str); // Should print "6"+ *   }+ *+ *   free(gcd_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_gcd(const cardano_bigint_t* lhs, const cardano_bigint_t* rhs, cardano_bigint_t* result);++/**+ * \brief Negates a bigint.+ *+ * This function computes the negation of the given \ref cardano_bigint_t object and stores the result in another bigint.+ *+ * \param[in] bignum A constant pointer to the bigint object.+ * \param[out] result A pointer to the pre-initialized \ref cardano_bigint_t object where the result will be stored.+ *                    This is not a factory method; \p result must be pre-initialized and cannot be NULL.+ *+ * \remark If any of the pointers (\p bignum or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * const char* bignum_str = "12";+ *+ * cardano_bigint_t* bignum = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t bignum_result = cardano_bigint_from_string(bignum_str, strlen(bignum_str), 10, &bignum);+ * cardano_error_t negate_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (bignum_result == CARDANO_SUCCESS && negate_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_negate(bignum, result);+ *+ *   size_t neg_size = cardano_bigint_get_string_size(result, 10);+ *   char* neg_str = (char*)malloc(neg_size);+ *+ *   cardano_error_t neg_str_result = cardano_bigint_to_string(result, neg_str, neg_size, 10);+ *+ *   if (neg_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Negated value: %s\n", neg_str); // Should print "-12"+ *   }+ *+ *   free(neg_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bignum);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_negate(const cardano_bigint_t* bignum, cardano_bigint_t* result);++/**+ * \brief Computes the signum function of a bigint.+ *+ * This function returns the signum of the given \ref cardano_bigint_t object. The signum function returns:+ * -1 if the bigint is negative,+ *  0 if the bigint is zero,+ *  1 if the bigint is positive.+ *+ * \param[in] bignum A constant pointer to the bigint object.+ *+ * \return The signum of the bigint as an \c int32_t.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bignum = ...; // Assume this is initialized+ * int32_t sign = cardano_bigint_signum(bignum);+ * // Use the sign+ * // Clean up+ * cardano_bigint_unref(&bignum);+ * \endcode+ */+CARDANO_EXPORT+int32_t cardano_bigint_signum(const cardano_bigint_t* bignum);++/**+ * \brief Computes the remainder of dividing one bigint object by another.+ *+ * This function performs the modulo operation on two \ref cardano_bigint_t objects and stores the result in a third bigint.+ *+ * \param[in] lhs A constant pointer to the dividend.+ * \param[in] rhs A constant pointer to the divisor.+ * \param[out] result A pointer to the bigint object where the result will be stored.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the big integers+ * int64_t lhs_value = 10;+ * int64_t rhs_value = 3;+ *+ * cardano_bigint_t* lhs = NULL;+ * cardano_bigint_t* rhs = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t lhs_result = cardano_bigint_from_int(lhs_value, &lhs);+ * cardano_error_t rhs_result = cardano_bigint_from_int(rhs_value, &rhs);+ * cardano_error_t mod_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (lhs_result == CARDANO_SUCCESS && rhs_result == CARDANO_SUCCESS && mod_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_mod(lhs, rhs, result);+ *+ *   size_t res_size = cardano_bigint_get_string_size(result, 10);+ *   char* res_str = (char*)malloc(res_size);+ *+ *   cardano_error_t res_str_result = cardano_bigint_to_string(result, res_str, res_size, 10);+ *+ *   if (res_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Modulo result: %s\n", res_str); // Should print "1" for 10 % 3+ *   }+ *+ *   free(res_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_mod(+  const cardano_bigint_t* lhs,+  const cardano_bigint_t* rhs,+  cardano_bigint_t*       result);++/**+ * \brief Computes the result of raising a bigint to the power of another bigint modulo a third bigint.+ *+ * This function computes the modular exponentiation of two \ref cardano_bigint_t objects and stores the result in a third bigint.+ *+ * \param[in] base A constant pointer to the base bigint.+ * \param[in] exponent A constant pointer to the exponent bigint.+ * \param[in] modulus A constant pointer to the modulus bigint.+ * \param[out] result A pointer to the bigint object where the result will be stored.+ *+ * \remark If any of the pointers (\p base, \p exponent, \p modulus, or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the big integers+ * int64_t base_value = 4;+ * int64_t exponent_value = 13;+ * int64_t modulus_value = 497;+ *+ * cardano_bigint_t* base = NULL;+ * cardano_bigint_t* exponent = NULL;+ * cardano_bigint_t* modulus = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t base_result = cardano_bigint_from_int(base_value, &base);+ * cardano_error_t exponent_result = cardano_bigint_from_int(exponent_value, &exponent);+ * cardano_error_t modulus_result = cardano_bigint_from_int(modulus_value, &modulus);+ * cardano_error_t result_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (base_result == CARDANO_SUCCESS && exponent_result == CARDANO_SUCCESS &&+ *     modulus_result == CARDANO_SUCCESS && result_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_mod_pow(base, exponent, modulus, result);+ *+ *   size_t res_size = cardano_bigint_get_string_size(result, 10);+ *   char* res_str = (char*)malloc(res_size);+ *+ *   cardano_error_t res_str_result = cardano_bigint_to_string(result, res_str, res_size, 10);+ *+ *   if (res_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Modular exponentiation result: %s\n", res_str); // Should print "445" for 4^13 % 497+ *   }+ *+ *   free(res_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&base);+ * cardano_bigint_unref(&exponent);+ * cardano_bigint_unref(&modulus);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_mod_pow(+  const cardano_bigint_t* base,+  const cardano_bigint_t* exponent,+  const cardano_bigint_t* modulus,+  cardano_bigint_t*       result);++/**+ * \brief Computes the modular multiplicative inverse of a bigint.+ *+ * This function computes the modular multiplicative inverse of a \ref cardano_bigint_t object and stores the result in another bigint.+ *+ * \param[in] bignum A constant pointer to the bigint whose modular inverse is to be computed.+ * \param[in] modulus A constant pointer to the modulus bigint.+ * \param[out] result A pointer to the bigint object where the result will be stored.+ *+ * \remark If any of the pointers (\p bignum, \p modulus, or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the big integers+ * int64_t bignum_value = 3;+ * int64_t modulus_value = 11;+ *+ * cardano_bigint_t* bignum = NULL;+ * cardano_bigint_t* modulus = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t bignum_result = cardano_bigint_from_int(bignum_value, &bignum);+ * cardano_error_t modulus_result = cardano_bigint_from_int(modulus_value, &modulus);+ * cardano_error_t result_result = cardano_bigint_from_int(0, &result); // Initialize result with 0+ *+ * if (bignum_result == CARDANO_SUCCESS && modulus_result == CARDANO_SUCCESS && result_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_mod_inverse(bignum, modulus, result);+ *+ *   size_t res_size = cardano_bigint_get_string_size(result, 10);+ *   char* res_str = (char*)malloc(res_size);+ *+ *   cardano_error_t res_str_result = cardano_bigint_to_string(result, res_str, res_size, 10);+ *+ *   if (res_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Modular inverse result: %s\n", res_str); // Should print "4" for 3^-1 % 11+ *   }+ *+ *   free(res_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bignum);+ * cardano_bigint_unref(&modulus);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_mod_inverse(+  const cardano_bigint_t* bignum,+  const cardano_bigint_t* modulus,+  cardano_bigint_t*       result);++/**+ * \brief Performs bitwise AND operation on two bigint objects.+ *+ * This function performs bitwise AND of two \ref cardano_bigint_t objects and stores the result in a third bigint.+ *+ * \param[in] lhs A constant pointer to the first operand.+ * \param[in] rhs A constant pointer to the second operand.+ * \param[out] result A pointer to the bigint object where the result will be stored.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect. The \p result pointer must be pre-initialized and cannot be NULL.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the big integers+ * const char* lhs_str = "101010"; // Binary: 101010+ * const char* rhs_str = "110011"; // Binary: 110011+ *+ * cardano_bigint_t* lhs = NULL;+ * cardano_bigint_t* rhs = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t lhs_result = cardano_bigint_from_string(lhs_str, strlen(lhs_str), 2, &lhs);+ * cardano_error_t rhs_result = cardano_bigint_from_string(rhs_str, strlen(rhs_str), 2, &rhs);+ * cardano_error_t res_result = cardano_bigint_from_string("0", 1, 2, &result); // Initialize result with 0+ *+ * if (lhs_result == CARDANO_SUCCESS && rhs_result == CARDANO_SUCCESS && res_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_and(lhs, rhs, result);+ *+ *   size_t res_size = cardano_bigint_get_string_size(result, 2);+ *   char* res_str = (char*)malloc(res_size);+ *+ *   cardano_error_t res_str_result = cardano_bigint_to_string(result, res_str, res_size, 2);+ *+ *   if (res_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Bitwise AND result: %s\n", res_str); // Should print "100010" for 101010 & 110011+ *   }+ *+ *   free(res_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_and(+  const cardano_bigint_t* lhs,+  const cardano_bigint_t* rhs,+  cardano_bigint_t*       result);++/**+ * \brief Performs bitwise OR operation on two bigint objects.+ *+ * This function performs bitwise OR of two \ref cardano_bigint_t objects and stores the result in a third bigint.+ *+ * \param[in] lhs A constant pointer to the first operand.+ * \param[in] rhs A constant pointer to the second operand.+ * \param[out] result A pointer to the bigint object where the result will be stored.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect. The \p result pointer must be pre-initialized and cannot be NULL.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the big integers+ * const char* lhs_str = "101010"; // Binary: 101010+ * const char* rhs_str = "110011"; // Binary: 110011+ *+ * cardano_bigint_t* lhs = NULL;+ * cardano_bigint_t* rhs = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t lhs_result = cardano_bigint_from_string(lhs_str, strlen(lhs_str), 2, &lhs);+ * cardano_error_t rhs_result = cardano_bigint_from_string(rhs_str, strlen(rhs_str), 2, &rhs);+ * cardano_error_t res_result = cardano_bigint_from_string("0", 1, 2, &result); // Initialize result with 0+ *+ * if (lhs_result == CARDANO_SUCCESS && rhs_result == CARDANO_SUCCESS && res_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_or(lhs, rhs, result);+ *+ *   size_t res_size = cardano_bigint_get_string_size(result, 2);+ *   char* res_str = (char*)malloc(res_size);+ *+ *   cardano_error_t res_str_result = cardano_bigint_to_string(result, res_str, res_size, 2);+ *+ *   if (res_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Bitwise OR result: %s\n", res_str); // Should print "111011" for 101010 | 110011+ *   }+ *+ *   free(res_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_or(+  const cardano_bigint_t* lhs,+  const cardano_bigint_t* rhs,+  cardano_bigint_t*       result);++/**+ * \brief Performs bitwise XOR operation on two bigint objects.+ *+ * This function performs bitwise XOR of two \ref cardano_bigint_t objects and stores the result in a third bigint.+ *+ * \param[in] lhs A constant pointer to the first operand.+ * \param[in] rhs A constant pointer to the second operand.+ * \param[out] result A pointer to the bigint object where the result will be stored.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect. The \p result pointer must be pre-initialized and cannot be NULL.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the big integers+ * const char* lhs_str = "101010"; // Binary: 101010+ * const char* rhs_str = "110011"; // Binary: 110011+ *+ * cardano_bigint_t* lhs = NULL;+ * cardano_bigint_t* rhs = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t lhs_result = cardano_bigint_from_string(lhs_str, strlen(lhs_str), 2, &lhs);+ * cardano_error_t rhs_result = cardano_bigint_from_string(rhs_str, strlen(rhs_str), 2, &rhs);+ * cardano_error_t res_result = cardano_bigint_from_string("0", 1, 2, &result); // Initialize result with 0+ *+ * if (lhs_result == CARDANO_SUCCESS && rhs_result == CARDANO_SUCCESS && res_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_xor(lhs, rhs, result);+ *+ *   size_t res_size = cardano_bigint_get_string_size(result, 2);+ *   char* res_str = (char*)malloc(res_size);+ *+ *   cardano_error_t res_str_result = cardano_bigint_to_string(result, res_str, res_size, 2);+ *+ *   if (res_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Bitwise XOR result: %s\n", res_str); // Should print "011001" for 101010 ^ 110011+ *   }+ *+ *   free(res_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_xor(+  const cardano_bigint_t* lhs,+  const cardano_bigint_t* rhs,+  cardano_bigint_t*       result);++/**+ * \brief Performs bitwise NOT operation on a bigint object.+ *+ * This function performs bitwise NOT of a \ref cardano_bigint_t object and stores the result in another bigint.+ *+ * \param[in] bigint A constant pointer to the operand.+ * \param[out] result A pointer to the bigint object where the result will be stored.+ *+ * \remark If any of the pointers (\p bigint or \p result) is NULL, the operation has no effect. The \p result pointer must be pre-initialized and cannot be NULL.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the big integers+ * const char* bigint_str = "101010"; // Binary: 101010+ *+ * cardano_bigint_t* bigint = NULL;+ * cardano_bigint_t* result = NULL;+ *+ * cardano_error_t bigint_result = cardano_bigint_from_string(bigint_str, strlen(bigint_str), 2, &bigint);+ * cardano_error_t res_result = cardano_bigint_from_string("0", 1, 2, &result); // Initialize result with 0+ *+ * if (bigint_result == CARDANO_SUCCESS && res_result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_not(bigint, result);+ *+ *   size_t res_size = cardano_bigint_get_string_size(result, 2);+ *   char* res_str = (char*)malloc(res_size);+ *+ *   cardano_error_t res_str_result = cardano_bigint_to_string(result, res_str, res_size, 2);+ *+ *   if (res_str_result == CARDANO_SUCCESS)+ *   {+ *     printf("Bitwise NOT result: %s\n", res_str); // Example result depends on the bit length+ *   }+ *+ *   free(res_str);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_not(+  const cardano_bigint_t* bigint,+  cardano_bigint_t*       result);++/**+ * \brief Tests whether a specific bit is set in a bigint object.+ *+ * This function checks whether the bit at the specified position in a \ref cardano_bigint_t object is set.+ *+ * \param[in] bigint A constant pointer to the bigint object to be tested.+ * \param[in] n The index of the bit to be tested (0-based).+ *+ * \return \c true if the bit at the specified position is set, \c false otherwise.+ *+ * \remark If the \p bigint pointer is NULL, the operation has no effect and returns \c false.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the bigint+ * const char* bigint_str = "101010"; // Binary: 101010 (42 in decimal)+ *+ * cardano_bigint_t* bigint = NULL;+ * cardano_error_t result = cardano_bigint_from_string(bigint_str, strlen(bigint_str), 2, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   uint32_t bit_index = 1;+ *   bool is_set = cardano_bigint_test_bit(bigint, bit_index);+ *+ *   if (is_set)+ *   {+ *     // The bit at index 1 is set+ *     printf("Bit at index %u is set.\n", bit_index);+ *   }+ *   else+ *   {+ *     // The bit at index 1 is not set+ *     printf("Bit at index %u is not set.\n", bit_index);+ *   }+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_bigint_test_bit(+  const cardano_bigint_t* bigint,+  uint32_t                n);++/**+ * \brief Sets a specific bit in a bigint object.+ *+ * This function sets the bit at the specified position in a \ref cardano_bigint_t object.+ *+ * \param[in,out] bigint A pointer to the bigint object in which the bit will be set.+ * \param[in] n The index of the bit to be set (0-based).+ *+ * \remark If the \p bigint pointer is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the bigint+ * const char* bigint_str = "101010"; // Binary: 101010 (42 in decimal)+ *+ * cardano_bigint_t* bigint = NULL;+ * cardano_error_t result = cardano_bigint_from_string(bigint_str, strlen(bigint_str), 2, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   uint32_t bit_index = 5;+ *   cardano_bigint_set_bit(bigint, bit_index);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_set_bit(+  cardano_bigint_t* bigint,+  uint32_t          n);++/**+ * \brief Clears a specific bit in a bigint object.+ *+ * This function clears the bit at the specified position in a \ref cardano_bigint_t object.+ *+ * \param[in,out] bigint A pointer to the bigint object in which the bit will be cleared.+ * \param[in] n The index of the bit to be cleared (0-based).+ *+ * \remark If the \p bigint pointer is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the bigint+ * const char* bigint_str = "111111"; // Binary: 111111 (63 in decimal)+ *+ * cardano_bigint_t* bigint = NULL;+ * cardano_error_t result = cardano_bigint_from_string(bigint_str, strlen(bigint_str), 2, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   uint32_t bit_index = 5;+ *   cardano_bigint_clear_bit(bigint, bit_index);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_clear_bit(+  cardano_bigint_t* bigint,+  uint32_t          n);++/**+ * \brief Flips a specific bit in a bigint object.+ *+ * This function toggles the bit at the specified position in a \ref cardano_bigint_t object.+ * If the bit is 1, it will be changed to 0. If the bit is 0, it will be changed to 1.+ *+ * \param[in,out] bigint A pointer to the bigint object in which the bit will be flipped.+ * \param[in] n The index of the bit to be flipped (0-based).+ *+ * \remark If the \p bigint pointer is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the bigint+ * const char* bigint_str = "101010"; // Binary: 101010 (42 in decimal)+ *+ * cardano_bigint_t* bigint = NULL;+ * cardano_error_t result = cardano_bigint_from_string(bigint_str, strlen(bigint_str), 2, &bigint);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   uint32_t bit_index = 1;+ *   cardano_bigint_flip_bit(bigint, bit_index);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_flip_bit(+  cardano_bigint_t* bigint,+  uint32_t          n);++/**+ * \brief Returns the number of bits in the two's complement representation of this BigInteger that differ from its sign bit.+ *+ * This function computes the number of bits in the two's complement representation of the given \ref cardano_bigint_t object that differ from its sign bit.+ *+ * \param[in] bigint A constant pointer to the bigint object.+ *+ * \return The number of bits that differ from the sign bit.+ *+ * \remark If the \p bigint pointer is NULL, the function returns 0.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized+ *+ * size_t bit_count = cardano_bigint_bit_count(bigint);+ * printf("The number of bits that differ from the sign bit is: %zu\n", bit_count);+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_bigint_bit_count(const cardano_bigint_t* bigint);++/**+ * \brief Returns the number of bits required to represent the bigint in a minimal two's-complement form.+ *+ * This function calculates the bit length required to represent the integer stored in a \ref cardano_bigint_t object in its minimal two's-complement form.+ * This count includes the necessary bits for the absolute value of the number and the sign bit.+ *+ * \param[in] bigint A constant pointer to the bigint object.+ *+ * \return The number of bits required to represent the bigint in two's-complement form, effectively equal to the actual bit length of the integer as stored.+ * If the bigint pointer is NULL, the function returns 0.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized+ *+ * size_t bit_length = cardano_bigint_bit_length(bigint);+ * printf("The bit length of the bigint is: %zu\n", bit_length);+ *+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_bigint_bit_length(const cardano_bigint_t* bigint);++/**+ * \brief Computes the minimum of two bigint objects.+ *+ * This function compares two \ref cardano_bigint_t objects and stores the smaller value in a third bigint object.+ *+ * \param[in] lhs A constant pointer to the first operand.+ * \param[in] rhs A constant pointer to the second operand.+ * \param[out] result A pointer to the bigint object where the minimum value will be stored.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect.+ *+ * \return \c true if the minimum value was successfully computed and stored in \p result, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* lhs = ...; // Assume these are initialized+ * cardano_bigint_t* rhs = ...;+ * cardano_bigint_t* result = ...;+ *+ * cardano_bigint_min(lhs, rhs, result);+ *+ * // Use the result+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_min(+  cardano_bigint_t* lhs,+  cardano_bigint_t* rhs,+  cardano_bigint_t* result);++/**+ * \brief Computes the maximum of two bigint objects.+ *+ * This function compares two \ref cardano_bigint_t objects and stores the larger value in a third bigint object.+ *+ * \param[in] lhs A constant pointer to the first operand.+ * \param[in] rhs A constant pointer to the second operand.+ * \param[out] result A pointer to the bigint object where the maximum value will be stored.+ *+ * \remark If any of the pointers (\p lhs, \p rhs, or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* lhs = ...; // Assume these are initialized+ * cardano_bigint_t* rhs = ...;+ * cardano_bigint_t* result ...;+ *+ * cardano_bigint_max(lhs, rhs, result);+ * // Use the result+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * cardano_bigint_unref(&result);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_max(+  cardano_bigint_t* lhs,+  cardano_bigint_t* rhs,+  cardano_bigint_t* result);++/**+ * \brief Performs left bitwise shift on a bigint object.+ *+ * This function shifts a \ref cardano_bigint_t object left by the specified number of bits and stores the result in another bigint.+ *+ * \param[in] n A constant pointer to the bigint to be shifted.+ * \param[in] bits The number of bits to shift.+ * \param[out] result A pointer to the bigint object where the result will be stored.+ *+ * \remark If any of the pointers (\p n or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the bigint from a binary string+ * const char* bigint_str = "1010"; // Binary: 1010 (10 in decimal)+ * cardano_bigint_t* n = NULL;+ * cardano_error_t result = cardano_bigint_from_string(bigint_str, strlen(bigint_str), 2, &n);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_t* result_bigint = cardano_bigint_new();+ *   uint32_t bits = 2;+ *+ *   cardano_bigint_shift_left(n, bits, result_bigint);+ *+ *   // Convert the result to a string for display+ *   size_t size = cardano_bigint_get_string_size(result_bigint, 2);+ *   char* buffer = (char*)malloc(size);+ *   cardano_bigint_to_string(result_bigint, buffer, size, 2);+ *+ *   printf("Result: %s\n", buffer); // Should print: 101000+ *+ *   // Clean up+ *   free(buffer);+ *   cardano_bigint_unref(&result_bigint);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&n);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_shift_left(+  const cardano_bigint_t* n,+  uint32_t                bits,+  cardano_bigint_t*       result);++/**+ * \brief Performs right bitwise shift on a bigint object.+ *+ * This function shifts a \ref cardano_bigint_t object right by the specified number of bits and stores the result in another bigint.+ *+ * \param[in] n A constant pointer to the bigint to be shifted.+ * \param[in] bits The number of bits to shift.+ * \param[out] result A pointer to the bigint object where the result will be stored.+ *+ * \remark If any of the pointers (\p n or \p result) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * // Initialize the bigint from a binary string+ * const char* bigint_str = "1010"; // Binary: 1010 (10 in decimal)+ * cardano_bigint_t* n = NULL;+ * cardano_error_t result = cardano_bigint_from_string(bigint_str, strlen(bigint_str), 2, &n);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   cardano_bigint_t* result_bigint = cardano_bigint_new();+ *   uint32_t bits = 2;+ *+ *   cardano_bigint_shift_right(n, bits, result_bigint);+ *+ *   // Convert the result to a string for display+ *   size_t size = cardano_bigint_get_string_size(result_bigint, 2);+ *   char* buffer = (char*)malloc(size);+ *   cardano_bigint_to_string(result_bigint, buffer, size, 2);+ *+ *   printf("Result: %s\n", buffer); // Should print: 10+ *+ *   // Clean up+ *   free(buffer);+ *   cardano_bigint_unref(&result_bigint);+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&n);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_shift_right(+  const cardano_bigint_t* n,+  uint32_t                bits,+  cardano_bigint_t*       result);++/**+ * \brief Checks if two bigint objects are equal.+ *+ * This function compares two \ref cardano_bigint_t objects to determine if they are equal.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_bigint_t object to be compared.+ * \param[in] rhs A constant pointer to the second \ref cardano_bigint_t object to be compared.+ *+ * \return \c true if the two bigints are equal, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* lhs = ...; // Assume these are initialized+ * cardano_bigint_t* rhs = ...;+ * bool are_equal = cardano_bigint_equals(lhs, rhs);+ *+ * if (are_equal)+ * {+ *   // The two bigints are equal+ * }+ *+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_bigint_equals(const cardano_bigint_t* lhs, const cardano_bigint_t* rhs);++/**+ * \brief Compares two bigint objects.+ *+ * This function compares two \ref cardano_bigint_t objects.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_bigint_t object to be compared.+ * \param[in] rhs A constant pointer to the second \ref cardano_bigint_t object to be compared.+ *+ * \return An integer less than, equal to, or greater than zero if \p lhs is found to be less than,+ * equal to, or greater than \p rhs, respectively.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* lhs = ...; // Assume these are initialized+ * cardano_bigint_t* rhs = ...;+ * int32 comparison = cardano_bigint_compare(lhs, rhs);+ *+ * if (comparison < 0)+ * {+ *   // lhs is less than rhs+ * }+ * else if (comparison > 0)+ * {+ *   // lhs is greater than rhs+ * }+ * else+ * {+ *   // lhs is equal to rhs+ * }+ * // Clean up+ * cardano_bigint_unref(&lhs);+ * cardano_bigint_unref(&rhs);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT int32_t cardano_bigint_compare(+  const cardano_bigint_t* lhs,+  const cardano_bigint_t* rhs);++/**+ * \brief Checks if a bigint is zero.+ *+ * This function checks if a \ref cardano_bigint_t object is zero.+ *+ * \param[in] n A constant pointer to the \ref cardano_bigint_t object to be checked.+ *+ * \return 1 if the bigint is zero, 0 otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* n = ...; // Assume this is initialized+ * bool is_zero = cardano_bigint_is_zero(n);+ * if (is_zero)+ * {+ *   // n is zero+ * }+ * else+ * {+ *   // n is not zero+ * }+ * // Clean up+ * cardano_bigint_unref(&n);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_bigint_is_zero(const cardano_bigint_t* n);++/**+ * \brief Increments a bigint.+ *+ * This function increments a \ref cardano_bigint_t object by one.+ *+ * \param[in,out] n A pointer to the \ref cardano_bigint_t object to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* n = ...; // Assume this is initialized+ * cardano_bigint_increment(n);+ * // n is now incremented+ * // Clean up+ * cardano_bigint_unref(&n);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_increment(cardano_bigint_t* n);++/**+ * \brief Decrements a bigint.+ *+ * This function decrements a \ref cardano_bigint_t object by one.+ *+ * \param[in,out] n A pointer to the \ref cardano_bigint_t object to be decremented.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* n = ...; // Assume this is initialized+ * cardano_bigint_decrement(n);+ * // n is now decremented+ * // Clean up+ * cardano_bigint_unref(&n);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_decrement(cardano_bigint_t* n);++/**+ * \brief Raises a bigint to a nonnegative integer power.+ *+ * \param[in] base A constant pointer to the base.+ * \param[in] exponent The exponent, using the full uint64_t range on every platform.+ * \param[out] result An initialized bigint that receives the power. May be the same+ * object as \p base.+ *+ * \remark An exponent of zero yields one, including when the base is zero. If+ * \p base or \p result is NULL, the operation has no effect. The result must fit+ * in available memory; large powers can require substantial memory and time.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* base = NULL;+ * cardano_bigint_t* power = NULL;+ *+ * if ((cardano_bigint_from_int(2, &base) == CARDANO_SUCCESS) &&+ *     (cardano_bigint_from_int(0, &power) == CARDANO_SUCCESS))+ * {+ *   cardano_bigint_pow(base, 3, power);+ *   int64_t value = cardano_bigint_to_int(power); // 8+ * }+ *+ * cardano_bigint_unref(&power);+ * cardano_bigint_unref(&base);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_pow(const cardano_bigint_t* base, uint64_t exponent, cardano_bigint_t* result);++/**+ * \brief Assigns one bigint to another.+ *+ * This function copies the value of one \ref cardano_bigint_t object to another.+ *+ * \param[in] source A constant pointer to the source bigint object.+ * \param[out] destination A pointer to the destination bigint object.+ *+ * \remark If any of the pointers (\p source or \p destination) is NULL, the operation has no effect.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* src = ...; // Assume these are initialized+ * cardano_bigint_t* dst = ...;+ * cardano_bigint_assign(src, dst);+ * // dst now has the same value as src+ * // Clean up+ * cardano_bigint_unref(&src);+ * cardano_bigint_unref(&dst);+ * \endcode+ */+CARDANO_EXPORT+void cardano_bigint_assign(+  const cardano_bigint_t* destination,+  cardano_bigint_t*       source);++/**+ * \brief Decrements the reference count of a bigint object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_bigint_t object+ * by decreasing its reference count. When the reference count reaches zero, the bigint is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] bigint A pointer to the pointer of the bigint object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = cardano_bigint_new();+ *+ * // Perform operations with the bigint...+ *+ * cardano_bigint_unref(&bigint);+ * // At this point, bigint is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_bigint_unref, the pointer to the \ref cardano_bigint_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_bigint_unref(cardano_bigint_t** bigint);++/**+ * \brief Increases the reference count of the cardano_bigint_t object.+ *+ * This function is used to manually increment the reference count of a bigint+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_bigint_unref.+ *+ * \param bigint A pointer to the bigint object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming bigint is a previously created bigint object+ *+ * cardano_bigint_ref(bigint);+ *+ * // Now bigint can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_bigint_ref there is a corresponding+ * call to \ref cardano_bigint_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_bigint_ref(cardano_bigint_t* bigint);++/**+ * \brief Retrieves the current reference count of the cardano_bigint_t object.+ *+ * This function returns the number of active references to a bigint object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_bigint_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param bigint A pointer to the bigint object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified bigint object. If the object+ * is properly managed (i.e., every \ref cardano_bigint_ref call is matched with a+ * \ref cardano_bigint_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming bigint is a previously created bigint object+ *+ * size_t ref_count = cardano_bigint_refcount(bigint);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_bigint_refcount(const cardano_bigint_t* bigint);++/**+ * \brief Sets the last error message for a given bigint object.+ *+ * Records an error message in the bigint's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] bigint A pointer to the \ref cardano_bigint_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the bigint's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized+ * cardano_bigint_set_last_error(bigint, "Error message");+ * // Later, retrieve the error+ * const char* error = cardano_bigint_get_last_error(bigint);+ * printf("Error: %s\n", error);+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_EXPORT void cardano_bigint_set_last_error(cardano_bigint_t* bigint, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific bigint.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_bigint_set_last_error for the given+ * bigint. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] bigint A pointer to the \ref cardano_bigint_t instance whose last error+ *                   message is to be retrieved. If the bigint is NULL, the function+ *                   returns a generic error message indicating the null bigint.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified bigint. If the bigint is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_bigint_set_last_error for the same bigint, or until+ *       the bigint is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * cardano_bigint_t* bigint = ...; // Assume this is initialized+ * const char* error = cardano_bigint_get_last_error(bigint);+ * printf("Error: %s\n", error);+ * // Clean up+ * cardano_bigint_unref(&bigint);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_bigint_get_last_error(const cardano_bigint_t* bigint);++/**+ * \brief Creates an independent deep copy of a \ref cardano_bigint_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_bigint_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_bigint_deep_clone(const cardano_bigint_t* source, cardano_bigint_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_BIGINT_H
+ vendor/include/cardano/common/byte_order.h view
@@ -0,0 +1,59 @@+/**+ * \file byte_order.h+ *+ * \author luisd.bianchi+ * \date   Jun 07, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_BYTE_ORDER_H+#define BIGLUP_LABS_INCLUDE_CARDANO_BYTE_ORDER_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Enumerates the possible byte order types for endianness interpretation.+ *+ * This enumeration is used to specify the byte order of data being processed,+ * particularly when bytes need to be interpreted as numeric values. It supports+ * specifying little-endian and big-endian byte orders.+ */+typedef enum+{+  /**+   * \brief Little-endian byte order. In this byte_order, the least significant byte (LSB)+   * is placed at the smallest address, and the most significant byte (MSB) is placed+   * at the largest address. This is the standard byte order used in x86 processors.+   */+  CARDANO_BYTE_ORDER_LITTLE_ENDIAN = 0,++  /**+   * \brief Big-endian byte order. In this byte_order, the most significant byte (MSB) is+   * placed at the smallest address, and the least significant byte (LSB) is placed+   * at the largest address. This is commonly used in network protocols (network byte order).+   */+  CARDANO_BYTE_ORDER_BIG_ENDIAN = 1+} cardano_byte_order_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_BYTE_ORDER_H
+ vendor/include/cardano/common/credential.h view
@@ -0,0 +1,788 @@+/**+ * \file credential.h+ *+ * \author angel.castillo+ * \date   Apr 12, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CREDENTIAL_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CREDENTIAL_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential_type.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a credential used in the Cardano blockchain, which can be either a key hash or a script hash.+ */+typedef struct cardano_credential_t cardano_credential_t;++/**+ * \brief Creates and initializes a new instance of a credential.+ *+ * This function allocates and initializes a new instance of \ref cardano_credential_t,+ * using the provided hash and credential type. It returns an error code to indicate success+ * or failure of the operation.+ *+ * \param[in] hash A pointer to \ref cardano_blake2b_hash_t representing the hash associated+ *             with this credential. The hash must be properly initialized before being+ *             passed to this function.+ * \param[in] type The type of credential, as defined in \ref cardano_credential_type_t,+ *             either a key hash or a script hash.+ * \param[out] credential On successful initialization, this will point to a newly created+ *             \ref cardano_credential_t object. This object represents a "strong reference"+ *             to the credential, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the credential is no longer needed, the caller must release it+ *             by calling \ref cardano_credential_unref.+ *+ * \return \ref CARDANO_SUCCESS if the credential was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_blake2b_hash_t* hash = { ... };  // Assume hash is initialized here+ * cardano_credential_t* credential = NULL;+ *+ * // Attempt to create a new credential+ * cardano_error_t result = cardano_credential_new(hash, CARDANO_CREDENTIAL_TYPE_KEY_HASH, &credential);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the credential+ *+ *   // Once done, ensure to clean up and release the credential+ *   cardano_credential_unref(&credential);+ * }+ *+ * cardano_blake2b_hash_unref(&hash);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_credential_new(+  const cardano_blake2b_hash_t* hash,+  cardano_credential_type_t     type,+  cardano_credential_t**        credential);++/**+ * \brief Creates a credential from a hexadecimal hash string.+ *+ * This function constructs a \ref cardano_credential_t object by interpreting the provided+ * hexadecimal string as a hash value and associating it with a specified credential type. It+ * returns an error code indicating the success or failure of the operation.+ *+ * \param[in] hex A pointer to a character array containing the hexadecimal representation of the hash.+ * \param[in] hex_size The size of the hexadecimal string in bytes.+ * \param[in] type The type of credential, as defined in \ref cardano_credential_type_t,+ *                 which determines how the hash is to be treated (e.g., as a key hash or a script hash).+ * \param[out] credential On successful initialization, this will point to a newly created+ *                 \ref cardano_credential_t object. This object represents a "strong reference"+ *                 to the credential, meaning that it is fully initialized and ready for use.+ *                 The caller is responsible for managing the lifecycle of this object,+ *                 specifically, once the credential is no longer needed, the caller must release it+ *                 by calling \ref cardano_credential_unref.+ *+ * \return \ref CARDANO_SUCCESS if the credential was successfully created, or an appropriate error code+ *         indicating the reason for failure.+ *+ * \note The function assumes that the hexadecimal string is valid and correctly formatted.+ *       Malformed input may lead to incorrect or undefined behavior.+ *+ * Usage Example:+ * \code{.c}+ * const char* hash_hex = "abcdef1234567890abcdef1234567890abcdef12....";+ * size_t hex_size = strlen(hash_hex);+ * cardano_credential_t* credential = NULL;+ *+ * // Attempt to create a new credential from a hexadecimal hash+ * cardano_error_t result = cardano_credential_from_hash_hex(hash_hex, hex_size, CARDANO_CREDENTIAL_TYPE_KEY_HASH, &credential);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the credential+ *+ *   // Once done, ensure to clean up and release the credential+ *   cardano_credential_unref(&credential);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_credential_from_hash_hex(+  const char*               hex,+  size_t                    hex_size,+  cardano_credential_type_t type,+  cardano_credential_t**    credential);++/**+ * \brief Creates a credential from a byte array representing a hash.+ *+ * This function constructs a \ref cardano_credential_t object by using the provided+ * byte array as a hash value and associating it with a specified credential type. It+ * returns an error code indicating the success or failure of the operation.+ *+ * \param[in] data A pointer to the byte array containing the hash data.+ * \param[in] data_size The size of the byte array in bytes.+ * \param[in] type The type of credential, as defined in \ref cardano_credential_type_t,+ *                 which determines how the hash is to be treated (e.g., as a key hash or a script hash).+ * \param[out] credential On successful initialization, this will point to a newly created+ *                 \ref cardano_credential_t object. This object represents a "strong reference"+ *                 to the credential, meaning that it is fully initialized and ready for use.+ *                 The caller is responsible for managing the lifecycle of this object,+ *                 specifically, once the credential is no longer needed, the caller must release it+ *                 by calling \ref cardano_credential_unref.+ *+ * \return \ref CARDANO_SUCCESS if the credential was successfully created, or an appropriate error code+ *         indicating the reason for failure.+ *+ * Usage Example:+ * \code{.c}+ * const byte_t hash_data[] = { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef ... };+ * size_t data_size = sizeof(hash_data);+ * cardano_credential_t* credential = NULL;+ *+ * // Attempt to create a new credential from byte array hash+ * cardano_error_t result = cardano_credential_from_hash_bytes(hash_data, data_size, CARDANO_CREDENTIAL_TYPE_KEY_HASH, &credential);+ *+ * if (result == CARDANO_SUCCESS && credential)+ * {+ *   // Use the credential+ *+ *   // Once done, ensure to clean up and release the credential+ *   cardano_credential_unref(&credential);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_credential_from_hash_bytes(+  const byte_t*             data,+  size_t                    data_size,+  cardano_credential_type_t type,+  cardano_credential_t**    credential);++/**+ * \brief Creates a credential from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_credential_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a credential.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded credential data.+ * \param[out] credential A pointer to a pointer of \ref cardano_credential_t that will be set to the address+ *                        of the newly created credential object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the credential was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_credential_t object by calling+ *       \ref cardano_credential_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_credential_t* credential = NULL;+ *+ * cardano_error_t result = cardano_credential_from_cbor(reader, &credential);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the credential+ *+ *   // Once done, ensure to clean up and release the credential+ *   cardano_credential_unref(&credential);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode credential: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_credential_from_cbor(cardano_cbor_reader_t* reader, cardano_credential_t** credential);++/**+ * \brief Serializes a credential into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_credential_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] credential A constant pointer to the \ref cardano_credential_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p credential or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_credential_to_cbor(credential, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_credential_to_cbor(+  const cardano_credential_t* credential,+  cardano_cbor_writer_t*      writer);++/**+ * \brief Serializes a credential to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ *+ * \param[in]  credential  Pointer to a valid \ref cardano_credential_t.+ * \param[in]  writer      Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ *         CARDANO_ERROR_POINTER_IS_NULL  If \p credential or \p writer is NULL.+ *         CARDANO_ERROR_ENCODING         If the credential is malformed (e.g., missing hash).+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_credential_to_cip116_json(+  const cardano_credential_t* credential,+  cardano_json_writer_t*      writer);++/**+ * \brief Retrieves the hash associated with a credential.+ *+ * This function provides access to the hash part of a \ref cardano_credential_t object.+ * It returns a new reference to a \ref cardano_blake2b_hash_t object representing the hash.+ * This allows the hash to be used independently of the original credential object. The+ * reference count of the hash object is increased by one, making it the caller's responsibility+ * to release it by calling \ref cardano_blake2b_hash_unref when it is no longer needed.+ *+ * \param credential A constant pointer to the \ref cardano_credential_t object from which+ *                   the hash is to be retrieved.+ *+ * \return A pointer to a new \ref cardano_blake2b_hash_t object containing the hash.+ *         If the input credential is NULL, returns NULL. The caller is responsible for+ *         managing the lifecycle of this object, including releasing it with+ *         \ref cardano_blake2b_hash_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* original_credential = cardano_credential_new(...);+ * cardano_blake2b_hash_t* hash_credential = cardano_credential_get_hash(original_credential);+ *+ * if (hash_credential)+ * {+ *   // Use the hash credential+ *+ *   // Once done, ensure to clean up and release the hash credential+ *   cardano_blake2b_hash_unref(&hash_credential);+ * }+ * // Release the original credential after use+ * cardano_credential_unref(&original_credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_credential_get_hash(const cardano_credential_t* credential);++/**+ * \brief Retrieves the size of the hash bytes stored in the credential.+ *+ * This function computes the size of the hash bytes stored within a \ref cardano_credential_t object.+ * It is particularly useful for determining the buffer size needed to store the hash bytes when+ * retrieving them via \ref cardano_credential_get_hash_bytes.+ *+ * \param[in] credential A constant pointer to the \ref cardano_credential_t object from which+ *                       the size of the hash bytes is to be retrieved.+ *+ * \return The size of the hash bytes. If the credential is NULL the function returns zero.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = cardano_credential_new(...);+ * size_t hash_size = cardano_credential_get_hash_bytes_size(credential);+ *+ * if (hash_size > 0)+ * {+ *   byte_t* hash_bytes = malloc(hash_size);+ *   if (hash_bytes)+ *   {+ *     // Proceed to get the hash bytes+ *   }+ * }+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_credential_get_hash_bytes_size(const cardano_credential_t* credential);++/**+ * \brief Retrieves the byte array representation of the hash from a credential.+ *+ * This function accesses the byte representation of the hash associated with a given+ * \ref cardano_credential_t object. It provides a direct pointer to the internal byte array+ * representing the hash, which should not be modified or freed by the caller.+ *+ * \param credential A constant pointer to the \ref cardano_credential_t object from which+ *                   the hash bytes are to be retrieved.+ *+ * \return A pointer to a constant byte array containing the hash data. If the input credential+ *         is NULL, returns NULL. The data remains valid as long as the credential object is not+ *         freed or modified.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = cardano_credential_new(...);+ * const byte_t* hash_bytes = cardano_credential_get_hash_bytes(credential);+ *+ * if (hash_bytes)+ * {+ *   // Use the hash bytes for operations like comparison or display+ * }+ *+ * // Clean up the credential object once done+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_credential_get_hash_bytes(const cardano_credential_t* credential);++/**+ * \brief Retrieves the size needed for the hexadecimal string representation of the credential's hash.+ *+ * This function calculates the size required to store the hexadecimal string representation of the hash+ * associated with a \ref cardano_credential_t object. This size includes the space needed for the null-terminator.+ *+ * \param[in] credential A constant pointer to the \ref cardano_credential_t object whose hash size is to be determined.+ *+ * \return The size in bytes required to store the hexadecimal representation of the hash, including the null terminator.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = cardano_credential_new(...);+ * size_t hex_size = cardano_credential_get_hash_hex_size(credential);+ * char* hex_string = malloc(hex_size);+ *+ * if (hex_string)+ * {+ *   // Now use hex_string to get the hash or do other operations+ *   free(hex_string);+ * }+ *+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_credential_get_hash_hex_size(const cardano_credential_t* credential);++/**+ * \brief Retrieves the hexadecimal string representation of the hash from a credential.+ *+ * This function provides access to the hexadecimal (hex) string representation of the hash+ * associated with a given \ref cardano_credential_t object. It returns a direct pointer to the+ * internal hex string which should not be modified or freed by the caller.+ *+ * \param credential A constant pointer to the \ref cardano_credential_t object from which+ *                   the hex string of the hash is to be retrieved. The object must not be NULL.+ *+ * \return A pointer to a constant character array containing the hex representation of the hash.+ *         If the input credential is NULL, returns NULL. The data remains valid as long as the+ *         credential object is not freed or modified.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = cardano_credential_new(...);+ * const char* hash_hex = cardano_credential_get_hash_hex(credential);+ *+ * if (hash_hex)+ * {+ *   // Use the hash hex for operations like logging, display, or comparison+ * }+ *+ * // Clean up the credential object once done+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_credential_get_hash_hex(const cardano_credential_t* credential);++/**+ * \brief Retrieves the type of the credential.+ *+ * This function retrieves the type of a given \ref cardano_credential_t object and stores it in the provided+ * output parameter. The credential type is defined in the \ref cardano_credential_type_t enumeration, which+ * specifies whether the credential is a key hash or a script hash.+ *+ * \param[in] credential A constant pointer to the \ref cardano_credential_t object from which+ *                       the type is to be retrieved. The object must not be NULL.+ * \param[out] type Pointer to a variable where the credential type will be stored. This variable will+ *                  be set to the value from the \ref cardano_credential_type_t enumeration.+ *+ * \return CARDANO_SUCCESS if the type was successfully retrieved, or an appropriate error code if the+ *         input is NULL or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = cardano_credential_new(...);+ * cardano_credential_type_t type;+ * cardano_error_t result = cardano_credential_get_type(credential, &type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   if (type == CARDANO_CREDENTIAL_TYPE_KEY_HASH)+ *   {+ *     // Handle key hash type credential+ *   }+ *   else if (type == CARDANO_CREDENTIAL_TYPE_SCRIPT_HASH)+ *   {+ *     // Handle script hash type credential+ *   }+ * }+ *+ * // Clean up the credential object once done+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_credential_get_type(const cardano_credential_t* credential, cardano_credential_type_t* type);++/**+ * \brief Sets the type of the credential.+ *+ * This function assigns a new type to an existing \ref cardano_credential_t object. The type is specified+ * by the \ref cardano_credential_type_t enumeration, which indicates whether the credential is derived from+ * a public key hash or a script hash.+ *+ * \param[in,out] credential A pointer to the \ref cardano_credential_t object whose type is to be set.+ * \param[in] type The new type of the credential, as defined in the \ref cardano_credential_type_t enumeration.+ *+ * \return Returns \ref CARDANO_SUCCESS if the type was successfully set. Returns \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p credential pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = cardano_credential_new(...);+ * cardano_error_t result = cardano_credential_set_type(credential, CARDANO_CREDENTIAL_TYPE_SCRIPT_HASH);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Credential type updated successfully+ * }+ *+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_credential_set_type(cardano_credential_t* credential, cardano_credential_type_t type);++/**+ * \brief Sets the hash for a credential.+ *+ * This function assigns a new hash to an existing \ref cardano_credential_t object. The hash+ * represents the identifying data for the credential.The function copies the provided hash into+ * the credential, so the original hash object may be modified or freed after this operation without+ * affecting the credential's hash.+ *+ * \param[in,out] credential A pointer to the \ref cardano_credential_t object whose hash is to be set.+ *                           This object must have been previously created and not yet freed.+ * \param[in] hash A pointer to a \ref cardano_blake2b_hash_t object containing the new hash to be set.+ *                 This parameter must not be NULL.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the hash was successfully set. If the \p credential or \p hash is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = ...;+ * cardano_blake2b_hash_t* new_hash = cardano_blake2b_compute_hash(...);+ *+ * cardano_error_t result = cardano_credential_set_hash(credential, new_hash);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *     // The hash was successfully set+ * }+ *+ * // Clean up+ * cardano_credential_unref(&credential);+ * cardano_blake2b_hash_unref(&new_hash);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_credential_set_hash(cardano_credential_t* credential, const cardano_blake2b_hash_t* hash);++/**+ * \brief Compares two credential objects for equality.+ *+ * This function compares two credential objects to determine if they are equal.+ *+ * \param[in] lhs Pointer to the first credential object.+ * \param[in] rhs Pointer to the second credential object.+ *+ * \return \c true if the credential objects are equal, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential1 = NULL;+ * cardano_credential_t* credential2 = NULL;+ *+ * // Assume credential1 and credential2 are initialized properly+ *+ * bool are_equal = cardano_credential_equals(credential1, credential2);+ *+ * if (are_equal)+ * {+ *   printf("The credential objects are equal.\n");+ * }+ * else+ * {+ *   printf("The credential objects are not equal.\n");+ * }+ *+ * // Clean up+ * cardano_credential_unref(&credential1);+ * cardano_credential_unref(&credential2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_credential_equals(+  const cardano_credential_t* lhs,+  const cardano_credential_t* rhs);++/**+ * \brief Compares two credential objects.+ *+ * This function compares two credential objects and returns an integer indicating+ * their relative order.+ *+ * \param[in] lhs Pointer to the first credential object.+ * \param[in] rhs Pointer to the second credential object.+ *+ * \return A negative value if lhs is less than rhs, zero if they are equal, and a positive value if lhs is greater than rhs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential1 = NULL;+ * cardano_credential_t* credential2 = NULL;+ *+ * // Assume credential1 and credential2 are initialized properly+ *+ * int32_t comparison = cardano_credential_compare(credential1, credential2);+ * if (comparison < 0)+ * {+ *   printf("credential1 is less than credential2.\n");+ * }+ * else if (comparison == 0)+ * {+ *   printf("credential1 is equal to credential2.\n");+ * }+ * else+ * {+ *   printf("credential1 is greater than credential2.\n");+ * }+ *+ * // Clean up+ * cardano_credential_unref(&credential1);+ * cardano_credential_unref(&credential2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT int32_t cardano_credential_compare(+  const cardano_credential_t* lhs,+  const cardano_credential_t* rhs);++/**+ * \brief Decrements the reference count of a credential object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_credential_t object+ * by decreasing its reference count. When the reference count reaches zero, the credential is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] credential A pointer to the pointer of the credential object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_credential_t* credential = cardano_credential_new();+ *+ * // Perform operations with the credential...+ *+ * cardano_credential_unref(&credential);+ * // At this point, credential is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_credential_unref, the pointer to the \ref cardano_credential_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_credential_unref(cardano_credential_t** credential);++/**+ * \brief Increases the reference count of the cardano_credential_t object.+ *+ * This function is used to manually increment the reference count of a credential+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_credential_unref.+ *+ * \param credential A pointer to the credential object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming credential is a previously created credential object+ *+ * cardano_credential_ref(credential);+ *+ * // Now credential can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_credential_ref there is a corresponding+ * call to \ref cardano_credential_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_credential_ref(cardano_credential_t* credential);++/**+ * \brief Retrieves the current reference count of the cardano_credential_t object.+ *+ * This function returns the number of active references to a credential object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_credential_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param credential A pointer to the credential object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified credential object. If the object+ * is properly managed (i.e., every \ref cardano_credential_ref call is matched with a+ * \ref cardano_credential_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming credential is a previously created credential object+ *+ * size_t ref_count = cardano_credential_refcount(credential);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_credential_refcount(const cardano_credential_t* credential);++/**+ * \brief Sets the last error message for a given credential object.+ *+ * Records an error message in the credential's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] credential A pointer to the \ref cardano_credential_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the credential's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_credential_set_last_error(cardano_credential_t* credential, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific credential.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_credential_set_last_error for the given+ * credential. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] credential A pointer to the \ref cardano_credential_t instance whose last error+ *                   message is to be retrieved. If the credential is NULL, the function+ *                   returns a generic error message indicating the null credential.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified credential. If the credential is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_credential_set_last_error for the same credential, or until+ *       the credential is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_credential_get_last_error(const cardano_credential_t* credential);++/**+ * \brief Creates an independent deep copy of a \ref cardano_credential_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_credential_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_credential_deep_clone(const cardano_credential_t* source, cardano_credential_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CREDENTIAL_H
+ vendor/include/cardano/common/credential_type.h view
@@ -0,0 +1,49 @@+/**+ * \file credential_type.h+ *+ * \author angel.castillo+ * \date   Apr 12, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_CREDENTIAL_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_CREDENTIAL_TYPE_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Enumerates the types of credentials.+ */+typedef enum+{+  /** Credential is a hash of a public key.+   */+  CARDANO_CREDENTIAL_TYPE_KEY_HASH = 0,++  /** Credential is a hash of a script.+   */+  CARDANO_CREDENTIAL_TYPE_SCRIPT_HASH = 1+} cardano_credential_type_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_CREDENTIAL_TYPE_H
+ vendor/include/cardano/common/datum.h view
@@ -0,0 +1,801 @@+/**+ * \file datum.h+ *+ * \author luisd.bianchi+ * \date   May 15, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_DATUM_H+#define BIGLUP_LABS_INCLUDE_CARDANO_DATUM_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/datum_type.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/plutus_data/plutus_data.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a piece of data attached to a UTxO that a Plutus script can read when the+ *        UTxO is being spent. Essentially, the Datum acts as a state for that UTxO, allowing+ *        Plutus scripts to perform more complex logic based on this stored state.+ */+typedef struct cardano_datum_t cardano_datum_t;++/**+ * \brief Creates and initializes a new instance of a datum.+ *+ * This function allocates and initializes a new instance of \ref cardano_datum_t,+ * using the provided hash. It returns an error code to indicate success+ * or failure of the operation.+ *+ * \param[in] hash A pointer to \ref cardano_blake2b_hash_t representing the hash associated+ *             with this datum. The hash must be properly initialized before being+ *             passed to this function.+ * \param[out] datum On successful initialization, this will point to a newly created+ *             \ref cardano_datum_t object. This object represents a "strong reference"+ *             to the datum, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the datum is no longer needed, the caller must release it+ *             by calling \ref cardano_datum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the datum was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_blake2b_hash_t* hash = { ... };  // Assume hash is initialized here+ * cardano_datum_t* datum = NULL;+ *+ * // Attempt to create a new datum+ * cardano_error_t result = cardano_datum_new_data_hash(hash, &datum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the datum+ *+ *   // Once done, ensure to clean up and release the datum+ *   cardano_datum_unref(&datum);+ * }+ *+ * cardano_blake2b_hash_unref(&hash);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_datum_new_data_hash(+  const cardano_blake2b_hash_t* hash,+  cardano_datum_t**             datum);++/**+ * \brief Creates a datum from a hexadecimal hash string.+ *+ * This function constructs a \ref cardano_datum_t object by interpreting the provided+ * hexadecimal string as a hash value. It returns an error code indicating the success or failure of the operation.+ *+ * \param[in] hex A pointer to a character array containing the hexadecimal representation of the hash.+ * \param[in] hex_size The size of the hexadecimal string in bytes.+ * \param[out] datum On successful initialization, this will point to a newly created+ *                 \ref cardano_datum_t object. This object represents a "strong reference"+ *                 to the datum, meaning that it is fully initialized and ready for use.+ *                 The caller is responsible for managing the lifecycle of this object,+ *                 specifically, once the datum is no longer needed, the caller must release it+ *                 by calling \ref cardano_datum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the datum was successfully created, or an appropriate error code+ *         indicating the reason for failure.+ *+ * \note The function assumes that the hexadecimal string is valid and correctly formatted.+ *       Malformed input may lead to incorrect or undefined behavior.+ *+ * Usage Example:+ * \code{.c}+ * const char* hash_hex = "abcdef1234567890abcdef1234567890abcdef12....";+ * size_t hex_size = strlen(hash_hex);+ * cardano_datum_t* datum = NULL;+ *+ * // Attempt to create a new datum from a hexadecimal hash+ * cardano_error_t result = cardano_datum_new_data_hash_hex(hash_hex, hex_size, &datum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the datum+ *+ *   // Once done, ensure to clean up and release the datum+ *   cardano_datum_unref(&datum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_datum_new_data_hash_hex(+  const char*       hex,+  size_t            hex_size,+  cardano_datum_t** datum);++/**+ * \brief Creates a datum from a byte array representing a hash.+ *+ * This function constructs a \ref cardano_datum_t object by using the provided+ * byte array as a hash value. It returns an error code indicating the success or failure of the operation.+ *+ * \param[in] data A pointer to the byte array containing the hash data.+ * \param[in] data_size The size of the byte array in bytes.+ * \param[out] datum On successful initialization, this will point to a newly created+ *                 \ref cardano_datum_t object. This object represents a "strong reference"+ *                 to the datum, meaning that it is fully initialized and ready for use.+ *                 The caller is responsible for managing the lifecycle of this object,+ *                 specifically, once the datum is no longer needed, the caller must release it+ *                 by calling \ref cardano_datum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the datum was successfully created, or an appropriate error code+ *         indicating the reason for failure.+ *+ * Usage Example:+ * \code{.c}+ * const byte_t hash_data[] = { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef ... };+ * size_t data_size = sizeof(hash_data);+ * cardano_datum_t* datum = NULL;+ *+ * // Attempt to create a new datum from byte array hash+ * cardano_error_t result = cardano_datum_new_data_hash_bytes(hash_data, data_size, &datum);+ *+ * if (result == CARDANO_SUCCESS && datum)+ * {+ *   // Use the datum+ *+ *   // Once done, ensure to clean up and release the datum+ *   cardano_datum_unref(&datum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_datum_new_data_hash_bytes(+  const byte_t*     data,+  size_t            data_size,+  cardano_datum_t** datum);++/**+ * \brief Creates a datum from inline data.+ *+ * This function constructs a \ref cardano_datum_t object using the provided+ * \ref cardano_plutus_data_t object. It returns an error code indicating the success or failure of the operation.+ *+ * \param[in] data A pointer to the \ref cardano_plutus_data_t object representing the inline data.+ * \param[out] datum On successful initialization, this will point to a newly created+ *                 \ref cardano_datum_t object. This object represents a "strong reference"+ *                 to the datum, meaning that it is fully initialized and ready for use.+ *                 The caller is responsible for managing the lifecycle of this object,+ *                 specifically, once the datum is no longer needed, the caller must release it+ *                 by calling \ref cardano_datum_unref.+ *+ * \return \ref CARDANO_SUCCESS if the datum was successfully created, or an appropriate error code+ *         indicating the reason for failure.+ *+ * Usage Example:+ * \code{.c}+ * cardano_plutus_data_t* data = ...;  // Assume data is initialized here+ * cardano_datum_t* datum = NULL;+ *+ * // Attempt to create a new datum from inline data+ * cardano_error_t result = cardano_datum_new_inline_data(data, &datum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the datum+ *+ *   // Once done, ensure to clean up and release the datum+ *   cardano_datum_unref(&datum);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_datum_new_inline_data(+  cardano_plutus_data_t* data,+  cardano_datum_t**      datum);++/**+ * \brief Creates a datum from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_datum_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a datum.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded datum data.+ * \param[out] datum A pointer to a pointer of \ref cardano_datum_t that will be set to the address+ *                        of the newly created datum object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the datum was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_datum_t object by calling+ *       \ref cardano_datum_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_datum_t* datum = NULL;+ *+ * cardano_error_t result = cardano_datum_from_cbor(reader, &datum);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the datum+ *+ *   // Once done, ensure to clean up and release the datum+ *   cardano_datum_unref(&datum);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode datum: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_datum_from_cbor(cardano_cbor_reader_t* reader, cardano_datum_t** datum);++/**+ * \brief Serializes a datum into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_datum_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] datum A constant pointer to the \ref cardano_datum_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p datum or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_datum_to_cbor(datum, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_datum_unref(&datum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_datum_to_cbor(+  const cardano_datum_t* datum,+  cardano_cbor_writer_t* writer);++/**+ * \brief Serializes a datum to CIP-116 JSON.+ *+ * This function serializes the datum object, which can be either inline+ * Plutus data or a datum hash, according to the schema.+ *+ * Schema (Inline):+ * { "tag": "datum", "value": { ...PlutusData... } }+ *+ * Schema (Hash):+ * { "tag": "datum_hash", "value": "<hex_hash>" }+ *+ * \param[in]  datum   Pointer to a valid \ref cardano_datum_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p datum or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_datum_to_cip116_json(+  const cardano_datum_t* datum,+  cardano_json_writer_t* writer);++/**+ * \brief Retrieves the inline data associated with a datum.+ *+ * This function provides access to the inline data part of a \ref cardano_datum_t object.+ * It returns a pointer to a \ref cardano_plutus_data_t object representing the inline data.+ * The caller is responsible for managing the lifecycle of this object, including releasing it with+ * \ref cardano_plutus_data_unref when it is no longer needed.+ *+ * \param datum A constant pointer to the \ref cardano_datum_t object from which+ *              the inline data is to be retrieved.+ *+ * \return A pointer to a \ref cardano_plutus_data_t object containing the inline data.+ *         If the input datum is NULL, returns NULL. The caller is responsible for+ *         managing the lifecycle of this object, including releasing it with+ *         \ref cardano_plutus_data_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum = ...;+ * cardano_plutus_data_t* data = cardano_datum_get_inline_data(datum);+ *+ * if (data)+ * {+ *   // Use the inline data+ *+ *   // Once done, ensure to clean up and release the inline data+ *   cardano_plutus_data_unref(&data);+ * }+ *+ * // Clean up the datum object once done+ * cardano_datum_unref(&datum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_plutus_data_t* cardano_datum_get_inline_data(cardano_datum_t* datum);++/**+ * \brief Retrieves the hash associated with a datum.+ *+ * This function provides access to the hash part of a \ref cardano_datum_t object.+ * It returns a new reference to a \ref cardano_blake2b_hash_t object representing the hash.+ * This allows the hash to be used independently of the original datum object. The+ * reference count of the hash object is increased by one, making it the caller's responsibility+ * to release it by calling \ref cardano_blake2b_hash_unref when it is no longer needed.+ *+ * For a datum of type \ref CARDANO_DATUM_TYPE_INLINE_DATA the hash is the datum hash of its plutus data: the+ * blake2b-256 hash of the CBOR encoding of the data, computed from the data on every call. Plutus data decoded+ * from CBOR is hashed over the bytes it was decoded from (until its CBOR cache is cleared), so the hash matches+ * the one the ledger computes.+ *+ * \param datum A constant pointer to the \ref cardano_datum_t object from which+ *                   the hash is to be retrieved.+ *+ * \return A pointer to a new \ref cardano_blake2b_hash_t object containing the hash.+ *         If the input datum is NULL or the hash cannot be computed or allocated, returns NULL.+ *         The caller is responsible for managing the lifecycle of this object,+ *         including releasing it with \ref cardano_blake2b_hash_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* original_datum = cardano_datum_new(...);+ * cardano_blake2b_hash_t* hash_datum = cardano_datum_get_data_hash(original_datum);+ *+ * if (hash_datum)+ * {+ *   // Use the hash datum+ *+ *   // Once done, ensure to clean up and release the hash datum+ *   cardano_blake2b_hash_unref(&hash_datum);+ * }+ * // Release the original datum after use+ * cardano_datum_unref(&original_datum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_datum_get_data_hash(const cardano_datum_t* datum);++/**+ * \brief Retrieves the size of the hash bytes stored in the datum.+ *+ * This function computes the size of the hash bytes stored within a \ref cardano_datum_t object.+ * It is particularly useful for determining the buffer size needed to store the hash bytes when+ * retrieving them via \ref cardano_datum_get_data_hash_bytes.+ *+ * \param[in] datum A constant pointer to the \ref cardano_datum_t object from which+ *                       the size of the hash bytes is to be retrieved.+ *+ * \return The size of the hash bytes. If the datum is NULL, the function returns zero.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum = cardano_datum_new(...);+ * size_t hash_size = cardano_datum_get_data_hash_bytes_size(datum);+ *+ * if (hash_size > 0)+ * {+ *   byte_t* hash_bytes = malloc(hash_size);+ *   if (hash_bytes)+ *   {+ *     // Proceed to get the hash bytes+ *   }+ * }+ * cardano_datum_unref(&datum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_datum_get_data_hash_bytes_size(const cardano_datum_t* datum);++/**+ * \brief Retrieves the byte array representation of the hash from a datum.+ *+ * This function accesses the byte representation of the hash associated with a given+ * \ref cardano_datum_t object. It provides a direct pointer to the internal byte array+ * representing the hash, which should not be modified or freed by the caller.+ *+ * For a datum of type \ref CARDANO_DATUM_TYPE_INLINE_DATA the hash is the datum hash of its plutus data, as+ * reported by \ref cardano_datum_get_data_hash. It is computed from the data on every call and stored in the+ * datum, despite the const parameter, so the returned bytes are only valid until the next call to+ * \ref cardano_datum_get_data_hash_bytes or \ref cardano_datum_get_data_hash_hex on the same datum. These two+ * functions must not be called concurrently on the same datum.+ *+ * \param datum A constant pointer to the \ref cardano_datum_t object from which+ *                   the hash bytes are to be retrieved.+ *+ * \return A pointer to a constant byte array containing the hash data. If the input datum+ *         is NULL, or the hash of an inline datum cannot be computed, returns NULL. For a datum created from a+ *         hash, the data remains valid as long as the datum is not freed or modified.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum = cardano_datum_new(...);+ * const byte_t* hash_bytes = cardano_datum_get_data_hash_bytes(datum);+ *+ * if (hash_bytes)+ * {+ *   // Use the hash bytes for operations like comparison or display+ * }+ *+ * // Clean up the datum object once done+ * cardano_datum_unref(&datum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_datum_get_data_hash_bytes(const cardano_datum_t* datum);++/**+ * \brief Retrieves the size needed for the hexadecimal string representation of the datum's hash.+ *+ * This function calculates the size required to store the hexadecimal string representation of the hash+ * associated with a \ref cardano_datum_t object. This size includes the space needed for the null-terminator.+ *+ * \param[in] datum A constant pointer to the \ref cardano_datum_t object whose hash size is to be determined.+ *+ * \return The size in bytes required to store the hexadecimal representation of the hash, including the null terminator.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum = cardano_datum_new(...);+ * size_t hex_size = cardano_datum_get_data_hash_hex_size(datum);+ * char* hex_string = malloc(hex_size);+ *+ * if (hex_string)+ * {+ *   // Now use hex_string to get the hash or do other operations+ *   free(hex_string);+ * }+ *+ * cardano_datum_unref(&datum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_datum_get_data_hash_hex_size(const cardano_datum_t* datum);++/**+ * \brief Retrieves the hexadecimal string representation of the hash from a datum.+ *+ * This function provides access to the hexadecimal (hex) string representation of the hash+ * associated with a given \ref cardano_datum_t object. It returns a direct pointer to the+ * internal hex string which should not be modified or freed by the caller.+ *+ * For a datum of type \ref CARDANO_DATUM_TYPE_INLINE_DATA the hash is the datum hash of its plutus data, as+ * reported by \ref cardano_datum_get_data_hash. It is computed from the data on every call and stored in the+ * datum, despite the const parameter, so the returned string is only valid until the next call to+ * \ref cardano_datum_get_data_hash_bytes or \ref cardano_datum_get_data_hash_hex on the same datum. These two+ * functions must not be called concurrently on the same datum.+ *+ * \param datum A constant pointer to the \ref cardano_datum_t object from which+ *                   the hex string of the hash is to be retrieved. The object must not be NULL.+ *+ * \return A pointer to a constant character array containing the hex representation of the hash.+ *         If the input datum is NULL, or the hash of an inline datum cannot be computed, returns NULL. For a datum+ *         created from a hash, the data remains valid as long as the datum is not freed or modified.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum = cardano_datum_new(...);+ * const char* hash_hex = cardano_datum_get_data_hash_hex(datum);+ *+ * if (hash_hex)+ * {+ *   // Use the hash hex for operations like logging, display, or comparison+ * }+ *+ * // Clean up the datum object once done+ * cardano_datum_unref(&datum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_datum_get_data_hash_hex(const cardano_datum_t* datum);++/**+ * \brief Retrieves the type of the datum.+ *+ * This function retrieves the type of a given \ref cardano_datum_t object and stores it in the provided+ * output parameter. The datum type is defined in the \ref cardano_datum_type_t enumeration.+ *+ * \param[in] datum A constant pointer to the \ref cardano_datum_t object from which+ *                       the type is to be retrieved. The object must not be NULL.+ * \param[out] type Pointer to a variable where the datum type will be stored. This variable will+ *                  be set to the value from the \ref cardano_datum_type_t enumeration.+ *+ * \return CARDANO_SUCCESS if the type was successfully retrieved, or an appropriate error code if the+ *         input is NULL or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum = cardano_datum_new(...);+ * cardano_datum_type_t type;+ * cardano_error_t result = cardano_datum_get_type(datum, &type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the type+ * }+ *+ * // Clean up the datum object once done+ * cardano_datum_unref(&datum);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_datum_get_type(const cardano_datum_t* datum, cardano_datum_type_t* type);++/**+ * \brief Sets the hash for a datum.+ *+ * This function assigns a new hash to an existing \ref cardano_datum_t object. The hash+ * represents the identifying data for the datum. The function copies the provided hash into+ * the datum, so the original hash object may be modified or freed after this operation without+ * affecting the datum's hash.+ *+ * An inline datum always reports the hash of its data, so a hash set on it is not reported by the hash getters.+ *+ * \param[in,out] datum A pointer to the \ref cardano_datum_t object whose hash is to be set.+ *                           This object must have been previously created and not yet freed.+ * \param[in] hash A pointer to a \ref cardano_blake2b_hash_t object containing the new hash to be set.+ *                 This parameter must not be NULL.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the hash was successfully set. If the \p datum or \p hash is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum = ...;+ * cardano_blake2b_hash_t* new_hash = cardano_blake2b_compute_hash(...);+ *+ * cardano_error_t result = cardano_datum_set_data_hash(datum, new_hash);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *     // The hash was successfully set+ * }+ *+ * // Clean up+ * cardano_datum_unref(&datum);+ * cardano_blake2b_hash_unref(&new_hash);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_datum_set_data_hash(cardano_datum_t* datum, const cardano_blake2b_hash_t* hash);++/**+ * \brief Compares two datum objects for equality.+ *+ * This function compares two datum objects to determine if they are equal.+ *+ * \param[in] lhs Pointer to the first datum object.+ * \param[in] rhs Pointer to the second datum object.+ *+ * \return \c true if the datum objects are equal, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum1 = NULL;+ * cardano_datum_t* datum2 = NULL;+ *+ * // Assume datum1 and datum2 are initialized properly+ *+ * bool are_equal = cardano_datum_equals(datum1, datum2);+ *+ * if (are_equal)+ * {+ *   printf("The datum objects are equal.\n");+ * }+ * else+ * {+ *   printf("The datum objects are not equal.\n");+ * }+ *+ * // Clean up+ * cardano_datum_unref(&datum1);+ * cardano_datum_unref(&datum2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_datum_equals(const cardano_datum_t* lhs, const cardano_datum_t* rhs);++/**+ * \brief Decrements the reference count of a datum object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_datum_t object+ * by decreasing its reference count. When the reference count reaches zero, the datum is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] datum A pointer to the pointer of the datum object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_datum_t* datum = cardano_datum_new();+ *+ * // Perform operations with the datum...+ *+ * cardano_datum_unref(&datum);+ * // At this point, datum is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_datum_unref, the pointer to the \ref cardano_datum_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_datum_unref(cardano_datum_t** datum);++/**+ * \brief Increases the reference count of the cardano_datum_t object.+ *+ * This function is used to manually increment the reference count of a datum+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_datum_unref.+ *+ * \param datum A pointer to the datum object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming datum is a previously created datum object+ *+ * cardano_datum_ref(datum);+ *+ * // Now datum can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_datum_ref there is a corresponding+ * call to \ref cardano_datum_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_datum_ref(cardano_datum_t* datum);++/**+ * \brief Retrieves the current reference count of the cardano_datum_t object.+ *+ * This function returns the number of active references to a datum object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_datum_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param datum A pointer to the datum object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified datum object. If the object+ * is properly managed (i.e., every \ref cardano_datum_ref call is matched with a+ * \ref cardano_datum_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming datum is a previously created datum object+ *+ * size_t ref_count = cardano_datum_refcount(datum);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_datum_refcount(const cardano_datum_t* datum);++/**+ * \brief Sets the last error message for a given datum object.+ *+ * Records an error message in the datum's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] datum A pointer to the \ref cardano_datum_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the datum's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_datum_set_last_error(cardano_datum_t* datum, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific datum.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_datum_set_last_error for the given+ * datum. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] datum A pointer to the \ref cardano_datum_t instance whose last error+ *                   message is to be retrieved. If the datum is NULL, the function+ *                   returns a generic error message indicating the null datum.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified datum. If the datum is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_datum_set_last_error for the same datum, or until+ *       the datum is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_datum_get_last_error(const cardano_datum_t* datum);++/**+ * \brief Creates an independent deep copy of a \ref cardano_datum_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_datum_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_datum_deep_clone(const cardano_datum_t* source, cardano_datum_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_DATUM_H
+ vendor/include/cardano/common/datum_type.h view
@@ -0,0 +1,57 @@+/**+ * \file datum_type.h+ *+ * \author luisd.bianchi+ * \date   May 15, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_DATUM_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_DATUM_TYPE_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents different ways of associating a Datum with a UTxO in a transaction.+ */+typedef enum+{+  /**+   * \brief Instead of including the full Datum directly within the transaction, it's possible to+   * include just a hash of the Datum. This is the DatumHash. By referencing the Datum+   * by its hash, the transaction can be more compact, especially if the Datum itself is large.+   * However, when using a DatumHash, the actual Datum value it represents must be provided+   * in the transaction witness set to ensure that users and validators can verify and use it.+   */+  CARDANO_DATUM_TYPE_DATA_HASH = 0,++  /**+   * \brief This represents the actual Datum value being included directly+   * within the transaction output. So, the Datum is "inlined" in the transaction+   * data itself.+   */+  CARDANO_DATUM_TYPE_INLINE_DATA = 1+} cardano_datum_type_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_DATUM_TYPE_H
+ vendor/include/cardano/common/drep.h view
@@ -0,0 +1,650 @@+/**+ * \file drep.h+ *+ * \author angel.castillo+ * \date   Jun 18, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_DREP_H+#define BIGLUP_LABS_INCLUDE_CARDANO_DREP_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/common/drep_type.h>+#include <cardano/error.h>+#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief In Voltaire, existing stake credentials will be able to delegate their stake to DReps+ * for voting purposes, in addition to the current delegation to stake pools for block production.+ *+ * Just as the number of blocks that a pool mint depends on the total stake, the amount of decision-making+ * power will depend on the number of coins delegated to a DRep.+ *+ * Registered DReps are identified by a credential that can be either:+ *+ * - A verification key (Ed25519)+ * - A native or Plutus script+ */+typedef struct cardano_drep_t cardano_drep_t;++/**+ * \brief Creates and initializes a new instance of a drep.+ *+ * This function allocates and initializes a new instance of \ref cardano_drep_t,+ * using the provided type and credential. It returns an error code to indicate the+ * success or failure of the operation.+ *+ * \param[in] type The type of the drep, represented by \ref cardano_drep_type_t.+ * \param[in] credential A pointer to \ref cardano_credential_t representing the credential+ *                       associated with this drep. The credential must be properly initialized+ *                       before being passed to this function. Must be NULL if \p type is+ *                       \ref CARDANO_DREP_TYPE_ABSTAIN or \ref CARDANO_DREP_TYPE_NO_CONFIDENCE.+ * \param[out] drep On successful initialization, this will point to a newly created+ *                  \ref cardano_drep_t object. This object represents a "strong reference"+ *                  to the drep, meaning that it is fully initialized and ready for use.+ *                  The caller is responsible for managing the lifecycle of this object.+ *                  Specifically, once the drep is no longer needed, the caller must release it+ *                  by calling \ref cardano_drep_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the drep was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_drep_type_t type = ...;  // Assume type is initialized here+ * cardano_credential_t* credential = ...;  // Assume credential is initialized here+ * cardano_drep_t* drep = NULL;+ *+ * // Attempt to create a new drep+ * cardano_error_t result = cardano_drep_new(type, credential, &drep);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the drep+ *+ *   // Once done, ensure to clean up and release the drep+ *   cardano_drep_unref(&drep);+ * }+ *+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_drep_new(+  cardano_drep_type_t   type,+  cardano_credential_t* credential,+  cardano_drep_t**      drep);++/**+ * \brief Converts a Bech32-encoded string representation of a DRep (Delegated Representative)+ *        into a `cardano_drep_t` object.+ *+ * The input string can follow one of two formats:+ *+ * 1. CIP-105 Format (DEPRECATED):+ *    - This format represents the key hash directly as a Bech32-encoded string.+ *+ * 2. CIP-129 Format:+ *    - This format introduces a header byte to encode additional metadata about the governance key type and credential type.+ *    - The binary structure is as follows:+ *+ *      Header Byte Structure:+ *      - The header byte consists of two parts:+ *        - Bits [7;4]: Key type (t t t t)+ *          - Defines the type of governance key being used.+ *          - Possible key types:+ *            - 0000 (CC Hot): Constitutional Committee Hot Key+ *            - 0001 (CC Cold): Constitutional Committee Cold Key+ *            - 0010 (DRep): Delegated Representative Key+ *        - Bits [3;0]: Credential type (c c c c)+ *          - Refers to the type of credential associated with the governance key.+ *          - Reserved values ensure no conflicts with Cardano address network tags:+ *            - 0010 (Key Hash): Key hash credential+ *            - 0011 (Script Hash): Script hash credential+ *+ * \param[in]  bech32_string   Pointer to the Bech32-encoded string.+ * \param[in]  string_length   Length of the input string.+ * \param[out] drep            Pointer to the output cardano_drep_t object.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the drep was successfully created, \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED+ *         if memory for the decoding buffers or the drep could not be allocated, or an+ *         appropriate error code indicating the failure reason.+ *+ * \note The caller is responsible for freeing the memory associated with the returned+ *       cardano_drep_t object using `cardano_drep_unref`.+ *+ * \code{.c}+ * const char* drep_bech32 = "drep1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";+ * size_t drep_length = strlen(drep_bech32);+ * cardano_drep_t* drep = NULL;+ *+ * cardano_error_t result = cardano_drep_from_string(drep_bech32, drep_length, &drep);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("DRep object successfully created.\n");+ *   // Use the drep object...+ *   cardano_drep_unref(drep);+ * }+ * else+ * {+ *   printf("Failed to parse DRep string: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_drep_from_string(+  const char*      bech32_string,+  size_t           string_length,+  cardano_drep_t** drep);++/**+ * \brief Creates a drep from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_drep_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a drep.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded drep data.+ * \param[out] drep A pointer to a pointer of \ref cardano_drep_t that will be set to the address+ *                        of the newly created drep object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the drep was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_drep_t object by calling+ *       \ref cardano_drep_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_drep_t* drep = NULL;+ *+ * cardano_error_t result = cardano_drep_from_cbor(reader, &drep);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the drep+ *+ *   // Once done, ensure to clean up and release the drep+ *   cardano_drep_unref(&drep);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode drep: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_drep_from_cbor(cardano_cbor_reader_t* reader, cardano_drep_t** drep);++/**+ * \brief Serializes a drep into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_drep_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] drep A constant pointer to the \ref cardano_drep_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p drep or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_drep_t* drep = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_drep_to_cbor(drep, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_drep_unref(&drep);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_drep_to_cbor(+  const cardano_drep_t*  drep,+  cardano_cbor_writer_t* writer);++/**+ * \brief Serializes a DRep to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ *+ * Schema:+ * - Key Hash: { "tag": "pubkey_hash", "value": "<hex>" }+ * - Script Hash: { "tag": "script_hash", "value": "<hex>" }+ * - Always Abstain: { "tag": "always_abstain" }+ * - Always No Confidence: { "tag": "always_no_confidence" }+ *+ * \param[in]  drep    Pointer to a valid \ref cardano_drep_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p drep or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_drep_to_cip116_json(+  const cardano_drep_t*  drep,+  cardano_json_writer_t* writer);++/**+ * \brief Retrieves the size needed for the string representation (CIP-129) of a Cardano DRep.+ *+ * This function calculates the size of the buffer required to hold the string representation+ * of a \ref cardano_drep_t object, including the null terminator. This size is necessary+ * to ensure that the buffer allocated for converting the DRep to a string is sufficient.+ *+ * \param[in] drep A constant pointer to the \ref cardano_drep_t object for which the string+ *                 size is being calculated. The object must not be NULL.+ *+ * \return The size in bytes needed to store the string representation of the DRep, including+ *         the null terminator. If the input \p DRep is NULL, the behavior is undefined.+ *+ * Usage Example:+ * \code{.c}+ * cardano_drep_t* drep = cardano_drep_new(...);+ * size_t required_size = cardano_drep_get_string_size(drep);+ *+ * char* drep_str = (char*)malloc(required_size);+ *+ * if (drep_str)+ * {+ *   cardano_error_t result = cardano_drep_to_string(drep, drep_str, required_size);+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("DRep: %s\n", drep_str);+ *   }+ *   free(drep_str);+ * }+ *+ * // Clean up the drep object once done+ * cardano_drep_unref(&drep);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_drep_get_string_size(const cardano_drep_t* drep);++/**+ * \brief Converts a Cardano DRep into its string representation (CIP-129).+ *+ * This function serializes the given \ref cardano_drep_t object into a string format.+ * The string is written to a user-provided buffer, and the size of this buffer must be+ * adequate to hold the entire string, including the null terminator. The required size+ * can be determined by calling \ref cardano_drep_get_string_size.+ *+ * \param[in] drep A constant pointer to the \ref cardano_drep_t object that is to be converted to a string.+ *                 The object must not be NULL.+ * \param[out] data A pointer to the buffer where the string representation of the drep will be written.+ * \param[in] size The size of the buffer pointed to by \p data. This size should be at least as large as the value+ *                 returned by \ref cardano_drep_get_string_size to ensure successful serialization.+ *+ * \return Returns \ref CARDANO_SUCCESS if the conversion is successful. If the buffer is too small, returns+ *         \ref CARDANO_ERROR_INSUFFICIENT_BUFFER_SIZE. If the \p drep or \p data is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_drep_t* drep = cardano_drep_new(...);+ * size_t required_size = cardano_drep_get_string_size(drep);+ * char* drep_str = (char*)malloc(required_size);+ *+ * if (drep_str)+ * {+ *   cardano_error_t result = cardano_drep_to_string(drep, drep_str, required_size);+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("Address: %s\n", drep_str);+ *   }+ *+ *   free(drep_str);+ * }+ *+ * // Clean up the drep object once done+ * cardano_drep_unref(&drep);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_drep_to_string(+  const cardano_drep_t* drep,+  char*                 data,+  size_t                size);++/**+ * \brief Retrieves the credential associated with a drep.+ *+ * This function retrieves the credential associated with the given \ref cardano_drep_t object.+ * The retrieved credential is returned via the \p credential output parameter.+ *+ * \param[in] drep A pointer to the \ref cardano_drep_t object from which to retrieve the credential.+ * \param[out] credential A pointer to a pointer that will be set to the address of the retrieved+ *                        \ref cardano_credential_t object. The caller is responsible for managing+ *                        the lifecycle of this credential. Specifically, once the credential is no+ *                        longer needed, the caller must release it by calling \ref cardano_credential_unref.+ *                        Will be NULL if the \p drep is of type \ref CARDANO_DREP_TYPE_ABSTAIN or+ *                        \ref CARDANO_DREP_TYPE_NO_CONFIDENCE.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the credential was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_drep_t* drep = ...;  // Assume drep is initialized here+ * cardano_credential_t* credential = NULL;+ *+ * // Retrieve the credential+ * cardano_error_t result = cardano_drep_get_credential(drep, &credential);+ *+ * if (result == CARDANO_SUCCESS && credential != NULL)+ * {+ *   // Use the credential+ *+ *   // Once done, ensure to clean up and release the credential+ *   cardano_credential_unref(&credential);+ * }+ *+ * cardano_drep_unref(&drep);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_drep_get_credential(cardano_drep_t* drep, cardano_credential_t** credential);++/**+ * \brief Sets the credential associated with a drep.+ *+ * This function sets the credential for the given \ref cardano_drep_t object.+ *+ * \param[in,out] drep A pointer to the \ref cardano_drep_t object for which to set the credential.+ * \param[in] credential A pointer to the \ref cardano_credential_t object to be associated with the drep.+ *                       The \p credential must be properly initialized before being passed to this function.+ *                       For \ref CARDANO_DREP_TYPE_ABSTAIN and \ref CARDANO_DREP_TYPE_NO_CONFIDENCE, this parameter+ *                       must be NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the credential was successfully set, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_drep_t* drep = ...;  // Assume drep is initialized here+ * cardano_credential_t* credential = ...;  // Assume credential is initialized here+ *+ * // Set the credential+ * cardano_error_t result = cardano_drep_set_credential(drep, credential);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Credential was successfully set+ * }+ *+ * // Clean up+ * cardano_drep_unref(&drep);+ * cardano_credential_unref(&credential);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_drep_set_credential(cardano_drep_t* drep, cardano_credential_t* credential);++/**+ * \brief Retrieves the type of a drep.+ *+ * This function gets the type of the given \ref cardano_drep_t object.+ *+ * \param[in] drep A constant pointer to the \ref cardano_drep_t object.+ * \param[out] type A pointer to a \ref cardano_drep_type_t variable where the type will be stored.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the type was successfully retrieved, or an appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_drep_t* drep = ...;  // Assume drep is initialized here+ * cardano_drep_type_t type;+ *+ * // Get the drep type+ * cardano_error_t result = cardano_drep_get_type(drep, &type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The type was successfully retrieved+ * }+ *+ * // Clean up+ * cardano_drep_unref(&drep);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_drep_get_type(const cardano_drep_t* drep, cardano_drep_type_t* type);++/**+ * \brief Sets the type of a drep.+ *+ * This function sets the type of the given \ref cardano_drep_t object.+ *+ * \param[in,out] drep A pointer to the \ref cardano_drep_t object whose type is to be set.+ * \param[in] type The \ref cardano_drep_type_t value to set for the drep.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the type was successfully set, or an appropriate error code indicating the failure reason.+ *+ * \remark If the type is set to \ref CARDANO_DREP_TYPE_ABSTAIN or \ref CARDANO_DREP_TYPE_NO_CONFIDENCE,+ *         the credential must be NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_drep_t* drep = ...;  // Assume drep is initialized here+ * cardano_drep_type_t type = CARDANO_DREP_TYPE_KEY_HASH;+ *+ * // Set the drep type+ * cardano_error_t result = cardano_drep_set_type(drep, type);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The type was successfully set+ * }+ *+ * // Clean up+ * cardano_drep_unref(&drep);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_drep_set_type(cardano_drep_t* drep, cardano_drep_type_t type);++/**+ * \brief Decrements the reference count of a drep object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_drep_t object+ * by decreasing its reference count. When the reference count reaches zero, the drep is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] drep A pointer to the pointer of the drep object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_drep_t* drep = cardano_drep_new();+ *+ * // Perform operations with the drep...+ *+ * cardano_drep_unref(&drep);+ * // At this point, drep is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_drep_unref, the pointer to the \ref cardano_drep_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_drep_unref(cardano_drep_t** drep);++/**+ * \brief Increases the reference count of the cardano_drep_t object.+ *+ * This function is used to manually increment the reference count of a drep+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_drep_unref.+ *+ * \param drep A pointer to the drep object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming drep is a previously created drep object+ *+ * cardano_drep_ref(drep);+ *+ * // Now drep can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_drep_ref there is a corresponding+ * call to \ref cardano_drep_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_drep_ref(cardano_drep_t* drep);++/**+ * \brief Retrieves the current reference count of the cardano_drep_t object.+ *+ * This function returns the number of active references to a drep object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_drep_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param drep A pointer to the drep object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified drep object. If the object+ * is properly managed (i.e., every \ref cardano_drep_ref call is matched with a+ * \ref cardano_drep_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming drep is a previously created drep object+ *+ * size_t ref_count = cardano_drep_refcount(drep);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_drep_refcount(const cardano_drep_t* drep);++/**+ * \brief Sets the last error message for a given drep object.+ *+ * Records an error message in the drep's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] drep A pointer to the \ref cardano_drep_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the drep's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_drep_set_last_error(cardano_drep_t* drep, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific drep.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_drep_set_last_error for the given+ * drep. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] drep A pointer to the \ref cardano_drep_t instance whose last error+ *                   message is to be retrieved. If the drep is NULL, the function+ *                   returns a generic error message indicating the null drep.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified drep. If the drep is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_drep_set_last_error for the same drep, or until+ *       the drep is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_drep_get_last_error(const cardano_drep_t* drep);++/**+ * \brief Creates an independent deep copy of a \ref cardano_drep_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_drep_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_drep_deep_clone(const cardano_drep_t* source, cardano_drep_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_DREP_H
+ vendor/include/cardano/common/drep_type.h view
@@ -0,0 +1,77 @@+/**+ * \file drep_type.h+ *+ * \author angel.castillo+ * \date   Jun 18, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_DREP_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_DREP_TYPE_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief In order to participate in governance, a stake credential must be delegated to a DRep.+ * Ada holders will generally delegate their voting rights to a registered DRep that will+ * vote on their behalf.+ *+ * In addition, two pre-defined DRep options are available: `Abstain` and `No Confidence`.+ */+typedef enum+{+  /**+   * \brief A DRep identified by a stake key hash.+   */+  CARDANO_DREP_TYPE_KEY_HASH = 0,++  /**+   * \brief A DRep identified by a script hash.+   */+  CARDANO_DREP_TYPE_SCRIPT_HASH = 1,++  /**+   * \brief If an Ada holder delegates to Abstain, then their stake is actively marked as not+   * participating in governance.+   *+   * The effect of delegating to Abstain on chain is that the delegated stake will not be+   * considered to be a part of the active voting stake. However, the stake will be considered+   * to be registered for the purpose of the incentives that are described in+   * the following link:+   *+   * \par+   * [Incentives for Ada holders to delegate voting stake](https://github.com/cardano-foundation/CIPs/blob/master/CIP-1694/README.md#incentives-for-ada-holders-to-delegate-voting-stake).+   */+  CARDANO_DREP_TYPE_ABSTAIN = 2,++  /**+   * \brief If an Ada holder delegates to No Confidence, then their stake is counted as a Yes vote on+   * every No Confidence action and a No vote on every other action. The delegated stake will+   * be considered part of the active voting stake. It also serves as a directly auditable+   * measure of the confidence of Ada holders in the constitutional committee.+   */+  CARDANO_DREP_TYPE_NO_CONFIDENCE = 3,+} cardano_drep_type_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_DREP_TYPE_H
+ vendor/include/cardano/common/ex_units.h view
@@ -0,0 +1,534 @@+/**+ * \file ex_units.h+ *+ * \author angel.castillo+ * \date   Mar 06, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_EX_UNITS_H+#define BIGLUP_LABS_INCLUDE_CARDANO_EX_UNITS_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represent a measure of computational resources, specifically, how much memory+ * and CPU a Plutus script will use when executed. It's an essential component to+ * estimate the cost of running a Plutus script on the Cardano blockchain.+ *+ * The two resources measured by ExUnits are memory and CPU. When a Plutus script+ * is executed, it consumes both these resources. The ExUnits system quantifies+ * this consumption, helping to ensure that scripts don't overrun the system and+ * that they terminate in a reasonable amount of time.+ */+typedef struct cardano_ex_units_t cardano_ex_units_t;++/**+ * \brief Creates and initializes a new instance of \ref cardano_ex_units_t.+ *+ * This function allocates and initializes a new instance of \ref cardano_ex_units_t.+ * Execution units (ExUnits) are a measure of  the computational resources required.+ *+ * \param[in] memory The amount of memory (in units) that the script is expected to consume.+ * \param[in] cpu_steps The number of CPU steps that the script is expected to consume.+ * \param[out] ex_units On successful initialization, this will point to a newly created+ *            \ref cardano_ex_units_t object. This object represents a "strong reference"+ *            to the ex_units, meaning that it is fully initialized and ready for use.+ *            The caller is responsible for managing the lifecycle of this object.+ *            Specifically, once the execution units are no longer needed, the caller must release them+ *            by calling \ref cardano_ex_units_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the execution units were successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_ex_units_t* ex_units = NULL;+ * uint64_t memory = 1024; // 1024 units of memory+ * uint64_t cpu_steps = 500; // 500 CPU steps+ *+ * // Attempt to create a new execution units object+ * cardano_error_t result = cardano_ex_units_new(memory, cpu_steps, &ex_units);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the ex_units+ *+ *   // Once done, ensure to clean up and release the ex_units+ *   cardano_ex_units_unref(&ex_units);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_ex_units_new(+  uint64_t             memory,+  uint64_t             cpu_steps,+  cardano_ex_units_t** ex_units);++/**+ * \brief Creates a \ref cardano_ex_units_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_ex_units_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a ex_units.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] ex_units A pointer to a pointer of \ref cardano_ex_units_t that will be set to the address+ *                        of the newly created ex_units object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the execution units were successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_ex_units_t object by calling+ *       \ref cardano_ex_units_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_ex_units_t* ex_units = NULL;+ *+ * cardano_error_t result = cardano_ex_units_from_cbor(reader, &ex_units);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the ex_units+ *+ *   // Once done, ensure to clean up and release the ex_units+ *   cardano_ex_units_unref(&ex_units);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode ex_units: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_ex_units_from_cbor(cardano_cbor_reader_t* reader, cardano_ex_units_t** ex_units);++/**+ * \brief Serializes execution units into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_ex_units_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] ex_units A constant pointer to the \ref cardano_ex_units_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p ex_units or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_ex_units_t* ex_units = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_ex_units_to_cbor(ex_units, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_ex_units_unref(&ex_units);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_ex_units_to_cbor(+  const cardano_ex_units_t* ex_units,+  cardano_cbor_writer_t*    writer);++/**+ * \brief Serializes execution units to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "mem", "steps".+ * Both values are encoded as strings to ensure precision for 64-bit integers in JSON.+ *+ * \param[in]  ex_units  Pointer to a valid \ref cardano_ex_units_t.+ * \param[in]  writer    Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p ex_units or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_ex_units_to_cip116_json(+  const cardano_ex_units_t* ex_units,+  cardano_json_writer_t*    writer);++/**+ * \brief Retrieves the memory component of the execution units.+ *+ * \param[in] ex_units A constant pointer to the \ref cardano_ex_units_t object from which+ *                     the memory is to be retrieved.+ *+ * \return The amount of memory.+ *+ * Usage Example:+ * \code{.c}+ * cardano_ex_units_t* ex_units = ...; // Assume ex_units is initialized and contains memory and cpu_steps+ * uint64_t memory_allocated = cardano_ex_units_get_memory(ex_units);+ * printf("Memory: %llu units\n", memory_allocated);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_ex_units_get_memory(+  const cardano_ex_units_t* ex_units);++/**+ * \brief Retrieves the memory budget of an \ref cardano_ex_units_t object.+ *+ * \param[in]  ex_units  A pointer to an initialised \ref cardano_ex_units_t object.+ *                       Must not be \c NULL.+ * \param[out] memory    A pointer to a 64-bit unsigned integer that will receive the+ *                       memory count on success. Must not be \c NULL.+ *+ * \return A \ref cardano_error_t value:+ *   - \ref CARDANO_SUCCESS               – The call succeeded and *steps now contains the memory budget.+ *   - \ref CARDANO_ERROR_POINTER_IS_NULL – \p ex_units or \p memory was \c NULL.+ *   - Any other error code propagated from the underlying implementation.+ *+ * \note If the function fails, a descriptive message can be obtained by calling \ref cardano_ex_units_get_last_error on the \p ex_units object.+ *+ * Usage Example:+ * \code{.c}+ * cardano_ex_units_t* ex_units = // previously initialised;+ * uint64_t memory = 0;+ *+ * cardano_error_t rc = cardano_ex_units_get_memory_ex(ex_units, &memory);+ *+ * if (rc == CARDANO_SUCCESS)+ * {+ *   printf("Memory steps allocated: %llu\n", (unsigned long long)memory);+ * }+ * else+ * {+ *   printf("Failed to read memory steps: %s\n", cardano_ex_units_get_last_error(ex_units));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_ex_units_get_memory_ex(+  const cardano_ex_units_t* ex_units,+  uint64_t*                 memory);++/**+ * \brief Sets the memory amount for the execution units.+ *+ * This function sets the memory units in the \ref cardano_ex_units_t object.+ *+ * \param[in,out] ex_units A pointer to the \ref cardano_ex_units_t object whose memory amount+ *                         is to be set. This object must be previously initialized.+ * \param[in] memory The memory amount to be set for the execution units.+ *+ * \return \ref CARDANO_SUCCESS if the memory was successfully set; otherwise, an appropriate+ *         error code is returned indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_ex_units_t* ex_units = cardano_ex_units_new(1024, 1000); // Assume ex_units is initialized with default values+ * cardano_error_t result = cardano_ex_units_set_memory(ex_units, 2048); // Update memory to 2048 bytes+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Memory value updated successfully+ * }+ * else+ * {+ *   // Handle error+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_ex_units_set_memory(+  cardano_ex_units_t* ex_units,+  uint64_t            memory);++/**+ * \brief Retrieves the CPU steps allocated to an cardano_ex_units_t object.+ *+ * This function retrieves the amount of CPU steps that have been allocated to a \ref cardano_ex_units_t object,+ * representing the computational resources allowed for executing a script.+ *+ * \param[in] ex_units A constant pointer to the \ref cardano_ex_units_t object from which+ *                     the CPU steps are to be retrieved.+ *+ * \return The amount of CPU steps allocated to the cardano_ex_units_t object. If the ex_units is NULL,+ *        the function returns 0.+ *+ * Usage Example:+ * \code{.c}+ * cardano_ex_units_t* ex_units = ...; // Assume this is initialized+ * uint64_t cpu_steps = cardano_ex_units_get_cpu_steps(ex_units);+ * printf("CPU steps allocated: %llu\n", (unsigned long long)cpu_steps);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_ex_units_get_cpu_steps(const cardano_ex_units_t* ex_units);++/**+ * \brief Retrieves the CPU-step budget of an \ref cardano_ex_units_t object.+ *+ * \param[in]  ex_units  A pointer to an initialised \ref cardano_ex_units_t object.+ *                       Must not be \c NULL.+ * \param[out] steps     A pointer to a 64-bit unsigned integer that will receive the+ *                       CPU-step count on success. Must not be \c NULL.+ *+ * \return A \ref cardano_error_t value:+ *   - \ref CARDANO_SUCCESS               – The call succeeded and *steps now contains the CPU budget.+ *   - \ref CARDANO_ERROR_POINTER_IS_NULL – \p ex_units or \p steps was \c NULL.+ *   - Any other error code propagated from the underlying implementation.+ *+ * \note If the function fails, a descriptive message can be obtained by calling \ref cardano_ex_units_get_last_error on the \p ex_units object.+ *+ * Usage Example:+ * \code{.c}+ * cardano_ex_units_t* ex_units = // previously initialised;+ * uint64_t cpu_steps = 0;+ *+ * cardano_error_t rc = cardano_ex_units_get_cpu_steps_ex(ex_units, &cpu_steps);+ *+ * if (rc == CARDANO_SUCCESS)+ * {+ *   printf("CPU steps allocated: %llu\n", (unsigned long long)cpu_steps);+ * }+ * else+ * {+ *   printf("Failed to read CPU steps: %s\n", cardano_ex_units_get_last_error(ex_units));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_ex_units_get_cpu_steps_ex(+  const cardano_ex_units_t* ex_units,+  uint64_t*                 steps);++/**+ * \brief Sets the CPU steps for the specified execution units object.+ *+ * This function sets the number of CPU steps that the execution units object will represent.+ *+ * \param[in,out] ex_units A pointer to the \ref cardano_ex_units_t object whose CPU steps are to be set.+ * \param[in] cpu_steps The number of CPU steps to set for the execution units.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the CPU steps were successfully set, or an appropriate error code if an error occurred.+ *+ * \note It is important to ensure that the \p ex_units object has been properly initialized before+ *       calling this function. If \p ex_units is NULL, the function will return \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_ex_units_t* ex_units = ...; // Assume ex_units is already created and initialized+ * uint64_t cpu_steps = 5000; // Example CPU steps+ *+ * cardano_error_t result = cardano_ex_units_set_cpu_steps(ex_units, cpu_steps);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // CPU steps are now set to 5000+ *   // Proceed with using the ex_units object+ * }+ * else+ * {+ *   // Handle the error+ *   fprintf(stderr, "Failed to set CPU steps: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_ex_units_set_cpu_steps(+  cardano_ex_units_t* ex_units,+  uint64_t            cpu_steps);++/**+ * \brief Decrements the reference count of a cardano_ex_units_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_ex_units_t object+ * by decreasing its reference count. When the reference count reaches zero, the ex_units is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] ex_units A pointer to the pointer of the ex_units object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_ex_units_t* ex_units = cardano_ex_units_new(mem, cpu_steps);+ *+ * // Perform operations with the ex_units...+ *+ * cardano_ex_units_unref(&ex_units);+ * // At this point, ex_units is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_ex_units_unref, the pointer to the \ref cardano_ex_units_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_ex_units_unref(cardano_ex_units_t** ex_units);++/**+ * \brief Increases the reference count of the cardano_ex_units_t object.+ *+ * This function is used to manually increment the reference count of an cardano_ex_units_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_ex_units_unref.+ *+ * \param ex_units A pointer to the cardano_ex_units_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming ex_units is a previously created ex_units object+ *+ * cardano_ex_units_ref(ex_units);+ *+ * // Now ex_units can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_ex_units_ref there is a corresponding+ * call to \ref cardano_ex_units_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_ex_units_ref(cardano_ex_units_t* ex_units);++/**+ * \brief Retrieves the current reference count of the cardano_ex_units_t object.+ *+ * This function returns the number of active references to an cardano_ex_units_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_ex_units_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param ex_units A pointer to the cardano_ex_units_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_ex_units_t object. If the object+ * is properly managed (i.e., every \ref cardano_ex_units_ref call is matched with a+ * \ref cardano_ex_units_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming ex_units is a previously created ex_units object+ *+ * size_t ref_count = cardano_ex_units_refcount(ex_units);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_ex_units_refcount(const cardano_ex_units_t* ex_units);++/**+ * \brief Sets the last error message for a given cardano_ex_units_t object.+ *+ * Records an error message in the ex_units's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] ex_units A pointer to the \ref cardano_ex_units_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the ex_units's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_ex_units_set_last_error(cardano_ex_units_t* ex_units, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific ex_units.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_ex_units_set_last_error for the given+ * ex_units. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] ex_units A pointer to the \ref cardano_ex_units_t instance whose last error+ *                   message is to be retrieved. If the ex_units is NULL, the function+ *                   returns a generic error message indicating the null ex_units.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified ex_units. If the ex_units is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_ex_units_set_last_error for the same ex_units, or until+ *       the ex_units is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_ex_units_get_last_error(const cardano_ex_units_t* ex_units);++/**+ * \brief Creates an independent deep copy of a \ref cardano_ex_units_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_ex_units_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_ex_units_deep_clone(const cardano_ex_units_t* source, cardano_ex_units_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_EX_UNITS_H
+ vendor/include/cardano/common/governance_action_id.h view
@@ -0,0 +1,897 @@+/**+ * \file governance_action_id.h+ *+ * \author angel.castillo+ * \date   Apr 12, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_GOVERNANCE_ACTION_ID_H+#define BIGLUP_LABS_INCLUDE_CARDANO_GOVERNANCE_ACTION_ID_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/crypto/blake2b_hash.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Each governance action that is accepted on the chain will be assigned a unique+ * identifier, consisting of the transaction hash that created it and the index within+ * the transaction body that points to it.+ */+typedef struct cardano_governance_action_id_t cardano_governance_action_id_t;++/**+ * \brief Creates and initializes a new instance of a governance action id.+ *+ * This function allocates and initializes a new instance of \ref cardano_governance_action_id_t,+ * using the provided transaction hash and index. It returns an error code to indicate success+ * or failure of the operation.+ *+ * \param[in] transaction_hash A pointer to \ref cardano_blake2b_hash_t representing the transaction hash associated+ *             with this governance action id. The hash must be properly initialized before being+ *             passed to this function.+ * \param[in] index The index within the transaction body that points this governance action.+ * \param[out] governance_action_id On successful initialization, this will point to a newly created+ *             \ref cardano_governance_action_id_t object. This object represents a "strong reference"+ *             to the governance_action_id, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the governance_action_id is no longer needed, the caller must release it+ *             by calling \ref cardano_governance_action_id_unref.+ *+ * \return \ref CARDANO_SUCCESS if the governance_action_id was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_blake2b_hash_t* hash = { ... };  // Assume hash is initialized here+ * cardano_governance_action_id_t* governance_action_id = NULL;+ *+ * // Attempt to create a new governance_action_id+ * cardano_error_t result = cardano_governance_action_id_new(hash, 1, &governance_action_id);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the governance_action_id+ *+ *   // Once done, ensure to clean up and release the governance_action_id+ *   cardano_governance_action_id_unref(&governance_action_id);+ * }+ *+ * cardano_blake2b_hash_unref(&hash);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_new(+  const cardano_blake2b_hash_t*    transaction_hash,+  uint64_t                         index,+  cardano_governance_action_id_t** governance_action_id);++/**+ * \brief Parses a Bech32-encoded governance action ID and initializes a corresponding governance action ID object.+ *+ * This function takes a Bech32-encoded string representation of a governance action ID, as specified in CIP-129,+ * and creates a \ref cardano_governance_action_id_t object.+ *+ * For example:+ * - Bech32-encoded input: `gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf`+ * - Resulting governance action ID: Transaction ID (`0000000000000000000000000000000000000000000000000000000000000000`),+ *   Index (`11`).+ *+ * \param[in] data A pointer to the Bech32-encoded string. This parameter must not be NULL.+ * \param[in] size The size of the Bech32-encoded string in bytes.+ * \param[out] action_id A pointer to a \ref cardano_governance_action_id_t pointer. On successful parsing, this pointer+ *             will point to a newly created governance action ID object. The caller is responsible for managing the+ *             lifecycle of this object and must release it using \ref cardano_governance_action_id_unref.+ *+ * \return \ref CARDANO_SUCCESS if the parsing was successful and the governance action ID object was created.+ *         Returns an appropriate error code otherwise:+ *         - \ref CARDANO_ERROR_POINTER_IS_NULL if any input pointer is NULL.+ *         - \ref CARDANO_ERROR_INVALID_ADDRESS_FORMAT if the input string is not a valid Bech32-encoded governance action ID.+ *         - \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if memory for the decoding buffers could not be allocated.+ *         - \ref CARDANO_ERROR_DECODING if the Bech32 string cannot be decoded, including allocation failures inside the+ *           Bech32 decoder itself.+ *+ * Usage Example+ * \code{.c}+ * const char* bech32_string = "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf";+ * cardano_governance_action_id_t* action_id = NULL;+ *+ * cardano_error_t result = cardano_governance_action_id_from_bech32(bech32_string, strlen(bech32_string), &action_id);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Governance Action ID successfully parsed.\n");+ *   // Use the action_id as needed+ *+ *   // Free the governance action ID object when done+ *   cardano_governance_action_id_unref(&action_id);+ * }+ * else+ * {+ *   printf("Failed to parse governance action ID from Bech32: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_from_bech32(+  const char*                      data,+  size_t                           size,+  cardano_governance_action_id_t** action_id);++/**+ * \brief Creates a governance action id from a hexadecimal transaction hash string.+ *+ * This function constructs a \ref cardano_governance_action_id_t object by interpreting the provided+ * hexadecimal string as a hash value and associating it with a specified index. It+ * returns an error code indicating the success or failure of the operation.+ *+ * \param[in] hex A pointer to a character array containing the hexadecimal representation of the transaction hash.+ * \param[in] hex_size The size of the hexadecimal string in bytes.+ * \param[in] index The index within the transaction body that points this governance action.+ * \param[out] governance_action_id On successful initialization, this will point to a newly created+ *                 \ref cardano_governance_action_id_t object. This object represents a "strong reference"+ *                 to the governance_action_id, meaning that it is fully initialized and ready for use.+ *                 The caller is responsible for managing the lifecycle of this object,+ *                 specifically, once the governance_action_id is no longer needed, the caller must release it+ *                 by calling \ref cardano_governance_action_id_unref.+ *+ * \return \ref CARDANO_SUCCESS if the governance_action_id was successfully created, or an appropriate error code+ *         indicating the reason for failure.+ *+ * \note The function assumes that the hexadecimal string is valid and correctly formatted.+ *+ * Usage Example:+ * \code{.c}+ * const char* hash_hex = "abcdef1234567890abcdef1234567890abcdef12....";+ * size_t hex_size = strlen(hash_hex);+ * cardano_governance_action_id_t* governance_action_id = NULL;+ *+ * // Attempt to create a new governance_action_id from a hexadecimal hash+ * cardano_error_t result = cardano_governance_action_id_from_hash_hex(hash_hex, hex_size, 1, &governance_action_id);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the governance_action_id+ *+ *   // Once done, ensure to clean up and release the governance_action_id+ *   cardano_governance_action_id_unref(&governance_action_id);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_from_hash_hex(+  const char*                      hex,+  size_t                           hex_size,+  uint64_t                         index,+  cardano_governance_action_id_t** governance_action_id);++/**+ * \brief Creates a governance action id from a byte array representing a transaction hash.+ *+ * This function constructs a \ref cardano_governance_action_id_t object by using the provided+ * byte array as a hash value and associating it with a specified index. It returns an error+ * code indicating the success or failure of the operation.+ *+ * \param[in] data A pointer to the byte array containing the hash data.+ * \param[in] data_size The size of the byte array in bytes.+ * \param[in] index The index within the transaction body that points this governance action.+ * \param[out] governance_action_id On successful initialization, this will point to a newly created+ *                 \ref cardano_governance_action_id_t object. This object represents a "strong reference"+ *                 to the governance_action_id, meaning that it is fully initialized and ready for use.+ *                 The caller is responsible for managing the lifecycle of this object,+ *                 specifically, once the governance_action_id is no longer needed, the caller must release it+ *                 by calling \ref cardano_governance_action_id_unref.+ *+ * \return \ref CARDANO_SUCCESS if the governance_action_id was successfully created, or an appropriate error code+ *         indicating the reason for failure.+ *+ * Usage Example:+ * \code{.c}+ * const byte_t hash_data[] = { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef ... };+ * size_t data_size = sizeof(hash_data);+ * cardano_governance_action_id_t* governance_action_id = NULL;+ *+ * // Attempt to create a new governance_action_id from byte array hash+ * cardano_error_t result = cardano_governance_action_id_from_hash_bytes(hash_data, data_size, 1, &governance_action_id);+ *+ * if (result == CARDANO_SUCCESS && governance_action_id)+ * {+ *   // Use the governance_action_id+ *+ *   // Once done, ensure to clean up and release the governance_action_id+ *   cardano_governance_action_id_unref(&governance_action_id);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_from_hash_bytes(+  const byte_t*                    data,+  size_t                           data_size,+  uint64_t                         index,+  cardano_governance_action_id_t** governance_action_id);++/**+ * \brief Creates a governance_action_id from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_governance_action_id_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a governance action id.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded governance action id data.+ * \param[out] governance_action_id A pointer to a pointer of \ref cardano_governance_action_id_t that will be set to the address+ *                        of the newly created governance action id object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the governance_action_id was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_governance_action_id_t object by calling+ *       \ref cardano_governance_action_id_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_governance_action_id_t* governance_action_id = NULL;+ *+ * cardano_error_t result = cardano_governance_action_id_from_cbor(reader, &governance_action_id);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the governance_action_id+ *+ *   // Once done, ensure to clean up and release the governance_action_id+ *   cardano_governance_action_id_unref(&governance_action_id);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode governance_action_id: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_from_cbor(cardano_cbor_reader_t* reader, cardano_governance_action_id_t** governance_action_id);++/**+ * \brief Serializes a governance action id into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_governance_action_id_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] governance_action_id A constant pointer to the \ref cardano_governance_action_id_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p governance_action_id or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_governance_action_id_to_cbor(governance_action_id, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_governance_action_id_unref(&governance_action_id);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_governance_action_id_to_cbor(+  const cardano_governance_action_id_t* governance_action_id,+  cardano_cbor_writer_t*                writer);++/**+ * \brief Serializes a governance action ID to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "transaction_id", "gov_action_index".+ *+ * \param[in]  action_id Pointer to a valid \ref cardano_governance_action_id_t.+ * \param[in]  writer    Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS                On success.+ * CARDANO_ERROR_POINTER_IS_NULL          If \p action_id or \p writer is NULL.+ * CARDANO_ERROR_MEMORY_ALLOCATION_FAILED If memory allocation fails.+ * Other                                  Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_to_cip116_json(+  const cardano_governance_action_id_t* action_id,+  cardano_json_writer_t*                writer);++/**+ * \brief Computes the required buffer size for a CIP-29 compliant Bech32 representation of a governance action ID.+ *+ * This function calculates the minimum buffer size, including null termination, needed to store the Bech32 string representation+ * of a governance action ID. The Bech32 representation combines a transaction ID (32 bytes) and an index (1 byte) into a single+ * string with the prefix `gov_action`.+ *+ * \param[in] governance_action_id A pointer to an initialized \ref cardano_governance_action_id_t object representing the+ *                                 governance action ID. This parameter must not be NULL.+ *+ * \return The required buffer size in bytes, including space for the null-terminator.+ *+ * Usage Example+ * \code{.c}+ * cardano_governance_action_id_t* gov_action_id = ...; // Assume initialized+ * size_t required_size = cardano_governance_action_id_get_bech32_size(gov_action_id);+ *+ * char* bech32_str = (char*)malloc(required_size);+ *+ * if (bech32_str != NULL)+ * {+ *   // Use the buffer for encoding the governance action ID into Bech32 format+ *   free(bech32_str);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t+cardano_governance_action_id_get_bech32_size(+  const cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Converts a governance action ID to its CIP-29 compliant Bech32 representation.+ *+ * This function encodes a governance action ID, which combines a transaction ID (32 bytes) and an index (1 byte), into its+ * Bech32 string representation. The resulting Bech32 string uses the prefix `gov_action` as defined in CIP-29 and is stored+ * in the provided buffer.+ *+ * \param[in] governance_action_id A pointer to an initialized \ref cardano_governance_action_id_t object representing the+ *                                 governance action ID to be converted. This parameter must not be NULL.+ * \param[out] data A pointer to the buffer where the resulting Bech32 string will be stored. The buffer must have sufficient+ *                  size, as determined by \ref cardano_governance_action_id_get_bech32_size.+ * \param[in] size The size of the provided buffer in bytes, including space for the null-terminator.+ *+ * \return \ref CARDANO_SUCCESS if the conversion was successful and the Bech32 string is stored in `data`. Returns an appropriate error code if the operation fails.+ *+ * Usage Example+ * \code{.c}+ * cardano_governance_action_id_t* gov_action_id = ...; // Assume initialized+ * size_t required_size = cardano_governance_action_id_get_bech32_size(gov_action_id);+ *+ * char* bech32_str = (char*)malloc(required_size);+ *+ * if (bech32_str != NULL)+ * {+ *   cardano_error_t result = cardano_governance_action_id_to_bech32(gov_action_id, bech32_str, required_size);+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     printf("Governance Action Bech32: %s\n", bech32_str);+ *   }+ *   else+ *   {+ *     printf("Error converting governance action ID to Bech32: %s\n", cardano_error_to_string(result));+ *   }+ *   free(bech32_str);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_to_bech32(+  const cardano_governance_action_id_t* governance_action_id,+  char*                                 data,+  size_t                                size);++/**+ * \brief Retrieves the Bech32 string representation of a governance action ID.+ *+ * This function returns the Bech32-encoded string representation of a governance action ID as specified in CIP-0129.+ * The governance action ID is derived from the transaction ID and index, and the Bech32 encoding includes the appropriate+ * prefix (`"gov_action"`) followed by the encoded ID.+ *+ * For example:+ * - Transaction ID: `0000000000000000000000000000000000000000000000000000000000000000`+ * - Index: `11`+ * - Bech32-encoded governance action ID: `gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf`+ *+ * \param[in] governance_action_id A pointer to an initialized \ref cardano_governance_action_id_t object representing the governance action ID.+ *                                 This parameter must not be NULL.+ *+ * \return A constant pointer to a null-terminated string containing the Bech32-encoded governance action ID.+ *         The returned string is managed internally by the library and must not be modified or freed by the caller.+ *         Returns `NULL` if the input pointer is invalid.+ *+ * ### Usage Example+ * \code{.c}+ * const cardano_governance_action_id_t* gov_action_id = ...; // Assume initialized+ * const char* bech32_string = cardano_governance_action_id_get_string(gov_action_id);+ *+ * if (bech32_string != NULL)+ * {+ *   printf("Governance Action ID (Bech32): %s\n", bech32_string);+ * }+ * else+ * {+ *   printf("Failed to retrieve governance action ID in Bech32 format.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char*+cardano_governance_action_id_get_string(+  const cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Retrieves the transaction hash associated with a governance action id.+ *+ * This function provides access to the hash part of a \ref cardano_governance_action_id_t object.+ * It returns a new reference to a \ref cardano_blake2b_hash_t object representing the hash.+ * This allows the hash to be used independently of the original governance_action_id object. The+ * reference count of the hash object is increased by one, making it the caller's responsibility+ * to release it by calling \ref cardano_blake2b_hash_unref when it is no longer needed.+ *+ * \param governance_action_id A constant pointer to the \ref cardano_governance_action_id_t object from which+ *                   the hash is to be retrieved.+ *+ * \return A pointer to a new \ref cardano_blake2b_hash_t object containing the hash.+ *         If the input governance_action_id is NULL, returns NULL. The caller is responsible for+ *         managing the lifecycle of this object, including releasing it with+ *         \ref cardano_blake2b_hash_unref.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* original_governance_action_id = cardano_governance_action_id_new(...);+ * cardano_blake2b_hash_t* hash_governance_action_id = cardano_governance_action_id_get_hash(original_governance_action_id);+ *+ * if (hash_governance_action_id)+ * {+ *   // Use the hash governance_action_id+ *+ *   // Once done, ensure to clean up and release the hash governance_action_id+ *   cardano_blake2b_hash_unref(&hash_governance_action_id);+ * }+ *+ * // Release the original governance_action_id after use+ * cardano_governance_action_id_unref(&original_governance_action_id);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_blake2b_hash_t* cardano_governance_action_id_get_hash(const cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Retrieves the size of the hash bytes stored in the governance action id.+ *+ * This function computes the size of the hash bytes stored within a \ref cardano_governance_action_id_t object.+ * It is particularly useful for determining the buffer size needed to store the hash bytes when+ * retrieving them via \ref cardano_governance_action_id_get_hash_bytes.+ *+ * \param[in] governance_action_id A constant pointer to the \ref cardano_governance_action_id_t object from which+ *                       the size of the hash bytes is to be retrieved.+ *+ * \return The size of the hash bytes. If the governance_action_id is NULL the function returns zero.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id = cardano_governance_action_id_new(...);+ * size_t hash_size = cardano_governance_action_id_get_hash_bytes_size(governance_action_id);+ *+ * if (hash_size > 0)+ * {+ *   byte_t* hash_bytes = malloc(hash_size);+ *+ *   if (hash_bytes)+ *   {+ *     // Proceed to get the hash bytes+ *   }+ * }+ * cardano_governance_action_id_unref(&governance_action_id);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_governance_action_id_get_hash_bytes_size(const cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Retrieves the byte array representation of the transaction hash from a governance action id.+ *+ * This function accesses the byte representation of the hash associated with a given+ * \ref cardano_governance_action_id_t object. It provides a direct pointer to the internal byte array+ * representing the hash, which should not be modified or freed by the caller.+ *+ * \param governance_action_id A constant pointer to the \ref cardano_governance_action_id_t object from which+ *                   the hash bytes are to be retrieved.+ *+ * \return A pointer to a constant byte array containing the hash data. If the input governance_action_id+ *         is NULL, returns NULL. The data remains valid as long as the governance_action_id object is not+ *         freed or modified.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id = cardano_governance_action_id_new(...);+ * const byte_t* hash_bytes = cardano_governance_action_id_get_hash_bytes(governance_action_id);+ *+ * if (hash_bytes)+ * {+ *   // Use the hash bytes for operations like comparison or display+ * }+ *+ * // Clean up the governance_action_id object once done+ * cardano_governance_action_id_unref(&governance_action_id);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const byte_t* cardano_governance_action_id_get_hash_bytes(const cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Retrieves the size needed for the hexadecimal string representation of the governance_action_id's hash.+ *+ * This function calculates the size required to store the hexadecimal string representation of the hash+ * associated with a \ref cardano_governance_action_id_t object. This size includes the space needed for the null-terminator.+ *+ * \param[in] governance_action_id A constant pointer to the \ref cardano_governance_action_id_t object whose hash size is to be determined.+ *+ * \return The size in bytes required to store the hexadecimal representation of the hash, including the null terminator.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id = cardano_governance_action_id_new(...);+ * size_t hex_size = cardano_governance_action_id_get_hash_hex_size(governance_action_id);+ * char* hex_string = malloc(hex_size);+ *+ * if (hex_string)+ * {+ *   // Now use hex_string to get the hash or do other operations+ *   free(hex_string);+ * }+ *+ * cardano_governance_action_id_unref(&governance_action_id);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_governance_action_id_get_hash_hex_size(const cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Retrieves the hexadecimal string representation of the hash from a governance action id.+ *+ * This function provides access to the hexadecimal (hex) string representation of the hash+ * associated with a given \ref cardano_governance_action_id_t object. It returns a direct pointer to the+ * internal hex string which should not be modified or freed by the caller.+ *+ * \param governance_action_id A constant pointer to the \ref cardano_governance_action_id_t object from which+ *                   the hex string of the hash is to be retrieved. The object must not be NULL.+ *+ * \return A pointer to a constant character array containing the hex representation of the hash.+ *         If the input governance_action_id is NULL, returns NULL. The data remains valid as long as the+ *         governance_action_id object is not freed or modified.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id = cardano_governance_action_id_new(...);+ * const char* hash_hex = cardano_governance_action_id_get_hash_hex(governance_action_id);+ *+ * if (hash_hex)+ * {+ *   // Use the hash hex for operations like logging, display, or comparison+ * }+ *+ * // Clean up the governance_action_id object once done+ * cardano_governance_action_id_unref(&governance_action_id);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_governance_action_id_get_hash_hex(const cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Retrieves the index of the governance action id.+ *+ * This function retrieves the index of a given \ref cardano_governance_action_id_t object and stores it in the provided+ * output parameter.+ *+ * \param[in] governance_action_id A constant pointer to the \ref cardano_governance_action_id_t object from which+ *                                 the index is to be retrieved. The object must not be NULL.+ * \param[out] index Pointer to a variable where the governance action id index will be stored.+ *+ * \return \ref CARDANO_SUCCESS if the index was successfully retrieved, or an appropriate error code if the+ *         input is NULL or any other error occurs.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id = cardano_governance_action_id_new(...);+ * uint64_t index = 0;+ * cardano_error_t result = cardano_governance_action_id_get_index(governance_action_id, &index);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *  // Handle governance action id index+ * }+ *+ * // Clean up the governance_action_id object once done+ * cardano_governance_action_id_unref(&governance_action_id);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_get_index(const cardano_governance_action_id_t* governance_action_id, uint64_t* index);++/**+ * \brief Sets the index of the governance action id.+ *+ * This function assigns a new index to an existing \ref cardano_governance_action_id_t object.+ *+ * \param[in,out] governance_action_id A pointer to the \ref cardano_governance_action_id_t object whose index is to be set.+ * \param[in] index The new index of the governance action id.+ *+ * \return Returns \ref CARDANO_SUCCESS if the type was successfully set. Returns \ref CARDANO_ERROR_POINTER_IS_NULL+ *         if the \p governance_action_id pointer is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id = cardano_governance_action_id_new(...);+ * cardano_error_t result = cardano_governance_action_id_set_index(governance_action_id, 1);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // governance_action_id index updated successfully+ * }+ *+ * cardano_governance_action_id_unref(&governance_action_id);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_set_index(cardano_governance_action_id_t* governance_action_id, uint64_t index);++/**+ * \brief Sets the hash for a governance action id.+ *+ * This function assigns a new hash to an existing \ref cardano_governance_action_id_t object. The function copies the+ * provided hash into the governance_action_id, so the original hash object may be modified or freed after this operation without+ * affecting the governance_action_id's hash.+ *+ * \param[in,out] governance_action_id A pointer to the \ref cardano_governance_action_id_t object whose hash is to be set.+ *                           This object must have been previously created and not yet freed.+ * \param[in] hash A pointer to a \ref cardano_blake2b_hash_t object containing the new hash to be set.+ *                 This parameter must not be NULL.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the hash was successfully set. If the \p governance_action_id or \p hash is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id = ...;+ * cardano_blake2b_hash_t* new_hash = cardano_blake2b_compute_hash(...);+ *+ * cardano_error_t result = cardano_governance_action_id_set_hash(governance_action_id, new_hash);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // The hash was successfully set+ * }+ *+ * // Clean up+ * cardano_governance_action_id_unref(&governance_action_id);+ * cardano_blake2b_hash_unref(&new_hash);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_set_hash(cardano_governance_action_id_t* governance_action_id, const cardano_blake2b_hash_t* hash);++/**+ * \brief Checks if two governance_action_id objects are equal.+ *+ * This function compares two \ref cardano_governance_action_id_t objects for equality.+ * It checks if the contents of the two governance_action_id objects are identical.+ *+ * \param[in] lhs A constant pointer to the first \ref cardano_governance_action_id_t object to be compared.+ * \param[in] rhs A constant pointer to the second \ref cardano_governance_action_id_t object to be compared.+ *+ * \return \c true if the two governance_action_id objects are equal (have the same contents), \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id1 = ...;+ * cardano_governance_action_id_t* governance_action_id2 = ...;+ *+ * if (cardano_governance_action_id_equals(governance_action_id1, governance_action_id2))+ * {+ *   printf("governance_action_id1 is equal to governance_action_id2\n");+ * }+ * else+ * {+ *   printf("governance_action_id1 is not equal to governance_action_id2\n");+ * }+ *+ * // Clean up the governance_action_id objects once done+ * cardano_governance_action_id_unref(&governance_action_id1);+ * cardano_governance_action_id_unref(&governance_action_id2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_governance_action_id_equals(const cardano_governance_action_id_t* lhs, const cardano_governance_action_id_t* rhs);++/**+ * \brief Decrements the reference count of a governance_action_id object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_governance_action_id_t object+ * by decreasing its reference count. When the reference count reaches zero, the governance_action_id is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] governance_action_id A pointer to the pointer of the governance_action_id object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_governance_action_id_t* governance_action_id = cardano_governance_action_id_new();+ *+ * // Perform operations with the governance action id...+ *+ * cardano_governance_action_id_unref(&governance_action_id);+ * // At this point, governance_action_id is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_governance_action_id_unref, the pointer to the \ref cardano_governance_action_id_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_governance_action_id_unref(cardano_governance_action_id_t** governance_action_id);++/**+ * \brief Increases the reference count of the cardano_governance_action_id_t object.+ *+ * This function is used to manually increment the reference count of a governance_action_id+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_governance_action_id_unref.+ *+ * \param governance_action_id A pointer to the governance_action_id object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming governance_action_id is a previously created governance_action_id object+ *+ * cardano_governance_action_id_ref(governance_action_id);+ *+ * // Now governance_action_id can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_governance_action_id_ref there is a corresponding+ * call to \ref cardano_governance_action_id_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_governance_action_id_ref(cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Retrieves the current reference count of the cardano_governance_action_id_t object.+ *+ * This function returns the number of active references to a governance_action_id object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_governance_action_id_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param governance_action_id A pointer to the governance_action_id object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified governance_action_id object. If the object+ * is properly managed (i.e., every \ref cardano_governance_action_id_ref call is matched with a+ * \ref cardano_governance_action_id_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming governance_action_id is a previously created governance_action_id object+ *+ * size_t ref_count = cardano_governance_action_id_refcount(governance_action_id);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_governance_action_id_refcount(const cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Sets the last error message for a given governance_action_id object.+ *+ * Records an error message in the governance_action_id's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] governance_action_id A pointer to the \ref cardano_governance_action_id_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the governance_action_id's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_governance_action_id_set_last_error(cardano_governance_action_id_t* governance_action_id, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific governance action id.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_governance_action_id_set_last_error for the given+ * governance action id. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] governance_action_id A pointer to the \ref cardano_governance_action_id_t instance whose last error+ *                   message is to be retrieved. If the governance_action_id is NULL, the function+ *                   returns a generic error message indicating the null governance action id.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified governance action id. If the governance_action_id is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_governance_action_id_set_last_error for the same governance_action_id, or until+ *       the governance_action_id is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_governance_action_id_get_last_error(const cardano_governance_action_id_t* governance_action_id);++/**+ * \brief Creates an independent deep copy of a \ref cardano_governance_action_id_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_governance_action_id_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_governance_action_id_deep_clone(const cardano_governance_action_id_t* source, cardano_governance_action_id_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_GOVERNANCE_ACTION_ID_H
+ vendor/include/cardano/common/governance_key_type.h view
@@ -0,0 +1,56 @@+/**+ * \file governance_key_type.h+ *+ * \author angel.castillo+ * \date   Nov 20, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_GOVERNANCE_KEY_TYPE_H+#define BIGLUP_LABS_INCLUDE_CARDANO_GOVERNANCE_KEY_TYPE_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Enumerates the types of governance keys.+ */+typedef enum+{+  /**+   * \brief CIP-1852’s constitutional committee hot verification signing key+   */+  CARDANO_GOVERNANCE_KEY_TYPE_CC_HOT = 0,++  /**+   * \brief Constitutional committee cold verification key hash (cold credential).+   */+  CARDANO_GOVERNANCE_KEY_TYPE_CC_COLD = 1,++  /**+   * \brief Constitutional committee hot verification key hash (hot credential).+   */+  CARDANO_GOVERNANCE_KEY_TYPE_DREP = 2+} cardano_governance_key_type_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_GOVERNANCE_KEY_TYPE_H
+ vendor/include/cardano/common/guard_set.h view
@@ -0,0 +1,515 @@+/**+ * \file guard_set.h+ *+ * \author angel.castillo+ * \date   Jul 16, 2026+ *+ * Copyright 2026 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_GUARD_SET_H+#define BIGLUP_LABS_INCLUDE_CARDANO_GUARD_SET_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/common/credential.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents the set of credentials that must authorize a transaction (the guards+ * transaction body field).+ *+ * Guards generalize the required signers field: in addition to key hash credentials, a guard+ * can be a script hash credential whose script must be executed to authorize the transaction.+ *+ * On the wire this set has two forms: a set of bare key hashes (the historical required+ * signers encoding) and an ordered set of credentials. The set preserves insertion order and+ * rejects duplicates, since redeemers for script hash guards are indexed by the position of+ * the credential within this set.+ */+typedef struct cardano_guard_set_t cardano_guard_set_t;++/**+ * \brief Serializes this Dijkstra value using CIP-116 JSON conventions.+ *+ * Encodes an array in insertion order. Each member uses its own CIP-116-style JSON representation.+ *+ * \param[in] value Value to serialize. Must not be NULL.+ * \param[in] writer JSON writer that receives the encoded value. Must not be NULL.+ *+ * \return CARDANO_SUCCESS on success, CARDANO_ERROR_POINTER_IS_NULL for a NULL argument,+ *         or the error returned by a child serializer.+ */+CARDANO_EXPORT cardano_error_t+cardano_guard_set_to_cip116_json(const cardano_guard_set_t* value, cardano_json_writer_t* writer);++/**+ * \brief Creates and initializes a new instance of a guard_set.+ *+ * This function allocates and initializes a new instance of \ref cardano_guard_set_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] guard_set On successful initialization, this will point to a newly created+ *             \ref cardano_guard_set_t object. This object represents a "strong reference"+ *             to the guard_set, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the guard_set is no longer needed, the caller must release it+ *             by calling \ref cardano_guard_set_unref.+ *+ * \return \ref CARDANO_SUCCESS if the guard_set was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_guard_set_t* guard_set = NULL;+ *+ * // Attempt to create a new guard_set+ * cardano_error_t result = cardano_guard_set_new(&guard_set);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the guard_set+ *+ *   // Once done, ensure to clean up and release the guard_set+ *   cardano_guard_set_unref(&guard_set);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_guard_set_new(cardano_guard_set_t** guard_set);++/**+ * \brief Creates a guard set from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_guard_set_t object.+ * The set accepts both wire forms, with or without the set tag (258): a set of bare 28 byte key hashes (each is wrapped as a+ * key hash credential) and an ordered set of credentials. The form is determined by the first element of the set; mixing+ * both forms within one set is a decoding error, as is an empty set or a duplicated element.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded guard set data.+ * \param[out] guard_set A pointer to a pointer of \ref cardano_guard_set_t that will be set to the address+ *                        of the newly created guard_set object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the guard_set was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_guard_set_t object by calling+ *       \ref cardano_guard_set_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_guard_set_t* guard_set = NULL;+ *+ * cardano_error_t result = cardano_guard_set_from_cbor(reader, &guard_set);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the guard_set+ *+ *   // Once done, ensure to clean up and release the guard_set+ *   cardano_guard_set_unref(&guard_set);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode guard_set: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_guard_set_from_cbor(cardano_cbor_reader_t* reader, cardano_guard_set_t** guard_set);++/**+ * \brief Serializes a guard set into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_guard_set_t object using a \ref cardano_cbor_writer_t.+ * The wire form is chosen by content: if every member is a key hash credential, the set is emitted as a set+ * of bare key hashes (the historical required signers encoding); if at least one member is a script hash+ * credential, the set is emitted as an ordered set of credentials.+ *+ * \param[in] guard_set A constant pointer to the \ref cardano_guard_set_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p guard_set or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_guard_set_t* guard_set = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_guard_set_to_cbor(guard_set, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_guard_set_unref(&guard_set);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_guard_set_to_cbor(+  const cardano_guard_set_t* guard_set,+  cardano_cbor_writer_t*     writer);++/**+ * \brief Retrieves the length of a guard set.+ *+ * This function retrieves the number of elements in the provided \ref cardano_guard_set_t object.+ *+ * \param[in] guard_set A constant pointer to the \ref cardano_guard_set_t object whose length is to be retrieved.+ *+ * \return The number of elements in the guard_set. Return 0 if the guard_set is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_guard_set_t* guard_set = NULL;+ * cardano_error_t result = cardano_guard_set_new(&guard_set);+ *+ * // Populate guard_set with elements+ *+ * size_t length = cardano_guard_set_get_length(guard_set);+ * printf("Length of the guard_set: %zu\n", length);+ *+ * // Clean up the guard_set object once done+ * cardano_guard_set_unref(&guard_set);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_guard_set_get_length(const cardano_guard_set_t* guard_set);++/**+ * \brief Retrieves an element from a guard set by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_guard_set_t object+ * and stores it in the output parameter. Elements keep the order in which they were decoded or added.+ *+ * \param[in] guard_set A constant pointer to the \ref cardano_guard_set_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the guard set. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_credential_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_credential_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_guard_set_t* guard_set = NULL;+ * cardano_error_t result = cardano_guard_set_new(&guard_set);+ *+ * // Populate guard_set with elements+ *+ * cardano_credential_t* element = NULL;+ * result = cardano_guard_set_get(guard_set, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_credential_unref(&element);+ * }+ *+ * // Clean up the guard_set object once done+ * cardano_guard_set_unref(&guard_set);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_guard_set_get(const cardano_guard_set_t* guard_set, size_t index, cardano_credential_t** element);++/**+ * \brief Adds an element to a guard set.+ *+ * This function adds the specified element to the end of the provided \ref cardano_guard_set_t object.+ * Insertion order is preserved, since redeemers for script hash guards are indexed by the position of+ * the credential within this set. Duplicated elements are rejected.+ *+ * \param[in] guard_set A constant pointer to the \ref cardano_guard_set_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_credential_t object that is to be added to the guard_set.+ *                    The element will be referenced by the guard_set after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the guard_set,+ *         \ref CARDANO_ERROR_DUPLICATED_KEY if the element is already present in the set, or an+ *         appropriate error code indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_guard_set_t* guard_set = NULL;+ * cardano_error_t result = cardano_guard_set_new(&guard_set);+ *+ * // Create and initialize a new credential element+ * cardano_credential_t* element = { ... };+ *+ * // Add the element to the guard_set+ * result = cardano_guard_set_add(guard_set, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the guard_set object once done+ * cardano_guard_set_unref(&guard_set);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_guard_set_add(cardano_guard_set_t* guard_set, cardano_credential_t* element);++/**+ * \brief Determines if the guard set uses tags in its encoding.+ *+ * This function checks whether the given \ref cardano_guard_set_t object+ * uses the Conway era encoding for sets, which are collections identified by a tag.+ *+ * \param[in] guard_set A pointer to an initialized \ref cardano_guard_set_t object.+ *+ * \return A boolean value:+ *         - \c true if the guard set uses the Conway era encoding for sets (tagged sets).+ *         - \c false if the guard set uses the older encoding (arrays without tags).+ *+ * \note This function helps in determining the serialization format of the guard set,+ *       which may be necessary for compatibility with other transaction encoders/decoders.+ *+ * Usage Example:+ * \code{.c}+ * cardano_guard_set_t* guard_set = ...; // Assume guard_set is already initialized+ * bool is_tagged_set = cardano_guard_set_is_tagged(guard_set);+ *+ * if (is_tagged_set)+ * {+ *   printf("The guard set uses Conway era tag for sets.\n");+ * }+ * else+ * {+ *   printf("The guard set uses pre-Conway era encoding.\n");+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_guard_set_is_tagged(const cardano_guard_set_t* guard_set);++/**+ * \brief Enables or disables tagged encoding (Conway era feature) for the guard set.+ *+ * This function sets whether the specified \ref cardano_guard_set_t object should use tagged encoding+ * (introduced in the Conway era) when serializing the set in CBOR. If \p use_tag is set to \c true, the set will be+ * encoded using tagged sets. Otherwise, it will use the older array-based encoding method.+ *+ * \param[in,out] guard_set A pointer to an initialized \ref cardano_guard_set_t object.+ * \param[in] use_tag A boolean value that determines whether to use tagged encoding (\c true) or legacy array encoding (\c false).+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS if the operation was successful,+ *         or an appropriate error code if an error occurred.+ *+ * Usage Example:+ * \code{.c}+ * cardano_guard_set_t* guard_set = ...; // Assume guard_set is already initialized+ * cardano_error_t result = cardano_guard_set_set_use_tag(guard_set, true);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("The guard set is now set to use tagged encoding.\n");+ * }+ * else+ * {+ *   printf("Failed to set tagged encoding: %s\n", cardano_error_to_string(result));+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_guard_set_set_use_tag(cardano_guard_set_t* guard_set, bool use_tag);++/**+ * \brief Decrements the reference count of a guard_set object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_guard_set_t object+ * by decreasing its reference count. When the reference count reaches zero, the guard_set is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] guard_set A pointer to the pointer of the guard_set object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_guard_set_t* guard_set = NULL;+ * cardano_error_t result = cardano_guard_set_new(&guard_set);+ *+ * // Perform operations with the guard_set...+ *+ * cardano_guard_set_unref(&guard_set);+ * // At this point, guard_set is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_guard_set_unref, the pointer to the \ref cardano_guard_set_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_guard_set_unref(cardano_guard_set_t** guard_set);++/**+ * \brief Increases the reference count of the cardano_guard_set_t object.+ *+ * This function is used to manually increment the reference count of a guard_set+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_guard_set_unref.+ *+ * \param guard_set A pointer to the guard_set object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming guard_set is a previously created guard_set object+ *+ * cardano_guard_set_ref(guard_set);+ *+ * // Now guard_set can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_guard_set_ref there is a corresponding+ * call to \ref cardano_guard_set_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_guard_set_ref(cardano_guard_set_t* guard_set);++/**+ * \brief Retrieves the current reference count of the cardano_guard_set_t object.+ *+ * This function returns the number of active references to a guard_set object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_guard_set_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param guard_set A pointer to the guard_set object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified guard_set object. If the object+ * is properly managed (i.e., every \ref cardano_guard_set_ref call is matched with a+ * \ref cardano_guard_set_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming guard_set is a previously created guard_set object+ *+ * size_t ref_count = cardano_guard_set_refcount(guard_set);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_guard_set_refcount(const cardano_guard_set_t* guard_set);++/**+ * \brief Sets the last error message for a given guard_set object.+ *+ * Records an error message in the guard_set's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] guard_set A pointer to the \ref cardano_guard_set_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the guard_set's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_guard_set_set_last_error(cardano_guard_set_t* guard_set, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific guard_set.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_guard_set_set_last_error for the given+ * guard_set. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] guard_set A pointer to the \ref cardano_guard_set_t instance whose last error+ *                   message is to be retrieved. If the guard_set is NULL, the function+ *                   returns a generic error message indicating the null guard_set.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified guard_set. If the guard_set is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_guard_set_set_last_error for the same guard_set, or until+ *       the guard_set is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_guard_set_get_last_error(const cardano_guard_set_t* guard_set);++/**+ * \brief Creates an independent deep copy of a \ref cardano_guard_set_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_guard_set_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_guard_set_deep_clone(const cardano_guard_set_t* source, cardano_guard_set_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_GUARD_SET_H
+ vendor/include/cardano/common/network_id.h view
@@ -0,0 +1,53 @@+/**+ * \file network_id.h+ *+ * \author angel.castillo+ * \date   Apr 12, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_NETWORK_ID_H+#define BIGLUP_LABS_INCLUDE_CARDANO_NETWORK_ID_H++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Defines the network identifiers used within the Cardano ecosystem.+ *+ * This enumeration is used to specify the network for which a Cardano transaction or operation is intended.+ */+typedef enum+{+  /**+   * \brief Represents the test network (testnet).+   */+  CARDANO_NETWORK_ID_TEST_NET = 0,++  /**+   * \brief Represents the main network (mainnet).+   */+  CARDANO_NETWORK_ID_MAIN_NET = 1+} cardano_network_id_t;++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_NETWORK_ID_H
+ vendor/include/cardano/common/network_magic.h view
@@ -0,0 +1,92 @@+/**+ * \file network_magic.h+ *+ * \author angel.castillo+ * \date   Sep 28, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_NETWORK_MAGIC_H+#define BIGLUP_LABS_INCLUDE_CARDANO_NETWORK_MAGIC_H++/* INCLUDES ******************************************************************/++#include <cardano/export.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Enumerates the available Cardano network environments.+ *+ * This enumeration defines the different network environments that can be used+ * with the Cardano provider.+ */+typedef enum+{+  /**+   * \brief The Pre-Production test network.+   *+   * The Pre-Production network is a Cardano testnet used for testing features+   * before they are deployed to the Mainnet. It closely mirrors the Mainnet+   * environment, providing a final testing ground for applications.+   */+  CARDANO_NETWORK_MAGIC_PREPROD = 1,++  /**+   * \brief The Preview test network.+   *+   * The Preview network is a Cardano testnet used for testing upcoming features+   * before they are released to the Pre-Production network. It allows developers+   * to experiment with new functionalities in a controlled environment.+   */+  CARDANO_NETWORK_MAGIC_PREVIEW = 2,++  /**+   * \brief The SanchoNet test network.+   *+   * SanchoNet is the testnet for rolling out governance features for the Cardano blockchain,+   * aligning with the comprehensive CIP-1694 specifications.+   */+  CARDANO_NETWORK_MAGIC_SANCHONET = 4,++  /**+   * \brief The Mainnet network.+   *+   * The Mainnet is the live Cardano network where real transactions occur.+   * Applications interacting with the Mainnet are dealing with actual ADA and+   * other assets. Caution should be exercised to ensure correctness and security.+   */+  CARDANO_NETWORK_MAGIC_MAINNET = 764824073,+} cardano_network_magic_t;++/**+ * \brief Converts network magics to their human readable form.+ *+ * \param[in] magic The network magic to get the string representation for.+ * \return Human readable form of the given network magic.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_network_magic_to_string(cardano_network_magic_t magic);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_NETWORK_MAGIC_H
+ vendor/include/cardano/common/protocol_version.h view
@@ -0,0 +1,464 @@+/**+ * \file protocol_version.h+ *+ * \author angel.castillo+ * \date   Mar 07, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_PROTOCOL_VERSION_H+#define BIGLUP_LABS_INCLUDE_CARDANO_PROTOCOL_VERSION_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief The protocol can be thought of as the set of rules that nodes in the network agree to follow,+ *  and this versioning system helps nodes to keep track of which set of rules they are adhering to and also+ *  allows for the decentralized updating of the protocol parameters without requiring a hard fork.+ */+typedef struct cardano_protocol_version_t cardano_protocol_version_t;++/**+ * \brief Creates and initializes a new instance of the Protocol Version.+ *+ * This function allocates and initializes a new instance of the Protocol Version,+ * representing a version of the Cardano protocol.+ *+ * \param[in] major The major version number, indicating significant alterations to the protocol+ *                  that are not backward compatible. Nodes would need to upgrade to continue+ *                  participating in the network.+ * \param[in] minor The minor version number, reflecting backward-compatible changes.+ * \param[out] protocol_version On successful initialization, this will point to a newly created+ *            Protocol Version object. This object represents a "strong reference",+ *            meaning that it is fully initialized and ready for use.+ *            The caller is responsible for managing the lifecycle of this object.+ *            Specifically, once the Protocol Version is no longer needed, the caller must release it+ *            by calling \ref cardano_protocol_version_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the Protocol Version was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_protocol_version_t* protocol_version = NULL;+ * uint64_t major = 1; // Major version 1+ * uint64_t minor = 0; // Minor version 0+ *+ * // Attempt to create a new Protocol Version object+ * cardano_error_t result = cardano_protocol_version_new(major, minor, &protocol_version);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the protocol_version+ *+ *   // Once done, ensure to clean up and release the protocol_version+ *   cardano_protocol_version_unref(&protocol_version);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_protocol_version_new(+  uint64_t                     major,+  uint64_t                     minor,+  cardano_protocol_version_t** protocol_version);++/**+ * \brief Creates a \ref cardano_protocol_version_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_protocol_version_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a protocol_version.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] protocol_version A pointer to a pointer of \ref cardano_protocol_version_t that will be set to the address+ *                        of the newly created protocol_version object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the protocol version were successfully created, or an appropriate error code if an error occurred.+ *+ * \remark The minor version is bounded to the uint32 range (0 to 4294967295); the function returns+ *         \ref CARDANO_ERROR_INVALID_CBOR_VALUE for larger values.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_protocol_version_t object by calling+ *       \ref cardano_protocol_version_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_protocol_version_t* protocol_version = NULL;+ *+ * cardano_error_t result = cardano_protocol_version_from_cbor(reader, &protocol_version);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the protocol_version+ *+ *   // Once done, ensure to clean up and release the protocol_version+ *   cardano_protocol_version_unref(&protocol_version);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode protocol_version: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_protocol_version_from_cbor(cardano_cbor_reader_t* reader, cardano_protocol_version_t** protocol_version);++/**+ * \brief Serializes protocol version into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_protocol_version_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] protocol_version A constant pointer to the \ref cardano_protocol_version_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p protocol_version or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_protocol_version_t* protocol_version = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_protocol_version_to_cbor(protocol_version, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_protocol_version_unref(&protocol_version);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_protocol_version_to_cbor(+  const cardano_protocol_version_t* protocol_version,+  cardano_cbor_writer_t*            writer);++/**+ * \brief Serializes a protocol version to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "major", "minor".+ *+ * \param[in]  version Pointer to a valid \ref cardano_protocol_version_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p version or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_protocol_version_to_cip116_json(+  const cardano_protocol_version_t* version,+  cardano_json_writer_t*            writer);++/**+ * \brief Retrieves the major version number of the Protocol Version.+ *+ * This function returns the major version number of the Protocol Version,+ *+ * \param[in] protocol_version Pointer to the Protocol Version object.+ *+ * \return The major version number of the Protocol Version.+ *+ * Usage Example:+ * \code{.c}+ * cardano_protocol_version_t* protocol_version = NULL;+ * // Assume protocol_version is initialized properly+ *+ * uint64_t major_version = cardano_protocol_version_get_major(protocol_version);+ * printf("Major Version: %lu\n", major_version);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_protocol_version_get_major(+  const cardano_protocol_version_t* protocol_version);++/**+ * \brief Sets the major version number of the Protocol Version.+ *+ * This function sets the major version number of the Protocol Version,+ *+ * \param[in] protocol_version Pointer to the Protocol Version object.+ * \param[in] major The major version number to set.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the major version number was successfully set, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_protocol_version_t* protocol_version = NULL;+ * // Assume protocol_version is initialized properly+ *+ * cardano_error_t result = cardano_protocol_version_set_major(protocol_version, 2);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Major version set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set major version: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_protocol_version_set_major(+  cardano_protocol_version_t* protocol_version,+  uint64_t                    major);++/**+ * \brief Retrieves the minor version number of the Protocol Version.+ *+ * This function returns the minor version number of the Protocol Version.+ *+ * \param[in] protocol_version Pointer to the Protocol Version object.+ *+ * \return The minor version number of the Protocol Version.+ *+ * Usage Example:+ * \code{.c}+ * cardano_protocol_version_t* protocol_version = NULL;+ * // Assume protocol_version is initialized properly+ *+ * uint64_t minor_version = cardano_protocol_version_get_minor(protocol_version);+ * printf("Minor Version: %lu\n", minor_version);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_protocol_version_get_minor(const cardano_protocol_version_t* protocol_version);++/**+ * \brief Sets the minor version number of the Protocol Version.+ *+ * This function sets the minor version number of the Protocol Version.+ *+ * \param[in] protocol_version Pointer to the Protocol Version object.+ * \param[in] minor The minor version number to set. It must be in the uint32 range (0 to 4294967295).+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the minor version number was successfully set, \ref CARDANO_ERROR_INVALID_ARGUMENT if+ *         \p minor is greater than the maximum uint32 value, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_protocol_version_t* protocol_version = NULL;+ * // Assume protocol_version is initialized properly+ *+ * cardano_error_t result = cardano_protocol_version_set_minor(protocol_version, 1);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Minor version set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set minor version: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_protocol_version_set_minor(+  cardano_protocol_version_t* protocol_version,+  uint64_t                    minor);++/**+ * \brief Decrements the reference count of a cardano_protocol_version_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_protocol_version_t object+ * by decreasing its reference count. When the reference count reaches zero, the protocol_version is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] protocol_version A pointer to the pointer of the protocol_version object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_protocol_version_t* protocol_version = cardano_protocol_version_new(major, minor);+ *+ * // Perform operations with the protocol_version...+ *+ * cardano_protocol_version_unref(&protocol_version);+ * // At this point, protocol_version is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_protocol_version_unref, the pointer to the \ref cardano_protocol_version_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_protocol_version_unref(cardano_protocol_version_t** protocol_version);++/**+ * \brief Increases the reference count of the cardano_protocol_version_t object.+ *+ * This function is used to manually increment the reference count of an cardano_protocol_version_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_protocol_version_unref.+ *+ * \param protocol_version A pointer to the cardano_protocol_version_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming protocol_version is a previously created protocol_version object+ *+ * cardano_protocol_version_ref(protocol_version);+ *+ * // Now protocol_version can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_protocol_version_ref there is a corresponding+ * call to \ref cardano_protocol_version_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_protocol_version_ref(cardano_protocol_version_t* protocol_version);++/**+ * \brief Retrieves the current reference count of the cardano_protocol_version_t object.+ *+ * This function returns the number of active references to an cardano_protocol_version_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_protocol_version_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param protocol_version A pointer to the cardano_protocol_version_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_protocol_version_t object. If the object+ * is properly managed (i.e., every \ref cardano_protocol_version_ref call is matched with a+ * \ref cardano_protocol_version_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming protocol_version is a previously created protocol_version object+ *+ * size_t ref_count = cardano_protocol_version_refcount(protocol_version);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_protocol_version_refcount(const cardano_protocol_version_t* protocol_version);++/**+ * \brief Sets the last error message for a given cardano_protocol_version_t object.+ *+ * Records an error message in the protocol_version's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] protocol_version A pointer to the \ref cardano_protocol_version_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the protocol_version's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_protocol_version_set_last_error(+  cardano_protocol_version_t* protocol_version,+  const char*                 message);++/**+ * \brief Retrieves the last error message recorded for a specific protocol_version.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_protocol_version_set_last_error for the given+ * protocol_version. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] protocol_version A pointer to the \ref cardano_protocol_version_t instance whose last error+ *                   message is to be retrieved. If the protocol_version is NULL, the function+ *                   returns a generic error message indicating the null protocol_version.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified protocol_version. If the protocol_version is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_protocol_version_set_last_error for the same protocol_version, or until+ *       the protocol_version is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_protocol_version_get_last_error(+  const cardano_protocol_version_t* protocol_version);++/**+ * \brief Creates an independent deep copy of a \ref cardano_protocol_version_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_protocol_version_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_protocol_version_deep_clone(const cardano_protocol_version_t* source, cardano_protocol_version_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_PROTOCOL_VERSION_H
+ vendor/include/cardano/common/reward_address_list.h view
@@ -0,0 +1,336 @@+/**+ * \file reward_address_list.h+ *+ * \author angel.castillo+ * \date   Aug 08, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_REWARD_ADDRESS_LIST_H+#define BIGLUP_LABS_INCLUDE_CARDANO_REWARD_ADDRESS_LIST_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a reward address in the Cardano blockchain ecosystem.+ *+ * A reward address is a cryptographic hash of the public stake key of the address. Reward account addresses are used+ * to distribute rewards for participating in the proof-of-stake protocol (either directly or via delegation).+ */+typedef struct cardano_reward_address_t cardano_reward_address_t;++/**+ * \brief Represents a list of reward address.+ */+typedef struct cardano_reward_address_list_t cardano_reward_address_list_t;++/**+ * \brief Creates and initializes a new instance of a reward_address_list.+ *+ * This function allocates and initializes a new instance of \ref cardano_reward_address_list_t.+ * It returns an error code to indicate success or failure of the operation.+ *+ * \param[out] reward_address_list On successful initialization, this will point to a newly created+ *             \ref cardano_reward_address_list_t object. This object represents a "strong reference"+ *             to the reward_address_list, meaning that it is fully initialized and ready for use.+ *             The caller is responsible for managing the lifecycle of this object.+ *             Specifically, once the reward_address_list is no longer needed, the caller must release it+ *             by calling \ref cardano_reward_address_list_unref.+ *+ * \return \ref CARDANO_SUCCESS if the reward_address_list was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_list_t* reward_address_list = NULL;+ *+ * // Attempt to create a new reward_address_list+ * cardano_error_t result = cardano_reward_address_list_new(&reward_address_list);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the reward_address_list+ *+ *   // Once done, ensure to clean up and release the reward_address_list+ *   cardano_reward_address_list_unref(&reward_address_list);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_reward_address_list_new(cardano_reward_address_list_t** reward_address_list);++/**+ * \brief Retrieves the length of a reward address list.+ *+ * This function retrieves the number of elements in the provided \ref cardano_reward_address_list_t object.+ *+ * \param[in] reward_address_list A constant pointer to the \ref cardano_reward_address_list_t object whose length is to be retrieved.+ *+ * \return The number of elements in the reward_address_list. Return 0 if the reward_address_list is NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_list_t* reward_address_list = cardano_reward_address_list_new();+ *+ * // Populate reward_address_list with elements+ *+ * size_t length = cardano_reward_address_list_get_length(reward_address_list);+ * printf("Length of the reward_address_list: %zu\n", length);+ *+ * // Clean up the reward_address_list object once done+ * cardano_reward_address_list_unref(&reward_address_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_reward_address_list_get_length(const cardano_reward_address_list_t* reward_address_list);++/**+ * \brief Retrieves an element from a reward address list by index.+ *+ * This function retrieves the element at the specified index from the provided \ref cardano_reward_address_list_t object+ * and stores it in the output parameter.+ *+ * \param[in] reward_address_list A constant pointer to the \ref cardano_reward_address_list_t object from which+ *                        the element is to be retrieved.+ * \param[in] index The index of the element to retrieve from the reward address list. Indexing starts at 0.+ * \param[out] element Pointer to a variable where the retrieved element will be stored.+ *                     This variable will point to the retrieved \ref cardano_reward_address_t object.+ *                     The caller is responsible for managing the lifecycle of the element by calling+ *                     \ref cardano_reward_address_unref when it is no longer needed.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully retrieved, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_list_t* reward_address_list = cardano_reward_address_list_new();+ *+ * // Populate reward_address_list with elements+ *+ * cardano_reward_address_t* element = NULL;+ * cardano_error_t result = cardano_reward_address_list_get(reward_address_list, 2, &element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the retrieved element+ *   // Remember to unreference the element once done if it's no longer needed+ *   cardano_reward_address_unref(&element);+ * }+ *+ * // Clean up the reward_address_list object once done+ * cardano_reward_address_list_unref(&reward_address_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_reward_address_list_get(const cardano_reward_address_list_t* reward_address_list, size_t index, cardano_reward_address_t** element);++/**+ * \brief Adds an element to a reward address list.+ *+ * This function adds the specified element to the end of the provided \ref cardano_reward_address_list_t object.+ *+ * \param[in] reward_address_list A constant pointer to the \ref cardano_reward_address_list_t object to which+ *                        the element is to be added.+ * \param[in] element Pointer to the \ref cardano_reward_address_t object that is to be added to the reward_address_list.+ *                    The element will be referenced by the reward_address_list after addition.+ *+ * \return \ref CARDANO_SUCCESS if the element was successfully added to the reward_address_list, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_list_t* reward_address_list = cardano_reward_address_list_new();+ *+ * // Create and initialize a new reward address element+ * cardano_reward_address_t* element = { ... };+ *+ * // Add the element to the reward_address_list+ * cardano_error_t result = cardano_reward_address_list_add(reward_address_list, element);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Element added successfully+ * }+ *+ * // Clean up the reward_address_list object once done+ * cardano_reward_address_list_unref(&reward_address_list);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_reward_address_list_add(cardano_reward_address_list_t* reward_address_list, cardano_reward_address_t* element);++/**+ * \brief Decrements the reference count of a reward_address_list object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_reward_address_list_t object+ * by decreasing its reference count. When the reference count reaches zero, the reward_address_list is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] reward_address_list A pointer to the pointer of the reward_address_list object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_reward_address_list_t* reward_address_list = cardano_reward_address_list_new();+ *+ * // Perform operations with the reward_address_list...+ *+ * cardano_reward_address_list_unref(&reward_address_list);+ * // At this point, reward_address_list is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_reward_address_list_unref, the pointer to the \ref cardano_reward_address_list_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_reward_address_list_unref(cardano_reward_address_list_t** reward_address_list);++/**+ * \brief Increases the reference count of the cardano_reward_address_list_t object.+ *+ * This function is used to manually increment the reference count of a reward_address_list+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_reward_address_list_unref.+ *+ * \param reward_address_list A pointer to the reward_address_list object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming reward_address_list is a previously created reward_address_list object+ *+ * cardano_reward_address_list_ref(reward_address_list);+ *+ * // Now reward_address_list can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_reward_address_list_ref there is a corresponding+ * call to \ref cardano_reward_address_list_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_reward_address_list_ref(cardano_reward_address_list_t* reward_address_list);++/**+ * \brief Retrieves the current reference count of the cardano_reward_address_list_t object.+ *+ * This function returns the number of active references to a reward_address_list object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_reward_address_list_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param reward_address_list A pointer to the reward_address_list object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified reward_address_list object. If the object+ * is properly managed (i.e., every \ref cardano_reward_address_list_ref call is matched with a+ * \ref cardano_reward_address_list_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming reward_address_list is a previously created reward_address_list object+ *+ * size_t ref_count = cardano_reward_address_list_refcount(reward_address_list);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_reward_address_list_refcount(const cardano_reward_address_list_t* reward_address_list);++/**+ * \brief Sets the last error message for a given reward_address_list object.+ *+ * Records an error message in the reward_address_list's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] reward_address_list A pointer to the \ref cardano_reward_address_list_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the reward_address_list's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_reward_address_list_set_last_error(cardano_reward_address_list_t* reward_address_list, const char* message);++/**+ * \brief Retrieves the last error message recorded for a specific reward_address_list.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_reward_address_list_set_last_error for the given+ * reward_address_list. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] reward_address_list A pointer to the \ref cardano_reward_address_list_t instance whose last error+ *                   message is to be retrieved. If the reward_address_list is NULL, the function+ *                   returns a generic error message indicating the null reward_address_list.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified reward_address_list. If the reward_address_list is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_reward_address_list_set_last_error for the same reward_address_list, or until+ *       the reward_address_list is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_reward_address_list_get_last_error(const cardano_reward_address_list_t* reward_address_list);++/**+ * \brief Creates an independent deep copy of a \ref cardano_reward_address_list_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_reward_address_list_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_reward_address_list_deep_clone(const cardano_reward_address_list_t* source, cardano_reward_address_list_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_REWARD_ADDRESS_LIST_H
+ vendor/include/cardano/common/unit_interval.h view
@@ -0,0 +1,529 @@+/**+ * \file unit_interval.h+ *+ * \author angel.castillo+ * \date   Mar 07, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_UNIT_INTERVAL_H+#define BIGLUP_LABS_INCLUDE_CARDANO_UNIT_INTERVAL_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/json/json_writer.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a rational number as a ratio of two integers.+ *+ * Unit intervals are serialized as Rational Numbers (Tag 30).+ * Rational numbers are numbers that can be expressed as a ratio of two integers:+ * a numerator, written as the top part of a fraction, and the denominator,+ * the bottom part. The value of a rational number is the numerator divided by the denominator.+ */+typedef struct cardano_unit_interval_t cardano_unit_interval_t;++/**+ * \brief Creates and initializes a new instance of a unit interval.+ *+ * This function allocates and initializes a new instance of a unit interval,+ * representing a rational number where the numerator and denominator are both+ * unsigned 64-bit integers. Unit intervals are serialized as Rational Numbers (Tag 30).+ * Rational numbers are numbers that can be expressed as a ratio of two integers:+ * a numerator, usually written as the top part of a fraction, and the denominator,+ * the bottom part. The value of a rational number is the numerator divided by the denominator.+ *+ * \param[in] numerator The numerator of the unit interval.+ * \param[in] denominator The denominator of the unit interval.+ * \param[out] unit_interval On successful initialization, this will point to a newly created+ *            unit interval object. This object represents a "strong reference",+ *            meaning that it is fully initialized and ready for use.+ *            The caller is responsible for managing the lifecycle of this object.+ *            Specifically, once the unit interval is no longer needed, the caller must release it+ *            by calling \ref cardano_unit_interval_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the unit interval was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unit_interval_t* unit_interval = NULL;+ * uint64_t numerator = 3;+ * uint64_t denominator = 4;+ *+ * // Attempt to create a new unit interval object+ * cardano_error_t result = cardano_unit_interval_new(numerator, denominator, &unit_interval);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the unit_interval+ *+ *   // Once done, ensure to clean up and release the unit_interval+ *   cardano_unit_interval_unref(&unit_interval);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unit_interval_new(+  uint64_t                  numerator,+  uint64_t                  denominator,+  cardano_unit_interval_t** unit_interval);++/**+ * \brief Creates and initializes a new instance of a unit interval from a floating-point value.+ *+ * This function creates a new instance of a unit interval from a floating-point value,+ * representing a rational number. The floating-point value is converted into a fraction+ * where the numerator and denominator are both unsigned 64-bit integers.+ *+ * \param[in] value The floating-point value from which to create the unit interval.+ * \param[out] unit_interval On successful initialization, this will point to a newly created+ *            unit interval object. This object represents a "strong reference",+ *            meaning that it is fully initialized and ready for use.+ *            The caller is responsible for managing the lifecycle of this object.+ *            Specifically, once the unit interval is no longer needed, the caller must release it+ *            by calling \ref cardano_unit_interval_unref.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the unit interval was successfully created, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unit_interval_t* unit_interval = NULL;+ * double value = 0.25; // Example floating-point value+ *+ * // Attempt to create a new unit interval object from the floating-point value+ * cardano_error_t result = cardano_unit_interval_from_double(value, &unit_interval);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the unit_interval+ *+ *   // Once done, ensure to clean up and release the unit_interval+ *   cardano_unit_interval_unref(&unit_interval);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unit_interval_from_double(double value, cardano_unit_interval_t** unit_interval);++/**+ * \brief Creates a \ref cardano_unit_interval_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_unit_interval_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a unit_interval.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] unit_interval A pointer to a pointer of \ref cardano_unit_interval_t that will be set to the address+ *                        of the newly created unit_interval object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the object was successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_unit_interval_t object by calling+ *       \ref cardano_unit_interval_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_unit_interval_t* unit_interval = NULL;+ *+ * cardano_error_t result = cardano_unit_interval_from_cbor(reader, &unit_interval);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the unit_interval+ *+ *   // Once done, ensure to clean up and release the unit_interval+ *   cardano_unit_interval_unref(&unit_interval);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode unit_interval: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unit_interval_from_cbor(cardano_cbor_reader_t* reader, cardano_unit_interval_t** unit_interval);++/**+ * \brief Serializes protocol version into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_unit_interval_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] unit_interval A constant pointer to the \ref cardano_unit_interval_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p unit_interval or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unit_interval_t* unit_interval = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_unit_interval_to_cbor(unit_interval, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_unit_interval_unref(&unit_interval);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_unit_interval_to_cbor(+  const cardano_unit_interval_t* unit_interval,+  cardano_cbor_writer_t*         writer);++/**+ * \brief Serializes a unit interval to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "numerator", "denominator".+ * Both values are encoded as strings to ensure precision for 64-bit integers in JSON.+ *+ * \param[in]  interval Pointer to a valid \ref cardano_unit_interval_t.+ * \param[in]  writer   Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p interval or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_unit_interval_to_cip116_json(+  const cardano_unit_interval_t* interval,+  cardano_json_writer_t*         writer);++/**+ * \brief Retrieves the numerator of the Unit Interval.+ *+ * This function returns the numerator of the Unit Interval,+ *+ * \param[in] unit_interval Pointer to the Unit Interval object.+ *+ * \return The numerator of the Unit Interval.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unit_interval_t* unit_interval = NULL;+ * // Assume unit_interval is initialized properly+ *+ * uint64_t numerator_version = cardano_unit_interval_get_numerator(unit_interval);+ * printf("Major Version: %lu\n", numerator_version);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_unit_interval_get_numerator(+  const cardano_unit_interval_t* unit_interval);++/**+ * \brief Sets the numerator of the Unit Interval.+ *+ * This function sets the numerator of the Unit Interval,+ *+ * \param[in] unit_interval Pointer to the Unit Interval object.+ * \param[in] numerator The numerator to set.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the numerator was successfully set, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unit_interval_t* unit_interval = NULL;+ * // Assume unit_interval is initialized properly+ *+ * cardano_error_t result = cardano_unit_interval_set_numerator(unit_interval, 2);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Major version set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set numerator version: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_unit_interval_set_numerator(+  cardano_unit_interval_t* unit_interval,+  uint64_t                 numerator);++/**+ * \brief Retrieves the denominator of the Unit Interval.+ *+ * This function returns the denominator of the Unit Interval.+ *+ * \param[in] unit_interval Pointer to the Unit Interval object.+ *+ * \return The denominator of the Unit Interval.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unit_interval_t* unit_interval = NULL;+ * // Assume unit_interval is initialized properly+ *+ * uint64_t denominator_version = cardano_unit_interval_get_denominator(unit_interval);+ * printf("Minor Version: %lu\n", denominator_version);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT uint64_t cardano_unit_interval_get_denominator(const cardano_unit_interval_t* unit_interval);++/**+ * \brief Converts a unit interval to a double-precision floating-point value.+ *+ * This function converts a unit interval, representing a rational number, to a+ * double-precision floating-point value. The rational number is converted into+ * a floating-point representation, providing a decimal approximation of the value.+ *+ * \param[in] unit_interval Pointer to the unit interval object to be converted.+ *+ * \return The double-precision floating-point value representing the unit interval.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unit_interval_t* unit_interval = NULL;+ * // Assume unit_interval is initialized properly+ *+ * double result = cardano_unit_interval_to_double(unit_interval);+ * printf("Result: %f\n", result);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT double cardano_unit_interval_to_double(const cardano_unit_interval_t* unit_interval);++/**+ * \brief Sets the denominator of the Unit Interval.+ *+ * This function sets the denominator of the Unit Interval.+ *+ * \param[in] unit_interval Pointer to the Unit Interval object.+ * \param[in] denominator The denominator to set.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the denominator was successfully set, or an appropriate error code+ *         indicating the failure reason.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unit_interval_t* unit_interval = NULL;+ * // Assume unit_interval is initialized properly+ *+ * cardano_error_t result = cardano_unit_interval_set_denominator(unit_interval, 1);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Minor version set successfully.\n");+ * }+ * else+ * {+ *   printf("Failed to set denominator version: %d\n", result);+ * }+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_unit_interval_set_denominator(+  cardano_unit_interval_t* unit_interval,+  uint64_t                 denominator);++/**+ * \brief Decrements the reference count of a cardano_unit_interval_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_unit_interval_t object+ * by decreasing its reference count. When the reference count reaches zero, the unit_interval is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] unit_interval A pointer to the pointer of the unit_interval object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_unit_interval_t* unit_interval = cardano_unit_interval_new(numerator, denominator);+ *+ * // Perform operations with the unit_interval...+ *+ * cardano_unit_interval_unref(&unit_interval);+ * // At this point, unit_interval is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_unit_interval_unref, the pointer to the \ref cardano_unit_interval_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_unit_interval_unref(cardano_unit_interval_t** unit_interval);++/**+ * \brief Increases the reference count of the cardano_unit_interval_t object.+ *+ * This function is used to manually increment the reference count of an cardano_unit_interval_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_unit_interval_unref.+ *+ * \param unit_interval A pointer to the cardano_unit_interval_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming unit_interval is a previously created unit_interval object+ *+ * cardano_unit_interval_ref(unit_interval);+ *+ * // Now unit_interval can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_unit_interval_ref there is a corresponding+ * call to \ref cardano_unit_interval_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_unit_interval_ref(cardano_unit_interval_t* unit_interval);++/**+ * \brief Retrieves the current reference count of the cardano_unit_interval_t object.+ *+ * This function returns the number of active references to an cardano_unit_interval_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_unit_interval_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param unit_interval A pointer to the cardano_unit_interval_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_unit_interval_t object. If the object+ * is properly managed (i.e., every \ref cardano_unit_interval_ref call is matched with a+ * \ref cardano_unit_interval_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming unit_interval is a previously created unit_interval object+ *+ * size_t ref_count = cardano_unit_interval_refcount(unit_interval);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_unit_interval_refcount(const cardano_unit_interval_t* unit_interval);++/**+ * \brief Sets the last error message for a given cardano_unit_interval_t object.+ *+ * Records an error message in the unit_interval's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] unit_interval A pointer to the \ref cardano_unit_interval_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the unit_interval's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_unit_interval_set_last_error(+  cardano_unit_interval_t* unit_interval,+  const char*              message);++/**+ * \brief Retrieves the last error message recorded for a specific unit_interval.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_unit_interval_set_last_error for the given+ * unit_interval. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] unit_interval A pointer to the \ref cardano_unit_interval_t instance whose last error+ *                   message is to be retrieved. If the unit_interval is NULL, the function+ *                   returns a generic error message indicating the null unit_interval.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified unit_interval. If the unit_interval is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_unit_interval_set_last_error for the same unit_interval, or until+ *       the unit_interval is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_unit_interval_get_last_error(+  const cardano_unit_interval_t* unit_interval);++/**+ * \brief Creates an independent deep copy of a \ref cardano_unit_interval_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_unit_interval_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_unit_interval_deep_clone(const cardano_unit_interval_t* source, cardano_unit_interval_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_UNIT_INTERVAL_H
+ vendor/include/cardano/common/utxo.h view
@@ -0,0 +1,558 @@+/**+ * \file utxo.h+ *+ * \author angel.castillo+ * \date   Sep 23, 2024+ *+ * Copyright 2024 Biglup Labs+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ *     www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#ifndef BIGLUP_LABS_INCLUDE_CARDANO_UTXO_H+#define BIGLUP_LABS_INCLUDE_CARDANO_UTXO_H++/* INCLUDES ******************************************************************/++#include <cardano/cbor/cbor_reader.h>+#include <cardano/cbor/cbor_writer.h>+#include <cardano/error.h>+#include <cardano/export.h>+#include <cardano/transaction_body/transaction_input.h>+#include <cardano/transaction_body/transaction_output.h>+#include <cardano/typedefs.h>++/* DECLARATIONS **************************************************************/++#ifdef __cplusplus+extern "C" {+#endif /* __cplusplus */++/**+ * \brief Represents a unspent output (UTxO).+ */+typedef struct cardano_utxo_t cardano_utxo_t;++/**+ * \brief Creates a new UTXO (Unspent Transaction Output) object.+ *+ * This function creates and initializes a new \ref cardano_utxo_t object by associating a+ * transaction input with its corresponding transaction output. UTXOs represent unspent+ * outputs from previous transactions that can be used as inputs in new transactions.+ *+ * \param[in] input A pointer to an initialized \ref cardano_transaction_input_t object,+ *                  representing the transaction input. This parameter must not be NULL.+ * \param[in] output A pointer to an initialized \ref cardano_transaction_output_t object,+ *                   representing the corresponding transaction output. This parameter must not be NULL.+ * \param[out] utxo A double pointer to a \ref cardano_utxo_t object. On successful creation,+ *                  this will point to the newly created UTXO object. The caller is responsible+ *                  for managing the lifecycle of this object and must release it by calling+ *                  \ref cardano_utxo_unref when it is no longer needed.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the UTXO was successfully created. If either \p input, \p output, or \p utxo is NULL,+ *         returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * \note A UTXO links a specific input to its corresponding output, representing spendable value+ *       in the Cardano blockchain. The newly created UTXO object must be properly freed by the+ *       caller using \ref cardano_utxo_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_transaction_input_t* input = ...;  // Assume input is initialized+ * cardano_transaction_output_t* output = ...;  // Assume output is initialized+ * cardano_utxo_t* utxo = NULL;+ *+ * cardano_error_t result = cardano_utxo_new(input, output, &utxo);+ * if (result == CARDANO_SUCCESS)+ * {+ *   // UTXO successfully created, use utxo as needed+ *+ *   // Clean up when done+ *   cardano_utxo_unref(&utxo);+ * }+ * else+ * {+ *   printf("Failed to create UTXO: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up input and output when no longer needed+ * cardano_transaction_input_unref(&input);+ * cardano_transaction_output_unref(&output);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_utxo_new(+  cardano_transaction_input_t*  input,+  cardano_transaction_output_t* output,+  cardano_utxo_t**              utxo);++/**+ * \brief Creates a \ref cardano_utxo_t from a CBOR reader.+ *+ * This function parses CBOR data using a provided \ref cardano_cbor_reader_t and constructs a \ref cardano_utxo_t object.+ * It assumes that the CBOR reader is set up correctly and that the CBOR data corresponds to the structure expected for a utxo.+ *+ * \param[in] reader A pointer to an initialized \ref cardano_cbor_reader_t that is ready to read the CBOR-encoded data.+ * \param[out] utxo A pointer to a pointer of \ref cardano_utxo_t that will be set to the address+ *                        of the newly created utxo object upon successful decoding.+ *+ * \return A \ref cardano_error_t value indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the utxo were successfully created, or an appropriate error code if an error occurred.+ *+ * \note If the function fails, the last error can be retrieved by calling \ref cardano_cbor_reader_get_last_error with the reader.+ *       The caller is responsible for freeing the created \ref cardano_utxo_t object by calling+ *       \ref cardano_utxo_unref when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_cbor_reader_t* reader = cardano_cbor_reader_new(cbor_data, data_size);+ * cardano_utxo_t* utxo = NULL;+ *+ * cardano_error_t result = cardano_utxo_from_cbor(reader, &utxo);+ *+ * if (result == CARDANO_SUCCESS)+ * {+ *   // Use the utxo+ *+ *   // Once done, ensure to clean up and release the utxo+ *   cardano_utxo_unref(&utxo);+ * }+ * else+ * {+ *   const char* error = cardano_cbor_reader_get_last_error(reader);+ *   printf("Failed to decode utxo: %s\n", error);+ * }+ *+ * cardano_cbor_reader_unref(&reader); // Cleanup the CBOR reader+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_utxo_from_cbor(cardano_cbor_reader_t* reader, cardano_utxo_t** utxo);++/**+ * \brief Serializes utxo into CBOR format using a CBOR writer.+ *+ * This function serializes the given \ref cardano_utxo_t object using a \ref cardano_cbor_writer_t.+ *+ * \param[in] utxo A constant pointer to the \ref cardano_utxo_t object that is to be serialized.+ * \param[out] writer A pointer to a \ref cardano_cbor_writer_t where the CBOR serialized data will be written.+ *                    The writer must already be initialized and ready to accept the data.+ *+ * \return Returns \ref CARDANO_SUCCESS if the serialization is successful. If the \p utxo or \p writer+ *         is NULL, returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * Usage Example:+ * \code{.c}+ * cardano_utxo_t* utxo = ...;+ * cardano_cbor_writer_t* writer = cardano_cbor_writer_new();+ *+ * if (writer)+ * {+ *   cardano_error_t result = cardano_utxo_to_cbor(utxo, writer);+ *+ *   if (result == CARDANO_SUCCESS)+ *   {+ *     // Use the writer's buffer containing the serialized data+ *   }+ *   else+ *   {+ *     const char* error_message = cardano_cbor_writer_get_last_error(writer);+ *     printf("Serialization failed: %s\n", error_message);+ *   }+ *+ *   cardano_cbor_writer_unref(&writer);+ * }+ *+ * cardano_utxo_unref(&utxo);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_utxo_to_cbor(+  const cardano_utxo_t*  utxo,+  cardano_cbor_writer_t* writer);++/**+ * \brief Serializes a transaction unspent output (UTXO) to CIP-116 JSON.+ *+ * The function writes the full JSON object, including the surrounding braces.+ * Keys are written in the order: "input", "output".+ *+ * \param[in]  utxo    Pointer to a valid \ref cardano_utxo_t.+ * \param[in]  writer  Pointer to a valid \ref cardano_json_writer_t.+ *+ * \return CARDANO_SUCCESS       On success.+ * CARDANO_ERROR_POINTER_IS_NULL If \p utxo or \p writer is NULL.+ * Other                         Any error propagated from nested writers.+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t cardano_utxo_to_cip116_json(+  const cardano_utxo_t*  utxo,+  cardano_json_writer_t* writer);++/**+ * \brief Retrieves the transaction input from a UTXO.+ *+ * This function fetches the transaction input associated with a given \ref cardano_utxo_t object.+ * The transaction input represents the source of the UTXO, which can be used as an input in a new transaction.+ *+ * \param[in] utxo A pointer to an initialized \ref cardano_utxo_t object. This parameter must not be NULL.+ *+ * \return A pointer to a \ref cardano_transaction_input_t object representing the transaction input of the UTXO.+ *         The returned object is a new reference, and the caller is responsible for managing its lifecycle.+ *         Specifically, the caller must release the object by calling \ref cardano_transaction_input_unref+ *         when it is no longer needed. If the \p utxo is NULL, the function returns NULL.+ *+ * \note The transaction input refers to the previous transaction from which the UTXO originates,+ *       representing a spendable output.+ *+ * Usage Example:+ * \code{.c}+ * cardano_utxo_t* utxo = ...; // Assume utxo is already initialized+ * cardano_transaction_input_t* input = cardano_utxo_get_input(utxo);+ *+ * if (input != NULL)+ * {+ *   // Use the transaction input as needed+ *+ *   // Clean up when done+ *   cardano_transaction_input_unref(&input);+ * }+ * else+ * {+ *   printf("Failed to retrieve the transaction input.\n");+ * }+ *+ * // Clean up the utxo when no longer needed+ * cardano_utxo_unref(&utxo);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_transaction_input_t* cardano_utxo_get_input(cardano_utxo_t* utxo);++/**+ * \brief Sets the transaction input for a UTXO.+ *+ * This function assigns a transaction input to the specified \ref cardano_utxo_t object. The transaction input+ * represents the source of the UTXO, which can be used as an input in a new transaction.+ *+ * \param[in,out] utxo A pointer to an initialized \ref cardano_utxo_t object where the input will be set.+ *                     This parameter must not be NULL.+ * \param[in] input A pointer to an initialized \ref cardano_transaction_input_t object representing the input+ *                  to be associated with the UTXO. This parameter must not be NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the transaction input was successfully set. If either \p utxo or \p input is NULL, returns+ *         \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * \note This function increases the reference count of the \p input object, meaning the caller retains+ *       ownership of the input and must release it by calling \ref cardano_transaction_input_unref+ *       when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_utxo_t* utxo = ...; // Assume utxo is initialized+ * cardano_transaction_input_t* input = ...; // Assume input is initialized+ *+ * cardano_error_t result = cardano_utxo_set_input(utxo, input);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Transaction input successfully set for the UTXO.\n");+ * }+ * else+ * {+ *   printf("Failed to set transaction input: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up resources+ * cardano_transaction_input_unref(&input);+ * cardano_utxo_unref(&utxo);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_utxo_set_input(cardano_utxo_t* utxo, cardano_transaction_input_t* input);++/**+ * \brief Retrieves the transaction output from a UTXO.+ *+ * This function fetches the transaction output associated with a given \ref cardano_utxo_t object.+ * The transaction output represents the destination of the UTXO, indicating the amount of value and recipient.+ *+ * \param[in] utxo A pointer to an initialized \ref cardano_utxo_t object. This parameter must not be NULL.+ *+ * \return A pointer to a \ref cardano_transaction_output_t object representing the transaction output of the UTXO.+ *         The returned object is a new reference, and the caller is responsible for managing its lifecycle.+ *         Specifically, the caller must release the object by calling \ref cardano_transaction_output_unref+ *         when it is no longer needed. If the \p utxo is NULL, the function returns NULL.+ *+ * \note The transaction output refers to the recipient and the amount of value in the UTXO, representing spendable value.+ *+ * Usage Example:+ * \code{.c}+ * cardano_utxo_t* utxo = ...; // Assume utxo is already initialized+ * cardano_transaction_output_t* output = cardano_utxo_get_output(utxo);+ *+ * if (output != NULL)+ * {+ *   // Use the transaction output as needed+ *+ *   // Clean up when done+ *   cardano_transaction_output_unref(&output);+ * }+ * else+ * {+ *   printf("Failed to retrieve the transaction output.\n");+ * }+ *+ * // Clean up the utxo when no longer needed+ * cardano_utxo_unref(&utxo);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_transaction_output_t* cardano_utxo_get_output(cardano_utxo_t* utxo);++/**+ * \brief Sets the transaction output for a UTXO.+ *+ * This function assigns a transaction output to the specified \ref cardano_utxo_t object.+ * The transaction output represents the destination of the UTXO, including the amount of value+ * and the recipient's address.+ *+ * \param[in,out] utxo A pointer to an initialized \ref cardano_utxo_t object where the output will be set.+ *                     This parameter must not be NULL.+ * \param[in] output A pointer to an initialized \ref cardano_transaction_output_t object representing the output+ *                   to be associated with the UTXO. This parameter must not be NULL.+ *+ * \return \ref cardano_error_t indicating the outcome of the operation. Returns \ref CARDANO_SUCCESS+ *         if the transaction output was successfully set. If either \p utxo or \p output is NULL,+ *         returns \ref CARDANO_ERROR_POINTER_IS_NULL.+ *+ * \note This function increases the reference count of the \p output object, meaning the caller retains+ *       ownership of the output and must release it by calling \ref cardano_transaction_output_unref+ *       when it is no longer needed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_utxo_t* utxo = ...; // Assume utxo is initialized+ * cardano_transaction_output_t* output = ...; // Assume output is initialized+ *+ * cardano_error_t result = cardano_utxo_set_output(utxo, output);+ * if (result == CARDANO_SUCCESS)+ * {+ *   printf("Transaction output successfully set for the UTXO.\n");+ * }+ * else+ * {+ *   printf("Failed to set transaction output: %s\n", cardano_error_to_string(result));+ * }+ *+ * // Clean up resources+ * cardano_transaction_output_unref(&output);+ * cardano_utxo_unref(&utxo);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT cardano_error_t+cardano_utxo_set_output(cardano_utxo_t* utxo, cardano_transaction_output_t* output);++/**+ * \brief Compares two UTxO objects for equality.+ *+ * This function compares two UTxO objects to determine if they are equal.+ *+ * \param[in] lhs Pointer to the first UTxO object.+ * \param[in] rhs Pointer to the second UTxO object.+ *+ * \return \c true if the utxo objects are equal, \c false otherwise.+ *+ * Usage Example:+ * \code{.c}+ * cardano_utxo_t* utxo1 = NULL;+ * cardano_utxo_t* utxo2 = NULL;+ *+ * // Assume utxo1 and utxo2 are initialized properly+ *+ * bool are_equal = cardano_utxo_equals(utxo1, utxo2);+ *+ * if (are_equal)+ * {+ *   printf("The utxo objects are equal.\n");+ * }+ * else+ * {+ *   printf("The utxo objects are not equal.\n");+ * }+ *+ * // Clean up+ * cardano_utxo_unref(&utxo1);+ * cardano_utxo_unref(&utxo2);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT bool cardano_utxo_equals(const cardano_utxo_t* lhs, const cardano_utxo_t* rhs);++/**+ * \brief Decrements the reference count of a cardano_utxo_t object.+ *+ * This function is responsible for managing the lifecycle of a \ref cardano_utxo_t object+ * by decreasing its reference count. When the reference count reaches zero, the utxo is+ * finalized; its associated resources are released, and its memory is deallocated.+ *+ * \param[in,out] utxo A pointer to the pointer of the utxo object. This double+ *                            indirection allows the function to set the caller's pointer to+ *                            NULL, avoiding dangling pointer issues after the object has been+ *                            freed.+ *+ * Usage Example:+ * \code{.c}+ * cardano_utxo_t* utxo = cardano_utxo_new(major, minor);+ *+ * // Perform operations with the utxo...+ *+ * cardano_utxo_unref(&utxo);+ * // At this point, utxo is NULL and cannot be used.+ * \endcode+ *+ * \note After calling \ref cardano_utxo_unref, the pointer to the \ref cardano_utxo_t object+ *       will be set to NULL to prevent its reuse.+ */+CARDANO_EXPORT void cardano_utxo_unref(cardano_utxo_t** utxo);++/**+ * \brief Increases the reference count of the cardano_utxo_t object.+ *+ * This function is used to manually increment the reference count of an cardano_utxo_t+ * object, indicating that another part of the code has taken ownership of it. This+ * ensures the object remains allocated and valid until all owners have released their+ * reference by calling \ref cardano_utxo_unref.+ *+ * \param utxo A pointer to the cardano_utxo_t object whose reference count is to be incremented.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming utxo is a previously created utxo object+ *+ * cardano_utxo_ref(utxo);+ *+ * // Now utxo can be safely used elsewhere without worrying about premature deallocation+ * \endcode+ *+ * \note Always ensure that for every call to \ref cardano_utxo_ref there is a corresponding+ * call to \ref cardano_utxo_unref to prevent memory leaks.+ */+CARDANO_EXPORT void cardano_utxo_ref(cardano_utxo_t* utxo);++/**+ * \brief Retrieves the current reference count of the cardano_utxo_t object.+ *+ * This function returns the number of active references to an cardano_utxo_t object. It's useful+ * for debugging purposes or managing the lifecycle of the object in complex scenarios.+ *+ * \warning This function does not account for transitive references. A transitive reference+ * occurs when an object holds a reference to another object, rather than directly to the+ * cardano_utxo_t. As such, the reported count may not fully represent the total number+ * of conceptual references in cases where such transitive relationships exist.+ *+ * \param utxo A pointer to the cardano_utxo_t object whose reference count is queried.+ *                    The object must not be NULL.+ *+ * \return The number of active references to the specified cardano_utxo_t object. If the object+ * is properly managed (i.e., every \ref cardano_utxo_ref call is matched with a+ * \ref cardano_utxo_unref call), this count should reach zero right before the object+ * is deallocated.+ *+ * Usage Example:+ * \code{.c}+ * // Assuming utxo is a previously created utxo object+ *+ * size_t ref_count = cardano_utxo_refcount(utxo);+ *+ * printf("Reference count: %zu\n", ref_count);+ * \endcode+ */+CARDANO_NODISCARD+CARDANO_EXPORT size_t cardano_utxo_refcount(const cardano_utxo_t* utxo);++/**+ * \brief Sets the last error message for a given cardano_utxo_t object.+ *+ * Records an error message in the utxo's last_error buffer, overwriting any existing message.+ * This is useful for storing descriptive error information that can be later retrieved. The message+ * is truncated if it exceeds the buffer's capacity.+ *+ * \param[in] utxo A pointer to the \ref cardano_utxo_t instance whose last error message is+ *                       to be set. If \c NULL, the function does nothing.+ * \param[in] message A null-terminated string containing the error message. If \c NULL, the utxo's+ *                    last_error is set to an empty string, indicating no error.+ *+ * \note The error message is limited to 1023 characters, including the null terminator, due to the+ * fixed size of the last_error buffer.+ */+CARDANO_EXPORT void cardano_utxo_set_last_error(+  cardano_utxo_t* utxo,+  const char*     message);++/**+ * \brief Retrieves the last error message recorded for a specific utxo.+ *+ * This function returns a pointer to the null-terminated string containing+ * the last error message set by \ref cardano_utxo_set_last_error for the given+ * utxo. If no error message has been set, or if the last_error buffer was+ * explicitly cleared, an empty string is returned, indicating no error.+ *+ * \param[in] utxo A pointer to the \ref cardano_utxo_t instance whose last error+ *                   message is to be retrieved. If the utxo is NULL, the function+ *                   returns a generic error message indicating the null utxo.+ *+ * \return A pointer to a null-terminated string containing the last error+ *         message for the specified utxo. If the utxo is NULL, "Object is NULL."+ *         is returned to indicate the error.+ *+ * \note The returned string points to internal storage within the object and+ *       must not be modified by the caller. The string remains valid until the+ *       next call to \ref cardano_utxo_set_last_error for the same utxo, or until+ *       the utxo is deallocated.+ */+CARDANO_NODISCARD+CARDANO_EXPORT const char* cardano_utxo_get_last_error(+  const cardano_utxo_t* utxo);++/**+ * \brief Creates an independent deep copy of a \ref cardano_utxo_t.+ *+ * Copies all owned children and preserves stored encoding and value state without+ * serializing the object. Optional absent fields remain absent. The source is not+ * modified and no mutable storage is shared with the result. Source graphs must+ * be acyclic. The copy starts with one owned reference and an empty error message.+ *+ * \param[in] source The object to copy. Must not be \c NULL.+ * \param[out] clone Receives the owned copy. Must not be \c NULL and must not+ * overwrite an existing owned reference. Set to \c NULL on failure.+ *+ * \return \ref CARDANO_SUCCESS on success, \ref CARDANO_ERROR_POINTER_IS_NULL+ * for a null argument, or \ref CARDANO_ERROR_MEMORY_ALLOCATION_FAILED when an+ * allocation fails. Partial copies are released before returning an error.+ *+ * \note Release the result with \ref cardano_utxo_unref.+ */+CARDANO_EXPORT cardano_error_t+cardano_utxo_deep_clone(const cardano_utxo_t* source, cardano_utxo_t** clone);++#ifdef __cplusplus+}+#endif /* __cplusplus */++#endif // BIGLUP_LABS_INCLUDE_CARDANO_UTXO_H
+ vendor/include/cardano/common/utxo_list.h view

file too large to diff

+ vendor/include/cardano/common/withdrawal_map.h view

file too large to diff

+ vendor/include/cardano/crypto/bip32_private_key.h view

file too large to diff

+ vendor/include/cardano/crypto/bip32_public_key.h view

file too large to diff

+ vendor/include/cardano/crypto/blake2b_hash.h view

file too large to diff

+ vendor/include/cardano/crypto/blake2b_hash_set.h view

file too large to diff

+ vendor/include/cardano/crypto/blake2b_hash_size.h view

file too large to diff

+ vendor/include/cardano/crypto/crc32.h view

file too large to diff

+ vendor/include/cardano/crypto/ed25519_private_key.h view

file too large to diff

+ vendor/include/cardano/crypto/ed25519_public_key.h view

file too large to diff

+ vendor/include/cardano/crypto/ed25519_signature.h view

file too large to diff

+ vendor/include/cardano/crypto/emip3.h view

file too large to diff

+ vendor/include/cardano/crypto/pbkdf2.h view

file too large to diff

+ vendor/include/cardano/encoding/base58.h view

file too large to diff

+ vendor/include/cardano/encoding/bech32.h view

file too large to diff

+ vendor/include/cardano/error.h view

file too large to diff

+ vendor/include/cardano/export.h view

file too large to diff

+ vendor/include/cardano/json/json_context.h view

file too large to diff

+ vendor/include/cardano/json/json_format.h view

file too large to diff

+ vendor/include/cardano/json/json_object.h view

file too large to diff

+ vendor/include/cardano/json/json_object_type.h view

file too large to diff

+ vendor/include/cardano/json/json_writer.h view

file too large to diff

+ vendor/include/cardano/key_handlers/account_derivation_path.h view

file too large to diff

+ vendor/include/cardano/key_handlers/cip_1852_constants.h view

file too large to diff

+ vendor/include/cardano/key_handlers/derivation_path.h view

file too large to diff

+ vendor/include/cardano/key_handlers/secure_key_handler.h view

file too large to diff

+ vendor/include/cardano/key_handlers/secure_key_handler_impl.h view

file too large to diff

+ vendor/include/cardano/key_handlers/secure_key_handler_type.h view

file too large to diff

+ vendor/include/cardano/key_handlers/software_secure_key_handler.h view

file too large to diff

+ vendor/include/cardano/message_signing/cip8.h view

file too large to diff

+ vendor/include/cardano/object.h view

file too large to diff

+ vendor/include/cardano/plutus_data/constr_plutus_data.h view

file too large to diff

+ vendor/include/cardano/plutus_data/plutus_data.h view

file too large to diff

+ vendor/include/cardano/plutus_data/plutus_data_kind.h view

file too large to diff

+ vendor/include/cardano/plutus_data/plutus_list.h view

file too large to diff

+ vendor/include/cardano/plutus_data/plutus_map.h view

file too large to diff

+ vendor/include/cardano/pool_params/bls_key.h view

file too large to diff

+ vendor/include/cardano/pool_params/ipv4.h view

file too large to diff

+ vendor/include/cardano/pool_params/ipv6.h view

file too large to diff

+ vendor/include/cardano/pool_params/multi_host_name_relay.h view

file too large to diff

+ vendor/include/cardano/pool_params/pool_metadata.h view

file too large to diff

+ vendor/include/cardano/pool_params/pool_owners.h view

file too large to diff

+ vendor/include/cardano/pool_params/pool_params.h view

file too large to diff

+ vendor/include/cardano/pool_params/relay.h view

file too large to diff

+ vendor/include/cardano/pool_params/relay_type.h view

file too large to diff

+ vendor/include/cardano/pool_params/relays.h view

file too large to diff

+ vendor/include/cardano/pool_params/single_host_addr_relay.h view

file too large to diff

+ vendor/include/cardano/pool_params/single_host_name_relay.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/committee.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/committee_members_map.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/constitution.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/credential_set.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/governance_action_type.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/hard_fork_initiation_action.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/info_action.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/new_constitution_action.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/no_confidence_action.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/parameter_change_action.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/proposal_procedure.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/proposal_procedure_set.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/treasury_withdrawals_action.h view

file too large to diff

+ vendor/include/cardano/proposal_procedures/update_committee_action.h view

file too large to diff

+ vendor/include/cardano/protocol_params/cost_model.h view

file too large to diff

+ vendor/include/cardano/protocol_params/costmdls.h view

file too large to diff

+ vendor/include/cardano/protocol_params/drep_voting_thresholds.h view

file too large to diff

+ vendor/include/cardano/protocol_params/ex_unit_prices.h view

file too large to diff

+ vendor/include/cardano/protocol_params/pool_voting_thresholds.h view

file too large to diff

+ vendor/include/cardano/protocol_params/proposed_param_updates.h view

file too large to diff

+ vendor/include/cardano/protocol_params/protocol_param_update.h view

file too large to diff

+ vendor/include/cardano/protocol_params/protocol_parameters.h view

file too large to diff

+ vendor/include/cardano/protocol_params/update.h view

file too large to diff

+ vendor/include/cardano/providers/provider.h view

file too large to diff

+ vendor/include/cardano/providers/provider_impl.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/native_script.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/native_script_list.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/native_script_type.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/script_all.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/script_any.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/script_invalid_after.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/script_invalid_before.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/script_n_of_k.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/script_pubkey.h view

file too large to diff

+ vendor/include/cardano/scripts/native_scripts/script_require_guard.h view

file too large to diff

+ vendor/include/cardano/scripts/plutus_scripts/plutus_language_version.h view

file too large to diff

+ vendor/include/cardano/scripts/plutus_scripts/plutus_v1_script.h view

file too large to diff

+ vendor/include/cardano/scripts/plutus_scripts/plutus_v2_script.h view

file too large to diff

+ vendor/include/cardano/scripts/plutus_scripts/plutus_v3_script.h view

file too large to diff

+ vendor/include/cardano/scripts/plutus_scripts/plutus_v4_script.h view

file too large to diff

+ vendor/include/cardano/scripts/script.h view

file too large to diff

+ vendor/include/cardano/scripts/script_language.h view

file too large to diff

+ vendor/include/cardano/slot_config.h view

file too large to diff

+ vendor/include/cardano/time.h view

file too large to diff

+ vendor/include/cardano/transaction/sub_transaction.h view

file too large to diff

+ vendor/include/cardano/transaction/transaction.h view

file too large to diff

+ vendor/include/cardano/transaction_body/account_balance_interval.h view

file too large to diff

+ vendor/include/cardano/transaction_body/account_balance_intervals_map.h view

file too large to diff

+ vendor/include/cardano/transaction_body/direct_deposit_map.h view

file too large to diff

+ vendor/include/cardano/transaction_body/required_guards_map.h view

file too large to diff

+ vendor/include/cardano/transaction_body/sub_transaction_body.h view

file too large to diff

+ vendor/include/cardano/transaction_body/sub_transaction_set.h view

file too large to diff

+ vendor/include/cardano/transaction_body/transaction_body.h view

file too large to diff

+ vendor/include/cardano/transaction_body/transaction_input.h view

file too large to diff

+ vendor/include/cardano/transaction_body/transaction_input_set.h view

file too large to diff

+ vendor/include/cardano/transaction_body/transaction_output.h view

file too large to diff

+ vendor/include/cardano/transaction_body/transaction_output_list.h view

file too large to diff

+ vendor/include/cardano/transaction_body/value.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/balancing/deferred_redeemer_list.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/balancing/implicit_coin.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/balancing/input_to_redeemer_map.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/balancing/transaction_balancing.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/coin_selection/coin_selection_request.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/coin_selection/coin_selection_strategy.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/coin_selection/coin_selector.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/coin_selection/coin_selector_impl.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/coin_selection/large_first_coin_selector.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/coin_selection/random_improve_coin_selector.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/evaluation/native_tx_evaluator.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/evaluation/provider_tx_evaluator.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/evaluation/tx_evaluator.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/evaluation/tx_evaluator_impl.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/fee.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/script_data_hash.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/sub_transaction_builder.h view

file too large to diff

+ vendor/include/cardano/transaction_builder/transaction_builder.h view

file too large to diff

+ vendor/include/cardano/typedefs.h view

file too large to diff

+ vendor/include/cardano/uplc/uplc_apply_params.h view

file too large to diff

+ vendor/include/cardano/voting_procedures/governance_action_id_list.h view

file too large to diff

+ vendor/include/cardano/voting_procedures/vote.h view

file too large to diff

+ vendor/include/cardano/voting_procedures/voter.h view

file too large to diff

+ vendor/include/cardano/voting_procedures/voter_list.h view

file too large to diff

+ vendor/include/cardano/voting_procedures/voter_type.h view

file too large to diff

+ vendor/include/cardano/voting_procedures/voting_procedure.h view

file too large to diff

+ vendor/include/cardano/voting_procedures/voting_procedure_list.h view

file too large to diff

+ vendor/include/cardano/voting_procedures/voting_procedures.h view

file too large to diff

+ vendor/include/cardano/witness_set/bootstrap_witness.h view

file too large to diff

+ vendor/include/cardano/witness_set/bootstrap_witness_set.h view

file too large to diff

+ vendor/include/cardano/witness_set/native_script_set.h view

file too large to diff

+ vendor/include/cardano/witness_set/plutus_data_set.h view

file too large to diff

+ vendor/include/cardano/witness_set/plutus_v1_script_set.h view

file too large to diff

+ vendor/include/cardano/witness_set/plutus_v2_script_set.h view

file too large to diff

+ vendor/include/cardano/witness_set/plutus_v3_script_set.h view

file too large to diff

+ vendor/include/cardano/witness_set/plutus_v4_script_set.h view

file too large to diff

+ vendor/include/cardano/witness_set/redeemer.h view

file too large to diff

+ vendor/include/cardano/witness_set/redeemer_list.h view

file too large to diff

+ vendor/include/cardano/witness_set/redeemer_tag.h view

file too large to diff

+ vendor/include/cardano/witness_set/vkey_witness.h view

file too large to diff

+ vendor/include/cardano/witness_set/vkey_witness_set.h view

file too large to diff

+ vendor/include/cardano/witness_set/witness_set.h view

file too large to diff

+ vendor/src/address/address.c view

file too large to diff

+ vendor/src/address/base_address.c view

file too large to diff

+ vendor/src/address/byron_address.c view

file too large to diff

+ vendor/src/address/enterprise_address.c view

file too large to diff

+ vendor/src/address/internals/addr_common.c view

file too large to diff

+ vendor/src/address/internals/addr_common.h view

file too large to diff

+ vendor/src/address/internals/base_addr_pack.c view

file too large to diff

+ vendor/src/address/internals/base_addr_pack.h view

file too large to diff

+ vendor/src/address/internals/byron_addr_pack.c view

file too large to diff

+ vendor/src/address/internals/byron_addr_pack.h view

file too large to diff

+ vendor/src/address/internals/byron_address_content.h view

file too large to diff

+ vendor/src/address/internals/enterprise_addr_pack.c view

file too large to diff

+ vendor/src/address/internals/enterprise_addr_pack.h view

file too large to diff

+ vendor/src/address/internals/pointer_addr_pack.c view

file too large to diff

+ vendor/src/address/internals/pointer_addr_pack.h view

file too large to diff

+ vendor/src/address/internals/reward_addr_pack.c view

file too large to diff

+ vendor/src/address/internals/reward_addr_pack.h view

file too large to diff

+ vendor/src/address/pointer_address.c view

file too large to diff

+ vendor/src/address/reward_address.c view

file too large to diff

+ vendor/src/allocators.c view

file too large to diff

+ vendor/src/allocators.h view

file too large to diff

+ vendor/src/assets/asset_id.c view

file too large to diff

+ vendor/src/assets/asset_id_list.c view

file too large to diff

+ vendor/src/assets/asset_id_map.c view

file too large to diff

+ vendor/src/assets/asset_name.c view

file too large to diff

+ vendor/src/assets/asset_name_list.c view

file too large to diff

+ vendor/src/assets/asset_name_map.c view

file too large to diff

+ vendor/src/assets/multi_asset.c view

file too large to diff

+ vendor/src/assets/policy_id_list.c view

file too large to diff

+ vendor/src/auxiliary_data/auxiliary_data.c view

file too large to diff

+ vendor/src/auxiliary_data/metadatum.c view

file too large to diff

+ vendor/src/auxiliary_data/metadatum_label_list.c view

file too large to diff

+ vendor/src/auxiliary_data/metadatum_list.c view

file too large to diff

+ vendor/src/auxiliary_data/metadatum_map.c view

file too large to diff

+ vendor/src/auxiliary_data/plutus_v1_script_list.c view

file too large to diff

+ vendor/src/auxiliary_data/plutus_v2_script_list.c view

file too large to diff

+ vendor/src/auxiliary_data/plutus_v3_script_list.c view

file too large to diff

+ vendor/src/auxiliary_data/plutus_v4_script_list.c view

file too large to diff

+ vendor/src/auxiliary_data/transaction_metadata.c view

file too large to diff

+ vendor/src/bip39/bip39.c view

file too large to diff

+ vendor/src/bip39/bip39_wordlist_en.h view

file too large to diff

+ vendor/src/buffer/buffer.c view

file too large to diff

+ vendor/src/cardano.c view

file too large to diff

+ vendor/src/cbor/cbor_additional_info.h view

file too large to diff

+ vendor/src/cbor/cbor_initial_byte.c view

file too large to diff

+ vendor/src/cbor/cbor_initial_byte.h view

file too large to diff

+ vendor/src/cbor/cbor_major_type.c view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader.c view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_collections.c view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_collections.h view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_core.c view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_core.h view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_numeric.c view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_numeric.h view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_simple_values.c view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_simple_values.h view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_tags.c view

file too large to diff

+ vendor/src/cbor/cbor_reader/cbor_reader_tags.h view

file too large to diff

+ vendor/src/cbor/cbor_reader_state.c view

file too large to diff

+ vendor/src/cbor/cbor_simple_value.c view

file too large to diff

+ vendor/src/cbor/cbor_tag.c view

file too large to diff

+ vendor/src/cbor/cbor_validation.c view

file too large to diff

+ vendor/src/cbor/cbor_validation.h view

file too large to diff

+ vendor/src/cbor/cbor_writer.c view

file too large to diff

+ vendor/src/certs/auth_committee_hot_cert.c view

file too large to diff

+ vendor/src/certs/cert_type.c view

file too large to diff

+ vendor/src/certs/certificate.c view

file too large to diff

+ vendor/src/certs/certificate_set.c view

file too large to diff

+ vendor/src/certs/genesis_key_delegation_cert.c view

file too large to diff

+ vendor/src/certs/mir_cert.c view

file too large to diff

+ vendor/src/certs/mir_to_pot_cert.c view

file too large to diff

+ vendor/src/certs/mir_to_stake_creds_cert.c view

file too large to diff

+ vendor/src/certs/pool_registration_cert.c view

file too large to diff

+ vendor/src/certs/pool_retirement_cert.c view

file too large to diff

+ vendor/src/certs/register_drep_cert.c view

file too large to diff

+ vendor/src/certs/registration_cert.c view

file too large to diff

+ vendor/src/certs/resign_committee_cold_cert.c view

file too large to diff

+ vendor/src/certs/stake_delegation_cert.c view

file too large to diff

+ vendor/src/certs/stake_deregistration_cert.c view

file too large to diff

+ vendor/src/certs/stake_registration_cert.c view

file too large to diff

+ vendor/src/certs/stake_registration_delegation_cert.c view

file too large to diff

+ vendor/src/certs/stake_vote_delegation_cert.c view

file too large to diff

+ vendor/src/certs/stake_vote_registration_delegation_cert.c view

file too large to diff

+ vendor/src/certs/unregister_drep_cert.c view

file too large to diff

+ vendor/src/certs/unregistration_cert.c view

file too large to diff

+ vendor/src/certs/update_drep_cert.c view

file too large to diff

+ vendor/src/certs/vote_delegation_cert.c view

file too large to diff

+ vendor/src/certs/vote_registration_delegation_cert.c view

file too large to diff

+ vendor/src/collections/array.c view

file too large to diff

+ vendor/src/collections/array.h view

file too large to diff

+ vendor/src/collections/set.c view

file too large to diff

+ vendor/src/collections/set.h view

file too large to diff

+ vendor/src/common/anchor.c view

file too large to diff

+ vendor/src/common/bigint.c view

file too large to diff

+ vendor/src/common/credential.c view

file too large to diff

+ vendor/src/common/datum.c view

file too large to diff

+ vendor/src/common/drep.c view

file too large to diff

+ vendor/src/common/ex_units.c view

file too large to diff

+ vendor/src/common/governance_action_id.c view

file too large to diff

+ vendor/src/common/guard_set.c view

file too large to diff

+ vendor/src/common/ledger_order.c view

file too large to diff

+ vendor/src/common/ledger_order.h view

file too large to diff

+ vendor/src/common/network_magic.c view

file too large to diff

+ vendor/src/common/protocol_version.c view

file too large to diff

+ vendor/src/common/reward_address_list.c view

file too large to diff

+ vendor/src/common/unit_interval.c view

file too large to diff

+ vendor/src/common/utxo.c view

file too large to diff

+ vendor/src/common/utxo_list.c view

file too large to diff

+ vendor/src/common/withdrawal_map.c view

file too large to diff

+ vendor/src/config.h view

file too large to diff

+ vendor/src/crypto/arithmetic.c view

file too large to diff

+ vendor/src/crypto/arithmetic.h view

file too large to diff

+ vendor/src/crypto/bip32_key_derivation.c view

file too large to diff

+ vendor/src/crypto/bip32_key_derivation.h view

file too large to diff

+ vendor/src/crypto/bip32_private_key.c view

file too large to diff

+ vendor/src/crypto/bip32_public_key.c view

file too large to diff

+ vendor/src/crypto/blake2b_hash.c view

file too large to diff

+ vendor/src/crypto/blake2b_hash_internal.h view

file too large to diff

+ vendor/src/crypto/blake2b_hash_set.c view

file too large to diff

+ vendor/src/crypto/crc32.c view

file too large to diff

+ vendor/src/crypto/ed25519_private_key.c view

file too large to diff

+ vendor/src/crypto/ed25519_public_key.c view

file too large to diff

+ vendor/src/crypto/ed25519_signature.c view

file too large to diff

+ vendor/src/crypto/emip3.c view

file too large to diff

+ vendor/src/crypto/pbkdf2.c view

file too large to diff

+ vendor/src/encoding/base58.c view

file too large to diff

+ vendor/src/encoding/bech32.c view

file too large to diff

+ vendor/src/endian.c view

file too large to diff

+ vendor/src/endian.h view

file too large to diff

+ vendor/src/error.c view

file too large to diff

+ vendor/src/json/internals/json_object_common.c view

file too large to diff

+ vendor/src/json/internals/json_object_common.h view

file too large to diff

+ vendor/src/json/internals/json_object_serialization.c view

file too large to diff

+ vendor/src/json/internals/json_object_serialization.h view

file too large to diff

+ vendor/src/json/internals/json_parser.c view

file too large to diff

+ vendor/src/json/internals/json_parser.h view

file too large to diff

+ vendor/src/json/internals/json_writer_common.c view

file too large to diff

+ vendor/src/json/internals/json_writer_common.h view

file too large to diff

+ vendor/src/json/internals/utf8.c view

file too large to diff

+ vendor/src/json/internals/utf8.h view

file too large to diff

+ vendor/src/json/json_object.c view

file too large to diff

+ vendor/src/json/json_writer.c view

file too large to diff

+ vendor/src/key_handlers/secure_key_handler.c view

file too large to diff

+ vendor/src/key_handlers/software_secure_key_handler.c view

file too large to diff

+ vendor/src/message_signing/cip8.c view

file too large to diff

+ vendor/src/object.c view

file too large to diff

+ vendor/src/plutus_data/constr_plutus_data.c view

file too large to diff

+ vendor/src/plutus_data/plutus_data.c view

file too large to diff

+ vendor/src/plutus_data/plutus_list.c view

file too large to diff

+ vendor/src/plutus_data/plutus_map.c view

file too large to diff

+ vendor/src/pool_params/bls_key.c view

file too large to diff

+ vendor/src/pool_params/ipv4.c view

file too large to diff

+ vendor/src/pool_params/ipv6.c view

file too large to diff

+ vendor/src/pool_params/multi_host_name_relay.c view

file too large to diff

+ vendor/src/pool_params/pool_metadata.c view

file too large to diff

+ vendor/src/pool_params/pool_owners.c view

file too large to diff

+ vendor/src/pool_params/pool_params.c view

file too large to diff

+ vendor/src/pool_params/relay.c view

file too large to diff

+ vendor/src/pool_params/relay_type.c view

file too large to diff

+ vendor/src/pool_params/relays.c view

file too large to diff

+ vendor/src/pool_params/single_host_addr_relay.c view

file too large to diff

+ vendor/src/pool_params/single_host_name_relay.c view

file too large to diff

+ vendor/src/proposal_procedures/committee.c view

file too large to diff

+ vendor/src/proposal_procedures/committee_members_map.c view

file too large to diff

+ vendor/src/proposal_procedures/constitution.c view

file too large to diff

+ vendor/src/proposal_procedures/credential_set.c view

file too large to diff

+ vendor/src/proposal_procedures/governance_action_type.c view

file too large to diff

+ vendor/src/proposal_procedures/hard_fork_initiation_action.c view

file too large to diff

+ vendor/src/proposal_procedures/info_action.c view

file too large to diff

+ vendor/src/proposal_procedures/new_constitution_action.c view

file too large to diff

+ vendor/src/proposal_procedures/no_confidence_action.c view

file too large to diff

+ vendor/src/proposal_procedures/parameter_change_action.c view

file too large to diff

+ vendor/src/proposal_procedures/proposal_procedure.c view

file too large to diff

+ vendor/src/proposal_procedures/proposal_procedure_set.c view

file too large to diff

+ vendor/src/proposal_procedures/treasury_withdrawals_action.c view

file too large to diff

+ vendor/src/proposal_procedures/update_committee_action.c view

file too large to diff

+ vendor/src/protocol_params/cost_model.c view

file too large to diff

+ vendor/src/protocol_params/costmdls.c view

file too large to diff

+ vendor/src/protocol_params/drep_voting_thresholds.c view

file too large to diff

+ vendor/src/protocol_params/ex_unit_prices.c view

file too large to diff

+ vendor/src/protocol_params/pool_voting_thresholds.c view

file too large to diff

+ vendor/src/protocol_params/proposed_param_updates.c view

file too large to diff

+ vendor/src/protocol_params/protocol_param_update.c view

file too large to diff

+ vendor/src/protocol_params/protocol_parameters.c view

file too large to diff

+ vendor/src/protocol_params/update.c view

file too large to diff

+ vendor/src/providers/emscripten/emscripten_provider.c view

file too large to diff

+ vendor/src/providers/provider.c view

file too large to diff

+ vendor/src/scripts/native_scripts/native_script.c view

file too large to diff

+ vendor/src/scripts/native_scripts/native_script_list.c view

file too large to diff

+ vendor/src/scripts/native_scripts/native_script_type.c view

file too large to diff

+ vendor/src/scripts/native_scripts/script_all.c view

file too large to diff

+ vendor/src/scripts/native_scripts/script_any.c view

file too large to diff

+ vendor/src/scripts/native_scripts/script_invalid_after.c view

file too large to diff

+ vendor/src/scripts/native_scripts/script_invalid_before.c view

file too large to diff

+ vendor/src/scripts/native_scripts/script_n_of_k.c view

file too large to diff

+ vendor/src/scripts/native_scripts/script_pubkey.c view

file too large to diff

+ vendor/src/scripts/native_scripts/script_require_guard.c view

file too large to diff

+ vendor/src/scripts/plutus_scripts/plutus_v1_script.c view

file too large to diff

+ vendor/src/scripts/plutus_scripts/plutus_v2_script.c view

file too large to diff

+ vendor/src/scripts/plutus_scripts/plutus_v3_script.c view

file too large to diff

+ vendor/src/scripts/plutus_scripts/plutus_v4_script.c view

file too large to diff

+ vendor/src/scripts/script.c view

file too large to diff

+ vendor/src/string_safe.c view

file too large to diff

+ vendor/src/string_safe.h view

file too large to diff

+ vendor/src/time.c view

file too large to diff

+ vendor/src/transaction/sub_transaction.c view

file too large to diff

+ vendor/src/transaction/transaction.c view

file too large to diff

+ vendor/src/transaction_body/account_balance_interval.c view

file too large to diff

+ vendor/src/transaction_body/account_balance_intervals_map.c view

file too large to diff

+ vendor/src/transaction_body/direct_deposit_map.c view

file too large to diff

+ vendor/src/transaction_body/internals/body_fields.c view

file too large to diff

+ vendor/src/transaction_body/internals/body_fields.h view

file too large to diff

+ vendor/src/transaction_body/required_guards_map.c view

file too large to diff

+ vendor/src/transaction_body/sub_transaction_body.c view

file too large to diff

+ vendor/src/transaction_body/sub_transaction_set.c view

file too large to diff

+ vendor/src/transaction_body/transaction_body.c view

file too large to diff

+ vendor/src/transaction_body/transaction_input.c view

file too large to diff

+ vendor/src/transaction_body/transaction_input_set.c view

file too large to diff

+ vendor/src/transaction_body/transaction_output.c view

file too large to diff

+ vendor/src/transaction_body/transaction_output_list.c view

file too large to diff

+ vendor/src/transaction_body/value.c view

file too large to diff

+ vendor/src/transaction_builder/balancing/deferred_redeemer_list.c view

file too large to diff

+ vendor/src/transaction_builder/balancing/implicit_coin.c view

file too large to diff

+ vendor/src/transaction_builder/balancing/input_to_redeemer_map.c view

file too large to diff

+ vendor/src/transaction_builder/balancing/internals/collateral.c view

file too large to diff

+ vendor/src/transaction_builder/balancing/internals/collateral.h view

file too large to diff

+ vendor/src/transaction_builder/balancing/internals/pool_deposits.c view

file too large to diff

+ vendor/src/transaction_builder/balancing/internals/pool_deposits.h view

file too large to diff

+ vendor/src/transaction_builder/balancing/internals/scripts_needed.c view

file too large to diff

+ vendor/src/transaction_builder/balancing/internals/scripts_needed.h view

file too large to diff

+ vendor/src/transaction_builder/balancing/internals/unique_signers.c view

file too large to diff

+ vendor/src/transaction_builder/balancing/internals/unique_signers.h view

file too large to diff

+ vendor/src/transaction_builder/balancing/transaction_balancing.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/coin_selector.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/change_builder.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/change_builder.h view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/emscripten_coin_selector.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/large_first_coin_selector.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/large_first_helpers.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/large_first_helpers.h view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/random_improve_change_state.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/random_improve_change_state.h view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/random_improve_coin_selector.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/random_improve_helpers.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/random_improve_helpers.h view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/random_improve_selection_index.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/random_improve_selection_index.h view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/random_improve_utxo_utils.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/random_improve_utxo_utils.h view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/value_splitting.c view

file too large to diff

+ vendor/src/transaction_builder/coin_selection/internals/value_splitting.h view

file too large to diff

+ vendor/src/transaction_builder/evaluation/emscripten_tx_evaluator.c view

file too large to diff

+ vendor/src/transaction_builder/evaluation/native_tx_evaluator.c view

file too large to diff

+ vendor/src/transaction_builder/evaluation/provider_tx_evaluator.c view

file too large to diff

+ vendor/src/transaction_builder/evaluation/tx_evaluator.c view

file too large to diff

+ vendor/src/transaction_builder/fee.c view

file too large to diff

+ vendor/src/transaction_builder/internals/blake2b_hash_to_redeemer_map.c view

file too large to diff

+ vendor/src/transaction_builder/internals/blake2b_hash_to_redeemer_map.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_build.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_build.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_certs.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_certs.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_config.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_config.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_entities.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_entities.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_inputs.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_inputs.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_mint.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_mint.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_outputs.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_outputs.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_proposals.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_proposals.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_redeemers.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_redeemers.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_state.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_state.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_sub_build.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_sub_build.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_sub_transactions.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_sub_transactions.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_votes.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_votes.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_withdrawals.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_withdrawals.h view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_witnesses.c view

file too large to diff

+ vendor/src/transaction_builder/internals/builder_witnesses.h view

file too large to diff

+ vendor/src/transaction_builder/internals/created_output_scripts.c view

file too large to diff

+ vendor/src/transaction_builder/internals/created_output_scripts.h view

file too large to diff

+ vendor/src/transaction_builder/script_data_hash.c view

file too large to diff

+ vendor/src/transaction_builder/sub_transaction_builder.c view

file too large to diff

+ vendor/src/transaction_builder/transaction_builder.c view

file too large to diff

+ vendor/src/uplc/arena/uplc_arena.c view

file too large to diff

+ vendor/src/uplc/arena/uplc_arena.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_constant.c view

file too large to diff

+ vendor/src/uplc/ast/uplc_constant.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_int.c view

file too large to diff

+ vendor/src/uplc/ast/uplc_int.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_int_math.c view

file too large to diff

+ vendor/src/uplc/ast/uplc_int_math.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_lang_version.c view

file too large to diff

+ vendor/src/uplc/ast/uplc_lang_version.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_program.c view

file too large to diff

+ vendor/src/uplc/ast/uplc_program.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_scope_check_mode.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_term.c view

file too large to diff

+ vendor/src/uplc/ast/uplc_term.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_term_kind.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_type.c view

file too large to diff

+ vendor/src/uplc/ast/uplc_type.h view

file too large to diff

+ vendor/src/uplc/ast/uplc_type_kind.h view

file too large to diff

+ vendor/src/uplc/builtins/bls.c view

file too large to diff

+ vendor/src/uplc/builtins/bls.h view

file too large to diff

+ vendor/src/uplc/builtins/builtins.c view

file too large to diff

+ vendor/src/uplc/builtins/builtins.h view

file too large to diff

+ vendor/src/uplc/builtins/uplc_builtin.c view

file too large to diff

+ vendor/src/uplc/builtins/uplc_builtin.h view

file too large to diff

+ vendor/src/uplc/builtins/uplc_builtin_outcome.h view

file too large to diff

+ vendor/src/uplc/builtins/uplc_builtin_semantics.c view

file too large to diff

+ vendor/src/uplc/builtins/uplc_builtin_semantics.h view

file too large to diff

+ vendor/src/uplc/builtins/uplc_byte_view.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_builtin_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_builtin_cost_arity.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_builtin_costs.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_builtin_costs.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_const_or_linear_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_const_or_two_arg_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_cost_model.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_cost_model.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_cost_model_version.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_cost_sat.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_cost_sat.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_diag_model_kind.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_ex_mem.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_ex_mem.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_exp_mod_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_four_arg_cost.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_four_arg_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_four_arg_kind.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_linear_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_machine_costs.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_machine_costs.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_one_arg_cost.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_one_arg_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_one_arg_kind.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_quadratic_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_selected_cost_model.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_selected_cost_model.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_six_arg_cost.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_six_arg_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_six_arg_kind.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_step_accumulator.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_step_accumulator.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_step_kind.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_subtracted_sizes_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_three_arg_cost.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_three_arg_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_three_arg_kind.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_two_arg_cost.c view

file too large to diff

+ vendor/src/uplc/cost/uplc_two_arg_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_two_arg_kind.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_two_var_linear_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_two_var_quadratic_cost.h view

file too large to diff

+ vendor/src/uplc/cost/uplc_with_interaction_cost.h view

file too large to diff

+ vendor/src/uplc/data/uplc_data.c view

file too large to diff

+ vendor/src/uplc/data/uplc_data.h view

file too large to diff

+ vendor/src/uplc/data/uplc_data_kind.h view

file too large to diff

+ vendor/src/uplc/data/uplc_data_pair.h view

file too large to diff

+ vendor/src/uplc/flat/flat_decode.c view

file too large to diff

+ vendor/src/uplc/flat/flat_decode.h view

file too large to diff

+ vendor/src/uplc/flat/flat_encode.c view

file too large to diff

+ vendor/src/uplc/flat/flat_encode.h view

file too large to diff

+ vendor/src/uplc/flat/flat_reader.c view

file too large to diff

+ vendor/src/uplc/flat/flat_reader.h view

file too large to diff

+ vendor/src/uplc/flat/flat_writer.c view

file too large to diff

+ vendor/src/uplc/flat/flat_writer.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_budget.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_env.c view

file too large to diff

+ vendor/src/uplc/machine/uplc_env.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_eval_result.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_eval_status.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_frame.c view

file too large to diff

+ vendor/src/uplc/machine/uplc_frame.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_frame_kind.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_machine.c view

file too large to diff

+ vendor/src/uplc/machine/uplc_machine.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_machine_version.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_state_kind.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_value.c view

file too large to diff

+ vendor/src/uplc/machine/uplc_value.h view

file too large to diff

+ vendor/src/uplc/machine/uplc_value_kind.h view

file too large to diff

+ vendor/src/uplc/syntax/pretty.c view

file too large to diff

+ vendor/src/uplc/syntax/pretty.h view

file too large to diff

+ vendor/src/uplc/syntax/text_parser.c view

file too large to diff

+ vendor/src/uplc/syntax/text_parser.h view

file too large to diff

+ vendor/src/uplc/tx/script_context.c view

file too large to diff

+ vendor/src/uplc/tx/script_context.h view

file too large to diff

+ vendor/src/uplc/tx/uplc_apply_params.c view

file too large to diff

+ vendor/src/voting_procedures/governance_action_id_list.c view

file too large to diff

+ vendor/src/voting_procedures/vote.c view

file too large to diff

+ vendor/src/voting_procedures/voter.c view

file too large to diff

+ vendor/src/voting_procedures/voter_list.c view

file too large to diff

+ vendor/src/voting_procedures/voter_type.c view

file too large to diff

+ vendor/src/voting_procedures/voting_procedure.c view

file too large to diff

+ vendor/src/voting_procedures/voting_procedure_list.c view

file too large to diff

+ vendor/src/voting_procedures/voting_procedure_map.c view

file too large to diff

+ vendor/src/voting_procedures/voting_procedure_map.h view

file too large to diff

+ vendor/src/voting_procedures/voting_procedures.c view

file too large to diff

+ vendor/src/witness_set/bootstrap_witness.c view

file too large to diff

+ vendor/src/witness_set/bootstrap_witness_set.c view

file too large to diff

+ vendor/src/witness_set/native_script_set.c view

file too large to diff

+ vendor/src/witness_set/plutus_data_set.c view

file too large to diff

+ vendor/src/witness_set/plutus_v1_script_set.c view

file too large to diff

+ vendor/src/witness_set/plutus_v2_script_set.c view

file too large to diff

+ vendor/src/witness_set/plutus_v3_script_set.c view

file too large to diff

+ vendor/src/witness_set/plutus_v4_script_set.c view

file too large to diff

+ vendor/src/witness_set/redeemer.c view

file too large to diff

+ vendor/src/witness_set/redeemer_list.c view

file too large to diff

+ vendor/src/witness_set/vkey_witness.c view

file too large to diff

+ vendor/src/witness_set/vkey_witness_set.c view

file too large to diff

+ vendor/src/witness_set/witness_set.c view

file too large to diff