Skip to content
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

take span instead of std::vector to simplify interface #190

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 8 additions & 22 deletions src/elements.cpp
Expand Up @@ -18,7 +18,7 @@

namespace bls {

G1Element G1Element::FromBytes(const Bytes& bytes)
G1Element G1Element::FromBytes(const Bytes bytes)
{
if (bytes.size() != SIZE) {
throw std::invalid_argument("G1Element::FromBytes: Invalid size");
Expand Down Expand Up @@ -64,7 +64,7 @@ G1Element G1Element::FromBytes(const Bytes& bytes)

G1Element G1Element::FromByteVector(const std::vector<uint8_t>& bytevec)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the FromByteVector() functions don't really serve a purpose with this patch anymore, since the Bytes overload can be used for std::vector as well. Since it's part of the public API though, I'm hesitant to remove it.

{
return G1Element::FromBytes(Bytes(bytevec));
return G1Element::FromBytes(bytevec);
}

G1Element G1Element::FromNative(const g1_t element)
Expand All @@ -75,19 +75,12 @@ G1Element G1Element::FromNative(const g1_t element)
return ele;
}

G1Element G1Element::FromMessage(const std::vector<uint8_t>& message,
const uint8_t* dst,
int dst_len)
{
return FromMessage(Bytes(message), dst, dst_len);
}

G1Element G1Element::FromMessage(const Bytes& message,
G1Element G1Element::FromMessage(const Bytes message,
const uint8_t* dst,
int dst_len)
{
G1Element ans;
ep_map_dst(ans.p, message.begin(), (int)message.size(), dst, dst_len);
ep_map_dst(ans.p, message.data(), (int)message.size(), dst, dst_len);
BLS::CheckRelicErrors();
assert(ans.IsValid());
return ans;
Expand Down Expand Up @@ -198,7 +191,7 @@ G1Element operator*(const bn_t& k, const G1Element& a) { return a * k; }



G2Element G2Element::FromBytes(const Bytes& bytes)
G2Element G2Element::FromBytes(const Bytes bytes)
{
if (bytes.size() != SIZE) {
throw std::invalid_argument("G2Element::FromBytes: Invalid size");
Expand Down Expand Up @@ -247,7 +240,7 @@ G2Element G2Element::FromBytes(const Bytes& bytes)

G2Element G2Element::FromByteVector(const std::vector<uint8_t>& bytevec)
{
return G2Element::FromBytes(Bytes(bytevec));
return G2Element::FromBytes(bytevec);
}

G2Element G2Element::FromNative(const g2_t element)
Expand All @@ -258,19 +251,12 @@ G2Element G2Element::FromNative(const g2_t element)
return ele;
}

G2Element G2Element::FromMessage(const std::vector<uint8_t>& message,
const uint8_t* dst,
int dst_len)
{
return FromMessage(Bytes(message), dst, dst_len);
}

G2Element G2Element::FromMessage(const Bytes& message,
G2Element G2Element::FromMessage(const Bytes message,
const uint8_t* dst,
int dst_len)
{
G2Element ans;
ep2_map_dst(ans.q, message.begin(), (int)message.size(), dst, dst_len);
ep2_map_dst(ans.q, message.data(), (int)message.size(), dst, dst_len);
BLS::CheckRelicErrors();
assert(ans.IsValid());
return ans;
Expand Down
18 changes: 12 additions & 6 deletions src/elements.hpp
Expand Up @@ -39,13 +39,16 @@ class G1Element {
g1_set_infty(p);
}

static G1Element FromBytes(const Bytes& bytes);
static G1Element FromBytes(Bytes bytes);
static G1Element FromByteVector(const std::vector<uint8_t> &bytevec);
static G1Element FromNative(const g1_t element);
static G1Element FromMessage(const std::vector<uint8_t> &message,
const uint8_t *dst,
int dst_len);
static G1Element FromMessage(const Bytes& message,
int dst_len)
{
return G1Element::FromMessage(Bytes(message), dst, dst_len);
}
static G1Element FromMessage(Bytes message,
const uint8_t* dst,
int dst_len);
static G1Element Generator();
Expand Down Expand Up @@ -77,13 +80,16 @@ class G2Element {
g2_set_infty(q);
}

static G2Element FromBytes(const Bytes& bytes);
static G2Element FromBytes(Bytes bytes);
static G2Element FromByteVector(const std::vector<uint8_t> &bytevec);
static G2Element FromNative(const g2_t element);
static G2Element FromMessage(const std::vector<uint8_t>& message,
const uint8_t* dst,
int dst_len);
static G2Element FromMessage(const Bytes& message,
int dst_len)
{
return G2Element::FromMessage(Bytes(message), dst, dst_len);
}
static G2Element FromMessage(Bytes message,
const uint8_t* dst,
int dst_len);
static G2Element Generator();
Expand Down
8 changes: 1 addition & 7 deletions src/hdkeys.hpp
Expand Up @@ -34,13 +34,7 @@ class HDKeys {
**/
public:
static const uint8_t HASH_LEN = 32;

static PrivateKey KeyGen(const std::vector<uint8_t>& seed)
{
return KeyGen(Bytes(seed));
}

static PrivateKey KeyGen(const Bytes& seed)
static PrivateKey KeyGen(const Bytes seed)
{
// KeyGen
// 1. PRK = HKDF-Extract("BLS-SIG-KEYGEN-SALT-", IKM || I2OSP(0, 1))
Expand Down