~ubuntu-branches/ubuntu/precise/gnupg2/precise-updates

« back to all changes in this revision

Viewing changes to tools/bftest.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2005-12-08 22:13:21 UTC
  • mto: (5.1.1 edgy) (7.1.1 squeeze) (1.1.13 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20051208221321-d54343ca8hlwzkac
Tags: upstream-1.9.19
ImportĀ upstreamĀ versionĀ 1.9.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* bftest.c - Blowfish test program
2
 
 *      Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3
 
 *
4
 
 * This file is part of GnuPG.
5
 
 *
6
 
 * GnuPG is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * GnuPG is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
#include <stdio.h>
23
 
#include <stdlib.h>
24
 
#include <string.h>
25
 
#ifdef HAVE_DOSISH_SYSTEM
26
 
#include <io.h>
27
 
#include <fcntl.h>
28
 
#endif
29
 
 
30
 
#include "util.h"
31
 
#include "cipher.h"
32
 
#include "i18n.h"
33
 
 
34
 
static void
35
 
my_usage(void)
36
 
{
37
 
    fprintf(stderr, "usage: bftest [-e][-d] algo key\n");
38
 
    exit(1);
39
 
}
40
 
 
41
 
const char *
42
 
strusage( int level )
43
 
{
44
 
    return default_strusage(level);
45
 
}
46
 
 
47
 
static void
48
 
i18n_init(void)
49
 
{
50
 
#ifdef ENABLE_NLS
51
 
  setlocale( LC_ALL, "" );
52
 
  bindtextdomain( PACKAGE, G10_LOCALEDIR );
53
 
  textdomain( PACKAGE );
54
 
#endif
55
 
}
56
 
 
57
 
int
58
 
main(int argc, char **argv)
59
 
{
60
 
    int encode=0;
61
 
    CIPHER_HANDLE hd;
62
 
    char buf[4096];
63
 
    int n, size=4096;
64
 
    int algo;
65
 
 
66
 
#ifdef HAVE_DOSISH_SYSTEM
67
 
    setmode( fileno(stdin), O_BINARY );
68
 
    setmode( fileno(stdout), O_BINARY );
69
 
#endif
70
 
 
71
 
    i18n_init();
72
 
    if( argc > 1 && !strcmp(argv[1], "-e") ) {
73
 
        encode++;
74
 
        argc--; argv++;
75
 
    }
76
 
    else if( argc > 1 && !strcmp(argv[1], "-E") ) {
77
 
        encode++;
78
 
        argc--; argv++;
79
 
        size = 10;
80
 
    }
81
 
    else if( argc > 1 && !strcmp(argv[1], "-d") ) {
82
 
        argc--; argv++;
83
 
    }
84
 
    else if( argc > 1 && !strcmp(argv[1], "-D") ) {
85
 
        argc--; argv++;
86
 
        size = 10;
87
 
    }
88
 
    if( argc != 3 )
89
 
        my_usage();
90
 
    argc--; argv++;
91
 
    algo = string_to_cipher_algo( *argv );
92
 
    argc--; argv++;
93
 
 
94
 
    hd = cipher_open( algo, CIPHER_MODE_CFB, 0 );
95
 
    cipher_setkey( hd, *argv, strlen(*argv) );
96
 
    cipher_setiv( hd, NULL, 0 );
97
 
    while( (n = fread( buf, 1, size, stdin )) > 0 ) {
98
 
        if( encode )
99
 
            cipher_encrypt( hd, buf, buf, n );
100
 
        else
101
 
            cipher_decrypt( hd, buf, buf, n );
102
 
        if( fwrite( buf, 1, n, stdout) != n )
103
 
            log_fatal("write error\n");
104
 
    }
105
 
    cipher_close(hd);
106
 
    return 0;
107
 
}