apr_sha1.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* NIST Secure Hash Algorithm
  17. * heavily modified by Uwe Hollerbach [email protected] edu
  18. * from Peter C. Gutmann's implementation as found in
  19. * Applied Cryptography by Bruce Schneier
  20. * This code is hereby placed in the public domain
  21. */
  22. #ifndef APR_SHA1_H
  23. #define APR_SHA1_H
  24. #include "apu.h"
  25. #include "apr_general.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * @file apr_sha1.h
  31. * @brief APR-UTIL SHA1 library
  32. */
  33. /** size of the SHA1 DIGEST */
  34. #define APR_SHA1_DIGESTSIZE 20
  35. /**
  36. * Define the Magic String prefix that identifies a password as being
  37. * hashed using our algorithm.
  38. */
  39. #define APR_SHA1PW_ID "{SHA}"
  40. /** length of the SHA Password */
  41. #define APR_SHA1PW_IDLEN 5
  42. /** @see apr_sha1_ctx_t */
  43. typedef struct apr_sha1_ctx_t apr_sha1_ctx_t;
  44. /**
  45. * SHA1 context structure
  46. */
  47. struct apr_sha1_ctx_t {
  48. /** message digest */
  49. apr_uint32_t digest[5];
  50. /** 64-bit bit counts */
  51. apr_uint32_t count_lo, count_hi;
  52. /** SHA data buffer */
  53. apr_uint32_t data[16];
  54. /** unprocessed amount in data */
  55. int local;
  56. };
  57. /**
  58. * Provide a means to SHA1 crypt/encode a plaintext password in a way which
  59. * makes password file compatible with those commonly use in netscape web
  60. * and ldap installations.
  61. * @param clear The plaintext password
  62. * @param len The length of the plaintext password
  63. * @param out The encrypted/encoded password
  64. * @note SHA1 support is useful for migration purposes, but is less
  65. * secure than Apache's password format, since Apache's (MD5)
  66. * password format uses a random eight character salt to generate
  67. * one of many possible hashes for the same password. Netscape
  68. * uses plain SHA1 without a salt, so the same password
  69. * will always generate the same hash, making it easier
  70. * to break since the search space is smaller.
  71. */
  72. APU_DECLARE(void) apr_sha1_base64(const char *clear, int len, char *out);
  73. /**
  74. * Initialize the SHA digest
  75. * @param context The SHA context to initialize
  76. */
  77. APU_DECLARE(void) apr_sha1_init(apr_sha1_ctx_t *context);
  78. /**
  79. * Update the SHA digest
  80. * @param context The SHA1 context to update
  81. * @param input The buffer to add to the SHA digest
  82. * @param inputLen The length of the input buffer
  83. */
  84. APU_DECLARE(void) apr_sha1_update(apr_sha1_ctx_t *context, const char *input,
  85. unsigned int inputLen);
  86. /**
  87. * Update the SHA digest with binary data
  88. * @param context The SHA1 context to update
  89. * @param input The buffer to add to the SHA digest
  90. * @param inputLen The length of the input buffer
  91. */
  92. APU_DECLARE(void) apr_sha1_update_binary(apr_sha1_ctx_t *context,
  93. const unsigned char *input,
  94. unsigned int inputLen);
  95. /**
  96. * Finish computing the SHA digest
  97. * @param digest the output buffer in which to store the digest
  98. * @param context The context to finalize
  99. */
  100. APU_DECLARE(void) apr_sha1_final(unsigned char digest[APR_SHA1_DIGESTSIZE],
  101. apr_sha1_ctx_t *context);
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif /* APR_SHA1_H */