This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] sha2: new header <sha2.h>
- From: Rich Felker <dalias at libc dot org>
- To: libc-alpha at sourceware dot org
- Date: Sat, 28 Mar 2015 01:41:02 -0400
- Subject: Re: [PATCH] sha2: new header <sha2.h>
- Authentication-results: sourceware.org; auth=none
- References: <CAJusiZVeSiuBJ1NuWw9KU2fboKcz6-9s6YhiTHVga5GyW-bbFw at mail dot gmail dot com> <1427492368-3482458-1-git-send-email-shawn at churchofgit dot com> <20150328034628 dot GC27135 at vapier>
On Fri, Mar 27, 2015 at 11:46:28PM -0400, Mike Frysinger wrote:
> > --- /dev/null
> > +++ b/crypt/align.h
> >
> > +#define put_be32(p, v) do { *(uint32_t *)(p) = be32toh(v); } while (0)
> > +#define put_be64(p, v) do { *(uint64_t *)(p) = be64toh(v); } while (0)
> > +#define put_be32(p, v) do { \
> > + unsigned int __v = (v); \
> > + *((unsigned char *)(p) + 0) = __v >> 24; \
> > + *((unsigned char *)(p) + 1) = __v >> 16; \
> > + *((unsigned char *)(p) + 2) = __v >> 8; \
> > + *((unsigned char *)(p) + 3) = __v >> 0; } while (0)
> > +#define put_be64(p, v) do { \
> > + unsigned int __v = (v); \
> > + *((unsigned char *)(p) + 0) = __v >> 56; \
> > + *((unsigned char *)(p) + 1) = __v >> 48; \
> > + *((unsigned char *)(p) + 2) = __v >> 40; \
> > + *((unsigned char *)(p) + 3) = __v >> 32; \
> > + *((unsigned char *)(p) + 4) = __v >> 24; \
> > + *((unsigned char *)(p) + 5) = __v >> 16; \
> > + *((unsigned char *)(p) + 6) = __v >> 8; \
> > + *((unsigned char *)(p) + 7) = __v >> 0; } while (0)
>
> these are like ... really bad. they violate strict aliasing so hard. just use
> the macros already available in endian.h. like htobe32 and htobe64. which you
> seem to use elsewhere in this patch already ;).
No they don't. This is legal access of the representation. It's no
different than if you'd used memcpy. OTOH I agree it's ugly.
Rich