|
Packit Service |
31306d |
/*
|
|
Packit Service |
31306d |
* This file is part of the SSH Library
|
|
Packit Service |
31306d |
*
|
|
Packit Service |
31306d |
* Copyright (c) 2018 Andreas Schneider <asn@cryptomilk.org>
|
|
Packit Service |
31306d |
*
|
|
Packit Service |
31306d |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
31306d |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
31306d |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
31306d |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
31306d |
*
|
|
Packit Service |
31306d |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
31306d |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
31306d |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
31306d |
* Lesser General Public License for more details.
|
|
Packit Service |
31306d |
*
|
|
Packit Service |
31306d |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
31306d |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
31306d |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
31306d |
*/
|
|
Packit Service |
31306d |
#ifndef _BYTEARRAY_H
|
|
Packit Service |
31306d |
#define _BYTEARRAY_H
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define _DATA_BYTE_CONST(data, pos) \
|
|
Packit Service |
31306d |
((uint8_t)(((const uint8_t *)(data))[(pos)]))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define _DATA_BYTE(data, pos) \
|
|
Packit Service |
31306d |
(((uint8_t *)(data))[(pos)])
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
/*
|
|
Packit Service |
31306d |
* These macros pull or push integer values from byte arrays stored in
|
|
Packit Service |
31306d |
* little-endian byte order.
|
|
Packit Service |
31306d |
*/
|
|
Packit Service |
31306d |
#define PULL_LE_U8(data, pos) \
|
|
Packit Service |
31306d |
(_DATA_BYTE_CONST(data, pos))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PULL_LE_U16(data, pos) \
|
|
Packit Service |
31306d |
((uint16_t)PULL_LE_U8(data, pos) | ((uint16_t)(PULL_LE_U8(data, (pos) + 1))) << 8)
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PULL_LE_U32(data, pos) \
|
|
Packit Service |
31306d |
((uint32_t)(PULL_LE_U16(data, pos) | ((uint32_t)PULL_LE_U16(data, (pos) + 2)) << 16))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PULL_LE_U64(data, pos) \
|
|
Packit Service |
31306d |
((uint64_t)(PULL_LE_U32(data, pos) | ((uint64_t)PULL_LE_U32(data, (pos) + 4)) << 32))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PUSH_LE_U8(data, pos, val) \
|
|
Packit Service |
31306d |
(_DATA_BYTE(data, pos) = ((uint8_t)(val)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PUSH_LE_U16(data, pos, val) \
|
|
Packit Service |
31306d |
(PUSH_LE_U8((data), (pos), (uint8_t)((uint16_t)(val) & 0xff)), PUSH_LE_U8((data), (pos) + 1, (uint8_t)((uint16_t)(val) >> 8)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PUSH_LE_U32(data, pos, val) \
|
|
Packit Service |
31306d |
(PUSH_LE_U16((data), (pos), (uint16_t)((uint32_t)(val) & 0xffff)), PUSH_LE_U16((data), (pos) + 2, (uint16_t)((uint32_t)(val) >> 16)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PUSH_LE_U64(data, pos, val) \
|
|
Packit Service |
31306d |
(PUSH_LE_U32((data), (pos), (uint32_t)((uint64_t)(val) & 0xffffffff)), PUSH_LE_U32((data), (pos) + 4, (uint32_t)((uint64_t)(val) >> 32)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
/*
|
|
Packit Service |
31306d |
* These macros pull or push integer values from byte arrays stored in
|
|
Packit Service |
31306d |
* big-endian byte order (network byte order).
|
|
Packit Service |
31306d |
*/
|
|
Packit Service |
31306d |
#define PULL_BE_U8(data, pos) \
|
|
Packit Service |
31306d |
(_DATA_BYTE_CONST(data, pos))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PULL_BE_U16(data, pos) \
|
|
Packit Service |
31306d |
((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PULL_BE_U32(data, pos) \
|
|
Packit Service |
31306d |
((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PULL_BE_U64(data, pos) \
|
|
Packit Service |
31306d |
((((uint64_t)PULL_BE_U32(data, pos)) << 32) | (uint64_t)(PULL_BE_U32(data, (pos) + 4)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PUSH_BE_U8(data, pos, val) \
|
|
Packit Service |
31306d |
(_DATA_BYTE(data, pos) = ((uint8_t)(val)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PUSH_BE_U16(data, pos, val) \
|
|
Packit Service |
31306d |
(PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PUSH_BE_U32(data, pos, val) \
|
|
Packit Service |
31306d |
(PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#define PUSH_BE_U64(data, pos, val) \
|
|
Packit Service |
31306d |
(PUSH_BE_U32((data), (pos), (uint32_t)(((uint64_t)(val)) >> 32)), PUSH_BE_U32((data), (pos) + 4, (uint32_t)((val) & 0xffffffff)))
|
|
Packit Service |
31306d |
|
|
Packit Service |
31306d |
#endif /* _BYTEARRAY_H */
|