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, size_t length, int rounds)
00051 {
00052         SetKey(key, length, MakeParameters(Name::Rounds(), rounds));
00053 }
00054 
00055 void SimpleKeyingInterface::SetKeyWithIV(const byte *key, size_t length, const byte *iv)
00056 {
00057         SetKey(key, length, MakeParameters(Name::IV(), iv));
00058 }
00059 
00060 void SimpleKeyingInterface::ThrowIfInvalidKeyLength(const Algorithm &algorithm, size_t 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, size_t 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, size_t 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, size_t 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(size_t 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, size_t 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(size_t 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, size_t &size)
00208 {
00209         if (channel.empty())
00210                 return CreatePutSpace(size);
00211         else
00212                 throw NoChannelSupport();
00213 }
00214 
00215 size_t BufferedTransformation::ChannelPut2(const std::string &channel, const byte *begin, size_t 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 size_t BufferedTransformation::ChannelPutModifiable2(const std::string &channel, byte *begin, size_t 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 lword 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 size_t BufferedTransformation::Get(byte &outByte)
00267 {
00268         if (AttachedTransformation())
00269                 return AttachedTransformation()->Get(outByte);
00270         else
00271                 return Get(&outByte, 1);
00272 }
00273 
00274 size_t BufferedTransformation::Get(byte *outString, size_t getMax)
00275 {
00276         if (AttachedTransformation())
00277                 return AttachedTransformation()->Get(outString, getMax);
00278         else
00279         {
00280                 ArraySink arraySink(outString, getMax);
00281                 return (size_t)TransferTo(arraySink, getMax);
00282         }
00283 }
00284 
00285 size_t BufferedTransformation::Peek(byte &outByte) const
00286 {
00287         if (AttachedTransformation())
00288                 return AttachedTransformation()->Peek(outByte);
00289         else
00290                 return Peek(&outByte, 1);
00291 }
00292 
00293 size_t BufferedTransformation::Peek(byte *outString, size_t peekMax) const
00294 {
00295         if (AttachedTransformation())
00296                 return AttachedTransformation()->Peek(outString, peekMax);
00297         else
00298         {
00299                 ArraySink arraySink(outString, peekMax);
00300                 return (size_t)CopyTo(arraySink, peekMax);
00301         }
00302 }
00303 
00304 lword BufferedTransformation::Skip(lword skipMax)
00305 {
00306         if (AttachedTransformation())
00307                 return AttachedTransformation()->Skip(skipMax);
00308         else
00309                 return TransferTo(TheBitBucket(), skipMax);
00310 }
00311 
00312 lword 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 size_t 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                         size_t blockedBytes;
00365                         lword transferredBytes;
00366 
00367                         while (AnyRetrievable())
00368                         {
00369                                 transferredBytes = LWORD_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 size_t 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                         size_t blockedBytes = TransferMessagesTo2(target, messageCount, channel, blocking);
00417                         if (blockedBytes)
00418                                 return blockedBytes;
00419                 }
00420                 while (messageCount != 0);
00421 
00422                 lword byteCount;
00423                 do
00424                 {
00425                         byteCount = ULONG_MAX;
00426                         size_t 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 size_t BufferedTransformation::ChannelPutWord16(const std::string &channel, word16 value, ByteOrder order, bool blocking)
00454 {
00455         PutWord(false, order, m_buf, value);
00456         return ChannelPut(channel, m_buf, 2, blocking);
00457 }
00458 
00459 size_t BufferedTransformation::ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order, bool blocking)
00460 {
00461         PutWord(false, order, m_buf, value);
00462         return ChannelPut(channel, m_buf, 4, blocking);
00463 }
00464 
00465 size_t BufferedTransformation::PutWord16(word16 value, ByteOrder order, bool blocking)
00466 {
00467         return ChannelPutWord16(NULL_CHANNEL, value, order, blocking);
00468 }
00469 
00470 size_t BufferedTransformation::PutWord32(word32 value, ByteOrder order, bool blocking)
00471 {
00472         return ChannelPutWord32(NULL_CHANNEL, value, order, blocking);
00473 }
00474 
00475 size_t BufferedTransformation::PeekWord16(word16 &value, ByteOrder order) const
00476 {
00477         byte buf[2] = {0, 0};
00478         size_t len = Peek(buf, 2);
00479 
00480         if (order)
00481                 value = (buf[0] << 8) | buf[1];
00482         else
00483                 value = (buf[1] << 8) | buf[0];
00484 
00485         return len;
00486 }
00487 
00488 size_t BufferedTransformation::PeekWord32(word32 &value, ByteOrder order) const
00489 {
00490         byte buf[4] = {0, 0, 0, 0};
00491         size_t len = Peek(buf, 4);
00492 
00493         if (order)
00494                 value = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf [3];
00495         else
00496                 value = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf [0];
00497 
00498         return len;
00499 }
00500 
00501 size_t BufferedTransformation::GetWord16(word16 &value, ByteOrder order)
00502 {
00503         return (size_t)Skip(PeekWord16(value, order));
00504 }
00505 
00506 size_t BufferedTransformation::GetWord32(word32 &value, ByteOrder order)
00507 {
00508         return (size_t)Skip(PeekWord32(value, order));
00509 }
00510 
00511 void BufferedTransformation::Attach(BufferedTransformation *newOut)
00512 {
00513         if (AttachedTransformation() && AttachedTransformation()->Attachable())
00514                 AttachedTransformation()->Attach(newOut);
00515         else
00516                 Detach(newOut);
00517 }
00518 
00519 void GeneratableCryptoMaterial::GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
00520 {
00521         GenerateRandom(rng, MakeParameters("KeySize", (int)keySize));
00522 }
00523 
00524 class PK_DefaultEncryptionFilter : public Unflushable<Filter>
00525 {
00526 public:
00527         PK_DefaultEncryptionFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment, const NameValuePairs &parameters)
00528                 : m_rng(rng), m_encryptor(encryptor), m_parameters(parameters)
00529         {
00530                 Detach(attachment);
00531         }
00532 
00533         size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
00534         {
00535                 FILTER_BEGIN;
00536                 m_plaintextQueue.Put(inString, length);
00537 
00538                 if (messageEnd)
00539                 {
00540                         {
00541                         size_t plaintextLength;
00542                         if (!SafeConvert(m_plaintextQueue.CurrentSize(), plaintextLength))
00543                                 throw InvalidArgument("PK_DefaultEncryptionFilter: plaintext too long");
00544                         size_t 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         size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
00579         {
00580                 FILTER_BEGIN;
00581                 m_ciphertextQueue.Put(inString, length);
00582 
00583                 if (messageEnd)
00584                 {
00585                         {
00586                         size_t ciphertextLength;
00587                         if (!SafeConvert(m_ciphertextQueue.CurrentSize(), ciphertextLength))
00588                                 throw InvalidArgument("PK_DefaultDecryptionFilter: ciphertext too long");
00589                         size_t maxPlaintextLength = m_decryptor.MaxPlaintextLength(ciphertextLength);
00590 
00591                         SecByteBlock ciphertext(ciphertextLength);
00592                         m_ciphertextQueue.Get(ciphertext, ciphertextLength);
00593                         m_plaintext.resize(maxPlaintextLength);
00594                         m_result = m_decryptor.Decrypt(m_rng, ciphertext, ciphertextLength, m_plaintext, m_parameters);
00595                         if (!m_result.isValidCoding)
00596                                 throw InvalidCiphertext(m_decryptor.AlgorithmName() + ": invalid ciphertext");
00597                         }
00598 
00599                         FILTER_OUTPUT(1, m_plaintext, m_result.messageLength, messageEnd);
00600                 }
00601                 FILTER_END_NO_MESSAGE_END;
00602         }
00603 
00604         RandomNumberGenerator &m_rng;
00605         const PK_Decryptor &m_decryptor;
00606         const NameValuePairs &m_parameters;
00607         ByteQueue m_ciphertextQueue;
00608         SecByteBlock m_plaintext;
00609         DecodingResult m_result;
00610 };
00611 
00612 BufferedTransformation * PK_Decryptor::CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs &parameters) const
00613 {
00614         return new PK_DefaultDecryptionFilter(rng, *this, attachment, parameters);
00615 }
00616 
00617 size_t PK_Signer::Sign(RandomNumberGenerator &rng, PK_MessageAccumulator *messageAccumulator, byte *signature) const
00618 {
00619         std::auto_ptr<PK_MessageAccumulator> m(messageAccumulator);
00620         return SignAndRestart(rng, *m, signature, false);
00621 }
00622 
00623 size_t PK_Signer::SignMessage(RandomNumberGenerator &rng, const byte *message, size_t messageLen, byte *signature) const
00624 {
00625         std::auto_ptr<PK_MessageAccumulator> m(NewSignatureAccumulator(rng));
00626         m->Update(message, messageLen);
00627         return SignAndRestart(rng, *m, signature, false);
00628 }
00629 
00630 size_t PK_Signer::SignMessageWithRecovery(RandomNumberGenerator &rng, const byte *recoverableMessage, size_t recoverableMessageLength, 
00631         const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength, byte *signature) const
00632 {
00633         std::auto_ptr<PK_MessageAccumulator> m(NewSignatureAccumulator(rng));
00634         InputRecoverableMessage(*m, recoverableMessage, recoverableMessageLength);
00635         m->Update(nonrecoverableMessage, nonrecoverableMessageLength);
00636         return SignAndRestart(rng, *m, signature, false);
00637 }
00638 
00639 bool PK_Verifier::Verify(PK_MessageAccumulator *messageAccumulator) const
00640 {
00641         std::auto_ptr<PK_MessageAccumulator> m(messageAccumulator);
00642         return VerifyAndRestart(*m);
00643 }
00644 
00645 bool PK_Verifier::VerifyMessage(const byte *message, size_t messageLen, const byte *signature, size_t signatureLength) const
00646 {
00647         std::auto_ptr<PK_MessageAccumulator> m(NewVerificationAccumulator());
00648         InputSignature(*m, signature, signatureLength);
00649         m->Update(message, messageLen);
00650         return VerifyAndRestart(*m);
00651 }
00652 
00653 DecodingResult PK_Verifier::Recover(byte *recoveredMessage, PK_MessageAccumulator *messageAccumulator) const
00654 {
00655         std::auto_ptr<PK_MessageAccumulator> m(messageAccumulator);
00656         return RecoverAndRestart(recoveredMessage, *m);
00657 }
00658 
00659 DecodingResult PK_Verifier::RecoverMessage(byte *recoveredMessage, 
00660         const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength, 
00661         const byte *signature, size_t signatureLength) const
00662 {
00663         std::auto_ptr<PK_MessageAccumulator> m(NewVerificationAccumulator());
00664         InputSignature(*m, signature, signatureLength);
00665         m->Update(nonrecoverableMessage, nonrecoverableMessageLength);
00666         return RecoverAndRestart(recoveredMessage, *m);
00667 }
00668 
00669 void SimpleKeyAgreementDomain::GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
00670 {
00671         GeneratePrivateKey(rng, privateKey);
00672         GeneratePublicKey(rng, privateKey, publicKey);
00673 }
00674 
00675 void AuthenticatedKeyAgreementDomain::GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
00676 {
00677         GenerateStaticPrivateKey(rng, privateKey);
00678         GenerateStaticPublicKey(rng, privateKey, publicKey);
00679 }
00680 
00681 void AuthenticatedKeyAgreementDomain::GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
00682 {
00683         GenerateEphemeralPrivateKey(rng, privateKey);
00684         GenerateEphemeralPublicKey(rng, privateKey, publicKey);
00685 }
00686 
00687 NAMESPACE_END
00688 
00689 #endif

Generated on Tue Aug 16 08:38:40 2005 for Crypto++ by  doxygen 1.3.9.1