root/utils/sha1pass

Revision b536209dfb7bd50c37061735fe10d2c19a97d26d, 0.6 KB (checked in by H. Peter Anvin <hpa@…>, 4 years ago)

Move files out of root into core, dos, and utils

Move source files out of the root directory; the root is a mess and
has become virtually unmaintainable. The Syslinux core now lives in
core/; the Linux and generic utilities has moved into utils/, and
copybs.com has moved into dos/; it had to go somewhere, and it seemed
as good a place as any.

  • Property mode set to 100755
Line 
1#!/usr/bin/perl
2
3use bytes;
4use Digest::SHA1;
5use MIME::Base64;
6
7sub random_bytes($) {
8    my($n) = @_;
9    my($v, $i);
10
11    if ( open(RANDOM, '<', '/dev/random') ||
12         open(RANDOM, '<', '/dev/urandom') ) {
13        read(RANDOM, $v, $n);
14    } else {
15        # No real RNG available...
16        srand($$ ^ time);
17        $v = '';
18        for ( $i = 0 ; $i < $n ; $i++ ) {
19            $v .= ord(int(rand() * 256));
20        }
21    }
22
23    return $v;
24}
25
26
27($pass, $salt) = @ARGV;
28
29unless (defined($salt)) {
30    $salt = MIME::Base64::encode(random_bytes(6), '');
31}
32$pass = Digest::SHA1::sha1_base64($salt, $pass);
33
34print '$4$', $salt, '$', $pass, "\$\n";
Note: See TracBrowser for help on using the browser.