2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
26 #include <gnutls_int.h>
31 int _gnutls_uint64pp(uint64 *);
32 int _gnutls_uint48pp(uint64 *);
34 #define UINT64DATA(x) ((x).i)
36 inline static uint32_t _gnutls_uint24touint32(uint24 num)
40 ((uint8_t *) & ret)[1] = num.pint[0];
41 ((uint8_t *) & ret)[2] = num.pint[1];
42 ((uint8_t *) & ret)[3] = num.pint[2];
46 inline static uint24 _gnutls_uint32touint24(uint32_t num)
50 ret.pint[0] = ((uint8_t *) & num)[1];
51 ret.pint[1] = ((uint8_t *) & num)[2];
52 ret.pint[2] = ((uint8_t *) & num)[3];
57 /* data should be at least 3 bytes */
58 inline static uint32_t _gnutls_read_uint24(const uint8_t * data)
63 num.pint[0] = data[0];
64 num.pint[1] = data[1];
65 num.pint[2] = data[2];
67 res = _gnutls_uint24touint32(num);
68 #ifndef WORDS_BIGENDIAN
74 inline static void _gnutls_write_uint64(uint64_t num, uint8_t * data)
76 #ifndef WORDS_BIGENDIAN
79 memcpy(data, &num, 8);
82 inline static void _gnutls_write_uint24(uint32_t num, uint8_t * data)
86 #ifndef WORDS_BIGENDIAN
89 tmp = _gnutls_uint32touint24(num);
91 data[0] = tmp.pint[0];
92 data[1] = tmp.pint[1];
93 data[2] = tmp.pint[2];
96 inline static uint32_t _gnutls_read_uint32(const uint8_t * data)
100 memcpy(&res, data, sizeof(uint32_t));
101 #ifndef WORDS_BIGENDIAN
107 inline static void _gnutls_write_uint32(uint32_t num, uint8_t * data)
110 #ifndef WORDS_BIGENDIAN
113 memcpy(data, &num, sizeof(uint32_t));
116 inline static uint16_t _gnutls_read_uint16(const uint8_t * data)
119 memcpy(&res, data, sizeof(uint16_t));
120 #ifndef WORDS_BIGENDIAN
126 inline static void _gnutls_write_uint16(uint16_t num, uint8_t * data)
129 #ifndef WORDS_BIGENDIAN
132 memcpy(data, &num, sizeof(uint16_t));
135 inline static uint32_t _gnutls_conv_uint32(uint32_t data)
137 #ifndef WORDS_BIGENDIAN
138 return bswap_32(data);
144 inline static uint16_t _gnutls_conv_uint16(uint16_t data)
146 #ifndef WORDS_BIGENDIAN
147 return bswap_16(data);
153 inline static uint32_t _gnutls_uint64touint32(const uint64 * num)
157 memcpy(&ret, &num->i[4], 4);
158 #ifndef WORDS_BIGENDIAN
165 #endif /* GNUTLS_NUM_H */