~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to tools/bftest.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

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
 
    #ifdef HAVE_LC_MESSAGES
52
 
       setlocale( LC_MESSAGES, "" );
53
 
    #else
54
 
       setlocale( LC_ALL, "" );
55
 
    #endif
56
 
    bindtextdomain( PACKAGE, G10_LOCALEDIR );
57
 
    textdomain( PACKAGE );
58
 
  #endif
59
 
}
60
 
 
61
 
int
62
 
main(int argc, char **argv)
63
 
{
64
 
    int encode=0;
65
 
    CIPHER_HANDLE hd;
66
 
    char buf[4096];
67
 
    int n, size=4096;
68
 
    int algo;
69
 
 
70
 
  #ifdef HAVE_DOSISH_SYSTEM
71
 
    setmode( fileno(stdin), O_BINARY );
72
 
    setmode( fileno(stdout), O_BINARY );
73
 
  #endif
74
 
 
75
 
    i18n_init();
76
 
    if( argc > 1 && !strcmp(argv[1], "-e") ) {
77
 
        encode++;
78
 
        argc--; argv++;
79
 
    }
80
 
    else if( argc > 1 && !strcmp(argv[1], "-E") ) {
81
 
        encode++;
82
 
        argc--; argv++;
83
 
        size = 10;
84
 
    }
85
 
    else if( argc > 1 && !strcmp(argv[1], "-d") ) {
86
 
        argc--; argv++;
87
 
    }
88
 
    else if( argc > 1 && !strcmp(argv[1], "-D") ) {
89
 
        argc--; argv++;
90
 
        size = 10;
91
 
    }
92
 
    if( argc != 3 )
93
 
        my_usage();
94
 
    argc--; argv++;
95
 
    algo = string_to_cipher_algo( *argv );
96
 
    argc--; argv++;
97
 
 
98
 
    hd = cipher_open( algo, CIPHER_MODE_CFB, 0 );
99
 
    cipher_setkey( hd, *argv, strlen(*argv) );
100
 
    cipher_setiv( hd, NULL, 0 );
101
 
    while( (n = fread( buf, 1, size, stdin )) > 0 ) {
102
 
        if( encode )
103
 
            cipher_encrypt( hd, buf, buf, n );
104
 
        else
105
 
            cipher_decrypt( hd, buf, buf, n );
106
 
        if( fwrite( buf, 1, n, stdout) != n )
107
 
            log_fatal("write error\n");
108
 
    }
109
 
    cipher_close(hd);
110
 
    return 0;
111
 
}
112