remove throw in ecdsa-wasm

dev
MITSUNARI Shigeo 7 years ago
parent 76c73cb0da
commit b3c2b12093
  1. 2
      Makefile
  2. 16
      include/mcl/ecdsa.hpp
  3. 2
      include/mcl/ecparam.hpp
  4. 6
      include/mcl/window_method.hpp
  5. 5
      src/ecdsa_c.cpp

@ -267,7 +267,7 @@ endif
emcc -o $@ src/fp.cpp src/bn_c512.cpp $(EMCC_OPT) -DMCL_MAX_BIT_SIZE=512 -DMCL_USE_WEB_CRYPTO_API -s DISABLE_EXCEPTION_CATCHING=1 -DCYBOZU_DONT_USE_EXCEPTION -DCYBOZU_DONT_USE_STRING -fno-exceptions
../ecdsa-wasm/ecdsa_c.js: src/ecdsa_c.cpp src/fp.cpp include/mcl/ecdsa.hpp include/mcl/ecdsa.h Makefile
emcc -o $@ src/fp.cpp src/ecdsa_c.cpp $(EMCC_OPT) -DMCL_MAX_BIT_SIZE=256 -DMCL_USE_WEB_CRYPTO_API -s DISABLE_EXCEPTION_CATCHING=1
emcc -o $@ src/fp.cpp src/ecdsa_c.cpp $(EMCC_OPT) -DMCL_MAX_BIT_SIZE=256 -DMCL_USE_WEB_CRYPTO_API -s DISABLE_EXCEPTION_CATCHING=1 -DCYBOZU_DONT_USE_EXCEPTION -DCYBOZU_DONT_USE_STRING -fno-exceptions
mcl-wasm:
$(MAKE) ../mcl-wasm/mcl_c.js

@ -91,16 +91,24 @@ inline void init(bool *pb)
Ec::setIoMode(mcl::IoEcAffine);
local::Param& p = local::getParam();
p.ecParam = ecParam;
p.P.set(Fp(ecParam.gx), Fp(ecParam.gy));
Fp x, y;
x.setStr(pb, ecParam.gx);
if (!*pb) return;
y.setStr(pb, ecParam.gy);
if (!*pb) return;
p.P.set(pb, x, y);
if (!*pb) return;
p.Pbase.init(pb, p.P, ecParam.bitSize, local::winSize);
}
#ifndef CYBOZU_DONT_USE_EXCEPTION
inline void init()
{
bool b;
init(&b);
if (!b) throw cybozu::Exception("ecdsa:init");
}
#endif
typedef Zn SecretKey;
typedef Ec PublicKey;
@ -111,12 +119,14 @@ struct PrecomputedPublicKey {
{
pubBase_.init(pb, pub, param.ecParam.bitSize, local::winSize);
}
#ifndef CYBOZU_DONT_USE_EXCEPTION
void init(const PublicKey& pub)
{
bool b;
init(&b, pub);
if (!b) throw cybozu::Exception("ecdsa:PrecomputedPublicKey:init");
}
#endif
};
inline void getPublicKey(PublicKey& pub, const SecretKey& sec)
@ -144,6 +154,7 @@ struct Signature : public mcl::fp::Serializable<Signature> {
}
s.save(pb, os, ioMode);
}
#ifndef CYBOZU_DONT_USE_EXCEPTION
template<class InputStream>
void load(InputStream& is, int ioMode = IoSerialize)
{
@ -158,6 +169,8 @@ struct Signature : public mcl::fp::Serializable<Signature> {
save(&b, os, ioMode);
if (!b) throw cybozu::Exception("ecdsa:Signature:save");
}
#endif
#ifndef CYBOZU_DONT_USE_STRING
friend std::istream& operator>>(std::istream& is, Signature& self)
{
self.load(is, fp::detectIoMode(Ec::getIoMode(), is));
@ -168,6 +181,7 @@ struct Signature : public mcl::fp::Serializable<Signature> {
self.save(os, fp::detectIoMode(Ec::getIoMode(), os));
return os;
}
#endif
};
inline void sign(Signature& sig, const SecretKey& sec, const void *msg, size_t msgSize)

@ -136,6 +136,7 @@ const struct mcl::EcParam NIST_P521 = {
} // mcl::ecparam
#ifndef CYBOZU_DONT_USE_STRING
static inline const mcl::EcParam* getEcParam(const std::string& name)
{
static const mcl::EcParam *tbl[] = {
@ -158,5 +159,6 @@ static inline const mcl::EcParam* getEcParam(const std::string& name)
}
throw cybozu::Exception("mcl::getEcParam:not support name") << name;
}
#endif
} // mcl

@ -109,12 +109,14 @@ public:
}
}
}
#ifndef CYBOZU_DONT_USE_EXCEPTION
void init(const Ec& x, size_t bitSize, size_t winSize)
{
bool b;
init(&b, x, bitSize, winSize);
if (!b) throw cybozu::Exception("mcl:WindowMethod:init") << bitSize << winSize;
}
#endif
/*
@param z [out] x multiplied by y
@param y [in] exponent
@ -129,10 +131,10 @@ public:
void mul(Ec& z, int64_t y) const
{
#if MCL_SIZEOF_UNIT == 8
Unit u = std::abs(y);
Unit u = fp::abs_(y);
powArray(z, &u, 1, y < 0);
#else
uint64_t ua = std::abs(y);
uint64_t ua = fp::abs_(y);
Unit u[2] = { uint32_t(ua), uint32_t(ua >> 32) };
size_t un = u[1] ? 2 : 1;
powArray(z, u, un, y < 0);

@ -1,6 +1,7 @@
#define ECDSA_DLL_EXPORT
#include <mcl/ecdsa.h>
#include <mcl/ecdsa.hpp>
#include <new>
using namespace mcl::ecdsa;
@ -18,6 +19,10 @@ static const PrecomputedPublicKey *cast(const ecdsaPrecomputedPublicKey *p) { re
#ifdef __EMSCRIPTEN__
// use these functions forcibly
extern "C" ECDSA_DLL_API void *ecdsaMalloc(size_t n)
{
return malloc(n);
}
extern "C" ECDSA_DLL_API void ecdsaFree(void *p)
{
free(p);

Loading…
Cancel
Save