xcrypt 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +106 -0
  3. data/ext/libxcrypt/AUTHORS +38 -0
  4. data/ext/libxcrypt/COPYING.LIB +502 -0
  5. data/ext/libxcrypt/ChangeLog +239 -0
  6. data/ext/libxcrypt/INSTALL +380 -0
  7. data/ext/libxcrypt/LICENSING +152 -0
  8. data/ext/libxcrypt/Makefile.am +704 -0
  9. data/ext/libxcrypt/Makefile.in +4110 -0
  10. data/ext/libxcrypt/NEWS +630 -0
  11. data/ext/libxcrypt/README +1 -0
  12. data/ext/libxcrypt/README.md +179 -0
  13. data/ext/libxcrypt/THANKS +13 -0
  14. data/ext/libxcrypt/TODO +1 -0
  15. data/ext/libxcrypt/TODO.md +100 -0
  16. data/ext/libxcrypt/aclocal.m4 +2617 -0
  17. data/ext/libxcrypt/autogen.sh +33 -0
  18. data/ext/libxcrypt/autom4te.cache/output.0 +19884 -0
  19. data/ext/libxcrypt/autom4te.cache/output.1 +19884 -0
  20. data/ext/libxcrypt/autom4te.cache/output.2 +19884 -0
  21. data/ext/libxcrypt/autom4te.cache/output.3 +19885 -0
  22. data/ext/libxcrypt/autom4te.cache/requests +714 -0
  23. data/ext/libxcrypt/autom4te.cache/traces.0 +4088 -0
  24. data/ext/libxcrypt/autom4te.cache/traces.1 +1060 -0
  25. data/ext/libxcrypt/autom4te.cache/traces.2 +4088 -0
  26. data/ext/libxcrypt/autom4te.cache/traces.3 +1060 -0
  27. data/ext/libxcrypt/build-aux/ci/ci-log-dependency-versions +79 -0
  28. data/ext/libxcrypt/build-aux/ci/ci-log-logfiles +22 -0
  29. data/ext/libxcrypt/build-aux/ci/clang-gcov-wrapper +2 -0
  30. data/ext/libxcrypt/build-aux/ci/configure-wrapper +10 -0
  31. data/ext/libxcrypt/build-aux/ci/summarize-coverage +24 -0
  32. data/ext/libxcrypt/build-aux/m4/ax_append_compile_flags.m4 +46 -0
  33. data/ext/libxcrypt/build-aux/m4/ax_append_flag.m4 +50 -0
  34. data/ext/libxcrypt/build-aux/m4/ax_check_compile_flag.m4 +53 -0
  35. data/ext/libxcrypt/build-aux/m4/ax_check_vscript.m4 +142 -0
  36. data/ext/libxcrypt/build-aux/m4/ax_gcc_func_attribute.m4 +246 -0
  37. data/ext/libxcrypt/build-aux/m4/ax_require_defined.m4 +37 -0
  38. data/ext/libxcrypt/build-aux/m4/ax_valgrind_check.m4 +239 -0
  39. data/ext/libxcrypt/build-aux/m4/libtool.m4 +8488 -0
  40. data/ext/libxcrypt/build-aux/m4/ltoptions.m4 +467 -0
  41. data/ext/libxcrypt/build-aux/m4/ltsugar.m4 +124 -0
  42. data/ext/libxcrypt/build-aux/m4/ltversion.m4 +24 -0
  43. data/ext/libxcrypt/build-aux/m4/lt~obsolete.m4 +99 -0
  44. data/ext/libxcrypt/build-aux/m4/pkg_compat.m4 +88 -0
  45. data/ext/libxcrypt/build-aux/m4/zw_alignment.m4 +90 -0
  46. data/ext/libxcrypt/build-aux/m4/zw_automodern.m4 +307 -0
  47. data/ext/libxcrypt/build-aux/m4/zw_detect_asan.m4 +24 -0
  48. data/ext/libxcrypt/build-aux/m4/zw_endianness.m4 +152 -0
  49. data/ext/libxcrypt/build-aux/m4/zw_ld_wrap.m4 +47 -0
  50. data/ext/libxcrypt/build-aux/m4/zw_prog_perl.m4 +40 -0
  51. data/ext/libxcrypt/build-aux/m4/zw_simple_warnings.m4 +150 -0
  52. data/ext/libxcrypt/build-aux/m4/zw_static_assert.m4 +68 -0
  53. data/ext/libxcrypt/build-aux/m4-autogen/compile +364 -0
  54. data/ext/libxcrypt/build-aux/m4-autogen/config.guess +1815 -0
  55. data/ext/libxcrypt/build-aux/m4-autogen/config.sub +2354 -0
  56. data/ext/libxcrypt/build-aux/m4-autogen/depcomp +792 -0
  57. data/ext/libxcrypt/build-aux/m4-autogen/install-sh +541 -0
  58. data/ext/libxcrypt/build-aux/m4-autogen/ltmain.sh +11524 -0
  59. data/ext/libxcrypt/build-aux/m4-autogen/missing +236 -0
  60. data/ext/libxcrypt/build-aux/m4-autogen/test-driver +160 -0
  61. data/ext/libxcrypt/build-aux/scripts/BuildCommon.pm +712 -0
  62. data/ext/libxcrypt/build-aux/scripts/check-perlcritic-config +76 -0
  63. data/ext/libxcrypt/build-aux/scripts/compute-symver-floor +116 -0
  64. data/ext/libxcrypt/build-aux/scripts/expand-selected-hashes +80 -0
  65. data/ext/libxcrypt/build-aux/scripts/gen-crypt-h +131 -0
  66. data/ext/libxcrypt/build-aux/scripts/gen-crypt-hashes-h +141 -0
  67. data/ext/libxcrypt/build-aux/scripts/gen-crypt-symbol-vers-h +150 -0
  68. data/ext/libxcrypt/build-aux/scripts/gen-libcrypt-map +67 -0
  69. data/ext/libxcrypt/build-aux/scripts/move-if-change +84 -0
  70. data/ext/libxcrypt/build-aux/scripts/skip-if-exec-format-error +78 -0
  71. data/ext/libxcrypt/codecov.yml +4 -0
  72. data/ext/libxcrypt/config.h.in +303 -0
  73. data/ext/libxcrypt/configure +19885 -0
  74. data/ext/libxcrypt/configure.ac +549 -0
  75. data/ext/libxcrypt/doc/crypt.3 +512 -0
  76. data/ext/libxcrypt/doc/crypt.5 +343 -0
  77. data/ext/libxcrypt/doc/crypt_checksalt.3 +106 -0
  78. data/ext/libxcrypt/doc/crypt_gensalt.3 +285 -0
  79. data/ext/libxcrypt/doc/crypt_gensalt_ra.3 +1 -0
  80. data/ext/libxcrypt/doc/crypt_gensalt_rn.3 +1 -0
  81. data/ext/libxcrypt/doc/crypt_preferred_method.3 +68 -0
  82. data/ext/libxcrypt/doc/crypt_r.3 +1 -0
  83. data/ext/libxcrypt/doc/crypt_ra.3 +1 -0
  84. data/ext/libxcrypt/doc/crypt_rn.3 +1 -0
  85. data/ext/libxcrypt/lib/alg-des-tables.c +3858 -0
  86. data/ext/libxcrypt/lib/alg-des.c +269 -0
  87. data/ext/libxcrypt/lib/alg-des.h +74 -0
  88. data/ext/libxcrypt/lib/alg-gost3411-2012-const.h +313 -0
  89. data/ext/libxcrypt/lib/alg-gost3411-2012-core.c +238 -0
  90. data/ext/libxcrypt/lib/alg-gost3411-2012-core.h +51 -0
  91. data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.c +78 -0
  92. data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.h +46 -0
  93. data/ext/libxcrypt/lib/alg-gost3411-2012-precalc.h +1426 -0
  94. data/ext/libxcrypt/lib/alg-gost3411-2012-ref.h +67 -0
  95. data/ext/libxcrypt/lib/alg-hmac-sha1.c +140 -0
  96. data/ext/libxcrypt/lib/alg-hmac-sha1.h +35 -0
  97. data/ext/libxcrypt/lib/alg-md4.c +270 -0
  98. data/ext/libxcrypt/lib/alg-md4.h +43 -0
  99. data/ext/libxcrypt/lib/alg-md5.c +291 -0
  100. data/ext/libxcrypt/lib/alg-md5.h +43 -0
  101. data/ext/libxcrypt/lib/alg-sha1.c +288 -0
  102. data/ext/libxcrypt/lib/alg-sha1.h +34 -0
  103. data/ext/libxcrypt/lib/alg-sha256.c +630 -0
  104. data/ext/libxcrypt/lib/alg-sha256.h +123 -0
  105. data/ext/libxcrypt/lib/alg-sha512.c +311 -0
  106. data/ext/libxcrypt/lib/alg-sha512.h +81 -0
  107. data/ext/libxcrypt/lib/alg-sm3-hmac.c +113 -0
  108. data/ext/libxcrypt/lib/alg-sm3-hmac.h +42 -0
  109. data/ext/libxcrypt/lib/alg-sm3.c +449 -0
  110. data/ext/libxcrypt/lib/alg-sm3.h +63 -0
  111. data/ext/libxcrypt/lib/alg-yescrypt-common.c +713 -0
  112. data/ext/libxcrypt/lib/alg-yescrypt-opt.c +1568 -0
  113. data/ext/libxcrypt/lib/alg-yescrypt-platform.c +106 -0
  114. data/ext/libxcrypt/lib/alg-yescrypt.h +360 -0
  115. data/ext/libxcrypt/lib/byteorder.h +164 -0
  116. data/ext/libxcrypt/lib/crypt-bcrypt.c +1061 -0
  117. data/ext/libxcrypt/lib/crypt-des-obsolete.c +215 -0
  118. data/ext/libxcrypt/lib/crypt-des.c +491 -0
  119. data/ext/libxcrypt/lib/crypt-gensalt-static.c +40 -0
  120. data/ext/libxcrypt/lib/crypt-gost-yescrypt.c +182 -0
  121. data/ext/libxcrypt/lib/crypt-md5.c +232 -0
  122. data/ext/libxcrypt/lib/crypt-nthash.c +134 -0
  123. data/ext/libxcrypt/lib/crypt-obsolete.h +40 -0
  124. data/ext/libxcrypt/lib/crypt-pbkdf1-sha1.c +260 -0
  125. data/ext/libxcrypt/lib/crypt-port.h +514 -0
  126. data/ext/libxcrypt/lib/crypt-scrypt.c +247 -0
  127. data/ext/libxcrypt/lib/crypt-sha256.c +308 -0
  128. data/ext/libxcrypt/lib/crypt-sha512.c +323 -0
  129. data/ext/libxcrypt/lib/crypt-sm3-yescrypt.c +189 -0
  130. data/ext/libxcrypt/lib/crypt-sm3.c +308 -0
  131. data/ext/libxcrypt/lib/crypt-static.c +44 -0
  132. data/ext/libxcrypt/lib/crypt-sunmd5.c +314 -0
  133. data/ext/libxcrypt/lib/crypt-yescrypt.c +177 -0
  134. data/ext/libxcrypt/lib/crypt.c +421 -0
  135. data/ext/libxcrypt/lib/crypt.h.in +249 -0
  136. data/ext/libxcrypt/lib/gen-des-tables.c +363 -0
  137. data/ext/libxcrypt/lib/hashes.conf +59 -0
  138. data/ext/libxcrypt/lib/libcrypt.map.in +48 -0
  139. data/ext/libxcrypt/lib/libcrypt.minver +97 -0
  140. data/ext/libxcrypt/lib/libxcrypt.pc.in +15 -0
  141. data/ext/libxcrypt/lib/util-base64.c +26 -0
  142. data/ext/libxcrypt/lib/util-gensalt-sha.c +88 -0
  143. data/ext/libxcrypt/lib/util-get-random-bytes.c +154 -0
  144. data/ext/libxcrypt/lib/util-make-failure-token.c +48 -0
  145. data/ext/libxcrypt/lib/util-xbzero.c +43 -0
  146. data/ext/libxcrypt/lib/util-xstrcpy.c +42 -0
  147. data/ext/libxcrypt/lib/xcrypt.h.in +58 -0
  148. data/ext/libxcrypt/libxcrypt.spec.rpkg +481 -0
  149. data/ext/libxcrypt/rpkg.conf +2 -0
  150. data/ext/libxcrypt/rpkg.macros +86 -0
  151. data/ext/libxcrypt/test/TestCommon.pm +326 -0
  152. data/ext/libxcrypt/test/alg-des.c +80 -0
  153. data/ext/libxcrypt/test/alg-gost3411-2012-hmac.c +90 -0
  154. data/ext/libxcrypt/test/alg-gost3411-2012.c +191 -0
  155. data/ext/libxcrypt/test/alg-hmac-sha1.c +187 -0
  156. data/ext/libxcrypt/test/alg-md4.c +111 -0
  157. data/ext/libxcrypt/test/alg-md5.c +134 -0
  158. data/ext/libxcrypt/test/alg-pbkdf-hmac-sha256.c +269 -0
  159. data/ext/libxcrypt/test/alg-sha1.c +111 -0
  160. data/ext/libxcrypt/test/alg-sha256.c +141 -0
  161. data/ext/libxcrypt/test/alg-sha512.c +170 -0
  162. data/ext/libxcrypt/test/alg-sm3-hmac.c +149 -0
  163. data/ext/libxcrypt/test/alg-sm3.c +168 -0
  164. data/ext/libxcrypt/test/alg-yescrypt.c +466 -0
  165. data/ext/libxcrypt/test/badsalt.c +726 -0
  166. data/ext/libxcrypt/test/badsetting.c +350 -0
  167. data/ext/libxcrypt/test/byteorder.c +254 -0
  168. data/ext/libxcrypt/test/checksalt.c +265 -0
  169. data/ext/libxcrypt/test/compile-strong-alias.c +43 -0
  170. data/ext/libxcrypt/test/crypt-badargs.c +392 -0
  171. data/ext/libxcrypt/test/crypt-gost-yescrypt.c +149 -0
  172. data/ext/libxcrypt/test/crypt-nested-call.c +180 -0
  173. data/ext/libxcrypt/test/crypt-sm3-yescrypt.c +149 -0
  174. data/ext/libxcrypt/test/crypt-too-long-phrase.c +157 -0
  175. data/ext/libxcrypt/test/des-cases.h +196 -0
  176. data/ext/libxcrypt/test/des-obsolete.c +206 -0
  177. data/ext/libxcrypt/test/des-obsolete_r.c +207 -0
  178. data/ext/libxcrypt/test/explicit-bzero.c +334 -0
  179. data/ext/libxcrypt/test/gensalt-bcrypt_x.c +54 -0
  180. data/ext/libxcrypt/test/gensalt-extradata.c +246 -0
  181. data/ext/libxcrypt/test/gensalt-nested-call.c +126 -0
  182. data/ext/libxcrypt/test/gensalt-nthash.c +65 -0
  183. data/ext/libxcrypt/test/gensalt.c +599 -0
  184. data/ext/libxcrypt/test/getrandom-fallbacks.c +295 -0
  185. data/ext/libxcrypt/test/getrandom-interface.c +211 -0
  186. data/ext/libxcrypt/test/ka-table-gen.py +945 -0
  187. data/ext/libxcrypt/test/ka-table.inc +5849 -0
  188. data/ext/libxcrypt/test/ka-tester.c +240 -0
  189. data/ext/libxcrypt/test/preferred-method.c +133 -0
  190. data/ext/libxcrypt/test/short-outbuf.c +119 -0
  191. data/ext/libxcrypt/test/special-char-salt.c +1160 -0
  192. data/ext/libxcrypt/test/symbols-compat.pl +137 -0
  193. data/ext/libxcrypt/test/symbols-renames.pl +107 -0
  194. data/ext/libxcrypt/test/symbols-static.pl +87 -0
  195. data/ext/xcrypt/xcrypt.c +9 -0
  196. data/lib/xcrypt/ffi.rb +76 -0
  197. data/lib/xcrypt/version.rb +5 -0
  198. data/lib/xcrypt.rb +89 -0
  199. metadata +267 -0
@@ -0,0 +1,514 @@
1
+ /* Portability glue for libcrypt.
2
+
3
+ Copyright 2007-2017 Thorsten Kukuk and Zack Weinberg
4
+ Copyright 2018-2019 Björn Esser
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public License
8
+ as published by the Free Software Foundation; either version 2.1 of
9
+ the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, see
18
+ <https://www.gnu.org/licenses/>. */
19
+
20
+ #ifndef _CRYPT_PORT_H
21
+ #define _CRYPT_PORT_H 1
22
+
23
+ #ifndef HAVE_CONFIG_H
24
+ #error "Run configure before compiling; see INSTALL for instructions"
25
+ #endif
26
+
27
+ #include "config.h"
28
+
29
+ #undef NDEBUG
30
+ #include <assert.h>
31
+
32
+ #include <stdbool.h>
33
+ #include <stddef.h>
34
+ #include <stdint.h>
35
+ #include <string.h>
36
+ #include <limits.h>
37
+ #ifdef HAVE_SYS_TYPES_H
38
+ #include <sys/types.h>
39
+ #endif
40
+ #ifdef HAVE_SYS_CDEFS_H
41
+ #include <sys/cdefs.h>
42
+ #endif
43
+ #ifdef HAVE_ENDIAN_H
44
+ #include <endian.h>
45
+ #endif
46
+ #ifdef HAVE_SYS_ENDIAN_H
47
+ #include <sys/endian.h>
48
+ #endif
49
+ #ifdef HAVE_SYS_PARAM_H
50
+ #include <sys/param.h>
51
+ #endif
52
+
53
+ /* unistd.h may contain declarations of crypt, crypt_r, crypt_data,
54
+ encrypt, and setkey; if present, they may be incompatible with our
55
+ declarations. Rename them out of the way with macros. This needs
56
+ to be done before we include crypt-symbol-vers.h, which defines
57
+ macros with the same names for symbol-versioning purposes. */
58
+ #ifdef HAVE_UNISTD_H
59
+ #define crypt unistd_crypt_is_incompatible
60
+ #define crypt_r unistd_crypt_r_is_incompatible
61
+ #define crypt_data unistd_crypt_data_is_incompatible
62
+ #define encrypt unistd_encrypt_is_incompatible
63
+ #define setkey unistd_setkey_is_incompatible
64
+ #include <unistd.h>
65
+ #undef crypt
66
+ #undef crypt_r
67
+ #undef crypt_data
68
+ #undef encrypt
69
+ #undef setkey
70
+ #endif
71
+
72
+ #ifndef HAVE_SYS_CDEFS_THROW
73
+ #define __THROW /* nothing */
74
+ #endif
75
+
76
+ /* Suppression of unused-argument warnings. */
77
+ #if defined __GNUC__ && __GNUC__ >= 3
78
+ # define ARG_UNUSED(x) x __attribute__ ((__unused__))
79
+ #else
80
+ # define ARG_UNUSED(x) x
81
+ #endif
82
+
83
+ /* Functions that should not be inlined. */
84
+ #if defined __GNUC__ && __GNUC__ >= 3
85
+ # define NO_INLINE __attribute__ ((__noinline__))
86
+ #else
87
+ # error "Don't know how to prevent function inlining"
88
+ #endif
89
+
90
+ /* C99 Static array indices in function parameter declarations. Syntax
91
+ such as: void bar(int myArray[static 10]); is allowed in C99, but
92
+ not all compiler support it properly. Define MIN_SIZE appropriately
93
+ so headers using it can be compiled using any compiler.
94
+ Use like this: void bar(int myArray[MIN_SIZE(10)]); */
95
+ #if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) && \
96
+ ((defined __GNUC__ && __GNUC__ > 4) || defined __clang__)
97
+ #define MIN_SIZE(x) static (x)
98
+ #else
99
+ #define MIN_SIZE(x) (x)
100
+ #endif
101
+
102
+ /* Detect system endianness. */
103
+ #if ENDIANNESS_IS_BIG
104
+ # define XCRYPT_USE_BIGENDIAN 1
105
+ #elif ENDIANNESS_IS_LITTLE
106
+ # define XCRYPT_USE_BIGENDIAN 0
107
+ #elif ENDIANNESS_IS_PDP
108
+ # error "Byte-order sensitive code in libxcrypt does not support PDP-endianness"
109
+ #else
110
+ # error "Unable to determine byte ordering"
111
+ #endif
112
+
113
+ /* static_assert shim. */
114
+ #ifdef HAVE_STATIC_ASSERT_IN_ASSERT_H
115
+ /* nothing to do */
116
+ #elif defined HAVE__STATIC_ASSERT
117
+ # define static_assert(expr, message) _Static_assert(expr, message)
118
+ #else
119
+ /* This fallback is known to work with most C99-compliant compilers.
120
+ See verify.h in gnulib for extensive discussion. */
121
+ # define static_assert(expr, message) \
122
+ extern int (*xcrypt_static_assert_fn (void)) \
123
+ [!!sizeof (struct { int xcrypt_error_if_negative: (expr) ? 2 : -1; })]
124
+ #endif
125
+
126
+ /* max_align_t shim. In the absence of official word from the
127
+ compiler, we guess that one of long double, uintmax_t, void *, and
128
+ void (*)(void) will have the maximum alignment. This is probably
129
+ not true in the presence of vector types, but we currently don't
130
+ use vector types, and hopefully any compiler with extra-aligned
131
+ vector types will provide max_align_t. */
132
+ #ifndef HAVE_MAX_ALIGN_T
133
+ typedef union
134
+ {
135
+ long double ld;
136
+ uintmax_t ui;
137
+ void *vp;
138
+ void (*vpf)(void);
139
+ } max_align_t;
140
+ #endif
141
+
142
+ /* Several files expect the traditional definitions of these macros.
143
+ (We don't trust sys/param.h to define them correctly.) */
144
+ #undef MIN
145
+ #define MIN(a, b) (((a) < (b)) ? (a) : (b))
146
+ #undef MAX
147
+ #define MAX(a, b) (((a) > (b)) ? (a) : (b))
148
+
149
+ /* Size of a declared array. */
150
+ #define ARRAY_SIZE(a_) (sizeof (a_) / sizeof ((a_)[0]))
151
+
152
+ /* Not all systems provide a library function usable for erasing
153
+ memory containing sensitive data, and among those that do, there is
154
+ no standard for what it should be called. (Plain memset and bzero
155
+ are not usable for this purpose, because the compiler may remove
156
+ calls to these functions if it thinks the stores are dead.)
157
+
158
+ All code in libxcrypt is standardized on explicit_bzero() as the
159
+ name for the function that does this job; here, we map that name
160
+ to whatever platform routine is available, or to our own fallback
161
+ implementation. */
162
+ #define INCLUDE_explicit_bzero 0
163
+ #if defined HAVE_MEMSET_EXPLICIT
164
+ /* Preferred over explicit_bzero, as this is part of the C23 standard.
165
+ See: ISO/IEC 9899:2024 */
166
+ #define explicit_bzero(s, len) memset_explicit(s, 0, len)
167
+ #elif defined HAVE_MEMSET_S
168
+ #define explicit_bzero(s, len) memset_s(s, len, 0, len)
169
+ #elif defined HAVE_EXPLICIT_BZERO
170
+ /* nothing to do */
171
+ #elif defined HAVE_EXPLICIT_MEMSET
172
+ #define explicit_bzero(s, len) explicit_memset(s, 0, len)
173
+ #else
174
+ /* activate our fallback implementation */
175
+ #undef INCLUDE_explicit_bzero
176
+ #define INCLUDE_explicit_bzero 1
177
+ #define explicit_bzero _crypt_explicit_bzero
178
+ extern void explicit_bzero (void *, size_t);
179
+ #endif
180
+
181
+ /* Provide a safe way to copy strings with the guarantee src,
182
+ including its terminating '\0', will fit d_size bytes.
183
+ The trailing bytes of d_size will be filled with '\0'.
184
+ dst and src must not be NULL. Returns strlen (src).
185
+ Note: dst and src are declared as void * instead of char *
186
+ because some of the hashing methods want to call this
187
+ function with unsigned char * arguments. */
188
+ #define strcpy_or_abort _crypt_strcpy_or_abort
189
+ extern size_t strcpy_or_abort (void *dst, size_t d_size, const void *src);
190
+
191
+
192
+ /* Define ALIASNAME as a strong alias for NAME. */
193
+ #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
194
+
195
+ /* Darwin (Mach-O) doesn't support alias attributes or symbol versioning.
196
+ It does, however, support symbol aliasing at the object file level. */
197
+ #ifdef __APPLE__
198
+
199
+ # define _strong_alias(name, aliasname) \
200
+ __asm__(".globl _" #aliasname); \
201
+ __asm__(".set _" #aliasname ", _" #name); \
202
+ extern __typeof(name) aliasname __THROW
203
+
204
+ # define symver_set(extstr, intname, version, mode) \
205
+ __asm__(".globl _" extstr); \
206
+ __asm__(".set _" extstr ", _" #intname)
207
+
208
+ #elif defined _WIN32
209
+
210
+ /* .symver is only supported for ELF format, Windows uses COFF/PE */
211
+ # define symver_set(extstr, intname, version, mode)
212
+
213
+ #elif defined __GNUC__ && __GNUC__ >= 3
214
+
215
+ # define _strong_alias(name, aliasname) \
216
+ extern __typeof (name) aliasname __THROW __attribute__ ((alias (#name)))
217
+
218
+ /* Starting with GCC 10, we can use the symver attribute, which is also
219
+ needed at the point we decide to enable link-time optimization. */
220
+ # if defined HAVE_FUNC_ATTRIBUTE_SYMVER
221
+
222
+ /* Set the symbol version for EXTNAME, which uses INTNAME as its
223
+ implementation. */
224
+ # define symver_set(extstr, intname, version, mode) \
225
+ extern __typeof (intname) intname __THROW \
226
+ __attribute__((symver (extstr mode #version)))
227
+
228
+ /* Referencing specific _compatibility_ symbols still needs inline asm. */
229
+ # define _symver_ref(extstr, intname, version) \
230
+ __asm__ (".symver " #intname "," extstr "@" #version)
231
+
232
+ # else
233
+
234
+ /* Set the symbol version for EXTNAME, which uses INTNAME as its
235
+ implementation. */
236
+ # define symver_set(extstr, intname, version, mode) \
237
+ __asm__ (".symver " #intname "," extstr mode #version)
238
+
239
+ # endif
240
+
241
+ #else
242
+ # error "Don't know how to do symbol versioning with this compiler"
243
+ #endif
244
+
245
+ /* A construct with the same syntactic role as the expansion of symver_set,
246
+ but which does nothing. */
247
+ #define symver_nop() __asm__ ("")
248
+
249
+ /* The macros for versioned symbols work differently in this library
250
+ than they do in glibc. They are mostly auto-generated
251
+ (see build-aux/scripts/gen-crypt-symbol-vers-h)
252
+ and we currently don't support compatibility symbols that need a different
253
+ definition from the default version.
254
+
255
+ Each definition of a public symbol should look like this:
256
+ #if INCLUDE_foo
257
+ int foo(arguments)
258
+ {
259
+ body
260
+ }
261
+ SYMVER_foo;
262
+ #endif
263
+
264
+ and the macros take care of the rest. Normally, to call a public
265
+ symbol you do nothing special. The macro symver_ref() forces
266
+ all uses of a particular name (in the file where it's used) to refer
267
+ to a particular version of a public symbol, e.g. for testing. */
268
+
269
+ #ifdef IN_LIBCRYPT
270
+
271
+ #include "crypt-symbol-vers.h"
272
+
273
+ #ifdef PIC
274
+
275
+ #define symver_compat(n, extstr, extname, intname, version) \
276
+ strong_alias (intname, extname ## __ ## n); \
277
+ symver_set (extstr, extname ## __ ## n, version, "@")
278
+
279
+ #define symver_compat0(extstr, intname, version) \
280
+ symver_set (extstr, intname, version, "@")
281
+
282
+ #define symver_default(extstr, intname, version) \
283
+ symver_set (extstr, intname, version, "@@")
284
+
285
+ #else
286
+
287
+ /* When not building the shared library, don't do any of this. */
288
+ #define symver_compat(n, extstr, extname, intname, version) symver_nop ()
289
+ #define symver_compat0(extstr, intname, version) symver_nop ()
290
+ #define symver_default(extstr, intname, version) symver_nop ()
291
+
292
+ #endif
293
+ #endif
294
+
295
+ /* Tests may need to _refer_ to compatibility symbols, but should never need
296
+ to _define_ them. */
297
+ #define symver_ref(extstr, intname, version) \
298
+ _symver_ref(extstr, intname, version)
299
+
300
+ /* Generic way for referencing specific _compatibility_ symbols. */
301
+ #ifndef _symver_ref
302
+ #define _symver_ref(extstr, intname, version) \
303
+ symver_set(extstr, intname, version, "@")
304
+ #endif
305
+
306
+ /* Define configuration macros used during compile-time by the
307
+ GOST R 34.11-2012 "Streebog" hash function. */
308
+ #if XCRYPT_USE_BIGENDIAN
309
+ #define __GOST3411_BIG_ENDIAN__ 1
310
+ #else
311
+ #define __GOST3411_LITTLE_ENDIAN__ 1
312
+ #endif
313
+
314
+ /* Get the set of hash algorithms to be included and some related
315
+ definitions. */
316
+ #include "crypt-hashes.h"
317
+
318
+ /* Rename all of the internal-but-global symbols with a _crypt_ prefix
319
+ so that they do not interfere with other people's code when linking
320
+ statically. This list cannot be autogenerated, but is validated by
321
+ test-symbols.sh. */
322
+
323
+ #define ascii64 _crypt_ascii64
324
+ #define get_random_bytes _crypt_get_random_bytes
325
+ #define make_failure_token _crypt_make_failure_token
326
+
327
+ #if INCLUDE_descrypt || INCLUDE_bsdicrypt || INCLUDE_bigcrypt
328
+ #define des_crypt_block _crypt_des_crypt_block
329
+ #define des_set_key _crypt_des_set_key
330
+ #define des_set_salt _crypt_des_set_salt
331
+ #define comp_maskl _crypt_comp_maskl
332
+ #define comp_maskr _crypt_comp_maskr
333
+ #define fp_maskl _crypt_fp_maskl
334
+ #define fp_maskr _crypt_fp_maskr
335
+ #define ip_maskl _crypt_ip_maskl
336
+ #define ip_maskr _crypt_ip_maskr
337
+ #define key_perm_maskl _crypt_key_perm_maskl
338
+ #define key_perm_maskr _crypt_key_perm_maskr
339
+ #define m_sbox _crypt_m_sbox
340
+ #define psbox _crypt_psbox
341
+ #endif
342
+
343
+ #if INCLUDE_nt
344
+ #define MD4_Init _crypt_MD4_Init
345
+ #define MD4_Update _crypt_MD4_Update
346
+ #define MD4_Final _crypt_MD4_Final
347
+ #endif
348
+
349
+ #if INCLUDE_md5crypt || INCLUDE_sunmd5
350
+ #define MD5_Init _crypt_MD5_Init
351
+ #define MD5_Update _crypt_MD5_Update
352
+ #define MD5_Final _crypt_MD5_Final
353
+ #endif
354
+
355
+ #if INCLUDE_sha1crypt
356
+ #define hmac_sha1_process_data _crypt_hmac_sha1_process_data
357
+ #define sha1_finish_ctx _crypt_sha1_finish_ctx
358
+ #define sha1_init_ctx _crypt_sha1_init_ctx
359
+ #define sha1_process_bytes _crypt_sha1_process_bytes
360
+ #endif
361
+
362
+ #if INCLUDE_sha512crypt
363
+ #define libcperciva_SHA512_Init _crypt_SHA512_Init
364
+ #define libcperciva_SHA512_Update _crypt_SHA512_Update
365
+ #define libcperciva_SHA512_Final _crypt_SHA512_Final
366
+ #define libcperciva_SHA512_Buf _crypt_SHA512_Buf
367
+ #endif
368
+
369
+ #if INCLUDE_md5crypt || INCLUDE_sha256crypt || INCLUDE_sha512crypt || \
370
+ INCLUDE_sm3crypt
371
+ #define gensalt_sha_rn _crypt_gensalt_sha_rn
372
+ #endif
373
+
374
+ #if INCLUDE_yescrypt || INCLUDE_scrypt || INCLUDE_gost_yescrypt || \
375
+ INCLUDE_sm3_yescrypt
376
+ #define PBKDF2_SHA256 _crypt_PBKDF2_SHA256
377
+ #define crypto_scrypt _crypt_crypto_scrypt
378
+ #define yescrypt _crypt_yescrypt
379
+ #define yescrypt_decode64 _crypt_yescrypt_decode64
380
+ #define yescrypt_digest_shared _crypt_yescrypt_digest_shared
381
+ #define yescrypt_encode64 _crypt_yescrypt_encode64
382
+ #define yescrypt_encode_params _crypt_yescrypt_encode_params
383
+ #define yescrypt_encode_params_r _crypt_yescrypt_encode_params_r
384
+ #define yescrypt_free_local _crypt_yescrypt_free_local
385
+ #define yescrypt_free_shared _crypt_yescrypt_free_shared
386
+ #define yescrypt_init_local _crypt_yescrypt_init_local
387
+ #define yescrypt_init_shared _crypt_yescrypt_init_shared
388
+ #define yescrypt_kdf _crypt_yescrypt_kdf
389
+ #define yescrypt_r _crypt_yescrypt_r
390
+ #define yescrypt_reencrypt _crypt_yescrypt_reencrypt
391
+
392
+ #define libcperciva_HMAC_SHA256_Init _crypt_HMAC_SHA256_Init
393
+ #define libcperciva_HMAC_SHA256_Update _crypt_HMAC_SHA256_Update
394
+ #define libcperciva_HMAC_SHA256_Final _crypt_HMAC_SHA256_Final
395
+ #define libcperciva_HMAC_SHA256_Buf _crypt_HMAC_SHA256_Buf
396
+ #endif
397
+
398
+ #if INCLUDE_sha256crypt || INCLUDE_scrypt || INCLUDE_yescrypt || \
399
+ INCLUDE_gost_yescrypt || INCLUDE_sm3_yescrypt
400
+ #define libcperciva_SHA256_Init _crypt_SHA256_Init
401
+ #define libcperciva_SHA256_Update _crypt_SHA256_Update
402
+ #define libcperciva_SHA256_Final _crypt_SHA256_Final
403
+ #define libcperciva_SHA256_Buf _crypt_SHA256_Buf
404
+ #endif
405
+
406
+ #if INCLUDE_sm3crypt || INCLUDE_sm3_yescrypt
407
+ #define sm3_init _crypt_sm3_init
408
+ #define sm3_update _crypt_sm3_update
409
+ #define sm3_final _crypt_sm3_final
410
+ #define sm3_hash _crypt_sm3_hash
411
+ #define sm3_buf _crypt_sm3_buf
412
+ #endif
413
+
414
+ #if INCLUDE_gost_yescrypt
415
+ #define GOST34112012Init _crypt_GOST34112012_Init
416
+ #define GOST34112012Update _crypt_GOST34112012_Update
417
+ #define GOST34112012Final _crypt_GOST34112012_Final
418
+ #define GOST34112012Cleanup _crypt_GOST34112012_Cleanup
419
+ #define gost_hash256 _crypt_gost_hash256
420
+ #define gost_hmac256 _crypt_gost_hmac256
421
+ #endif
422
+
423
+ #if INCLUDE_sm3_yescrypt
424
+ #define sm3_hmac_buf _crypt_sm3_hmac_buf
425
+ #define sm3_hmac_final _crypt_sm3_hmac_final
426
+ #define sm3_hmac_init _crypt_sm3_hmac_init
427
+ #define sm3_hmac_update _crypt_sm3_hmac_update
428
+ #define sm3_hmac _crypt_sm3_hmac
429
+ #endif
430
+
431
+ /* Those are not present, if gost-yescrypt or sm3-yescrypt
432
+ is selected, but yescrypt is not. */
433
+ #if !INCLUDE_yescrypt && (INCLUDE_gost_yescrypt || INCLUDE_sm3_yescrypt)
434
+ #define gensalt_yescrypt_rn _crypt_gensalt_yescrypt_rn
435
+ extern void gensalt_yescrypt_rn
436
+ (unsigned long, const uint8_t *, size_t, uint8_t *, size_t);
437
+ #endif
438
+
439
+ /* Those are not present, if des-big is selected, but des is not. */
440
+ #if INCLUDE_bigcrypt && !INCLUDE_descrypt
441
+ #define gensalt_descrypt_rn _crypt_gensalt_descrypt_rn
442
+ extern void gensalt_descrypt_rn
443
+ (unsigned long, const uint8_t *, size_t, uint8_t *, size_t);
444
+ #endif
445
+
446
+ /* Those are not present, if scrypt is selected, but yescrypt is not. */
447
+ #if INCLUDE_scrypt && !INCLUDE_yescrypt
448
+ #define crypt_yescrypt_rn _crypt_crypt_yescrypt_rn
449
+ extern void crypt_yescrypt_rn (const char *, size_t, const char *,
450
+ size_t, uint8_t *, size_t, void *, size_t);
451
+ #endif
452
+
453
+ /* We need a prototype for fcrypt for some tests. */
454
+ #if ENABLE_OBSOLETE_API
455
+ extern char *fcrypt (const char *key, const char *setting);
456
+ #endif
457
+
458
+ /* Utility functions */
459
+
460
+ /* Fill BUF with BUFLEN bytes whose values are chosen uniformly at
461
+ random, using a cryptographically strong RNG provided by the
462
+ operating system. BUFLEN may not be greater than 256. Returns
463
+ true if all BUFLEN bytes were successfully filled, false otherwise;
464
+ sets errno when it returns false. Can block. */
465
+ extern bool get_random_bytes (void *buf, size_t buflen);
466
+
467
+ /* Generate a setting string in the format common to md5crypt,
468
+ sha256crypt, and sha512crypt. */
469
+ extern void gensalt_sha_rn (const char *tag, size_t maxsalt, unsigned long defcount,
470
+ unsigned long mincount, unsigned long maxcount,
471
+ unsigned long count,
472
+ const uint8_t *rbytes, size_t nrbytes,
473
+ uint8_t *output, size_t output_size);
474
+
475
+ /* For historical reasons, crypt and crypt_r are not expected ever
476
+ to return 0, and for internal implementation reasons (see
477
+ call_crypt_fn, in crypt.c), it is simpler if the individual
478
+ algorithms' crypt and gensalt functions return nothing.
479
+
480
+ This function generates a "failure token" in the output buffer,
481
+ which is guaranteed not to be equal to any valid password hash or
482
+ setting string, nor to the setting(+hash) string that was passed
483
+ in; thus, a subsequent blind attempt to authenticate someone by
484
+ comparing the output to a previously recorded hash string will
485
+ fail, even if that string is itself one of these "failure tokens".
486
+
487
+ We always call this function on the output buffer as the first
488
+ step. If the individual algorithm's crypt or gensalt function
489
+ succeeds, it overwrites the failure token with real output;
490
+ otherwise the token is left intact, and the API functions that
491
+ _can_ return 0 on error notice it. */
492
+ extern void
493
+ make_failure_token (const char *setting, char *output, int size);
494
+
495
+ /* The base-64 encoding table used by most hashing methods.
496
+ (bcrypt uses a slightly different encoding.) Size 65
497
+ because it's used as a C string in a few places. */
498
+ extern const unsigned char ascii64[65];
499
+
500
+ /* Same table gets used with other names in various places. */
501
+ #define b64t ((const char *) ascii64)
502
+ #define itoa64 ascii64
503
+
504
+ /* Calculate the size of a base64 encoding of N bytes:
505
+ 6 bits per output byte, rounded up. */
506
+ #define BASE64_LEN(bytes) ((((bytes) * 8) + 5) / 6)
507
+
508
+ /* The "scratch" area passed to each of the individual hash functions is
509
+ this big. */
510
+ #define ALG_SPECIFIC_SIZE 8192
511
+
512
+ #include "crypt.h"
513
+
514
+ #endif /* crypt-port.h */