crc64.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /****************************************************************************
  2. * include/crc64.h
  3. *
  4. * Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved.
  5. * Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __INCLUDE_CRC64_H
  36. #define __INCLUDE_CRC64_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <sys/types.h>
  42. #include <stdint.h>
  43. #ifdef CONFIG_HAVE_LONG_LONG
  44. /****************************************************************************
  45. * Pre-processor Definitions
  46. ****************************************************************************/
  47. /*
  48. * CRC64_CHECK is the CRC64 of the string "123456789" without the null byte.
  49. *
  50. * const uint8_t checkbuf[] =
  51. * {
  52. * '1', '2', '3', '4', '5', '6', '7', '8', '9'
  53. * };
  54. *
  55. * assert(crc64(checkbuf, sizeof(checkbuf)) == CRC64_CHECK);
  56. */
  57. /* CRC-64/WE */
  58. #define CRC64_POLY ((uint64_t)0x42f0e1eba9ea3693ull)
  59. #define CRC64_INIT ((uint64_t)0xffffffffffffffffull)
  60. #define CRC64_XOROUT ((uint64_t)0xffffffffffffffffull)
  61. #define CRC64_CHECK ((uint64_t)0x62ec59e3f1a4f00aull)
  62. /****************************************************************************
  63. * Public Function Prototypes
  64. ****************************************************************************/
  65. #ifdef __cplusplus
  66. #define EXTERN extern "C"
  67. extern "C"
  68. {
  69. #else
  70. #define EXTERN extern
  71. #endif
  72. /****************************************************************************
  73. * Name: crc64part
  74. *
  75. * Description:
  76. * Continue CRC calculation on a part of the buffer.
  77. *
  78. ****************************************************************************/
  79. uint64_t crc64part(FAR const uint8_t *src, size_t len, uint64_t crc64val);
  80. /****************************************************************************
  81. * Name: crc64
  82. *
  83. * Description:
  84. * Return a 64-bit CRC of the contents of the 'src' buffer, length 'len'.
  85. *
  86. ****************************************************************************/
  87. uint64_t crc64(FAR const uint8_t *src, size_t len);
  88. #undef EXTERN
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif /* CONFIG_HAVE_LONG_LONG */
  93. #endif /* __INCLUDE_CRC64_H */