13 if( !$Config{d_crypt} ) {
14 skip_all("crypt unimplemented");
21 # Can't assume too much about the string returned by crypt(),
22 # and about how many bytes of the encrypted (really, hashed)
25 # HISTORICALLY the results started with the first two bytes of the salt,
26 # followed by 11 bytes from the set [./0-9A-Za-z], and only the first
27 # eight characters mattered, but those are probably no more safe
28 # bets, given alternative encryption/hashing schemes like MD5,
29 # C2 (or higher) security schemes, and non-UNIX platforms.
31 # On platforms implementing FIPS mode, using a weak algorithm (including
32 # the default triple-DES algorithm) causes crypt(3) to return a null
33 # pointer, which Perl converts into undef. We assume for now that all
34 # such platforms support glibc-style selection of a different hashing
36 my $alg = ''; # Use default algorithm
37 if ( !defined(crypt("ab", "cd")) ) {
38 $alg = '$5$'; # Use SHA-256
42 skip ("VOS crypt ignores salt.", 1) if ($^O eq 'vos');
43 ok(substr(crypt("ab", $alg."cd"), 2) ne substr(crypt("ab", $alg."ce"), 2),
44 "salt makes a difference");
49 eval {$b = crypt($a, $alg."cd")};
50 like($@, qr/Wide character in crypt/, "wide characters ungood");
52 chop $a; # throw away the wide character
54 eval {$b = crypt($a, $alg."cd")};
55 is($@, '', "downgrade to eight bit characters");
56 is($b, crypt("a\xFF", $alg."cd"), "downgrade results agree");
58 my $x = chr 256; # has to be lexical, and predeclared
59 # Assignment gets optimised away here:
60 $x = crypt "foo", ${\"bar"}; # ${\ } to defeat constant folding
61 is $x, crypt("foo", "bar"), 'crypt writing to utf8 target';
62 ok !utf8::is_utf8($x), 'crypt turns off utf8 on its target';