sph_types.h File Reference

#include <limits.h>

Go to the source code of this file.

Defines

#define SPH_C32(x)
#define SPH_T32(x)
#define SPH_ROTL32(x, n)
#define SPH_ROTR32(x, n)
#define SPH_64
#define SPH_64_TRUE
#define SPH_C64(x)
#define SPH_T64(x)
#define SPH_ROTL64(x, n)
#define SPH_ROTR64(x, n)
#define SPH_INLINE
#define SPH_LITTLE_ENDIAN
#define SPH_BIG_ENDIAN
#define SPH_LITTLE_FAST
#define SPH_BIG_FAST
#define SPH_UPTR
#define SPH_UNALIGNED

Typedefs

typedef __arch_dependant__ sph_u32
typedef __arch_dependant__ sph_s32
typedef __arch_dependant__ sph_u64
typedef __arch_dependant__ sph_s64

Functions

static sph_u32 sph_bswap32 (sph_u32 x)
static sph_u64 sph_bswap64 (sph_u64 x)
static unsigned sph_dec16le (const void *src)
static void sph_enc16le (void *dst, unsigned val)
static unsigned sph_dec16be (const void *src)
static void sph_enc16be (void *dst, unsigned val)
static sph_u32 sph_dec32le (const void *src)
static sph_u32 sph_dec32le_aligned (const void *src)
static void sph_enc32le (void *dst, sph_u32 val)
static void sph_enc32le_aligned (void *dst, sph_u32 val)
static sph_u32 sph_dec32be (const void *src)
static sph_u32 sph_dec32be_aligned (const void *src)
static void sph_enc32be (void *dst, sph_u32 val)
static void sph_enc32be_aligned (void *dst, sph_u32 val)
static sph_u64 sph_dec64le (const void *src)
static sph_u64 sph_dec64le_aligned (const void *src)
static void sph_enc64le (void *dst, sph_u64 val)
static void sph_enc64le_aligned (void *dst, sph_u64 val)
static sph_u64 sph_dec64be (const void *src)
static sph_u64 sph_dec64be_aligned (const void *src)
static void sph_enc64be (void *dst, sph_u64 val)
static void sph_enc64be_aligned (void *dst, sph_u64 val)

Detailed Description

Basic type definitions.

This header file defines the generic integer types that will be used for the implementation of hash functions; it also contains helper functions which encode and decode multi-byte integer values, using either little-endian or big-endian conventions.

This file contains a compile-time test on the size of a byte (the unsigned char C type). If bytes are not octets, i.e. if they do not have a size of exactly 8 bits, then compilation is aborted. Architectures where bytes are not octets are relatively rare, even in the embedded devices market. We forbid non-octet bytes because there is no clear convention on how octet streams are encoded on such systems.

==========================(LICENSE BEGIN)============================

Copyright (c) 2007-2010 Projet RNRT SAPHIR

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

===========================(LICENSE END)=============================

Author:
Thomas Pornin <thomas.pornin@cryptolog.com>

Define Documentation

#define SPH_C32 (  ) 

This macro expands the token x into a suitable constant expression of type sph_u32. Depending on how this type is defined, a suffix such as UL may be appended to the argument.

Parameters:
x the token to expand into a suitable constant expression
#define SPH_T32 (  ) 

Truncate a 32-bit value to exactly 32 bits. On most systems, this is a no-op, recognized as such by the compiler.

Parameters:
x the value to truncate (of type sph_u32)
#define SPH_ROTL32 ( x,
 ) 

Rotate a 32-bit value by a number of bits to the left. The rotate count must reside between 1 and 31. This macro assumes that its first argument fits in 32 bits (no extra bit allowed on machines where sph_u32 is wider); both arguments may be evaluated several times.

Parameters:
x the value to rotate (of type sph_u32)
n the rotation count (between 1 and 31, inclusive)
#define SPH_ROTR32 ( x,
 ) 

Rotate a 32-bit value by a number of bits to the left. The rotate count must reside between 1 and 31. This macro assumes that its first argument fits in 32 bits (no extra bit allowed on machines where sph_u32 is wider); both arguments may be evaluated several times.

Parameters:
x the value to rotate (of type sph_u32)
n the rotation count (between 1 and 31, inclusive)
#define SPH_64

This macro is defined on systems for which a 64-bit type has been detected, and is used for sph_u64.

#define SPH_64_TRUE

This macro is defined on systems for the "native" integer size is 64 bits (64-bit values fit in one register).

#define SPH_C64 (  ) 

This macro expands the token x into a suitable constant expression of type sph_u64. Depending on how this type is defined, a suffix such as ULL may be appended to the argument. This macro is defined only if a 64-bit type was detected and used for sph_u64.

Parameters:
x the token to expand into a suitable constant expression
#define SPH_T64 (  ) 

Truncate a 64-bit value to exactly 64 bits. On most systems, this is a no-op, recognized as such by the compiler. This macro is defined only if a 64-bit type was detected and used for sph_u64.

Parameters:
x the value to truncate (of type sph_u64)
#define SPH_ROTL64 ( x,
 ) 

Rotate a 64-bit value by a number of bits to the left. The rotate count must reside between 1 and 63. This macro assumes that its first argument fits in 64 bits (no extra bit allowed on machines where sph_u64 is wider); both arguments may be evaluated several times. This macro is defined only if a 64-bit type was detected and used for sph_u64.

Parameters:
x the value to rotate (of type sph_u64)
n the rotation count (between 1 and 63, inclusive)
#define SPH_ROTR64 ( x,
 ) 

Rotate a 64-bit value by a number of bits to the left. The rotate count must reside between 1 and 63. This macro assumes that its first argument fits in 64 bits (no extra bit allowed on machines where sph_u64 is wider); both arguments may be evaluated several times. This macro is defined only if a 64-bit type was detected and used for sph_u64.

Parameters:
x the value to rotate (of type sph_u64)
n the rotation count (between 1 and 63, inclusive)
#define SPH_INLINE

This macro evaluates to inline or an equivalent construction, if available on the compilation platform, or to nothing otherwise. This is used to declare inline functions, for which the compiler should endeavour to include the code directly in the caller. Inline functions are typically defined in header files as replacement for macros.

#define SPH_LITTLE_ENDIAN

This macro is defined if the platform has been detected as using little-endian convention. This implies that the sph_u32 type (and the sph_u64 type also, if it is defined) has an exact width (i.e. exactly 32-bit, respectively 64-bit).

#define SPH_BIG_ENDIAN

This macro is defined if the platform has been detected as using big-endian convention. This implies that the sph_u32 type (and the sph_u64 type also, if it is defined) has an exact width (i.e. exactly 32-bit, respectively 64-bit).

#define SPH_LITTLE_FAST

This macro is defined if 32-bit words (and 64-bit words, if defined) can be read from and written to memory efficiently in little-endian convention. This is the case for little-endian platforms, and also for the big-endian platforms which have special little-endian access opcodes (e.g. Ultrasparc).

#define SPH_BIG_FAST

This macro is defined if 32-bit words (and 64-bit words, if defined) can be read from and written to memory efficiently in big-endian convention. This is the case for little-endian platforms, and also for the little-endian platforms which have special big-endian access opcodes.

#define SPH_UPTR

On some platforms, this macro is defined to an unsigned integer type into which pointer values may be cast. The resulting value can then be tested for being a multiple of 2, 4 or 8, indicating an aligned pointer for, respectively, 16-bit, 32-bit or 64-bit memory accesses.

#define SPH_UNALIGNED

When defined, this macro indicates that unaligned memory accesses are possible with only a minor penalty, and thus should be prefered over strategies which first copy data to an aligned buffer.


Typedef Documentation

typedef __arch_dependant__ sph_u32

Unsigned integer type whose length is at least 32 bits; on most architectures, it will have a width of exactly 32 bits. Unsigned C types implement arithmetics modulo a power of 2; use the SPH_T32() macro to ensure that the value is truncated to exactly 32 bits. Unless otherwise specified, all macros and functions which accept sph_u32 values assume that these values fit on 32 bits, i.e. do not exceed 2^32-1, even on architectures where sph_u32 is larger than that.

typedef __arch_dependant__ sph_s32

Signed integer type corresponding to sph_u32; it has width 32 bits or more.

typedef __arch_dependant__ sph_u64

Unsigned integer type whose length is at least 64 bits; on most architectures which feature such a type, it will have a width of exactly 64 bits. C99-compliant platform will have this type; it is also defined when the GNU compiler (gcc) is used, and on platforms where unsigned long is large enough. If this type is not available, then some hash functions which depends on a 64-bit type will not be available (most notably SHA-384, SHA-512, Tiger and WHIRLPOOL).

typedef __arch_dependant__ sph_s64

Signed integer type corresponding to sph_u64; it has width 64 bits or more.


Function Documentation

static sph_u32 sph_bswap32 ( sph_u32  x  )  [inline, static]

Byte-swap a 32-bit word (i.e. 0x12345678 becomes 0x78563412). This is an inline function which resorts to inline assembly on some platforms, for better performance.

Parameters:
x the 32-bit value to byte-swap
Returns:
the byte-swapped value
static sph_u64 sph_bswap64 ( sph_u64  x  )  [inline, static]

Byte-swap a 64-bit word. This is an inline function which resorts to inline assembly on some platforms, for better performance. This function is defined only if a suitable 64-bit type was found for sph_u64

Parameters:
x the 64-bit value to byte-swap
Returns:
the byte-swapped value
static unsigned sph_dec16le ( const void *  src  )  [inline, static]

Decode a 16-bit unsigned value from memory, in little-endian convention (least significant byte comes first).

Parameters:
src the source address
Returns:
the decoded value
static void sph_enc16le ( void *  dst,
unsigned  val 
) [inline, static]

Encode a 16-bit unsigned value into memory, in little-endian convention (least significant byte comes first).

Parameters:
dst the destination buffer
val the value to encode
static unsigned sph_dec16be ( const void *  src  )  [inline, static]

Decode a 16-bit unsigned value from memory, in big-endian convention (most significant byte comes first).

Parameters:
src the source address
Returns:
the decoded value
static void sph_enc16be ( void *  dst,
unsigned  val 
) [inline, static]

Encode a 16-bit unsigned value into memory, in big-endian convention (most significant byte comes first).

Parameters:
dst the destination buffer
val the value to encode
static sph_u32 sph_dec32le ( const void *  src  )  [inline, static]

Decode a 32-bit unsigned value from memory, in little-endian convention (least significant byte comes first).

Parameters:
src the source address
Returns:
the decoded value
static sph_u32 sph_dec32le_aligned ( const void *  src  )  [inline, static]

Decode a 32-bit unsigned value from memory, in little-endian convention (least significant byte comes first). This function assumes that the source address is suitably aligned for a direct access, if the platform supports such things; it can thus be marginally faster than the generic sph_dec32le() function.

Parameters:
src the source address
Returns:
the decoded value
static void sph_enc32le ( void *  dst,
sph_u32  val 
) [inline, static]

Encode a 32-bit unsigned value into memory, in little-endian convention (least significant byte comes first).

Parameters:
dst the destination buffer
val the value to encode
static void sph_enc32le_aligned ( void *  dst,
sph_u32  val 
) [inline, static]

Encode a 32-bit unsigned value into memory, in little-endian convention (least significant byte comes first). This function assumes that the destination address is suitably aligned for a direct access, if the platform supports such things; it can thus be marginally faster than the generic sph_enc32le() function.

Parameters:
dst the destination buffer
val the value to encode
static sph_u32 sph_dec32be ( const void *  src  )  [inline, static]

Decode a 32-bit unsigned value from memory, in big-endian convention (most significant byte comes first).

Parameters:
src the source address
Returns:
the decoded value
static sph_u32 sph_dec32be_aligned ( const void *  src  )  [inline, static]

Decode a 32-bit unsigned value from memory, in big-endian convention (most significant byte comes first). This function assumes that the source address is suitably aligned for a direct access, if the platform supports such things; it can thus be marginally faster than the generic sph_dec32be() function.

Parameters:
src the source address
Returns:
the decoded value
static void sph_enc32be ( void *  dst,
sph_u32  val 
) [inline, static]

Encode a 32-bit unsigned value into memory, in big-endian convention (most significant byte comes first).

Parameters:
dst the destination buffer
val the value to encode
static void sph_enc32be_aligned ( void *  dst,
sph_u32  val 
) [inline, static]

Encode a 32-bit unsigned value into memory, in big-endian convention (most significant byte comes first). This function assumes that the destination address is suitably aligned for a direct access, if the platform supports such things; it can thus be marginally faster than the generic sph_enc32be() function.

Parameters:
dst the destination buffer
val the value to encode
static sph_u64 sph_dec64le ( const void *  src  )  [inline, static]

Decode a 64-bit unsigned value from memory, in little-endian convention (least significant byte comes first). This function is defined only if a suitable 64-bit type was detected and used for sph_u64.

Parameters:
src the source address
Returns:
the decoded value
static sph_u64 sph_dec64le_aligned ( const void *  src  )  [inline, static]

Decode a 64-bit unsigned value from memory, in little-endian convention (least significant byte comes first). This function assumes that the source address is suitably aligned for a direct access, if the platform supports such things; it can thus be marginally faster than the generic sph_dec64le() function. This function is defined only if a suitable 64-bit type was detected and used for sph_u64.

Parameters:
src the source address
Returns:
the decoded value
static void sph_enc64le ( void *  dst,
sph_u64  val 
) [inline, static]

Encode a 64-bit unsigned value into memory, in little-endian convention (least significant byte comes first). This function is defined only if a suitable 64-bit type was detected and used for sph_u64.

Parameters:
dst the destination buffer
val the value to encode
static void sph_enc64le_aligned ( void *  dst,
sph_u64  val 
) [inline, static]

Encode a 64-bit unsigned value into memory, in little-endian convention (least significant byte comes first). This function assumes that the destination address is suitably aligned for a direct access, if the platform supports such things; it can thus be marginally faster than the generic sph_enc64le() function. This function is defined only if a suitable 64-bit type was detected and used for sph_u64.

Parameters:
dst the destination buffer
val the value to encode
static sph_u64 sph_dec64be ( const void *  src  )  [inline, static]

Decode a 64-bit unsigned value from memory, in big-endian convention (most significant byte comes first). This function is defined only if a suitable 64-bit type was detected and used for sph_u64.

Parameters:
src the source address
Returns:
the decoded value
static sph_u64 sph_dec64be_aligned ( const void *  src  )  [inline, static]

Decode a 64-bit unsigned value from memory, in big-endian convention (most significant byte comes first). This function assumes that the source address is suitably aligned for a direct access, if the platform supports such things; it can thus be marginally faster than the generic sph_dec64be() function. This function is defined only if a suitable 64-bit type was detected and used for sph_u64.

Parameters:
src the source address
Returns:
the decoded value
static void sph_enc64be ( void *  dst,
sph_u64  val 
) [inline, static]

Encode a 64-bit unsigned value into memory, in big-endian convention (most significant byte comes first). This function is defined only if a suitable 64-bit type was detected and used for sph_u64.

Parameters:
dst the destination buffer
val the value to encode
static void sph_enc64be_aligned ( void *  dst,
sph_u64  val 
) [inline, static]

Encode a 64-bit unsigned value into memory, in big-endian convention (most significant byte comes first). This function assumes that the destination address is suitably aligned for a direct access, if the platform supports such things; it can thus be marginally faster than the generic sph_enc64be() function. This function is defined only if a suitable 64-bit type was detected and used for sph_u64.

Parameters:
dst the destination buffer
val the value to encode
Generated on Mon Jun 21 17:48:04 2010 for sphlib by  doxygen 1.6.3