Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type cleanups for htons and byte swap #326

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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