sha512_mb_ctx.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Header file for multi buffer SHA512 context
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * Copyright(c) 2016 Intel Corporation.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * Contact Information:
  21. * Megha Dey <megha.dey@linux.intel.com>
  22. *
  23. * BSD LICENSE
  24. *
  25. * Copyright(c) 2016 Intel Corporation.
  26. *
  27. * Redistribution and use in source and binary forms, with or without
  28. * modification, are permitted provided that the following conditions
  29. * are met:
  30. *
  31. * * Redistributions of source code must retain the above copyright
  32. * notice, this list of conditions and the following disclaimer.
  33. * * Redistributions in binary form must reproduce the above copyright
  34. * notice, this list of conditions and the following disclaimer in
  35. * the documentation and/or other materials provided with the
  36. * distribution.
  37. * * Neither the name of Intel Corporation nor the names of its
  38. * contributors may be used to endorse or promote products derived
  39. * from this software without specific prior written permission.
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  42. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  44. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  45. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  46. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  47. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  48. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  49. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  50. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  51. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. */
  53. #ifndef _SHA_MB_CTX_INTERNAL_H
  54. #define _SHA_MB_CTX_INTERNAL_H
  55. #include "sha512_mb_mgr.h"
  56. #define HASH_UPDATE 0x00
  57. #define HASH_FIRST 0x01
  58. #define HASH_LAST 0x02
  59. #define HASH_ENTIRE 0x03
  60. #define HASH_DONE 0x04
  61. #define HASH_FINAL 0x08
  62. #define HASH_CTX_STS_IDLE 0x00
  63. #define HASH_CTX_STS_PROCESSING 0x01
  64. #define HASH_CTX_STS_LAST 0x02
  65. #define HASH_CTX_STS_COMPLETE 0x04
  66. enum hash_ctx_error {
  67. HASH_CTX_ERROR_NONE = 0,
  68. HASH_CTX_ERROR_INVALID_FLAGS = -1,
  69. HASH_CTX_ERROR_ALREADY_PROCESSING = -2,
  70. HASH_CTX_ERROR_ALREADY_COMPLETED = -3,
  71. };
  72. #define hash_ctx_user_data(ctx) ((ctx)->user_data)
  73. #define hash_ctx_digest(ctx) ((ctx)->job.result_digest)
  74. #define hash_ctx_processing(ctx) ((ctx)->status & HASH_CTX_STS_PROCESSING)
  75. #define hash_ctx_complete(ctx) ((ctx)->status == HASH_CTX_STS_COMPLETE)
  76. #define hash_ctx_status(ctx) ((ctx)->status)
  77. #define hash_ctx_error(ctx) ((ctx)->error)
  78. #define hash_ctx_init(ctx) \
  79. do { \
  80. (ctx)->error = HASH_CTX_ERROR_NONE; \
  81. (ctx)->status = HASH_CTX_STS_COMPLETE; \
  82. } while (0)
  83. /* Hash Constants and Typedefs */
  84. #define SHA512_DIGEST_LENGTH 8
  85. #define SHA512_LOG2_BLOCK_SIZE 7
  86. #define SHA512_PADLENGTHFIELD_SIZE 16
  87. #ifdef SHA_MB_DEBUG
  88. #define assert(expr) \
  89. do { \
  90. if (unlikely(!(expr))) { \
  91. printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \
  92. #expr, __FILE__, __func__, __LINE__); \
  93. } \
  94. } while (0)
  95. #else
  96. #define assert(expr) do {} while (0)
  97. #endif
  98. struct sha512_ctx_mgr {
  99. struct sha512_mb_mgr mgr;
  100. };
  101. /* typedef struct sha512_ctx_mgr sha512_ctx_mgr; */
  102. struct sha512_hash_ctx {
  103. /* Must be at struct offset 0 */
  104. struct job_sha512 job;
  105. /* status flag */
  106. int status;
  107. /* error flag */
  108. int error;
  109. uint32_t total_length;
  110. const void *incoming_buffer;
  111. uint32_t incoming_buffer_length;
  112. uint8_t partial_block_buffer[SHA512_BLOCK_SIZE * 2];
  113. uint32_t partial_block_buffer_length;
  114. void *user_data;
  115. };
  116. #endif