@authon/react-native-wallet 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +34 -4
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/dev/authon/reactnative/wallet/AuthonWalletModule.kt +57 -3
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/AndroidCapabilityProbe.kt +86 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/AuthonWallet.kt +29 -2
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Bitcoin.kt +296 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Chains.kt +157 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Der.kt +17 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Encodings.kt +133 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Http.kt +6 -2
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/KeystoreDeviceStore.kt +27 -23
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Solana.kt +195 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Tron.kt +184 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletApi.kt +16 -8
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletCapabilities.kt +91 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletError.kt +18 -2
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletOps.kt +103 -1
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletTypes.kt +8 -1
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Xrp.kt +193 -0
- package/build/client.d.ts +18 -2
- package/build/client.d.ts.map +1 -1
- package/build/client.js +88 -6
- package/build/client.js.map +1 -1
- package/build/errors.d.ts +8 -1
- package/build/errors.d.ts.map +1 -1
- package/build/errors.js +7 -1
- package/build/errors.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/native.d.ts +5 -1
- package/build/native.d.ts.map +1 -1
- package/build/native.js.map +1 -1
- package/build/types.d.ts +47 -1
- package/build/types.d.ts.map +1 -1
- package/ios/AuthonReactNativeWallet.podspec +6 -2
- package/ios/AuthonWalletModule.swift +46 -3
- package/ios/vendor/AuthonWallet/AuthonWallet.swift +24 -4
- package/ios/vendor/AuthonWallet/Capabilities.swift +149 -0
- package/ios/vendor/AuthonWallet/Chains/Bitcoin.swift +296 -0
- package/ios/vendor/AuthonWallet/Chains/Solana.swift +207 -0
- package/ios/vendor/AuthonWallet/Chains/Tron.swift +181 -0
- package/ios/vendor/AuthonWallet/Chains/XRP.swift +191 -0
- package/ios/vendor/AuthonWallet/Crypto/Chains.swift +278 -0
- package/ios/vendor/AuthonWallet/Crypto/Secp256k1.swift +24 -0
- package/ios/vendor/AuthonWallet/Wallet/WalletAPI.swift +19 -8
- package/ios/vendor/AuthonWallet/Wallet/WalletOps.swift +101 -2
- package/ios/vendor/AuthonWallet/WalletError.swift +32 -2
- package/ios/vendor/CKeccak/README.md +6 -3
- package/ios/vendor/CKeccak/include/ckeccak.h +4 -0
- package/ios/vendor/CKeccak/ripemd160.c +343 -0
- package/ios/vendor/CKeccak/ripemd160.h +22 -0
- package/ios/vendor/CMonocypher/LICENCE.md +173 -0
- package/ios/vendor/CMonocypher/README.md +27 -0
- package/ios/vendor/CMonocypher/include/monocypher-ed25519.h +140 -0
- package/ios/vendor/CMonocypher/include/monocypher.h +321 -0
- package/ios/vendor/CMonocypher/monocypher-ed25519.c +500 -0
- package/ios/vendor/CMonocypher/monocypher.c +2956 -0
- package/ios/vendor/GENERATED.md +1 -1
- package/package.json +3 -2
- package/src/client.ts +90 -6
- package/src/errors.ts +7 -1
- package/src/index.ts +5 -0
- package/src/native.ts +4 -2
- package/src/types.ts +52 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Monocypher as a whole is dual-licensed. Choose whichever licence you
|
|
2
|
+
want from the two licences listed below.
|
|
3
|
+
|
|
4
|
+
The first licence is a regular 2-clause BSD licence. The second licence
|
|
5
|
+
is the CC-0 from Creative Commons. It is intended to release Monocypher
|
|
6
|
+
to the public domain. The BSD licence serves as a fallback option.
|
|
7
|
+
|
|
8
|
+
See the individual files for specific information about who contributed
|
|
9
|
+
to what file during which years. See below for special notes.
|
|
10
|
+
|
|
11
|
+
Licence 1 (2-clause BSD)
|
|
12
|
+
------------------------
|
|
13
|
+
|
|
14
|
+
Copyright (c) 2017-2023, Loup Vaillant
|
|
15
|
+
Copyright (c) 2017-2019, Michael Savage
|
|
16
|
+
Copyright (c) 2017-2023, Fabio Scotoni
|
|
17
|
+
All rights reserved.
|
|
18
|
+
|
|
19
|
+
Redistribution and use in source and binary forms, with or without
|
|
20
|
+
modification, are permitted provided that the following conditions are
|
|
21
|
+
met:
|
|
22
|
+
|
|
23
|
+
1. Redistributions of source code must retain the above copyright
|
|
24
|
+
notice, this list of conditions and the following disclaimer.
|
|
25
|
+
|
|
26
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
27
|
+
notice, this list of conditions and the following disclaimer in the
|
|
28
|
+
documentation and/or other materials provided with the
|
|
29
|
+
distribution.
|
|
30
|
+
|
|
31
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
32
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
33
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
34
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
35
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
36
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
37
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
38
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
39
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
40
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
41
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Licence 2 (CC-0)
|
|
45
|
+
----------------
|
|
46
|
+
|
|
47
|
+
> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
48
|
+
> LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
49
|
+
> ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
50
|
+
> INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
51
|
+
> REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
52
|
+
> PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
53
|
+
> THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
54
|
+
> HEREUNDER.
|
|
55
|
+
|
|
56
|
+
### Statement of Purpose
|
|
57
|
+
|
|
58
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
59
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
60
|
+
and subsequent owner(s) (each and all, an "owner") of an original work
|
|
61
|
+
of authorship and/or a database (each, a "Work").
|
|
62
|
+
|
|
63
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
64
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
65
|
+
scientific works ("Commons") that the public can reliably and without
|
|
66
|
+
fear of later claims of infringement build upon, modify, incorporate in
|
|
67
|
+
other works, reuse and redistribute as freely as possible in any form
|
|
68
|
+
whatsoever and for any purposes, including without limitation commercial
|
|
69
|
+
purposes. These owners may contribute to the Commons to promote the
|
|
70
|
+
ideal of a free culture and the further production of creative, cultural
|
|
71
|
+
and scientific works, or to gain reputation or greater distribution for
|
|
72
|
+
their Work in part through the use and efforts of others.
|
|
73
|
+
|
|
74
|
+
For these and/or other purposes and motivations, and without any
|
|
75
|
+
expectation of additional consideration or compensation, the person
|
|
76
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or
|
|
77
|
+
she is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
78
|
+
elects to apply CC0 to the Work and publicly distribute the Work under
|
|
79
|
+
its terms, with knowledge of his or her Copyright and Related Rights in
|
|
80
|
+
the Work and the meaning and intended legal effect of CC0 on those
|
|
81
|
+
rights.
|
|
82
|
+
|
|
83
|
+
1. **Copyright and Related Rights.** A Work made available under CC0 may
|
|
84
|
+
be protected by copyright and related or neighboring rights
|
|
85
|
+
("Copyright and Related Rights"). Copyright and Related Rights
|
|
86
|
+
include, but are not limited to, the following:
|
|
87
|
+
|
|
88
|
+
- the right to reproduce, adapt, distribute, perform, display,
|
|
89
|
+
communicate, and translate a Work;
|
|
90
|
+
- moral rights retained by the original author(s) and/or
|
|
91
|
+
performer(s); publicity and privacy rights pertaining to a person's
|
|
92
|
+
image or likeness depicted in a Work;
|
|
93
|
+
- rights protecting against unfair competition in regards to a Work,
|
|
94
|
+
subject to the limitations in paragraph 4(a), below;
|
|
95
|
+
- rights protecting the extraction, dissemination, use and reuse of
|
|
96
|
+
data in a Work;
|
|
97
|
+
- database rights (such as those arising under Directive 96/9/EC of
|
|
98
|
+
the European Parliament and of the Council of 11 March 1996 on the
|
|
99
|
+
legal protection of databases, and under any national
|
|
100
|
+
implementation thereof, including any amended or successor version
|
|
101
|
+
of such directive); and
|
|
102
|
+
- other similar, equivalent or corresponding rights throughout the
|
|
103
|
+
world based on applicable law or treaty, and any national
|
|
104
|
+
implementations thereof.
|
|
105
|
+
|
|
106
|
+
2. **Waiver.** To the greatest extent permitted by, but not in
|
|
107
|
+
contravention of, applicable law, Affirmer hereby overtly, fully,
|
|
108
|
+
permanently, irrevocably and unconditionally waives, abandons, and
|
|
109
|
+
surrenders all of Affirmer's Copyright and Related Rights and
|
|
110
|
+
associated claims and causes of action, whether now known or unknown
|
|
111
|
+
(including existing as well as future claims and causes of action),
|
|
112
|
+
in the Work (i) in all territories worldwide, (ii) for the maximum
|
|
113
|
+
duration provided by applicable law or treaty (including future time
|
|
114
|
+
extensions), (iii) in any current or future medium and for any number
|
|
115
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
116
|
+
limitation commercial, advertising or promotional purposes (the
|
|
117
|
+
"Waiver"). Affirmer makes the Waiver for the benefit of each member
|
|
118
|
+
of the public at large and to the detriment of Affirmer's heirs and
|
|
119
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
120
|
+
revocation, rescission, cancellation, termination, or any other legal
|
|
121
|
+
or equitable action to disrupt the quiet enjoyment of the Work by the
|
|
122
|
+
public as contemplated by Affirmer's express Statement of Purpose.
|
|
123
|
+
|
|
124
|
+
3. **Public License Fallback.** Should any part of the Waiver for any
|
|
125
|
+
reason be judged legally invalid or ineffective under applicable law,
|
|
126
|
+
then the Waiver shall be preserved to the maximum extent permitted
|
|
127
|
+
taking into account Affirmer's express Statement of Purpose. In
|
|
128
|
+
addition, to the extent the Waiver is so judged Affirmer hereby
|
|
129
|
+
grants to each affected person a royalty-free, non transferable, non
|
|
130
|
+
sublicensable, non exclusive, irrevocable and unconditional license
|
|
131
|
+
to exercise Affirmer's Copyright and Related Rights in the Work (i)
|
|
132
|
+
in all territories worldwide, (ii) for the maximum duration provided
|
|
133
|
+
by applicable law or treaty (including future time extensions), (iii)
|
|
134
|
+
in any current or future medium and for any number of copies, and
|
|
135
|
+
(iv) for any purpose whatsoever, including without limitation
|
|
136
|
+
commercial, advertising or promotional purposes (the "License"). The
|
|
137
|
+
License shall be deemed effective as of the date CC0 was applied by
|
|
138
|
+
Affirmer to the Work. Should any part of the License for any reason
|
|
139
|
+
be judged legally invalid or ineffective under applicable law, such
|
|
140
|
+
partial invalidity or ineffectiveness shall not invalidate the
|
|
141
|
+
remainder of the License, and in such case Affirmer hereby affirms
|
|
142
|
+
that he or she will not (i) exercise any of his or her remaining
|
|
143
|
+
Copyright and Related Rights in the Work or (ii) assert any
|
|
144
|
+
associated claims and causes of action with respect to the Work, in
|
|
145
|
+
either case contrary to Affirmer's express Statement of Purpose.
|
|
146
|
+
|
|
147
|
+
4. **Limitations and Disclaimers.**
|
|
148
|
+
|
|
149
|
+
- No trademark or patent rights held by Affirmer are waived,
|
|
150
|
+
abandoned, surrendered, licensed or otherwise affected by this
|
|
151
|
+
document.
|
|
152
|
+
- Affirmer offers the Work as-is and makes no representations or
|
|
153
|
+
warranties of any kind concerning the Work, express, implied,
|
|
154
|
+
statutory or otherwise, including without limitation warranties of
|
|
155
|
+
title, merchantability, fitness for a particular purpose, non
|
|
156
|
+
infringement, or the absence of latent or other defects, accuracy,
|
|
157
|
+
or the present or absence of errors, whether or not discoverable,
|
|
158
|
+
all to the greatest extent permissible under applicable law.
|
|
159
|
+
- Affirmer disclaims responsibility for clearing rights of other
|
|
160
|
+
persons that may apply to the Work or any use thereof, including
|
|
161
|
+
without limitation any person's Copyright and Related Rights in the
|
|
162
|
+
Work. Further, Affirmer disclaims responsibility for obtaining any
|
|
163
|
+
necessary consents, permissions or other rights required for any
|
|
164
|
+
use of the Work.
|
|
165
|
+
- Affirmer understands and acknowledges that Creative Commons is not
|
|
166
|
+
a party to this document and has no duty or obligation with respect
|
|
167
|
+
to this CC0 or use of the Work.
|
|
168
|
+
|
|
169
|
+
Special notes
|
|
170
|
+
-------------
|
|
171
|
+
|
|
172
|
+
The files in `tests/externals/` were placed in the public domain by
|
|
173
|
+
their respective authors. See the `AUTHORS.md` files in each directory.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# CMonocypher
|
|
2
|
+
|
|
3
|
+
Monocypher **4.0.2** (BSD-2-Clause or CC0, see LICENCE.md; audited by Cure53 in 2017), vendored for
|
|
4
|
+
deterministic Ed25519 (RFC 8032) Solana signatures. CryptoKit's `Curve25519.Signing` is not used for
|
|
5
|
+
signing because its signatures are randomized, so they would not equal the web frame's byte for byte;
|
|
6
|
+
CryptoKit still derives and verifies the public keys.
|
|
7
|
+
|
|
8
|
+
- Source tarball: https://github.com/LoupVaillant/Monocypher/archive/refs/tags/4.0.2.tar.gz
|
|
9
|
+
- Tarball SHA-256: `bc1ca30b1b2654e4e7daf2492c0d204200e55137f23fda6b7142fd7d523bd6b4`
|
|
10
|
+
- Copied unchanged:
|
|
11
|
+
|
|
12
|
+
| File | From | SHA-256 |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| monocypher.c | src/monocypher.c | 02174117935699d418443c75a558a287deb06ef8cf7c1adced61d9047d2f323d |
|
|
15
|
+
| monocypher-ed25519.c | src/optional/monocypher-ed25519.c | 97d581639dfa72be08a6d57deb7d79b736be001cb416819cab196d22559d242b |
|
|
16
|
+
| include/monocypher.h | src/monocypher.h | fcaf6ed771358bb4f40fba016f6518ae86ec02b1b877d2cc35ad92d3a26fd7b3 |
|
|
17
|
+
| include/monocypher-ed25519.h | src/optional/monocypher-ed25519.h | 3a3035181f991a158d0e1c7567258f0bae8ba0f1f23c5512b4a1db1b3c9730ce |
|
|
18
|
+
| LICENCE.md | LICENCE.md | a5781770269d2516e52ba4863f790c10a16da4089a1e81823aee19ff1e9026b0 |
|
|
19
|
+
|
|
20
|
+
## Building outside SwiftPM (CocoaPods)
|
|
21
|
+
|
|
22
|
+
Self-contained; no defines, flags or header search paths.
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
s.source_files = 'CMonocypher/*.c', 'CMonocypher/include/*.h'
|
|
26
|
+
s.public_header_files = 'CMonocypher/include/*.h'
|
|
27
|
+
```
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Monocypher version __git__
|
|
2
|
+
//
|
|
3
|
+
// This file is dual-licensed. Choose whichever licence you want from
|
|
4
|
+
// the two licences listed below.
|
|
5
|
+
//
|
|
6
|
+
// The first licence is a regular 2-clause BSD licence. The second licence
|
|
7
|
+
// is the CC-0 from Creative Commons. It is intended to release Monocypher
|
|
8
|
+
// to the public domain. The BSD licence serves as a fallback option.
|
|
9
|
+
//
|
|
10
|
+
// SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
|
|
11
|
+
//
|
|
12
|
+
// ------------------------------------------------------------------------
|
|
13
|
+
//
|
|
14
|
+
// Copyright (c) 2017-2019, Loup Vaillant
|
|
15
|
+
// All rights reserved.
|
|
16
|
+
//
|
|
17
|
+
//
|
|
18
|
+
// Redistribution and use in source and binary forms, with or without
|
|
19
|
+
// modification, are permitted provided that the following conditions are
|
|
20
|
+
// met:
|
|
21
|
+
//
|
|
22
|
+
// 1. Redistributions of source code must retain the above copyright
|
|
23
|
+
// notice, this list of conditions and the following disclaimer.
|
|
24
|
+
//
|
|
25
|
+
// 2. Redistributions in binary form must reproduce the above copyright
|
|
26
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
27
|
+
// documentation and/or other materials provided with the
|
|
28
|
+
// distribution.
|
|
29
|
+
//
|
|
30
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
31
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
32
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
33
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
34
|
+
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
35
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
36
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
37
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
38
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
39
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
40
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
41
|
+
//
|
|
42
|
+
// ------------------------------------------------------------------------
|
|
43
|
+
//
|
|
44
|
+
// Written in 2017-2019 by Loup Vaillant
|
|
45
|
+
//
|
|
46
|
+
// To the extent possible under law, the author(s) have dedicated all copyright
|
|
47
|
+
// and related neighboring rights to this software to the public domain
|
|
48
|
+
// worldwide. This software is distributed without any warranty.
|
|
49
|
+
//
|
|
50
|
+
// You should have received a copy of the CC0 Public Domain Dedication along
|
|
51
|
+
// with this software. If not, see
|
|
52
|
+
// <https://creativecommons.org/publicdomain/zero/1.0/>
|
|
53
|
+
|
|
54
|
+
#ifndef ED25519_H
|
|
55
|
+
#define ED25519_H
|
|
56
|
+
|
|
57
|
+
#include "monocypher.h"
|
|
58
|
+
|
|
59
|
+
#ifdef MONOCYPHER_CPP_NAMESPACE
|
|
60
|
+
namespace MONOCYPHER_CPP_NAMESPACE {
|
|
61
|
+
#elif defined(__cplusplus)
|
|
62
|
+
extern "C" {
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
////////////////////////
|
|
66
|
+
/// Type definitions ///
|
|
67
|
+
////////////////////////
|
|
68
|
+
|
|
69
|
+
// Do not rely on the size or content on any of those types,
|
|
70
|
+
// they may change without notice.
|
|
71
|
+
typedef struct {
|
|
72
|
+
uint64_t hash[8];
|
|
73
|
+
uint64_t input[16];
|
|
74
|
+
uint64_t input_size[2];
|
|
75
|
+
size_t input_idx;
|
|
76
|
+
} crypto_sha512_ctx;
|
|
77
|
+
|
|
78
|
+
typedef struct {
|
|
79
|
+
uint8_t key[128];
|
|
80
|
+
crypto_sha512_ctx ctx;
|
|
81
|
+
} crypto_sha512_hmac_ctx;
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
// SHA 512
|
|
85
|
+
// -------
|
|
86
|
+
void crypto_sha512_init (crypto_sha512_ctx *ctx);
|
|
87
|
+
void crypto_sha512_update(crypto_sha512_ctx *ctx,
|
|
88
|
+
const uint8_t *message, size_t message_size);
|
|
89
|
+
void crypto_sha512_final (crypto_sha512_ctx *ctx, uint8_t hash[64]);
|
|
90
|
+
void crypto_sha512(uint8_t hash[64],
|
|
91
|
+
const uint8_t *message, size_t message_size);
|
|
92
|
+
|
|
93
|
+
// SHA 512 HMAC
|
|
94
|
+
// ------------
|
|
95
|
+
void crypto_sha512_hmac_init(crypto_sha512_hmac_ctx *ctx,
|
|
96
|
+
const uint8_t *key, size_t key_size);
|
|
97
|
+
void crypto_sha512_hmac_update(crypto_sha512_hmac_ctx *ctx,
|
|
98
|
+
const uint8_t *message, size_t message_size);
|
|
99
|
+
void crypto_sha512_hmac_final(crypto_sha512_hmac_ctx *ctx, uint8_t hmac[64]);
|
|
100
|
+
void crypto_sha512_hmac(uint8_t hmac[64],
|
|
101
|
+
const uint8_t *key , size_t key_size,
|
|
102
|
+
const uint8_t *message, size_t message_size);
|
|
103
|
+
|
|
104
|
+
// SHA 512 HKDF
|
|
105
|
+
// ------------
|
|
106
|
+
void crypto_sha512_hkdf_expand(uint8_t *okm, size_t okm_size,
|
|
107
|
+
const uint8_t *prk, size_t prk_size,
|
|
108
|
+
const uint8_t *info, size_t info_size);
|
|
109
|
+
void crypto_sha512_hkdf(uint8_t *okm , size_t okm_size,
|
|
110
|
+
const uint8_t *ikm , size_t ikm_size,
|
|
111
|
+
const uint8_t *salt, size_t salt_size,
|
|
112
|
+
const uint8_t *info, size_t info_size);
|
|
113
|
+
|
|
114
|
+
// Ed25519
|
|
115
|
+
// -------
|
|
116
|
+
// Signatures (EdDSA with curve25519 + SHA-512)
|
|
117
|
+
// --------------------------------------------
|
|
118
|
+
void crypto_ed25519_key_pair(uint8_t secret_key[64],
|
|
119
|
+
uint8_t public_key[32],
|
|
120
|
+
uint8_t seed[32]);
|
|
121
|
+
void crypto_ed25519_sign(uint8_t signature [64],
|
|
122
|
+
const uint8_t secret_key[64],
|
|
123
|
+
const uint8_t *message, size_t message_size);
|
|
124
|
+
int crypto_ed25519_check(const uint8_t signature [64],
|
|
125
|
+
const uint8_t public_key[32],
|
|
126
|
+
const uint8_t *message, size_t message_size);
|
|
127
|
+
|
|
128
|
+
// Pre-hash variants
|
|
129
|
+
void crypto_ed25519_ph_sign(uint8_t signature [64],
|
|
130
|
+
const uint8_t secret_key [64],
|
|
131
|
+
const uint8_t message_hash[64]);
|
|
132
|
+
int crypto_ed25519_ph_check(const uint8_t signature [64],
|
|
133
|
+
const uint8_t public_key [32],
|
|
134
|
+
const uint8_t message_hash[64]);
|
|
135
|
+
|
|
136
|
+
#ifdef __cplusplus
|
|
137
|
+
}
|
|
138
|
+
#endif
|
|
139
|
+
|
|
140
|
+
#endif // ED25519_H
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// Monocypher version __git__
|
|
2
|
+
//
|
|
3
|
+
// This file is dual-licensed. Choose whichever licence you want from
|
|
4
|
+
// the two licences listed below.
|
|
5
|
+
//
|
|
6
|
+
// The first licence is a regular 2-clause BSD licence. The second licence
|
|
7
|
+
// is the CC-0 from Creative Commons. It is intended to release Monocypher
|
|
8
|
+
// to the public domain. The BSD licence serves as a fallback option.
|
|
9
|
+
//
|
|
10
|
+
// SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
|
|
11
|
+
//
|
|
12
|
+
// ------------------------------------------------------------------------
|
|
13
|
+
//
|
|
14
|
+
// Copyright (c) 2017-2019, Loup Vaillant
|
|
15
|
+
// All rights reserved.
|
|
16
|
+
//
|
|
17
|
+
//
|
|
18
|
+
// Redistribution and use in source and binary forms, with or without
|
|
19
|
+
// modification, are permitted provided that the following conditions are
|
|
20
|
+
// met:
|
|
21
|
+
//
|
|
22
|
+
// 1. Redistributions of source code must retain the above copyright
|
|
23
|
+
// notice, this list of conditions and the following disclaimer.
|
|
24
|
+
//
|
|
25
|
+
// 2. Redistributions in binary form must reproduce the above copyright
|
|
26
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
27
|
+
// documentation and/or other materials provided with the
|
|
28
|
+
// distribution.
|
|
29
|
+
//
|
|
30
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
31
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
32
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
33
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
34
|
+
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
35
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
36
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
37
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
38
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
39
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
40
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
41
|
+
//
|
|
42
|
+
// ------------------------------------------------------------------------
|
|
43
|
+
//
|
|
44
|
+
// Written in 2017-2019 by Loup Vaillant
|
|
45
|
+
//
|
|
46
|
+
// To the extent possible under law, the author(s) have dedicated all copyright
|
|
47
|
+
// and related neighboring rights to this software to the public domain
|
|
48
|
+
// worldwide. This software is distributed without any warranty.
|
|
49
|
+
//
|
|
50
|
+
// You should have received a copy of the CC0 Public Domain Dedication along
|
|
51
|
+
// with this software. If not, see
|
|
52
|
+
// <https://creativecommons.org/publicdomain/zero/1.0/>
|
|
53
|
+
|
|
54
|
+
#ifndef MONOCYPHER_H
|
|
55
|
+
#define MONOCYPHER_H
|
|
56
|
+
|
|
57
|
+
#include <stddef.h>
|
|
58
|
+
#include <stdint.h>
|
|
59
|
+
|
|
60
|
+
#ifdef MONOCYPHER_CPP_NAMESPACE
|
|
61
|
+
namespace MONOCYPHER_CPP_NAMESPACE {
|
|
62
|
+
#elif defined(__cplusplus)
|
|
63
|
+
extern "C" {
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
// Constant time comparisons
|
|
67
|
+
// -------------------------
|
|
68
|
+
|
|
69
|
+
// Return 0 if a and b are equal, -1 otherwise
|
|
70
|
+
int crypto_verify16(const uint8_t a[16], const uint8_t b[16]);
|
|
71
|
+
int crypto_verify32(const uint8_t a[32], const uint8_t b[32]);
|
|
72
|
+
int crypto_verify64(const uint8_t a[64], const uint8_t b[64]);
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
// Erase sensitive data
|
|
76
|
+
// --------------------
|
|
77
|
+
void crypto_wipe(void *secret, size_t size);
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
// Authenticated encryption
|
|
81
|
+
// ------------------------
|
|
82
|
+
void crypto_aead_lock(uint8_t *cipher_text,
|
|
83
|
+
uint8_t mac [16],
|
|
84
|
+
const uint8_t key [32],
|
|
85
|
+
const uint8_t nonce[24],
|
|
86
|
+
const uint8_t *ad, size_t ad_size,
|
|
87
|
+
const uint8_t *plain_text, size_t text_size);
|
|
88
|
+
int crypto_aead_unlock(uint8_t *plain_text,
|
|
89
|
+
const uint8_t mac [16],
|
|
90
|
+
const uint8_t key [32],
|
|
91
|
+
const uint8_t nonce[24],
|
|
92
|
+
const uint8_t *ad, size_t ad_size,
|
|
93
|
+
const uint8_t *cipher_text, size_t text_size);
|
|
94
|
+
|
|
95
|
+
// Authenticated stream
|
|
96
|
+
// --------------------
|
|
97
|
+
typedef struct {
|
|
98
|
+
uint64_t counter;
|
|
99
|
+
uint8_t key[32];
|
|
100
|
+
uint8_t nonce[8];
|
|
101
|
+
} crypto_aead_ctx;
|
|
102
|
+
|
|
103
|
+
void crypto_aead_init_x(crypto_aead_ctx *ctx,
|
|
104
|
+
const uint8_t key[32], const uint8_t nonce[24]);
|
|
105
|
+
void crypto_aead_init_djb(crypto_aead_ctx *ctx,
|
|
106
|
+
const uint8_t key[32], const uint8_t nonce[8]);
|
|
107
|
+
void crypto_aead_init_ietf(crypto_aead_ctx *ctx,
|
|
108
|
+
const uint8_t key[32], const uint8_t nonce[12]);
|
|
109
|
+
|
|
110
|
+
void crypto_aead_write(crypto_aead_ctx *ctx,
|
|
111
|
+
uint8_t *cipher_text,
|
|
112
|
+
uint8_t mac[16],
|
|
113
|
+
const uint8_t *ad , size_t ad_size,
|
|
114
|
+
const uint8_t *plain_text, size_t text_size);
|
|
115
|
+
int crypto_aead_read(crypto_aead_ctx *ctx,
|
|
116
|
+
uint8_t *plain_text,
|
|
117
|
+
const uint8_t mac[16],
|
|
118
|
+
const uint8_t *ad , size_t ad_size,
|
|
119
|
+
const uint8_t *cipher_text, size_t text_size);
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
// General purpose hash (BLAKE2b)
|
|
123
|
+
// ------------------------------
|
|
124
|
+
|
|
125
|
+
// Direct interface
|
|
126
|
+
void crypto_blake2b(uint8_t *hash, size_t hash_size,
|
|
127
|
+
const uint8_t *message, size_t message_size);
|
|
128
|
+
|
|
129
|
+
void crypto_blake2b_keyed(uint8_t *hash, size_t hash_size,
|
|
130
|
+
const uint8_t *key, size_t key_size,
|
|
131
|
+
const uint8_t *message, size_t message_size);
|
|
132
|
+
|
|
133
|
+
// Incremental interface
|
|
134
|
+
typedef struct {
|
|
135
|
+
// Do not rely on the size or contents of this type,
|
|
136
|
+
// for they may change without notice.
|
|
137
|
+
uint64_t hash[8];
|
|
138
|
+
uint64_t input_offset[2];
|
|
139
|
+
uint64_t input[16];
|
|
140
|
+
size_t input_idx;
|
|
141
|
+
size_t hash_size;
|
|
142
|
+
} crypto_blake2b_ctx;
|
|
143
|
+
|
|
144
|
+
void crypto_blake2b_init(crypto_blake2b_ctx *ctx, size_t hash_size);
|
|
145
|
+
void crypto_blake2b_keyed_init(crypto_blake2b_ctx *ctx, size_t hash_size,
|
|
146
|
+
const uint8_t *key, size_t key_size);
|
|
147
|
+
void crypto_blake2b_update(crypto_blake2b_ctx *ctx,
|
|
148
|
+
const uint8_t *message, size_t message_size);
|
|
149
|
+
void crypto_blake2b_final(crypto_blake2b_ctx *ctx, uint8_t *hash);
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
// Password key derivation (Argon2)
|
|
153
|
+
// --------------------------------
|
|
154
|
+
#define CRYPTO_ARGON2_D 0
|
|
155
|
+
#define CRYPTO_ARGON2_I 1
|
|
156
|
+
#define CRYPTO_ARGON2_ID 2
|
|
157
|
+
|
|
158
|
+
typedef struct {
|
|
159
|
+
uint32_t algorithm; // Argon2d, Argon2i, Argon2id
|
|
160
|
+
uint32_t nb_blocks; // memory hardness, >= 8 * nb_lanes
|
|
161
|
+
uint32_t nb_passes; // CPU hardness, >= 1 (>= 3 recommended for Argon2i)
|
|
162
|
+
uint32_t nb_lanes; // parallelism level (single threaded anyway)
|
|
163
|
+
} crypto_argon2_config;
|
|
164
|
+
|
|
165
|
+
typedef struct {
|
|
166
|
+
const uint8_t *pass;
|
|
167
|
+
const uint8_t *salt;
|
|
168
|
+
uint32_t pass_size;
|
|
169
|
+
uint32_t salt_size; // 16 bytes recommended
|
|
170
|
+
} crypto_argon2_inputs;
|
|
171
|
+
|
|
172
|
+
typedef struct {
|
|
173
|
+
const uint8_t *key; // may be NULL if no key
|
|
174
|
+
const uint8_t *ad; // may be NULL if no additional data
|
|
175
|
+
uint32_t key_size; // 0 if no key (32 bytes recommended otherwise)
|
|
176
|
+
uint32_t ad_size; // 0 if no additional data
|
|
177
|
+
} crypto_argon2_extras;
|
|
178
|
+
|
|
179
|
+
extern const crypto_argon2_extras crypto_argon2_no_extras;
|
|
180
|
+
|
|
181
|
+
void crypto_argon2(uint8_t *hash, uint32_t hash_size, void *work_area,
|
|
182
|
+
crypto_argon2_config config,
|
|
183
|
+
crypto_argon2_inputs inputs,
|
|
184
|
+
crypto_argon2_extras extras);
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
// Key exchange (X-25519)
|
|
188
|
+
// ----------------------
|
|
189
|
+
|
|
190
|
+
// Shared secrets are not quite random.
|
|
191
|
+
// Hash them to derive an actual shared key.
|
|
192
|
+
void crypto_x25519_public_key(uint8_t public_key[32],
|
|
193
|
+
const uint8_t secret_key[32]);
|
|
194
|
+
void crypto_x25519(uint8_t raw_shared_secret[32],
|
|
195
|
+
const uint8_t your_secret_key [32],
|
|
196
|
+
const uint8_t their_public_key [32]);
|
|
197
|
+
|
|
198
|
+
// Conversion to EdDSA
|
|
199
|
+
void crypto_x25519_to_eddsa(uint8_t eddsa[32], const uint8_t x25519[32]);
|
|
200
|
+
|
|
201
|
+
// scalar "division"
|
|
202
|
+
// Used for OPRF. Be aware that exponential blinding is less secure
|
|
203
|
+
// than Diffie-Hellman key exchange.
|
|
204
|
+
void crypto_x25519_inverse(uint8_t blind_salt [32],
|
|
205
|
+
const uint8_t private_key[32],
|
|
206
|
+
const uint8_t curve_point[32]);
|
|
207
|
+
|
|
208
|
+
// "Dirty" versions of x25519_public_key().
|
|
209
|
+
// Use with crypto_elligator_rev().
|
|
210
|
+
// Leaks 3 bits of the private key.
|
|
211
|
+
void crypto_x25519_dirty_small(uint8_t pk[32], const uint8_t sk[32]);
|
|
212
|
+
void crypto_x25519_dirty_fast (uint8_t pk[32], const uint8_t sk[32]);
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
// Signatures
|
|
216
|
+
// ----------
|
|
217
|
+
|
|
218
|
+
// EdDSA with curve25519 + BLAKE2b
|
|
219
|
+
void crypto_eddsa_key_pair(uint8_t secret_key[64],
|
|
220
|
+
uint8_t public_key[32],
|
|
221
|
+
uint8_t seed[32]);
|
|
222
|
+
void crypto_eddsa_sign(uint8_t signature [64],
|
|
223
|
+
const uint8_t secret_key[64],
|
|
224
|
+
const uint8_t *message, size_t message_size);
|
|
225
|
+
int crypto_eddsa_check(const uint8_t signature [64],
|
|
226
|
+
const uint8_t public_key[32],
|
|
227
|
+
const uint8_t *message, size_t message_size);
|
|
228
|
+
|
|
229
|
+
// Conversion to X25519
|
|
230
|
+
void crypto_eddsa_to_x25519(uint8_t x25519[32], const uint8_t eddsa[32]);
|
|
231
|
+
|
|
232
|
+
// EdDSA building blocks
|
|
233
|
+
void crypto_eddsa_trim_scalar(uint8_t out[32], const uint8_t in[32]);
|
|
234
|
+
void crypto_eddsa_reduce(uint8_t reduced[32], const uint8_t expanded[64]);
|
|
235
|
+
void crypto_eddsa_mul_add(uint8_t r[32],
|
|
236
|
+
const uint8_t a[32],
|
|
237
|
+
const uint8_t b[32],
|
|
238
|
+
const uint8_t c[32]);
|
|
239
|
+
void crypto_eddsa_scalarbase(uint8_t point[32], const uint8_t scalar[32]);
|
|
240
|
+
int crypto_eddsa_check_equation(const uint8_t signature[64],
|
|
241
|
+
const uint8_t public_key[32],
|
|
242
|
+
const uint8_t h_ram[32]);
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
// Chacha20
|
|
246
|
+
// --------
|
|
247
|
+
|
|
248
|
+
// Specialised hash.
|
|
249
|
+
// Used to hash X25519 shared secrets.
|
|
250
|
+
void crypto_chacha20_h(uint8_t out[32],
|
|
251
|
+
const uint8_t key[32],
|
|
252
|
+
const uint8_t in [16]);
|
|
253
|
+
|
|
254
|
+
// Unauthenticated stream cipher.
|
|
255
|
+
// Don't forget to add authentication.
|
|
256
|
+
uint64_t crypto_chacha20_djb(uint8_t *cipher_text,
|
|
257
|
+
const uint8_t *plain_text,
|
|
258
|
+
size_t text_size,
|
|
259
|
+
const uint8_t key[32],
|
|
260
|
+
const uint8_t nonce[8],
|
|
261
|
+
uint64_t ctr);
|
|
262
|
+
uint32_t crypto_chacha20_ietf(uint8_t *cipher_text,
|
|
263
|
+
const uint8_t *plain_text,
|
|
264
|
+
size_t text_size,
|
|
265
|
+
const uint8_t key[32],
|
|
266
|
+
const uint8_t nonce[12],
|
|
267
|
+
uint32_t ctr);
|
|
268
|
+
uint64_t crypto_chacha20_x(uint8_t *cipher_text,
|
|
269
|
+
const uint8_t *plain_text,
|
|
270
|
+
size_t text_size,
|
|
271
|
+
const uint8_t key[32],
|
|
272
|
+
const uint8_t nonce[24],
|
|
273
|
+
uint64_t ctr);
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
// Poly 1305
|
|
277
|
+
// ---------
|
|
278
|
+
|
|
279
|
+
// This is a *one time* authenticator.
|
|
280
|
+
// Disclosing the mac reveals the key.
|
|
281
|
+
// See crypto_lock() on how to use it properly.
|
|
282
|
+
|
|
283
|
+
// Direct interface
|
|
284
|
+
void crypto_poly1305(uint8_t mac[16],
|
|
285
|
+
const uint8_t *message, size_t message_size,
|
|
286
|
+
const uint8_t key[32]);
|
|
287
|
+
|
|
288
|
+
// Incremental interface
|
|
289
|
+
typedef struct {
|
|
290
|
+
// Do not rely on the size or contents of this type,
|
|
291
|
+
// for they may change without notice.
|
|
292
|
+
uint8_t c[16]; // chunk of the message
|
|
293
|
+
size_t c_idx; // How many bytes are there in the chunk.
|
|
294
|
+
uint32_t r [4]; // constant multiplier (from the secret key)
|
|
295
|
+
uint32_t pad[4]; // random number added at the end (from the secret key)
|
|
296
|
+
uint32_t h [5]; // accumulated hash
|
|
297
|
+
} crypto_poly1305_ctx;
|
|
298
|
+
|
|
299
|
+
void crypto_poly1305_init (crypto_poly1305_ctx *ctx, const uint8_t key[32]);
|
|
300
|
+
void crypto_poly1305_update(crypto_poly1305_ctx *ctx,
|
|
301
|
+
const uint8_t *message, size_t message_size);
|
|
302
|
+
void crypto_poly1305_final (crypto_poly1305_ctx *ctx, uint8_t mac[16]);
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
// Elligator 2
|
|
306
|
+
// -----------
|
|
307
|
+
|
|
308
|
+
// Elligator mappings proper
|
|
309
|
+
void crypto_elligator_map(uint8_t curve [32], const uint8_t hidden[32]);
|
|
310
|
+
int crypto_elligator_rev(uint8_t hidden[32], const uint8_t curve [32],
|
|
311
|
+
uint8_t tweak);
|
|
312
|
+
|
|
313
|
+
// Easy to use key pair generation
|
|
314
|
+
void crypto_elligator_key_pair(uint8_t hidden[32], uint8_t secret_key[32],
|
|
315
|
+
uint8_t seed[32]);
|
|
316
|
+
|
|
317
|
+
#ifdef __cplusplus
|
|
318
|
+
}
|
|
319
|
+
#endif
|
|
320
|
+
|
|
321
|
+
#endif // MONOCYPHER_H
|