1 /* bftest.c - Blowfish test program
2 * Copyright (C) 1998 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
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.
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.
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
25 #ifdef HAVE_DOSISH_SYSTEM
37 fprintf(stderr
, "usage: bftest [-e][-d] algo mode key\n");
46 #ifdef HAVE_LC_MESSAGES
47 setlocale( LC_MESSAGES
, "" );
49 setlocale( LC_ALL
, "" );
51 bindtextdomain( PACKAGE
, GNUPG_LOCALEDIR
);
52 textdomain( PACKAGE
);
57 main(int argc
, char **argv
)
66 #ifdef HAVE_DOSISH_SYSTEM
67 setmode( fileno(stdin
), O_BINARY
);
68 setmode( fileno(stdout
), O_BINARY
);
72 if( argc
> 1 && !strcmp(argv
[1], "-e") ) {
76 else if( argc
> 1 && !strcmp(argv
[1], "-E") ) {
81 else if( argc
> 1 && !strcmp(argv
[1], "-d") ) {
84 else if( argc
> 1 && !strcmp(argv
[1], "-D") ) {
91 algo
= gcry_cipher_map_name( *argv
);
93 s
= *argv
; argc
--; argv
++;
94 if ( !strcasecmp( s
, "cfb" ) )
95 mode
= GCRY_CIPHER_MODE_CFB
;
96 else if ( !strcasecmp( s
, "cbc" ) )
97 mode
= GCRY_CIPHER_MODE_CBC
;
98 else if ( !strcasecmp( s
, "ebc" ) )
99 mode
= GCRY_CIPHER_MODE_ECB
;
100 else if ( !strcasecmp( s
, "none" ) )
101 mode
= GCRY_CIPHER_MODE_NONE
;
102 else if ( !strcasecmp( s
, "stream" ) )
103 mode
= GCRY_CIPHER_MODE_STREAM
;
106 "wrong mode; use one of: none, ecb, cbc, cfb, stream\n");
110 hd
= gcry_cipher_open( algo
, mode
, 0 );
112 log_fatal("cipher open failed: %s\n", gcry_strerror(-1) );
113 rc
= gcry_cipher_setkey( hd
, *argv
, strlen(*argv
) );
115 log_fatal("setkey failed: %s\n", gcry_strerror(rc
) );
116 gcry_cipher_setiv( hd
, NULL
, 0 );
117 while( (n
= fread( buf
, 1, size
, stdin
)) > 0 ) {
119 gcry_cipher_encrypt( hd
, buf
, n
, buf
, n
);
121 gcry_cipher_decrypt( hd
, buf
, n
, buf
, n
);
122 if( fwrite( buf
, 1, n
, stdout
) != n
)
123 log_fatal("write error\n");
125 gcry_cipher_close(hd
);