You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

76 lines
2.1 KiB

/* This file was modified for the NiklasRosenstein C++ library and namespace. */
/*
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
* MD5 Message-Digest Algorithm (RFC 1321).
*
* Homepage:
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
*
* Author:
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
*
* This software was written by Alexander Peslyak in 2001. No copyright is
* claimed, and the software is hereby placed in the public domain.
* In case this attempt to disclaim copyright and place the software in the
* public domain is deemed null and void, then the software is
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
* general public under the following terms:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*
* See md5.c for more information.
*/
#pragma once
#include <cstdint>
#include <cstring>
#include <string>
#include "string.hpp"
namespace niklasrosenstein {
typedef uint32_t md5_uint32;
struct md5 {
public: /* Data members */
md5_uint32 lo, hi;
md5_uint32 a, b, c, d;
unsigned char buffer[64];
md5_uint32 block[16];
public: /* Methods */
md5();
md5(char const* str) : md5() { update(str); }
md5(void const* data, size_t size) : md5() { update(data, size); }
void update(char const* str) { update(str, strlen(str)); }
void update(void const* data, size_t size);
void digest(char* buffer);
std::string digest() { std::string r(16, 0); digest(&r[0]); return r; }
void hexdigest(char* buffer) { char dbuf[16]; digest(dbuf); tohex(buffer, dbuf, 16); }
std::string hexdigest() { std::string r(32, 0); hexdigest(&r[0]); return r; }
private:
void const* body(void const* data, size_t size);
};
} // namespace niklasrosenstein
#include "md5_impl.cpp"
// Undo all the defines from the implementation file.
#undef F
#undef G
#undef H
#undef H2
#undef I
#undef STEP
#undef SET
#undef GET
#undef OUT