2009-07-23 Pavel Roskin <proski@gnu.org>
+ * commands/xnu_uuid.c (transform): Use GRUB_CPU_WORDS_BIGENDIAN
+ instead of WORDS_BIGENDIAN. Use grub_le_to_cpu32(), so that the
+ case of little endian words becomes just an optimization.
+ Respect const modifier.
+ (md5_final): Use code that doesn't depend on endianess.
+
* include/grub/misc.h (ALIGN_UP): Cast align to the type of addr
to avoid loss of upper bits if align is unsigned and shorter
than addr.
register grub_uint32_t D = ctx->D;
grub_uint32_t *cwp = correct_words;
-#ifdef WORDS_BIGENDIAN
- {
+#ifdef GRUB_CPU_WORDS_BIGENDIAN
+ {
int i;
- grub_uint8_t *p2, *p1;
- for(i=0, p1=data, p2=(grub_uint8_t*)correct_words; i < 16; i++, p2 += 4 )
- {
- p2[3] = *p1++;
- p2[2] = *p1++;
- p2[1] = *p1++;
- p2[0] = *p1++;
- }
+ const grub_uint32_t *p = (const grub_uint32_t *) data;
+
+ for (i = 0; i < 16; i++)
+ correct_words[i] = grub_le_to_cpu32 (p[i]);
}
#else
- memcpy( correct_words, data, 64 );
+ memcpy (correct_words, data, 64);
#endif
#define OP(a, b, c, d, s, T) \
{
MD5_CONTEXT *hd = context;
grub_uint32_t t, msb, lsb;
- grub_uint8_t *p;
+ grub_uint32_t *p;
md5_write(hd, NULL, 0); /* flush */;
transform( hd, hd->buf );
// _gcry_burn_stack (80+6*sizeof(void*));
- p = hd->buf;
-#ifdef WORDS_BIGENDIAN
-#define X(a) do { *p++ = hd->a ; *p++ = hd->a >> 8; \
- *p++ = hd->a >> 16; *p++ = hd->a >> 24; } while(0)
-#else /* little endian */
-#define X(a) do { *(grub_uint32_t*)p = (*hd).a ; p += 4; } while(0)
-#endif
+ p = (grub_uint32_t *) hd->buf;
+#define X(a) do { *p = grub_le_to_cpu32 (hd->a); p++; } while (0)
X(A);
X(B);
X(C);