/* externs.h - System-specific declarations */ #include #include /* Define our own set of types */ #undef quad #define quad long long #define bool _Bool typedef char s8; typedef short s16; typedef int s32; typedef quad s64; typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; typedef unsigned quad u64; /* Provide 64-bit versions of htonl()/ntohl() */ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ # define htonll(q) __builtin_bswap64(q) # define ntohll(q) __builtin_bswap64(q) #else # define htonll(q) (q) # define ntohll(q) (q) #endif /* Rotate a 32-bit word right or left */ #define ROR(x,n) ({ unsigned int _x=(x), _n=(n); (_x >> _n) | (_x << (32-_n)); }) #define ROL(x,n) ({ unsigned int _x=(x), _n=(n); (_x << _n) | (_x >> (32-_n)); }) /* SHA-256 algorithm context */ struct sha256_context { u64 total; int state[8]; char buffer[64]; }; /* Use packed structures for unaligned access */ typedef struct { u16 _x; } __attribute__((packed)) uu16; typedef struct { u32 _x; } __attribute__((packed)) uu32; typedef struct { u64 _x; } __attribute__((packed)) uu64; /* Macros to read big-endian integers and strings from a character stream */ #define get8(p) (*(u8 *)p++) #define get16(p) ({ u16 _x=ntohs(((uu16 *)p)->_x); p+=2; _x; }) #define get32(p) ({ u32 _x=ntohl(((uu32 *)p)->_x); p+=4; _x; }) #define get64(p) ({ u64 _x=ntohll(((uu64 *)p)->_x); p+=8; _x; }) /* Macros to write big-endian integers and strings to a character stream */ #define put8(p,x) (void)({ *p++=(x); }) #define put16(p,x) (void)({ uu16 *_p=(uu16 *)p; _p->_x=htons(x); p+=2; }) #define put32(p,x) (void)({ uu32 *_p=(uu32 *)p; _p->_x=htonl(x); p+=4; }) #define put64(p,x) (void)({ uu64 *_p=(uu64 *)p; _p->_x=htonll(x); p+=8; })