Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go-bindings/elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ int CG1ElementSize() {
return bls::G1Element::SIZE;
}

CG1Element CG1ElementFromBytes(const void* data, bool* didErr) {
CG1Element CG1ElementFromBytes(const void* data, size_t len, bool* didErr) {
bls::G1Element* el = nullptr;
try {
el = new bls::G1Element(
bls::G1Element::FromBytes(bls::Bytes((uint8_t*)(data), bls::G1Element::SIZE))
bls::G1Element::FromBytes(bls::Bytes((uint8_t*)data, len))
);
} catch(const std::exception& ex) {
gErrMsg = ex.what();
Expand Down Expand Up @@ -93,11 +93,11 @@ int CG2ElementSize() {
return bls::G2Element::SIZE;
}

CG2Element CG2ElementFromBytes(const void* data, bool* didErr) {
CG2Element CG2ElementFromBytes(const void* data, size_t len, bool* didErr) {
bls::G2Element* el = nullptr;
try {
el = new bls::G2Element(
bls::G2Element::FromBytes(bls::Bytes((uint8_t*)data, bls::G2Element::SIZE))
bls::G2Element::FromBytes(bls::Bytes((uint8_t*)data, len))
);
*didErr = false;
} catch(const std::exception& ex) {
Expand Down
4 changes: 2 additions & 2 deletions go-bindings/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func G1ElementFromBytes(data []byte) (*G1Element, error) {
defer C.free(cBytesPtr)
var cDidErr C.bool
el := G1Element{
val: C.CG1ElementFromBytes(cBytesPtr, &cDidErr),
val: C.CG1ElementFromBytes(cBytesPtr, C.size_t(len(data)), &cDidErr),
}
if bool(cDidErr) {
return nil, errFromC()
Expand Down Expand Up @@ -131,7 +131,7 @@ func G2ElementFromBytes(data []byte) (*G2Element, error) {
defer C.free(cBytesPtr)
var cDidErr C.bool
el := G2Element{
val: C.CG2ElementFromBytes(cBytesPtr, &cDidErr),
val: C.CG2ElementFromBytes(cBytesPtr, C.size_t(len(data)), &cDidErr),
}
if bool(cDidErr) {
return nil, errFromC()
Expand Down
4 changes: 2 additions & 2 deletions go-bindings/elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef void* CPrivateKey;

// G1Element
int CG1ElementSize();
CG1Element CG1ElementFromBytes(const void* data, bool* didErr);
CG1Element CG1ElementFromBytes(const void* data, size_t len, bool* didErr);
CG1Element CG1ElementGenerator();
bool CG1ElementIsValid(const CG1Element el);
uint32_t CG1ElementGetFingerprint(const CG1Element el);
Expand All @@ -40,7 +40,7 @@ void CG1ElementFree(const CG1Element el);

// G2Element
int CG2ElementSize();
CG2Element CG2ElementFromBytes(const void* data, bool* didErr);
CG2Element CG2ElementFromBytes(const void* data, size_t len, bool* didErr);
CG2Element CG2ElementGenerator();
bool CG2ElementIsValid(const CG2Element el);
bool CG2ElementIsEqual(const CG2Element el1, const CG2Element el2);
Expand Down
4 changes: 2 additions & 2 deletions go-bindings/privatekey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#include "utils.hpp"

// private key bindings implementation
CPrivateKey CPrivateKeyFromBytes(const void* data, const bool modOrder, bool* didErr) {
CPrivateKey CPrivateKeyFromBytes(const void* data, size_t len, const bool modOrder, bool* didErr) {
bls::PrivateKey* skPtr = nullptr;
try {
skPtr = new bls::PrivateKey(
bls::PrivateKey::FromBytes(
bls::Bytes((uint8_t*)data, bls::PrivateKey::PRIVATE_KEY_SIZE),
bls::Bytes((uint8_t*)data, len),
modOrder
)
);
Expand Down
2 changes: 1 addition & 1 deletion go-bindings/privatekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func PrivateKeyFromBytes(data []byte, modOrder bool) (*PrivateKey, error) {
defer C.SecFree(cBytesPtr)
var cDidErr C.bool
sk := PrivateKey{
val: C.CPrivateKeyFromBytes(cBytesPtr, C.bool(modOrder), &cDidErr),
val: C.CPrivateKeyFromBytes(cBytesPtr, C.size_t(len(data)), C.bool(modOrder), &cDidErr),
}
if bool(cDidErr) {
return nil, errFromC()
Expand Down
2 changes: 1 addition & 1 deletion go-bindings/privatekey.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {

typedef void* CPrivateKey;

CPrivateKey CPrivateKeyFromBytes(const void* data, const bool modOrder, bool* didErr);
CPrivateKey CPrivateKeyFromBytes(const void* data, size_t len, const bool modOrder, bool* didErr);
CPrivateKey CPrivateKeyAggregate(void** sks, const size_t len);
CG1Element CPrivateKeyGetG1Element(const CPrivateKey sk, bool* didErr);
CG2Element CPrivateKeyGetG2Element(const CPrivateKey sk, bool* didErr);
Expand Down
26 changes: 13 additions & 13 deletions python-bindings/pythonbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PYBIND11_MODULE(blspy, m)
}
auto data_ptr = reinterpret_cast<const uint8_t *>(info.ptr);
std::array<uint8_t, PrivateKey::PRIVATE_KEY_SIZE> data;
std::copy(data_ptr, data_ptr + PrivateKey::PRIVATE_KEY_SIZE, data.data());
std::copy(data_ptr, data_ptr + data.size(), data.data());
py::gil_scoped_release release;
return PrivateKey::FromBytes(data);
})
Expand Down Expand Up @@ -360,7 +360,7 @@ PYBIND11_MODULE(blspy, m)
if (_PyLong_AsByteArray(
(PyLongObject *)pyint.ptr(),
buffer.data(),
G1Element::SIZE,
buffer.size(),
0,
0) < 0) {
throw std::invalid_argument("Failed to cast int to G1Element");
Expand All @@ -380,7 +380,7 @@ PYBIND11_MODULE(blspy, m)
}
auto data_ptr = static_cast<uint8_t *>(info.ptr);
std::array<uint8_t, G1Element::SIZE> data;
std::copy(data_ptr, data_ptr + G1Element::SIZE, data.data());
std::copy(data_ptr, data_ptr + data.size(), data.data());
py::gil_scoped_release release;
return G1Element::FromBytes(data);
}))
Expand All @@ -398,7 +398,7 @@ PYBIND11_MODULE(blspy, m)
}
auto data_ptr = reinterpret_cast<const uint8_t *>(info.ptr);
std::array<uint8_t, G1Element::SIZE> data;
std::copy(data_ptr, data_ptr + G1Element::SIZE, data.data());
std::copy(data_ptr, data_ptr + data.size(), data.data());
py::gil_scoped_release release;
return G1Element::FromBytes(data);
})
Expand Down Expand Up @@ -509,7 +509,7 @@ PYBIND11_MODULE(blspy, m)
}
auto data_ptr = static_cast<uint8_t *>(info.ptr);
std::array<uint8_t, G2Element::SIZE> data;
std::copy(data_ptr, data_ptr + G2Element::SIZE, data.data());
std::copy(data_ptr, data_ptr + data.size(), data.data());
py::gil_scoped_release release;
return G2Element::FromBytes(data);
}))
Expand All @@ -518,7 +518,7 @@ PYBIND11_MODULE(blspy, m)
if (_PyLong_AsByteArray(
(PyLongObject *)pyint.ptr(),
buffer.data(),
G2Element::SIZE,
buffer.size(),
0,
0) < 0) {
throw std::invalid_argument("Failed to cast int to G2Element");
Expand All @@ -540,7 +540,7 @@ PYBIND11_MODULE(blspy, m)
}
auto data_ptr = reinterpret_cast<const uint8_t *>(info.ptr);
std::array<uint8_t, G2Element::SIZE> data;
std::copy(data_ptr, data_ptr + G2Element::SIZE, data.data());
std::copy(data_ptr, data_ptr + data.size(), data.data());
py::gil_scoped_release release;
return G2Element::FromBytes(data);
})
Expand Down Expand Up @@ -637,20 +637,20 @@ PYBIND11_MODULE(blspy, m)

if ((int)info.size != GTElement::SIZE) {
throw std::invalid_argument(
"Length of bytes object not equal to G2Element::SIZE");
"Length of bytes object not equal to GTElement::SIZE");
}
auto data_ptr = static_cast<uint8_t *>(info.ptr);
std::array<uint8_t, GTElement::SIZE> data;
std::copy(data_ptr, data_ptr + GTElement::SIZE, data.data());
std::copy(data_ptr, data_ptr + data.size(), data.data());
py::gil_scoped_release release;
return GTElement::FromBytes(data);
}))
.def(py::init([](py::int_ pyint) {
std::array<uint8_t, G1Element::SIZE> buffer{};
std::array<uint8_t, GTElement::SIZE> buffer{};
if (_PyLong_AsByteArray(
(PyLongObject *)pyint.ptr(),
buffer.data(),
GTElement::SIZE,
buffer.size(),
0,
0) < 0) {
throw std::invalid_argument("Failed to cast int to GTElement");
Expand All @@ -672,7 +672,7 @@ PYBIND11_MODULE(blspy, m)
}
auto data_ptr = reinterpret_cast<const uint8_t *>(info.ptr);
std::array<uint8_t, GTElement::SIZE> data;
std::copy(data_ptr, data_ptr + GTElement::SIZE, data.data());
std::copy(data_ptr, data_ptr + data.size(), data.data());
py::gil_scoped_release release;
return GTElement::FromBytes(data);
})
Expand All @@ -690,7 +690,7 @@ PYBIND11_MODULE(blspy, m)
}
auto data_ptr = reinterpret_cast<const uint8_t *>(info.ptr);
std::array<uint8_t, GTElement::SIZE> data;
std::copy(data_ptr, data_ptr + GTElement::SIZE, data.data());
std::copy(data_ptr, data_ptr + data.size(), data.data());
py::gil_scoped_release release;
return GTElement::FromBytesUnchecked(data);
})
Expand Down
5 changes: 5 additions & 0 deletions rust-bindings/bls-dash-sys/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern "C" {

pub fn G1ElementFromBytes(
data: *const ::std::os::raw::c_void,
len: usize,
legacy: bool,
didErr: *mut bool,
) -> G1Element;
Expand Down Expand Up @@ -43,6 +44,7 @@ extern "C" {

pub fn G2ElementFromBytes(
data: *const ::std::os::raw::c_void,
len: usize,
legacy: bool,
didErr: *mut bool,
) -> G2Element;
Expand All @@ -67,6 +69,7 @@ extern "C" {

pub fn PrivateKeyFromBytes(
data: *const ::std::os::raw::c_void,
len: usize,
modOrder: bool,
didErr: *mut bool,
) -> PrivateKey;
Expand Down Expand Up @@ -355,6 +358,7 @@ extern "C" {

pub fn BIP32ExtendedPublicKeyFromBytes(
data: *const ::std::os::raw::c_void,
len: usize,
legacy: bool,
didErr: *mut bool,
) -> BIP32ExtendedPublicKey;
Expand Down Expand Up @@ -385,6 +389,7 @@ extern "C" {

pub fn BIP32ExtendedPrivateKeyFromBytes(
data: *const ::std::os::raw::c_void,
len: usize,
didErr: *mut bool,
) -> BIP32ExtendedPrivateKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include "../error.h"
#include "bls.hpp"

BIP32ExtendedPrivateKey BIP32ExtendedPrivateKeyFromBytes(const void* data, bool* didErr)
BIP32ExtendedPrivateKey BIP32ExtendedPrivateKeyFromBytes(const void* data, size_t len, bool* didErr)
{
bls::ExtendedPrivateKey* el = nullptr;
try {
el = new bls::ExtendedPrivateKey(bls::ExtendedPrivateKey::FromBytes(
bls::Bytes((uint8_t*)(data), bls::ExtendedPrivateKey::SIZE)));
bls::Bytes((uint8_t*)data, len)));
} catch (const std::exception& ex) {
gErrMsg = ex.what();
*didErr = true;
Expand All @@ -26,7 +26,7 @@ BIP32ExtendedPrivateKey BIP32ExtendedPrivateKeyFromSeed(const void* data, const
bls::ExtendedPrivateKey* el = nullptr;
try {
el = new bls::ExtendedPrivateKey(bls::ExtendedPrivateKey::FromSeed(
bls::Bytes((uint8_t*)(data), len)));
bls::Bytes((uint8_t*)data, len)));
} catch (const std::exception& ex) {
gErrMsg = ex.what();
*didErr = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ typedef void* BIP32ExtendedPrivateKey;
// ExtendedPrivateKey
BIP32ExtendedPrivateKey BIP32ExtendedPrivateKeyFromBytes(
const void* data,
size_t len,
bool* didErr);
BIP32ExtendedPrivateKey BIP32ExtendedPrivateKeyFromSeed(const void* data, const size_t len, bool* didErr);
BIP32ExtendedPrivateKey BIP32ExtendedPrivateKeyPrivateChild(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

BIP32ExtendedPublicKey BIP32ExtendedPublicKeyFromBytes(
const void* data,
size_t len,
const bool legacy,
bool* didErr)
{
bls::ExtendedPublicKey* el = nullptr;
try {
el = new bls::ExtendedPublicKey(bls::ExtendedPublicKey::FromBytes(
bls::Bytes((uint8_t*)(data), bls::ExtendedPublicKey::SIZE),
bls::Bytes((uint8_t*)data, len),
legacy));
} catch (const std::exception& ex) {
gErrMsg = ex.what();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef void* BIP32ExtendedPublicKey;
// ExtendedPublicKey
BIP32ExtendedPublicKey BIP32ExtendedPublicKeyFromBytes(
const void* data,
size_t len,
const bool legacy,
bool* didErr);
BIP32ExtendedPublicKey BIP32ExtendedPublicKeyPublicChild(
Expand Down
8 changes: 4 additions & 4 deletions rust-bindings/bls-dash-sys/c-bindings/elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ int G1ElementSize() {
return bls::G1Element::SIZE;
}

G1Element G1ElementFromBytes(const void* data, bool legacy, bool* didErr) {
G1Element G1ElementFromBytes(const void* data, size_t len, bool legacy, bool* didErr) {
bls::G1Element* el = nullptr;
try {
el = new bls::G1Element(
bls::G1Element::FromBytes(bls::Bytes((uint8_t*)(data), bls::G1Element::SIZE), legacy)
bls::G1Element::FromBytes(bls::Bytes((uint8_t*)data, len), legacy)
);
} catch(const std::exception& ex) {
gErrMsg = ex.what();
Expand Down Expand Up @@ -97,11 +97,11 @@ int G2ElementSize() {
return bls::G2Element::SIZE;
}

G2Element G2ElementFromBytes(const void* data, const bool legacy, bool* didErr) {
G2Element G2ElementFromBytes(const void* data, size_t len, const bool legacy, bool* didErr) {
bls::G2Element* el = nullptr;
try {
el = new bls::G2Element(
bls::G2Element::FromBytes(bls::Bytes((uint8_t*)data, bls::G2Element::SIZE), legacy)
bls::G2Element::FromBytes(bls::Bytes((uint8_t*)data, len), legacy)
);
*didErr = false;
} catch(const std::exception& ex) {
Expand Down
4 changes: 2 additions & 2 deletions rust-bindings/bls-dash-sys/c-bindings/elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef void* PrivateKey;

// G1Element
int G1ElementSize();
G1Element G1ElementFromBytes(const void* data, const bool legacy, bool* didErr);
G1Element G1ElementFromBytes(const void* data, size_t len, const bool legacy, bool* didErr);
G1Element G1ElementGenerator();
bool G1ElementIsValid(const G1Element el);
uint32_t G1ElementGetFingerprint(const G1Element el, const bool legacy);
Expand All @@ -41,7 +41,7 @@ void G1ElementFree(const G1Element el);

// G2Element
int G2ElementSize();
G2Element G2ElementFromBytes(const void* data, const bool legacy, bool* didErr);
G2Element G2ElementFromBytes(const void* data, size_t len, const bool legacy, bool* didErr);
G2Element G2ElementGenerator();
bool G2ElementIsValid(const G2Element el);
bool G2ElementIsEqual(const G2Element el1, const G2Element el2);
Expand Down
4 changes: 2 additions & 2 deletions rust-bindings/bls-dash-sys/c-bindings/privatekey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#include "utils.hpp"

// private key bindings implementation
PrivateKey PrivateKeyFromBytes(const void* data, const bool modOrder, bool* didErr) {
PrivateKey PrivateKeyFromBytes(const void* data, size_t len, const bool modOrder, bool* didErr) {
bls::PrivateKey* skPtr = nullptr;
try {
skPtr = new bls::PrivateKey(
bls::PrivateKey::FromBytes(
bls::Bytes((uint8_t*)data, bls::PrivateKey::PRIVATE_KEY_SIZE),
bls::Bytes((uint8_t*)data, len),
modOrder
)
);
Expand Down
2 changes: 1 addition & 1 deletion rust-bindings/bls-dash-sys/c-bindings/privatekey.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {

typedef void* PrivateKey;

PrivateKey PrivateKeyFromBytes(const void* data, const bool modOrder, bool* didErr);
PrivateKey PrivateKeyFromBytes(const void* data, size_t len, const bool modOrder, bool* didErr);
PrivateKey PrivateKeyFromSeedBIP32(const void* data, const size_t len);
PrivateKey PrivateKeyAggregate(void** sks, const size_t len);
G1Element PrivateKeyGetG1Element(const PrivateKey sk, bool* didErr);
Expand Down
2 changes: 1 addition & 1 deletion rust-bindings/bls-signatures/src/bip32/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl ExtendedPrivateKey {
}
Ok(ExtendedPrivateKey {
c_extended_private_key: c_err_to_result(|did_err| unsafe {
BIP32ExtendedPrivateKeyFromBytes(bytes.as_ptr() as *const _, did_err)
BIP32ExtendedPrivateKeyFromBytes(bytes.as_ptr() as *const _, bytes.len(), did_err)
})?,
})
}
Expand Down
2 changes: 1 addition & 1 deletion rust-bindings/bls-signatures/src/bip32/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ExtendedPublicKey {
}
Ok(ExtendedPublicKey {
c_extended_public_key: c_err_to_result(|did_err| unsafe {
BIP32ExtendedPublicKeyFromBytes(bytes.as_ptr() as *const _, legacy, did_err)
BIP32ExtendedPublicKeyFromBytes(bytes.as_ptr() as *const _, bytes.len(), legacy, did_err)
})?,
})
}
Expand Down
Loading
Loading