use secp256k1 in sample/ecdh.cpp

update-fork
MITSUNARI Shigeo 5 years ago
parent e769bd6cea
commit 6761619ba6
  1. 27
      sample/ecdh.cpp

@ -3,43 +3,48 @@
*/
#include <iostream>
#include <fstream>
#include <cybozu/random_generator.hpp>
#include <mcl/fp.hpp>
#include <mcl/ecparam.hpp>
#include <mcl/ec.hpp>
typedef mcl::FpT<mcl::FpTag> Fp;
typedef mcl::FpT<mcl::ZnTag> Zn;
typedef mcl::FpT<mcl::FpTag, 256> Fp;
typedef mcl::FpT<mcl::ZnTag, 256> Fr;
typedef mcl::EcT<Fp> Ec;
void put(const char *msg, const Ec& P)
{
std::cout << msg << P.getStr(mcl::IoEcAffine | 16) << std::endl;
}
int main()
{
/*
Ec is an elliptic curve over Fp
the cyclic group of <P> is isomorphic to Zn
the cyclic group of <P> is isomorphic to Fr
*/
Ec P;
mcl::initCurve<Ec, Zn>(MCL_SECP192K1, &P);
mcl::initCurve<Ec, Fr>(MCL_SECP256K1, &P);
put("P=", P);
/*
Alice setups a private key a and public key aP
*/
Zn a;
Fr a;
Ec aP;
a.setByCSPRNG();
Ec::mul(aP, P, a); // aP = a * P;
std::cout << "aP=" << aP << std::endl;
put("aP=", aP);
/*
Bob setups a private key b and public key bP
*/
Zn b;
Fr b;
Ec bP;
b.setByCSPRNG();
Ec::mul(bP, P, b); // bP = b * P;
std::cout << "bP=" << bP << std::endl;
put("bP=", bP);
Ec abP, baP;

Loading…
Cancel
Save