00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00126 #endif
00127
00128 #ifdef __cplusplus
00129 extern "C" {
00130 #endif
00131
00132
00135 BEECRYPTAPI
00136 int encodeByte(javabyte b, byte* data)
00137 ;
00138
00141 BEECRYPTAPI
00142 int encodeShort(javashort s, byte* data)
00143 ;
00144
00147 BEECRYPTAPI
00148 int encodeInt(javaint i, byte* data)
00149 ;
00150
00153 BEECRYPTAPI
00154 int encodeLong(javalong l, byte* data)
00155 ;
00156
00159 BEECRYPTAPI
00160 int encodeChar(javachar c, byte* data)
00161 ;
00162
00165 BEECRYPTAPI
00166 int encodeFloat(javafloat f, byte* data)
00167 ;
00168
00171 BEECRYPTAPI
00172 int encodeDouble(javadouble d, byte* data)
00173 ;
00174
00177 BEECRYPTAPI
00178 int encodeInts(const javaint* i, byte* data, int count)
00179 ;
00180
00183 BEECRYPTAPI
00184 int encodeIntsPartial(const javaint* i, byte* data, int bytecount)
00185 ;
00186
00189 BEECRYPTAPI
00190 int encodeIntsPartialPad(const javaint* i, byte* data, int bytecount, byte padvalue)
00191 ;
00192
00195 BEECRYPTAPI
00196 int encodeChars(const javachar* c, byte* data, int count)
00197 ;
00198
00201 BEECRYPTAPI
00202 int decodeByte( javabyte* b, const byte* data)
00203 ;
00204
00207 BEECRYPTAPI
00208 int decodeShort( javashort* s, const byte* data)
00209 ;
00210
00213 BEECRYPTAPI
00214 int decodeInt( javaint* i, const byte* data)
00215 ;
00216
00219 BEECRYPTAPI
00220 int decodeLong( javalong* l, const byte* data)
00221 ;
00222
00225 BEECRYPTAPI
00226 int decodeChar( javachar* c, const byte* data)
00227 ;
00228
00231 BEECRYPTAPI
00232 int decodeFloat( javafloat* f, const byte* data)
00233 ;
00234
00237 BEECRYPTAPI
00238 int decodeDouble( javadouble* d, const byte* data)
00239 ;
00240
00243 BEECRYPTAPI
00244 int decodeInts( javaint* i, const byte* data, int count)
00245 ;
00246
00249 BEECRYPTAPI
00250 int decodeIntsPartial( javaint* i, const byte* data, int bytecount)
00251 ;
00252
00255 BEECRYPTAPI
00256 int decodeChars( javachar* c, const byte* data, int count)
00257 ;
00258
00261 BEECRYPTAPI
00262 int writeByte(javabyte b, FILE* ofp)
00263
00264 ;
00265
00268 BEECRYPTAPI
00269 int writeShort(javashort s, FILE* ofp)
00270
00271 ;
00272
00275
00276 BEECRYPTAPI
00277 int writeInt(javaint i, FILE* ofp)
00278
00279 ;
00280
00281
00284 BEECRYPTAPI
00285 int writeLong(javalong l, FILE* ofp)
00286
00287 ;
00288
00291
00292 BEECRYPTAPI
00293 int writeChar(javachar c, FILE* ofp)
00294
00295 ;
00296
00297
00300 BEECRYPTAPI
00301 int writeInts(const javaint* i, FILE* ofp, int count)
00302
00303 ;
00304
00307 BEECRYPTAPI
00308 int writeChars(const javachar* c, FILE* ofp, int count)
00309
00310 ;
00311
00314 BEECRYPTAPI
00315 int readByte( javabyte* b, FILE* ifp)
00316
00317 ;
00318
00321 BEECRYPTAPI
00322 int readShort( javashort* s, FILE* ifp)
00323
00324 ;
00325
00328 BEECRYPTAPI
00329 int readInt( javaint* i, FILE* ifp)
00330
00331 ;
00332
00335 BEECRYPTAPI
00336 int readLong( javalong* l, FILE* ifp)
00337
00338 ;
00339
00342 BEECRYPTAPI
00343 int readChar( javachar* c, FILE* ifp)
00344
00345 ;
00346
00349 BEECRYPTAPI
00350 int readInts( javaint* i, FILE* ifp, int count)
00351
00352 ;
00353
00356 BEECRYPTAPI
00357 int readChars( javachar* c, FILE* ifp, int count)
00358
00359 ;
00360
00361 #ifdef __cplusplus
00362 }
00363 #endif
00364
00365 #endif