This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] sha2: new header <sha2.h>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]