00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BOTAN_MEMORY_OPS_H__
00009 #define BOTAN_MEMORY_OPS_H__
00010
00011 #include <botan/types.h>
00012 #include <cstring>
00013
00014 namespace Botan {
00015
00016
00017
00018
00019
00020
00021
00022 template<typename T> inline void copy_mem(T* out, const T* in, u32bit n)
00023 {
00024 std::memmove(out, in, sizeof(T)*n);
00025 }
00026
00027
00028
00029
00030
00031
00032 template<typename T> inline void clear_mem(T* ptr, u32bit n)
00033 {
00034 if(n)
00035 std::memset(ptr, 0, sizeof(T)*n);
00036 }
00037
00038
00039
00040
00041
00042
00043
00044 template<typename T>
00045 inline void set_mem(T* ptr, u32bit n, byte val)
00046 {
00047 std::memset(ptr, val, sizeof(T)*n);
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057 template<typename T> inline bool same_mem(const T* p1, const T* p2, u32bit n)
00058 {
00059 bool is_same = true;
00060
00061 for(u32bit i = 0; i != n; ++i)
00062 is_same &= (p1[i] == p2[i]);
00063
00064 return is_same;
00065 }
00066
00067 }
00068
00069 #endif