Tuesday 20 June 2017

Scalar Multiplication in Elliptic curve in Crypto++

#include<bits/stdc++.h>
using std::cout;
using std::endl;

#include <cryptopp/ecp.h>
#include <cryptopp/asn.h>
#include <cryptopp/integer.h>
using CryptoPP::Integer;

#include <cryptopp/eccrypto.h>
using CryptoPP::ECP;    // Prime field
using CryptoPP::ECPPoint;
using CryptoPP::DL_GroupParameters_EC;

#include <cryptopp/asn.h>
#include <cryptopp/oids.h>
namespace ASN1 = CryptoPP::ASN1;

int main()
{
	DL_GroupParameters_EC<ECP> groupParameter = ASN1::secp160r1();

	
	cout << "Modulus: "<< groupParameter.GetCurve().GetField().GetModulus() << endl;
	cout << "Cofactor: "<< groupParameter.GetCofactor() << endl;
		    
	cout << "Coefficients" << endl;
	cout << "  A: "<< groupParameter.GetCurve().GetA() << endl;
	cout << "  B: "<< groupParameter.GetCurve().GetB() << endl;
	
	ECP curve=groupParameter.GetCurve();
	
	Integer y = groupParameter.GetSubgroupGenerator().x;
	Integer x = groupParameter.GetSubgroupGenerator().y;
	
	ECPPoint P=ECPPoint(x,y);
	cout<<"P = "<<P.x<<" , "<<P.y<<endl;

	ECPPoint R = curve.ScalarMultiply(P,Integer(2));

	cout<<"R = "<<R.x<<" , "<<R.y<<endl;

	return 0;
}



No comments:

Post a Comment