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