Help with FileSource

View: New views
6 Messages — Rating Filter:   Alert me  

Help with FileSource

by SpaceCowboy850 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'm using the Deffie-Hellman algorithm in Crypto 5.60 under Visual
Studio 2005.  I'm trying to create my own seed file instead of using
the ones provided in the example.

This is the way I create my file:

  const size_t seedBufSize = 1024;
  unsigned char seedBuf[seedBufSize];
  g_autoRNG.GenerateBlock( reinterpret_cast<byte*>(seedBuf),
seedBufSize );
  CryptoPP::FileSink fileSink( "seed.dat" );
  fileSink.GetStream()->write( (const char*)seedBuf, seedBufSize );
  fileSink.IsolatedFlush( true, true );

I then try to load it like this:

  CryptoPP::FileSource fileSource( "seed.dat", true );
  g_pKeyAgreementAlg = new CryptoPP::DH(fileSource);

I keep getting a BERDecodeError.  I've tried using a HexDecoder like
this:

  CryptoPP::FileSource fileSource( "seed.dat", true, new
CryptoPP::HexDecoder() );

It appears the first byte is not the asnTag.  I know this is simple,
but what am I doing wrong?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-unsubscribe@....
More information about Crypto++ and this group is available at http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---


Re: Help with FileSource

by Jeffrey Walton-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> It appears the first byte is not the asnTag.  I know this is simple,
> but what am I doing wrong?
You're writing random data, and then trying to read it as an ASN.1
encoded object. Take a look at the wiki's DH example, or Crypto++'s
examples in validate1.cpp, validate2.cpp, etc.

Jeff

On 5/27/09, SpaceCowboy850 <browlett@...> wrote:

>
> I'm using the Deffie-Hellman algorithm in Crypto 5.60 under Visual
> Studio 2005.  I'm trying to create my own seed file instead of using
> the ones provided in the example.
>
> This is the way I create my file:
>
>  const size_t seedBufSize = 1024;
>  unsigned char seedBuf[seedBufSize];
>  g_autoRNG.GenerateBlock( reinterpret_cast<byte*>(seedBuf),
> seedBufSize );
>  CryptoPP::FileSink fileSink( "seed.dat" );
>  fileSink.GetStream()->write( (const char*)seedBuf, seedBufSize );
>  fileSink.IsolatedFlush( true, true );
>
> I then try to load it like this:
>
>  CryptoPP::FileSource fileSource( "seed.dat", true );
>  g_pKeyAgreementAlg = new CryptoPP::DH(fileSource);
>
> I keep getting a BERDecodeError.  I've tried using a HexDecoder like
> this:
>
>  CryptoPP::FileSource fileSource( "seed.dat", true, new
> CryptoPP::HexDecoder() );
>
> It appears the first byte is not the asnTag.  I know this is simple,
> but what am I doing wrong?
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-unsubscribe@....
More information about Crypto++ and this group is available at http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---


Re: Help with FileSource

by SpaceCowboy850 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I've taken a look at both of those thoroughly, (http://
www.cryptopp.com/wiki/Diffie-Hellman and the source code in the
examples), and they were very instrumental in getting me a working
version.  I got DH working before I posted the first time using those
two resources.  Now, what I want to do is make my own dat file, but
I'm having trouble locating what generates a dat file and the
requisites for generating this dat file.  From what I can tell, the
dat files are part of the download and not generated by the code.

On May 27, 7:14 pm, Jeffrey Walton <noloa...@...> wrote:

> > It appears the first byte is not the asnTag.  I know this is simple,
> > but what am I doing wrong?
>
> You're writing random data, and then trying to read it as an ASN.1
> encoded object. Take a look at the wiki's DH example, or Crypto++'s
> examples in validate1.cpp, validate2.cpp, etc.
>
> Jeff
>
> On 5/27/09, SpaceCowboy850 <browl...@...> wrote:
>
>
>
> > I'm using the Deffie-Hellman algorithm in Crypto 5.60 under Visual
> > Studio 2005.  I'm trying to create my own seed file instead of using
> > the ones provided in the example.
>
> > This is the way I create my file:
>
> >  const size_t seedBufSize = 1024;
> >  unsigned char seedBuf[seedBufSize];
> >  g_autoRNG.GenerateBlock( reinterpret_cast<byte*>(seedBuf),
> > seedBufSize );
> >  CryptoPP::FileSink fileSink( "seed.dat" );
> >  fileSink.GetStream()->write( (const char*)seedBuf, seedBufSize );
> >  fileSink.IsolatedFlush( true, true );
>
> > I then try to load it like this:
>
> >  CryptoPP::FileSource fileSource( "seed.dat", true );
> >  g_pKeyAgreementAlg = new CryptoPP::DH(fileSource);
>
> > I keep getting a BERDecodeError.  I've tried using a HexDecoder like
> > this:
>
> >  CryptoPP::FileSource fileSource( "seed.dat", true, new
> > CryptoPP::HexDecoder() );
>
> > It appears the first byte is not the asnTag.  I know this is simple,
> > but what am I doing wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-unsubscribe@....
More information about Crypto++ and this group is available at http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---


Re: Help with FileSource

by SpaceCowboy850 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Really this comes down to three issues:

1)  How do I generate a DH prime and generator (primitive root modulo
the prime)?  I see how to generate a prime with the Integer class, but
that has no way of setting a generator or getting the generator for
the generated prime.  I'm beginning to think that the dat file has the
prime and generator and is not just a seed value for the PRNG.  (Also,
I'm not talking about how to simply access the modulus that is there,
as that is easy.  I want to be able to set my own and not use the
example).

2)  How do I save this prime/generator pair out?  I'm guessing once I
have step 1, it is as simple as calling SetModulusAndSubgroupGenerator
on my GroupParameters, then saying groupParameters->Save( FileSink );
From what I can tell, I need to write out a prime, a q (??) and a
generator.  Not sure what the second integer being read in during the
BERDecode is though (I think maybe the subgroup order?  I guess I'll
need to set that as well).

3)  Ideally, it would be nice to be able to create the prime/generator
pair and save them without going through the GroupParameters.  I'm
somewhat confused that it looks like there is a BERDecoder, but you
can only encode with DEREncode...I would think there would be
corrolary functions (BEREncode, for instance).

The search continues...

On May 28, 11:19 am, SpaceCowboy850 <browl...@...> wrote:

> I've taken a look at both of those thoroughly, (http://www.cryptopp.com/wiki/Diffie-Hellmanand the source code in the
> examples), and they were very instrumental in getting me a working
> version.  I got DH working before I posted the first time using those
> two resources.  Now, what I want to do is make my own dat file, but
> I'm having trouble locating what generates a dat file and the
> requisites for generating this dat file.  From what I can tell, the
> dat files are part of the download and not generated by the code.
>
> On May 27, 7:14 pm, Jeffrey Walton <noloa...@...> wrote:
>
> > > It appears the first byte is not the asnTag.  I know this is simple,
> > > but what am I doing wrong?
>
> > You're writing random data, and then trying to read it as an ASN.1
> > encoded object. Take a look at the wiki's DH example, or Crypto++'s
> > examples in validate1.cpp, validate2.cpp, etc.
>
> > Jeff
>
> > On 5/27/09, SpaceCowboy850 <browl...@...> wrote:
>
> > > I'm using the Deffie-Hellman algorithm in Crypto 5.60 under Visual
> > > Studio 2005.  I'm trying to create my own seed file instead of using
> > > the ones provided in the example.
>
> > > This is the way I create my file:
>
> > >  const size_t seedBufSize = 1024;
> > >  unsigned char seedBuf[seedBufSize];
> > >  g_autoRNG.GenerateBlock( reinterpret_cast<byte*>(seedBuf),
> > > seedBufSize );
> > >  CryptoPP::FileSink fileSink( "seed.dat" );
> > >  fileSink.GetStream()->write( (const char*)seedBuf, seedBufSize );
> > >  fileSink.IsolatedFlush( true, true );
>
> > > I then try to load it like this:
>
> > >  CryptoPP::FileSource fileSource( "seed.dat", true );
> > >  g_pKeyAgreementAlg = new CryptoPP::DH(fileSource);
>
> > > I keep getting a BERDecodeError.  I've tried using a HexDecoder like
> > > this:
>
> > >  CryptoPP::FileSource fileSource( "seed.dat", true, new
> > > CryptoPP::HexDecoder() );
>
> > > It appears the first byte is not the asnTag.  I know this is simple,
> > > but what am I doing wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-unsubscribe@....
More information about Crypto++ and this group is available at http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---


Re: Help with FileSource

by SpaceCowboy850 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Okay...I finally found the answer.

It WAS in the wiki, though not very well highlighted.  The example I
got working I was using the example code from the samples to kick off
my first DH algorithm (which inits the algorithm via a file), then I
was extracting the prime/generator and passing those values to the
other end of the algorithm.  This ended up bypassing the first few
lines in the wiki example which did the prime/generator generation I
was missing.

AutoSeededRandomPool arngA;
RandomNumberGenerator& rngA = *dynamic_cast<RandomNumberGenerator *>
(&arngA);
DH dhA(rngA, 128);

Having some comments on the DH constructors would help a lot,
especially since the parameters aren't very meaningful (v1, v2, v3...)

On May 28, 4:17 pm, SpaceCowboy850 <browl...@...> wrote:

> Really this comes down to three issues:
>
> 1)  How do I generate a DH prime and generator (primitive root modulo
> the prime)?  I see how to generate a prime with the Integer class, but
> that has no way of setting a generator or getting the generator for
> the generated prime.  I'm beginning to think that the dat file has the
> prime and generator and is not just a seed value for the PRNG.  (Also,
> I'm not talking about how to simply access the modulus that is there,
> as that is easy.  I want to be able to set my own and not use the
> example).
>
> 2)  How do I save this prime/generator pair out?  I'm guessing once I
> have step 1, it is as simple as calling SetModulusAndSubgroupGenerator
> on my GroupParameters, then saying groupParameters->Save( FileSink );
> From what I can tell, I need to write out a prime, a q (??) and a
> generator.  Not sure what the second integer being read in during the
> BERDecode is though (I think maybe the subgroup order?  I guess I'll
> need to set that as well).
>
> 3)  Ideally, it would be nice to be able to create the prime/generator
> pair and save them without going through the GroupParameters.  I'm
> somewhat confused that it looks like there is a BERDecoder, but you
> can only encode with DEREncode...I would think there would be
> corrolary functions (BEREncode, for instance).
>
> The search continues...
>
> On May 28, 11:19 am, SpaceCowboy850 <browl...@...> wrote:
>
> > I've taken a look at both of those thoroughly, (http://www.cryptopp.com/wiki/Diffie-Hellmanandthe source code in the
> > examples), and they were very instrumental in getting me a working
> > version.  I got DH working before I posted the first time using those
> > two resources.  Now, what I want to do is make my own dat file, but
> > I'm having trouble locating what generates a dat file and the
> > requisites for generating this dat file.  From what I can tell, the
> > dat files are part of the download and not generated by the code.
>
> > On May 27, 7:14 pm, Jeffrey Walton <noloa...@...> wrote:
>
> > > > It appears the first byte is not the asnTag.  I know this is simple,
> > > > but what am I doing wrong?
>
> > > You're writing random data, and then trying to read it as an ASN.1
> > > encoded object. Take a look at the wiki's DH example, or Crypto++'s
> > > examples in validate1.cpp, validate2.cpp, etc.
>
> > > Jeff
>
> > > On 5/27/09, SpaceCowboy850 <browl...@...> wrote:
>
> > > > I'm using the Deffie-Hellman algorithm in Crypto 5.60 under Visual
> > > > Studio 2005.  I'm trying to create my own seed file instead of using
> > > > the ones provided in the example.
>
> > > > This is the way I create my file:
>
> > > >  const size_t seedBufSize = 1024;
> > > >  unsigned char seedBuf[seedBufSize];
> > > >  g_autoRNG.GenerateBlock( reinterpret_cast<byte*>(seedBuf),
> > > > seedBufSize );
> > > >  CryptoPP::FileSink fileSink( "seed.dat" );
> > > >  fileSink.GetStream()->write( (const char*)seedBuf, seedBufSize );
> > > >  fileSink.IsolatedFlush( true, true );
>
> > > > I then try to load it like this:
>
> > > >  CryptoPP::FileSource fileSource( "seed.dat", true );
> > > >  g_pKeyAgreementAlg = new CryptoPP::DH(fileSource);
>
> > > > I keep getting a BERDecodeError.  I've tried using a HexDecoder like
> > > > this:
>
> > > >  CryptoPP::FileSource fileSource( "seed.dat", true, new
> > > > CryptoPP::HexDecoder() );
>
> > > > It appears the first byte is not the asnTag.  I know this is simple,
> > > > but what am I doing wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-unsubscribe@....
More information about Crypto++ and this group is available at http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---


Re: Help with FileSource

by Jeffrey Walton-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>  Having some comments on the DH constructors would help a lot,
>  especially since the parameters aren't very meaningful (v1, v2, v3...)
That's one of the benefits of Wiki :)

On 5/29/09, SpaceCowboy850 <browlett@...> wrote:

>
>  Okay...I finally found the answer.
>
>  It WAS in the wiki, though not very well highlighted.  The example I
>  got working I was using the example code from the samples to kick off
>  my first DH algorithm (which inits the algorithm via a file), then I
>  was extracting the prime/generator and passing those values to the
>  other end of the algorithm.  This ended up bypassing the first few
>  lines in the wiki example which did the prime/generator generation I
>  was missing.
>
>  AutoSeededRandomPool arngA;
>  RandomNumberGenerator& rngA = *dynamic_cast<RandomNumberGenerator *>
>  (&arngA);
>  DH dhA(rngA, 128);
>
>  Having some comments on the DH constructors would help a lot,
>  especially since the parameters aren't very meaningful (v1, v2, v3...)
>
>  [SNIP]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-unsubscribe@....
More information about Crypto++ and this group is available at http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---