archive_hmac_private.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*-
  2. * Copyright (c) 2014 Michihiro NAKAJIMA
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef __LIBARCHIVE_BUILD
  26. #error This header is only to be used internally to libarchive.
  27. #endif
  28. #ifndef ARCHIVE_HMAC_PRIVATE_H_INCLUDED
  29. #define ARCHIVE_HMAC_PRIVATE_H_INCLUDED
  30. /*
  31. * On systems that do not support any recognized crypto libraries,
  32. * the archive_hmac.c file is expected to define no usable symbols.
  33. *
  34. * But some compilers and linkers choke on empty object files, so
  35. * define a public symbol that will always exist. This could
  36. * be removed someday if this file gains another always-present
  37. * symbol definition.
  38. */
  39. int __libarchive_hmac_build_hack(void);
  40. #ifdef __APPLE__
  41. # include <AvailabilityMacros.h>
  42. # if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
  43. # define ARCHIVE_HMAC_USE_Apple_CommonCrypto
  44. # endif
  45. #endif
  46. #ifdef ARCHIVE_HMAC_USE_Apple_CommonCrypto
  47. #include <CommonCrypto/CommonHMAC.h>
  48. typedef CCHmacContext archive_hmac_sha1_ctx;
  49. #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H)
  50. #include <bcrypt.h>
  51. typedef struct {
  52. BCRYPT_ALG_HANDLE hAlg;
  53. BCRYPT_HASH_HANDLE hHash;
  54. DWORD hash_len;
  55. PBYTE hash;
  56. } archive_hmac_sha1_ctx;
  57. #elif defined(HAVE_LIBNETTLE) && defined(HAVE_NETTLE_HMAC_H)
  58. #include <nettle/hmac.h>
  59. typedef struct hmac_sha1_ctx archive_hmac_sha1_ctx;
  60. #elif defined(HAVE_LIBCRYPTO)
  61. #include "archive_openssl_hmac_private.h"
  62. typedef HMAC_CTX* archive_hmac_sha1_ctx;
  63. #else
  64. typedef int archive_hmac_sha1_ctx;
  65. #endif
  66. /* HMAC */
  67. #define archive_hmac_sha1_init(ctx, key, key_len)\
  68. __archive_hmac.__hmac_sha1_init(ctx, key, key_len)
  69. #define archive_hmac_sha1_update(ctx, data, data_len)\
  70. __archive_hmac.__hmac_sha1_update(ctx, data, data_len)
  71. #define archive_hmac_sha1_final(ctx, out, out_len)\
  72. __archive_hmac.__hmac_sha1_final(ctx, out, out_len)
  73. #define archive_hmac_sha1_cleanup(ctx)\
  74. __archive_hmac.__hmac_sha1_cleanup(ctx)
  75. struct archive_hmac {
  76. /* HMAC */
  77. int (*__hmac_sha1_init)(archive_hmac_sha1_ctx *, const uint8_t *,
  78. size_t);
  79. void (*__hmac_sha1_update)(archive_hmac_sha1_ctx *, const uint8_t *,
  80. size_t);
  81. void (*__hmac_sha1_final)(archive_hmac_sha1_ctx *, uint8_t *, size_t *);
  82. void (*__hmac_sha1_cleanup)(archive_hmac_sha1_ctx *);
  83. };
  84. extern const struct archive_hmac __archive_hmac;
  85. #endif /* ARCHIVE_HMAC_PRIVATE_H_INCLUDED */