Files
odkitee/oemcrypto_ta/oemcrypto_endianness.c
2020-07-24 12:03:58 -07:00

27 lines
676 B
C

// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine Master
// License Agreement.
#include "oemcrypto_endianness.h"
#include <stdint.h>
#include <string.h>
uint32_t HostToNetworkU32(uint32_t host) {
uint8_t bytes[] = {
(uint8_t)(host >> 24u),
(uint8_t)(host >> 16u),
(uint8_t)(host >> 8u),
(uint8_t)(host >> 0u),
};
uint32_t network;
memcpy(&network, bytes, sizeof(network));
return network;
}
uint32_t NetworkToHostU32(uint32_t network) {
// These functions are symmetrical on any byte-ordering used in practice.
return HostToNetworkU32(network);
}