aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 23:59:53 +0000
committerlloyd <[email protected]>2008-09-28 23:59:53 +0000
commit45c4fcfce66d894dda6b1d29a92fa47515b944af (patch)
tree75b96e2003588308e098d8b4a8dfcc4f89df9780 /include
parentc14cca7ef7338de3a8da784dd0865634b4110539 (diff)
More headers (loadstore, mem_ops, rotate, types) for util module
Diffstat (limited to 'include')
-rw-r--r--include/loadstor.h279
-rw-r--r--include/mem_ops.h31
-rw-r--r--include/rotate.h28
-rw-r--r--include/types.h38
4 files changed, 0 insertions, 376 deletions
diff --git a/include/loadstor.h b/include/loadstor.h
deleted file mode 100644
index 0bcafe411..000000000
--- a/include/loadstor.h
+++ /dev/null
@@ -1,279 +0,0 @@
-/*************************************************
-* Load/Store Operators Header File *
-* (C) 1999-2007 Jack Lloyd *
-* 2007 Yves Jerschow *
-*************************************************/
-
-#ifndef BOTAN_LOAD_STORE_H__
-#define BOTAN_LOAD_STORE_H__
-
-#include <botan/types.h>
-#include <botan/bswap.h>
-#include <botan/rotate.h>
-
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
-
-#if defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN)
-
-#define BOTAN_ENDIAN_N2B(x) (x)
-#define BOTAN_ENDIAN_B2N(x) (x)
-
-#define BOTAN_ENDIAN_N2L(x) reverse_bytes(x)
-#define BOTAN_ENDIAN_L2N(x) reverse_bytes(x)
-
-#elif defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN)
-
-#define BOTAN_ENDIAN_N2L(x) (x)
-#define BOTAN_ENDIAN_L2N(x) (x)
-
-#define BOTAN_ENDIAN_N2B(x) reverse_bytes(x)
-#define BOTAN_ENDIAN_B2N(x) reverse_bytes(x)
-
-#endif
-
-#endif
-
-namespace Botan {
-
-/*************************************************
-* Byte Extraction Function *
-*************************************************/
-template<typename T> inline byte get_byte(u32bit byte_num, T input)
- {
- return (input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3));
- }
-
-/*************************************************
-* Byte to Word Conversions *
-*************************************************/
-inline u16bit make_u16bit(byte i0, byte i1)
- {
- return ((static_cast<u16bit>(i0) << 8) | i1);
- }
-
-inline u32bit make_u32bit(byte i0, byte i1, byte i2, byte i3)
- {
- return ((static_cast<u32bit>(i0) << 24) |
- (static_cast<u32bit>(i1) << 16) |
- (static_cast<u32bit>(i2) << 8) |
- (static_cast<u32bit>(i3)));
- }
-
-inline u64bit make_u64bit(byte i0, byte i1, byte i2, byte i3,
- byte i4, byte i5, byte i6, byte i7)
- {
- return ((static_cast<u64bit>(i0) << 56) |
- (static_cast<u64bit>(i1) << 48) |
- (static_cast<u64bit>(i2) << 40) |
- (static_cast<u64bit>(i3) << 32) |
- (static_cast<u64bit>(i4) << 24) |
- (static_cast<u64bit>(i5) << 16) |
- (static_cast<u64bit>(i6) << 8) |
- (static_cast<u64bit>(i7)));
- }
-
-/*************************************************
-* Endian-Specific Word Loading Operations *
-*************************************************/
-template<typename T>
-inline T load_be(const byte in[], u32bit off)
- {
- in += off * sizeof(T);
- T out = 0;
- for(u32bit j = 0; j != sizeof(T); j++)
- out = (out << 8) | in[j];
- return out;
- }
-
-template<typename T>
-inline T load_le(const byte in[], u32bit off)
- {
- in += off * sizeof(T);
- T out = 0;
- for(u32bit j = 0; j != sizeof(T); j++)
- out = (out << 8) | in[sizeof(T)-1-j];
- return out;
- }
-
-template<>
-inline u16bit load_be<u16bit>(const byte in[], u32bit off)
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- return BOTAN_ENDIAN_N2B(*(reinterpret_cast<const u16bit*>(in) + off));
-#else
- in += off * sizeof(u16bit);
- return make_u16bit(in[0], in[1]);
-#endif
- }
-
-template<>
-inline u16bit load_le<u16bit>(const byte in[], u32bit off)
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- return BOTAN_ENDIAN_N2L(*(reinterpret_cast<const u16bit*>(in) + off));
-#else
- in += off * sizeof(u16bit);
- return make_u16bit(in[1], in[0]);
-#endif
- }
-
-template<>
-inline u32bit load_be<u32bit>(const byte in[], u32bit off)
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- return BOTAN_ENDIAN_N2B(*(reinterpret_cast<const u32bit*>(in) + off));
-#else
- in += off * sizeof(u32bit);
- return make_u32bit(in[0], in[1], in[2], in[3]);
-#endif
- }
-
-template<>
-inline u32bit load_le<u32bit>(const byte in[], u32bit off)
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- return BOTAN_ENDIAN_N2L(*(reinterpret_cast<const u32bit*>(in) + off));
-#else
- in += off * sizeof(u32bit);
- return make_u32bit(in[3], in[2], in[1], in[0]);
-#endif
- }
-
-template<>
-inline u64bit load_be<u64bit>(const byte in[], u32bit off)
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- return BOTAN_ENDIAN_N2B(*(reinterpret_cast<const u64bit*>(in) + off));
-#else
- in += off * sizeof(u64bit);
- return make_u64bit(in[0], in[1], in[2], in[3],
- in[4], in[5], in[6], in[7]);
-#endif
- }
-
-template<>
-inline u64bit load_le<u64bit>(const byte in[], u32bit off)
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- return BOTAN_ENDIAN_N2L(*(reinterpret_cast<const u64bit*>(in) + off));
-#else
- in += off * sizeof(u64bit);
- return make_u64bit(in[7], in[6], in[5], in[4],
- in[3], in[2], in[1], in[0]);
-#endif
- }
-
-/*************************************************
-* Endian-Specific Word Storing Operations *
-*************************************************/
-inline void store_be(u16bit in, byte out[2])
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- *reinterpret_cast<u16bit*>(out) = BOTAN_ENDIAN_B2N(in);
-#else
- out[0] = get_byte(0, in);
- out[1] = get_byte(1, in);
-#endif
- }
-
-inline void store_le(u16bit in, byte out[2])
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- *reinterpret_cast<u16bit*>(out) = BOTAN_ENDIAN_L2N(in);
-#else
- out[0] = get_byte(1, in);
- out[1] = get_byte(0, in);
-#endif
- }
-
-inline void store_be(u32bit in, byte out[4])
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- *reinterpret_cast<u32bit*>(out) = BOTAN_ENDIAN_B2N(in);
-#else
- out[0] = get_byte(0, in);
- out[1] = get_byte(1, in);
- out[2] = get_byte(2, in);
- out[3] = get_byte(3, in);
-#endif
- }
-
-inline void store_le(u32bit in, byte out[4])
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- *reinterpret_cast<u32bit*>(out) = BOTAN_ENDIAN_L2N(in);
-#else
- out[0] = get_byte(3, in);
- out[1] = get_byte(2, in);
- out[2] = get_byte(1, in);
- out[3] = get_byte(0, in);
-#endif
- }
-
-inline void store_be(u64bit in, byte out[8])
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- *reinterpret_cast<u64bit*>(out) = BOTAN_ENDIAN_B2N(in);
-#else
- out[0] = get_byte(0, in);
- out[1] = get_byte(1, in);
- out[2] = get_byte(2, in);
- out[3] = get_byte(3, in);
- out[4] = get_byte(4, in);
- out[5] = get_byte(5, in);
- out[6] = get_byte(6, in);
- out[7] = get_byte(7, in);
-#endif
- }
-
-inline void store_le(u64bit in, byte out[8])
- {
-#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
- *reinterpret_cast<u64bit*>(out) = BOTAN_ENDIAN_L2N(in);
-#else
- out[0] = get_byte(7, in);
- out[1] = get_byte(6, in);
- out[2] = get_byte(5, in);
- out[3] = get_byte(4, in);
- out[4] = get_byte(3, in);
- out[5] = get_byte(2, in);
- out[6] = get_byte(1, in);
- out[7] = get_byte(0, in);
-#endif
- }
-
-template<typename T>
-inline void store_le(byte out[], T a, T b)
- {
- store_le(a, out + (0 * sizeof(T)));
- store_le(b, out + (1 * sizeof(T)));
- }
-
-template<typename T>
-inline void store_be(byte out[], T a, T b)
- {
- store_be(a, out + (0 * sizeof(T)));
- store_be(b, out + (1 * sizeof(T)));
- }
-
-template<typename T>
-inline void store_le(byte out[], T a, T b, T c, T d)
- {
- store_le(a, out + (0 * sizeof(T)));
- store_le(b, out + (1 * sizeof(T)));
- store_le(c, out + (2 * sizeof(T)));
- store_le(d, out + (3 * sizeof(T)));
- }
-
-template<typename T>
-inline void store_be(byte out[], T a, T b, T c, T d)
- {
- store_be(a, out + (0 * sizeof(T)));
- store_be(b, out + (1 * sizeof(T)));
- store_be(c, out + (2 * sizeof(T)));
- store_be(d, out + (3 * sizeof(T)));
- }
-
-}
-
-#endif
diff --git a/include/mem_ops.h b/include/mem_ops.h
deleted file mode 100644
index 810356bce..000000000
--- a/include/mem_ops.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*************************************************
-* Memory Operations Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
-
-#ifndef BOTAN_MEMORY_OPS_H__
-#define BOTAN_MEMORY_OPS_H__
-
-#include <botan/types.h>
-#include <cstring>
-
-namespace Botan {
-
-/*************************************************
-* Memory Manipulation Functions *
-*************************************************/
-template<typename T> inline void copy_mem(T* out, const T* in, u32bit n)
- { std::memmove(out, in, sizeof(T)*n); }
-
-template<typename T> inline void clear_mem(T* ptr, u32bit n)
- { 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); }
-
-template<typename T> inline bool same_mem(const T* p1, const T* p2, u32bit n)
- { return (std::memcmp(p1, p2, sizeof(T)*n) == 0); }
-
-}
-
-#endif
diff --git a/include/rotate.h b/include/rotate.h
deleted file mode 100644
index d90e207b5..000000000
--- a/include/rotate.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*************************************************
-* Word Rotation Operations Header File *
-* (C) 1999-2008 Jack Lloyd *
-*************************************************/
-
-#ifndef BOTAN_WORD_ROTATE_H__
-#define BOTAN_WORD_ROTATE_H__
-
-#include <botan/types.h>
-
-namespace Botan {
-
-/*************************************************
-* Word Rotation Functions *
-*************************************************/
-template<typename T> inline T rotate_left(T input, u32bit rot)
- {
- return static_cast<T>((input << rot) | (input >> (8*sizeof(T)-rot)));;
- }
-
-template<typename T> inline T rotate_right(T input, u32bit rot)
- {
- return static_cast<T>((input >> rot) | (input << (8*sizeof(T)-rot)));
- }
-
-}
-
-#endif
diff --git a/include/types.h b/include/types.h
deleted file mode 100644
index 49d1a3c4c..000000000
--- a/include/types.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*************************************************
-* Low Level Types Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
-
-#ifndef BOTAN_TYPES_H__
-#define BOTAN_TYPES_H__
-
-#include <botan/build.h>
-
-namespace Botan {
-
-typedef unsigned char byte;
-typedef unsigned short u16bit;
-typedef unsigned int u32bit;
-
-typedef signed int s32bit;
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
- typedef unsigned __int64 u64bit;
-#elif defined(__KCC)
- typedef unsigned __long_long u64bit;
-#elif defined(__GNUG__)
- __extension__ typedef unsigned long long u64bit;
-#else
- typedef unsigned long long u64bit;
-#endif
-
-}
-
-namespace Botan_types {
-
-using Botan::byte;
-using Botan::u32bit;
-
-}
-
-#endif