[she] add test of ZkpDecGT

update-fork
MITSUNARI Shigeo 4 years ago
parent 0d123843df
commit 5cd31b666d
  1. 14
      include/mcl/she.h
  2. 33
      src/she_c_impl.hpp
  3. 28
      test/she_c_test.hpp

@ -78,6 +78,14 @@ typedef struct {
typedef struct { typedef struct {
mclBnFr d[2]; mclBnFr d[2];
} sheZkpDec; } sheZkpDec;
typedef struct {
mclBnGT d[4];
} sheAuxiliaryForZkpDecGT;
typedef struct {
mclBnFr d[4];
} sheZkpDecGT;
/* /*
initialize this library initialize this library
call this once before using the other functions call this once before using the other functions
@ -101,6 +109,7 @@ MCLSHE_DLL_API mclSize sheZkpBinSerialize(void *buf, mclSize maxBufSize, const s
MCLSHE_DLL_API mclSize sheZkpEqSerialize(void *buf, mclSize maxBufSize, const sheZkpEq *zkp); MCLSHE_DLL_API mclSize sheZkpEqSerialize(void *buf, mclSize maxBufSize, const sheZkpEq *zkp);
MCLSHE_DLL_API mclSize sheZkpBinEqSerialize(void *buf, mclSize maxBufSize, const sheZkpBinEq *zkp); MCLSHE_DLL_API mclSize sheZkpBinEqSerialize(void *buf, mclSize maxBufSize, const sheZkpBinEq *zkp);
MCLSHE_DLL_API mclSize sheZkpDecSerialize(void *buf, mclSize maxBufSize, const sheZkpDec *zkp); MCLSHE_DLL_API mclSize sheZkpDecSerialize(void *buf, mclSize maxBufSize, const sheZkpDec *zkp);
MCLSHE_DLL_API mclSize sheZkpDecGTSerialize(void *buf, mclSize maxBufSize, const sheZkpDecGT *zkp);
// return read byte size if sucess else 0 // return read byte size if sucess else 0
MCLSHE_DLL_API mclSize sheSecretKeyDeserialize(sheSecretKey* sec, const void *buf, mclSize bufSize); MCLSHE_DLL_API mclSize sheSecretKeyDeserialize(sheSecretKey* sec, const void *buf, mclSize bufSize);
@ -112,6 +121,7 @@ MCLSHE_DLL_API mclSize sheZkpBinDeserialize(sheZkpBin* zkp, const void *buf, mcl
MCLSHE_DLL_API mclSize sheZkpEqDeserialize(sheZkpEq* zkp, const void *buf, mclSize bufSize); MCLSHE_DLL_API mclSize sheZkpEqDeserialize(sheZkpEq* zkp, const void *buf, mclSize bufSize);
MCLSHE_DLL_API mclSize sheZkpBinEqDeserialize(sheZkpBinEq* zkp, const void *buf, mclSize bufSize); MCLSHE_DLL_API mclSize sheZkpBinEqDeserialize(sheZkpBinEq* zkp, const void *buf, mclSize bufSize);
MCLSHE_DLL_API mclSize sheZkpDecDeserialize(sheZkpDec* zkp, const void *buf, mclSize bufSize); MCLSHE_DLL_API mclSize sheZkpDecDeserialize(sheZkpDec* zkp, const void *buf, mclSize bufSize);
MCLSHE_DLL_API mclSize sheZkpDecGTDeserialize(sheZkpDecGT* zkp, const void *buf, mclSize bufSize);
/* /*
set secretKey if system has /dev/urandom or CryptGenRandom set secretKey if system has /dev/urandom or CryptGenRandom
@ -121,6 +131,8 @@ MCLSHE_DLL_API int sheSecretKeySetByCSPRNG(sheSecretKey *sec);
MCLSHE_DLL_API void sheGetPublicKey(shePublicKey *pub, const sheSecretKey *sec); MCLSHE_DLL_API void sheGetPublicKey(shePublicKey *pub, const sheSecretKey *sec);
MCLSHE_DLL_API void sheGetAuxiliaryForZkpDecGT(sheAuxiliaryForZkpDecGT *aux, const shePublicKey *pub);
/* /*
make table to decode DLP make table to decode DLP
return 0 if success return 0 if success
@ -203,6 +215,7 @@ MCLSHE_DLL_API int shePrecomputedPublicKeyEncWithZkpEq(sheCipherTextG1 *c1, sheC
return 0 if success return 0 if success
*/ */
MCLSHE_DLL_API int sheDecWithZkpDecG1(mclInt *m, sheZkpDec *zkp, const sheSecretKey *sec, const sheCipherTextG1 *c, const shePublicKey *pub); MCLSHE_DLL_API int sheDecWithZkpDecG1(mclInt *m, sheZkpDec *zkp, const sheSecretKey *sec, const sheCipherTextG1 *c, const shePublicKey *pub);
MCLSHE_DLL_API int sheDecWithZkpDecGT(mclInt *m, sheZkpDecGT *zkp, const sheSecretKey *sec, const sheCipherTextGT *c, const sheAuxiliaryForZkpDecGT *aux);
/* /*
decode c and set m decode c and set m
@ -224,6 +237,7 @@ MCLSHE_DLL_API int shePrecomputedPublicKeyVerifyZkpBinG2(const shePrecomputedPub
MCLSHE_DLL_API int shePrecomputedPublicKeyVerifyZkpEq(const shePrecomputedPublicKey *ppub, const sheCipherTextG1 *c1, const sheCipherTextG2 *c2, const sheZkpEq *zkp); MCLSHE_DLL_API int shePrecomputedPublicKeyVerifyZkpEq(const shePrecomputedPublicKey *ppub, const sheCipherTextG1 *c1, const sheCipherTextG2 *c2, const sheZkpEq *zkp);
MCLSHE_DLL_API int shePrecomputedPublicKeyVerifyZkpBinEq(const shePrecomputedPublicKey *ppub, const sheCipherTextG1 *c1, const sheCipherTextG2 *c2, const sheZkpBinEq *zkp); MCLSHE_DLL_API int shePrecomputedPublicKeyVerifyZkpBinEq(const shePrecomputedPublicKey *ppub, const sheCipherTextG1 *c1, const sheCipherTextG2 *c2, const sheZkpBinEq *zkp);
MCLSHE_DLL_API int sheVerifyZkpDecG1(const shePublicKey *pub, const sheCipherTextG1 *c1, mclInt m, const sheZkpDec *zkp); MCLSHE_DLL_API int sheVerifyZkpDecG1(const shePublicKey *pub, const sheCipherTextG1 *c1, mclInt m, const sheZkpDec *zkp);
MCLSHE_DLL_API int sheVerifyZkpDecGT(const sheAuxiliaryForZkpDecGT *aux, const sheCipherTextGT *ct, mclInt m, const sheZkpDecGT *zkp);
/* /*
decode c via GT and set m decode c via GT and set m
return 0 if success return 0 if success

@ -44,6 +44,12 @@ static const ZkpBinEq *cast(const sheZkpBinEq *p) { return reinterpret_cast<cons
static ZkpDec *cast(sheZkpDec *p) { return reinterpret_cast<ZkpDec*>(p); } static ZkpDec *cast(sheZkpDec *p) { return reinterpret_cast<ZkpDec*>(p); }
static const ZkpDec *cast(const sheZkpDec *p) { return reinterpret_cast<const ZkpDec*>(p); } static const ZkpDec *cast(const sheZkpDec *p) { return reinterpret_cast<const ZkpDec*>(p); }
static AuxiliaryForZkpDecGT *cast(sheAuxiliaryForZkpDecGT *p) { return reinterpret_cast<AuxiliaryForZkpDecGT*>(p); }
static const AuxiliaryForZkpDecGT *cast(const sheAuxiliaryForZkpDecGT *p) { return reinterpret_cast<const AuxiliaryForZkpDecGT*>(p); }
static ZkpDecGT *cast(sheZkpDecGT *p) { return reinterpret_cast<ZkpDecGT*>(p); }
static const ZkpDecGT *cast(const sheZkpDecGT *p) { return reinterpret_cast<const ZkpDecGT*>(p); }
int sheInit(int curve, int compiledTimeVar) int sheInit(int curve, int compiledTimeVar)
try try
{ {
@ -124,6 +130,11 @@ mclSize sheZkpDecSerialize(void *buf, mclSize maxBufSize, const sheZkpDec *zkp)
return (mclSize)cast(zkp)->serialize(buf, maxBufSize); return (mclSize)cast(zkp)->serialize(buf, maxBufSize);
} }
mclSize sheZkpGTDecSerialize(void *buf, mclSize maxBufSize, const sheZkpDecGT *zkp)
{
return (mclSize)cast(zkp)->serialize(buf, maxBufSize);
}
mclSize sheSecretKeyDeserialize(sheSecretKey* sec, const void *buf, mclSize bufSize) mclSize sheSecretKeyDeserialize(sheSecretKey* sec, const void *buf, mclSize bufSize)
{ {
return (mclSize)cast(sec)->deserialize(buf, bufSize); return (mclSize)cast(sec)->deserialize(buf, bufSize);
@ -169,6 +180,11 @@ mclSize sheZkpDecDeserialize(sheZkpDec* zkp, const void *buf, mclSize bufSize)
return (mclSize)cast(zkp)->deserialize(buf, bufSize); return (mclSize)cast(zkp)->deserialize(buf, bufSize);
} }
mclSize sheZkpDecGTDeserialize(sheZkpDecGT* zkp, const void *buf, mclSize bufSize)
{
return (mclSize)cast(zkp)->deserialize(buf, bufSize);
}
int sheSecretKeySetByCSPRNG(sheSecretKey *sec) int sheSecretKeySetByCSPRNG(sheSecretKey *sec)
{ {
cast(sec)->setByCSPRNG(); cast(sec)->setByCSPRNG();
@ -180,6 +196,11 @@ void sheGetPublicKey(shePublicKey *pub, const sheSecretKey *sec)
cast(sec)->getPublicKey(*cast(pub)); cast(sec)->getPublicKey(*cast(pub));
} }
void sheGetAuxiliaryForZkpDecGT(sheAuxiliaryForZkpDecGT *aux, const shePublicKey *pub)
{
cast(pub)->getAuxiliaryForZkpDecGT(*cast(aux));
}
static int wrapSetRangeForDLP(void f(size_t), mclSize hashSize) static int wrapSetRangeForDLP(void f(size_t), mclSize hashSize)
try try
{ {
@ -788,8 +809,20 @@ int sheDecWithZkpDecG1(mclInt *m, sheZkpDec *zkp, const sheSecretKey *sec, const
return b ? 0 : -1; return b ? 0 : -1;
} }
int sheDecWithZkpDecGT(mclInt *m, sheZkpDecGT *zkp, const sheSecretKey *sec, const sheCipherTextGT *c, const sheAuxiliaryForZkpDecGT *aux)
{
bool b;
*m = cast(sec)->decWithZkpDec(&b, *cast(zkp), *cast(c), *cast(aux));
return b ? 0 : -1;
}
int sheVerifyZkpDecG1(const shePublicKey *pub, const sheCipherTextG1 *c1, mclInt m, const sheZkpDec *zkp) int sheVerifyZkpDecG1(const shePublicKey *pub, const sheCipherTextG1 *c1, mclInt m, const sheZkpDec *zkp)
{ {
return cast(pub)->verify(*cast(c1), m, *cast(zkp)); return cast(pub)->verify(*cast(c1), m, *cast(zkp));
} }
int sheVerifyZkpDecGT(const sheAuxiliaryForZkpDecGT *aux, const sheCipherTextGT *ct, mclInt m, const sheZkpDecGT *zkp)
{
return cast(aux)->verify(*cast(ct), m, *cast(zkp));
}

@ -442,7 +442,7 @@ void ZkpEqTest(const sheSecretKey *sec, const PK *pub, encWithZkpFunc encWithZkp
} }
} }
CYBOZU_TEST_AUTO(ZkpEq) CYBOZU_TEST_AUTO(ZkpDecG1)
{ {
sheSecretKey sec; sheSecretKey sec;
sheSecretKeySetByCSPRNG(&sec); sheSecretKeySetByCSPRNG(&sec);
@ -464,7 +464,31 @@ CYBOZU_TEST_AUTO(ZkpEq)
CYBOZU_TEST_EQUAL(sheVerifyZkpDecG1(&pub, &c1, m, &zkp), 0); CYBOZU_TEST_EQUAL(sheVerifyZkpDecG1(&pub, &c1, m, &zkp), 0);
} }
CYBOZU_TEST_AUTO(ZkpDec) CYBOZU_TEST_AUTO(ZkpDecGT)
{
sheSecretKey sec;
sheSecretKeySetByCSPRNG(&sec);
shePublicKey pub;
sheGetPublicKey(&pub, &sec);
sheAuxiliaryForZkpDecGT aux;
sheGetAuxiliaryForZkpDecGT(&aux, &pub);
int m = 123;
sheCipherTextGT c1;
sheEncGT(&c1, &pub, m);
sheZkpDecGT zkp;
int64_t dec;
CYBOZU_TEST_EQUAL(sheDecWithZkpDecGT(&dec, &zkp, &sec, &c1, &aux), 0);
CYBOZU_TEST_EQUAL(m, dec);
CYBOZU_TEST_EQUAL(sheVerifyZkpDecGT(&aux, &c1, m, &zkp), 1);
CYBOZU_TEST_EQUAL(sheVerifyZkpDecGT(&aux, &c1, m + 1, &zkp), 0);
sheCipherTextGT c2;
sheEncGT(&c2, &pub, m);
CYBOZU_TEST_EQUAL(sheVerifyZkpDecGT(&aux, &c2, m, &zkp), 0);
zkp.d[0].d[0]++;
CYBOZU_TEST_EQUAL(sheVerifyZkpDecGT(&aux, &c1, m, &zkp), 0);
}
CYBOZU_TEST_AUTO(ZkpEq)
{ {
sheSecretKey sec; sheSecretKey sec;
sheSecretKeySetByCSPRNG(&sec); sheSecretKeySetByCSPRNG(&sec);

Loading…
Cancel
Save