]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/rc5/rc5_locl.h
Fix gcc-7 warnings.
[thirdparty/openssl.git] / crypto / rc5 / rc5_locl.h
CommitLineData
2039c421
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
58964a49 3 *
2039c421
RS
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
58964a49
RE
8 */
9
10#include <stdlib.h>
11
12#undef c2l
0f113f3e
MC
13#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
14 l|=((unsigned long)(*((c)++)))<< 8L, \
15 l|=((unsigned long)(*((c)++)))<<16L, \
16 l|=((unsigned long)(*((c)++)))<<24L)
58964a49
RE
17
18/* NOTE - c is not incremented as per c2l */
19#undef c2ln
0f113f3e
MC
20#define c2ln(c,l1,l2,n) { \
21 c+=n; \
22 l1=l2=0; \
23 switch (n) { \
24 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
018fcbec 25 /* fall thru */ \
0f113f3e 26 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
018fcbec 27 /* fall thru */ \
0f113f3e 28 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
018fcbec
BE
29 /* fall thru */ \
30 case 5: l2|=((unsigned long)(*(--(c)))); \
31 /* fall thru */ \
0f113f3e 32 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
018fcbec 33 /* fall thru */ \
0f113f3e 34 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
018fcbec 35 /* fall thru */ \
0f113f3e 36 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
018fcbec
BE
37 /* fall thru */ \
38 case 1: l1|=((unsigned long)(*(--(c)))); \
0f113f3e
MC
39 } \
40 }
58964a49
RE
41
42#undef l2c
0f113f3e
MC
43#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
44 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
45 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
46 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
58964a49
RE
47
48/* NOTE - c is not incremented as per l2c */
49#undef l2cn
0f113f3e
MC
50#define l2cn(l1,l2,c,n) { \
51 c+=n; \
52 switch (n) { \
53 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
018fcbec 54 /* fall thru */ \
0f113f3e 55 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
018fcbec 56 /* fall thru */ \
0f113f3e 57 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
018fcbec 58 /* fall thru */ \
0f113f3e 59 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
018fcbec 60 /* fall thru */ \
0f113f3e 61 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
018fcbec 62 /* fall thru */ \
0f113f3e 63 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
018fcbec 64 /* fall thru */ \
0f113f3e 65 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
018fcbec 66 /* fall thru */ \
0f113f3e
MC
67 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
68 } \
69 }
58964a49
RE
70
71/* NOTE - c is not incremented as per n2l */
0f113f3e
MC
72#define n2ln(c,l1,l2,n) { \
73 c+=n; \
74 l1=l2=0; \
75 switch (n) { \
76 case 8: l2 =((unsigned long)(*(--(c)))) ; \
018fcbec 77 /* fall thru */ \
0f113f3e 78 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
018fcbec 79 /* fall thru */ \
0f113f3e 80 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
018fcbec 81 /* fall thru */ \
0f113f3e 82 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
018fcbec 83 /* fall thru */ \
0f113f3e 84 case 4: l1 =((unsigned long)(*(--(c)))) ; \
018fcbec 85 /* fall thru */ \
0f113f3e 86 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
018fcbec 87 /* fall thru */ \
0f113f3e 88 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
018fcbec 89 /* fall thru */ \
0f113f3e
MC
90 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
91 } \
92 }
58964a49
RE
93
94/* NOTE - c is not incremented as per l2n */
0f113f3e
MC
95#define l2nn(l1,l2,c,n) { \
96 c+=n; \
97 switch (n) { \
98 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
018fcbec 99 /* fall thru */ \
0f113f3e 100 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
018fcbec 101 /* fall thru */ \
0f113f3e 102 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
018fcbec 103 /* fall thru */ \
0f113f3e 104 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
018fcbec 105 /* fall thru */ \
0f113f3e 106 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
018fcbec 107 /* fall thru */ \
0f113f3e 108 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
018fcbec 109 /* fall thru */ \
0f113f3e 110 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
018fcbec 111 /* fall thru */ \
0f113f3e
MC
112 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
113 } \
114 }
58964a49
RE
115
116#undef n2l
117#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
118 l|=((unsigned long)(*((c)++)))<<16L, \
119 l|=((unsigned long)(*((c)++)))<< 8L, \
120 l|=((unsigned long)(*((c)++))))
121
122#undef l2n
123#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
124 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
125 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
126 *((c)++)=(unsigned char)(((l) )&0xff))
127
cf5ecc3e 128#if (defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER))
0f113f3e
MC
129# define ROTATE_l32(a,n) _lrotl(a,n)
130# define ROTATE_r32(a,n) _lrotr(a,n)
cf5ecc3e 131#elif defined(__ICC)
0f113f3e
MC
132# define ROTATE_l32(a,n) _rotl(a,n)
133# define ROTATE_r32(a,n) _rotr(a,n)
85982899 134#elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
2f98abbc 135# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
0f113f3e
MC
136# define ROTATE_l32(a,n) ({ register unsigned int ret; \
137 asm ("roll %%cl,%0" \
138 : "=r"(ret) \
139 : "c"(n),"0"((unsigned int)(a)) \
140 : "cc"); \
141 ret; \
142 })
143# define ROTATE_r32(a,n) ({ register unsigned int ret; \
144 asm ("rorl %%cl,%0" \
145 : "=r"(ret) \
146 : "c"(n),"0"((unsigned int)(a)) \
147 : "cc"); \
148 ret; \
149 })
2f98abbc 150# endif
6be4688b
AP
151#endif
152#ifndef ROTATE_l32
35ade23b 153# define ROTATE_l32(a,n) (((a)<<(n&0x1f))|(((a)&0xffffffff)>>((32-n)&0x1f)))
6be4688b
AP
154#endif
155#ifndef ROTATE_r32
35ade23b 156# define ROTATE_r32(a,n) (((a)<<((32-n)&0x1f))|(((a)&0xffffffff)>>(n&0x1f)))
58964a49
RE
157#endif
158
0f113f3e 159#define RC5_32_MASK 0xffffffffL
58964a49 160
0f113f3e
MC
161#define RC5_16_P 0xB7E1
162#define RC5_16_Q 0x9E37
163#define RC5_32_P 0xB7E15163L
164#define RC5_32_Q 0x9E3779B9L
165#define RC5_64_P 0xB7E151628AED2A6BLL
166#define RC5_64_Q 0x9E3779B97F4A7C15LL
58964a49
RE
167
168#define E_RC5_32(a,b,s,n) \
0f113f3e
MC
169 a^=b; \
170 a=ROTATE_l32(a,b); \
171 a+=s[n]; \
172 a&=RC5_32_MASK; \
173 b^=a; \
174 b=ROTATE_l32(b,a); \
175 b+=s[n+1]; \
176 b&=RC5_32_MASK;
58964a49
RE
177
178#define D_RC5_32(a,b,s,n) \
0f113f3e
MC
179 b-=s[n+1]; \
180 b&=RC5_32_MASK; \
181 b=ROTATE_r32(b,a); \
182 b^=a; \
183 a-=s[n]; \
184 a&=RC5_32_MASK; \
185 a=ROTATE_r32(a,b); \
186 a^=b;