Hi All,

Onto the next stumbling block. I think this is due more to my EC
ignorance than anything else, so pointers are appreciated.

ECB has generated the following parameters:

Root of Q over GF(P)
--------------------
Z = 1

Curve of Order R*S over GF(P)
-----------------------------
P = 16645250515930250003
R = 2774208418037906651
S = 6
A = 13660927788187972202
B = -2661640677458764141

I am attempting to use DL_GroupParameters_EC< EC >::Intialize(...). I
am able to Encrypt (but I don't know if it is successful at this
point). Decryption blows up. I was forming Point G as (R, S) - I am
fairly certain this is not correct. I assumed

Initialize( ) is documented (with no comments as to Point G, Integer
n, and Integer k) at
http://cryptopp.sourceforge.net/docs/ref521/class_d_l___group_parameters___e_c.html

Also, Wei: Please forgive my ignorance with ValidateECDSA().

Jeff

// Crypto++ Includes
#include "cryptlib.h"
#include "osrng.h"
#include "eccrypto.h"
#include "asn.h"
#include "ecp.h"
#include "simple.h"
#include "integer.h"

int main(int argc, char* argv[]) {

   try {

       // User Defined Curve Parameters
       CryptoPP::Integer modulos = CryptoPP::Integer( "16645250515930250003" );
       CryptoPP::Integer a( "13660927788187972202" );
       CryptoPP::Integer b( "-2661640677458764141" );

       CryptoPP::ECP ec( modulos, a, b );

       CryptoPP::ECIES< CryptoPP::ECP >::PrivateKey    PrivateKey;
       CryptoPP::ECIES< CryptoPP::ECP >::PublicKey     PublicKey;
       CryptoPP::AutoSeededRandomPool                  rng;

       // PrivateKey.Initialize( rng, CryptoPP::ASN1::secp112r1() );
       //   Worked... But we want a smaller curve

       // PrivateKey.Initialize( rng, ec );
       //   No constructor (ctor)

       // PrivateKey.Initialize( rng, modulos );
       //   Throws "RandomPool: CopyRangeTo2() is not supported by this store"

       // G is not correct
       PrivateKey.Initialize( ec, G, CryptoPP::Integer::One(),
CryptoPP::Integer::Zero() );
       //   Throws "Crypto++ Error: Integer: Min must be no greater than Max"
       //    Should b := b + modulous to make positive?

       // Encryptor and Decryptor
       CryptoPP::ECIES< CryptoPP::ECP >::Encryptor Encryptor( PublicKey );
       CryptoPP::ECIES< CryptoPP::ECP >::Decryptor Decryptor( PrivateKey );

       // Message
       std::string PlainText = "ECC";
       // std::string PlainText = "ECC Test";
       // std::string PlainText = "Yoda said, Do or do not. There is no try.";
       // std::string PlainText = "Winnie the Pooh said, I am a bear
of very little brain, and long words bother me.";

       // Runtime Sizes...
       unsigned int PlainTextLength = PlainText.length() + 1;
       unsigned int CipherTextLength = Encryptor.CiphertextLength(
PlainTextLength );
       if( 0 == CipherTextLength ) { throw
std::string("plaintextLength is not valid (too long)"); }

       // Diagnostics
       std::cout << "Plain text:" << std::endl << "    '" <<
PlainText << "'" << std::endl;
       std::cout << "The plain text length is " << PlainTextLength <<
" (including the trailing '\\0')" << std::endl;

       std::cout << "The cipher text length for this message is " <<
CipherTextLength << std::endl;

       // Scratch for Encryption
       byte* CipherText = new byte[ CipherTextLength ];
       if( NULL == CipherText ) { throw std::string( "CipherText
Allocation Failure" ); }
       ::memset( CipherText, 0xFB, Encryptor.CiphertextLength(
PlainTextLength ) );

       // Encryption
       Encryptor.Encrypt( rng, reinterpret_cast<const byte*>(
PlainText.c_str() ), PlainTextLength, CipherText );

       // Scratch for Decryption
       unsigned int RecoveredTextLength =
Decryptor.MaxPlaintextLength( CipherTextLength );
       if( 0 == RecoveredTextLength ) { throw
std::string("ciphertextLength is not valid (too long or too short)");
}

       // Decryption Buffer
       char* RecoveredText = new char[ RecoveredTextLength ];
       if( NULL == RecoveredText ) { throw std::string(
"RecoveredText CipherText Allocation Failure" ); }
       ::memset( RecoveredText, 0xFB, PlainTextLength );

       // Decryption
       Decryptor.Decrypt( rng, CipherText, CipherTextLength,
reinterpret_cast<byte*>( RecoveredText ) );

       // Diagnostics
       std::cout << "The recovered text length for this cipher is "
<< RecoveredTextLength << std::endl;
       std::cout << "Recovered text:" << std::endl << "    '" <<
RecoveredText << "'" << std::endl;

       // Cleanup
       if( NULL != CipherText ) { delete[] CipherText; }
       if( NULL != RecoveredText ) { delete[] RecoveredText; }

   }

   catch( CryptoPP::Exception& e ) {
       std::cerr << "Crypto++ Error: " << e.what() << std::endl;
   }

   catch( std::string& s ) {
       std::cerr << "Error: " << s << std::endl;
   }

   catch (...) {
       std::cerr << "Unknown Error" << std::endl;
   }

        return 0;
}

Reply via email to