openbsd-ports/devel/libmtp/patches/patch-src_mtpz_c
2013-03-29 23:39:13 +00:00

79 lines
3.2 KiB
Plaintext

$OpenBSD: patch-src_mtpz_c,v 1.2 2013/03/29 23:39:13 brad Exp $
--- src/mtpz.c.orig Fri Mar 15 02:34:22 2013
+++ src/mtpz.c Fri Mar 15 18:31:28 2013
@@ -238,7 +238,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);
@@ -250,6 +250,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 */
@@ -1576,11 +1587,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);
@@ -1592,19 +1603,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);
@@ -1638,8 +1649,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;
};