2 * Copyright (C) 2000 Nikos Mavroyanopoulos
4 * This file is part of GNUTLS.
6 * GNUTLS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNUTLS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #include <gnutls_int.h>
23 #define GMIN(x,y) (x<y)?x:y
24 #define GMAX(x,y) (x>y)?x:y
26 #define rotl32(x,n) (((x) << ((uint16)(n))) | ((x) >> (32 - (uint16)(n))))
27 #define rotr32(x,n) (((x) >> ((uint16)(n))) | ((x) << (32 - (uint16)(n))))
28 #define rotl16(x,n) (((x) << ((uint16)(n))) | ((x) >> (16 - (uint16)(n))))
29 #define rotr16(x,n) (((x) >> ((uint16)(n))) | ((x) << (16 - (uint16)(n))))
31 #define byteswap16(x) ((rotl16(x, 8) & 0x00ff) | (rotr16(x, 8) & 0xff00))
32 #define byteswap32(x) ((rotl32(x, 8) & 0x00ff00ffUL) | (rotr32(x, 8) & 0xff00ff00UL))
34 uint32
_gnutls_uint24touint32( uint24 num
);
35 uint24
_gnutls_uint32touint24( uint32 num
);
36 uint32
_gnutls_read_uint32( const opaque
* data
);
37 uint16
_gnutls_read_uint16( const opaque
* data
);
38 uint32
_gnutls_conv_uint32( uint32 data
);
39 uint16
_gnutls_conv_uint16( uint16 data
);
40 uint64
_gnutls_conv_uint64( const uint64
*data
);
41 uint32
_gnutls_read_uint24( const opaque
* data
);
42 void _gnutls_write_uint24( uint32 num
, opaque
* data
);
43 void _gnutls_write_uint32( uint32 num
, opaque
* data
);
44 void _gnutls_write_uint16( uint16 num
, opaque
* data
);
45 uint32
_gnutls_uint64touint32( const uint64
*);
48 int _gnutls_uint64zero( uint64
*);
49 int _gnutls_uint64pp( uint64
*);
50 # define UINT64DATA(x) x.i
53 # define UINT64DATA(x) &x
54 # define rotl64(x,n) (((x) << ((uint16)(n))) | ((x) >> (64 - (uint16)(n))))
55 # define rotr64(x,n) (((x) >> ((uint16)(n))) | ((x) << (64 - (uint16)(n))))
56 # define byteswap64(x) ((rotl64(x, 8) & 0x00ff00ff00ff00ffUL) | (rotr64(x, 8) & 0xff00ff00ff00ff00UL))
58 # define _gnutls_uint64pp(x) ((++(*x)==0) ? -1 : 0)
59 # define _gnutls_uint64zero(x) (*x) = 0