gooderp18绿色标准版
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.

116 satır
4.3KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * sha2.h
  4. * Generic headers for SHA224, 256, 384 AND 512 functions of PostgreSQL.
  5. *
  6. * Portions Copyright (c) 2016-2019, PostgreSQL Global Development Group
  7. *
  8. * IDENTIFICATION
  9. * src/include/common/sha2.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. /* $OpenBSD: sha2.h,v 1.2 2004/04/28 23:11:57 millert Exp $ */
  14. /*
  15. * FILE: sha2.h
  16. * AUTHOR: Aaron D. Gifford <me@aarongifford.com>
  17. *
  18. * Copyright (c) 2000-2001, Aaron D. Gifford
  19. * All rights reserved.
  20. *
  21. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions
  23. * are met:
  24. * 1. Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * 2. Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in the
  28. * documentation and/or other materials provided with the distribution.
  29. * 3. Neither the name of the copyright holder nor the names of contributors
  30. * may be used to endorse or promote products derived from this software
  31. * without specific prior written permission.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
  34. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  35. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
  37. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  38. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  39. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  40. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  41. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  42. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  43. * SUCH DAMAGE.
  44. *
  45. * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
  46. */
  47. #ifndef _PG_SHA2_H_
  48. #define _PG_SHA2_H_
  49. #ifdef USE_OPENSSL
  50. #include <openssl/sha.h>
  51. #endif
  52. /*** SHA224/256/384/512 Various Length Definitions ***********************/
  53. #define PG_SHA224_BLOCK_LENGTH 64
  54. #define PG_SHA224_DIGEST_LENGTH 28
  55. #define PG_SHA224_DIGEST_STRING_LENGTH (PG_SHA224_DIGEST_LENGTH * 2 + 1)
  56. #define PG_SHA256_BLOCK_LENGTH 64
  57. #define PG_SHA256_DIGEST_LENGTH 32
  58. #define PG_SHA256_DIGEST_STRING_LENGTH (PG_SHA256_DIGEST_LENGTH * 2 + 1)
  59. #define PG_SHA384_BLOCK_LENGTH 128
  60. #define PG_SHA384_DIGEST_LENGTH 48
  61. #define PG_SHA384_DIGEST_STRING_LENGTH (PG_SHA384_DIGEST_LENGTH * 2 + 1)
  62. #define PG_SHA512_BLOCK_LENGTH 128
  63. #define PG_SHA512_DIGEST_LENGTH 64
  64. #define PG_SHA512_DIGEST_STRING_LENGTH (PG_SHA512_DIGEST_LENGTH * 2 + 1)
  65. /* Context Structures for SHA-1/224/256/384/512 */
  66. #ifdef USE_OPENSSL
  67. typedef SHA256_CTX pg_sha256_ctx;
  68. typedef SHA512_CTX pg_sha512_ctx;
  69. typedef SHA256_CTX pg_sha224_ctx;
  70. typedef SHA512_CTX pg_sha384_ctx;
  71. #else
  72. typedef struct pg_sha256_ctx
  73. {
  74. uint32 state[8];
  75. uint64 bitcount;
  76. uint8 buffer[PG_SHA256_BLOCK_LENGTH];
  77. } pg_sha256_ctx;
  78. typedef struct pg_sha512_ctx
  79. {
  80. uint64 state[8];
  81. uint64 bitcount[2];
  82. uint8 buffer[PG_SHA512_BLOCK_LENGTH];
  83. } pg_sha512_ctx;
  84. typedef struct pg_sha256_ctx pg_sha224_ctx;
  85. typedef struct pg_sha512_ctx pg_sha384_ctx;
  86. #endif /* USE_OPENSSL */
  87. /* Interface routines for SHA224/256/384/512 */
  88. extern void pg_sha224_init(pg_sha224_ctx *ctx);
  89. extern void pg_sha224_update(pg_sha224_ctx *ctx, const uint8 *input0,
  90. size_t len);
  91. extern void pg_sha224_final(pg_sha224_ctx *ctx, uint8 *dest);
  92. extern void pg_sha256_init(pg_sha256_ctx *ctx);
  93. extern void pg_sha256_update(pg_sha256_ctx *ctx, const uint8 *input0,
  94. size_t len);
  95. extern void pg_sha256_final(pg_sha256_ctx *ctx, uint8 *dest);
  96. extern void pg_sha384_init(pg_sha384_ctx *ctx);
  97. extern void pg_sha384_update(pg_sha384_ctx *ctx,
  98. const uint8 *, size_t len);
  99. extern void pg_sha384_final(pg_sha384_ctx *ctx, uint8 *dest);
  100. extern void pg_sha512_init(pg_sha512_ctx *ctx);
  101. extern void pg_sha512_update(pg_sha512_ctx *ctx, const uint8 *input0,
  102. size_t len);
  103. extern void pg_sha512_final(pg_sha512_ctx *ctx, uint8 *dest);
  104. #endif /* _PG_SHA2_H_ */
上海开阖软件有限公司 沪ICP备12045867号-1