crypt.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Mon, 08 Mar 2010 18:30:04 +0100
changeset 120 430dbec0c228
parent 119 305d2ca32936
child 128 efa226a4801e
permissions -rw-r--r--
step 1) move all headers to include/lsf committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
77
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 74
diff changeset
     2
 * crypt.c
9
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 8
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <stdio.h>
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <stdlib.h>
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
     8
#include <time.h>
119
305d2ca32936 crypt.h seems to be broken on many systems.
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
     9
#include <unistd.h>
305d2ca32936 crypt.h seems to be broken on many systems.
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    10
305d2ca32936 crypt.h seems to be broken on many systems.
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    11
#ifndef NO_CRYPT
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    12
#include <crypt.h>
119
305d2ca32936 crypt.h seems to be broken on many systems.
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    13
#endif
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    14
74
829976007e62 getrandom macro fixed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 56
diff changeset
    15
#define GETRANDOM(max) ('a'+(int)((float)(max)*rand()/RAND_MAX+1.0))
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
int main (int argc, char **argv)
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
{
56
966ad681f25d Short Description
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 32
diff changeset
    19
    char salt[12] = { 0 };
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
    if (argc != 2) {
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    22
        printf ("Usage: %s <plaintext>\n", argv[0]);
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    23
        return EXIT_FAILURE;
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
    }
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    26
    srand (time (NULL));
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
56
966ad681f25d Short Description
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 32
diff changeset
    28
    sprintf (salt, "$1$%c%c%c%c%c%c%c%c",
966ad681f25d Short Description
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 32
diff changeset
    29
             GETRANDOM (26), GETRANDOM (26),
966ad681f25d Short Description
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 32
diff changeset
    30
             GETRANDOM (26), GETRANDOM (26), GETRANDOM (26), GETRANDOM (26), GETRANDOM (26), GETRANDOM (26));
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
32
9b56360ec64e crypt extended
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
    32
    printf ("%s\n", crypt (argv[1], salt));
8
96d16dfe787a We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 0
diff changeset
    33
    return EXIT_SUCCESS;
0
af501b0c1716 demos cvs copy
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
}