summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpiano/src/crypt.c12
-rw-r--r--src/player.c8
2 files changed, 12 insertions, 8 deletions
diff --git a/libpiano/src/crypt.c b/libpiano/src/crypt.c
index ef0b2dc..e94a54d 100644
--- a/libpiano/src/crypt.c
+++ b/libpiano/src/crypt.c
@@ -25,6 +25,7 @@ THE SOFTWARE.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <arpa/inet.h>
#include "crypt_key_output.h"
#include "crypt_key_input.h"
@@ -35,6 +36,9 @@ THE SOFTWARE.
(((x) << 8) & 0x00ff0000) | \
(((x) << 24) & 0xff000000))
+#define hostToBigEndian32(x) htonl(x)
+#define bigToHostEndian32(x) ntohl(x)
+
/* decrypt hex-encoded, blowfish-crypted string: decode 2 hex-encoded blocks,
* decrypt, byteswap
* @param hex string
@@ -98,8 +102,8 @@ unsigned char *PianoDecryptString (const unsigned char *strInput) {
r ^= in_key_p [1];
l ^= in_key_p [0];
- *(iDecrypt-2) = byteswap32 (l);
- *(iDecrypt-1) = byteswap32 (r);
+ *(iDecrypt-2) = bigToHostEndian32 (l);
+ *(iDecrypt-1) = bigToHostEndian32 (r);
intsDecoded = 0;
}
@@ -142,8 +146,8 @@ unsigned char *PianoEncryptString (const unsigned char *strInput) {
register uint32_t l, r;
int i;
- l = byteswap32 (*blockPtr);
- r = byteswap32 (*(blockPtr+1));
+ l = hostToBigEndian32 (*blockPtr);
+ r = hostToBigEndian32 (*(blockPtr+1));
/* encrypt blocks */
for (i = 0; i < out_key_n; i++) {
diff --git a/src/player.c b/src/player.c
index 9a83256..18809bd 100644
--- a/src/player.c
+++ b/src/player.c
@@ -28,13 +28,13 @@ THE SOFTWARE.
#include <math.h>
#include <stdint.h>
#include <limits.h>
+#include <arpa/inet.h>
#include "player.h"
#include "config.h"
#include "ui.h"
-#define byteswap32(x) (((x >> 24) & 0x000000ff) | ((x >> 8) & 0x0000ff00) | \
- ((x << 8) & 0x00ff0000) | ((x << 24) & 0xff000000))
+#define bigToHostEndian32(x) ntohl(x)
/* wait while locked, but don't slow down main thread by keeping
* locks too long */
@@ -233,7 +233,7 @@ static WaitressCbReturn_t BarPlayerAACCb (void *ptr, size_t size, void *stream)
if (player->sampleSizeN == 0) {
/* mp4 uses big endian, convert */
player->sampleSizeN =
- byteswap32 (*((int *) (player->buffer +
+ bigToHostEndian32 (*((int *) (player->buffer +
player->bufferRead)));
player->sampleSize = calloc (player->sampleSizeN,
sizeof (player->sampleSizeN));
@@ -251,7 +251,7 @@ static WaitressCbReturn_t BarPlayerAACCb (void *ptr, size_t size, void *stream)
break;
} else {
player->sampleSize[player->sampleSizeCurr] =
- byteswap32 (*((int *) (player->buffer +
+ bigToHostEndian32 (*((int *) (player->buffer +
player->bufferRead)));
player->sampleSizeCurr++;
player->bufferRead += 4;