ZeusBase-Library  2.0.4
SecurityDefines.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch)
3  *****************************************************************************
4  * Project : Zeus Base Library
5  * Module : SecurityDefines
6  * Package : Zeus.ZeusBase.Security
7  * Author : Benjamin Hadorn
8  * Date : 27.12.2011
9  * System : Zeus-Framework
10  *****************************************************************************
11  * Licence: *
12  * This library is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU Lesser General Public License as *
14  * published by the Free Software Foundation; either version *
15  * 2.1 of the License, or (at your option) any later version. *
16  * *
17  * This library is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU Lesser General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU Lesser General Public *
23  * License along with this library; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
25  *****************************************************************************/
26 
27 /*****************************************************************************
28  * Changes:
29  * 27.12.2011 bha: created zeus 2.0
30  *****************************************************************************/
31 
32 #ifndef SecurityDefinesHPP
33 #define SecurityDefinesHPP
34 
35 /**********************************************************************/
38 /**********************************************************************/
40 {
41  etSimpleDES = 0, // Simple DES (not secure, just for demonstration purposes)
42  etXTEA = 1 // eXtended Tiny Encryption Algorithm (pretty secure)
43 };
44 
45 
46 #define SHFR(x, n) (x >> n)
47 #define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
48 #define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n)))
49 #define CH(x, y, z) ((x & y) ^ (~x & z))
50 #define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
51 
52 //Packs 4 bytes into a 32bit value
53 // [0][1][2][3] where as [3] represents the lowest 8 bits
54 #define PACK32(str, x)\
55  { \
56  *(x) = ((Uint32) *((str) + 3)) | \
57  ((Uint32) *((str) + 2) << 8) | \
58  ((Uint32) *((str) + 1) << 16) | \
59  ((Uint32) *((str) + 0) << 24); \
60  }
61 
62 //Unpacks a 32bit value into 4 bytes
63 // [0][1][2][3] where as [3] represents the lowest 8 bits
64 #define UNPACK32(x, str) \
65  { \
66  *((str) + 3) = (Uint8) ((x)); \
67  *((str) + 2) = (Uint8) ((x) >> 8); \
68  *((str) + 1) = (Uint8) ((x) >> 16); \
69  *((str) + 0) = (Uint8) ((x) >> 24); \
70  }
71 
72 //Packs 8 bytes into a 64bit value
73 // [0][1][2][3][4][5][6][7] where as [7] represents the lowest 8 bits
74 #define PACK64(str, x) \
75  { \
76  *(x) = ((Uint64) *((str) + 7) ) | \
77  ((Uint64) *((str) + 6) << 8) | \
78  ((Uint64) *((str) + 5) << 16) | \
79  ((Uint64) *((str) + 4) << 24) | \
80  ((Uint64) *((str) + 3) << 32) | \
81  ((Uint64) *((str) + 2) << 40) | \
82  ((Uint64) *((str) + 1) << 48) | \
83  ((Uint64) *((str) + 0) << 56); \
84  }
85 
86 //Unpacks a 64bit value into 8 bytes
87 // [0][1][2][3][4][5][6][7] where as [7] represents the lowest 8 bits
88 #define UNPACK64(x, str) \
89  { \
90  *((str) + 7) = (Uint8) ((x)); \
91  *((str) + 6) = (Uint8) ((x) >> 8); \
92  *((str) + 5) = (Uint8) ((x) >> 16); \
93  *((str) + 4) = (Uint8) ((x) >> 24); \
94  *((str) + 3) = (Uint8) ((x) >> 32); \
95  *((str) + 2) = (Uint8) ((x) >> 40); \
96  *((str) + 1) = (Uint8) ((x) >> 48); \
97  *((str) + 0) = (Uint8) ((x) >> 56); \
98  }
99 
100 
101 
102 #if defined(ZEUS_LITTLE_ENDIAN)
103 
104  #ifndef HOST_c2l
105  #define HOST_c2l(c,l) (\
106  l =(((Uint32)(*((c)++))) ), \
107  l|=(((Uint32)(*((c)++)))<< 8), \
108  l|=(((Uint32)(*((c)++)))<<16), \
109  l|=(((Uint32)(*((c)++)))<<24), \
110  l)
111  #endif
112  #ifndef HOST_l2c
113  #define HOST_l2c(l,c) (\
114  *((c)++)=(Uint8)(((l) )&0xff), \
115  *((c)++)=(Uint8)(((l)>> 8)&0xff), \
116  *((c)++)=(Uint8)(((l)>>16)&0xff), \
117  *((c)++)=(Uint8)(((l)>>24)&0xff), \
118  l)
119  #endif
120 
121 #else //defined(ZEUS_BIG_ENDIAN)
122  #ifndef HOST_c2l
123  #define HOST_c2l(c,l) (\
124  l =(((Uint32)(*((c)++)))<<24), \
125  l|=(((Uint32)(*((c)++)))<<16), \
126  l|=(((Uint32)(*((c)++)))<< 8), \
127  l|=(((Uint32)(*((c)++))) ), \
128  l)
129  #endif
130 
131  #ifndef HOST_l2c
132  #define HOST_l2c(l,c) (\
133  *((c)++)=(Uint8)(((l)>>24)&0xff), \
134  *((c)++)=(Uint8)(((l)>>16)&0xff), \
135  *((c)++)=(Uint8)(((l)>> 8)&0xff), \
136  *((c)++)=(Uint8)(((l) )&0xff), \
137  l)
138  #endif
139 #endif //defined(ZEUS_BIG_ENDIAN)
140 
141 
142 //Swaps the bytes for big endian systems
143 #ifdef ZEUS_BIG_ENDIAN
144  #define SWAP(n) (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
145 #else
146  #define SWAP(n) (n)
147 #endif
148 
149 #endif
Definition: SecurityDefines.hpp:41
ECryptType
Definition: SecurityDefines.hpp:39
Definition: SecurityDefines.hpp:42


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Tue Sep 13 2016 22:30:49