diff --git a/lib/ngtcp2_conv.c b/lib/ngtcp2_conv.c index 319dd14a9b9d4fa3ce5d131868c61e8ce18f5846..5318468537884548193d8a38523e1b30310c535c 100644 --- a/lib/ngtcp2_conv.c +++ b/lib/ngtcp2_conv.c @@ -34,13 +34,13 @@ uint64_t ngtcp2_get_uint64(const uint8_t *p) { uint64_t n; memcpy(&n, p, 8); - return bswap64(n); + return ngtcp2_ntohl64(n); } uint64_t ngtcp2_get_uint48(const uint8_t *p) { uint64_t n = 0; memcpy(((uint8_t *)&n) + 2, p, 6); - return bswap64(n); + return ngtcp2_ntohl64(n); } uint32_t ngtcp2_get_uint32(const uint8_t *p) { @@ -85,7 +85,7 @@ uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p) { case 8: memcpy(&n, p, 8); n.b[0] &= 0x3f; - return bswap64(n.n64); + return ngtcp2_ntohl64(n.n64); } assert(0); @@ -107,12 +107,12 @@ int64_t ngtcp2_get_pkt_num(const uint8_t *p, size_t pkt_numlen) { } uint8_t *ngtcp2_put_uint64be(uint8_t *p, uint64_t n) { - n = bswap64(n); + n = ngtcp2_htonl64(n); return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n)); } uint8_t *ngtcp2_put_uint48be(uint8_t *p, uint64_t n) { - n = bswap64(n); + n = ngtcp2_htonl64(n); return ngtcp2_cpymem(p, ((const uint8_t *)&n) + 2, 6); } diff --git a/lib/ngtcp2_conv.h b/lib/ngtcp2_conv.h index c70d42cfc4cbf5b582e6032ae312d337da3ca182..d902aede04a22d3abfd46b4903a797c727a47fb1 100644 --- a/lib/ngtcp2_conv.h +++ b/lib/ngtcp2_conv.h @@ -36,10 +36,13 @@ #include <ngtcp2/ngtcp2.h> #ifdef WORDS_BIGENDIAN -# define bswap64(N) (N) +# define ngtcp2_ntohl64(N) (N) +# define ngtcp2_htonl64(N) (N) #else /* !WORDS_BIGENDIAN */ -# define bswap64(N) \ +# define ngtcp2_bswap64(N) \ ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32))) +# define ngtcp2_ntohl64(N) ngtcp2_bswap64(N) +# define ngtcp2_htonl64(N) ngtcp2_bswap64(N) #endif /* !WORDS_BIGENDIAN */ /* diff --git a/lib/ngtcp2_crypto.c b/lib/ngtcp2_crypto.c index 40248126eb679c7c4b1c56a6fff1f184dad31566..0bdbedaad03b235eff898f47e7d0bacdf5c65abb 100644 --- a/lib/ngtcp2_crypto.c +++ b/lib/ngtcp2_crypto.c @@ -72,7 +72,7 @@ void ngtcp2_crypto_create_nonce(uint8_t *dest, const uint8_t *iv, size_t ivlen, uint64_t n; memcpy(dest, iv, ivlen); - n = bswap64((uint64_t)pkt_num); + n = ngtcp2_htonl64((uint64_t)pkt_num); for (i = 0; i < 8; ++i) { dest[ivlen - 8 + i] ^= ((uint8_t *)&n)[i]; diff --git a/lib/ngtcp2_map.c b/lib/ngtcp2_map.c index fd4757dbb60b6d15311eb52597b747fc92c8a5af..756b3ffeed14bcc0252516596c94e02ae7f906be 100644 --- a/lib/ngtcp2_map.c +++ b/lib/ngtcp2_map.c @@ -92,7 +92,9 @@ static uint32_t hash(key_type key, uint32_t mod) { uint8_t *p, *end; uint32_t h = 0x811C9DC5u; - key = bswap64(key); +#ifndef WORDS_BIGENDIAN + key = ngtcp2_bswap64(key); +#endif /* !WORDS_BIGENDIAN */ p = (uint8_t *)&key; end = p + sizeof(key_type);