Tomato 1.26
[tomato.git] / release / src / router / matrixssl / src / crypto / peersec / pscrypto.h
blob43a9666648f738041cedbb2247aab49f99b8fab8
1 /*
2 * pscrypto.h
3 * Release $Name: MATRIXSSL_1_8_8_OPEN $
5 * Internal definitions for PeerSec Networks MatrixSSL cryptography provider
6 */
7 /*
8 * Copyright (c) PeerSec Networks, 2002-2009. All Rights Reserved.
9 * The latest version of this code is available at http://www.matrixssl.org
11 * This software is open source; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This General Public License does NOT permit incorporating this software
17 * into proprietary programs. If you are unable to comply with the GPL, a
18 * commercial license for this software may be purchased from PeerSec Networks
19 * at http://www.peersec.com
21 * This program is distributed in WITHOUT ANY WARRANTY; without even the
22 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * See the GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * http://www.gnu.org/copyleft/gpl.html
30 /******************************************************************************/
32 #ifndef _h_PSCRYPTO
33 #define _h_PSCRYPTO
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
40 PeerSec crypto-specific defines.
42 #define SMALL_CODE
43 #define CLEAN_STACK
45 If Native 64 bit integers are not supported, we must set the 16 bit flag
46 to produce 32 bit mp_words in mpi.h
47 We must also include the slow MPI functions because the fast ones only
48 work with larger (28 bit) digit sizes.
50 #ifndef USE_INT64
51 #define MP_16BIT
52 #define USE_SMALL_WORD
53 #endif /* USE_INT64 */
55 /******************************************************************************/
57 #ifdef USE_RSA
59 #include "mpi.h"
61 #if LINUX
62 #define _stat stat
63 #endif
65 /* this is the "32-bit at least" data type
66 * Re-define it to suit your platform but it must be at least 32-bits
68 typedef unsigned long ulong32;
71 Primary RSA Key struct. Define here for crypto
73 typedef struct {
74 mp_int e, d, N, qP, dP, dQ, p, q;
75 int32 size; /* Size of the key in bytes */
76 int32 optimized; /* 1 for optimized */
77 } sslRsaKey_t;
79 #endif /* USE_RSA */
84 * Private
86 extern int32 ps_base64_decode(const unsigned char *in, uint32 len,
87 unsigned char *out, uint32 *outlen);
90 * Memory routines
92 extern void psZeromem(void *dst, size_t len);
93 extern void psBurnStack(unsigned long len);
96 /* max size of either a cipher/hash block or symmetric key [largest of the two] */
97 #define MAXBLOCKSIZE 24
99 /* ch1-01-1 */
100 /* error codes [will be expanded in future releases] */
101 enum {
102 CRYPT_OK=0, /* Result OK */
103 CRYPT_ERROR, /* Generic Error */
104 CRYPT_NOP, /* Not a failure but no operation was performed */
106 CRYPT_INVALID_KEYSIZE, /* Invalid key size given */
107 CRYPT_INVALID_ROUNDS, /* Invalid number of rounds */
108 CRYPT_FAIL_TESTVECTOR, /* Algorithm failed test vectors */
110 CRYPT_BUFFER_OVERFLOW, /* Not enough space for output */
111 CRYPT_INVALID_PACKET, /* Invalid input packet given */
113 CRYPT_INVALID_PRNGSIZE, /* Invalid number of bits for a PRNG */
114 CRYPT_ERROR_READPRNG, /* Could not read enough from PRNG */
116 CRYPT_INVALID_CIPHER, /* Invalid cipher specified */
117 CRYPT_INVALID_HASH, /* Invalid hash specified */
118 CRYPT_INVALID_PRNG, /* Invalid PRNG specified */
120 CRYPT_MEM, /* Out of memory */
122 CRYPT_PK_TYPE_MISMATCH, /* Not equivalent types of PK keys */
123 CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */
125 CRYPT_INVALID_ARG, /* Generic invalid argument */
126 CRYPT_FILE_NOTFOUND, /* File Not Found */
128 CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */
129 CRYPT_PK_INVALID_SYSTEM, /* Invalid PK system specified */
130 CRYPT_PK_DUP, /* Duplicate key already in key ring */
131 CRYPT_PK_NOT_FOUND, /* Key not found in keyring */
132 CRYPT_PK_INVALID_SIZE, /* Invalid size input for PK parameters */
134 CRYPT_INVALID_PRIME_SIZE /* Invalid size of prime requested */
137 /******************************************************************************/
139 hash defines
141 struct sha1_state {
142 #ifdef USE_INT64
143 ulong64 length;
144 #else
145 ulong32 lengthHi;
146 ulong32 lengthLo;
147 #endif /* USE_INT64 */
148 ulong32 state[5], curlen;
149 unsigned char buf[64];
152 struct md5_state {
153 #ifdef USE_INT64
154 ulong64 length;
155 #else
156 ulong32 lengthHi;
157 ulong32 lengthLo;
158 #endif /* USE_INT64 */
159 ulong32 state[4], curlen;
160 unsigned char buf[64];
163 #ifdef USE_MD2
164 struct md2_state {
165 unsigned char chksum[16], X[48], buf[16];
166 unsigned long curlen;
168 #endif /* USE_MD2 */
172 typedef union {
173 struct sha1_state sha1;
174 struct md5_state md5;
175 #ifdef USE_MD2
176 struct md2_state md2;
177 #endif /* USE_MD2 */
178 } hash_state;
180 typedef hash_state sslSha1Context_t;
181 typedef hash_state sslMd5Context_t;
182 #ifdef USE_MD2
183 typedef hash_state sslMd2Context_t;
184 #endif /* USE_MD2 */
186 typedef struct {
187 unsigned char pad[64];
188 union {
189 sslMd5Context_t md5;
190 sslSha1Context_t sha1;
191 } u;
192 } sslHmacContext_t;
194 /******************************************************************************/
198 #ifdef USE_ARC4
199 typedef struct {
200 unsigned char state[256];
201 uint32 byteCount;
202 unsigned char x;
203 unsigned char y;
204 } rc4_key;
205 #endif /* USE_ARC4 */
208 #define SSL_DES3_KEY_LEN 24
209 #define SSL_DES3_IV_LEN 8
210 #define SSL_DES_KEY_LEN 8
212 #ifdef USE_3DES
214 typedef struct {
215 ulong32 ek[3][32], dk[3][32];
216 } des3_key;
219 A block cipher CBC structure
221 typedef struct {
222 int32 blocklen;
223 unsigned char IV[8];
224 des3_key key;
225 int32 explicitIV; /* 1 if yes */
226 } des3_CBC;
228 extern int32 des3_setup(const unsigned char *key, int32 keylen, int32 num_rounds,
229 des3_CBC *skey);
230 extern void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct,
231 des3_CBC *key);
232 extern void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt,
233 des3_CBC *key);
234 extern int32 des3_keysize(int32 *desired_keysize);
236 extern int32 des_setup(const unsigned char *key, int32 keylen, int32 num_rounds,
237 des3_CBC *skey);
238 extern void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct,
239 des3_CBC *key);
240 extern void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt,
241 des3_CBC *key);
243 #endif /* USE_3DES */
247 typedef union {
248 #ifdef USE_ARC4
249 rc4_key arc4;
250 #endif
251 #ifdef USE_3DES
252 des3_CBC des3;
253 #endif
254 } sslCipherContext_t;
258 Controls endianess and size of registers. Leave uncommented to get
259 platform neutral [slower] code detect x86-32 machines somewhat
261 #if (defined(_MSC_VER) && defined(WIN32)) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__)))
262 #define ENDIAN_LITTLE
263 #define ENDIAN_32BITWORD
264 #endif
267 /* #define ENDIAN_LITTLE */
268 /* #define ENDIAN_BIG */
270 /* #define ENDIAN_32BITWORD */
271 /* #define ENDIAN_64BITWORD */
273 #if (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD))
274 #error You must specify a word size as well as endianess
275 #endif
277 #if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
278 #define ENDIAN_NEUTRAL
279 #endif
282 helper macros
284 #if defined (ENDIAN_NEUTRAL)
286 #define STORE32L(x, y) \
287 { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
288 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
290 #define LOAD32L(x, y) \
291 { x = ((unsigned long)((y)[3] & 255)<<24) | \
292 ((unsigned long)((y)[2] & 255)<<16) | \
293 ((unsigned long)((y)[1] & 255)<<8) | \
294 ((unsigned long)((y)[0] & 255)); }
296 #define STORE64L(x, y) \
297 { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
298 (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
299 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
300 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
302 #define LOAD64L(x, y) \
303 { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
304 (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
305 (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
306 (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
308 #define STORE32H(x, y) \
309 { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
310 (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
312 #define LOAD32H(x, y) \
313 { x = ((unsigned long)((y)[0] & 255)<<24) | \
314 ((unsigned long)((y)[1] & 255)<<16) | \
315 ((unsigned long)((y)[2] & 255)<<8) | \
316 ((unsigned long)((y)[3] & 255)); }
318 #define STORE64H(x, y) \
319 { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
320 (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
321 (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
322 (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
324 #define LOAD64H(x, y) \
325 { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
326 (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
327 (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
328 (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
330 #endif /* ENDIAN_NEUTRAL */
332 #ifdef ENDIAN_LITTLE
334 #define STORE32H(x, y) \
335 { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
336 (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
338 #define LOAD32H(x, y) \
339 { x = ((unsigned long)((y)[0] & 255)<<24) | \
340 ((unsigned long)((y)[1] & 255)<<16) | \
341 ((unsigned long)((y)[2] & 255)<<8) | \
342 ((unsigned long)((y)[3] & 255)); }
344 #define STORE64H(x, y) \
345 { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
346 (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
347 (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
348 (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
350 #define LOAD64H(x, y) \
351 { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
352 (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
353 (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
354 (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
356 #ifdef ENDIAN_32BITWORD
358 #define STORE32L(x, y) \
359 { unsigned long __t = (x); memcpy(y, &__t, 4); }
361 #define LOAD32L(x, y) \
362 memcpy(&(x), y, 4);
364 #define STORE64L(x, y) \
365 { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
366 (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
367 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
368 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
370 #define LOAD64L(x, y) \
371 { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
372 (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
373 (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
374 (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
376 #else /* 64-bit words then */
378 #define STORE32L(x, y) \
379 { unsigned long __t = (x); memcpy(y, &__t, 4); }
381 #define LOAD32L(x, y) \
382 { memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
384 #define STORE64L(x, y) \
385 { ulong64 __t = (x); memcpy(y, &__t, 8); }
387 #define LOAD64L(x, y) \
388 { memcpy(&(x), y, 8); }
390 #endif /* ENDIAN_64BITWORD */
391 #endif /* ENDIAN_LITTLE */
393 #ifdef ENDIAN_BIG
394 #define STORE32L(x, y) \
395 { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
396 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
398 #define LOAD32L(x, y) \
399 { x = ((unsigned long)((y)[3] & 255)<<24) | \
400 ((unsigned long)((y)[2] & 255)<<16) | \
401 ((unsigned long)((y)[1] & 255)<<8) | \
402 ((unsigned long)((y)[0] & 255)); }
404 #define STORE64L(x, y) \
405 { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
406 (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
407 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
408 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
410 #define LOAD64L(x, y) \
411 { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48) | \
412 (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32) | \
413 (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16) | \
414 (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
416 #ifdef ENDIAN_32BITWORD
418 #define STORE32H(x, y) \
419 { unsigned long __t = (x); memcpy(y, &__t, 4); }
421 #define LOAD32H(x, y) \
422 memcpy(&(x), y, 4);
424 #define STORE64H(x, y) \
425 { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
426 (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
427 (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
428 (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
430 #define LOAD64H(x, y) \
431 { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48)| \
432 (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32)| \
433 (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16)| \
434 (((ulong64)((y)[6] & 255))<<8)| (((ulong64)((y)[7] & 255))); }
436 #else /* 64-bit words then */
438 #define STORE32H(x, y) \
439 { unsigned long __t = (x); memcpy(y, &__t, 4); }
441 #define LOAD32H(x, y) \
442 { memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
444 #define STORE64H(x, y) \
445 { ulong64 __t = (x); memcpy(y, &__t, 8); }
447 #define LOAD64H(x, y) \
448 { memcpy(&(x), y, 8); }
450 #endif /* ENDIAN_64BITWORD */
451 #endif /* ENDIAN_BIG */
454 packet code */
455 #if defined(USE_RSA) || defined(MDH) || defined(MECC)
456 #define PACKET
459 size of a packet header in bytes */
460 #define PACKET_SIZE 4
463 Section tags
465 #define PACKET_SECT_RSA 0
466 #define PACKET_SECT_DH 1
467 #define PACKET_SECT_ECC 2
468 #define PACKET_SECT_DSA 3
471 Subsection Tags for the first three sections
473 #define PACKET_SUB_KEY 0
474 #define PACKET_SUB_ENCRYPTED 1
475 #define PACKET_SUB_SIGNED 2
476 #define PACKET_SUB_ENC_KEY 3
477 #endif
480 fix for MSVC ...evil!
482 #ifdef WIN32
483 #ifdef _MSC_VER
484 #define CONST64(n) n ## ui64
485 typedef unsigned __int64 ulong64;
486 #else
487 #define CONST64(n) n ## ULL
488 typedef unsigned long long ulong64;
489 #endif
490 #endif /* WIN32 */
493 #define BSWAP(x) ( ((x>>24)&0x000000FFUL) | ((x<<24)&0xFF000000UL) | \
494 ((x>>8)&0x0000FF00UL) | ((x<<8)&0x00FF0000UL) )
496 #ifdef _MSC_VER
499 instrinsic rotate
501 #include <stdlib.h>
502 #pragma intrinsic(_lrotr,_lrotl)
503 #define ROR(x,n) _lrotr(x,n)
504 #define ROL(x,n) _lrotl(x,n)
505 #define RORc(x,n) _lrotr(x,n)
506 #define ROLc(x,n) _lrotl(x,n)
509 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(PS_NO_ASM)
511 static inline unsigned ROL(unsigned word, int32 i)
513 asm ("roll %%cl,%0"
514 :"0" (word),"c" (i));
515 return word;
518 static inline unsigned ROR(unsigned word, int32 i)
520 asm ("rorl %%cl,%0"
521 :"=r" (word)
522 :"0" (word),"c" (i));
523 return word;
527 #ifndef PS_NO_ROLC
529 static inline unsigned ROLc(unsigned word, const int32 i)
531 asm ("roll %2,%0"
532 :"=r" (word)
533 :"0" (word),"I" (i));
534 return word;
537 static inline unsigned RORc(unsigned word, const int32 i)
539 asm ("rorl %2,%0"
540 :"=r" (word)
541 :"0" (word),"I" (i));
542 return word;
545 #else
547 #define ROLc ROL
548 #define RORc ROR
550 #endif
553 #else /* _MSC_VER */
556 rotates the hard way
558 #define ROL(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
559 #define ROR(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
560 #define ROLc(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
561 #define RORc(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
563 #endif /* _MSC_VER */
565 /* 64-bit Rotates */
566 #if 0
568 #if defined(__GNUC__) && defined(__x86_64__) && !defined(PS_NO_ASM)
570 static inline unsigned long ROL64(unsigned long word, int32 i)
572 asm("rolq %%cl,%0"
573 :"=r" (word)
574 :"0" (word),"c" (i));
575 return word;
578 static inline unsigned long ROR64(unsigned long word, int32 i)
580 asm("rorq %%cl,%0"
581 :"=r" (word)
582 :"0" (word),"c" (i));
583 return word;
586 #ifndef PS_NO_ROLC
588 static inline unsigned long ROL64c(unsigned long word, const int32 i)
590 asm("rolq %2,%0"
591 :"=r" (word)
592 :"0" (word),"J" (i));
593 return word;
596 static inline unsigned long ROR64c(unsigned long word, const int32 i)
598 asm("rorq %2,%0"
599 :"=r" (word)
600 :"0" (word),"J" (i));
601 return word;
604 #else /* PS_NO_ROLC */
606 #define ROL64c ROL
607 #define ROR64c ROR
609 #endif /* PS_NO_ROLC */
610 #endif
611 #endif /* commented out */
613 #define ROL64(x, y) \
614 ( (((x)<<((ulong64)(y)&63)) | \
615 (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
617 #define ROR64(x, y) \
618 ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
619 ((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
621 #define ROL64c(x, y) \
622 ( (((x)<<((ulong64)(y)&63)) | \
623 (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
625 #define ROR64c(x, y) \
626 ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
627 ((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
629 #undef MAX
630 #undef MIN
631 #define MAX(x, y) ( ((x)>(y))?(x):(y) )
632 #define MIN(x, y) ( ((x)<(y))?(x):(y) )
635 extract a byte portably This MSC code causes runtime errors in VS.NET,
636 always use the other
639 #ifdef _MSC_VER
640 #define byte(x, n) ((unsigned char)((x) >> (8 * (n))))
641 #else
643 #define byte(x, n) (((x) >> (8 * (n))) & 255)
645 #endif
647 #ifdef __cplusplus
649 #endif /* __cplusplus */
651 #endif /* _h_PSCRYPTO */
653 /******************************************************************************/