050-Revert-Disallow-use-of-DES-encryption-functions-in-n.patch 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. From cfc93329e00cd23c226f34b3ffd5552a93c35bd7 Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <[email protected]>
  3. Date: Mon, 23 Mar 2020 22:33:46 +0100
  4. Subject: Revert "Disallow use of DES encryption functions in new programs."
  5. This reverts commit b10a0accee709a5efff2fadf0b0bbb79ff0ad759.
  6. ppp still uses the encrypt functions from the libc. musl libc also
  7. provides them.
  8. ---
  9. conform/data/stdlib.h-data | 3 +
  10. conform/data/unistd.h-data | 6 ++
  11. crypt/cert.c | 26 -----
  12. crypt/crypt-entry.c | 15 ++-
  13. crypt/crypt.h | 16 +++
  14. crypt/crypt_util.c | 9 --
  15. manual/conf.texi | 2 -
  16. manual/crypt.texi | 201 +++++++++++++++++++++++++++++++++++++
  17. manual/string.texi | 82 +++++++--------
  18. posix/unistd.h | 22 ++--
  19. stdlib/stdlib.h | 6 ++
  20. sunrpc/Makefile | 2 +-
  21. sunrpc/des_crypt.c | 7 +-
  22. sunrpc/des_soft.c | 2 +-
  23. 14 files changed, 303 insertions(+), 96 deletions(-)
  24. --- a/conform/data/stdlib.h-data
  25. +++ b/conform/data/stdlib.h-data
  26. @@ -149,6 +149,9 @@ function {unsigned short int*} seed48 (u
  27. #if !defined ISO && !defined ISO99 && !defined ISO11 && !defined POSIX && !defined XPG4 && !defined XPG42 && !defined UNIX98
  28. function int setenv (const char*, const char*, int)
  29. #endif
  30. +#if !defined ISO && !defined ISO99 && !defined ISO11 && !defined POSIX && !defined POSIX2008
  31. +function void setkey (const char*)
  32. +#endif
  33. #if !defined ISO && !defined ISO99 && !defined ISO11 && !defined XPG4 && !defined POSIX && !defined POSIX2008
  34. function {char*} setstate (char*)
  35. #endif
  36. --- a/conform/data/unistd.h-data
  37. +++ b/conform/data/unistd.h-data
  38. @@ -437,6 +437,9 @@ function int chroot (const char*)
  39. function int chown (const char*, uid_t, gid_t)
  40. function int close (int)
  41. function size_t confstr (int, char*, size_t)
  42. +#if !defined POSIX && !defined POSIX2008
  43. +function {char*} crypt (const char*, const char*)
  44. +#endif
  45. #if defined XPG4 || defined XPG42 || defined UNIX98
  46. function {char*} ctermid (char*)
  47. function {char*} cuserid (char*)
  48. @@ -446,6 +449,9 @@ allow cuserid
  49. #endif
  50. function int dup (int)
  51. function int dup2 (int, int)
  52. +#if !defined POSIX && !defined POSIX2008
  53. +function void encrypt (char[64], int)
  54. +#endif
  55. function int execl (const char*, const char*, ...)
  56. function int execle (const char*, const char*, ...)
  57. function int execlp (const char*, const char*, ...)
  58. --- a/crypt/cert.c
  59. +++ b/crypt/cert.c
  60. @@ -10,22 +10,6 @@
  61. #include <stdlib.h>
  62. #include "crypt.h"
  63. -/* This file tests the deprecated setkey/encrypt interface. */
  64. -#include <shlib-compat.h>
  65. -#if TEST_COMPAT (libcrypt, GLIBC_2_0, GLIBC_2_28)
  66. -
  67. -#define libcrypt_version_reference(symbol, version) \
  68. - _libcrypt_version_reference (symbol, VERSION_libcrypt_##version)
  69. -#define _libcrypt_version_reference(symbol, version) \
  70. - __libcrypt_version_reference (symbol, version)
  71. -#define __libcrypt_version_reference(symbol, version) \
  72. - __asm__ (".symver " #symbol ", " #symbol "@" #version)
  73. -
  74. -extern void setkey (const char *);
  75. -extern void encrypt (const char *, int);
  76. -libcrypt_version_reference (setkey, GLIBC_2_0);
  77. -libcrypt_version_reference (encrypt, GLIBC_2_0);
  78. -
  79. int totfails = 0;
  80. int main (int argc, char *argv[]);
  81. @@ -120,13 +104,3 @@ put8 (char *cp)
  82. printf("%02x", t);
  83. }
  84. }
  85. -
  86. -#else /* encrypt and setkey are not available. */
  87. -
  88. -int
  89. -main (void)
  90. -{
  91. - return 77; /* UNSUPPORTED */
  92. -}
  93. -
  94. -#endif
  95. --- a/crypt/crypt-entry.c
  96. +++ b/crypt/crypt-entry.c
  97. @@ -35,7 +35,6 @@
  98. #endif
  99. #include "crypt-private.h"
  100. -#include <shlib-compat.h>
  101. /* Prototypes for local functions. */
  102. #ifndef __GNU_LIBRARY__
  103. @@ -177,7 +176,17 @@ crypt (const char *key, const char *salt
  104. return __crypt_r (key, salt, &_ufc_foobar);
  105. }
  106. -#if SHLIB_COMPAT (libcrypt, GLIBC_2_0, GLIBC_2_28)
  107. +
  108. +/*
  109. + * To make fcrypt users happy.
  110. + * They don't need to call init_des.
  111. + */
  112. +#ifdef _LIBC
  113. weak_alias (crypt, fcrypt)
  114. -compat_symbol (libcrypt, fcrypt, fcrypt, GLIBC_2_0);
  115. +#else
  116. +char *
  117. +__fcrypt (const char *key, const char *salt)
  118. +{
  119. + return crypt (key, salt);
  120. +}
  121. #endif
  122. --- a/crypt/crypt.h
  123. +++ b/crypt/crypt.h
  124. @@ -36,6 +36,14 @@ __BEGIN_DECLS
  125. extern char *crypt (const char *__phrase, const char *__salt)
  126. __THROW __nonnull ((1, 2));
  127. +/* Setup DES tables according KEY. */
  128. +extern void setkey (const char *__key) __THROW __nonnull ((1));
  129. +
  130. +/* Encrypt data in BLOCK in place if EDFLAG is zero; otherwise decrypt
  131. + block in place. */
  132. +extern void encrypt (char *__glibc_block, int __edflag)
  133. + __THROW __nonnull ((1));
  134. +
  135. #ifdef __USE_GNU
  136. /* This structure provides scratch and output buffers for 'crypt_r'.
  137. @@ -63,6 +71,14 @@ struct crypt_data
  138. extern char *crypt_r (const char *__phrase, const char *__salt,
  139. struct crypt_data * __restrict __data)
  140. __THROW __nonnull ((1, 2, 3));
  141. +
  142. +extern void setkey_r (const char *__key,
  143. + struct crypt_data * __restrict __data)
  144. + __THROW __nonnull ((1, 2));
  145. +
  146. +extern void encrypt_r (char *__glibc_block, int __edflag,
  147. + struct crypt_data * __restrict __data)
  148. + __THROW __nonnull ((1, 3));
  149. #endif
  150. __END_DECLS
  151. --- a/crypt/crypt_util.c
  152. +++ b/crypt/crypt_util.c
  153. @@ -34,7 +34,6 @@
  154. #endif
  155. #include "crypt-private.h"
  156. -#include <shlib-compat.h>
  157. /* Prototypes for local functions. */
  158. #ifndef __GNU_LIBRARY__
  159. @@ -151,7 +150,6 @@ static const int sbox[8][4][16]= {
  160. }
  161. };
  162. -#if SHLIB_COMPAT (libcrypt, GLIBC_2_0, GLIBC_2_28)
  163. /*
  164. * This is the initial
  165. * permutation matrix
  166. @@ -162,7 +160,6 @@ static const int initial_perm[64] = {
  167. 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
  168. 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
  169. };
  170. -#endif
  171. /*
  172. * This is the final
  173. @@ -788,7 +785,6 @@ _ufc_output_conversion_r (ufc_long v1, u
  174. __data->crypt_3_buf[13] = 0;
  175. }
  176. -#if SHLIB_COMPAT (libcrypt, GLIBC_2_0, GLIBC_2_28)
  177. /*
  178. * UNIX encrypt function. Takes a bitvector
  179. @@ -889,14 +885,12 @@ __encrypt_r (char *__block, int __edflag
  180. }
  181. }
  182. weak_alias (__encrypt_r, encrypt_r)
  183. -compat_symbol (libcrypt, encrypt_r, encrypt_r, GLIBC_2_0);
  184. void
  185. encrypt (char *__block, int __edflag)
  186. {
  187. __encrypt_r(__block, __edflag, &_ufc_foobar);
  188. }
  189. -compat_symbol (libcrypt, encrypt, encrypt, GLIBC_2_0);
  190. /*
  191. @@ -921,15 +915,12 @@ __setkey_r (const char *__key, struct cr
  192. _ufc_mk_keytab_r((char *) ktab, __data);
  193. }
  194. weak_alias (__setkey_r, setkey_r)
  195. -compat_symbol (libcrypt, setkey_r, setkey_r, GLIBC_2_0);
  196. void
  197. setkey (const char *__key)
  198. {
  199. __setkey_r(__key, &_ufc_foobar);
  200. }
  201. -compat_symbol (libcrypt, setkey, setkey, GLIBC_2_0);
  202. -#endif /* SHLIB_COMPAT (libcrypt, GLIBC_2_0, GLIBC_2_28) */
  203. void
  204. __b64_from_24bit (char **cp, int *buflen,
  205. --- a/manual/conf.texi
  206. +++ b/manual/conf.texi
  207. @@ -780,8 +780,6 @@ Inquire about the parameter correspondin
  208. @item _SC_XOPEN_CRYPT
  209. @standards{X/Open, unistd.h}
  210. Inquire about the parameter corresponding to @code{_XOPEN_CRYPT}.
  211. -@Theglibc no longer implements the @code{_XOPEN_CRYPT} extensions,
  212. -so @samp{sysconf (_SC_XOPEN_CRYPT)} always returns @code{-1}.
  213. @item _SC_XOPEN_ENH_I18N
  214. @standards{X/Open, unistd.h}
  215. --- a/manual/crypt.texi
  216. +++ b/manual/crypt.texi
  217. @@ -16,8 +16,19 @@ subject to them, even if you do not use
  218. yourself. The restrictions vary from place to place and are changed
  219. often, so we cannot give any more specific advice than this warning.
  220. +@vindex AUTH_DES
  221. +@cindex FIPS 140-2
  222. +It also provides support for Secure RPC, and some library functions that
  223. +can be used to perform normal DES encryption. The @code{AUTH_DES}
  224. +authentication flavor in Secure RPC, as provided by @theglibc{},
  225. +uses DES and does not comply with FIPS 140-2 nor does any other use of DES
  226. +within @theglibc{}. It is recommended that Secure RPC should not be used
  227. +for systems that need to comply with FIPS 140-2 since all flavors of
  228. +encrypted authentication use normal DES.
  229. +
  230. @menu
  231. * Passphrase Storage:: One-way hashing for passphrases.
  232. +* DES Encryption:: Routines for DES encryption.
  233. * Unpredictable Bytes:: Randomness for cryptographic purposes.
  234. @end menu
  235. @@ -200,6 +211,196 @@ hashes for the same passphrase.
  236. @include testpass.c.texi
  237. @end smallexample
  238. +@node DES Encryption
  239. +@section DES Encryption
  240. +
  241. +@cindex FIPS 46-3
  242. +The Data Encryption Standard is described in the US Government Federal
  243. +Information Processing Standards (FIPS) 46-3 published by the National
  244. +Institute of Standards and Technology. The DES has been very thoroughly
  245. +analyzed since it was developed in the late 1970s, and no new
  246. +significant flaws have been found.
  247. +
  248. +However, the DES uses only a 56-bit key (plus 8 parity bits), and a
  249. +machine has been built in 1998 which can search through all possible
  250. +keys in about 6 days, which cost about US$200000; faster searches would
  251. +be possible with more money. This makes simple DES insecure for most
  252. +purposes, and NIST no longer permits new US government systems
  253. +to use simple DES.
  254. +
  255. +For serious encryption functionality, it is recommended that one of the
  256. +many free encryption libraries be used instead of these routines.
  257. +
  258. +The DES is a reversible operation which takes a 64-bit block and a
  259. +64-bit key, and produces another 64-bit block. Usually the bits are
  260. +numbered so that the most-significant bit, the first bit, of each block
  261. +is numbered 1.
  262. +
  263. +Under that numbering, every 8th bit of the key (the 8th, 16th, and so
  264. +on) is not used by the encryption algorithm itself. But the key must
  265. +have odd parity; that is, out of bits 1 through 8, and 9 through 16, and
  266. +so on, there must be an odd number of `1' bits, and this completely
  267. +specifies the unused bits.
  268. +
  269. +@deftypefun void setkey (const char *@var{key})
  270. +@standards{BSD, crypt.h}
  271. +@standards{SVID, crypt.h}
  272. +@safety{@prelim{}@mtunsafe{@mtasurace{:crypt}}@asunsafe{@asucorrupt{} @asulock{}}@acunsafe{@aculock{}}}
  273. +@c The static buffer stores the key, making it fundamentally
  274. +@c thread-unsafe. The locking issues are only in the initialization
  275. +@c path; cancelling the initialization will leave the lock held, it
  276. +@c would otherwise repeat the initialization on the next call.
  277. +
  278. +The @code{setkey} function sets an internal data structure to be an
  279. +expanded form of @var{key}. @var{key} is specified as an array of 64
  280. +bits each stored in a @code{char}, the first bit is @code{key[0]} and
  281. +the 64th bit is @code{key[63]}. The @var{key} should have the correct
  282. +parity.
  283. +@end deftypefun
  284. +
  285. +@deftypefun void encrypt (char *@var{block}, int @var{edflag})
  286. +@standards{BSD, crypt.h}
  287. +@standards{SVID, crypt.h}
  288. +@safety{@prelim{}@mtunsafe{@mtasurace{:crypt}}@asunsafe{@asucorrupt{} @asulock{}}@acunsafe{@aculock{}}}
  289. +@c Same issues as setkey.
  290. +
  291. +The @code{encrypt} function encrypts @var{block} if
  292. +@var{edflag} is 0, otherwise it decrypts @var{block}, using a key
  293. +previously set by @code{setkey}. The result is
  294. +placed in @var{block}.
  295. +
  296. +Like @code{setkey}, @var{block} is specified as an array of 64 bits each
  297. +stored in a @code{char}, but there are no parity bits in @var{block}.
  298. +@end deftypefun
  299. +
  300. +@deftypefun void setkey_r (const char *@var{key}, {struct crypt_data *} @var{data})
  301. +@deftypefunx void encrypt_r (char *@var{block}, int @var{edflag}, {struct crypt_data *} @var{data})
  302. +@standards{GNU, crypt.h}
  303. +@c setkey_r: @safety{@prelim{}@mtsafe{}@asunsafe{@asucorrupt{} @asulock{}}@acunsafe{@aculock{}}}
  304. +@safety{@prelim{}@mtsafe{}@asunsafe{@asucorrupt{} @asulock{}}@acunsafe{@aculock{}}}
  305. +
  306. +These are reentrant versions of @code{setkey} and @code{encrypt}. The
  307. +only difference is the extra parameter, which stores the expanded
  308. +version of @var{key}. Before calling @code{setkey_r} the first time,
  309. +@code{data->initialized} must be cleared to zero.
  310. +@end deftypefun
  311. +
  312. +The @code{setkey_r} and @code{encrypt_r} functions are GNU extensions.
  313. +@code{setkey}, @code{encrypt}, @code{setkey_r}, and @code{encrypt_r} are
  314. +defined in @file{crypt.h}.
  315. +
  316. +@deftypefun int ecb_crypt (char *@var{key}, char *@var{blocks}, unsigned int @var{len}, unsigned int @var{mode})
  317. +@standards{SUNRPC, rpc/des_crypt.h}
  318. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
  319. +
  320. +The function @code{ecb_crypt} encrypts or decrypts one or more blocks
  321. +using DES. Each block is encrypted independently.
  322. +
  323. +The @var{blocks} and the @var{key} are stored packed in 8-bit bytes, so
  324. +that the first bit of the key is the most-significant bit of
  325. +@code{key[0]} and the 63rd bit of the key is stored as the
  326. +least-significant bit of @code{key[7]}. The @var{key} should have the
  327. +correct parity.
  328. +
  329. +@var{len} is the number of bytes in @var{blocks}. It should be a
  330. +multiple of 8 (so that there are a whole number of blocks to encrypt).
  331. +@var{len} is limited to a maximum of @code{DES_MAXDATA} bytes.
  332. +
  333. +The result of the encryption replaces the input in @var{blocks}.
  334. +
  335. +The @var{mode} parameter is the bitwise OR of two of the following:
  336. +
  337. +@vtable @code
  338. +@item DES_ENCRYPT
  339. +@standards{SUNRPC, rpc/des_crypt.h}
  340. +This constant, used in the @var{mode} parameter, specifies that
  341. +@var{blocks} is to be encrypted.
  342. +
  343. +@item DES_DECRYPT
  344. +@standards{SUNRPC, rpc/des_crypt.h}
  345. +This constant, used in the @var{mode} parameter, specifies that
  346. +@var{blocks} is to be decrypted.
  347. +
  348. +@item DES_HW
  349. +@standards{SUNRPC, rpc/des_crypt.h}
  350. +This constant, used in the @var{mode} parameter, asks to use a hardware
  351. +device. If no hardware device is available, encryption happens anyway,
  352. +but in software.
  353. +
  354. +@item DES_SW
  355. +@standards{SUNRPC, rpc/des_crypt.h}
  356. +This constant, used in the @var{mode} parameter, specifies that no
  357. +hardware device is to be used.
  358. +@end vtable
  359. +
  360. +The result of the function will be one of these values:
  361. +
  362. +@vtable @code
  363. +@item DESERR_NONE
  364. +@standards{SUNRPC, rpc/des_crypt.h}
  365. +The encryption succeeded.
  366. +
  367. +@item DESERR_NOHWDEVICE
  368. +@standards{SUNRPC, rpc/des_crypt.h}
  369. +The encryption succeeded, but there was no hardware device available.
  370. +
  371. +@item DESERR_HWERROR
  372. +@standards{SUNRPC, rpc/des_crypt.h}
  373. +The encryption failed because of a hardware problem.
  374. +
  375. +@item DESERR_BADPARAM
  376. +@standards{SUNRPC, rpc/des_crypt.h}
  377. +The encryption failed because of a bad parameter, for instance @var{len}
  378. +is not a multiple of 8 or @var{len} is larger than @code{DES_MAXDATA}.
  379. +@end vtable
  380. +@end deftypefun
  381. +
  382. +@deftypefun int DES_FAILED (int @var{err})
  383. +@standards{SUNRPC, rpc/des_crypt.h}
  384. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
  385. +This macro returns 1 if @var{err} is a `success' result code from
  386. +@code{ecb_crypt} or @code{cbc_crypt}, and 0 otherwise.
  387. +@end deftypefun
  388. +
  389. +@deftypefun int cbc_crypt (char *@var{key}, char *@var{blocks}, unsigned int @var{len}, unsigned int @var{mode}, char *@var{ivec})
  390. +@standards{SUNRPC, rpc/des_crypt.h}
  391. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
  392. +
  393. +The function @code{cbc_crypt} encrypts or decrypts one or more blocks
  394. +using DES in Cipher Block Chaining mode.
  395. +
  396. +For encryption in CBC mode, each block is exclusive-ored with @var{ivec}
  397. +before being encrypted, then @var{ivec} is replaced with the result of
  398. +the encryption, then the next block is processed. Decryption is the
  399. +reverse of this process.
  400. +
  401. +This has the advantage that blocks which are the same before being
  402. +encrypted are very unlikely to be the same after being encrypted, making
  403. +it much harder to detect patterns in the data.
  404. +
  405. +Usually, @var{ivec} is set to 8 random bytes before encryption starts.
  406. +Then the 8 random bytes are transmitted along with the encrypted data
  407. +(without themselves being encrypted), and passed back in as @var{ivec}
  408. +for decryption. Another possibility is to set @var{ivec} to 8 zeroes
  409. +initially, and have the first block encrypted consist of 8 random
  410. +bytes.
  411. +
  412. +Otherwise, all the parameters are similar to those for @code{ecb_crypt}.
  413. +@end deftypefun
  414. +
  415. +@deftypefun void des_setparity (char *@var{key})
  416. +@standards{SUNRPC, rpc/des_crypt.h}
  417. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
  418. +
  419. +The function @code{des_setparity} changes the 64-bit @var{key}, stored
  420. +packed in 8-bit bytes, to have odd parity by altering the low bits of
  421. +each byte.
  422. +@end deftypefun
  423. +
  424. +The @code{ecb_crypt}, @code{cbc_crypt}, and @code{des_setparity}
  425. +functions and their accompanying macros are all defined in the header
  426. +@file{rpc/des_crypt.h}.
  427. +
  428. @node Unpredictable Bytes
  429. @section Generating Unpredictable Bytes
  430. @cindex randomness source
  431. --- a/manual/string.texi
  432. +++ b/manual/string.texi
  433. @@ -36,8 +36,8 @@ too.
  434. for delimiters.
  435. * Erasing Sensitive Data:: Clearing memory which contains sensitive
  436. data, after it's no longer needed.
  437. -* Shuffling Bytes:: Or how to flash-cook a string.
  438. -* Obfuscating Data:: Reversibly obscuring data from casual view.
  439. +* strfry:: Function for flash-cooking a string.
  440. +* Trivial Encryption:: Obscuring data.
  441. * Encode Binary Data:: Encoding and Decoding of Binary Data.
  442. * Argz and Envz Vectors:: Null-separated string vectors.
  443. @end menu
  444. @@ -2426,73 +2426,73 @@ functionality under a different name, su
  445. systems it may be in @file{strings.h} instead.
  446. @end deftypefun
  447. -
  448. -@node Shuffling Bytes
  449. -@section Shuffling Bytes
  450. +@node strfry
  451. +@section strfry
  452. The function below addresses the perennial programming quandary: ``How do
  453. I take good data in string form and painlessly turn it into garbage?''
  454. -This is not a difficult thing to code for oneself, but the authors of
  455. -@theglibc{} wish to make it as convenient as possible.
  456. +This is actually a fairly simple task for C programmers who do not use
  457. +@theglibc{} string functions, but for programs based on @theglibc{},
  458. +the @code{strfry} function is the preferred method for
  459. +destroying string data.
  460. -To @emph{erase} data, use @code{explicit_bzero} (@pxref{Erasing
  461. -Sensitive Data}); to obfuscate it reversibly, use @code{memfrob}
  462. -(@pxref{Obfuscating Data}).
  463. +The prototype for this function is in @file{string.h}.
  464. @deftypefun {char *} strfry (char *@var{string})
  465. @standards{GNU, string.h}
  466. @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
  467. @c Calls initstate_r, time, getpid, strlen, and random_r.
  468. -@code{strfry} performs an in-place shuffle on @var{string}. Each
  469. -character is swapped to a position selected at random, within the
  470. -portion of the string starting with the character's original position.
  471. -(This is the Fisher-Yates algorithm for unbiased shuffling.)
  472. -
  473. -Calling @code{strfry} will not disturb any of the random number
  474. -generators that have global state (@pxref{Pseudo-Random Numbers}).
  475. +@code{strfry} creates a pseudorandom anagram of a string, replacing the
  476. +input with the anagram in place. For each position in the string,
  477. +@code{strfry} swaps it with a position in the string selected at random
  478. +(from a uniform distribution). The two positions may be the same.
  479. The return value of @code{strfry} is always @var{string}.
  480. @strong{Portability Note:} This function is unique to @theglibc{}.
  481. -It is declared in @file{string.h}.
  482. +
  483. @end deftypefun
  484. -@node Obfuscating Data
  485. -@section Obfuscating Data
  486. +@node Trivial Encryption
  487. +@section Trivial Encryption
  488. +@cindex encryption
  489. +
  490. +
  491. +The @code{memfrob} function converts an array of data to something
  492. +unrecognizable and back again. It is not encryption in its usual sense
  493. +since it is easy for someone to convert the encrypted data back to clear
  494. +text. The transformation is analogous to Usenet's ``Rot13'' encryption
  495. +method for obscuring offensive jokes from sensitive eyes and such.
  496. +Unlike Rot13, @code{memfrob} works on arbitrary binary data, not just
  497. +text.
  498. @cindex Rot13
  499. -The @code{memfrob} function reversibly obfuscates an array of binary
  500. -data. This is not true encryption; the obfuscated data still bears a
  501. -clear relationship to the original, and no secret key is required to
  502. -undo the obfuscation. It is analogous to the ``Rot13'' cipher used on
  503. -Usenet for obscuring offensive jokes, spoilers for works of fiction,
  504. -and so on, but it can be applied to arbitrary binary data.
  505. -
  506. -Programs that need true encryption---a transformation that completely
  507. -obscures the original and cannot be reversed without knowledge of a
  508. -secret key---should use a dedicated cryptography library, such as
  509. -@uref{https://www.gnu.org/software/libgcrypt/,,libgcrypt}.
  510. -
  511. -Programs that need to @emph{destroy} data should use
  512. -@code{explicit_bzero} (@pxref{Erasing Sensitive Data}), or possibly
  513. -@code{strfry} (@pxref{Shuffling Bytes}).
  514. +For true encryption, @xref{Cryptographic Functions}.
  515. +
  516. +This function is declared in @file{string.h}.
  517. +@pindex string.h
  518. @deftypefun {void *} memfrob (void *@var{mem}, size_t @var{length})
  519. @standards{GNU, string.h}
  520. @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
  521. -The function @code{memfrob} obfuscates @var{length} bytes of data
  522. -beginning at @var{mem}, in place. Each byte is bitwise xor-ed with
  523. -the binary pattern 00101010 (hexadecimal 0x2A). The return value is
  524. -always @var{mem}.
  525. -
  526. -@code{memfrob} a second time on the same data returns it to
  527. -its original state.
  528. +@code{memfrob} transforms (frobnicates) each byte of the data structure
  529. +at @var{mem}, which is @var{length} bytes long, by bitwise exclusive
  530. +oring it with binary 00101010. It does the transformation in place and
  531. +its return value is always @var{mem}.
  532. +
  533. +Note that @code{memfrob} a second time on the same data structure
  534. +returns it to its original state.
  535. +
  536. +This is a good function for hiding information from someone who doesn't
  537. +want to see it or doesn't want to see it very much. To really prevent
  538. +people from retrieving the information, use stronger encryption such as
  539. +that described in @xref{Cryptographic Functions}.
  540. @strong{Portability Note:} This function is unique to @theglibc{}.
  541. -It is declared in @file{string.h}.
  542. +
  543. @end deftypefun
  544. @node Encode Binary Data
  545. --- a/posix/unistd.h
  546. +++ b/posix/unistd.h
  547. @@ -107,6 +107,9 @@ __BEGIN_DECLS
  548. /* The X/Open Unix extensions are available. */
  549. #define _XOPEN_UNIX 1
  550. +/* Encryption is present. */
  551. +#define _XOPEN_CRYPT 1
  552. +
  553. /* The enhanced internationalization capabilities according to XPG4.2
  554. are present. */
  555. #define _XOPEN_ENH_I18N 1
  556. @@ -1115,17 +1118,20 @@ ssize_t copy_file_range (int __infd, __o
  557. extern int fdatasync (int __fildes);
  558. #endif /* Use POSIX199309 */
  559. -#ifdef __USE_MISC
  560. -/* One-way hash PHRASE, returning a string suitable for storage in the
  561. - user database. SALT selects the one-way function to use, and
  562. - ensures that no two users' hashes are the same, even if they use
  563. - the same passphrase. The return value points to static storage
  564. - which will be overwritten by the next call to crypt. */
  565. +
  566. +/* XPG4.2 specifies that prototypes for the encryption functions must
  567. + be defined here. */
  568. +#ifdef __USE_XOPEN
  569. +/* Encrypt at most 8 characters from KEY using salt to perturb DES. */
  570. extern char *crypt (const char *__key, const char *__salt)
  571. __THROW __nonnull ((1, 2));
  572. -#endif
  573. -#ifdef __USE_XOPEN
  574. +/* Encrypt data in BLOCK in place if EDFLAG is zero; otherwise decrypt
  575. + block in place. */
  576. +extern void encrypt (char *__glibc_block, int __edflag)
  577. + __THROW __nonnull ((1));
  578. +
  579. +
  580. /* Swab pairs bytes in the first N bytes of the area pointed to by
  581. FROM and copy the result to TO. The value of TO must not be in the
  582. range [FROM - N + 1, FROM - 1]. If N is odd the first byte in FROM
  583. --- a/stdlib/stdlib.h
  584. +++ b/stdlib/stdlib.h
  585. @@ -961,6 +961,12 @@ extern int getsubopt (char **__restrict
  586. #endif
  587. +#ifdef __USE_XOPEN
  588. +/* Setup DES tables according KEY. */
  589. +extern void setkey (const char *__key) __THROW __nonnull ((1));
  590. +#endif
  591. +
  592. +
  593. /* X/Open pseudo terminal handling. */
  594. #ifdef __USE_XOPEN2KXSI
  595. --- a/sunrpc/Makefile
  596. +++ b/sunrpc/Makefile
  597. @@ -51,7 +51,7 @@ rpcsvc = bootparam_prot.x nlm_prot.x rst
  598. headers-sunrpc = $(addprefix rpc/,auth.h auth_unix.h clnt.h pmap_clnt.h \
  599. pmap_prot.h pmap_rmt.h rpc.h rpc_msg.h \
  600. svc.h svc_auth.h types.h xdr.h auth_des.h \
  601. - key_prot.h) \
  602. + des_crypt.h key_prot.h rpc_des.h) \
  603. $(rpcsvc:%=rpcsvc/%) rpcsvc/bootparam.h
  604. headers = rpc/netdb.h
  605. install-others = $(inst_sysconfdir)/rpc
  606. --- a/sunrpc/des_crypt.c
  607. +++ b/sunrpc/des_crypt.c
  608. @@ -86,9 +86,6 @@ common_crypt (char *key, char *buf, regi
  609. return desdev == DES_SW ? DESERR_NONE : DESERR_NOHWDEVICE;
  610. }
  611. -/* Note: these cannot be excluded from the build yet, because they are
  612. - still used internally. */
  613. -
  614. /*
  615. * CBC mode encryption
  616. */
  617. @@ -105,7 +102,7 @@ cbc_crypt (char *key, char *buf, unsigne
  618. COPY8 (dp.des_ivec, ivec);
  619. return err;
  620. }
  621. -hidden_nolink (cbc_crypt, libc, GLIBC_2_1)
  622. +libc_hidden_nolink_sunrpc (cbc_crypt, GLIBC_2_1)
  623. /*
  624. * ECB mode encryption
  625. @@ -118,4 +115,4 @@ ecb_crypt (char *key, char *buf, unsigne
  626. dp.des_mode = ECB;
  627. return common_crypt (key, buf, len, mode, &dp);
  628. }
  629. -hidden_nolink (ecb_crypt, libc, GLIBC_2_1)
  630. +libc_hidden_nolink_sunrpc (ecb_crypt, GLIBC_2_1)
  631. --- a/sunrpc/des_soft.c
  632. +++ b/sunrpc/des_soft.c
  633. @@ -71,4 +71,4 @@ des_setparity (char *p)
  634. p++;
  635. }
  636. }
  637. -hidden_nolink (des_setparity, libc, GLIBC_2_1)
  638. +libc_hidden_nolink_sunrpc (des_setparity, GLIBC_2_1)