-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BLS12-381 Crypto Primitives #154
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c82a076
added bls12-381 crypto primitives
mschoenebeck 861a86e
removed bls types
mschoenebeck f778277
sync with branch 'main' of https://github.com/AntelopeIO/cdt
mschoenebeck e2bec04
synced with Antelope/main
mschoenebeck 80ef305
fixed submodule
mschoenebeck 5a97108
removed bls types leftovers
mschoenebeck 9142b69
Merge branch 'main' of https://github.com/AntelopeIO/cdt
mschoenebeck 2975faa
update according to leap update
mschoenebeck 21a8221
don't throw but propagate error back to smart contract to be handled …
mschoenebeck 7a6dfcb
added bls integration tests
mschoenebeck 9d1424d
added bls types to enforce correct operand sizes
mschoenebeck 8a18e7a
Merge branch 'main' of https://github.com/AntelopeIO/cdt
mschoenebeck 3f701e2
better fp2 type
mschoenebeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
#include "types.h" | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g1_add(const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g2_add(const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g1_mul(const char* point, uint32_t point_len, const char* scalar, uint32_t scalar_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g2_mul(const char* point, uint32_t point_len, const char* scalar, uint32_t scalar_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g1_exp(const char* points, uint32_t points_len, const char* scalars, uint32_t scalars_len, uint32_t n, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g2_exp(const char* points, uint32_t points_len, const char* scalars, uint32_t scalars_len, uint32_t n, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_pairing(const char* g1_points, uint32_t g1_points_len, const char* g2_points, uint32_t g2_points_len, uint32_t n, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g1_map(const char* e, uint32_t e_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g2_map(const char* e, uint32_t e_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_fp_mod(const char* s, uint32_t s_len, char* res, uint32_t res_len); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#pragma once | ||
|
||
#include "fixed_bytes.hpp" | ||
#include "varint.hpp" | ||
#include "serialize.hpp" | ||
|
||
#include <array> | ||
#include <vector> | ||
|
||
namespace eosio { | ||
|
||
namespace internal_use_do_not_use { | ||
extern "C" { | ||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g1_add(const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g2_add(const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g1_mul(const char* point, uint32_t point_len, const char* scalar, uint32_t scalar_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g2_mul(const char* point, uint32_t point_len, const char* scalar, uint32_t scalar_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g1_exp(const char* points, uint32_t points_len, const char* scalars, uint32_t scalars_len, uint32_t n, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g2_exp(const char* points, uint32_t points_len, const char* scalars, uint32_t scalars_len, uint32_t n, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_pairing(const char* g1_points, uint32_t g1_points_len, const char* g2_points, uint32_t g2_points_len, uint32_t n, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g1_map(const char* e, uint32_t e_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_g2_map(const char* e, uint32_t e_len, char* res, uint32_t res_len); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
int32_t bls_fp_mod(const char* s, uint32_t s_len, char* res, uint32_t res_len); | ||
} | ||
} | ||
|
||
int32_t bls_g1_add(const uint8_t* op1, const uint8_t* op2, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_g1_add(reinterpret_cast<const char*>(op1), 144, reinterpret_cast<const char*>(op2), 144, reinterpret_cast<char*>(res), 144); | ||
} | ||
|
||
int32_t bls_g2_add(const uint8_t* op1, const uint8_t* op2, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_g2_add(reinterpret_cast<const char*>(op1), 288, reinterpret_cast<const char*>(op2), 288, reinterpret_cast<char*>(res), 288); | ||
} | ||
|
||
int32_t bls_g1_mul(const uint8_t* point, const uint8_t* scalar, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_g1_mul(reinterpret_cast<const char*>(point), 144, reinterpret_cast<const char*>(scalar), 32, reinterpret_cast<char*>(res), 144); | ||
} | ||
|
||
int32_t bls_g2_mul(const uint8_t* point, const uint8_t* scalar, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_g2_mul(reinterpret_cast<const char*>(point), 288, reinterpret_cast<const char*>(scalar), 32, reinterpret_cast<char*>(res), 288); | ||
} | ||
|
||
int32_t bls_g1_exp(const uint8_t* points, const uint8_t* scalars, const uint32_t num, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_g1_exp(reinterpret_cast<const char*>(points), num * 144, reinterpret_cast<const char*>(scalars), num * 32, num, reinterpret_cast<char*>(res), 144); | ||
} | ||
|
||
int32_t bls_g2_exp(const uint8_t* points, const uint8_t* scalars, const uint32_t num, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_g2_exp(reinterpret_cast<const char*>(points), num * 288, reinterpret_cast<const char*>(scalars), num * 32, num, reinterpret_cast<char*>(res), 288); | ||
} | ||
|
||
int32_t bls_pairing(const uint8_t* g1_points, const uint8_t* g2_points, const uint32_t num, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_pairing(reinterpret_cast<const char*>(g1_points), num * 144, reinterpret_cast<const char*>(g2_points), num * 288, num, reinterpret_cast<char*>(res), 576); | ||
} | ||
|
||
int32_t bls_g1_map(const uint8_t* e, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_g1_map(reinterpret_cast<const char*>(e), 48, reinterpret_cast<char*>(res), 144); | ||
} | ||
|
||
int32_t bls_g2_map(const uint8_t* e, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_g2_map(reinterpret_cast<const char*>(e), 96, reinterpret_cast<char*>(res), 288); | ||
} | ||
|
||
int32_t bls_fp_mod(const uint8_t* s, uint8_t* res) | ||
{ | ||
return internal_use_do_not_use::bls_fp_mod(reinterpret_cast<const char*>(s), 64, reinterpret_cast<char*>(res), 48); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about something like this? that way you can enforce structure size:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added bls types to enforce correct operand sizes in: mschoenebeck@9d1424d
Edit: Updated https://github.com/mschoenebeck/aggsigtest/blob/main/aggsigtest.cpp as well.