/[mcrypt]/libmcrypt/lib/swap.c
ViewVC logotype

Contents of /libmcrypt/lib/swap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Thu Oct 12 21:06:31 2000 UTC (20 years, 6 months ago) by nmav
Branch: MAIN
CVS Tags: libmcrypt_2_4_15, libmcrypt_2_4_16, mcrypt_2_4_20, mcrypt_2_4_12, libmcrypt_2_4_16b, libmcrypt_2_5_3, libmcrypt_2_5_2, libmcrypt_2_5_0, libmcrypt_2_5_7, libmcrypt_2_5_6, libmcrypt_2_5_5, libmcrypt_2_5_4, mcrypt_2_4_9, libmcrypt-2_4_9-beta, libmcrypt_2_4_17, libmcrypt_2_5_5rc1, libmcrypt_2_4_21, mcrypt_2_4_13, HEAD
Changes since 1.1: +2 -2 lines
File MIME type: text/plain
Added defines and some function emulation needed in WIN32. Thanks goes
to Dimitris Souflis (dsouflis@altera.gr)

1 /*
2 * Copyright (C) 1998,1999 Nikos Mavroyanopoulos
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20 /* $Id: swap.c,v 1.1.1.1 2000/05/22 13:07:52 nmav Exp $ */
21
22 #ifndef LIBDEFS_H
23 # define LIBDEFS_H
24 # include <libdefs.h>
25 #endif
26
27 #include <bzero.h>
28 #include <swap.h>
29 #include <xmemory.h>
30
31 #ifndef FAST
32
33 word32 rotl(word32 v, word32 cnt)
34 {
35 cnt &= (32 - 1);
36 while (cnt--)
37 v = ((v << 1) | (v >> (32 - 1)));
38 return v;
39 }
40 /* rotate right */
41 word32 rotr(word32 v, word32 cnt)
42 {
43 cnt &= (32 - 1);
44 while (cnt--)
45 v = ((v >> 1) | (v << (32 - 1)));
46 return v;
47 }
48
49 word16 rotl16(word16 v, word16 cnt)
50 {
51 cnt &= (16 - 1);
52 while (cnt--)
53 v = ((v << 1) | (v >> (16 - 1)));
54 return v;
55 }
56 /* rotate right */
57 word16 rotr16(word16 v, word16 cnt)
58 {
59 cnt &= (16 - 1);
60 while (cnt--)
61 v = ((v >> 1) | (v << (16 - 1)));
62 return v;
63 }
64
65 #endif
66
67 #ifndef FAST
68 /* Byte swap a 32bit integer */
69 word32 byteswap(word32 x)
70 {
71 return ((rotl(x, 8) & 0x00ff00ff) | (rotr(x, 8) & 0xff00ff00));
72 }
73
74
75 #endif
76
77 /* Byte swap a 16bit integer */
78 word16 byteswap16(word16 x)
79 {
80 return ( (rotl16(x, 8) & 0x00ff) | (rotr16(x, 8) & 0xff00) );
81 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26