diff options
-rw-r--r-- | src/engine/def_engine/default_engine.h | 7 | ||||
-rw-r--r-- | src/filters/hex/hex.cpp | 3 | ||||
-rw-r--r-- | src/filters/hex/hex.h | 17 | ||||
-rw-r--r-- | src/math/numbertheory/curve_gfp.h | 22 | ||||
-rw-r--r-- | src/utils/mem_ops.h | 41 |
5 files changed, 76 insertions, 14 deletions
diff --git a/src/engine/def_engine/default_engine.h b/src/engine/def_engine/default_engine.h index f7e6d9746..0d864e514 100644 --- a/src/engine/def_engine/default_engine.h +++ b/src/engine/def_engine/default_engine.h @@ -51,6 +51,13 @@ class Default_Engine : public Engine Algorithm_Factory&) const; }; +/** +* Create a cipher mode filter object +* @param block_cipher a block cipher object +* @param direction are we encrypting or decrypting? +* @param mode the name of the cipher mode to use +* @param padding the mode padding to use (only used for ECB, CBC) +*/ Keyed_Filter* get_cipher_mode(const BlockCipher* block_cipher, Cipher_Dir direction, const std::string& mode, diff --git a/src/filters/hex/hex.cpp b/src/filters/hex/hex.cpp index 651899b73..7191e1554 100644 --- a/src/filters/hex/hex.cpp +++ b/src/filters/hex/hex.cpp @@ -13,6 +13,9 @@ namespace Botan { +/** +* Size used for internal buffer in hex encoder/decoder +*/ const u32bit HEX_CODEC_BUFFER_SIZE = 256; /* diff --git a/src/filters/hex/hex.h b/src/filters/hex/hex.h index 035bf4ef9..b03b933bc 100644 --- a/src/filters/hex/hex.h +++ b/src/filters/hex/hex.h @@ -24,7 +24,7 @@ class BOTAN_DLL Hex_Encoder : public Filter enum Case { Uppercase, Lowercase }; /** - Encode a single byte into two hex characters + * Encode a single byte into two hex characters */ static void encode(byte in, byte out[2], Case the_case = Uppercase); @@ -63,8 +63,19 @@ class BOTAN_DLL Hex_Encoder : public Filter class BOTAN_DLL Hex_Decoder : public Filter { public: - static byte decode(const byte[2]); - static bool is_valid(byte); + /** + * Decode a pair of hex chars to a byte + * @param in an array of two hex chars + * @return byte formed by decoding in + */ + static byte decode(const byte in[2]); + + /** + * Check if this character is a valid hex input + * @param c a single character + * @return true iff c is a valid hex char + */ + static bool is_valid(byte c); void write(const byte[], u32bit); void end_msg(); diff --git a/src/math/numbertheory/curve_gfp.h b/src/math/numbertheory/curve_gfp.h index 0a91fc52d..8a46a9735 100644 --- a/src/math/numbertheory/curve_gfp.h +++ b/src/math/numbertheory/curve_gfp.h @@ -52,14 +52,12 @@ class BOTAN_DLL CurveGFp // CurveGFp& operator=(const CurveGFp& other) = default; /** - * Get coefficient a - * @return coefficient a + * @return curve coefficient a */ const BigInt& get_a() const { return a; } /** - * Get coefficient b - * @return coefficient b + * @return curve coefficient b */ const BigInt& get_b() const { return b; } @@ -94,11 +92,14 @@ class BOTAN_DLL CurveGFp */ u32bit get_p_words() const { return p_words; } + /** + * @return modular reducer for p + */ const Modular_Reducer& mod_p() const { return reducer_p; } /** * swaps the states of *this and other, does not throw - * @param other The curve to swap values with + * @param other curve to swap values with */ void swap(CurveGFp& other) { @@ -112,6 +113,11 @@ class BOTAN_DLL CurveGFp std::swap(p_dash, other.p_dash); } + /** + * Equality operator + * @param other curve to compare with + * @return true iff this is the same curve as other + */ bool operator==(const CurveGFp& other) const { return (p == other.p && a == other.a && b == other.b); @@ -130,6 +136,12 @@ class BOTAN_DLL CurveGFp Modular_Reducer reducer_p; }; +/** +* Equality operator +* @param lhs a curve +* @param rhs a curve +* @return true iff lhs is not the same as rhs +*/ inline bool operator!=(const CurveGFp& lhs, const CurveGFp& rhs) { return !(lhs == rhs); diff --git a/src/utils/mem_ops.h b/src/utils/mem_ops.h index 0fcf34ba8..503be90b3 100644 --- a/src/utils/mem_ops.h +++ b/src/utils/mem_ops.h @@ -13,18 +13,47 @@ namespace Botan { -/* -* Memory Manipulation Functions +/** +* Copy memory +* @param out the destination array +* @param in the source array +* @param n the number of elements of in/out */ template<typename T> inline void copy_mem(T* out, const T* in, u32bit n) - { std::memmove(out, in, sizeof(T)*n); } + { + std::memmove(out, in, sizeof(T)*n); + } +/** +* Zeroize memory +* @param ptr a pointer to an array +* @param n the number of Ts pointed to by ptr +*/ template<typename T> inline void clear_mem(T* ptr, u32bit n) - { if(n) std::memset(ptr, 0, sizeof(T)*n); } + { + if(n) // avoid glibc warning if n == 0 + std::memset(ptr, 0, sizeof(T)*n); + } -template<typename T> inline void set_mem(T* ptr, u32bit n, byte val) - { std::memset(ptr, val, sizeof(T)*n); } +/** +* Set memory to a fixed value +* @param ptr a pointer to an array +* @param n the number of Ts pointed to by ptr +* @param val the value to set each byte to +*/ +template<typename T> +inline void set_mem(T* ptr, u32bit n, byte val) + { + std::memset(ptr, val, sizeof(T)*n); + } +/** +* Memory comparison, input insensitive +* @param p1 a pointer to an array +* @param p2 a pointer to another array +* @param n the number of Ts in p1 and p2 +* @return true iff p1[i] == p2[i] forall i in [0...n) +*/ template<typename T> inline bool same_mem(const T* p1, const T* p2, u32bit n) { bool is_same = true; |