Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

cryptlib.cpp

00001 // cryptlib.cpp - written and placed in the public domain by Wei Dai
00002 
00003 #include "pch.h"
00004 
00005 #ifndef CRYPTOPP_IMPORTS
00006 
00007 #include "cryptlib.h"
00008 #include "misc.h"
00009 #include "filters.h"
00010 #include "algparam.h"
00011 #include "fips140.h"
00012 #include "argnames.h"
00013 #include "fltrimpl.h"
00014 
00015 #include <memory>
00016 
00017 NAMESPACE_BEGIN(CryptoPP)
00018 
00019 CRYPTOPP_COMPILE_ASSERT(sizeof(byte) == 1);
00020 CRYPTOPP_COMPILE_ASSERT(sizeof(word16) == 2);
00021 CRYPTOPP_COMPILE_ASSERT(sizeof(word32) == 4);
00022 #ifdef WORD64_AVAILABLE
00023 CRYPTOPP_COMPILE_ASSERT(sizeof(word64) == 8);
00024 #endif
00025 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
00026 CRYPTOPP_COMPILE_ASSERT(sizeof(dword) == 2*sizeof(word));
00027 #endif
00028 
00029 const std::string BufferedTransformation::NULL_CHANNEL;
00030 const NullNameValuePairs g_nullNameValuePairs;
00031 
00032 BufferedTransformation & TheBitBucket()
00033 {
00034         static BitBucket bitBucket;
00035         return bitBucket;
00036 }
00037 
00038 Algorithm::Algorithm(bool checkSelfTestStatus)
00039 {
00040         if (checkSelfTestStatus && FIPS_140_2_ComplianceEnabled())
00041         {
00042                 if (GetPowerUpSelfTestStatus() == POWER_UP_SELF_TEST_NOT_DONE && !PowerUpSelfTestInProgressOnThisThread())
00043                         throw SelfTestFailure("Cryptographic algorithms are disabled before the power-up self tests are performed.");
00044 
00045                 if (GetPowerUpSelfTestStatus() == POWER_UP_SELF_TEST_FAILED)
00046                         throw SelfTestFailure("Cryptographic algorithms are disabled after a power-up self test failed.");
00047         }
00048 }
00049 
00050 void SimpleKeyingInterface::SetKeyWithRounds(const byte *key, unsigned int length, int rounds)
00051 {
00052         SetKey(key, length, MakeParameters(Name::Rounds(), rounds));
00053 }
00054 
00055 void SimpleKeyingInterface::SetKeyWithIV(const byte *key, unsigned int length, const byte *iv)
00056 {
00057         SetKey(key, length, MakeParameters(Name::IV(), iv));
00058 }
00059 
00060 void SimpleKeyingInterface::ThrowIfInvalidKeyLength(const Algorithm &algorithm, unsigned int length)
00061 {
00062         if (!IsValidKeyLength(length))
00063                 throw InvalidKeyLength(algorithm.AlgorithmName(), length);
00064 }
00065 
00066 void SimpleKeyingInterface::ThrowIfResynchronizable()
00067 {
00068         if (IsResynchronizable())
00069                 throw InvalidArgument("SimpleKeyingInterface: this object requires an IV");
00070 }
00071 
00072 void SimpleKeyingInterface::ThrowIfInvalidIV(const byte *iv)
00073 {
00074         if (!iv && !(IVRequirement() == INTERNALLY_GENERATED_IV || IVRequirement() == STRUCTURED_IV || !IsResynchronizable()))
00075                 throw InvalidArgument("SimpleKeyingInterface: this object cannot use a null IV");
00076 }
00077 
00078 const byte * SimpleKeyingInterface::GetIVAndThrowIfInvalid(const NameValuePairs &params)
00079 {
00080         const byte *iv;
00081         if (params.GetValue(Name::IV(), iv))
00082                 ThrowIfInvalidIV(iv);
00083         else
00084                 ThrowIfResynchronizable();
00085         return iv;
00086 }
00087 
00088 void BlockTransformation::ProcessAndXorMultipleBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, unsigned int numberOfBlocks) const
00089 {
00090         unsigned int blockSize = BlockSize();
00091         while (numberOfBlocks--)
00092         {
00093                 ProcessAndXorBlock(inBlocks, xorBlocks, outBlocks);
00094                 inBlocks += blockSize;
00095                 outBlocks += blockSize;
00096                 if (xorBlocks)
00097                         xorBlocks += blockSize;
00098         }
00099 }
00100 
00101 void StreamTransformation::ProcessLastBlock(byte *outString, const byte *inString, unsigned int length)
00102 {
00103         assert(MinLastBlockSize() == 0);        // this function should be overriden otherwise
00104 
00105         if (length == MandatoryBlockSize())
00106                 ProcessData(outString, inString, length);
00107         else if (length != 0)
00108                 throw NotImplemented("StreamTransformation: this object does't support a special last block");
00109 }
00110 
00111 unsigned int RandomNumberGenerator::GenerateBit()
00112 {
00113         return Parity(GenerateByte());
00114 }
00115 
00116 void RandomNumberGenerator::GenerateBlock(byte *output, unsigned int size)
00117 {
00118         while (size--)
00119                 *output++ = GenerateByte();
00120 }
00121 
00122 word32 RandomNumberGenerator::GenerateWord32(word32 min, word32 max)
00123 {
00124         word32 range = max-min;
00125         const int maxBytes = BytePrecision(range);
00126         const int maxBits = BitPrecision(range);
00127 
00128         word32 value;
00129 
00130         do
00131         {
00132                 value = 0;
00133                 for (int i=0; i<maxBytes; i++)
00134                         value = (value << 8) | GenerateByte();
00135 
00136                 value = Crop(value, maxBits);
00137         } while (value > range);
00138 
00139         return value+min;
00140 }
00141 
00142 void RandomNumberGenerator::DiscardBytes(unsigned int n)
00143 {
00144         while (n--)
00145                 GenerateByte();
00146 }
00147 
00148 //! see NullRNG()
00149 class ClassNullRNG : public RandomNumberGenerator
00150 {
00151 public:
00152         std::string AlgorithmName() const {return "NullRNG";}
00153         byte GenerateByte() {throw NotImplemented("NullRNG: NullRNG should only be passed to functions that don't need to generate random bytes");}
00154 };
00155 
00156 RandomNumberGenerator & NullRNG()
00157 {
00158         static ClassNullRNG s_nullRNG;
00159         return s_nullRNG;
00160 }
00161 
00162 bool HashTransformation::TruncatedVerify(const byte *digestIn, unsigned int digestLength)
00163 {
00164         ThrowIfInvalidTruncatedSize(digestLength);
00165         SecByteBlock digest(digestLength);
00166         TruncatedFinal(digest, digestLength);
00167         return memcmp(digest, digestIn, digestLength) == 0;
00168 }
00169 
00170 void HashTransformation::ThrowIfInvalidTruncatedSize(unsigned int size) const
00171 {
00172         if (size > DigestSize())
00173                 throw InvalidArgument("HashTransformation: can't truncate a " + IntToString(DigestSize()) + " byte digest to " + IntToString(size) + " bytes");
00174 }
00175 
00176 unsigned int BufferedTransformation::GetMaxWaitObjectCount() const
00177 {
00178         const BufferedTransformation *t = AttachedTransformation();
00179         return t ? t->GetMaxWaitObjectCount() : 0;
00180 }
00181 
00182 void BufferedTransformation::GetWaitObjects(WaitObjectContainer &container)
00183 {
00184         BufferedTransformation *t = AttachedTransformation();
00185         if (t)
00186                 t->GetWaitObjects(container);
00187 }
00188 
00189 void BufferedTransformation::Initialize(const NameValuePairs &parameters, int propagation)
00190 {
00191         assert(!AttachedTransformation());
00192         IsolatedInitialize(parameters);
00193 }
00194 
00195 bool BufferedTransformation::Flush(bool hardFlush, int propagation, bool blocking)
00196 {
00197         assert(!AttachedTransformation());
00198         return IsolatedFlush(hardFlush, blocking);
00199 }
00200 
00201 bool BufferedTransformation::MessageSeriesEnd(int propagation, bool blocking)
00202 {
00203         assert(!AttachedTransformation());
00204         return IsolatedMessageSeriesEnd(blocking);
00205 }
00206 
00207 byte * BufferedTransformation::ChannelCreatePutSpace(const std::string &channel, unsigned int &size)
00208 {
00209         if (channel.empty())
00210                 return CreatePutSpace(size);
00211         else
00212                 throw NoChannelSupport();
00213 }
00214 
00215 unsigned int BufferedTransformation::ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking)
00216 {
00217         if (channel.empty())
00218                 return Put2(begin, length, messageEnd, blocking);
00219         else
00220                 throw NoChannelSupport();
00221 }
00222 
00223 unsigned int BufferedTransformation::ChannelPutModifiable2(const std::string &channel, byte *begin, unsigned int length, int messageEnd, bool blocking)
00224 {
00225         if (channel.empty())
00226                 return PutModifiable2(begin, length, messageEnd, blocking);
00227         else
00228                 return ChannelPut2(channel, begin, length, messageEnd, blocking);
00229 }
00230 
00231 bool BufferedTransformation::ChannelFlush(const std::string &channel, bool completeFlush, int propagation, bool blocking)
00232 {
00233         if (channel.empty())
00234                 return Flush(completeFlush, propagation, blocking);
00235         else
00236                 throw NoChannelSupport();
00237 }
00238 
00239 bool BufferedTransformation::ChannelMessageSeriesEnd(const std::string &channel, int propagation, bool blocking)
00240 {
00241         if (channel.empty())
00242                 return MessageSeriesEnd(propagation, blocking);
00243         else
00244                 throw NoChannelSupport();
00245 }
00246 
00247 unsigned long BufferedTransformation::MaxRetrievable() const
00248 {
00249         if (AttachedTransformation())
00250                 return AttachedTransformation()->MaxRetrievable();
00251         else
00252                 return CopyTo(TheBitBucket());
00253 }
00254 
00255 bool BufferedTransformation::AnyRetrievable() const
00256 {
00257         if (AttachedTransformation())
00258                 return AttachedTransformation()->AnyRetrievable();
00259         else
00260         {
00261                 byte b;
00262                 return Peek(b) != 0;
00263         }
00264 }
00265 
00266 unsigned int BufferedTransformation::Get(byte &outByte)
00267 {
00268         if (AttachedTransformation())
00269                 return AttachedTransformation()->Get(outByte);
00270         else
00271                 return Get(&outByte, 1);
00272 }
00273 
00274 unsigned int BufferedTransformation::Get(byte *outString, unsigned int getMax)
00275 {
00276         if (AttachedTransformation())
00277                 return AttachedTransformation()->Get(outString, getMax);
00278         else
00279         {
00280                 ArraySink arraySink(outString, getMax);
00281                 return TransferTo(arraySink, getMax);
00282         }
00283 }
00284 
00285 unsigned int BufferedTransformation::Peek(byte &outByte) const
00286 {
00287         if (AttachedTransformation())
00288                 return AttachedTransformation()->Peek(outByte);
00289         else
00290                 return Peek(&outByte, 1);
00291 }
00292 
00293 unsigned int BufferedTransformation::Peek(byte *outString, unsigned int peekMax) const
00294 {
00295         if (AttachedTransformation())
00296                 return AttachedTransformation()->Peek(outString, peekMax);
00297         else
00298         {
00299                 ArraySink arraySink(outString, peekMax);
00300                 return CopyTo(arraySink, peekMax);
00301         }
00302 }
00303 
00304 unsigned long BufferedTransformation::Skip(unsigned long skipMax)
00305 {
00306         if (AttachedTransformation())
00307                 return AttachedTransformation()->Skip(skipMax);
00308         else
00309                 return TransferTo(TheBitBucket(), skipMax);
00310 }
00311 
00312 unsigned long BufferedTransformation::TotalBytesRetrievable() const
00313 {
00314         if (AttachedTransformation())
00315                 return AttachedTransformation()->TotalBytesRetrievable();
00316         else
00317                 return MaxRetrievable();
00318 }
00319 
00320 unsigned int BufferedTransformation::NumberOfMessages() const
00321 {
00322         if (AttachedTransformation())
00323                 return AttachedTransformation()->NumberOfMessages();
00324         else
00325                 return CopyMessagesTo(TheBitBucket());
00326 }
00327 
00328 bool BufferedTransformation::AnyMessages() const
00329 {
00330         if (AttachedTransformation())
00331                 return AttachedTransformation()->AnyMessages();
00332         else
00333                 return NumberOfMessages() != 0;
00334 }
00335 
00336 bool BufferedTransformation::GetNextMessage()
00337 {
00338         if (AttachedTransformation())
00339                 return AttachedTransformation()->GetNextMessage();
00340         else
00341         {
00342                 assert(!AnyMessages());
00343                 return false;
00344         }
00345 }
00346 
00347 unsigned int BufferedTransformation::SkipMessages(unsigned int count)
00348 {
00349         if (AttachedTransformation())
00350                 return AttachedTransformation()->SkipMessages(count);
00351         else
00352                 return TransferMessagesTo(TheBitBucket(), count);
00353 }
00354 
00355 unsigned int BufferedTransformation::TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel, bool blocking)
00356 {
00357         if (AttachedTransformation())
00358                 return AttachedTransformation()->TransferMessagesTo2(target, messageCount, channel, blocking);
00359         else
00360         {
00361                 unsigned int maxMessages = messageCount;
00362                 for (messageCount=0; messageCount < maxMessages && AnyMessages(); messageCount++)
00363                 {
00364                         unsigned int blockedBytes;
00365                         unsigned long transferredBytes;
00366 
00367                         while (AnyRetrievable())
00368                         {
00369                                 transferredBytes = ULONG_MAX;
00370                                 blockedBytes = TransferTo2(target, transferredBytes, channel, blocking);
00371                                 if (blockedBytes > 0)
00372                                         return blockedBytes;
00373                         }
00374 
00375                         if (target.ChannelMessageEnd(channel, GetAutoSignalPropagation(), blocking))
00376                                 return 1;
00377 
00378                         bool result = GetNextMessage();
00379                         assert(result);
00380                 }
00381                 return 0;
00382         }
00383 }
00384 
00385 unsigned int BufferedTransformation::CopyMessagesTo(BufferedTransformation &target, unsigned int count, const std::string &channel) const
00386 {
00387         if (AttachedTransformation())
00388                 return AttachedTransformation()->CopyMessagesTo(target, count, channel);
00389         else
00390                 return 0;
00391 }
00392 
00393 void BufferedTransformation::SkipAll()
00394 {
00395         if (AttachedTransformation())
00396                 AttachedTransformation()->SkipAll();
00397         else
00398         {
00399                 while (SkipMessages()) {}
00400                 while (Skip()) {}
00401         }
00402 }
00403 
00404 unsigned int BufferedTransformation::TransferAllTo2(BufferedTransformation &target, const std::string &channel, bool blocking)
00405 {
00406         if (AttachedTransformation())
00407                 return AttachedTransformation()->TransferAllTo2(target, channel, blocking);
00408         else
00409         {
00410                 assert(!NumberOfMessageSeries());
00411 
00412                 unsigned int messageCount;
00413                 do
00414                 {
00415                         messageCount = UINT_MAX;
00416                         unsigned int blockedBytes = TransferMessagesTo2(target, messageCount, channel, blocking);
00417                         if (blockedBytes)
00418                                 return blockedBytes;
00419                 }
00420                 while (messageCount != 0);
00421 
00422                 unsigned long byteCount;
00423                 do
00424                 {
00425                         byteCount = ULONG_MAX;
00426                         unsigned int blockedBytes = TransferTo2(target, byteCount, channel, blocking);
00427                         if (blockedBytes)
00428                                 return blockedBytes;
00429                 }
00430                 while (byteCount != 0);
00431 
00432                 return 0;
00433         }
00434 }
00435 
00436 void BufferedTransformation::CopyAllTo(BufferedTransformation &target, const std::string &channel) const
00437 {
00438         if (AttachedTransformation())
00439                 AttachedTransformation()->CopyAllTo(target, channel);
00440         else
00441         {
00442                 assert(!NumberOfMessageSeries());
00443                 while (CopyMessagesTo(target, UINT_MAX, channel)) {}
00444         }
00445 }
00446 
00447 void BufferedTransformation::SetRetrievalChannel(const std::string &channel)
00448 {
00449         if (AttachedTransformation())
00450                 AttachedTransformation()->SetRetrievalChannel(channel);
00451 }
00452 
00453 unsigned int BufferedTransformation::ChannelPutWord16(const std::string &channel, word16 value, ByteOrder order, bool blocking)
00454 {
00455         FixedSizeSecBlock<byte, 2> buf;
00456         PutWord(false, order, buf, value);
00457         return ChannelPut(channel, buf, 2, blocking);
00458 }
00459 
00460 unsigned int BufferedTransformation::ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order, bool blocking)
00461 {
00462         FixedSizeSecBlock<byte, 4> buf;
00463         PutWord(false, order, buf, value);
00464         return ChannelPut(channel, buf, 4, blocking);
00465 }
00466 
00467 unsigned int BufferedTransformation::PutWord16(word16 value, ByteOrder order, bool blocking)
00468 {
00469         return ChannelPutWord16(NULL_CHANNEL, value, order, blocking);
00470 }
00471 
00472 unsigned int BufferedTransformation::PutWord32(word32 value, ByteOrder order, bool blocking)
00473 {
00474         return ChannelPutWord32(NULL_CHANNEL, value, order, blocking);
00475 }
00476 
00477 unsigned int BufferedTransformation::PeekWord16(word16 &value, ByteOrder order)
00478 {
00479         byte buf[2] = {0, 0};
00480         unsigned int len = Peek(buf, 2);
00481 
00482         if (order)
00483                 value = (buf[0] << 8) | buf[1];
00484         else
00485                 value = (buf[1] << 8) | buf[0];
00486 
00487         return len;
00488 }
00489 
00490 unsigned int BufferedTransformation::PeekWord32(word32 &value, ByteOrder order)
00491 {
00492         byte buf[4] = {0, 0, 0, 0};
00493         unsigned int len = Peek(buf, 4);
00494 
00495         if (order)
00496                 value = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf [3];
00497         else
00498                 value = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf [0];
00499 
00500         return len;
00501 }
00502 
00503 unsigned int BufferedTransformation::GetWord16(word16 &value, ByteOrder order)
00504 {
00505         return Skip(PeekWord16(value, order));
00506 }
00507 
00508 unsigned int BufferedTransformation::GetWord32(word32 &value, ByteOrder order)
00509 {
00510         return Skip(PeekWord32(value, order));
00511 }
00512 
00513 void BufferedTransformation::Attach(BufferedTransformation *newOut)
00514 {
00515         if (AttachedTransformation() && AttachedTransformation()->Attachable())
00516                 AttachedTransformation()->Attach(newOut);
00517         else
00518                 Detach(newOut);
00519 }
00520 
00521 void GeneratableCryptoMaterial::GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
00522 {
00523         GenerateRandom(rng, MakeParameters("KeySize", (int)keySize));
00524 }
00525 
00526 class PK_DefaultEncryptionFilter : public Unflushable<Filter>
00527 {
00528 public:
00529         PK_DefaultEncryptionFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment, const NameValuePairs &parameters)
00530                 : m_rng(rng), m_encryptor(encryptor), m_parameters(parameters)
00531         {
00532                 Detach(attachment);
00533         }
00534 
00535         unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking)
00536         {
00537                 FILTER_BEGIN;
00538                 m_plaintextQueue.Put(inString, length);
00539 
00540                 if (messageEnd)
00541                 {
00542                         {
00543                         unsigned int plaintextLength = m_plaintextQueue.CurrentSize();
00544                         unsigned int ciphertextLength = m_encryptor.CiphertextLength(plaintextLength);
00545 
00546                         SecByteBlock plaintext(plaintextLength);
00547                         m_plaintextQueue.Get(plaintext, plaintextLength);
00548                         m_ciphertext.resize(ciphertextLength);
00549                         m_encryptor.Encrypt(m_rng, plaintext, plaintextLength, m_ciphertext, m_parameters);
00550                         }
00551                         
00552                         FILTER_OUTPUT(1, m_ciphertext, m_ciphertext.size(), messageEnd);
00553                 }
00554                 FILTER_END_NO_MESSAGE_END;
00555         }
00556 
00557         RandomNumberGenerator &m_rng;
00558         const PK_Encryptor &m_encryptor;
00559         const NameValuePairs &m_parameters;
00560         ByteQueue m_plaintextQueue;
00561         SecByteBlock m_ciphertext;
00562 };
00563 
00564 BufferedTransformation * PK_Encryptor::CreateEncryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs &parameters) const
00565 {
00566         return new PK_DefaultEncryptionFilter(rng, *this, attachment, parameters);
00567 }
00568 
00569 class PK_DefaultDecryptionFilter : public Unflushable<Filter>
00570 {
00571 public:
00572         PK_DefaultDecryptionFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment, const NameValuePairs &parameters)
00573                 : m_rng(rng), m_decryptor(decryptor), m_parameters(parameters)
00574         {
00575                 Detach(attachment);
00576         }
00577 
00578         unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking)
00579         {
00580                 FILTER_BEGIN;
00581                 m_ciphertextQueue.Put(inString, length);
00582 
00583                 if (messageEnd)
00584                 {
00585                         {
00586                         unsigned int ciphertextLength = m_ciphertextQueue.CurrentSize();
00587                         unsigned int maxPlaintextLength = m_decryptor.MaxPlaintextLength(ciphertextLength);
00588 
00589                         SecByteBlock ciphertext(ciphertextLength);
00590                         m_ciphertextQueue.Get(ciphertext, ciphertextLength);
00591                         m_plaintext.resize(maxPlaintextLength);
00592                         m_result = m_decryptor.Decrypt(m_rng, ciphertext, ciphertextLength, m_plaintext, m_parameters);
00593                         if (!m_result.isValidCoding)
00594                                 throw InvalidCiphertext(m_decryptor.AlgorithmName() + ": invalid ciphertext");
00595                         }
00596 
00597                         FILTER_OUTPUT(1, m_plaintext, m_result.messageLength, messageEnd);
00598                 }
00599                 FILTER_END_NO_MESSAGE_END;
00600         }
00601 
00602         RandomNumberGenerator &m_rng;
00603         const PK_Decryptor &m_decryptor;
00604         const NameValuePairs &m_parameters;
00605         ByteQueue m_ciphertextQueue;
00606         SecByteBlock m_plaintext;
00607         DecodingResult m_result;
00608 };
00609 
00610 BufferedTransformation * PK_Decryptor::CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs &parameters) const
00611 {
00612         return new PK_DefaultDecryptionFilter(rng, *this, attachment, parameters);
00613 }
00614 
00615 unsigned int PK_Signer::Sign(RandomNumberGenerator &rng, PK_MessageAccumulator *messageAccumulator, byte *signature) const
00616 {
00617         std::auto_ptr<PK_MessageAccumulator> m(messageAccumulator);
00618         return SignAndRestart(rng, *m, signature, false);
00619 }
00620 
00621 unsigned int PK_Signer::SignMessage(RandomNumberGenerator &rng, const byte *message, unsigned int messageLen, byte *signature) const
00622 {
00623         std::auto_ptr<PK_MessageAccumulator> m(NewSignatureAccumulator(rng));
00624         m->Update(message, messageLen);
00625         return SignAndRestart(rng, *m, signature, false);
00626 }
00627 
00628 unsigned int PK_Signer::SignMessageWithRecovery(RandomNumberGenerator &rng, const byte *recoverableMessage, unsigned int recoverableMessageLength, 
00629         const byte *nonrecoverableMessage, unsigned int nonrecoverableMessageLength, byte *signature) const
00630 {
00631         std::auto_ptr<PK_MessageAccumulator> m(NewSignatureAccumulator(rng));
00632         InputRecoverableMessage(*m, recoverableMessage, recoverableMessageLength);
00633         m->Update(nonrecoverableMessage, nonrecoverableMessageLength);
00634         return SignAndRestart(rng, *m, signature, false);
00635 }
00636 
00637 bool PK_Verifier::Verify(PK_MessageAccumulator *messageAccumulator) const
00638 {
00639         std::auto_ptr<PK_MessageAccumulator> m(messageAccumulator);
00640         return VerifyAndRestart(*m);
00641 }
00642 
00643 bool PK_Verifier::VerifyMessage(const byte *message, unsigned int messageLen, const byte *signature, unsigned int signatureLength) const
00644 {
00645         std::auto_ptr<PK_MessageAccumulator> m(NewVerificationAccumulator());
00646         InputSignature(*m, signature, signatureLength);
00647         m->Update(message, messageLen);
00648         return VerifyAndRestart(*m);
00649 }
00650 
00651 DecodingResult PK_Verifier::Recover(byte *recoveredMessage, PK_MessageAccumulator *messageAccumulator) const
00652 {
00653         std::auto_ptr<PK_MessageAccumulator> m(messageAccumulator);
00654         return RecoverAndRestart(recoveredMessage, *m);
00655 }
00656 
00657 DecodingResult PK_Verifier::RecoverMessage(byte *recoveredMessage, 
00658         const byte *nonrecoverableMessage, unsigned int nonrecoverableMessageLength, 
00659         const byte *signature, unsigned int signatureLength) const
00660 {
00661         std::auto_ptr<PK_MessageAccumulator> m(NewVerificationAccumulator());
00662         InputSignature(*m, signature, signatureLength);
00663         m->Update(nonrecoverableMessage, nonrecoverableMessageLength);
00664         return RecoverAndRestart(recoveredMessage, *m);
00665 }
00666 
00667 void SimpleKeyAgreementDomain::GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
00668 {
00669         GeneratePrivateKey(rng, privateKey);
00670         GeneratePublicKey(rng, privateKey, publicKey);
00671 }
00672 
00673 void AuthenticatedKeyAgreementDomain::GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
00674 {
00675         GenerateStaticPrivateKey(rng, privateKey);
00676         GenerateStaticPublicKey(rng, privateKey, publicKey);
00677 }
00678 
00679 void AuthenticatedKeyAgreementDomain::GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
00680 {
00681         GenerateEphemeralPrivateKey(rng, privateKey);
00682         GenerateEphemeralPublicKey(rng, privateKey, publicKey);
00683 }
00684 
00685 NAMESPACE_END
00686 
00687 #endif

Generated on Tue Oct 26 20:20:58 2004 for Crypto++ by  doxygen 1.3.9.1