99 #ifndef CRYPTOPP_CRYPTLIB_H 100 #define CRYPTOPP_CRYPTLIB_H 106 #if CRYPTOPP_MSC_VERSION 107 # pragma warning(push) 108 # pragma warning(disable: 4127 4189 4505 4702) 131 template <
typename ENUM_TYPE,
int VALUE>
134 static ENUM_TYPE ToEnum() {
return (ENUM_TYPE)VALUE;}
183 const char *
what()
const throw() {
return (m_what.c_str());}
185 const std::string &
GetWhat()
const {
return m_what;}
187 void SetWhat(
const std::string &s) {m_what = s;}
238 OS_Error(
ErrorType errorType,
const std::string &s,
const std::string& operation,
int errorCode)
239 :
Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {}
247 std::string m_operation;
304 ValueTypeMismatch(
const std::string &name,
const std::type_info &stored,
const std::type_info &retrieving)
305 :
InvalidArgument(
"NameValuePairs: type mismatch for '" + name +
"', stored '" + stored.name() +
"', trying to retrieve '" + retrieving.name() +
"'")
306 , m_stored(stored), m_retrieving(retrieving) {}
317 const std::type_info &m_stored;
318 const std::type_info &m_retrieving;
327 return GetValue((std::string(
"ThisObject:")+
typeid(T).name()).c_str(),
object);
336 return GetValue((std::string(
"ThisPointer:")+
typeid(T).name()).c_str(), ptr);
349 return GetVoidValue(name,
typeid(T), &value);
363 bool result = GetValue(name, value);
365 if (result) {
return value;}
372 CRYPTOPP_DLL std::string GetValueNames()
const 373 {std::string result; GetValue(
"ValueNames", result);
return result;}
383 CRYPTOPP_DLL
bool GetIntValue(
const char *name,
int &value)
const 384 {
return GetValue(name, value);}
392 CRYPTOPP_DLL
int GetIntValueWithDefault(
const char *name,
int defaultValue)
const 393 {
return GetValueWithDefault(name, defaultValue);}
404 CRYPTOPP_DLL
static void CRYPTOPP_API ThrowIfTypeMismatch(
const char *name,
const std::type_info &stored,
const std::type_info &retrieving)
420 if (!GetValue(name, value))
421 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
433 CRYPTOPP_DLL
void GetRequiredIntParameter(
const char *className,
const char *name,
int &value)
const 435 if (!GetIntValue(name, value))
436 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
449 CRYPTOPP_DLL
virtual bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
465 bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const 466 {CRYPTOPP_UNUSED(name); CRYPTOPP_UNUSED(valueType); CRYPTOPP_UNUSED(pValue);
return false;}
475 #if CRYPTOPP_DOXYGEN_PROCESSING 497 #elif defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5130) 500 static const NameValuePairs& g_nullNameValuePairs = s_nullNameValuePairs;
512 #if CRYPTOPP_DOXYGEN_PROCESSING 520 DOCUMENTED_NAMESPACE_BEGIN(
Name)
522 DOCUMENTED_NAMESPACE_END
536 DOCUMENTED_NAMESPACE_BEGIN(
Weak)
538 DOCUMENTED_NAMESPACE_END
543 DOCUMENTED_NAMESPACE_BEGIN(
NaCl)
545 DOCUMENTED_NAMESPACE_END
550 DOCUMENTED_NAMESPACE_BEGIN(
Test)
552 DOCUMENTED_NAMESPACE_END
586 Algorithm(
bool checkSelfTestStatus =
true);
606 virtual size_t MinKeyLength()
const =0;
609 virtual size_t MaxKeyLength()
const =0;
612 virtual size_t DefaultKeyLength()
const =0;
622 virtual size_t GetValidKeyLength(
size_t keylength)
const =0;
629 {
return keylength == GetValidKeyLength(keylength);}
635 virtual void SetKey(
const byte *key,
size_t length,
const NameValuePairs ¶ms = g_nullNameValuePairs);
645 void SetKeyWithRounds(
const byte *key,
size_t length,
int rounds);
655 void SetKeyWithIV(
const byte *key,
size_t length,
const byte *iv,
size_t ivLength);
665 {SetKeyWithIV(key, length, iv, IVSize());}
715 {
throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");}
737 CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(ivLength);
738 throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");
755 virtual const Algorithm & GetAlgorithm()
const =0;
762 virtual void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms) =0;
767 void ThrowIfInvalidKeyLength(
size_t length);
774 void ThrowIfResynchronizable();
783 void ThrowIfInvalidIV(
const byte *iv);
788 size_t ThrowIfInvalidIVLength(
int length);
795 const byte * GetIVAndThrowIfInvalid(
const NameValuePairs ¶ms,
size_t &size);
799 inline void AssertValidKeyLength(
size_t length)
const 822 virtual void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const =0;
833 {ProcessAndXorBlock(inBlock, NULLPTR, outBlock);}
842 {ProcessAndXorBlock(inoutBlock, NULLPTR, inoutBlock);}
846 virtual unsigned int BlockSize()
const =0;
851 virtual unsigned int OptimalDataAlignment()
const;
860 virtual bool IsForwardTransformation()
const =0;
870 BT_InBlockIsCounter=1,
872 BT_DontIncrementInOutPointers=2,
876 BT_ReverseDirection=8,
878 BT_AllowParallel=16};
888 virtual size_t AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
const;
934 virtual unsigned int OptimalDataAlignment()
const;
943 virtual void ProcessData(byte *outString,
const byte *inString,
size_t length) =0;
957 virtual size_t ProcessLastBlock(byte *outString,
size_t outLength,
const byte *inString,
size_t inLength);
1014 {ProcessData(inoutString, inoutString, length);}
1022 {ProcessData(outString, inString, length);}
1028 {ProcessData(&input, &input, 1);
return input;}
1032 virtual bool IsRandomAccess()
const =0;
1041 CRYPTOPP_UNUSED(pos);
1043 throw NotImplemented(
"StreamTransformation: this object doesn't support random access");
1050 virtual bool IsSelfInverting()
const =0;
1055 virtual bool IsForwardTransformation()
const =0;
1078 virtual void Update(
const byte *input,
size_t length) =0;
1101 {TruncatedFinal(NULLPTR, 0);}
1128 virtual unsigned int OptimalDataAlignment()
const;
1140 {Update(input, length); Final(digest);}
1152 {
return TruncatedVerify(digest,
DigestSize());}
1167 virtual bool VerifyDigest(
const byte *digest,
const byte *input,
size_t length)
1168 {Update(input, length);
return Verify(digest);}
1175 virtual void TruncatedFinal(byte *digest,
size_t digestSize) =0;
1188 {Update(input, length); TruncatedFinal(digest, digestSize);}
1200 virtual bool TruncatedVerify(
const byte *digest,
size_t digestLength);
1217 {Update(input, length);
return TruncatedVerify(digest, digestLength);}
1224 void ThrowIfInvalidTruncatedSize(
size_t size)
const;
1232 const Algorithm & GetAlgorithm()
const {
return *
this;}
1240 const Algorithm & GetAlgorithm()
const {
return *
this;}
1248 const Algorithm & GetAlgorithm()
const {
return *
this;}
1278 explicit BadState(
const std::string &name,
const char *message) :
Exception(OTHER_ERROR, name +
": " + message) {}
1279 explicit BadState(
const std::string &name,
const char *
function,
const char *state) :
Exception(OTHER_ERROR, name +
": " +
function +
" was called before " + state) {}
1284 virtual lword MaxHeaderLength()
const =0;
1287 virtual lword MaxMessageLength()
const =0;
1300 void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0);
1304 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);
1309 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);
1316 virtual std::string AlgorithmName()
const;
1321 virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
1322 {CRYPTOPP_UNUSED(headerLength); CRYPTOPP_UNUSED(messageLength); CRYPTOPP_UNUSED(footerLength);}
1345 CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
1346 throw NotImplemented(
"RandomNumberGenerator: IncorporateEntropy not implemented");
1358 virtual byte GenerateByte();
1365 virtual unsigned int GenerateBit();
1375 virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL);
1384 virtual void GenerateBlock(byte *output,
size_t size);
1396 virtual void GenerateIntoBufferedTransformation(
BufferedTransformation &target,
const std::string &channel, lword length);
1400 virtual void DiscardBytes(
size_t n);
1406 template <
class IT>
void Shuffle(IT begin, IT end)
1409 for (; begin != end; ++begin)
1410 std::iter_swap(begin, begin + GenerateWord32(0, static_cast<word32>(end-begin-1)));
1423 virtual std::string AlgorithmName()
const =0;
1427 virtual size_t MinDerivedLength()
const;
1431 virtual size_t MaxDerivedLength()
const;
1436 virtual size_t GetValidDerivedLength(
size_t keylength)
const =0;
1443 return keylength == GetValidDerivedLength(keylength);
1459 virtual size_t DeriveKey(byte *derived,
size_t derivedLen,
const byte *secret,
size_t secretLen,
const NameValuePairs& params = g_nullNameValuePairs)
const =0;
1470 virtual const Algorithm & GetAlgorithm()
const =0;
1475 void ThrowIfInvalidDerivedLength(
size_t length)
const;
1503 virtual unsigned int GetMaxWaitObjectCount()
const =0;
1519 bool Wait(
unsigned long milliseconds,
CallStack const& callStack);
1567 size_t Put(byte inByte,
bool blocking=
true)
1568 {
return Put(&inByte, 1, blocking);}
1577 size_t Put(
const byte *inString,
size_t length,
bool blocking=
true)
1578 {
return Put2(inString, length, 0, blocking);}
1607 {size=0;
return NULLPTR;}
1622 {
return PutModifiable2(inString, length, 0, blocking);}
1630 {
return !!Put2(NULLPTR, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1643 size_t PutMessageEnd(
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1644 {
return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1654 virtual size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking) =0;
1664 virtual size_t PutModifiable2(byte *inString,
size_t length,
int messageEnd,
bool blocking)
1665 {
return Put2(inString, length, messageEnd, blocking);}
1676 unsigned int GetMaxWaitObjectCount()
const;
1703 CRYPTOPP_UNUSED(parameters);
1704 throw NotImplemented(
"BufferedTransformation: this object can't be reinitialized");
1711 virtual bool IsolatedFlush(
bool hardFlush,
bool blocking) =0;
1717 {CRYPTOPP_UNUSED(blocking);
return false;}
1727 virtual void Initialize(
const NameValuePairs ¶meters=g_nullNameValuePairs,
int propagation=-1);
1743 virtual bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1753 virtual bool MessageSeriesEnd(
int propagation=-1,
bool blocking=
true);
1760 {CRYPTOPP_UNUSED(propagation);}
1775 virtual lword MaxRetrievable()
const;
1779 virtual bool AnyRetrievable()
const;
1785 virtual size_t Get(byte &outByte);
1792 virtual size_t Get(byte *outString,
size_t getMax);
1799 virtual size_t Peek(byte &outByte)
const;
1807 virtual size_t Peek(byte *outString,
size_t peekMax)
const;
1849 {TransferTo2(target, transferMax, channel);
return transferMax;}
1862 virtual lword Skip(lword skipMax=LWORD_MAX);
1874 {
return CopyRangeTo(target, 0, copyMax, channel);}
1887 {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel);
return i-position;}
1895 virtual lword TotalBytesRetrievable()
const;
1901 virtual unsigned int NumberOfMessages()
const;
1906 virtual bool AnyMessages()
const;
1912 virtual bool GetNextMessage();
1919 virtual unsigned int SkipMessages(
unsigned int count=UINT_MAX);
1931 {TransferMessagesTo2(target, count, channel);
return count;}
1945 virtual void SkipAll();
1953 {TransferAllTo2(target, channel);}
2053 size_t ChannelPut(
const std::string &channel, byte inByte,
bool blocking=
true)
2054 {
return ChannelPut(channel, &inByte, 1, blocking);}
2063 size_t ChannelPut(
const std::string &channel,
const byte *inString,
size_t length,
bool blocking=
true)
2064 {
return ChannelPut2(channel, inString, length, 0, blocking);}
2074 {
return ChannelPutModifiable2(channel, inString, length, 0, blocking);}
2083 size_t ChannelPutWord16(
const std::string &channel, word16 value,
ByteOrder order=
BIG_ENDIAN_ORDER,
bool blocking=
true);
2092 size_t ChannelPutWord32(
const std::string &channel, word32 value,
ByteOrder order=
BIG_ENDIAN_ORDER,
bool blocking=
true);
2103 {
return !!ChannelPut2(channel, NULLPTR, 0, propagation < 0 ? -1 : propagation+1, blocking);}
2114 size_t ChannelPutMessageEnd(
const std::string &channel,
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
2115 {
return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
2128 virtual byte * ChannelCreatePutSpace(
const std::string &channel,
size_t &size);
2137 virtual size_t ChannelPut2(
const std::string &channel,
const byte *inString,
size_t length,
int messageEnd,
bool blocking);
2146 virtual size_t ChannelPutModifiable2(
const std::string &channel, byte *inString,
size_t length,
int messageEnd,
bool blocking);
2156 virtual bool ChannelFlush(
const std::string &channel,
bool hardFlush,
int propagation=-1,
bool blocking=
true);
2167 virtual bool ChannelMessageSeriesEnd(
const std::string &channel,
int propagation=-1,
bool blocking=
true);
2172 virtual void SetRetrievalChannel(
const std::string &channel);
2207 throw NotImplemented(
"BufferedTransformation: this object is not attachable");
2218 static int DecrementPropagation(
int propagation)
2219 {
return propagation != 0 ? propagation - 1 : 0;}
2269 {
if (!Validate(rng, level))
throw InvalidMaterial(
"CryptoMaterial: this object contains invalid values");}
2281 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support saving");}
2298 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support loading");}
2314 CRYPTOPP_UNUSED(precomputationStorage);
CRYPTOPP_ASSERT(!SupportsPrecomputation());
2315 throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");
2323 {CRYPTOPP_UNUSED(storedPrecomputation);
CRYPTOPP_ASSERT(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
2330 {CRYPTOPP_UNUSED(storedPrecomputation);
CRYPTOPP_ASSERT(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
2336 #if (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) 2338 char m_sunCCworkaround;
2355 CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(params);
2356 throw NotImplemented(
"GeneratableCryptoMaterial: this object does not support key/parameter generation");
2407 {AccessMaterial().
Load(bt);}
2414 {GetMaterial().Save(bt);}
2429 {
return AccessPublicKey();}
2433 {
return GetPublicKey();}
2437 virtual PublicKey & AccessPublicKey() =0;
2459 virtual PrivateKey & AccessPrivateKey() =0;
2480 virtual CryptoParameters & AccessCryptoParameters() =0;
2497 virtual size_t MaxPlaintextLength(
size_t ciphertextLength)
const =0;
2502 virtual size_t CiphertextLength(
size_t plaintextLength)
const =0;
2509 virtual bool ParameterSupported(
const char *name)
const =0;
2547 const byte *plaintext,
size_t plaintextLength,
2548 byte *ciphertext,
const NameValuePairs ¶meters = g_nullNameValuePairs)
const =0;
2581 const byte *ciphertext,
size_t ciphertextLength,
2582 byte *plaintext,
const NameValuePairs ¶meters = g_nullNameValuePairs)
const =0;
2607 {
return Decrypt(rng, ciphertext, FixedCiphertextLength(), plaintext, parameters);}
2639 virtual size_t SignatureLength()
const =0;
2647 {CRYPTOPP_UNUSED(recoverablePartLength);
return SignatureLength();}
2653 virtual size_t MaxRecoverableLength()
const =0;
2661 virtual size_t MaxRecoverableLengthFromSignatureLength(
size_t signatureLength)
const =0;
2667 virtual bool IsProbabilistic()
const =0;
2671 virtual bool AllowNonrecoverablePart()
const =0;
2683 virtual bool RecoverablePartFirst()
const =0;
2694 {
throw NotImplemented(
"PK_MessageAccumulator: DigestSize() should not be called");}
2699 CRYPTOPP_UNUSED(digest); CRYPTOPP_UNUSED(digestSize);
2700 throw NotImplemented(
"PK_MessageAccumulator: TruncatedFinal() should not be called");
2721 virtual void InputRecoverableMessage(
PK_MessageAccumulator &messageAccumulator,
const byte *recoverableMessage,
size_t recoverableMessageLength)
const =0;
2748 virtual size_t SignMessage(
RandomNumberGenerator &rng,
const byte *message,
size_t messageLen, byte *signature)
const;
2759 virtual size_t SignMessageWithRecovery(
RandomNumberGenerator &rng,
const byte *recoverableMessage,
size_t recoverableMessageLength,
2760 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength, byte *signature)
const;
2784 virtual void InputSignature(
PK_MessageAccumulator &messageAccumulator,
const byte *signature,
size_t signatureLength)
const =0;
2804 virtual bool VerifyMessage(
const byte *message,
size_t messageLen,
2805 const byte *signature,
size_t signatureLen)
const;
2832 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength,
2833 const byte *signature,
size_t signatureLength)
const;
2848 virtual unsigned int AgreedValueLength()
const =0;
2852 virtual unsigned int PrivateKeyLength()
const =0;
2856 virtual unsigned int PublicKeyLength()
const =0;
2869 virtual void GeneratePublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2892 virtual bool Agree(byte *agreedValue,
const byte *privateKey,
const byte *otherPublicKey,
bool validateOtherPublicKey=
true)
const =0;
2907 virtual unsigned int AgreedValueLength()
const =0;
2911 virtual unsigned int StaticPrivateKeyLength()
const =0;
2915 virtual unsigned int StaticPublicKeyLength()
const =0;
2928 virtual void GenerateStaticPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2937 virtual void GenerateStaticKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
2941 virtual unsigned int EphemeralPrivateKeyLength()
const =0;
2945 virtual unsigned int EphemeralPublicKeyLength()
const =0;
2958 virtual void GenerateEphemeralPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2965 virtual void GenerateEphemeralKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
2983 virtual bool Agree(byte *agreedValue,
2984 const byte *staticPrivateKey,
const byte *ephemeralPrivateKey,
2985 const byte *staticOtherPublicKey,
const byte *ephemeralOtherPublicKey,
2986 bool validateStaticOtherPublicKey=
true)
const =0;
3012 class ProtocolSession
3019 ProtocolError(ErrorType errorType,
const std::string &s) :
Exception(errorType, s) {}
3024 class UnexpectedMethodCall :
public Exception 3027 UnexpectedMethodCall(
const std::string &s) :
Exception(OTHER_ERROR, s) {}
3030 virtual ~ProtocolSession() {}
3032 ProtocolSession() : m_rng(NULLPTR), m_throwOnProtocolError(
true), m_validState(
false) {}
3036 bool GetThrowOnProtocolError()
const {
return m_throwOnProtocolError;}
3037 void SetThrowOnProtocolError(
bool throwOnProtocolError) {m_throwOnProtocolError = throwOnProtocolError;}
3039 bool HasValidState()
const {
return m_validState;}
3041 virtual bool OutgoingMessageAvailable()
const =0;
3042 virtual unsigned int GetOutgoingMessageLength()
const =0;
3043 virtual void GetOutgoingMessage(byte *message) =0;
3045 virtual bool LastMessageProcessed()
const =0;
3046 virtual void ProcessIncomingMessage(
const byte *message,
unsigned int messageLength) =0;
3050 void CheckAndHandleInvalidState()
const;
3051 void SetValidState(
bool valid) {m_validState = valid;}
3056 bool m_throwOnProtocolError, m_validState;
3059 class KeyAgreementSession :
public ProtocolSession
3062 virtual ~KeyAgreementSession() {}
3064 virtual unsigned int GetAgreedValueLength()
const =0;
3065 virtual void GetAgreedValue(byte *agreedValue)
const =0;
3068 class PasswordAuthenticatedKeyAgreementSession :
public KeyAgreementSession
3071 virtual ~PasswordAuthenticatedKeyAgreementSession() {}
3074 const byte *myId,
unsigned int myIdLength,
3075 const byte *counterPartyId,
unsigned int counterPartyIdLength,
3076 const byte *passwordOrVerifier,
unsigned int passwordOrVerifierLength);
3084 virtual ~PasswordAuthenticatedKeyAgreementDomain() {}
3088 {
return GetCryptoParameters().Validate(rng, 2);}
3090 virtual unsigned int GetPasswordVerifierLength(
const byte *password,
unsigned int passwordLength)
const =0;
3091 virtual void GeneratePasswordVerifier(
RandomNumberGenerator &rng,
const byte *userId,
unsigned int userIdLength,
const byte *password,
unsigned int passwordLength, byte *verifier)
const =0;
3093 enum RoleFlags {CLIENT=1, SERVER=2, INITIATOR=4, RESPONDER=8};
3095 virtual bool IsValidRole(
unsigned int role) =0;
3096 virtual PasswordAuthenticatedKeyAgreementSession * CreateProtocolSession(
unsigned int role)
const =0;
3200 return CRYPTOPP_VERSION;
3206 #if CRYPTOPP_MSC_VERSION 3207 # pragma warning(pop)
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Base class for all exceptions thrown by the library.
int HeaderVersion()
Specifies the runtime version of the library.
Exception thrown when invalid crypto material is detected.
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
the cipher is performing decryption
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.
virtual bool IsValidDerivedLength(size_t keylength) const
Returns whether keylength is a valid key length.
Interface for message authentication codes.
ErrorType
Error types or categories.
container of wait objects
Interface for asymmetric algorithms.
virtual unsigned int MinIVLength() const
Provides the minimum size of an IV.
Namespace containing NaCl library functions.
virtual bool NeedsPrespecifiedDataLengths() const
Determines if data lengths must be specified prior to inputting 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 authenticated encryption modes of operation.
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.
Exception thrown when the object is in the wrong state for the operation.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to Crypto Parameters.
Interface for public-key signers.
Interface for public-key encryptors.
Converts an enumeration to a type suitable for use as a template parameter.
bool GetThisObject(T &object) const
Get a copy of this object or subobject.
bool CanUseRandomIVs() const
Determines if the object can use random IVs.
CipherDir
Specifies a direction for a cipher to operate.
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()
Retrieves a reference to a Private Key.
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.
EnumToType< ByteOrder, LITTLE_ENDIAN_ORDER > LittleEndian
Provides a constant for LittleEndian.
Library configuration file.
Interface for random number generators.
size_t messageLength
Recovered message length if isValidCoding is true, undefined otherwise.
virtual const PublicKey & GetPublicKey() const
Retrieves a reference to a Public Key.
Interface for private keys.
Interface for cloning objects.
virtual size_t FixedCiphertextLength() const
Provides the fixed ciphertext length, if one exists.
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
Data integerity check, such as CRC or MAC, failed.
byte order is little-endian
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.
the cipher is performing encryption
virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
Save precomputation for later use.
const std::type_info & GetRetrievingTypeInfo() const
Provides the retrieveing type.
void DoQuickSanityCheck() const
Perform a quick sanity check.
Interface for domains of simple key agreement protocols.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Private Key.
bool CanUsePredictableIVs() const
Determines if the object can use random but possibly predictable IVs.
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.
Exception throw when the private or public key is too short to sign or verify.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
bool operator!=(const DecodingResult &rhs) const
Compare two DecodingResult.
virtual unsigned int MaxIVLength() const
Provides the maximum size of an IV.
unsigned int DigestSize() const
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.
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.
Exception throw when the private or public key has a length that can't be used.
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.
Namespace containing testing and benchmark classes.
virtual bool CanIncorporateEntropy() const
Determines if a generator can accept additional entropy.
bool CanUseStructuredIVs() const
Determines if the object can use structured IVs.
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.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
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
Provides the default size of an IV.
A decryption filter encountered invalid ciphertext.
Interface for key agreement algorithms.
Interface for retrieving values given their names.
const NameValuePairs g_nullNameValuePairs
An empty set of name-value pairs.
IV_Requirement
Secure IVs requirements as enumerated values.
CryptoMaterial & AccessMaterial()
Retrieves a reference to a Public Key.
virtual const CryptoParameters & GetCryptoParameters() const
Retrieves a reference to Crypto Parameters.
Interface for public-key signature verifiers.
void Shuffle(IT begin, IT end)
Randomly shuffle the specified array.
Debugging and diagnostic assertions.
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.
Interface for password based key derivation functions.
CryptoMaterial & AccessMaterial()
Retrieves a reference to Crypto Parameters.
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.
int LibraryVersion(...)
Specifies the build-time version of the library.
Interface for public keys.
Crypto++ library namespace.
bool GetValue(const char *name, T &value) const
Get a named value.
The IV must be random and unpredictable.
bool IsResynchronizable() const
Determines if the object can be resynchronized.
Interface for domains of authenticated key agreement protocols.
void TruncatedFinal(byte *digest, size_t digestSize)
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.
virtual lword MaxFooterLength() const
Provides the the maximum length of AAD.
virtual const PrivateKey & GetPrivateKey() const
Retrieves a reference to a Private Key.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Public Key.
virtual size_t MaxSignatureLength(size_t recoverablePartLength=0) const
Provides the maximum signature length produced given the length of the recoverable message part...
EnumToType< ByteOrder, BIG_ENDIAN_ORDER > BigEndian
Provides a constant for BigEndian.
Namespace containing weak and wounded algorithms.
virtual bool SignatureUpfront() const
Determines whether the signature must be input before the message.
virtual void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
Interface for key derivation functions.
virtual size_t FixedMaxPlaintextLength() const
Provides the maximum plaintext length given a fixed ciphertext length.
Interface for retrieving values given their names.
Exception thrown when an ASN.1 BER decoing error is encountered.
The IV must be random and possibly predictable.
const std::string & GetWhat() const
Retrieves a string describing the exception.