Skip to content

Commit 39d8dca

Browse files
authored
added ecdsa256 doc (#31)
1 parent 9b406a9 commit 39d8dca

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

docs/getting-started/Overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
The library consists of modules and utilities that are built leveraging [Openzeppelin Contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) (4.9.6) and **go far beyond mediocre solidity**.
88

99
* Implementation of the [**Contracts Registry**](https://eips.ethereum.org/EIPS/eip-6224) pattern
10-
* State-of-the-art cryptography primitives (**ECDSA over 384-bit curves**, **RSASSA-PSS**)
10+
* State-of-the-art cryptography primitives (**ECDSA over 256-bit and 384-bit curves**, **RSASSA-PSS**)
1111
* Advanced data structures (**Vector**, **DynamicSet**, **PriorityQueue**, **AVLTree**)
1212
* ZK-friendly [**Sparse Merkle Tree**](https://docs.iden3.io/publications/pdfs/Merkle-Tree.pdf) and [**Incremental Merkle Tree**](https://github.com/runtimeverification/deposit-contract-verification/blob/master/deposit-contract-verification.pdf) implementations
1313
* Versatile **RBAC** and **MultiOwnable** smart contracts
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# ╭╯ ECDSA256
2+
3+
## Introduction
4+
5+
This library provides functionality for ECDSA verification over any 256-bit curve.
6+
7+
For more information about the logic behind the contract implementation, please refer to the [OpenZeppelin documentation](https://docs.openzeppelin.com/contracts/5.x/api/utils#P256), particularly the [verifySolidity](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.1.0/contracts/utils/cryptography/P256.sol#L102) function.
8+
9+
## Functions
10+
11+
To use the `ECDSA256` library, you need to import it.
12+
13+
```solidity
14+
import "@solarity/solidity-lib/libs/crypto/ECDSA256.sol";
15+
```
16+
17+
And optionally bind it to the type with the `using` statement.
18+
19+
```solidity
20+
using ECDSA256 for *;
21+
```
22+
23+
### verify
24+
25+
```solidity
26+
function verify(
27+
ECDSA256.Parameters memory curveParams_,
28+
bytes32 hashedMessage_,
29+
bytes memory signature_,
30+
bytes memory pubKey_
31+
) internal view returns (bool)
32+
```
33+
34+
#### Description
35+
36+
The function to verify the ECDSA signature
37+
38+
##### Parameters:
39+
40+
<table>
41+
<thead>
42+
<tr>
43+
<th>Name</th>
44+
<th>Type</th>
45+
<th>Description</th>
46+
</tr>
47+
</thead>
48+
<tbody>
49+
<tr>
50+
<td><code>curveParams</code></td>
51+
<td>struct ECDSA256.Parameters</td>
52+
<td>The 256-bit curve parameters. <code>lowSmax</code> is <code>n/2</code></td>
53+
</tr>
54+
<tr>
55+
<td><code>hashedMessage</code></td>
56+
<td>bytes32</td>
57+
<td>The already hashed message to be verified</td>
58+
</tr>
59+
<tr>
60+
<td><code>signature</code></td>
61+
<td>bytes</td>
62+
<td>The ECDSA signature. Equals to <code>bytes(r) + bytes(s)</code></td>
63+
</tr>
64+
<tr>
65+
<td><code>pubKey</code></td>
66+
<td>bytes</td>
67+
<td>The full public key of a signer. Equals to <code>bytes(x) + bytes(y)</code>. Note that signatures only from the lower part of the curve are accepted. If your <code>s > n / 2</code>, change it to <code>s = n - s</code></td>
68+
</tr>
69+
</tbody>
70+
</table>
71+
72+
#### Example
73+
74+
```solidity
75+
function verifySECP256r1(
76+
bytes memory message_,
77+
bytes memory signature_,
78+
bytes memory pubKey_
79+
) external view returns (bool) {
80+
ECDSA256.Parameters memory curveParams_ =
81+
ECDSA256.Parameters({
82+
a: 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC,
83+
b: 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B,
84+
gx: 0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296,
85+
gy: 0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5,
86+
p: 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF,
87+
n: 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551,
88+
lowSmax: 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5617e3192a8
89+
});
90+
91+
return curveParams_.verify(sha256(message_), signature_, pubKey_);
92+
}
93+
```

0 commit comments

Comments
 (0)