she ; exported-she.json is removed

dev
MITSUNARI Shigeo 7 years ago
parent 48ede76489
commit 2f53f90067
  1. 11
      Makefile
  2. 266
      docs/demo/exported-she.json
  3. 158
      docs/demo/she.js
  4. 2
      docs/demo/she_c.js
  5. BIN
      docs/demo/she_c.wasm
  6. 4
      include/mcl/she.h
  7. 12
      include/mcl/she.hpp
  8. 12
      src/she_c_impl.hpp
  9. 6
      test/she_c_test.hpp
  10. 2
      test/she_test.cpp

@ -209,12 +209,6 @@ test: $(TEST_EXE)
@sh -ec 'for i in $(TEST_EXE); do $$i|grep "ctest:name"; done' > result.txt
@grep -v "ng=0, exception=0" result.txt; if [ $$? -eq 1 ]; then echo "all unit tests succeed"; else exit 1; fi
SHE_JSON=docs/demo/exported-she.json
SHE_RE_TXT=ffi/js/she-re.txt
SHE_EXPORT_OPT=-re $(SHE_RE_TXT)
$(SHE_JSON): include/mcl/she.h
python ffi/js/export-functions.py $(SHE_EXPORT_OPT) -json $^ > $(SHE_JSON)
MCL_JSON=docs/demo/exported-mcl.json
$(MCL_JSON): include/mcl/bn.h
python ffi/js/export-functions.py -json $^ > $(MCL_JSON)
@ -222,7 +216,7 @@ $(MCL_JSON): include/mcl/bn.h
EMCC_OPT=-I./include -I./src -I../cybozulib/include
EMCC_OPT+=-O3 -DNDEBUG -DMCLBN_FP_UNIT_SIZE=4 -DMCL_MAX_BIT_SIZE=256 -DMCLSHE_WIN_SIZE=8
EMCC_OPT+=-s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s NO_EXIT_RUNTIME=1
JS_DEP=src/fp.cpp src/she_c256.cpp src/she_c_impl.hpp include/mcl/she.hpp $(SHE_JSON) Makefile ffi/js/pre.js
JS_DEP=src/fp.cpp src/she_c256.cpp src/she_c_impl.hpp include/mcl/she.hpp Makefile ffi/js/pre.js
ifeq ($(MCL_USE_LLVM),2)
EMCC_OPT+=src/base64m.ll -DMCL_USE_LLVM
JS_DEP+=src/base64m.ll
@ -233,7 +227,6 @@ docs/demo/she_c.js: $(JS_DEP)
../she-wasm/she_c.js: $(JS_DEP)
emcc -o $@ src/fp.cpp src/she_c256.cpp $(EMCC_OPT) --pre-js ffi/js/pre.js
cp docs/demo/she.js ../she-wasm/
cp $(SHE_JSON) ../she-wasm/
../mcl-wasm/mcl_c.js: src/fp.cpp src/bn_c256.cpp $(MCL_JSON)
emcc -o $@ src/fp.cpp src/bn_c256.cpp $(EMCC_OPT) --pre-js ffi/js/pre-mcl.js
@ -250,7 +243,7 @@ mcl-wasm:
$(MAKE) ../mcl-wasm/mcl_c.js
clean_demo:
$(RM) $(SHE_JSON) docs/demo/she_c.js docs/demo/she_c.wasm
$(RM) docs/demo/she_c.js docs/demo/she_c.wasm
clean:
$(MAKE) clean_demo

@ -1,266 +0,0 @@
[
{
"name":"sheInit",
"exportName":"_sheInit",
"ret":"number",
"args":[ "number", "number" ]
}
,{
"name":"sheSecretKeySerialize",
"exportName":"_sheSecretKeySerialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"shePublicKeySerialize",
"exportName":"_shePublicKeySerialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheCipherTextG1Serialize",
"exportName":"_sheCipherTextG1Serialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheCipherTextG2Serialize",
"exportName":"_sheCipherTextG2Serialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheCipherTextGTSerialize",
"exportName":"_sheCipherTextGTSerialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheSecretKeyDeserialize",
"exportName":"_sheSecretKeyDeserialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"shePublicKeyDeserialize",
"exportName":"_shePublicKeyDeserialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheCipherTextG1Deserialize",
"exportName":"_sheCipherTextG1Deserialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheCipherTextG2Deserialize",
"exportName":"_sheCipherTextG2Deserialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheCipherTextGTDeserialize",
"exportName":"_sheCipherTextGTDeserialize",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheSecretKeySetByCSPRNG",
"exportName":"sheSecretKeySetByCSPRNG",
"ret":"number",
"args":[ "number" ]
}
,{
"name":"sheGetPublicKey",
"exportName":"sheGetPublicKey",
"ret":"null",
"args":[ "number", "number" ]
}
,{
"name":"sheSetRangeForDLP",
"exportName":"sheSetRangeForDLP",
"ret":"number",
"args":[ "number", "number" ]
}
,{
"name":"sheSetRangeForG1DLP",
"exportName":"sheSetRangeForG1DLP",
"ret":"number",
"args":[ "number", "number" ]
}
,{
"name":"sheSetRangeForG2DLP",
"exportName":"sheSetRangeForG2DLP",
"ret":"number",
"args":[ "number", "number" ]
}
,{
"name":"sheSetRangeForGTDLP",
"exportName":"sheSetRangeForGTDLP",
"ret":"number",
"args":[ "number", "number" ]
}
,{
"name":"sheEncG1",
"exportName":"sheEncG1",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheEncG2",
"exportName":"sheEncG2",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheEncGT",
"exportName":"sheEncGT",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheEnc32G1",
"exportName":"sheEnc32G1",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheEnc32G2",
"exportName":"sheEnc32G2",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheEnc32GT",
"exportName":"sheEnc32GT",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheDecG1",
"exportName":"_sheDecG1",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheDecG2",
"exportName":"_sheDecG2",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheDecGT",
"exportName":"_sheDecGT",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheAddG1",
"exportName":"sheAddG1",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheAddG2",
"exportName":"sheAddG2",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheAddGT",
"exportName":"sheAddGT",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheSubG1",
"exportName":"sheSubG1",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheSubG2",
"exportName":"sheSubG2",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheSubGT",
"exportName":"sheSubGT",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheMulG1",
"exportName":"sheMulG1",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheMulG2",
"exportName":"sheMulG2",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheMulGT",
"exportName":"sheMulGT",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheMul32G1",
"exportName":"sheMul32G1",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheMul32G2",
"exportName":"sheMul32G2",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheMul32GT",
"exportName":"sheMul32GT",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheMul",
"exportName":"sheMul",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheReRandG1",
"exportName":"sheReRandG1",
"ret":"number",
"args":[ "number", "number" ]
}
,{
"name":"sheReRandG2",
"exportName":"sheReRandG2",
"ret":"number",
"args":[ "number", "number" ]
}
,{
"name":"sheReRandGT",
"exportName":"sheReRandGT",
"ret":"number",
"args":[ "number", "number" ]
}
,{
"name":"sheConvertFromG1",
"exportName":"sheConvertFromG1",
"ret":"number",
"args":[ "number", "number", "number" ]
}
,{
"name":"sheConvertFromG2",
"exportName":"sheConvertFromG2",
"ret":"number",
"args":[ "number", "number", "number" ]
}
]

@ -26,8 +26,6 @@
const SHE_CIPHERTEXT_G2_SIZE = MCLBN_G2_SIZE * 2
const SHE_CIPHERTEXT_GT_SIZE = MCLBN_GT_SIZE * 4
let capi = {}
exports.capi = capi
let mod = exports.mod
/*
@ -46,26 +44,12 @@
}
return new Promise((resolve) => {
mod.onRuntimeInitialized = () => {
const f = (exportedFuncs) => {
exportedFuncs.forEach(func => {
capi[func.exportName] = mod.cwrap(func.name, func.returns, func.args)
})
define_extra_functions(mod)
capi.sheInit()
console.log(`initializing sheSetRangeForDLP(range=${range}, tryNum=${tryNum})`)
const r = capi.sheSetRangeForDLP(range, tryNum)
console.log('finished ' + r)
resolve()
}
if (isNodeJs) {
const fs = require('fs')
const jsonStr = fs.readFileSync('./exported-she.json')
f(JSON.parse(jsonStr))
} else {
fetch('exported-she.json')
.then(response => response.json())
.then(exportedFuncs => f(exportedFuncs))
}
define_extra_functions(mod)
let r = mod._sheInit(MCLBN_CURVE_FP254BNB, MCLBN_FP_UNIT_SIZE)
console.log(`initializing sheSetRangeForDLP(range=${range}, tryNum=${tryNum})`)
r = mod._sheSetRangeForDLP(range, tryNum)
console.log('finished ' + r)
resolve()
}
})
}
@ -253,8 +237,8 @@
mod.Runtime.stackRestore(stack)
if (r) throw('callReRand err')
}
// convertFrom
const callConvertFrom = function(func, pub, c) {
// convert
const callConvert = function(func, pub, c) {
let ct = new exports.CipherTextGT()
let stack = mod.Runtime.stackSave()
let ctPos = mod.Runtime.stackAlloc(ct.a_.length * 4)
@ -265,47 +249,24 @@
let r = func(ctPos, pubPos, cPos)
copyToUint32Array(ct.a_, ctPos)
mod.Runtime.stackRestore(stack)
if (r) throw('callConvertFrom err')
if (r) throw('callConvert err')
return ct
}
const define_extra_functions = function(mod) {
capi.she_free = function(p) {
mod._free(p)
}
capi.sheSecretKey_malloc = function() {
return mod._malloc(SHE_SECRETKEY_SIZE)
}
capi.shePublicKey_malloc = function() {
return mod._malloc(SHE_PUBLICKEY_SIZE)
}
capi.sheCipherTextG2_malloc = function() {
return mod._malloc(SHE_CIPHERTEXT_G2_SIZE)
}
capi.sheCipherTextGT_malloc = function() {
return mod._malloc(SHE_CIPHERTEXT_GT_SIZE)
}
capi.sheCipherTextG1_malloc = function() {
return mod._malloc(SHE_CIPHERTEXT_G1_SIZE)
}
capi.sheSecretKeySerialize = wrap_outputArray(capi._sheSecretKeySerialize)
capi.sheSecretKeyDeserialize = wrap_input(capi._sheSecretKeyDeserialize, 1)
capi.shePublicKeySerialize = wrap_outputArray(capi._shePublicKeySerialize)
capi.shePublicKeyDeserialize = wrap_input(capi._shePublicKeyDeserialize, 1)
capi.sheCipherTextG1Serialize = wrap_outputArray(capi._sheCipherTextG1Serialize)
capi.sheCipherTextG1Deserialize = wrap_input(capi._sheCipherTextG1Deserialize, 1)
capi.sheDecG1 = wrap_dec(capi._sheDecG1)
capi.sheCipherTextG2Serialize = wrap_outputArray(capi._sheCipherTextG2Serialize)
capi.sheCipherTextG2Deserialize = wrap_input(capi._sheCipherTextG2Deserialize, 1)
capi.sheDecG2 = wrap_dec(capi._sheDecG2)
capi.sheCipherTextGTSerialize = wrap_outputArray(capi._sheCipherTextGTSerialize)
capi.sheCipherTextGTDeserialize = wrap_input(capi._sheCipherTextGTDeserialize, 1)
capi.sheDecGT = wrap_dec(capi._sheDecGT)
mod.sheSecretKeySerialize = wrap_outputArray(mod._sheSecretKeySerialize)
mod.sheSecretKeyDeserialize = wrap_input(mod._sheSecretKeyDeserialize, 1)
mod.shePublicKeySerialize = wrap_outputArray(mod._shePublicKeySerialize)
mod.shePublicKeyDeserialize = wrap_input(mod._shePublicKeyDeserialize, 1)
mod.sheCipherTextG1Serialize = wrap_outputArray(mod._sheCipherTextG1Serialize)
mod.sheCipherTextG1Deserialize = wrap_input(mod._sheCipherTextG1Deserialize, 1)
mod.sheDecG1 = wrap_dec(mod._sheDecG1)
mod.sheCipherTextG2Serialize = wrap_outputArray(mod._sheCipherTextG2Serialize)
mod.sheCipherTextG2Deserialize = wrap_input(mod._sheCipherTextG2Deserialize, 1)
mod.sheDecG2 = wrap_dec(mod._sheDecG2)
mod.sheCipherTextGTSerialize = wrap_outputArray(mod._sheCipherTextGTSerialize)
mod.sheCipherTextGTDeserialize = wrap_input(mod._sheCipherTextGTDeserialize, 1)
mod.sheDecGT = wrap_dec(mod._sheDecGT)
capi.sheInit = function(curveType = MCLBN_CURVE_FP254BNB) {
let r = capi._sheInit(curveType, MCLBN_FP_UNIT_SIZE)
console.log('sheInit ' + r)
if (r) throw('sheInit')
}
class Common {
constructor(size) {
this.a_ = new Uint32Array(size / 4)
@ -325,15 +286,15 @@
super(SHE_SECRETKEY_SIZE)
}
serialize() {
return callGetter(capi.sheSecretKeySerialize, this.a_)
return callGetter(mod.sheSecretKeySerialize, this.a_)
}
deserialize(s) {
callSetter(capi.sheSecretKeyDeserialize, this.a_, s)
callSetter(mod.sheSecretKeyDeserialize, this.a_, s)
}
setByCSPRNG() {
let stack = mod.Runtime.stackSave()
let secPos = mod.Runtime.stackAlloc(this.a_.length * 4)
capi.sheSecretKeySetByCSPRNG(secPos)
mod._sheSecretKeySetByCSPRNG(secPos)
copyToUint32Array(this.a_, secPos)
mod.Runtime.stackRestore(stack)
}
@ -343,7 +304,7 @@
let secPos = mod.Runtime.stackAlloc(this.a_.length * 4)
let pubPos = mod.Runtime.stackAlloc(pub.a_.length * 4)
copyFromUint32Array(secPos, this.a_)
capi.sheGetPublicKey(pubPos, secPos)
mod._sheGetPublicKey(pubPos, secPos)
copyToUint32Array(pub.a_, pubPos)
mod.Runtime.stackRestore(stack)
return pub
@ -351,11 +312,11 @@
dec(c) {
let dec = null
if (exports.CipherTextG1.prototype.isPrototypeOf(c)) {
dec = capi.sheDecG1
dec = mod.sheDecG1
} else if (exports.CipherTextG2.prototype.isPrototypeOf(c)) {
dec = capi.sheDecG2
dec = mod.sheDecG2
} else if (exports.CipherTextGT.prototype.isPrototypeOf(c)) {
dec = capi.sheDecGT
dec = mod.sheDecGT
} else {
throw('exports.SecretKey.dec:not supported')
}
@ -373,43 +334,44 @@
super(SHE_PUBLICKEY_SIZE)
}
serialize() {
return callGetter(capi.shePublicKeySerialize, this.a_)
return callGetter(mod.shePublicKeySerialize, this.a_)
}
deserialize(s) {
callSetter(capi.shePublicKeyDeserialize, this.a_, s)
callSetter(mod.shePublicKeyDeserialize, this.a_, s)
}
encG1(m) {
return callEnc(capi.sheEnc32G1, exports.CipherTextG1, this.a_, m)
return callEnc(mod._sheEnc32G1, exports.CipherTextG1, this.a_, m)
}
encG2(m) {
return callEnc(capi.sheEnc32G2, exports.CipherTextG2, this.a_, m)
return callEnc(mod._sheEnc32G2, exports.CipherTextG2, this.a_, m)
}
encGT(m) {
return callEnc(capi.sheEnc32GT, exports.CipherTextGT, this.a_, m)
return callEnc(mod._sheEnc32GT, exports.CipherTextGT, this.a_, m)
}
reRand(c) {
let reRand = null
if (exports.CipherTextG1.prototype.isPrototypeOf(c)) {
reRand = capi.sheReRandG1
reRand = mod._sheReRandG1
} else if (exports.CipherTextG2.prototype.isPrototypeOf(c)) {
reRand = capi.sheReRandG2
reRand = mod._sheReRandG2
} else if (exports.CipherTextGT.prototype.isPrototypeOf(c)) {
reRand = capi.sheReRandGT
reRand = mod._sheReRandGT
} else {
throw('exports.PublicKey.reRand:not supported')
}
return callReRand(reRand, c.a_, this.a_)
}
convertToCipherTextGT(c) {
let convertFrom = null
// convert to CipherTextGT
convert(c) {
let convert = null
if (exports.CipherTextG1.prototype.isPrototypeOf(c)) {
convertFrom = capi.sheConvertFromG1
convert = mod._sheConvertG1
} else if (exports.CipherTextG2.prototype.isPrototypeOf(c)) {
convertFrom = capi.sheConvertFromG2
convert = mod._sheConvertG2
} else {
throw('exports.PublicKey.convertToCipherTextGT:not supported')
throw('exports.PublicKey.convert:not supported')
}
return callConvertFrom(convertFrom, this.a_, c.a_)
return callConvert(convert, this.a_, c.a_)
}
}
@ -423,10 +385,10 @@
super(SHE_CIPHERTEXT_G1_SIZE)
}
serialize() {
return callGetter(capi.sheCipherTextG1Serialize, this.a_)
return callGetter(mod.sheCipherTextG1Serialize, this.a_)
}
deserialize(s) {
callSetter(capi.sheCipherTextG1Deserialize, this.a_, s)
callSetter(mod.sheCipherTextG1Deserialize, this.a_, s)
}
}
@ -440,10 +402,10 @@
super(SHE_CIPHERTEXT_G2_SIZE)
}
serialize() {
return callGetter(capi.sheCipherTextG2Serialize, this.a_)
return callGetter(mod.sheCipherTextG2Serialize, this.a_)
}
deserialize(s) {
callSetter(capi.sheCipherTextG2Deserialize, this.a_, s)
callSetter(mod.sheCipherTextG2Deserialize, this.a_, s)
}
}
@ -458,10 +420,10 @@
super(SHE_CIPHERTEXT_GT_SIZE)
}
serialize() {
return callGetter(capi.sheCipherTextGTSerialize, this.a_)
return callGetter(mod.sheCipherTextGTSerialize, this.a_)
}
deserialize(s) {
callSetter(capi.sheCipherTextGTDeserialize, this.a_, s)
callSetter(mod.sheCipherTextGTDeserialize, this.a_, s)
}
}
@ -476,13 +438,13 @@
let add = null
let cstr = null
if (exports.CipherTextG1.prototype.isPrototypeOf(x)) {
add = capi.sheAddG1
add = mod._sheAddG1
cstr = exports.CipherTextG1
} else if (exports.CipherTextG2.prototype.isPrototypeOf(x)) {
add = capi.sheAddG2
add = mod._sheAddG2
cstr = exports.CipherTextG2
} else if (exports.CipherTextGT.prototype.isPrototypeOf(x)) {
add = capi.sheAddGT
add = mod._sheAddGT
cstr = exports.CipherTextGT
} else {
throw('exports.add:not supported')
@ -495,13 +457,13 @@
let sub = null
let cstr = null
if (exports.CipherTextG1.prototype.isPrototypeOf(x)) {
sub = capi.sheSubG1
sub = mod._sheSubG1
cstr = exports.CipherTextG1
} else if (exports.CipherTextG2.prototype.isPrototypeOf(x)) {
sub = capi.sheSubG2
sub = mod._sheSubG2
cstr = exports.CipherTextG2
} else if (exports.CipherTextGT.prototype.isPrototypeOf(x)) {
sub = capi.sheSubGT
sub = mod._sheSubGT
cstr = exports.CipherTextGT
} else {
throw('exports.sub:not supported')
@ -513,13 +475,13 @@
let mulInt = null
let cstr = null
if (exports.CipherTextG1.prototype.isPrototypeOf(x)) {
mulInt = capi.sheMul32G1
mulInt = mod._sheMul32G1
cstr = exports.CipherTextG1
} else if (exports.CipherTextG2.prototype.isPrototypeOf(x)) {
mulInt = capi.sheMul32G2
mulInt = mod._sheMul32G2
cstr = exports.CipherTextG2
} else if (exports.CipherTextGT.prototype.isPrototypeOf(x)) {
mulInt = capi.sheMul32GT
mulInt = mod._sheMul32GT
cstr = exports.CipherTextGT
} else {
throw('exports.mulInt:not supported')
@ -537,7 +499,7 @@
let zPos = mod.Runtime.stackAlloc(z.a_.length * 4)
copyFromUint32Array(xPos, x.a_)
copyFromUint32Array(yPos, y.a_)
capi.sheMul(zPos, xPos, yPos)
mod._sheMul(zPos, xPos, yPos)
copyToUint32Array(z.a_, zPos)
mod.Runtime.stackRestore(stack)
return z

File diff suppressed because one or more lines are too long

Binary file not shown.

@ -161,8 +161,8 @@ MCLSHE_DLL_API int sheReRandGT(sheCipherTextGT *c, const shePublicKey *pub);
// return 0 if success
// y = convert(x)
MCLSHE_DLL_API int sheConvertFromG1(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG1 *x);
MCLSHE_DLL_API int sheConvertFromG2(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG2 *x);
MCLSHE_DLL_API int sheConvertG1(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG1 *x);
MCLSHE_DLL_API int sheConvertG2(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG2 *x);
#ifdef __cplusplus
}

@ -766,7 +766,7 @@ public:
/*
convert from CipherTextG1 to CipherTextGT
*/
void convertToCipherTextGT(CipherTextGT& cm, const CipherTextG1& c1) const
void convert(CipherTextGT& cm, const CipherTextG1& c1) const
{
/*
Enc(1) = (S, T) = (Q + r yQ, rQ) = (Q, 0) if r = 0
@ -784,7 +784,7 @@ public:
/*
convert from CipherTextG2 to CipherTextGT
*/
void convertToCipherTextGT(CipherTextGT& cm, const CipherTextG2& c2) const
void convert(CipherTextGT& cm, const CipherTextG2& c2) const
{
/*
Enc(1) = (S, T) = (P + r xP, rP) = (P, 0) if r = 0
@ -793,15 +793,15 @@ public:
G1 zero; zero.clear();
tensorProduct(cm.g_, P_, zero, c2.S_, c2.T_);
}
void convertToCipherTextGT(CipherTextGT& cm, const CipherTextA& ca) const
void convert(CipherTextGT& cm, const CipherTextA& ca) const
{
convertToCipherTextGT(cm, ca.c1_);
convert(cm, ca.c1_);
}
void convertToCipherTextGT(CipherText& cm, const CipherText& ca) const
void convert(CipherText& cm, const CipherText& ca) const
{
if (ca.isMultiplied()) throw cybozu::Exception("she:PublicKey:convertCipherText:already isMultiplied");
cm.isMultiplied_ = true;
convertToCipherTextGT(cm.m_, ca.a_);
convert(cm.m_, ca.a_);
}
/*
c += Enc(0)

@ -423,22 +423,22 @@ int sheReRandGT(sheCipherTextGT *c, const shePublicKey *pub)
}
template<class CT>
int convertTo(sheCipherTextGT *y, const shePublicKey *pub, const CT *x)
int convert(sheCipherTextGT *y, const shePublicKey *pub, const CT *x)
try
{
cast(pub)->convertToCipherTextGT(*cast(y), *cast(x));
cast(pub)->convert(*cast(y), *cast(x));
return 0;
} catch (std::exception& e) {
fprintf(stderr, "err %s\n", e.what());
return -1;
}
int sheConvertFromG1(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG1 *x)
int sheConvertG1(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG1 *x)
{
return convertTo(y, pub, x);
return convert(y, pub, x);
}
int sheConvertFromG2(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG2 *x)
int sheConvertG2(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG2 *x)
{
return convertTo(y, pub, x);
return convert(y, pub, x);
}

@ -207,7 +207,7 @@ CYBOZU_TEST_AUTO(serialize)
CYBOZU_TEST_EQUAL_ARRAY(buf1, buf2, n2);
}
CYBOZU_TEST_AUTO(convertFrom)
CYBOZU_TEST_AUTO(convert)
{
sheSecretKey sec;
sheSecretKeySetByCSPRNG(&sec);
@ -220,7 +220,7 @@ CYBOZU_TEST_AUTO(convertFrom)
sheEnc32G1(&c1, &pub, m);
CYBOZU_TEST_EQUAL(sheDecG1(&dec, &sec, &c1), 0);
CYBOZU_TEST_EQUAL(dec, 123);
sheConvertFromG1(&ct, &pub, &c1);
sheConvertG1(&ct, &pub, &c1);
dec = 0;
CYBOZU_TEST_EQUAL(sheDecGT(&dec, &sec, &ct), 0);
CYBOZU_TEST_EQUAL(dec, 123);
@ -229,7 +229,7 @@ CYBOZU_TEST_AUTO(convertFrom)
sheEnc32G2(&c2, &pub, m);
CYBOZU_TEST_EQUAL(sheDecG2(&dec, &sec, &c2), 0);
CYBOZU_TEST_EQUAL(dec, 123);
sheConvertFromG2(&ct, &pub, &c2);
sheConvertG2(&ct, &pub, &c2);
dec = 0;
CYBOZU_TEST_EQUAL(sheDecGT(&dec, &sec, &ct), 0);
CYBOZU_TEST_EQUAL(dec, 123);

@ -168,7 +168,7 @@ CYBOZU_TEST_AUTO(add_mul_add_sub)
CYBOZU_TEST_EQUAL(sec.dec(c[i]), m[i]);
CYBOZU_TEST_ASSERT(!c[i].isMultiplied());
CipherText mc;
pub.convertToCipherTextGT(mc, c[i]);
pub.convert(mc, c[i]);
CYBOZU_TEST_ASSERT(mc.isMultiplied());
CYBOZU_TEST_EQUAL(sec.dec(mc), m[i]);
}

Loading…
Cancel
Save