Elliptic Curve Cryptography
From Crypto++ Wiki
Elliptic Curve Cryptography (ECC) is based on the algebraic structure of elliptic curves over finite fields. The use of elliptic curves in cryptography was independently suggested by Neal Koblitz and Victor Miller in 1985. Certicom holds a majority of patents in the Elliptic Curve Cryptography arena.
Contents |
Mathematical Problem
Elliptic Curve Cryptography is based on the Discrete Logarithm Problem.
Examples
#define ECC_ALGORITHM CryptoPP::ECP #define ECC_CURVE CryptoPP::ASN1::secp160r1() CryptoPP::ECIES< ECC_ALGORITHM >::PrivateKey PrivateKey; CryptoPP::ECIES< ECC_ALGORITHM >::PublicKey PublicKey; CryptoPP::AutoSeededRandomPool rng; // Curve Key Generation PrivateKey.Initialize( rng, ECC_CURVE ); PrivateKey.MakePublicKey( PublicKey ); // Encryptor and Decryptor CryptoPP::ECIES< ECC_ALGORITHM >::Encryptor Encryptor( PublicKey ); CryptoPP::ECIES< ECC_ALGORITHM >::Decryptor Decryptor( PrivateKey ); // Message std::string PlainText = "Yoda said, Do or do not. There is no try."; ... // Encryption Encryptor.Encrypt( rng, reinterpret_cast<const byte*> ( PlainText.c_str() ), PlainTextLength, CipherText ); ... // Decryption Decryptor.Decrypt( rng, CipherText, CipherTextLength, reinterpret_cast<byte*>( RecoveredText ) );
Minimizing Key Size for Persistence
Taking from Wei Dai on the Crypto++ mailing list:
To minimize the size of public and private keys, what you need to do is encode only the private exponent of the private key, and the public point of the public key.
// save private exponent
PrivateKey.GetPrivateExponent().DEREncode(privFile);
// load private exponent
Integer x;
x.BERDecode(privFile);
PrivateKey.AccessGroupParameters().Initialize(CryptoPP::ASN1::secp160k1());
PrivateKey.SetPrivateExponent(x);
// save public element
PublicKey.GetGroupParameters().GetCurve().EncodePoint(pubFile,
PublicKey.GetPublicElement(), true);
// load public element
ECP::Point p;
PublicKey.AccessGroupParameters().Initialize(CryptoPP::ASN1::secp160k1());
PublicKey.GetGroupParameters().GetCurve().DecodePoint(p, pubFile,
PublicKey.GetGroupParameters().GetCurve().EncodedPointSize(true));
PublicKey.SetPublicElement(p);
Sample Programs
DPVal.zip - Elliptic Curve Domain Parameter Validation. The program dumps the Public and Private keys, and validates the curve per Certicom's SEC 2 Whitepaper. The curve used for demonstartion purposes is NIST P-112. In addition, it demonstrates mathematics with the Point of Infinity and Scalar Multiplications using Crypto++.
ECCTest.zip - Exercises ECC Curves using ANSI and NIST curves by way of #define - 5.8Kb
