You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

79 lines
2.1 KiB

  1. /**
  2. * @file decaf_common.h
  3. * @author Mike Hamburg
  4. *
  5. * @copyright
  6. * Copyright (c) 2015 Cryptography Research, Inc. \n
  7. * Released under the MIT License. See LICENSE.txt for license information.
  8. *
  9. * @brief Common utility headers for Decaf library.
  10. */
  11. #ifndef __DECAF_COMMON_H__
  12. #define __DECAF_COMMON_H__ 1
  13. #include <stdint.h>
  14. #include <sys/types.h>
  15. /* Goldilocks' build flags default to hidden and stripping executables. */
  16. /** @cond internal */
  17. #if defined(DOXYGEN) && !defined(__attribute__)
  18. #define __attribute__((x))
  19. #endif
  20. #define API_VIS __attribute__((visibility("default")))
  21. #define NOINLINE __attribute__((noinline))
  22. #define WARN_UNUSED __attribute__((warn_unused_result))
  23. #define NONNULL1 __attribute__((nonnull(1)))
  24. #define NONNULL2 __attribute__((nonnull(1,2)))
  25. #define NONNULL3 __attribute__((nonnull(1,2,3)))
  26. #define NONNULL13 __attribute__((nonnull(1,3)))
  27. #define NONNULL4 __attribute__((nonnull(1,2,3,4)))
  28. #define NONNULL5 __attribute__((nonnull(1,2,3,4,5)))
  29. /** @endcond */
  30. /* Internal word types */
  31. #if (defined(__ILP64__) || defined(__amd64__) || defined(__x86_64__) || (((__UINT_FAST32_MAX__)>>30)>>30)) \
  32. && !defined(DECAF_FORCE_32_BIT)
  33. #define DECAF_WORD_BITS 64
  34. typedef uint64_t decaf_word_t, decaf_bool_t;
  35. typedef __uint128_t decaf_dword_t;
  36. #else
  37. #define DECAF_WORD_BITS 32
  38. typedef uint32_t decaf_word_t, decaf_bool_t;
  39. typedef uint64_t decaf_dword_t;
  40. #endif
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /** DECAF_TRUE = -1 so that DECAF_TRUE & x = x */
  45. static const decaf_bool_t DECAF_TRUE = -(decaf_bool_t)1, DECAF_FALSE = 0;
  46. /** NB Success is -1, failure is 0. */
  47. static const decaf_bool_t DECAF_SUCCESS = -(decaf_bool_t)1 /*DECAF_TRUE*/,
  48. DECAF_FAILURE = 0 /*DECAF_FALSE*/;
  49. /**
  50. * @brief Overwrite data with zeros. Uses memset_s if available.
  51. */
  52. void decaf_bzero (
  53. void *data,
  54. size_t size
  55. ) NONNULL1 API_VIS;
  56. /**
  57. * @brief Compare two buffers, returning DECAF_TRUE if they are equal.
  58. */
  59. decaf_bool_t decaf_memeq (
  60. const void *data1,
  61. const void *data2,
  62. size_t size
  63. ) NONNULL2 WARN_UNUSED API_VIS;
  64. #ifdef __cplusplus
  65. } /* extern "C" */
  66. #endif
  67. #endif /* __DECAF_COMMON_H__ */