78 #ifndef CRYPTOPP_CRYPTLIB_H
79 #define CRYPTOPP_CRYPTLIB_H
84 NAMESPACE_BEGIN(CryptoPP)
98 template <
typename ENUM_TYPE,
int VALUE>
101 static ENUM_TYPE ToEnum() {
return (ENUM_TYPE)VALUE;}
104 enum ByteOrder {LITTLE_ENDIAN_ORDER = 0, BIG_ENDIAN_ORDER = 1};
130 explicit Exception(ErrorType errorType,
const std::string &s) : m_errorType(errorType), m_what(s) {}
132 const char *what()
const throw() {
return (m_what.c_str());}
133 const std::string &GetWhat()
const {
return m_what;}
134 void SetWhat(
const std::string &s) {m_what = s;}
135 ErrorType GetErrorType()
const {
return m_errorType;}
136 void SetErrorType(ErrorType errorType) {m_errorType = errorType;}
139 ErrorType m_errorType;
182 OS_Error(
ErrorType errorType,
const std::string &s,
const std::string& operation,
int errorCode)
183 :
Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {}
187 const std::string & GetOperation()
const {
return m_operation;}
189 int GetErrorCode()
const {
return m_errorCode;}
192 std::string m_operation;
199 explicit DecodingResult() : isValidCoding(
false), messageLength(0) {}
200 explicit DecodingResult(
size_t len) : isValidCoding(
true), messageLength(len) {}
202 bool operator==(
const DecodingResult &rhs)
const {
return isValidCoding == rhs.isValidCoding && messageLength == rhs.messageLength;}
203 bool operator!=(
const DecodingResult &rhs)
const {
return !operator==(rhs);}
206 size_t messageLength;
208 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
209 operator size_t()
const {
return isValidCoding ? messageLength : 0;}
233 ValueTypeMismatch(
const std::string &name,
const std::type_info &stored,
const std::type_info &retrieving)
234 :
InvalidArgument(
"NameValuePairs: type mismatch for '" + name +
"', stored '" + stored.name() +
"', trying to retrieve '" + retrieving.name() +
"'")
235 , m_stored(stored), m_retrieving(retrieving) {}
237 const std::type_info & GetStoredTypeInfo()
const {
return m_stored;}
238 const std::type_info & GetRetrievingTypeInfo()
const {
return m_retrieving;}
241 const std::type_info &m_stored;
242 const std::type_info &m_retrieving;
249 return GetValue((std::string(
"ThisObject:")+
typeid(T).name()).c_str(),
object);
256 return GetValue((std::string(
"ThisPointer:")+
typeid(T).name()).c_str(), p);
263 return GetVoidValue(name,
typeid(T), &value);
270 GetValue(name, defaultValue);
276 {std::string result; GetValue(
"ValueNames", result);
return result;}
282 {
return GetValue(name, value);}
286 {
return GetValueWithDefault(name, defaultValue);}
289 CRYPTOPP_DLL
static void CRYPTOPP_API
ThrowIfTypeMismatch(
const char *name,
const std::type_info &stored,
const std::type_info &retrieving)
293 void GetRequiredParameter(
const char *className,
const char *name, T &value)
const
295 if (!GetValue(name, value))
296 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
299 CRYPTOPP_DLL
void GetRequiredIntParameter(
const char *className,
const char *name,
int &value)
const
301 if (!GetIntValue(name, value))
302 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
306 CRYPTOPP_DLL
virtual bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
315 DOCUMENTED_NAMESPACE_BEGIN(Name)
317 DOCUMENTED_NAMESPACE_END
328 virtual ~Clonable() {}
340 Algorithm(
bool checkSelfTestStatus =
true);
352 virtual size_t MinKeyLength()
const =0;
354 virtual size_t MaxKeyLength()
const =0;
356 virtual size_t DefaultKeyLength()
const =0;
359 virtual size_t GetValidKeyLength(
size_t n)
const =0;
363 {
return n == GetValidKeyLength(n);}
367 virtual void SetKey(
const byte *key,
size_t length,
const NameValuePairs ¶ms = g_nullNameValuePairs);
370 void SetKeyWithRounds(
const byte *key,
size_t length,
int rounds);
373 void SetKeyWithIV(
const byte *key,
size_t length,
const byte *iv,
size_t ivLength);
377 {SetKeyWithIV(key, length, iv, IVSize());}
379 enum IV_Requirement {UNIQUE_IV = 0, RANDOM_IV, UNPREDICTABLE_RANDOM_IV, INTERNALLY_GENERATED_IV, NOT_RESYNCHRONIZABLE};
381 virtual IV_Requirement IVRequirement()
const =0;
393 virtual unsigned int IVSize()
const {
throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");}
401 virtual void Resynchronize(
const byte *iv,
int ivLength=-1) {
throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");}
409 virtual const Algorithm & GetAlgorithm()
const =0;
410 virtual void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms) =0;
412 void ThrowIfInvalidKeyLength(
size_t length);
413 void ThrowIfResynchronizable();
414 void ThrowIfInvalidIV(
const byte *iv);
415 size_t ThrowIfInvalidIVLength(
int size);
416 const byte * GetIVAndThrowIfInvalid(
const NameValuePairs ¶ms,
size_t &size);
417 inline void AssertValidKeyLength(
size_t length)
const
418 {assert(IsValidKeyLength(length));}
432 virtual void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const =0;
437 {ProcessAndXorBlock(inBlock, NULL, outBlock);}
441 {ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);}
444 virtual unsigned int BlockSize()
const =0;
447 virtual unsigned int OptimalDataAlignment()
const;
453 virtual bool IsForwardTransformation()
const =0;
458 enum {BT_InBlockIsCounter=1, BT_DontIncrementInOutPointers=2, BT_XorInput=4, BT_ReverseDirection=8, BT_AllowParallel=16} FlagsForAdvancedProcessBlocks;
462 virtual size_t AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
const;
464 inline CipherDir GetCipherDirection()
const {
return IsForwardTransformation() ? ENCRYPTION : DECRYPTION;}
485 virtual unsigned int OptimalDataAlignment()
const;
489 virtual void ProcessData(byte *outString,
const byte *inString,
size_t length) =0;
493 virtual void ProcessLastBlock(byte *outString,
const byte *inString,
size_t length);
499 {ProcessData(inoutString, inoutString, length);}
501 inline void ProcessString(byte *outString,
const byte *inString,
size_t length)
502 {ProcessData(outString, inString, length);}
505 {ProcessData(&input, &input, 1);
return input;}
508 virtual bool IsRandomAccess()
const =0;
512 assert(!IsRandomAccess());
513 throw NotImplemented(
"StreamTransformation: this object doesn't support random access");
517 virtual bool IsSelfInverting()
const =0;
519 virtual bool IsForwardTransformation()
const =0;
537 virtual void Update(
const byte *input,
size_t length) =0;
545 {TruncatedFinal(digest, DigestSize());}
549 {TruncatedFinal(NULL, 0);}
552 virtual unsigned int DigestSize()
const =0;
555 unsigned int TagSize()
const {
return DigestSize();}
565 virtual unsigned int OptimalDataAlignment()
const;
569 {Update(input, length); Final(digest);}
575 {
return TruncatedVerify(digest, DigestSize());}
578 virtual bool VerifyDigest(
const byte *digest,
const byte *input,
size_t length)
579 {Update(input, length);
return Verify(digest);}
582 virtual void TruncatedFinal(byte *digest,
size_t digestSize) =0;
586 {Update(input, length); TruncatedFinal(digest, digestSize);}
589 virtual bool TruncatedVerify(
const byte *digest,
size_t digestLength);
593 {Update(input, length);
return TruncatedVerify(digest, digestLength);}
596 void ThrowIfInvalidTruncatedSize(
size_t size)
const;
606 const Algorithm & GetAlgorithm()
const {
return *
this;}
613 const Algorithm & GetAlgorithm()
const {
return *
this;}
620 const Algorithm & GetAlgorithm()
const {
return *
this;}
633 explicit BadState(
const std::string &name,
const char *message) :
Exception(OTHER_ERROR, name +
": " + message) {}
634 explicit BadState(
const std::string &name,
const char *
function,
const char *state) :
Exception(OTHER_ERROR, name +
": " +
function +
" was called before " + state) {}
638 virtual lword MaxHeaderLength()
const =0;
640 virtual lword MaxMessageLength()
const =0;
647 void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0);
649 virtual void EncryptAndAuthenticate(byte *ciphertext, byte *mac,
size_t macSize,
const byte *iv,
int ivLength,
const byte *header,
size_t headerLength,
const byte *message,
size_t messageLength);
651 virtual bool DecryptAndVerify(byte *message,
const byte *mac,
size_t macLength,
const byte *iv,
int ivLength,
const byte *header,
size_t headerLength,
const byte *ciphertext,
size_t ciphertextLength);
658 virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength) {}
661 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
678 virtual byte GenerateByte();
682 virtual unsigned int GenerateBit();
685 virtual word32 GenerateWord32(word32 a=0, word32 b=0xffffffffL);
688 virtual void GenerateBlock(byte *output,
size_t size);
691 virtual void DiscardBytes(
size_t n);
694 virtual void GenerateIntoBufferedTransformation(
BufferedTransformation &target,
const std::string &channel, lword length);
697 template <
class IT>
void Shuffle(IT begin, IT end)
699 for (; begin != end; ++begin)
700 std::iter_swap(begin, begin + GenerateWord32(0, end-begin-1));
703 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
704 byte GetByte() {
return GenerateByte();}
705 unsigned int GetBit() {
return GenerateBit();}
706 word32 GetLong(word32 a=0, word32 b=0xffffffffL) {
return GenerateWord32(a, b);}
707 word16 GetShort(word16 a=0, word16 b=0xffff) {
return (word16)GenerateWord32(a, b);}
708 void GetBlock(byte *output,
size_t size) {GenerateBlock(output, size);}
726 virtual unsigned int GetMaxWaitObjectCount()
const =0;
735 bool Wait(
unsigned long milliseconds,
CallStack const& callStack);
774 static const std::string &NULL_CHANNEL;
784 size_t Put(byte inByte,
bool blocking=
true)
785 {
return Put(&inByte, 1, blocking);}
787 size_t Put(
const byte *inString,
size_t length,
bool blocking=
true)
788 {
return Put2(inString, length, 0, blocking);}
791 size_t PutWord16(word16 value, ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
793 size_t PutWord32(word32 value, ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
800 virtual bool CanModifyInput()
const {
return false;}
804 {
return PutModifiable2(inString, length, 0, blocking);}
806 bool MessageEnd(
int propagation=-1,
bool blocking=
true)
807 {
return !!Put2(NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
808 size_t PutMessageEnd(
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
809 {
return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
813 virtual size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking) =0;
816 virtual size_t PutModifiable2(byte *inString,
size_t length,
int messageEnd,
bool blocking)
817 {
return Put2(inString, length, messageEnd, blocking);}
832 virtual void IsolatedInitialize(
const NameValuePairs ¶meters) {
throw NotImplemented(
"BufferedTransformation: this object can't be reinitialized");}
833 virtual bool IsolatedFlush(
bool hardFlush,
bool blocking) =0;
834 virtual bool IsolatedMessageSeriesEnd(
bool blocking) {
return false;}
837 virtual void Initialize(
const NameValuePairs ¶meters=g_nullNameValuePairs,
int propagation=-1);
849 virtual bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true);
852 virtual bool MessageSeriesEnd(
int propagation=-1,
bool blocking=
true);
859 virtual int GetAutoSignalPropagation()
const {
return 0;}
862 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
863 void Close() {MessageEnd();}
873 virtual lword MaxRetrievable()
const;
876 virtual bool AnyRetrievable()
const;
879 virtual size_t Get(byte &outByte);
881 virtual size_t Get(byte *outString,
size_t getMax);
884 virtual size_t Peek(byte &outByte)
const;
886 virtual size_t Peek(byte *outString,
size_t peekMax)
const;
889 size_t GetWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER);
891 size_t GetWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER);
894 size_t PeekWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER)
const;
896 size_t PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER)
const;
900 {TransferTo2(target, transferMax, channel);
return transferMax;}
903 virtual lword Skip(lword skipMax=LWORD_MAX);
907 {
return CopyRangeTo(target, 0, copyMax, channel);}
911 {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel);
return i-position;}
913 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
914 unsigned long MaxRetrieveable()
const {
return MaxRetrievable();}
921 virtual lword TotalBytesRetrievable()
const;
923 virtual unsigned int NumberOfMessages()
const;
925 virtual bool AnyMessages()
const;
931 virtual bool GetNextMessage();
933 virtual unsigned int SkipMessages(
unsigned int count=UINT_MAX);
935 unsigned int TransferMessagesTo(
BufferedTransformation &target,
unsigned int count=UINT_MAX,
const std::string &channel=DEFAULT_CHANNEL)
936 {TransferMessagesTo2(target, count, channel);
return count;}
938 unsigned int CopyMessagesTo(
BufferedTransformation &target,
unsigned int count=UINT_MAX,
const std::string &channel=DEFAULT_CHANNEL)
const;
941 virtual void SkipAll();
944 {TransferAllTo2(target, channel);}
948 virtual bool GetNextMessageSeries() {
return false;}
949 virtual unsigned int NumberOfMessagesInThisSeries()
const {
return NumberOfMessages();}
950 virtual unsigned int NumberOfMessageSeries()
const {
return 0;}
956 virtual size_t TransferTo2(
BufferedTransformation &target, lword &byteCount,
const std::string &channel=DEFAULT_CHANNEL,
bool blocking=
true) =0;
958 virtual size_t CopyRangeTo2(
BufferedTransformation &target, lword &begin, lword end=LWORD_MAX,
const std::string &channel=DEFAULT_CHANNEL,
bool blocking=
true)
const =0;
960 size_t TransferMessagesTo2(
BufferedTransformation &target,
unsigned int &messageCount,
const std::string &channel=DEFAULT_CHANNEL,
bool blocking=
true);
962 size_t TransferAllTo2(
BufferedTransformation &target,
const std::string &channel=DEFAULT_CHANNEL,
bool blocking=
true);
972 size_t ChannelPut(
const std::string &channel, byte inByte,
bool blocking=
true)
973 {
return ChannelPut(channel, &inByte, 1, blocking);}
974 size_t ChannelPut(
const std::string &channel,
const byte *inString,
size_t length,
bool blocking=
true)
975 {
return ChannelPut2(channel, inString, length, 0, blocking);}
977 size_t ChannelPutModifiable(
const std::string &channel, byte *inString,
size_t length,
bool blocking=
true)
978 {
return ChannelPutModifiable2(channel, inString, length, 0, blocking);}
980 size_t ChannelPutWord16(
const std::string &channel, word16 value, ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
981 size_t ChannelPutWord32(
const std::string &channel, word32 value, ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
983 bool ChannelMessageEnd(
const std::string &channel,
int propagation=-1,
bool blocking=
true)
984 {
return !!ChannelPut2(channel, NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
985 size_t ChannelPutMessageEnd(
const std::string &channel,
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
986 {
return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
988 virtual byte * ChannelCreatePutSpace(
const std::string &channel,
size_t &size);
990 virtual size_t ChannelPut2(
const std::string &channel,
const byte *begin,
size_t length,
int messageEnd,
bool blocking);
991 virtual size_t ChannelPutModifiable2(
const std::string &channel, byte *begin,
size_t length,
int messageEnd,
bool blocking);
993 virtual bool ChannelFlush(
const std::string &channel,
bool hardFlush,
int propagation=-1,
bool blocking=
true);
994 virtual bool ChannelMessageSeriesEnd(
const std::string &channel,
int propagation=-1,
bool blocking=
true);
996 virtual void SetRetrievalChannel(
const std::string &channel);
1016 {assert(!Attachable());
throw NotImplemented(
"BufferedTransformation: this object is not attachable");}
1022 static int DecrementPropagation(
int propagation)
1023 {
return propagation != 0 ? propagation - 1 : 0;}
1059 {
if (!Validate(rng, level))
throw InvalidMaterial(
"CryptoMaterial: this object contains invalid values");}
1065 {
throw NotImplemented(
"CryptoMaterial: this object does not support saving");}
1072 {
throw NotImplemented(
"CryptoMaterial: this object does not support loading");}
1081 {assert(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
1084 {assert(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
1087 {assert(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
1090 void DoQuickSanityCheck()
const {ThrowIfInvalid(
NullRNG(), 0);}
1092 #if (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
1094 char m_sunCCworkaround;
1107 {
throw NotImplemented(
"GeneratableCryptoMaterial: this object does not support key/parameter generation");}
1143 {AccessMaterial().Load(bt);}
1146 {GetMaterial().Save(bt);}
1158 virtual PublicKey & AccessPublicKey() =0;
1198 virtual size_t MaxPlaintextLength(
size_t ciphertextLength)
const =0;
1202 virtual size_t CiphertextLength(
size_t plaintextLength)
const =0;
1206 virtual bool ParameterSupported(
const char *name)
const =0;
1216 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
1217 size_t MaxPlainTextLength(
size_t cipherTextLength)
const {
return MaxPlaintextLength(cipherTextLength);}
1218 size_t CipherTextLength(
size_t plainTextLength)
const {
return CiphertextLength(plainTextLength);}
1238 const byte *plaintext,
size_t plaintextLength,
1239 byte *ciphertext,
const NameValuePairs ¶meters = g_nullNameValuePairs)
const =0;
1259 const byte *ciphertext,
size_t ciphertextLength,
1273 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
1338 {
throw NotImplemented(
"PK_MessageAccumulator: DigestSize() should not be called");}
1341 {
throw NotImplemented(
"PK_MessageAccumulator: TruncatedFinal() should not be called");}
1352 virtual void InputRecoverableMessage(
PK_MessageAccumulator &messageAccumulator,
const byte *recoverableMessage,
size_t recoverableMessageLength)
const =0;
1370 virtual size_t SignMessage(
RandomNumberGenerator &rng,
const byte *message,
size_t messageLen, byte *signature)
const;
1376 virtual size_t SignMessageWithRecovery(
RandomNumberGenerator &rng,
const byte *recoverableMessage,
size_t recoverableMessageLength,
1377 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength, byte *signature)
const;
1394 virtual void InputSignature(
PK_MessageAccumulator &messageAccumulator,
const byte *signature,
size_t signatureLength)
const =0;
1403 virtual bool VerifyMessage(
const byte *message,
size_t messageLen,
1404 const byte *signature,
size_t signatureLength)
const;
1420 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength,
1421 const byte *signature,
size_t signatureLength)
const;
1434 virtual unsigned int AgreedValueLength()
const =0;
1436 virtual unsigned int PrivateKeyLength()
const =0;
1438 virtual unsigned int PublicKeyLength()
const =0;
1444 virtual void GeneratePublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
1454 virtual bool Agree(byte *agreedValue,
const byte *privateKey,
const byte *otherPublicKey,
bool validateOtherPublicKey=
true)
const =0;
1456 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
1458 {
return GetCryptoParameters().Validate(rng, 2);}
1472 virtual unsigned int AgreedValueLength()
const =0;
1475 virtual unsigned int StaticPrivateKeyLength()
const =0;
1477 virtual unsigned int StaticPublicKeyLength()
const =0;
1483 virtual void GenerateStaticPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
1486 virtual void GenerateStaticKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
1489 virtual unsigned int EphemeralPrivateKeyLength()
const =0;
1491 virtual unsigned int EphemeralPublicKeyLength()
const =0;
1497 virtual void GenerateEphemeralPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
1500 virtual void GenerateEphemeralKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
1511 virtual bool Agree(byte *agreedValue,
1512 const byte *staticPrivateKey,
const byte *ephemeralPrivateKey,
1513 const byte *staticOtherPublicKey,
const byte *ephemeralOtherPublicKey,
1514 bool validateStaticOtherPublicKey=
true)
const =0;
1516 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
1518 {
return GetCryptoParameters().Validate(rng, 2);}
1545 class ProtocolSession
1552 ProtocolError(ErrorType errorType,
const std::string &s) :
Exception(errorType, s) {}
1557 class UnexpectedMethodCall :
public Exception
1560 UnexpectedMethodCall(
const std::string &s) :
Exception(OTHER_ERROR, s) {}
1563 ProtocolSession() : m_rng(NULL), m_throwOnProtocolError(true), m_validState(false) {}
1564 virtual ~ProtocolSession() {}
1568 bool GetThrowOnProtocolError()
const {
return m_throwOnProtocolError;}
1569 void SetThrowOnProtocolError(
bool throwOnProtocolError) {m_throwOnProtocolError = throwOnProtocolError;}
1571 bool HasValidState()
const {
return m_validState;}
1573 virtual bool OutgoingMessageAvailable()
const =0;
1574 virtual unsigned int GetOutgoingMessageLength()
const =0;
1575 virtual void GetOutgoingMessage(byte *message) =0;
1577 virtual bool LastMessageProcessed()
const =0;
1578 virtual void ProcessIncomingMessage(
const byte *message,
unsigned int messageLength) =0;
1582 void CheckAndHandleInvalidState()
const;
1583 void SetValidState(
bool valid) {m_validState = valid;}
1588 bool m_throwOnProtocolError, m_validState;
1591 class KeyAgreementSession :
public ProtocolSession
1594 virtual unsigned int GetAgreedValueLength()
const =0;
1595 virtual void GetAgreedValue(byte *agreedValue)
const =0;
1598 class PasswordAuthenticatedKeyAgreementSession :
public KeyAgreementSession
1602 const byte *myId,
unsigned int myIdLength,
1603 const byte *counterPartyId,
unsigned int counterPartyIdLength,
1604 const byte *passwordOrVerifier,
unsigned int passwordOrVerifierLength);
1612 {
return GetCryptoParameters().Validate(rng, 2);}
1614 virtual unsigned int GetPasswordVerifierLength(
const byte *password,
unsigned int passwordLength)
const =0;
1615 virtual void GeneratePasswordVerifier(
RandomNumberGenerator &rng,
const byte *userId,
unsigned int userIdLength,
const byte *password,
unsigned int passwordLength, byte *verifier)
const =0;
1617 enum RoleFlags {CLIENT=1, SERVER=2, INITIATOR=4, RESPONDER=8};
1619 virtual bool IsValidRole(
unsigned int role) =0;
1620 virtual PasswordAuthenticatedKeyAgreementSession * CreateProtocolSession(
unsigned int role)
const =0;
1646 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY