openbsd-ports/devel/libmtp/patches/patch-src_mtpz_c
brad 9ca15ca9f7 Update libmtp to 1.1.5.
Started by LEVAI Daniel and I patched it so it will build with older
GCC versions due to the use of __builtin_bswap32.

ok sthen@
2013-01-26 09:46:35 +00:00

79 lines
3.2 KiB
Plaintext

$OpenBSD: patch-src_mtpz_c,v 1.1 2013/01/26 09:46:35 brad Exp $
--- src/mtpz.c.orig Sun Sep 2 10:46:25 2012
+++ src/mtpz.c Mon Jan 14 10:41:14 2013
@@ -236,7 +236,7 @@ unsigned int mtpz_aes_gb9[];
#define MTPZ_ENCRYPTIONBYTE2(val) (((val) >> 8) & 0xFF)
#define MTPZ_ENCRYPTIONBYTE3(val) (((val) >> 0) & 0xFF)
-#define MTPZ_SWAP(x) __builtin_bswap32(x)
+#define MTPZ_SWAP(x) mtpz_bswap32(x)
void mtpz_encryption_cipher(unsigned char *data, unsigned int len, char encrypt);
void mtpz_encryption_cipher_advanced(unsigned char *key, unsigned int key_len, unsigned char *data, unsigned int data_len, char encrypt);
@@ -248,6 +248,17 @@ void mtpz_encryption_encrypt_custom(unsigned char *dat
void mtpz_encryption_encrypt_mac(unsigned char *hash, unsigned int hash_length, unsigned char *seed, unsigned int seed_len, unsigned char *out);
+static inline uint32_t mtpz_bswap32(uint32_t x)
+{
+#if defined __GNUC__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) || defined(__clang__)
+ return __builtin_bswap32(x)
+#else
+ return (x >> 24) |
+ ((x >> 8) & 0x0000ff00) |
+ ((x << 8) & 0x00ff0000) |
+ (x << 24);
+#endif
+}
/* MTPZ RSA implementation */
@@ -1574,11 +1585,11 @@ ptp_mtpz_validatehandshakeresponse (PTPParams* params,
mtpz_encryption_cipher_advanced((unsigned char *)hash_key, 16, act_msg, 832, 0);
act_reader++;
- unsigned int certs_length = __builtin_bswap32(*(unsigned int *)(act_reader));
+ unsigned int certs_length = MTPZ_SWAP(*(unsigned int *)(act_reader));
act_reader += 4;
act_reader += certs_length;
- unsigned int rand_length = __builtin_bswap32(*(unsigned short *)(act_reader) << 16);
+ unsigned int rand_length = MTPZ_SWAP(*(unsigned short *)(act_reader) << 16);
act_reader += 2;
unsigned char *rand_data = (unsigned char *)malloc(rand_length);
memcpy(rand_data, act_reader, rand_length);
@@ -1590,19 +1601,19 @@ ptp_mtpz_validatehandshakeresponse (PTPParams* params,
free(rand_data);
act_reader += rand_length;
- unsigned int dev_rand_length = __builtin_bswap32(*(unsigned short *)(act_reader) << 16);
+ unsigned int dev_rand_length = MTPZ_SWAP(*(unsigned short *)(act_reader) << 16);
act_reader += 2;
act_reader += dev_rand_length;
act_reader++;
- unsigned int sig_length = __builtin_bswap32(*(unsigned short *)(act_reader) << 16);
+ unsigned int sig_length = MTPZ_SWAP(*(unsigned short *)(act_reader) << 16);
act_reader += 2;
act_reader += sig_length;
act_reader++;
- unsigned int machash_length = __builtin_bswap32(*(unsigned short *)(act_reader) << 16);
+ unsigned int machash_length = MTPZ_SWAP(*(unsigned short *)(act_reader) << 16);
act_reader += 2;
unsigned char *machash_data = (unsigned char *)malloc(machash_length);
memcpy(machash_data, act_reader, machash_length);
@@ -1636,8 +1647,8 @@ ptp_mtpz_opensecuresyncsession (PTPParams* params, uns
mtpz_encryption_encrypt_mac(hash, 16, (unsigned char *)(&macCount), 4, mch);
ret = ptp_mtpz_wmdrmpd_enabletrustedfilesoperations(params,
- __builtin_bswap32(hashparams[0]), __builtin_bswap32(hashparams[1]),
- __builtin_bswap32(hashparams[2]), __builtin_bswap32(hashparams[3]));
+ MTPZ_SWAP(hashparams[0]), MTPZ_SWAP(hashparams[1]),
+ MTPZ_SWAP(hashparams[2]), MTPZ_SWAP(hashparams[3]));
return ret;
};