Signing with prehashed SHA1:

template <typename Hash>class Prehashed : public HashTransformation{public:
  enum { DIGESTSIZE = Hash::DIGESTSIZE };
  static const char * CRYPTOPP_API StaticAlgorithmName() {return 
Hash::StaticAlgorithmName();}

  virtual void Update(const byte *input, size_t length)
  {
    m_prehashed += SecByteBlock(input, length);
  }

  virtual unsigned int DigestSize() const
  {
    return m_prehashed.size();
  }

  virtual void TruncatedFinal(byte *digest, size_t digestSize)
  {
    memcpy(digest, m_prehashed.data(), digestSize);
  }
private:
  SecByteBlock m_prehashed;};
template<> const byte PKCS_DigestDecoration<Prehashed<SHA1> >::decoration[] = 
{0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14};template<>
 const unsigned int PKCS_DigestDecoration<Prehashed<SHA1> >::length = 
sizeof(PKCS_DigestDecoration<Prehashed<SHA1>>::decoration);


// Signer objectRSASS<PKCS1v15, Prehashed<SHA1> >::Signer signer(privateKey);
// Verifier objectRSASS<PKCS1v15, SHA1>::Verifier verifier(publicKey);



Понеділок, 21 лютого 2011 р. 18:06:33 UTC+2 користувач Geoff Beier написав:
>
> On Mon, Feb 21, 2011 at 09:03, Magnus J <[email protected] <javascript:>> 
> wrote:
> > Thank you.
> >
> >> Then I have a factory function that takes the digest buffer and length
> >> as parameters and returns a pointer to a newly allocated
> >> CryptoPP::PK_MessageAccumulatorImpl<MyExternalDigestHashTransformation>.
> >
> > This part gets me a bit perplex though. I still don't see how you get
> > the hash into the message accumulator. The PK_MessageAccumulatorImpl
> > objectholder looks very protected.
> >
>
> It's kind of a dirty trick, but the only way I could find to wire this
> in without subclassing for each digest I wanted. (If anyone knows a
> cleaner way to accomplish this, I'd love to hear. I can confirm that
> this works, though :-) )
>
> Here's the relevant code from my factory:
> http://cryptopp.pastebin.com/d0DHqaqF
>
> Then when signing, the basic flow is
> PK_Signer * signer = 0; // set up signer for the algorithm you need
> PKIFCryptoPPErrorsAccumulator * ed = 
> NewEDAccumulator(pHashData,nHashDataLen);
> signer->Sign(rng, ed, pSignature);
>
> And when verifying it's
> PK_Verifier * verifier = 0; // set up verifier for the algorithm you need
> PKIFCryptoPPExternalDigestAccumulator * ed =
> NewEDAccumulator(pHashData,nHashDataLen);
> verifier->InputSignature(*ed,pSignature,nSignatureLen);
> bool verified = verifier->Verify(ed);
>
>
> HTH,
>
> Geoff
>
>

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to