Nikos Mavrogiannopoulos nmav@gnutls.org writes:
Do you mean something like: struct gcm_cast_st { struct gcm_key key; struct gcm_ctx gcm; char xx[1]; }; #define GCM_CTX_GET_KEY(ptr) (&((struct gcm_cast_st*)ptr)->key) #define GCM_CTX_GET_CTX(ptr) (&((struct gcm_cast_st*)ptr)->gcm) #define GCM_CTX_GET_CIPHER(ptr) ((void*)&((struct gcm_cast_st*)ptr)->xx)
It looks indeed simpler. Not sure how valid is the GCM_CTX_GET_CIPHER cast though. It would be nice if nettle's gcm.h provided such macros.
Only potential problem I see is alignment. You could make it an unsigned long array rather than a char array. And I'd drop the GET_KEY and GET_CTX macros; they're perfectly normal struct accesses.
You could perhaps use GCM_CTX, from nettle/gcm.h, with a generic cipher type, say
struct gcm_st GCM_CTX(unsigned long);
but I'm not sure that's better than making your own. Of the other GCM_* macros in nettle/gcm.h, I think they might work with the above context, provided that the passed in encrypt function takes a void * (or const void *) as the first argument.
Regards, /Niels