X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Faddon%2Fmd5.hpp;h=2f441e012983ed70a0868483230704cac83a2630;hb=24fc5a4c6959f07a6925dd2ab1af3da7fd982007;hp=f6aa930d0a0da2e0d58b489cc2fec5c371f3fd39;hpb=79f870896e74b27bd093dca36b90e5ea3182ce92;p=supertux.git diff --git a/src/addon/md5.hpp b/src/addon/md5.hpp index f6aa930d0..2f441e012 100644 --- a/src/addon/md5.hpp +++ b/src/addon/md5.hpp @@ -41,59 +41,58 @@ // documentation and/or software. // -#ifndef SUPERTUX_ADDON_MD5_HPP -#define SUPERTUX_ADDON_MD5_HPP +#ifndef HEADER_SUPERTUX_ADDON_MD5_HPP +#define HEADER_SUPERTUX_ADDON_MD5_HPP -#include #include -#include #include -#include -class MD5 { +class MD5 +{ +public: + MD5(); + MD5(uint8_t* string); /**< digest string, finalize */ + MD5(std::istream& stream); /**< digest stream, finalize */ + MD5(FILE *file); /**< digest file, close, finalize */ + MD5(std::ifstream& stream); /**< digest stream, close, finalize */ - public: - MD5(); - MD5(uint8_t* string); /**< digest string, finalize */ - MD5(std::istream& stream); /**< digest stream, finalize */ - MD5(FILE *file); /**< digest file, close, finalize */ - MD5(std::ifstream& stream); /**< digest stream, close, finalize */ + void update(uint8_t* input, unsigned int input_length); /**< MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ + void update(std::istream& stream); + void update(FILE *file); + void update(std::ifstream& stream); - void update(uint8_t* input, unsigned int input_length); /**< MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ - void update(std::istream& stream); - void update(FILE *file); - void update(std::ifstream& stream); + uint8_t* raw_digest(); /**< digest as a 16-byte binary array */ + std::string hex_digest(); /**< digest as a 33-byte ascii-hex string */ + friend std::ostream& operator<<(std::ostream&, MD5 context); - uint8_t* raw_digest(); /**< digest as a 16-byte binary array */ - std::string hex_digest(); /**< digest as a 33-byte ascii-hex string */ - friend std::ostream& operator<<(std::ostream&, MD5 context); +private: + uint32_t state[4]; + uint32_t count[2]; /**< number of _bits_, mod 2^64 */ + uint8_t buffer[64]; /**< input buffer */ + uint8_t digest[16]; + bool finalized; - private: - uint32_t state[4]; - uint32_t count[2]; /**< number of _bits_, mod 2^64 */ - uint8_t buffer[64]; /**< input buffer */ - uint8_t digest[16]; - bool finalized; + void init(); /**< called by all constructors */ + void finalize(); /**< MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the context. */ + void transform(uint8_t* buffer); /**< MD5 basic transformation. Transforms state based on block. Does the real update work. Note that length is implied to be 64. */ - void init(); /**< called by all constructors */ - void finalize(); /**< MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the context. */ - void transform(uint8_t* buffer); /**< MD5 basic transformation. Transforms state based on block. Does the real update work. Note that length is implied to be 64. */ + static void encode(uint8_t* dest, uint32_t* src, uint32_t length); /**< Encodes input (uint32_t) into output (uint8_t). Assumes len is a multiple of 4. */ + static void decode(uint32_t* dest, uint8_t* src, uint32_t length); /**< Decodes input (uint8_t) into output (uint32_t). Assumes len is a multiple of 4. */ + static void memcpy(uint8_t* dest, uint8_t* src, uint32_t length); + static void memset(uint8_t* start, uint8_t val, uint32_t length); - static void encode(uint8_t* dest, uint32_t* src, uint32_t length); /**< Encodes input (uint32_t) into output (uint8_t). Assumes len is a multiple of 4. */ - static void decode(uint32_t* dest, uint8_t* src, uint32_t length); /**< Decodes input (uint8_t) into output (uint32_t). Assumes len is a multiple of 4. */ - static void memcpy(uint8_t* dest, uint8_t* src, uint32_t length); - static void memset(uint8_t* start, uint8_t val, uint32_t length); - - static inline uint32_t rotate_left(uint32_t x, uint32_t n); - static inline uint32_t F(uint32_t x, uint32_t y, uint32_t z); //*< F, G, H and I are basic MD5 functions. */ - static inline uint32_t G(uint32_t x, uint32_t y, uint32_t z); - static inline uint32_t H(uint32_t x, uint32_t y, uint32_t z); - static inline uint32_t I(uint32_t x, uint32_t y, uint32_t z); - static inline void FF(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac); /**< FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent recomputation. */ - static inline void GG(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac); - static inline void HH(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac); - static inline void II(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac); + static inline uint32_t rotate_left(uint32_t x, uint32_t n); + static inline uint32_t F(uint32_t x, uint32_t y, uint32_t z); //*< F, G, H and I are basic MD5 functions. */ + static inline uint32_t G(uint32_t x, uint32_t y, uint32_t z); + static inline uint32_t H(uint32_t x, uint32_t y, uint32_t z); + static inline uint32_t I(uint32_t x, uint32_t y, uint32_t z); + static inline void FF(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac); /**< FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent recomputation. */ + static inline void GG(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac); + static inline void HH(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac); + static inline void II(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac); }; #endif /*SUPERTUX_ADDON_MD5_HPP*/ + +/* EOF */