Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

beecrypt/endianness.h

Go to the documentation of this file.
00001 /*
00002  * endianness.h
00003  *
00004  * Endian-dependant encoding/decoding, header
00005  *
00006  * Copyright (c) 1998, 1999, 2000, 2001 Virtual Unlimited B.V.
00007  *
00008  * Author: Bob Deblier <bob@virtualunlimited.com>
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 #ifndef _ENDIANNESS_H
00027 #define _ENDIANNESS_H
00028 
00029 #include "beecrypt.h"
00030 
00031 #include <stdio.h>
00032 
00033 #ifdef __cplusplus
00034 inline int16 swap16(int16 n)
00035 {
00036         return (    ((n & 0xff) << 8) |
00037                                 ((n & 0xff00) >> 8) );
00038 }
00039 
00040 inline uint16 swapu16(uint16 n)
00041 {
00042         return (    ((n & 0xffU) << 8) |
00043                                 ((n & 0xff00U) >> 8) );
00044 }
00045 
00046 inline int32 swap32(int32 n)
00047 {
00048         #if (SIZEOF_LONG == 4)
00049         return (    ((n & 0xff) << 24) |
00050                                 ((n & 0xff00) << 8) |
00051                                 ((n & 0xff0000) >> 8) |
00052                                 ((n & 0xff000000) >> 24) );
00053         #else
00054         return (    ((n & 0xffL) << 24) |
00055                                 ((n & 0xff00L) << 8) |
00056                                 ((n & 0xff0000L) >> 8) |
00057                                 ((n & 0xff000000L) >> 24) );
00058         #endif
00059 }
00060 
00061 inline uint32 swapu32(uint32 n)
00062 {
00063         #if (SIZEOF_UNSIGNED_LONG == 4)
00064         return (    ((n & 0xffU) << 24) |
00065                                 ((n & 0xff00U) << 8) |
00066                                 ((n & 0xff0000U) >> 8) |
00067                                 ((n & 0xff000000U) >> 24) );
00068         #else
00069         return (    ((n & 0xffUL) << 24) |
00070                                 ((n & 0xff00UL) << 8) |
00071                                 ((n & 0xff0000UL) >> 8) |
00072                                 ((n & 0xff000000UL) >> 24) );
00073         #endif
00074 }
00075 
00076 inline int64 swap64(int64 n)
00077 {
00078         #if HAVE_LONG_LONG
00079         return (    ((n & 0xffLL) << 56) |
00080                                 ((n & 0xff00LL) << 40) |
00081                                 ((n & 0xff0000LL) << 24) |
00082                                 ((n & 0xff000000LL) << 8) |
00083                                 ((n & 0xff00000000LL) >> 8) |
00084                                 ((n & 0xff0000000000LL) >> 24) |
00085                                 ((n & 0xff000000000000LL) >> 40) |
00086                                 ((n & 0xff00000000000000LL) >> 56) );
00087         #else
00088         return (    ((n & 0xffL) << 56) |
00089                                 ((n & 0xff00L) << 40) |
00090                                 ((n & 0xff0000L) << 24) |
00091                                 ((n & 0xff000000L) << 8) |
00092                                 ((n & 0xff00000000L) >> 8) |
00093                                 ((n & 0xff0000000000L) >> 24) |
00094                                 ((n & 0xff000000000000L) >> 40) |
00095                                 ((n & 0xff00000000000000L) >> 56) );
00096         #endif
00097 }
00098 #else
00099 /*@-exportlocal@*/
00100 
00103  int16 swap16 (int16 n)
00104         /*@*/;
00105 
00108 uint16 swapu16(uint16 n)
00109         /*@*/;
00110 
00113  int32 swap32 (int32 n)
00114         /*@*/;
00115 
00118 uint32 swapu32(uint32 n)
00119         /*@*/;
00120 
00123  int64 swap64 (int64 n)
00124         /*@*/;
00125 /*@=exportlocal@*/
00126 #endif
00127 
00128 #ifdef __cplusplus
00129 extern "C" {
00130 #endif
00131 
00132 
00135 BEECRYPTAPI /*@unused@*/
00136 int encodeByte(javabyte b, /*@out@*/ byte* data)
00137         /*@modifies data */;
00138 
00141 BEECRYPTAPI /*@unused@*/
00142 int encodeShort(javashort s, /*@out@*/ byte* data)
00143         /*@modifies data */;
00144 
00147 BEECRYPTAPI /*@unused@*/
00148 int encodeInt(javaint i, /*@out@*/ byte* data)
00149         /*@modifies data */;
00150 
00153 BEECRYPTAPI /*@unused@*/
00154 int encodeLong(javalong l, /*@out@*/ byte* data)
00155         /*@modifies data */;
00156 
00159 BEECRYPTAPI /*@unused@*/
00160 int encodeChar(javachar c, /*@out@*/ byte* data)
00161         /*@modifies data */;
00162 
00165 BEECRYPTAPI /*@unused@*/
00166 int encodeFloat(javafloat f, /*@out@*/ byte* data)
00167         /*@modifies data */;
00168 
00171 BEECRYPTAPI /*@unused@*/
00172 int encodeDouble(javadouble d, /*@out@*/ byte* data)
00173         /*@modifies data */;
00174 
00177 BEECRYPTAPI
00178 int encodeInts(const javaint* i, /*@out@*/ byte* data, int count)
00179         /*@modifies data */;
00180 
00183 BEECRYPTAPI /*@unused@*/
00184 int encodeIntsPartial(const javaint* i, /*@out@*/ byte* data, int bytecount)
00185         /*@modifies data */;
00186 
00189 BEECRYPTAPI /*@unused@*/
00190 int encodeIntsPartialPad(const javaint* i, byte* data, int bytecount, byte padvalue)
00191         /*@modifies data */;
00192 
00195 BEECRYPTAPI /*@unused@*/
00196 int encodeChars(const javachar* c, /*@out@*/ byte* data, int count)
00197         /*@modifies data */;
00198 
00201 BEECRYPTAPI /*@unused@*/
00202 int decodeByte(/*@out@*/ javabyte* b, const byte* data)
00203         /*@modifies b */;
00204 
00207 BEECRYPTAPI /*@unused@*/
00208 int decodeShort(/*@out@*/ javashort* s, const byte* data)
00209         /*@modifies s */;
00210 
00213 BEECRYPTAPI /*@unused@*/
00214 int decodeInt(/*@out@*/ javaint* i, const byte* data)
00215         /*@modifies i */;
00216 
00219 BEECRYPTAPI /*@unused@*/
00220 int decodeLong(/*@out@*/ javalong* l, const byte* data)
00221         /*@modifies l */;
00222 
00225 BEECRYPTAPI /*@unused@*/
00226 int decodeChar(/*@out@*/ javachar* c, const byte* data)
00227         /*@modifies c */;
00228 
00231 BEECRYPTAPI /*@unused@*/
00232 int decodeFloat(/*@out@*/ javafloat* f, const byte* data)
00233         /*@modifies f */;
00234 
00237 BEECRYPTAPI /*@unused@*/
00238 int decodeDouble(/*@out@*/ javadouble* d, const byte* data)
00239         /*@modifies d */;
00240 
00243 BEECRYPTAPI /*@unused@*/
00244 int decodeInts(/*@out@*/ javaint* i, const byte* data, int count)
00245         /*@modifies i */;
00246 
00249 BEECRYPTAPI /*@unused@*/
00250 int decodeIntsPartial(/*@out@*/ javaint* i, const byte* data, int bytecount)
00251         /*@modifies i */;
00252 
00255 BEECRYPTAPI /*@unused@*/
00256 int decodeChars(/*@out@*/ javachar* c, const byte* data, int count)
00257         /*@modifies c */;
00258 
00261 BEECRYPTAPI /*@unused@*/
00262 int writeByte(javabyte b, FILE* ofp)
00263         /*@globals fileSystem @*/
00264         /*@modifies ofp, fileSystem */;
00265 
00268 BEECRYPTAPI /*@unused@*/
00269 int writeShort(javashort s, FILE* ofp)
00270         /*@globals fileSystem @*/
00271         /*@modifies ofp, fileSystem */;
00272 
00275 /*@-exportlocal@*/
00276 BEECRYPTAPI
00277 int writeInt(javaint i, FILE* ofp)
00278         /*@globals fileSystem @*/
00279         /*@modifies ofp, fileSystem */;
00280 /*@=exportlocal@*/
00281 
00284 BEECRYPTAPI /*@unused@*/
00285 int writeLong(javalong l, FILE* ofp)
00286         /*@globals fileSystem @*/
00287         /*@modifies ofp, fileSystem */;
00288 
00291 /*@-exportlocal@*/
00292 BEECRYPTAPI
00293 int writeChar(javachar c, FILE* ofp)
00294         /*@globals fileSystem @*/
00295         /*@modifies ofp, fileSystem */;
00296 /*@=exportlocal@*/
00297 
00300 BEECRYPTAPI /*@unused@*/
00301 int writeInts(const javaint* i, FILE* ofp, int count)
00302         /*@globals fileSystem @*/
00303         /*@modifies ofp, fileSystem */;
00304 
00307 BEECRYPTAPI /*@unused@*/
00308 int writeChars(const javachar* c, FILE* ofp, int count)
00309         /*@globals fileSystem @*/
00310         /*@modifies ofp, fileSystem */;
00311 
00314 BEECRYPTAPI /*@unused@*/
00315 int readByte(/*@out@*/ javabyte* b, FILE* ifp)
00316         /*@globals fileSystem @*/
00317         /*@modifies b, ifp, fileSystem */;
00318 
00321 BEECRYPTAPI /*@unused@*/
00322 int readShort(/*@out@*/ javashort* s, FILE* ifp)
00323         /*@globals fileSystem @*/
00324         /*@modifies s, ifp, fileSystem */;
00325 
00328 BEECRYPTAPI /*@unused@*/
00329 int readInt(/*@out@*/ javaint* i, FILE* ifp)
00330         /*@globals fileSystem @*/
00331         /*@modifies i, ifp, fileSystem */;
00332 
00335 BEECRYPTAPI /*@unused@*/
00336 int readLong(/*@out@*/ javalong* l, FILE* ifp)
00337         /*@globals fileSystem @*/
00338         /*@modifies l, ifp, fileSystem */;
00339 
00342 BEECRYPTAPI /*@unused@*/
00343 int readChar(/*@out@*/ javachar* c, FILE* ifp)
00344         /*@globals fileSystem @*/
00345         /*@modifies c, ifp, fileSystem */;
00346 
00349 BEECRYPTAPI /*@unused@*/
00350 int readInts(/*@out@*/ javaint* i, FILE* ifp, int count)
00351         /*@globals fileSystem @*/
00352         /*@modifies i, ifp, fileSystem */;
00353 
00356 BEECRYPTAPI /*@unused@*/
00357 int readChars(/*@out@*/ javachar* c, FILE* ifp, int count)
00358         /*@globals fileSystem @*/
00359         /*@modifies c, ifp, fileSystem */;
00360 
00361 #ifdef __cplusplus
00362 }
00363 #endif
00364 
00365 #endif

Generated on Tue Sep 17 15:56:36 2002 for rpm by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002