diff options
author | Ken Raeburn <raeburn@mit.edu> | 2003-12-13 06:28:35 +0000 |
---|---|---|
committer | Ken Raeburn <raeburn@mit.edu> | 2003-12-13 06:28:35 +0000 |
commit | a87606b8e2b12a6a5260539a5544f55fb81d53bc (patch) | |
tree | 6417250436c25f4dc42f0142d211872c57ca1ba2 /src/include/k5-platform.h | |
parent | 7943823ea88ccb7e5a2b9e1981f1f601ba261af5 (diff) | |
download | krb5-a87606b8e2b12a6a5260539a5544f55fb81d53bc.tar.gz krb5-a87606b8e2b12a6a5260539a5544f55fb81d53bc.tar.xz krb5-a87606b8e2b12a6a5260539a5544f55fb81d53bc.zip |
Add platform-dependent 64-bit and inline-function support via new header
k5-platform.h. Add 64-bit serializer support. [Not needed for ticket 1471,
but needed for 2040 and annoying to check in separately.]
Add to (internal for now) crypto API a function to get the mandatory checksum
type associated with an enctype.
New support for server-generated subkey, selected via an auth_context flag.
ticket: 1471
status: open
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15908 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/include/k5-platform.h')
-rw-r--r-- | src/include/k5-platform.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h new file mode 100644 index 0000000000..e6d2ad0e47 --- /dev/null +++ b/src/include/k5-platform.h @@ -0,0 +1,136 @@ +/* Copyright 2003 Massachusetts Institute of Technology. All rights reserved. */ +/* Platform-dependent junk. */ + +#ifndef K5_PLATFORM_H +#define K5_PLATFORM_H + +#if !defined(inline) +# if __STDC_VERSION__ >= 199901L +/* C99 supports inline, don't do anything. */ +# elif defined(__GNUC__) +# define inline __inline__ /* this form silences -pedantic warnings */ +# elif defined(__mips) && defined(__sgi) +# define inline __inline /* IRIX used at MIT does inline but not c99 yet */ +# elif defined(__sun) && __SUNPRO_C >= 0x540 +/* The Forte Developer 7 C compiler supports "inline". */ +# elif defined(_WIN32) +# define inline __inline +# else +# define inline /* nothing, just static */ +# endif +#endif + +#include "autoconf.h" + +/* 64-bit support: krb5_ui_8 and krb5_int64. + + This should move to krb5.h eventually, but without the namespace + pollution from the autoconf macros. */ +#if defined(HAVE_STDINT_H) || defined(HAVE_INTTYPES_H) +# ifdef HAVE_STDINT_H +# include <stdint.h> +# endif +# ifdef HAVE_INTTYPES_H +# include <inttypes.h> +# endif +# define INT64_TYPE int64_t +# define UINT64_TYPE uint64_t +#elif defined(_WIN32) +# define INT64_TYPE signed __int64 +# define UINT64_TYPE unsigned __int64 +#else /* not Windows, and neither stdint.h nor inttypes.h */ +# define INT64_TYPE signed long long +# define UINT64_TYPE unsigned long long +#endif + +/* Read and write integer values as (unaligned) octet strings in + specific byte orders. + + Add per-platform optimizations later if needed. (E.g., maybe x86 + unaligned word stores and gcc/asm instructions for byte swaps, + etc.) */ + +static inline void +store_16_be (unsigned int val, unsigned char *p) +{ + p[0] = (val >> 8) & 0xff; + p[1] = (val ) & 0xff; +} +static inline void +store_16_le (unsigned int val, unsigned char *p) +{ + p[1] = (val >> 8) & 0xff; + p[0] = (val ) & 0xff; +} +static inline void +store_32_be (unsigned int val, unsigned char *p) +{ + p[0] = (val >> 24) & 0xff; + p[1] = (val >> 16) & 0xff; + p[2] = (val >> 8) & 0xff; + p[3] = (val ) & 0xff; +} +static inline void +store_32_le (unsigned int val, unsigned char *p) +{ + p[3] = (val >> 24) & 0xff; + p[2] = (val >> 16) & 0xff; + p[1] = (val >> 8) & 0xff; + p[0] = (val ) & 0xff; +} +static inline void +store_64_be (UINT64_TYPE val, unsigned char *p) +{ + p[0] = (val >> 56) & 0xff; + p[1] = (val >> 48) & 0xff; + p[2] = (val >> 40) & 0xff; + p[3] = (val >> 32) & 0xff; + p[4] = (val >> 24) & 0xff; + p[5] = (val >> 16) & 0xff; + p[6] = (val >> 8) & 0xff; + p[7] = (val ) & 0xff; +} +static inline void +store_64_le (UINT64_TYPE val, unsigned char *p) +{ + p[7] = (val >> 56) & 0xff; + p[6] = (val >> 48) & 0xff; + p[5] = (val >> 40) & 0xff; + p[4] = (val >> 32) & 0xff; + p[3] = (val >> 24) & 0xff; + p[2] = (val >> 16) & 0xff; + p[1] = (val >> 8) & 0xff; + p[0] = (val ) & 0xff; +} +static inline unsigned short +load_16_be (unsigned char *p) +{ + return (p[1] | (p[0] << 8)); +} +static inline unsigned short +load_16_le (unsigned char *p) +{ + return (p[0] | (p[1] << 8)); +} +static inline unsigned int +load_32_be (unsigned char *p) +{ + return (p[3] | (p[2] << 8) | (p[1] << 16) | (p[0] << 24)); +} +static inline unsigned int +load_32_le (unsigned char *p) +{ + return (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24)); +} +static inline UINT64_TYPE +load_64_be (unsigned char *p) +{ + return ((UINT64_TYPE)load_32_be(p) << 32) | load_32_be(p+4); +} +static inline UINT64_TYPE +load_64_le (unsigned char *p) +{ + return ((UINT64_TYPE)load_32_le(p+4) << 32) | load_32_le(p); +} + +#endif /* K5_PLATFORM_H */ |