Skip to content

Commit

Permalink
Merge pull request #326 from dgarske/htons
Browse files Browse the repository at this point in the history
Type cleanups for htons and byte swap
  • Loading branch information
lealem47 authored Jan 29, 2024
2 parents 0adf473 + a2a45d2 commit 0b3448c
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions wolftpm/tpm2_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ typedef int64_t INT64;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>

#ifdef WOLFTPM_USER_SETTINGS
#include "user_settings.h"
Expand Down Expand Up @@ -231,20 +230,6 @@ typedef int64_t INT64;
#ifndef WOLFTPM_CUSTOM_TYPES
#include <stdlib.h>

#ifndef XHTONS
/* WOLFCRYPT_ONLY means no wolfio and no arpa/inet.h */
#ifdef WOLFCRYPT_ONLY
#ifdef BIG_ENDIAN_ORDER
#define XHTONS(s) (s)
#else
#define XHTONS(s) ((((s) & 0xff) << 8) | (((s) & 0xff00) >> 8))
#endif
#else
#include <arpa/inet.h>
#define XHTONS(s) htons((s))
#endif
#endif

#define XSTRTOL(s,e,b) strtol((s),(e),(b))
#define XATOI(s) atoi((s))

Expand Down Expand Up @@ -718,7 +703,7 @@ static inline word16 ByteReverseWord16(word16 value)

static inline word32 ByteReverseWord32(word32 value)
{
#if !defined(WOLF_NO_BUILTIN) && defined(__GNUC_PREREQ) && __GNUC_PREREQ(4, 3)
#if defined(WOLF_ALLOW_BUILTIN) && defined(__GNUC_PREREQ) && __GNUC_PREREQ(4, 3)
return (word32)__builtin_bswap32(value);
#elif defined(PPC_INTRINSICS)
/* PPC: load reverse indexed instruction */
Expand Down Expand Up @@ -758,7 +743,7 @@ static inline word32 ByteReverseWord32(word32 value)

static inline word64 ByteReverseWord64(word64 value)
{
#if !defined(WOLF_NO_BUILTIN) && defined(__GNUC_PREREQ) && __GNUC_PREREQ(4, 3)
#if defined(WOLF_ALLOW_BUILTIN) && defined(__GNUC_PREREQ) && __GNUC_PREREQ(4, 3)
return (word64)__builtin_bswap64(value);
#else
return (word64)((word64)ByteReverseWord32((word32)value)) << 32 |
Expand Down

0 comments on commit 0b3448c

Please sign in to comment.