Skip to content

Commit 65b9116

Browse files
author
Docs Syncer
committed
CI: d7bb26f
1 parent 6a3bff4 commit 65b9116

File tree

3 files changed

+397
-0
lines changed

3 files changed

+397
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# ECDSA384
2+
3+
## Overview
4+
5+
#### License: MIT
6+
7+
```solidity
8+
library ECDSA384
9+
```
10+
11+
Cryptography module
12+
13+
This library provides functionality for ECDSA verification over any 384-bit curve. Currently,
14+
this is the most efficient implementation out there, consuming ~9 million gas per call.
15+
16+
The approach is Strauss-Shamir double scalar multiplication with 4 bits of precompute + projective points.
17+
## Structs info
18+
19+
### Parameters
20+
21+
```solidity
22+
struct Parameters {
23+
bytes a;
24+
bytes b;
25+
bytes gx;
26+
bytes gy;
27+
bytes p;
28+
bytes n;
29+
bytes lowSmax;
30+
}
31+
```
32+
33+
384-bit curve parameters.
34+
### _Parameters
35+
36+
```solidity
37+
struct _Parameters {
38+
uint256 a;
39+
uint256 b;
40+
uint256 gx;
41+
uint256 gy;
42+
uint256 p;
43+
uint256 n;
44+
uint256 lowSmax;
45+
}
46+
```
47+
48+
49+
### _Inputs
50+
51+
```solidity
52+
struct _Inputs {
53+
uint256 r;
54+
uint256 s;
55+
uint256 x;
56+
uint256 y;
57+
}
58+
```
59+
60+
61+
## Functions info
62+
63+
### verify
64+
65+
```solidity
66+
function verify(
67+
ECDSA384.Parameters memory curveParams_,
68+
bytes memory hashedMessage_,
69+
bytes memory signature_,
70+
bytes memory pubKey_
71+
) internal view returns (bool)
72+
```
73+
74+
The function to verify the ECDSA signature
75+
76+
77+
Parameters:
78+
79+
| Name | Type | Description |
80+
| :------------- | :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
81+
| curveParams_ | struct ECDSA384.Parameters | the 384-bit curve parameters. `lowSmax` is `n / 2`. |
82+
| hashedMessage_ | bytes | the already hashed message to be verified. |
83+
| signature_ | bytes | the ECDSA signature. Equals to `bytes(r) + bytes(s)`. |
84+
| pubKey_ | bytes | the full public key of a signer. Equals to `bytes(x) + bytes(y)`. Note that signatures only from the lower part of the curve are accepted. If your `s >= n / 2`, change it to `s = n - s`. |
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# RSASSAPSS
2+
3+
## Overview
4+
5+
#### License: MIT
6+
7+
```solidity
8+
library RSASSAPSS
9+
```
10+
11+
Cryptography module
12+
13+
This library provides functionality to verify RSASSA-PSS signatures with MGF1 mask generation function.
14+
15+
Users may provide custom hash functions via `Parameters` struct. However, the usage of `sha256` is recommended.
16+
The RSASSA-PSS signature verification costs ~340k gas.
17+
18+
Learn more about the algorithm [here](https://datatracker.ietf.org/doc/html/rfc3447#section-8.1).
19+
## Structs info
20+
21+
### Parameters
22+
23+
```solidity
24+
struct Parameters {
25+
uint256 hashLength;
26+
uint256 saltLength;
27+
function (bytes) pure returns (bytes) hasher;
28+
}
29+
```
30+
31+
The RSASSA-PSS parameters.
32+
33+
34+
Parameters:
35+
36+
| Name | Type | Description |
37+
| :--------- | :------------------------------------ | :---------------------------------------------- |
38+
| hashLength | uint256 | the hash function output length in bytes. |
39+
| saltLength | uint256 | the pss encoding salt length in bytes. |
40+
| hasher | function (bytes) pure returns (bytes) | the function-pointer to a custom hash function. |
41+
42+
## Functions info
43+
44+
### verifySha256
45+
46+
```solidity
47+
function verifySha256(
48+
bytes memory message_,
49+
bytes memory s_,
50+
bytes memory e_,
51+
bytes memory n_
52+
) internal view returns (bool)
53+
```
54+
55+
Same as `verify` but with `sha256` hash function preconfiguration.
56+
### verify
57+
58+
```solidity
59+
function verify(
60+
RSASSAPSS.Parameters memory params_,
61+
bytes memory message_,
62+
bytes memory s_,
63+
bytes memory e_,
64+
bytes memory n_
65+
) internal view returns (bool)
66+
```
67+
68+
Verifies RSAPSS-SSA signature with custom parameters.
69+
70+
71+
Parameters:
72+
73+
| Name | Type | Description |
74+
| :------- | :-------------------------- | :------------------------------------------------------------------------------------ |
75+
| params_ | struct RSASSAPSS.Parameters | The parameters to specify the hash length, salt length, and hash function of choice. |
76+
| message_ | bytes | The arbitrary message to be verified. |
77+
| s_ | bytes | The "encrypted" signature |
78+
| e_ | bytes | The public key exponent. `65537` is a recommended value. |
79+
| n_ | bytes | The modulus of a public key. |
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# U384
2+
3+
## Overview
4+
5+
#### License: MIT
6+
7+
```solidity
8+
library U384
9+
```
10+
11+
Low-level utility library that implements unsigned 384-bit arithmetics.
12+
13+
Should not be used outside of this file.
14+
## Functions info
15+
16+
### init
17+
18+
```solidity
19+
function init(uint256 from_) internal pure returns (uint256 handler_)
20+
```
21+
22+
23+
### init
24+
25+
```solidity
26+
function init(bytes memory from_) internal pure returns (uint256 handler_)
27+
```
28+
29+
30+
### init2
31+
32+
```solidity
33+
function init2(
34+
bytes memory from2_
35+
) internal pure returns (uint256 handler1_, uint256 handler2_)
36+
```
37+
38+
39+
### initCall
40+
41+
```solidity
42+
function initCall(uint256 m_) internal pure returns (uint256 handler_)
43+
```
44+
45+
46+
### copy
47+
48+
```solidity
49+
function copy(uint256 handler_) internal pure returns (uint256 handlerCopy_)
50+
```
51+
52+
53+
### eq
54+
55+
```solidity
56+
function eq(uint256 a_, uint256 b_) internal pure returns (bool eq_)
57+
```
58+
59+
60+
### eqInteger
61+
62+
```solidity
63+
function eqInteger(
64+
uint256 a_,
65+
uint256 bInteger_
66+
) internal pure returns (bool eq_)
67+
```
68+
69+
70+
### cmp
71+
72+
```solidity
73+
function cmp(uint256 a_, uint256 b_) internal pure returns (int256 cmp_)
74+
```
75+
76+
77+
### modexp
78+
79+
```solidity
80+
function modexp(
81+
uint256 call_,
82+
uint256 b_,
83+
uint256 eInteger_
84+
) internal view returns (uint256 r_)
85+
```
86+
87+
88+
### modexpAssign
89+
90+
```solidity
91+
function modexpAssign(
92+
uint256 call_,
93+
uint256 b_,
94+
uint256 eInteger_
95+
) internal view
96+
```
97+
98+
99+
### modexpAssignTo
100+
101+
```solidity
102+
function modexpAssignTo(
103+
uint256 call_,
104+
uint256 to_,
105+
uint256 b_,
106+
uint256 eInteger_
107+
) internal view
108+
```
109+
110+
111+
### modadd
112+
113+
```solidity
114+
function modadd(
115+
uint256 a_,
116+
uint256 b_,
117+
uint256 m_
118+
) internal pure returns (uint256 r_)
119+
```
120+
121+
122+
### modaddAssign
123+
124+
```solidity
125+
function modaddAssign(uint256 a_, uint256 b_, uint256 m_) internal pure
126+
```
127+
128+
129+
### modaddAssignTo
130+
131+
```solidity
132+
function modaddAssignTo(
133+
uint256 to_,
134+
uint256 a_,
135+
uint256 b_,
136+
uint256 m_
137+
) internal pure
138+
```
139+
140+
141+
### modmul
142+
143+
```solidity
144+
function modmul(
145+
uint256 call_,
146+
uint256 a_,
147+
uint256 b_
148+
) internal view returns (uint256 r_)
149+
```
150+
151+
152+
### modmulAssign
153+
154+
```solidity
155+
function modmulAssign(uint256 call_, uint256 a_, uint256 b_) internal view
156+
```
157+
158+
159+
### modmulAssignTo
160+
161+
```solidity
162+
function modmulAssignTo(
163+
uint256 call_,
164+
uint256 to_,
165+
uint256 a_,
166+
uint256 b_
167+
) internal view
168+
```
169+
170+
171+
### sub
172+
173+
```solidity
174+
function sub(uint256 a_, uint256 b_) internal pure returns (uint256 r_)
175+
```
176+
177+
178+
### subAssignTo
179+
180+
```solidity
181+
function subAssignTo(uint256 to_, uint256 a_, uint256 b_) internal pure
182+
```
183+
184+
185+
### modshl1Assign
186+
187+
```solidity
188+
function modshl1Assign(uint256 a_, uint256 m_) internal pure
189+
```
190+
191+
192+
### modshl1AssignTo
193+
194+
```solidity
195+
function modshl1AssignTo(uint256 to_, uint256 a_, uint256 m_) internal pure
196+
```
197+
198+
199+
### moddiv
200+
201+
```solidity
202+
function moddiv(
203+
uint256 call_,
204+
uint256 a_,
205+
uint256 b_,
206+
uint256 m_
207+
) internal view returns (uint256 r_)
208+
```
209+
210+
211+
### modinv
212+
213+
```solidity
214+
function modinv(
215+
uint256 call_,
216+
uint256 b_,
217+
uint256 m_
218+
) internal view returns (uint256 r_)
219+
```
220+
221+
222+
### _shl1
223+
224+
```solidity
225+
function _shl1(uint256 a_, uint256 r_) internal pure
226+
```
227+
228+
229+
### _shl1To
230+
231+
```solidity
232+
function _shl1To(uint256 a_) internal pure
233+
```
234+

0 commit comments

Comments
 (0)