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);}
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;}
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,
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
base class for all exceptions thrown by Crypto++
exception thrown when invalid crypto material is detected
exception thrown when an invalid argument is detected
void SetKeyWithIV(const byte *key, size_t length, const byte *iv)
calls SetKey() with an NameValuePairs object that just specifies "IV"
bool GetThisObject(T &object) const
get a copy of this object or a subobject of it
bool CanUseRandomIVs() const
returns whether this object can use random IVs (in addition to ones returned by GetNextIV) ...
interface for message authentication codes
container of wait objects
virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
save precomputation for later use
interface for asymmetric algorithms
interface for public-key encryptors and decryptors
error reported by the operating system
interface for for one direction (encryption or decryption) of a stream cipher or block cipher mode wi...
T GetValueWithDefault(const char *name, T defaultValue) const
get a named value, returns the default if the name doesn't exist
virtual void Load(BufferedTransformation &bt)
load key from a BufferedTransformation
virtual bool NeedsPrespecifiedDataLengths() const
if this function returns true, SpecifyDataLengths() must be called before attempting to input data ...
this indicates that a member function was called in the wrong state, for example trying to encrypt a ...
interface for public-key signers
virtual void ThrowIfInvalid(RandomNumberGenerator &rng, unsigned int level) const
throws InvalidMaterial if this object fails Validate() test
interface for public-key encryptors
CipherDir
used to specify a direction for a cipher to operate in (encrypt or decrypt)
void BERDecode(BufferedTransformation &bt)
for backwards compatibility, calls AccessMaterial().Load(bt)
exception thrown by a class when Flush(true) is called but it can't completely flush its buffers ...
virtual void Save(BufferedTransformation &bt) const
save key into a BufferedTransformation
exception thrown when trying to retrieve a value using a different type than expected ...
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
interface for asymmetric algorithms using private keys
BufferedTransformation & TheBitBucket()
returns a reference to a BufferedTransformation object that discards all input
virtual bool IsProbabilistic() const =0
requires a random number generator to sign
virtual bool SupportsPrecomputation() const
virtual bool AllowNonrecoverablePart() const =0
whether or not a non-recoverable message part can be signed
virtual bool CanIncorporateEntropy() const
returns true if IncorporateEntropy is implemented
std::string GetValueNames() const
get a list of value names that can be retrieved
interface for random number generators
virtual size_t SignatureLength() const =0
signature length if it only depends on the key, otherwise 0
virtual lword MaxFooterLength() const
the maximum length of AAD that can be input after the encrypted data
interface for private keys
interface for cloning objects, this is not implemented by most classes yet
virtual unsigned int MinIVLength() const
returns minimal length of IVs accepted by this object
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
bool GetThisPointer(T *&p) const
get a pointer to this object, as a pointer to T
bool GetIntValue(const char *name, int &value) const
get a named value with type int
virtual bool IsValidKeyLength(size_t n) const
returns whether n is a valid key length
data integerity check (such as CRC or MAC) failed
interface for one direction (encryption or decryption) of a block cipher
interface for objects that you can wait for
virtual size_t MaxRecoverableLength() const =0
length of longest message that can be recovered, or 0 if this signature scheme does not support messa...
interface for domains of simple key agreement protocols
virtual unsigned int GetMaxWaitObjectCount() const =0
maximum number of wait objects that this object can return
used to return decoding results
virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation)
retrieve previously saved precomputation
Algorithm(bool checkSelfTestStatus=true)
exception thrown when trying to encrypt plaintext of invalid length
bool CanUsePredictableIVs() const
returns whether this object can use random but possibly predictable IVs (in addition to ones returned...
DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *ciphertext, byte *plaintext, const NameValuePairs ¶meters=g_nullNameValuePairs) const
decrypt a fixed size ciphertext
received input data that doesn't conform to expected format
bool GetValue(const char *name, T &value) const
get a named value, returns true if the name exists
interface for public-key decryptors
virtual void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)=0
put wait objects into container
int GetIntValueWithDefault(const char *name, int defaultValue) const
get a named value with type int, with default
exception thrown by a class if a non-implemented method is called
key too short exception, may be thrown by any function in this class if the private or public key is ...
virtual size_t FixedCiphertextLength() const
return fixed ciphertext length, if one exists, otherwise return 0
const std::string DEFAULT_CHANNEL
the default channel for BufferedTransformation, equal to the empty string
bool IsResynchronizable() const
returns whether this object can be resynchronized (i.e. supports initialization vectors) ...
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
interface for encoding and decoding ASN1 objects
virtual void Resynchronize(const byte *iv, int ivLength=-1)
resynchronize with an IV. ivLength=-1 means use IVSize()
virtual size_t MaxSignatureLength(size_t recoverablePartLength=0) const
maximum signature length produced for a given length of recoverable message part
bool CanUseStructuredIVs() const
returns whether this object can use structured IVs, for example a counter (in addition to ones return...
interface for one direction (encryption or decryption) of a stream cipher or cipher mode ...
multiple precision integer and basic arithmetics
invalid key exception, may be thrown by any function in this class if the private or public key has a...
keying interface for crypto algorithms that take byte strings as keys
virtual std::string AlgorithmName() const
returns name of this algorithm, not universally implemented yet
interface for asymmetric algorithms using public keys
virtual size_t FixedMaxPlaintextLength() const
return maximum plaintext length given the fixed ciphertext length, if one exists, otherwise return 0 ...
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
virtual size_t MaxRecoverableLengthFromSignatureLength(size_t signatureLength) const =0
length of longest message that can be recovered from a signature of given length, or 0 if this signat...
const NameValuePairs & g_nullNameValuePairs
empty set of name-value pairs
unsigned int DigestSize() const
should not be called on PK_MessageAccumulator
interface for public-key signers and verifiers
RandomNumberGenerator & NullRNG()
returns a reference that can be passed to functions that ask for a RNG but doesn't actually use it ...
const unsigned long INFINITE_TIME
used to represent infinite time
virtual unsigned int MaxIVLength() const
returns maximal length of IVs accepted by this object
interface for all crypto algorithms
unsigned int DefaultIVLength() const
returns default length of IVs accepted by this object
virtual void BEREncode(BufferedTransformation &bt) const
encode this object into a BufferedTransformation, using BER
interface for accumulating messages to be signed or verified
virtual Clonable * Clone() const
this is not implemented by most classes yet
exception thrown by decryption filters when trying to decrypt an invalid ciphertext ...
interface for key agreement algorithms
static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
used by derived classes to check for type mismatch
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
interface for public-key signature verifiers
void Shuffle(IT begin, IT end)
randomly shuffle the specified array, resulting permutation is uniformly distributed ...
virtual bool SignatureUpfront() const
if this function returns true, during verification you must input the signature before the message...
interface for crypto material, such as public and private keys, and crypto parameters ...
virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs)
generate a random key or crypto parameters
void DEREncode(BufferedTransformation &bt) const
for backwards compatibility, calls GetMaterial().Save(bt)
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
invalid function argument
interface for generatable crypto material, such as private keys and crypto parameters ...
virtual bool RecoverablePartFirst() const =0
whether you must input the recoverable part before the non-recoverable part during signing ...
interface for crypto prameters
namespace containing value name definitions
BufferedTransformation received a Flush(true) signal but can't flush buffers.
interface for public keys
interface for domains of authenticated key agreement protocols
void TruncatedFinal(byte *digest, size_t digestSize)
should not be called on PK_MessageAccumulator
a method is not implemented
const std::string AAD_CHANNEL
channel for additional authenticated data, equal to "AAD"
error reading from input device or writing to output device
virtual void Precompute(unsigned int n)
do precomputation
virtual void IncorporateEntropy(const byte *input, size_t length)
update RNG state with additional unpredictable values
interface for retrieving values given their names
BER Decode Exception Class, may be thrown during an ASN1 BER decode operation.