Skip to content

Commit 62a6111

Browse files
committed
Add example EC arithmetic in Jacobian coordinates
1 parent c9eefe8 commit 62a6111

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

README.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,38 @@ If configured correctly, you should be able to add the antelope.ck library to yo
8282
```cpp
8383
#include <ack/ack.hpp>
8484

85-
// Calculate sum of 2 EC points on secp256k1 curve
85+
// Calculate sum of 2 EC points on secp256k1 curve using affine coordinates
8686
const auto p1 = ack::ec_curve::secp256k1.make_point( p1_x, p1_y );
8787
const auto p2 = ack::ec_curve::secp256k1.generate_point( "85d0c2e48955214783ecf50a4f041" );
8888
const auto p3 = p1 + p2;
8989

90-
// triple the p3 point
90+
// Triple the p3 point
9191
const auto p4 = p3 * 3;
9292

93-
// multiply the inverse of p4 by integer 0x73c5f6a67456ae48209b5a32d1b8
93+
// Multiply the inverse of p4 by integer 0x73c5f6a67456ae48209b5a32d1b8
9494
const auto p5 = -p4 * "73c5f6a67456ae48209b5a32d1b8";
95+
96+
// Generate 2 EC points on secp256r1 curve using Jacobi coordinates representation
97+
using secp256r1_t = decltype( ack::ec_curve::secp256r1 );
98+
using point_r1_jacobi = ack::ec_point_fp_jacobi<secp256r1_t>;
99+
100+
const auto p1 = ack::ec_curve::secp256k1.generate_point<point_r1_jacobi>( "5d0c2e48955214783ecf50a4f041" );
101+
const auto p2_affine = ack::ec_curve::secp256k1.make_point( p2_x, p2_y );
102+
const auto p2 = point_r1_jacobi( p2_affine );
103+
104+
// Calculate sum of 2 EC points on secp256r1 curve in Jacobi coordinates
105+
const auto p3 = p1 + p2;
106+
107+
// Double point p3
108+
const auto p4 = p3 * 2; // or p3.doubled();
109+
110+
// Verify point p4 is not identity and lies on the curve
111+
eosio::check( !p4.is_identity(), "invalid point" );
112+
eosio::check( p4.is_on_curve() , "invalid point" );
113+
eosio::check( p4.is_valid() , "invalid point" );
114+
115+
// Convert point p4 to affine coordinates
116+
const auto p4_affine = p4.to_affine();
95117

96118
// Verify secp256k1 ECDSA-SHA256 signature
97119
auto pub_point = ack::ec_curve::secp256k1.make_point( pubkey_x, pubkey_y );

0 commit comments

Comments
 (0)