00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FXSECURE_H
00023 #define FXSECURE_H
00024
00025 #include "FXStream.h"
00026 #include "FXString.h"
00027 #include <string.h>
00028 #include <stdlib.h>
00029 #include <new>
00030
00031 namespace FX {
00032
00036 namespace Secure { struct heap { }; }
00037 }
00038
00039 #if defined(_MSC_VER) && _MSC_VER<=1310
00040 #pragma warning(push)
00041 #pragma warning(disable: 4290)
00042 #endif
00043
00045 FXAPI void *operator new(size_t size, const FX::Secure::heap &) throw(std::bad_alloc);
00048 FXAPI void *operator new[](size_t size, const FX::Secure::heap &) throw(std::bad_alloc);
00051 FXAPI void operator delete(void *p, const FX::Secure::heap &) throw();
00054 FXAPI void operator delete[](void *p, const FX::Secure::heap &) throw();
00055 #if defined(_MSC_VER) && _MSC_VER<=1310
00056 #pragma warning(pop)
00057 #endif
00058
00059 namespace FX {
00064 namespace Secure
00065 {
00066 extern FXAPI void *mallocI(size_t size) throw();
00067 extern FXAPI void *callocI(size_t no, size_t size) throw();
00068 extern FXAPI void free(void *p) throw();
00071 template<typename T> T *malloc(size_t size) throw() { return (T *) mallocI(size); }
00074 template<typename T> T *calloc(size_t no, size_t size) throw() { return (T *) callocI(no, size); }
00077 template<typename T> void free(T *p) throw() { free((void *) p); }
00078
00085 struct TigerHashValue
00086 {
00088 union Data_t
00089 {
00090 FXuchar bytes[24];
00091 FXulong longlong[3];
00092 } data;
00093 ~TigerHashValue()
00094 {
00095 ::memset(data.bytes, 0, sizeof(data));
00096 }
00098 FXString asString() const
00099 {
00100 #if FOX_BIGENDIAN==1
00101 FXString ret("0x%1%2%3");
00102 #else
00103 FXString ret("0x%3%2%1");
00104 #endif
00105 return ret.arg(data.longlong[0]).arg(data.longlong[1]).arg(data.longlong[2]);
00106 }
00107 bool operator==(const TigerHashValue &o) const throw() { return data.longlong[0]==o.data.longlong[0]
00108 && data.longlong[1]==o.data.longlong[1]
00109 && data.longlong[2]==o.data.longlong[2]; }
00110 bool operator!=(const TigerHashValue &o) const throw() { return !(*this==o); }
00111 friend FXStream &operator<<(FXStream &s, const TigerHashValue &v) { s.writeRawBytes(v.data.bytes, 24); return s; }
00112 friend FXStream &operator>>(FXStream &s, TigerHashValue &v) { s.readRawBytes(v.data.bytes, 24); return s; }
00113 };
00114
00159 class FXAPI Randomness
00160 {
00161 Randomness();
00162 Randomness(const Randomness &);
00163 Randomness &operator=(const Randomness &);
00164 public:
00168 static FXuval readBlock(FXuchar *buffer, FXuval length);
00170 static FXuval size();
00171 };
00185 class FXAPI PRandomness
00186 {
00187 PRandomness();
00188 PRandomness(const PRandomness &);
00189 PRandomness &operator=(const PRandomness &);
00190 public:
00194 static FXuval readBlock(FXuchar *buffer, FXuval length);
00196 static void freshen(FXuval amount);
00198 static FXuval size() { return (FXuval)-1; }
00199 };
00200
00224 class FXAPI TigerHash
00225 {
00226 FXuint mypasses;
00227 public:
00229 TigerHash(FXuint passes=3) : mypasses(passes) { }
00231 FXuint passes() const throw() { return mypasses; }
00233 void setPasses(FXuint passes) throw() { mypasses=passes; }
00235 TigerHashValue calc(FXuchar *buffer, FXuval length) const throw();
00236 };
00237
00238 }
00239 }
00240 #endif
00241