83 #ifndef CRYPTOPP_CRYPTLIB_H 84 #define CRYPTOPP_CRYPTLIB_H 89 #if CRYPTOPP_MSC_VERSION 90 # pragma warning(push) 91 # pragma warning(disable: 4127 4189 4702) 109 template <
typename ENUM_TYPE,
int VALUE>
112 static ENUM_TYPE ToEnum() {
return (ENUM_TYPE)VALUE;}
116 enum ByteOrder {LITTLE_ENDIAN_ORDER = 0, BIG_ENDIAN_ORDER = 1};
150 const char *
what()
const throw() {
return (m_what.c_str());}
152 const std::string &
GetWhat()
const {
return m_what;}
154 void SetWhat(
const std::string &s) {m_what = s;}
204 OS_Error(
ErrorType errorType,
const std::string &s,
const std::string& operation,
int errorCode)
205 :
Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {}
214 std::string m_operation;
245 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 246 operator size_t()
const {
return isValidCoding ? messageLength : 0;}
276 ValueTypeMismatch(
const std::string &name,
const std::type_info &stored,
const std::type_info &retrieving)
277 :
InvalidArgument(
"NameValuePairs: type mismatch for '" + name +
"', stored '" + stored.name() +
"', trying to retrieve '" + retrieving.name() +
"'")
278 , m_stored(stored), m_retrieving(retrieving) {}
289 const std::type_info &m_stored;
290 const std::type_info &m_retrieving;
299 return GetValue((std::string(
"ThisObject:")+
typeid(T).name()).c_str(),
object);
308 return GetValue((std::string(
"ThisPointer:")+
typeid(T).name()).c_str(), ptr);
321 return GetVoidValue(name,
typeid(T), &value);
335 bool result = GetValue(name, value);
337 if (result) {
return value;}
344 CRYPTOPP_DLL std::string GetValueNames()
const 345 {std::string result; GetValue(
"ValueNames", result);
return result;}
355 CRYPTOPP_DLL
bool GetIntValue(
const char *name,
int &value)
const 356 {
return GetValue(name, value);}
364 CRYPTOPP_DLL
int GetIntValueWithDefault(
const char *name,
int defaultValue)
const 365 {
return GetValueWithDefault(name, defaultValue);}
376 CRYPTOPP_DLL
static void CRYPTOPP_API ThrowIfTypeMismatch(
const char *name,
const std::type_info &stored,
const std::type_info &retrieving)
392 if (!GetValue(name, value))
393 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
405 CRYPTOPP_DLL
void GetRequiredIntParameter(
const char *className,
const char *name,
int &value)
const 407 if (!GetIntValue(name, value))
408 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
421 CRYPTOPP_DLL
virtual bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
424 #if CRYPTOPP_DOXYGEN_PROCESSING 433 DOCUMENTED_NAMESPACE_BEGIN(
Name)
435 DOCUMENTED_NAMESPACE_END
440 DOCUMENTED_NAMESPACE_BEGIN(
Weak)
442 DOCUMENTED_NAMESPACE_END
480 Algorithm(
bool checkSelfTestStatus =
true);
490 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 503 virtual size_t MinKeyLength()
const =0;
505 virtual size_t MaxKeyLength()
const =0;
507 virtual size_t DefaultKeyLength()
const =0;
511 virtual size_t GetValidKeyLength(
size_t n)
const =0;
516 {
return keylength == GetValidKeyLength(keylength);}
533 void SetKeyWithRounds(
const byte *key,
size_t length,
int rounds);
542 void SetKeyWithIV(
const byte *key,
size_t length,
const byte *iv,
size_t ivLength);
552 {SetKeyWithIV(key, length, iv, IVSize());}
584 {
throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");}
593 CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(ivLength);
594 throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");
610 virtual const Algorithm & GetAlgorithm()
const =0;
617 virtual void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms) =0;
622 void ThrowIfInvalidKeyLength(
size_t length);
629 void ThrowIfResynchronizable();
638 void ThrowIfInvalidIV(
const byte *iv);
643 size_t ThrowIfInvalidIVLength(
int length);
650 const byte * GetIVAndThrowIfInvalid(
const NameValuePairs ¶ms,
size_t &size);
654 inline void AssertValidKeyLength(
size_t length)
const 655 {CRYPTOPP_UNUSED(length); assert(IsValidKeyLength(length));}
675 virtual void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const =0;
686 {ProcessAndXorBlock(inBlock, NULL, outBlock);}
695 {ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);}
699 virtual unsigned int BlockSize()
const =0;
703 virtual unsigned int OptimalDataAlignment()
const;
711 virtual bool IsForwardTransformation()
const =0;
721 BT_InBlockIsCounter=1,
723 BT_DontIncrementInOutPointers=2,
727 BT_ReverseDirection=8,
729 BT_AllowParallel=16};
739 virtual size_t AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
const;
744 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 777 virtual unsigned int OptimalDataAlignment()
const;
784 virtual void ProcessData(byte *outString,
const byte *inString,
size_t length) =0;
792 virtual void ProcessLastBlock(byte *outString,
const byte *inString,
size_t length);
802 {ProcessData(inoutString, inoutString, length);}
809 inline void ProcessString(byte *outString,
const byte *inString,
size_t length)
810 {ProcessData(outString, inString, length);}
816 {ProcessData(&input, &input, 1);
return input;}
820 virtual bool IsRandomAccess()
const =0;
829 CRYPTOPP_UNUSED(pos);
830 assert(!IsRandomAccess());
831 throw NotImplemented(
"StreamTransformation: this object doesn't support random access");
838 virtual bool IsSelfInverting()
const =0;
843 virtual bool IsForwardTransformation()
const =0;
845 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 869 virtual void Update(
const byte *input,
size_t length) =0;
891 {TruncatedFinal(NULL, 0);}
918 virtual unsigned int OptimalDataAlignment()
const;
928 {Update(input, length); Final(digest);}
939 {
return TruncatedVerify(digest,
DigestSize());}
952 virtual bool VerifyDigest(
const byte *digest,
const byte *input,
size_t length)
953 {Update(input, length);
return Verify(digest);}
960 virtual void TruncatedFinal(byte *digest,
size_t digestSize) =0;
971 {Update(input, length); TruncatedFinal(digest, digestSize);}
983 virtual bool TruncatedVerify(
const byte *digest,
size_t digestLength);
998 {Update(input, length);
return TruncatedVerify(digest, digestLength);}
1000 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1006 void ThrowIfInvalidTruncatedSize(
size_t size)
const;
1016 const Algorithm & GetAlgorithm()
const {
return *
this;}
1023 const Algorithm & GetAlgorithm()
const {
return *
this;}
1030 const Algorithm & GetAlgorithm()
const {
return *
this;}
1043 explicit BadState(
const std::string &name,
const char *message) :
Exception(OTHER_ERROR, name +
": " + message) {}
1044 explicit BadState(
const std::string &name,
const char *
function,
const char *state) :
Exception(OTHER_ERROR, name +
": " +
function +
" was called before " + state) {}
1048 virtual lword MaxHeaderLength()
const =0;
1050 virtual lword MaxMessageLength()
const =0;
1057 void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0);
1059 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);
1061 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);
1064 virtual std::string AlgorithmName()
const =0;
1066 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1073 virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
1074 {CRYPTOPP_UNUSED(headerLength); CRYPTOPP_UNUSED(messageLength); CRYPTOPP_UNUSED(footerLength);}
1077 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1098 CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
1099 throw NotImplemented(
"RandomNumberGenerator: IncorporateEntropy not implemented");
1111 virtual byte GenerateByte();
1118 virtual unsigned int GenerateBit();
1128 virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL);
1137 virtual void GenerateBlock(byte *output,
size_t size);
1149 virtual void GenerateIntoBufferedTransformation(
BufferedTransformation &target,
const std::string &channel, lword length);
1153 virtual void DiscardBytes(
size_t n);
1159 template <
class IT>
void Shuffle(IT begin, IT end)
1162 for (; begin != end; ++begin)
1163 std::iter_swap(begin, begin + GenerateWord32(0, end-begin-1));
1166 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1170 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1171 byte
GetByte() {
return GenerateByte();}
1172 unsigned int GetBit() {
return GenerateBit();}
1173 word32 GetLong(word32 a=0, word32 b=0xffffffffL) {
return GenerateWord32(a, b);}
1174 word16 GetShort(word16 a=0, word16 b=0xffff) {
return (word16)GenerateWord32(a, b);}
1175 void GetBlock(byte *output,
size_t size) {GenerateBlock(output, size);}
1200 virtual unsigned int GetMaxWaitObjectCount()
const =0;
1214 bool Wait(
unsigned long milliseconds,
CallStack const& callStack);
1223 extern CRYPTOPP_DLL
const std::string
AAD_CHANNEL;
1252 static const std::string &NULL_CHANNEL;
1269 size_t Put(byte inByte,
bool blocking=
true)
1270 {
return Put(&inByte, 1, blocking);}
1278 size_t Put(
const byte *inString,
size_t length,
bool blocking=
true)
1279 {
return Put2(inString, length, 0, blocking);}
1286 size_t PutWord16(word16 value,
ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
1293 size_t PutWord32(word32 value,
ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
1305 {size=0;
return NULL;}
1320 {
return PutModifiable2(inString, length, 0, blocking);}
1328 {
return !!Put2(NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1339 size_t PutMessageEnd(
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1340 {
return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1348 virtual size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking) =0;
1356 virtual size_t PutModifiable2(byte *inString,
size_t length,
int messageEnd,
bool blocking)
1357 {
return Put2(inString, length, messageEnd, blocking);}
1367 unsigned int GetMaxWaitObjectCount()
const;
1395 CRYPTOPP_UNUSED(parameters);
1396 throw NotImplemented(
"BufferedTransformation: this object can't be reinitialized");
1403 virtual bool IsolatedFlush(
bool hardFlush,
bool blocking) =0;
1409 {CRYPTOPP_UNUSED(blocking);
return false;}
1436 virtual bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1446 virtual bool MessageSeriesEnd(
int propagation=-1,
bool blocking=
true);
1453 {CRYPTOPP_UNUSED(propagation);}
1459 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1460 void Close() {MessageEnd();}
1471 virtual lword MaxRetrievable()
const;
1475 virtual bool AnyRetrievable()
const;
1481 virtual size_t Get(byte &outByte);
1488 virtual size_t Get(byte *outString,
size_t getMax);
1495 virtual size_t Peek(byte &outByte)
const;
1503 virtual size_t Peek(byte *outString,
size_t peekMax)
const;
1510 size_t GetWord16(word16 &value,
ByteOrder order=BIG_ENDIAN_ORDER);
1517 size_t GetWord32(word32 &value,
ByteOrder order=BIG_ENDIAN_ORDER);
1525 size_t PeekWord16(word16 &value,
ByteOrder order=BIG_ENDIAN_ORDER)
const;
1533 size_t PeekWord32(word32 &value,
ByteOrder order=BIG_ENDIAN_ORDER)
const;
1545 {TransferTo2(target, transferMax, channel);
return transferMax;}
1550 virtual lword Skip(lword skipMax=LWORD_MAX);
1562 {
return CopyRangeTo(target, 0, copyMax, channel);}
1575 {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel);
return i-position;}
1577 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1578 unsigned long MaxRetrieveable()
const {
return MaxRetrievable();}
1587 virtual lword TotalBytesRetrievable()
const;
1593 virtual unsigned int NumberOfMessages()
const;
1598 virtual bool AnyMessages()
const;
1604 virtual bool GetNextMessage();
1611 virtual unsigned int SkipMessages(
unsigned int count=UINT_MAX);
1623 {TransferMessagesTo2(target, count, channel);
return count;}
1637 virtual void SkipAll();
1640 {TransferAllTo2(target, channel);}
1644 virtual bool GetNextMessageSeries() {
return false;}
1645 virtual unsigned int NumberOfMessagesInThisSeries()
const {
return NumberOfMessages();}
1646 virtual unsigned int NumberOfMessageSeries()
const {
return 0;}
1726 size_t ChannelPut(
const std::string &channel, byte inByte,
bool blocking=
true)
1727 {
return ChannelPut(channel, &inByte, 1, blocking);}
1736 size_t ChannelPut(
const std::string &channel,
const byte *inString,
size_t length,
bool blocking=
true)
1737 {
return ChannelPut2(channel, inString, length, 0, blocking);}
1747 {
return ChannelPutModifiable2(channel, inString, length, 0, blocking);}
1756 size_t ChannelPutWord16(
const std::string &channel, word16 value,
ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
1765 size_t ChannelPutWord32(
const std::string &channel, word32 value,
ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
1776 {
return !!ChannelPut2(channel, NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1788 size_t ChannelPutMessageEnd(
const std::string &channel,
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1789 {
return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1801 virtual byte * ChannelCreatePutSpace(
const std::string &channel,
size_t &size);
1809 virtual size_t ChannelPut2(
const std::string &channel,
const byte *inString,
size_t length,
int messageEnd,
bool blocking);
1817 virtual size_t ChannelPutModifiable2(
const std::string &channel, byte *inString,
size_t length,
int messageEnd,
bool blocking);
1826 virtual bool ChannelFlush(
const std::string &channel,
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1837 virtual bool ChannelMessageSeriesEnd(
const std::string &channel,
int propagation=-1,
bool blocking=
true);
1842 virtual void SetRetrievalChannel(
const std::string &channel);
1874 CRYPTOPP_UNUSED(newAttachment); assert(!Attachable());
1875 throw NotImplemented(
"BufferedTransformation: this object is not attachable");
1884 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1891 static int DecrementPropagation(
int propagation)
1892 {
return propagation != 0 ? propagation - 1 : 0;}
1940 {
if (!Validate(rng, level))
throw InvalidMaterial(
"CryptoMaterial: this object contains invalid values");}
1952 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support saving");}
1969 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support loading");}
1983 CRYPTOPP_UNUSED(precomputationStorage); assert(!SupportsPrecomputation());
1984 throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");
1989 {CRYPTOPP_UNUSED(storedPrecomputation); assert(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
1992 {CRYPTOPP_UNUSED(storedPrecomputation); assert(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
1995 void DoQuickSanityCheck()
const {ThrowIfInvalid(
NullRNG(), 0);}
1997 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2001 #if (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) 2003 char m_sunCCworkaround;
2020 CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(params);
2021 throw NotImplemented(
"GeneratableCryptoMaterial: this object does not support key/parameter generation");
2032 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2067 {AccessMaterial().Load(bt);}
2070 {GetMaterial().Save(bt);}
2072 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2086 virtual PublicKey & AccessPublicKey() =0;
2087 virtual const PublicKey & GetPublicKey()
const {
return const_cast<PublicKeyAlgorithm *
>(
this)->AccessPublicKey();}
2089 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2102 virtual PrivateKey & AccessPrivateKey() =0;
2103 virtual const PrivateKey & GetPrivateKey()
const {
return const_cast<PrivateKeyAlgorithm *
>(
this)->AccessPrivateKey();}
2105 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2118 virtual CryptoParameters & AccessCryptoParameters() =0;
2119 virtual const CryptoParameters & GetCryptoParameters()
const {
return const_cast<KeyAgreementAlgorithm *
>(
this)->AccessCryptoParameters();}
2121 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2138 virtual size_t MaxPlaintextLength(
size_t ciphertextLength)
const =0;
2142 virtual size_t CiphertextLength(
size_t plaintextLength)
const =0;
2146 virtual bool ParameterSupported(
const char *name)
const =0;
2156 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2157 size_t MaxPlainTextLength(
size_t cipherTextLength)
const {
return MaxPlaintextLength(cipherTextLength);}
2158 size_t CipherTextLength(
size_t plainTextLength)
const {
return CiphertextLength(plainTextLength);}
2185 const byte *plaintext,
size_t plaintextLength,
2215 const byte *ciphertext,
size_t ciphertextLength,
2226 {
return Decrypt(rng, ciphertext, FixedCiphertextLength(), plaintext, parameters);}
2228 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2233 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2264 virtual size_t SignatureLength()
const =0;
2268 {CRYPTOPP_UNUSED(recoverablePartLength);
return SignatureLength();}
2271 virtual size_t MaxRecoverableLength()
const =0;
2274 virtual size_t MaxRecoverableLengthFromSignatureLength(
size_t signatureLength)
const =0;
2278 virtual bool IsProbabilistic()
const =0;
2281 virtual bool AllowNonrecoverablePart()
const =0;
2287 virtual bool RecoverablePartFirst()
const =0;
2299 {
throw NotImplemented(
"PK_MessageAccumulator: DigestSize() should not be called");}
2304 CRYPTOPP_UNUSED(digest); CRYPTOPP_UNUSED(digestSize);
2305 throw NotImplemented(
"PK_MessageAccumulator: TruncatedFinal() should not be called");
2317 virtual void InputRecoverableMessage(
PK_MessageAccumulator &messageAccumulator,
const byte *recoverableMessage,
size_t recoverableMessageLength)
const =0;
2335 virtual size_t SignMessage(
RandomNumberGenerator &rng,
const byte *message,
size_t messageLen, byte *signature)
const;
2341 virtual size_t SignMessageWithRecovery(
RandomNumberGenerator &rng,
const byte *recoverableMessage,
size_t recoverableMessageLength,
2342 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength, byte *signature)
const;
2344 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2363 virtual void InputSignature(
PK_MessageAccumulator &messageAccumulator,
const byte *signature,
size_t signatureLength)
const =0;
2372 virtual bool VerifyMessage(
const byte *message,
size_t messageLen,
2373 const byte *signature,
size_t signatureLength)
const;
2389 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength,
2390 const byte *signature,
size_t signatureLength)
const;
2392 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2407 virtual unsigned int AgreedValueLength()
const =0;
2409 virtual unsigned int PrivateKeyLength()
const =0;
2411 virtual unsigned int PublicKeyLength()
const =0;
2417 virtual void GeneratePublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2427 virtual bool Agree(byte *agreedValue,
const byte *privateKey,
const byte *otherPublicKey,
bool validateOtherPublicKey=
true)
const =0;
2429 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2433 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2435 {
return GetCryptoParameters().Validate(rng, 2);}
2449 virtual unsigned int AgreedValueLength()
const =0;
2452 virtual unsigned int StaticPrivateKeyLength()
const =0;
2454 virtual unsigned int StaticPublicKeyLength()
const =0;
2460 virtual void GenerateStaticPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2463 virtual void GenerateStaticKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
2466 virtual unsigned int EphemeralPrivateKeyLength()
const =0;
2468 virtual unsigned int EphemeralPublicKeyLength()
const =0;
2474 virtual void GenerateEphemeralPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2477 virtual void GenerateEphemeralKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
2489 virtual bool Agree(byte *agreedValue,
2490 const byte *staticPrivateKey,
const byte *ephemeralPrivateKey,
2491 const byte *staticOtherPublicKey,
const byte *ephemeralOtherPublicKey,
2492 bool validateStaticOtherPublicKey=
true)
const =0;
2494 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2498 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2500 {
return GetCryptoParameters().Validate(rng, 2);}
2527 class ProtocolSession
2534 ProtocolError(ErrorType errorType,
const std::string &s) :
Exception(errorType, s) {}
2539 class UnexpectedMethodCall :
public Exception 2542 UnexpectedMethodCall(
const std::string &s) :
Exception(OTHER_ERROR, s) {}
2545 ProtocolSession() : m_rng(NULL), m_throwOnProtocolError(
true), m_validState(
false) {}
2546 virtual ~ProtocolSession() {}
2550 bool GetThrowOnProtocolError()
const {
return m_throwOnProtocolError;}
2551 void SetThrowOnProtocolError(
bool throwOnProtocolError) {m_throwOnProtocolError = throwOnProtocolError;}
2553 bool HasValidState()
const {
return m_validState;}
2555 virtual bool OutgoingMessageAvailable()
const =0;
2556 virtual unsigned int GetOutgoingMessageLength()
const =0;
2557 virtual void GetOutgoingMessage(byte *message) =0;
2559 virtual bool LastMessageProcessed()
const =0;
2560 virtual void ProcessIncomingMessage(
const byte *message,
unsigned int messageLength) =0;
2564 void CheckAndHandleInvalidState()
const;
2565 void SetValidState(
bool valid) {m_validState = valid;}
2570 bool m_throwOnProtocolError, m_validState;
2573 class KeyAgreementSession :
public ProtocolSession
2576 virtual unsigned int GetAgreedValueLength()
const =0;
2577 virtual void GetAgreedValue(byte *agreedValue)
const =0;
2579 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2580 virtual ~KeyAgreementSession() {}
2584 class PasswordAuthenticatedKeyAgreementSession :
public KeyAgreementSession
2588 const byte *myId,
unsigned int myIdLength,
2589 const byte *counterPartyId,
unsigned int counterPartyIdLength,
2590 const byte *passwordOrVerifier,
unsigned int passwordOrVerifierLength);
2592 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2593 virtual ~PasswordAuthenticatedKeyAgreementSession() {}
2602 {
return GetCryptoParameters().Validate(rng, 2);}
2604 virtual unsigned int GetPasswordVerifierLength(
const byte *password,
unsigned int passwordLength)
const =0;
2605 virtual void GeneratePasswordVerifier(
RandomNumberGenerator &rng,
const byte *userId,
unsigned int userIdLength,
const byte *password,
unsigned int passwordLength, byte *verifier)
const =0;
2607 enum RoleFlags {CLIENT=1, SERVER=2, INITIATOR=4, RESPONDER=8};
2609 virtual bool IsValidRole(
unsigned int role) =0;
2610 virtual PasswordAuthenticatedKeyAgreementSession * CreateProtocolSession(
unsigned int role)
const =0;
2612 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2613 virtual ~PasswordAuthenticatedKeyAgreementDomain() {}
2652 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2660 #if CRYPTOPP_MSC_VERSION 2661 # pragma warning(pop)
Base class for all exceptions thrown by Crypto++.
void DEREncode(BufferedTransformation &bt) const
for backwards compatibility, calls GetMaterial().Save(bt)
exception thrown when invalid crypto material is detected
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
const char * DigestSize()
int, in bytes
An invalid argument was detected.
void SetKeyWithIV(const byte *key, size_t length, const byte *iv)
Sets or reset the key of this object.
Interface for message authentication codes.
container of wait objects
Interface for asymmetric algorithms.
virtual unsigned int MinIVLength() const
returns minimal length of IVs accepted by this object
virtual bool NeedsPrespecifiedDataLengths() const
if this function returns true, SpecifyDataLengths() must be called before attempting to input data ...
Interface for public-key encryptors and decryptors.
ByteOrder
Provides the byte ordering.
const char * what() const
Retrieves a C-string describing the exception.
virtual void ThrowIfInvalid(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
The IV is set by the object.
The operating system reported an error.
Interface for one direction (encryption or decryption) of a stream cipher or block cipher mode with a...
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
const std::type_info & GetStoredTypeInfo() const
Provides the stored type.
virtual void Load(BufferedTransformation &bt)
Loads a key from a BufferedTransformation.
Exception(ErrorType errorType, const std::string &s)
Construct a new Exception.
this indicates that a member function was called in the wrong state, for example trying to encrypt a ...
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
Interface for public-key signers.
Interface for public-key encryptors.
Converts a typename to an enumerated value.
bool GetThisObject(T &object) const
Get a copy of this object or subobject.
bool CanUseRandomIVs() const
returns whether the object can use random IVs (in addition to ones returned by GetNextIV) ...
CipherDir
Specifies a direction for a cipher to operate.
void BERDecode(BufferedTransformation &bt)
for backwards compatibility, calls AccessMaterial().Load(bt)
DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *ciphertext, byte *plaintext, const NameValuePairs ¶meters=g_nullNameValuePairs) const
decrypt a fixed size ciphertext
Flush(true) was called but it can't completely flush its buffers.
Thrown when an unexpected type is encountered.
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
Interface for asymmetric algorithms using private keys.
BufferedTransformation & TheBitBucket()
An input discarding BufferedTransformation.
ValueTypeMismatch(const std::string &name, const std::type_info &stored, const std::type_info &retrieving)
Construct a ValueTypeMismatch.
virtual Clonable * Clone() const
Copies this object.
Library configuration file.
Interface for random number generators.
size_t messageLength
Recovered message length if isValidCoding is true, undefined otherwise.
Interface for private keys.
Interface for cloning objects.
virtual size_t FixedCiphertextLength() const
return fixed ciphertext length, if one exists, otherwise return 0
Data integerity check, such as CRC or MAC, failed.
Interface for one direction (encryption or decryption) of a block cipher.
void SetWhat(const std::string &s)
Sets the error string for the exception.
Interface for objects that can be waited on.
virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
save precomputation for later use
const std::type_info & GetRetrievingTypeInfo() const
Provides the retrieveing type.
Interface for domains of simple key agreement protocols.
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
bool CanUsePredictableIVs() const
returns whether the object can use random but possibly predictable IVs (in addition to ones returned ...
Returns a decoding results.
virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation)
retrieve previously saved precomputation
Exception thrown when trying to encrypt plaintext of invalid length.
Input data was received that did not conform to expected format.
Interface for public-key decryptors.
A method was called which was not implemented.
key too short exception, may be thrown by any function in this class if the private or public key is ...
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
bool operator!=(const DecodingResult &rhs) const
Compare two DecodingResult.
virtual unsigned int MaxIVLength() const
returns maximal length of IVs accepted by this object
unsigned int DigestSize() const
should not be called on PK_MessageAccumulator
virtual bool IsValidKeyLength(size_t keylength) const
Returns whether keylength is a valid key length.
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()
DecodingResult()
Constructs a DecodingResult.
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Multiple precision integer with arithmetic operations.
DecodingResult(size_t len)
Constructs a DecodingResult.
invalid key exception, may be thrown by any function in this class if the private or public key has a...
Interface for algorithms that take byte strings as keys.
bool operator==(const DecodingResult &rhs) const
Compare two DecodingResult.
Interface for asymmetric algorithms using public keys.
virtual unsigned int IVSize() const
Returns length of the IV accepted by this object.
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
virtual bool CanIncorporateEntropy() const
Determines if a generator can accept additional entropy.
bool CanUseStructuredIVs() const
returns whether the object can use structured IVs, for example a counter (in addition to ones returne...
Interface for public-key signers and verifiers.
const std::string & GetOperation() const
Retrieve the operating system API that reported the error.
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
RandomNumberGenerator & NullRNG()
Random Number Generator that does not produce random numbers.
int GetErrorCode() const
Retrieve the error code returned by the operating system.
const char * BlockSize()
int, in bytes
const unsigned long INFINITE_TIME
Represents infinite time.
ErrorType GetErrorType() const
Retrieves the error type for the exception.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
Interface for all crypto algorithms.
Interface for accumulating messages to be signed or verified.
unsigned int DefaultIVLength() const
returns default length of IVs accepted by this object
A decryption filter encountered invalid ciphertext.
Interface for key agreement algorithms.
IV_Requirement
Provides IV requirements as an enumerated value.
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.
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.
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
An invalid argument was detected.
Interface for generatable crypto material, such as private keys and crypto parameters.
Interface for crypto prameters.
bool GetThisPointer(T *&ptr) const
Get a pointer to this object.
bool isValidCoding
Flag to indicate the decoding is valid.
Namespace containing value name definitions.
BufferedTransformation received a Flush(true) signal but can't flush buffers.
void SetErrorType(ErrorType errorType)
Sets the error type for the exceptions.
Interface for public keys.
Crypto++ library namespace.
bool GetValue(const char *name, T &value) const
Get a named value.
The IV must be unpredictable.
bool IsResynchronizable() const
returns whether the object can be resynchronized (i.e. supports initialization vectors) ...
Interface for domains of authenticated key agreement protocols.
void TruncatedFinal(byte *digest, size_t digestSize)
should not be called on PK_MessageAccumulator
A method was called which was not implemented.
const std::string AAD_CHANNEL
Channel for additional authenticated data.
virtual void BEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
Error reading from input device or writing to output device.
virtual void Save(BufferedTransformation &bt) const
Saves a key to a BufferedTransformation.
virtual bool SupportsPrecomputation() const
Determines whether the object supports precomputation.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
virtual lword MaxFooterLength() const
the maximum length of AAD that can be input after the encrypted data
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
virtual size_t MaxSignatureLength(size_t recoverablePartLength=0) const
maximum signature length produced for a given length of recoverable message part
Namespace containing weak and wounded algorithms.
virtual bool SignatureUpfront() const
if this function returns true, during verification you must input the signature before the message...
virtual void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
virtual size_t FixedMaxPlaintextLength() const
return maximum plaintext length given the fixed ciphertext length, if one exists, otherwise return 0 ...
Interface for retrieving values given their names.
Exception thrown when an ASN1 BER decoing error is encountered.
const std::string & GetWhat() const
Retrieves a string describing the exception.