summaryrefslogtreecommitdiff
path: root/misc.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-03-10 00:55:57 -0500
committerJeffrey Walton <noloader@gmail.com>2021-03-10 00:55:57 -0500
commit3a74e072a54d391927988380bf19fb1950c866f7 (patch)
treeb90957ccb8134a08279f216cab0402d45771392c /misc.h
parentbf77d89dcd44635cb3d0053827f66a4c49e5e0fb (diff)
downloadcryptopp-git-3a74e072a54d391927988380bf19fb1950c866f7.tar.gz
Fix spelling
Diffstat (limited to 'misc.h')
-rw-r--r--misc.h55
1 files changed, 32 insertions, 23 deletions
diff --git a/misc.h b/misc.h
index b2272ae9..6eddbe1a 100644
--- a/misc.h
+++ b/misc.h
@@ -285,10 +285,10 @@ struct NewObject
/// \tparam T the class or type
/// \tparam F the object factory for T
/// \tparam instance an instance counter for the class object
-/// \details This class safely initializes a static object in a multithreaded environment. For C++03
+/// \details This class safely initializes a static object in a multi-threaded environment. For C++03
/// and below it will do so without using locks for portability. If two threads call Ref() at the same
/// time, they may get back different references, and one object may end up being memory leaked. This
-/// is by design and it avoids a subltle initialization problem ina multithreaded environment with thread
+/// is by design and it avoids a subtle initialization problem in a multi-threaded environment with thread
/// local storage on early Windows platforms, like Windows XP and Windows 2003.
/// \details For C++11 and above, a standard double-checked locking pattern with thread fences
/// are used. The locks and fences are standard and do not hinder portability.
@@ -436,7 +436,7 @@ inline size_t PtrByteDiff(const PTR pointer1, const PTR pointer2)
/// \since Crypto++ 8.0
inline byte* BytePtr(std::string& str)
{
- // Caller wants a writeable pointer
+ // Caller wants a writable pointer
CRYPTOPP_ASSERT(str.empty() == false);
if (str.empty())
@@ -489,16 +489,24 @@ size_t BytePtrSize(const SecByteBlock& str);
/// \details EnumToInt is a convenience macro to convert enums
/// to integers. The cast avoids C++20 enum-enum conversion
/// warnings.
-/// \details A macro is used due to [lack of] constexpr-ness in
+/// \details C++11 and above use a constexpr function. C++03
+/// and below use a macro due to [lack of] constexpr-ness in
/// early versions of C++.
/// \since Crypto++ 8.6
-#define EnumToInt(v) static_cast<int>(v)
+#if (CRYPTOPP_CXX11_CONSTEXPR)
+template <typename T>
+constexpr int EnumToInt(T v) {
+ return static_cast<int>(v);
+}
+#else
+# define EnumToInt(v) static_cast<int>(v)
+#endif
#if (!__STDC_WANT_SECURE_LIB__ && !defined(_MEMORY_S_DEFINED)) || defined(CRYPTOPP_WANT_SECURE_LIB)
/// \brief Bounds checking replacement for memcpy()
-/// \param dest pointer to the desination memory block
-/// \param sizeInBytes size of the desination memory block, in bytes
+/// \param dest pointer to the destination memory block
+/// \param sizeInBytes size of the destination memory block, in bytes
/// \param src pointer to the source memory block
/// \param count the number of bytes to copy
/// \throw InvalidArgument
@@ -522,7 +530,7 @@ inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t cou
CRYPTOPP_ASSERT(dest != NULLPTR); CRYPTOPP_ASSERT(src != NULLPTR);
// Restricted pointers. We want to check ranges, but it is not clear how to do it.
CRYPTOPP_ASSERT(src != dest);
- // Destination buffer must be large enough to satsify request
+ // Destination buffer must be large enough to satisfy request
CRYPTOPP_ASSERT(sizeInBytes >= count);
if (count > sizeInBytes)
@@ -543,8 +551,8 @@ inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t cou
}
/// \brief Bounds checking replacement for memmove()
-/// \param dest pointer to the desination memory block
-/// \param sizeInBytes size of the desination memory block, in bytes
+/// \param dest pointer to the destination memory block
+/// \param sizeInBytes size of the destination memory block, in bytes
/// \param src pointer to the source memory block
/// \param count the number of bytes to copy
/// \throw InvalidArgument
@@ -566,7 +574,7 @@ inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t co
// Pointers must be valid; otherwise undefined behavior
CRYPTOPP_ASSERT(dest != NULLPTR); CRYPTOPP_ASSERT(src != NULLPTR);
- // Destination buffer must be large enough to satsify request
+ // Destination buffer must be large enough to satisfy request
CRYPTOPP_ASSERT(sizeInBytes >= count);
if (count > sizeInBytes)
@@ -587,7 +595,8 @@ inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t co
}
#if __BORLANDC__ >= 0x620
-// C++Builder 2010 workaround: can't use std::memcpy_s because it doesn't allow 0 lengths
+// C++Builder 2010 workaround: can't use std::memcpy_s
+// because it doesn't allow 0 lengths
# define memcpy_s CryptoPP::memcpy_s
# define memmove_s CryptoPP::memmove_s
#endif
@@ -628,7 +637,7 @@ inline void vec_swap(T& a, T& b)
/// \sa SecureWipeBuffer
inline void * memset_z(void *ptr, int val, size_t num)
{
-// avoid extranous warning on GCC 4.3.2 Ubuntu 8.10
+// avoid extraneous warning on GCC 4.3.2 Ubuntu 8.10
#if CRYPTOPP_GCC_VERSION >= 30001 || CRYPTOPP_LLVM_CLANG_VERSION >= 20800 || \
CRYPTOPP_APPLE_CLANG_VERSION >= 30000
if (__builtin_constant_p(num) && num==0)
@@ -675,7 +684,7 @@ template <class T> inline const T& STDMAX(const T& a, const T& b)
# endif
#endif
-/// \brief Safe comparison of values that could be neagtive and incorrectly promoted
+/// \brief Safe comparison of values that could be negative and incorrectly promoted
/// \tparam T1 class or type
/// \tparam T2 class or type
/// \param a the first value
@@ -746,7 +755,7 @@ std::string IntToString(T value, unsigned int base = 10)
/// \param base the base to use during the conversion
/// \return the string representation of value in base.
/// \details this template function specialization was added to suppress
-/// Coverity findings on IntToString() with unsigned types.
+/// Coverity findings on IntToString() with unsigned types.
template <> CRYPTOPP_DLL
std::string IntToString<word64>(word64 value, unsigned int base);
@@ -983,7 +992,7 @@ CRYPTOPP_DLL void CRYPTOPP_API xorbuf(byte *output, const byte *input, const byt
/// \param buf2 the second buffer
/// \param count the size of the buffers, in bytes
/// \details VerifyBufsEqual performs an XOR of the elements in two equally sized
-/// buffers and retruns a result based on the XOR operation. A count of 0 returns
+/// buffers and returns a result based on the XOR operation. A count of 0 returns
/// true because two empty buffers are considered equal.
/// \details The function is near constant-time because CPU micro-code timings could
/// affect the "constant-ness". Calling code is responsible for mitigating timing
@@ -1128,7 +1137,7 @@ inline T2 ModPowerOf2(const T1 &a, const T2 &b)
/// \return the possibly unmodified value \n
/// \details RoundDownToMultipleOf is effectively a floor function based on m. The function returns
/// the value <tt>n - n\%m</tt>. If n is a multiple of m, then the original value is returned.
-/// \note <tt>T1</tt> and <tt>T2</tt> should be usigned arithmetic types. If <tt>T1</tt> or
+/// \note <tt>T1</tt> and <tt>T2</tt> should be unsigned arithmetic types. If <tt>T1</tt> or
/// <tt>T2</tt> is signed, then the value should be non-negative. The library asserts in
/// debug builds when practical, but allows you to perform the operation in release builds.
template <class T1, class T2>
@@ -1158,7 +1167,7 @@ inline T1 RoundDownToMultipleOf(const T1 &n, const T2 &m)
/// \details RoundUpToMultipleOf is effectively a ceiling function based on m. The function
/// returns the value <tt>n + n\%m</tt>. If n is a multiple of m, then the original value is
/// returned. If the value n would overflow, then an InvalidArgument exception is thrown.
-/// \note <tt>T1</tt> and <tt>T2</tt> should be usigned arithmetic types. If <tt>T1</tt> or
+/// \note <tt>T1</tt> and <tt>T2</tt> should be unsigned arithmetic types. If <tt>T1</tt> or
/// <tt>T2</tt> is signed, then the value should be non-negative. The library asserts in
/// debug builds when practical, but allows you to perform the operation in release builds.
template <class T1, class T2>
@@ -1271,7 +1280,7 @@ inline bool NativeByteOrderIs(ByteOrder order)
/// DECRYPTION otherwise
/// \details A cipher can be operated in a "forward" direction (encryption) or a "reverse"
/// direction (decryption). The operations do not have to be symmetric, meaning a second
-/// application of the transformation does not necessariy return the original message.
+/// application of the transformation does not necessarily return the original message.
/// That is, <tt>E(D(m))</tt> may not equal <tt>E(E(m))</tt>; and <tt>D(E(m))</tt> may not
/// equal <tt>D(D(m))</tt>.
template <class T>
@@ -1326,7 +1335,7 @@ inline void IncrementCounterByOne(byte *output, const byte *input, unsigned int
}
}
-/// \brief Performs a branchless swap of values a and b if condition c is true
+/// \brief Performs a branch-less swap of values a and b if condition c is true
/// \tparam T class or type
/// \param c the condition to perform the swap
/// \param a the first value
@@ -1339,7 +1348,7 @@ inline void ConditionalSwap(bool c, T &a, T &b)
b ^= t;
}
-/// \brief Performs a branchless swap of pointers a and b if condition c is true
+/// \brief Performs a branch-less swap of pointers a and b if condition c is true
/// \tparam T class or type
/// \param c the condition to perform the swap
/// \param a the first pointer
@@ -2204,12 +2213,12 @@ inline T ConditionalByteReverse(ByteOrder order, T value)
///
/// cout << "V1: ";
/// for(unsigned int i = 0; i < v1.size(); i++)
-/// cout << std::hex << v1[i] << " ";
+/// cout << std::hex << v1[i] << " ";
/// cout << endl;
///
/// cout << "V2: ";
/// for(unsigned int i = 0; i < v2.size(); i++)
-/// cout << std::hex << v2[i] << " ";
+/// cout << std::hex << v2[i] << " ";
/// cout << endl;</pre>
/// The program above results in the following output.
/// <pre>V1: 00000001 00000002 00000003 00000004