~ubuntu-branches/ubuntu/natty/ccrypt/natty

« back to all changes in this revision

Viewing changes to check/crypt3-check.c

  • Committer: Bazaar Package Importer
  • Author(s): Jean-Francois Dive
  • Date: 2003-09-07 21:46:53 UTC
  • Revision ID: james.westby@ubuntu.com-20030907214653-ht1thvjqegmejyq0
Tags: 1.6-1
* New upstream version.
* Removed the cccat renaming and conflict with cfs (closes: #180915).
* debian/rules clean remove configure generated files.
* Fix gcc 3.3 cleanups (multi-line and reserved word warnings) (closes: 194875).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2003 Peter Selinger.
 
2
   This file is part of ccrypt. It is free software and it is covered
 
3
   by the GNU general public license. See the file COPYING for details. */
 
4
 
 
5
/* test the crypt(3) replacement against the library crypt(3). Note
 
6
   that on many systems, crypt(3) does not exist, and even on those
 
7
   systems where it does, it is often buggy. 
 
8
 
 
9
   crypt(3) only looks at the lower 7 bits of the characters in a key,
 
10
   and only at the first 8 characters. Some implementations differ in
 
11
   whether they consider 128 as an end-of-string character or not
 
12
   (FreeBSD does, SunOS and GNU do not). The character 128 is unlikely
 
13
   to appear in a password, and we only check compliance for
 
14
   characters 1-127 here. */
 
15
 
 
16
#include <config.h>        /* generated by configure */
 
17
 
 
18
#ifndef HAVE_LIBCRYPT      /* this check doesn't make sense if the
 
19
                              reference crypt(3) is not available */
 
20
int main() {
 
21
  return 77;
 
22
}
 
23
 
 
24
#else
 
25
 
 
26
#define _XOPEN_SOURCE
 
27
#include <unistd.h>
 
28
#include <stdio.h>
 
29
#include <time.h>
 
30
#include <stdlib.h>
 
31
#include <string.h>
 
32
 
 
33
#include "../src/unixcrypt3.h"
 
34
 
 
35
#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
 
36
 
 
37
int main() {
 
38
  int seed = time(0);
 
39
  int total = 0;
 
40
  int i,j,l,n,k;
 
41
  char salt[2];
 
42
  char key[8];
 
43
  char res1[13];
 
44
  char res2[13];
 
45
  char *p;
 
46
 
 
47
  printf("Random seed: %d\n", seed);
 
48
  srand(seed);
 
49
 
 
50
  /* give it a good spin */
 
51
  for (i=0; i<64; i++) {
 
52
    salt[0] = bin_to_ascii(i);
 
53
 
 
54
    for (k=0; k<20; k++) {
 
55
      j = rand() % 64;
 
56
      salt[1] = bin_to_ascii(j);
 
57
 
 
58
      l = rand() % 9;
 
59
      for (n=0; n<l; n++) {
 
60
        key[n] = rand() % 127 + 1;
 
61
      }
 
62
      if (n<8) {
 
63
        key[n] = 0;
 
64
      }
 
65
      p = crypt_replacement(key, salt);
 
66
      strncpy(res1, p, 13);
 
67
      p = crypt(key, salt);
 
68
      strncpy(res2, p, 13);
 
69
      if (strncmp(res1, res2, 13)!=0) {
 
70
        printf("Discrepancy for salt %c%c, password length %d\n",
 
71
               salt[0], salt[1], l);
 
72
        total++;
 
73
      }
 
74
    }
 
75
  }
 
76
  
 
77
  if (total) {
 
78
    printf("Failed: %d discrepancies.\n", total);
 
79
    return 1;
 
80
  } else {
 
81
    printf("Passed.\n");
 
82
    return 0;
 
83
  }
 
84
}
 
85
 
 
86
#endif /* HAVE_LIBCRYPT */