lbn.h
上传用户:zbbssh
上传日期:2007-01-08
资源大小:196k
文件大小:4k
源码类别:

CA认证

开发平台:

C/C++

  1. /*
  2.  * lbn.h - Low-level bignum header.
  3.  * Defines various word sizes and useful macros.
  4.  *
  5.  * Copyright (c) 1995  Colin Plumb.  All rights reserved.
  6.  * For licensing and other legal details, see the file legal.c.
  7.  */
  8. #ifndef LBN_H
  9. #define LBN_H
  10. #if HAVE_CONFIG_H
  11. #include "config.h"
  12. #endif
  13. #if !NO_LIMITS_H
  14. #include <limits.h>
  15. #if UCHAR_MAX != 0xff || CHAR_BIT != 8
  16. #error The bignum library requires 8-bit unsigned characters.
  17. #endif
  18. #endif
  19. #ifdef BNINCLUDE /* If this is defined as, say, foo.h */
  20. #define STR(x) #x /* STR(BNINCLUDE) -> "BNINCLUDE" */
  21. #define XSTR(x) STR(x) /* XSTR(BNINCLUDE) -> STR(foo.h) -> "foo.h" */
  22. #include XSTR(BNINCLUDE) /* #include "foo.h" */
  23. #undef XSTR
  24. #undef STR
  25. #endif
  26. /* Figure out the endianness */
  27. /* Error if more than one is defined */
  28. #if BN_BIG_ENDIAN && BN_LITTLE_ENDIAN
  29. #error Only one of BN_BIG_ENDIAN or BN_LITTLE_ENDIAN may be defined
  30. #endif
  31. /*
  32.  * If no preference is stated, little-endian C code is slightly more
  33.  * efficient, so prefer that.  (The endianness here does NOT have to
  34.  * match the machine's native byte sex; the library's C code will work
  35.  * either way.  The flexibility is allowed for assembly routines
  36.  * that do care.
  37.  */
  38. #if !defined(BN_BIG_ENDIAN) && !defined(BN_LITTLE_ENDIAN)
  39. #define BN_LITTLE_ENDIAN 1
  40. #endif /* !BN_BIG_ENDIAN && !BN_LITTLE_ENDIAN */
  41. /* Macros to choose between big and little endian */
  42. #if BN_BIG_ENDIAN
  43. #define BIG(b) b
  44. #define LITTLE(l) /*nothing*/
  45. #define BIGLITTLE(b,l) b
  46. #elif BN_LITTLE_ENDIAN
  47. #define BIG(b) /*nothing*/
  48. #define LITTLE(l) l
  49. #define BIGLITTLE(b,l) l
  50. #else
  51. #error One of BN_BIG_ENDIAN or BN_LITTLE_ENDIAN must be defined as 1
  52. #endif
  53. /*
  54.  * Find a 16-bit unsigned type.
  55.  * Unsigned short is preferred over unsigned int to make the type chosen
  56.  * by this file more stable on platforms (such as many 68000 compilers)
  57.  * which support both 16- and 32-bit ints.
  58.  */
  59. #ifndef BNWORD16
  60. #ifndef USHRT_MAX /* No <limits.h> available - guess */
  61. typedef unsigned short bnword16;
  62. #define BNWORD16 bnword16
  63. #elif USHRT_MAX == 0xffff
  64. typedef unsigned short bnword16;
  65. #define BNWORD16 bnword16
  66. #elif UINT_MAX == 0xffff
  67. typedef unsigned bnword16;
  68. #define BNWORD16 bnword16
  69. #endif
  70. #endif /* BNWORD16 */
  71. /*
  72.  * Find a 32-bit unsigned type.
  73.  * Unsigned long is preferred over unsigned int to make the type chosen
  74.  * by this file more stable on platforms (such as many 68000 compilers)
  75.  * which support both 16- and 32-bit ints.
  76.  */
  77. #ifndef BNWORD32
  78. #ifndef ULONG_MAX /* No <limits.h> available - guess */
  79. typedef unsigned long bnword32;
  80. #define BNWORD32 bnword32
  81. #elif ULONG_MAX == 0xffffffffu
  82. typedef unsigned long bnword32;
  83. #define BNWORD32 bnword32
  84. #elif UINT_MAX == 0xffffffffu
  85. typedef unsigned bnword32;
  86. #define BNWORD32 bnword32
  87. #elif USHRT_MAX == 0xffffffffu
  88. typedef unsigned short bnword32;
  89. #define BNWORD32 bnword32
  90. #endif
  91. #endif /* BNWORD16 */
  92. /*
  93.  * Find a 64-bit unsigned type.
  94.  * The conditions here are more complicated to avoid using numbers that
  95.  * will choke lesser preprocessors (like 0xffffffffffffffff) unless
  96.  * we're reasonably certain that they'll be acceptable.
  97.  */
  98. #if !defined(BNWORD64) && ULONG_MAX > 0xffffffffu
  99. #if ULONG_MAX == 0xffffffffffffffffu
  100. typedef unsigned long bnword64;
  101. #define BNWORD64 bnword64
  102. #endif
  103. #endif
  104. /*
  105.  * I would test the value of unsigned long long, but some *preprocessors*
  106.  * don't constants that long even if the compiler can accept them, so it
  107.  * doesn't work reliably.  So cross our fingers and hope that it's a 64-bit
  108.  * type.
  109.  *
  110.  * GCC uses ULONG_LONG_MAX.  Solaris uses ULLONG_MAX.  IRIX uses ULONGLONG_MAX.
  111.  * Are there any other names for this?
  112.  */
  113. #if !defined(BNWORD64) && 
  114.     (defined(ULONG_LONG_MAX) || defined (ULLONG_MAX) || defined(ULONGLONG_MAX))
  115. typedef unsigned long long bnword64;
  116. #define BNWORD64 bnword64
  117. #endif
  118. /* We don't even try to find a 128-bit type at the moment */
  119. #endif /* !LBN_H */