aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/bitsliced-tea/bstea.h
blob: 15607464eb5ae159415f085cb28cd88a0828bfce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef __BSTEA_H
#define __BSTEA_H

#include <stdint.h>
#include <limits.h>

#include "bstea_wordsize.h"

#define TERNARY(x, v1, v0) ((x) ? (v1) : (v0))

#define TEA_ROUNDS      32

#define TEA_BLOCK_SIZE  64
#define TEA_KEY_SIZE    128

#if __BSTEA_WORDSIZE == 64
typedef uint64_t vector_width_t;  /* 64-way bit-level vectorization */
#define VECTOR_AT_ONE	0xffffffffffffffff
#define VECTOR_AT_ZERO	0x0000000000000000
#elif __BSTEA_WORDSIZE == 32
typedef uint32_t vector_width_t;  /* 32-way bit-level vectorization */
#define VECTOR_AT_ONE	0xffffffff
#define VECTOR_AT_ZERO	0x00000000
#elif __BSTEA_WORDSIZE == 16
typedef uint32_t vector_width_t;  /* 16-way bit-level vectorization */
#define VECTOR_AT_ONE	0xffff
#define VECTOR_AT_ZERO	0x0000
#elif __BSTEA_WORDSIZE == 8
typedef uint32_t vector_width_t;  /* 8-way bit-level vectorization */
#define VECTOR_AT_ONE	0xff
#define VECTOR_AT_ZERO	0x00
#else 
typedef unsigned long int vector_width_t;  /* word-way bit-level vectorization */
#define VECTOR_AT_ONE	ULONG_MAX
#define VECTOR_AT_ZERO	0
#endif


typedef vector_width_t parallel_blocks_t[TEA_BLOCK_SIZE];
typedef vector_width_t parallel_keys_t[TEA_KEY_SIZE];


/* __P is a macro used to wrap function prototypes, so that compilers
   that don't understand ANSI C prototypes still work, and ANSI C
   compilers can issue warnings about type mismatches. */
#undef __P
#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus)
 # define __P(protos)    protos
#else
 # define __P(protos)    ()
#endif


/* __BEGIN_DECLS should be used at the beginning of your declarations,
   so that C++ compilers don't mangle their names.  Use __END_DECLS at
   the end of C declarations. */
#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif

/* The following definitions for FAR are needed only for MSDOS mixed
 * model programming (small or medium model with some far allocations).
 * This was tested only with MSC. If you don't need the mixed model,
 * just define FAR to be empty.
 */
#ifdef SYS16BIT
#  if defined(M_I86SM) || defined(M_I86MM)
     /* MSC small or medium model */
#    define SMALL_MEDIUM
#    ifdef _MSC_VER
#      define FAR _far
#    else
#      define FAR far
#    endif
#  endif
#  if (defined(__SMALL__) || defined(__MEDIUM__))
     /* Turbo C small or medium model */
#    define SMALL_MEDIUM
#    ifdef __BORLANDC__
#      define FAR _far
#    else
#      define FAR far
#    endif
#  endif
#endif


#if defined(WINDOWS) || defined(WIN32)
#  ifdef BSTEA_DLL
#    if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
#      ifdef BSTEA_INTERNAL
#        define BSTEA_EXTERN extern __declspec(dllexport)
#      else
#        define BSTEA_EXTERN extern __declspec(dllimport)
#      endif
#    endif
#  endif  /* BSTEA_DLL */

   /* If building or using bstea with the WINAPI/WINAPIV calling convention,
    * define BSTEA_WINAPI.
    * Caution: the standard BSTEA.DLL is NOT compiled using BSTEA_WINAPI.
    */
#  ifdef BSTEA_WINAPI
#    ifdef FAR
#      undef FAR
#    endif
#    include <windows.h>
     /* No need for _export, use BSTEA_LIB.DEF instead. */
     /* For complete Windows compatibility, use WINAPI, not __stdcall. */
#    define BSTEA_EXPORT WINAPI
#    ifdef WIN32
#      define BSTEA_EXPORTVA WINAPIV
#    else
#      define BSTEA_EXPORTVA FAR CDECL
#    endif
#  endif

#else
# include <stdbool.h>
#endif

#ifndef BSTEA_EXTERN
#  define BSTEA_EXTERN extern
#endif
#ifndef BSTEA_EXPORT
#  define BSTEA_EXPORT
#endif
#ifndef BSTEA_EXPORTVA
#  define BSTEA_EXPORTVA
#endif

#ifndef FAR
# define FAR
#endif

__BEGIN_DECLS

BSTEA_EXTERN  void encrypt __P((parallel_blocks_t, const parallel_keys_t, unsigned int));
BSTEA_EXTERN  void decrypt __P((parallel_blocks_t, const parallel_keys_t, unsigned int));

__END_DECLS

#endif /* __BSTEA_H */