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

Annotation of /libmcrypt/lib/swap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon May 22 13:07:52 2000 UTC (23 years, 10 months ago) by nmav
Branch: MAIN
Branch point for: mcrypt
File MIME type: text/plain
Initial revision

1 nmav 1.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 1999/12/13 21:13:21 nikos 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 byteswap_16(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