aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-05-05 07:07:47 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-05-05 07:07:47 +0800
commitb85df3bdcea93108a0c1c12e9471ba3e700329f6 (patch)
treec2c70171360cfd345e982494361edfe589bd18ab /include
parente75cbb14166d3b418d84cd5924d8445c96e849a8 (diff)
downloaddexon-bls-b85df3bdcea93108a0c1c12e9471ba3e700329f6.tar
dexon-bls-b85df3bdcea93108a0c1c12e9471ba3e700329f6.tar.gz
dexon-bls-b85df3bdcea93108a0c1c12e9471ba3e700329f6.tar.bz2
dexon-bls-b85df3bdcea93108a0c1c12e9471ba3e700329f6.tar.lz
dexon-bls-b85df3bdcea93108a0c1c12e9471ba3e700329f6.tar.xz
dexon-bls-b85df3bdcea93108a0c1c12e9471ba3e700329f6.tar.zst
dexon-bls-b85df3bdcea93108a0c1c12e9471ba3e700329f6.zip
change api of GetStr/SetStr
Diffstat (limited to 'include')
-rw-r--r--include/bls.hpp36
-rw-r--r--include/bls_if.h57
2 files changed, 52 insertions, 41 deletions
diff --git a/include/bls.hpp b/include/bls.hpp
index 5cb4471..915e8bb 100644
--- a/include/bls.hpp
+++ b/include/bls.hpp
@@ -27,6 +27,14 @@ enum {
CurveFp382_2 = 2
};
+// same value with IoMode of mcl/op.hpp
+enum {
+ IoBin = 2, // binary number
+ IoDec = 10, // decimal number
+ IoHex = 16, // hexadecimal number
+ IoEcComp = 512 // fixed byte representation
+};
+
namespace impl {
struct SecretKey;
@@ -89,11 +97,8 @@ public:
bool operator!=(const Id& rhs) const { return !(*this == rhs); }
friend std::ostream& operator<<(std::ostream& os, const Id& id);
friend std::istream& operator>>(std::istream& is, Id& id);
- /*
- get tight repl
- */
- void getData(std::string& str) const;
- void setData(const std::string& str);
+ void getStr(std::string& str, int ioMode = 0) const;
+ void setStr(const std::string& str, int ioMode = 0);
bool isZero() const;
/*
set p[0, .., keySize)
@@ -117,11 +122,8 @@ public:
bool operator!=(const SecretKey& rhs) const { return !(*this == rhs); }
friend std::ostream& operator<<(std::ostream& os, const SecretKey& sec);
friend std::istream& operator>>(std::istream& is, SecretKey& sec);
- /*
- get tight repl
- */
- void getData(std::string& str) const;
- void setData(const std::string& str);
+ void getStr(std::string& str, int ioMode = 0) const;
+ void setStr(const std::string& str, int ioMode = 0);
/*
initialize secretKey with random number and set id = 0
*/
@@ -183,11 +185,8 @@ public:
bool operator!=(const PublicKey& rhs) const { return !(*this == rhs); }
friend std::ostream& operator<<(std::ostream& os, const PublicKey& pub);
friend std::istream& operator>>(std::istream& is, PublicKey& pub);
- /*
- get tight repl
- */
- void getData(std::string& str) const;
- void setData(const std::string& str);
+ void getStr(std::string& str, int ioMode = 0) const;
+ void setStr(const std::string& str, int ioMode = 0);
/*
set public for id from mpk
*/
@@ -224,11 +223,8 @@ public:
bool operator!=(const Sign& rhs) const { return !(*this == rhs); }
friend std::ostream& operator<<(std::ostream& os, const Sign& s);
friend std::istream& operator>>(std::istream& is, Sign& s);
- /*
- get tight repl
- */
- void getData(std::string& str) const;
- void setData(const std::string& str);
+ void getStr(std::string& str, int ioMode = 0) const;
+ void setStr(const std::string& str, int ioMode = 0);
bool verify(const PublicKey& pub, const std::string& m) const;
/*
verify self(pop) with pub
diff --git a/include/bls_if.h b/include/bls_if.h
index 2eb8f1b..313e78a 100644
--- a/include/bls_if.h
+++ b/include/bls_if.h
@@ -27,6 +27,14 @@ enum {
BlsCurveFp382_2 = 2
};
+// same value with bls.hpp
+enum {
+ BlsIoBin = 2, // binary number
+ BlsIoDec = 10, // decimal number
+ BlsIoHex = 16, // hexadecimal number
+ BlsIoEcComp = 512 // fixed byte representation
+};
+
typedef struct {
uint64_t buf[BLS_MAX_OP_UNIT_SIZE];
} blsId;
@@ -56,18 +64,20 @@ int blsGetFieldOrder(char *buf, size_t maxBufSize);
blsId *blsIdCreate(void);
void blsIdDestroy(blsId *id);
-size_t blsIdGetData(const blsId *id, char *buf, size_t maxBufSize);
-int blsIdSetData(blsId *id, const char *buf, size_t bufSize);
// return 1 if same else 0
int blsIdIsSame(const blsId *lhs, const blsId *rhs);
void blsIdPut(const blsId *id);
void blsIdCopy(blsId *dst, const blsId *src);
// return 0 if success
-int blsIdSetStr(blsId *id, const char *buf, size_t bufSize);
+int blsIdSetStr(blsId *id, const char *buf, size_t bufSize, int ioMode);
-// return strlen(buf) if success else 0
-size_t blsIdGetStr(const blsId *id, char *buf, size_t maxBufSize);
+/*
+ return written byte size if ioMode = BlsIoComp
+ return strlen(buf) if ioMode = 2, 10, 16 ; written byte size = strlen(buf) + 1
+ return 0 otherwise
+*/
+size_t blsIdGetStr(const blsId *id, char *buf, size_t maxBufSize, int ioMode);
/*
access p[0], ..., p[3] if 256-bit curve
access p[0], ..., p[5] if 384-bit curve
@@ -76,18 +86,19 @@ void blsIdSet(blsId *id, const uint64_t *p);
blsSecretKey* blsSecretKeyCreate(void);
void blsSecretKeyDestroy(blsSecretKey *sec);
-// return written byte size if success else 0
-size_t blsSecretKeyGetData(const blsSecretKey *sec, char *buf, size_t maxBufSize);
-int blsSecretKeySetData(blsSecretKey *sec, const char *buf, size_t bufSize);
// return 1 if same else 0
int blsSecretKeyIsSame(const blsSecretKey *lhs, const blsSecretKey *rhs);
void blsSecretKeyPut(const blsSecretKey *sec);
void blsSecretKeyCopy(blsSecretKey *dst, const blsSecretKey *src);
void blsSecretKeySetArray(blsSecretKey *sec, const uint64_t *p);
-int blsSecretKeySetStr(blsSecretKey *sec, const char *buf, size_t bufSize);
-// return strlen(buf) if success else 0
-size_t blsSecretKeyGetStr(const blsSecretKey *sec, char *buf, size_t maxBufSize);
+int blsSecretKeySetStr(blsSecretKey *sec, const char *buf, size_t bufSize, int ioMode);
+/*
+ return written byte size if ioMode = BlsIoComp
+ return strlen(buf) if ioMode = 2, 10, 16 ; written byte size = strlen(buf) + 1
+ return 0 otherwise
+*/
+size_t blsSecretKeyGetStr(const blsSecretKey *sec, char *buf, size_t maxBufSize, int ioMode);
void blsSecretKeyAdd(blsSecretKey *sec, const blsSecretKey *rhs);
void blsSecretKeyInit(blsSecretKey *sec);
@@ -99,30 +110,34 @@ void blsSecretKeyGetPop(const blsSecretKey *sec, blsSign *sign);
blsPublicKey *blsPublicKeyCreate(void);
void blsPublicKeyDestroy(blsPublicKey *pub);
-size_t blsPublicKeyGetData(const blsPublicKey *pub, char *buf, size_t maxBufSize);
-int blsPublicKeySetData(blsPublicKey *pub, const char *buf, size_t bufSize);
// return 1 if same else 0
int blsPublicKeyIsSame(const blsPublicKey *lhs, const blsPublicKey *rhs);
void blsPublicKeyPut(const blsPublicKey *pub);
void blsPublicKeyCopy(blsPublicKey *dst, const blsPublicKey *src);
-int blsPublicKeySetStr(blsPublicKey *pub, const char *buf, size_t bufSize);
-// return strlen(buf) if success else 0
-size_t blsPublicKeyGetStr(const blsPublicKey *pub, char *buf, size_t maxBufSize);
+int blsPublicKeySetStr(blsPublicKey *pub, const char *buf, size_t bufSize, int ioMode);
+/*
+ return written byte size if ioMode = BlsIoComp
+ return strlen(buf) if ioMode = 2, 10, 16 ; written byte size = strlen(buf) + 1
+ return 0 otherwise
+*/
+size_t blsPublicKeyGetStr(const blsPublicKey *pub, char *buf, size_t maxBufSize, int ioMode);
void blsPublicKeyAdd(blsPublicKey *pub, const blsPublicKey *rhs);
void blsPublicKeySet(blsPublicKey *pub, const blsPublicKey *mpk, size_t k, const blsId *id);
void blsPublicKeyRecover(blsPublicKey *pub, const blsPublicKey *pubVec, const blsId *idVec, size_t n);
blsSign *blsSignCreate(void);
void blsSignDestroy(blsSign *sign);
-size_t blsSignGetData(const blsSign *sign, char *buf, size_t maxBufSize);
-int blsSignSetData(blsSign *sign, const char *buf, size_t bufSize);
// return 1 if same else 0
int blsSignIsSame(const blsSign *lhs, const blsSign *rhs);
void blsSignPut(const blsSign *sign);
void blsSignCopy(blsSign *dst, const blsSign *src);
-int blsSignSetStr(blsSign *sign, const char *buf, size_t bufSize);
-// return strlen(buf) if success else 0
-size_t blsSignGetStr(const blsSign *sign, char *buf, size_t maxBufSize);
+int blsSignSetStr(blsSign *sign, const char *buf, size_t bufSize, int ioMode);
+/*
+ return written byte size if ioMode = BlsIoComp
+ return strlen(buf) if ioMode = 2, 10, 16 ; written byte size = strlen(buf) + 1
+ return 0 otherwise
+*/
+size_t blsSignGetStr(const blsSign *sign, char *buf, size_t maxBufSize, int ioMode);
void blsSignAdd(blsSign *sign, const blsSign *rhs);
void blsSignRecover(blsSign *sign, const blsSign *signVec, const blsId *idVec, size_t n);