2
0

sha2.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /*
  17. * FILE: sha2.h
  18. * AUTHOR: Aaron D. Gifford <me@aarongifford.com>
  19. *
  20. * A licence was granted to the ASF by Aaron on 4 November 2003.
  21. */
  22. #ifndef __SHA2_H__
  23. #define __SHA2_H__
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include "fspr.h"
  28. /*** SHA-256/384/512 Various Length Definitions ***********************/
  29. #define SHA256_BLOCK_LENGTH 64
  30. #define SHA256_DIGEST_LENGTH 32
  31. #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
  32. #define SHA384_BLOCK_LENGTH 128
  33. #define SHA384_DIGEST_LENGTH 48
  34. #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
  35. #define SHA512_BLOCK_LENGTH 128
  36. #define SHA512_DIGEST_LENGTH 64
  37. #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
  38. /*** SHA-256/384/512 Context Structures *******************************/
  39. typedef struct _SHA256_CTX {
  40. fspr_uint32_t state[8];
  41. fspr_uint64_t bitcount;
  42. fspr_byte_t buffer[SHA256_BLOCK_LENGTH];
  43. } SHA256_CTX;
  44. typedef struct _SHA512_CTX {
  45. fspr_uint64_t state[8];
  46. fspr_uint64_t bitcount[2];
  47. fspr_byte_t buffer[SHA512_BLOCK_LENGTH];
  48. } SHA512_CTX;
  49. typedef SHA512_CTX SHA384_CTX;
  50. /*** SHA-256/384/512 Function Prototypes ******************************/
  51. void fspr__SHA256_Init(SHA256_CTX *);
  52. void fspr__SHA256_Update(SHA256_CTX *, const fspr_byte_t *, size_t);
  53. void fspr__SHA256_Final(fspr_byte_t [SHA256_DIGEST_LENGTH], SHA256_CTX *);
  54. char* fspr__SHA256_End(SHA256_CTX *, char [SHA256_DIGEST_STRING_LENGTH]);
  55. char* fspr__SHA256_Data(const fspr_byte_t *, size_t,
  56. char [SHA256_DIGEST_STRING_LENGTH]);
  57. void fspr__SHA384_Init(SHA384_CTX *);
  58. void fspr__SHA384_Update(SHA384_CTX *, const fspr_byte_t *, size_t);
  59. void fspr__SHA384_Final(fspr_byte_t [SHA384_DIGEST_LENGTH], SHA384_CTX *);
  60. char* fspr__SHA384_End(SHA384_CTX *, char [SHA384_DIGEST_STRING_LENGTH]);
  61. char* fspr__SHA384_Data(const fspr_byte_t *, size_t,
  62. char [SHA384_DIGEST_STRING_LENGTH]);
  63. void fspr__SHA512_Init(SHA512_CTX *);
  64. void fspr__SHA512_Update(SHA512_CTX *, const fspr_byte_t *, size_t);
  65. void fspr__SHA512_Final(fspr_byte_t [SHA512_DIGEST_LENGTH], SHA512_CTX *);
  66. char* fspr__SHA512_End(SHA512_CTX *, char [SHA512_DIGEST_STRING_LENGTH]);
  67. char* fspr__SHA512_Data(const fspr_byte_t *, size_t,
  68. char [SHA512_DIGEST_STRING_LENGTH]);
  69. #ifdef __cplusplus
  70. }
  71. #endif /* __cplusplus */
  72. #endif /* __SHA2_H__ */