2 * Copyright (C) 1997,2000 Ian Jackson
4 * This is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with userv-utils; if not, write to the Free Software
16 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 static void checkrw(int r, int exp_r, const char *op, FILE *f) {
26 if (ferror(f)) { perror(op); exit(3); }
27 if (feof(f)) { fprintf(stderr,"unexpected eof on %s\n",op); exit(2); }
32 struct blowfish_cbc_state cbc;
33 unsigned char keybuf[BLOWFISH_MAXKEYBYTES], ivbuf[BLOWFISH_BLOCKBYTES];
34 unsigned char ibuf[BLOWFISH_BLOCKBYTES], obuf[BLOWFISH_BLOCKBYTES];
37 r= fread(keybuf,1,sizeof(keybuf),stdin); checkrw(r,sizeof(keybuf),"input",stdin);
38 blowfish_loadkey(&cbc.ek,keybuf,sizeof(keybuf));
40 r= fread(ibuf,1,sizeof(ivbuf),stdin); checkrw(r,sizeof(ivbuf),"input",stdin);
41 blowfish_cbc_setiv(&cbc,ivbuf);
44 r= fread(ibuf,1,sizeof(ibuf),stdin); if (r<sizeof(ibuf) && r>=0) break;
45 checkrw(r,sizeof(ibuf),"input",stdin);
46 blowfish_cbc_encrypt(&cbc,ibuf,obuf);
47 r= fwrite(obuf,1,sizeof(obuf),stdout); checkrw(r,sizeof(obuf),"output",stdout);
49 memset(ibuf+r,sizeof(ibuf)-r,sizeof(ibuf)-r);
50 blowfish_cbc_encrypt(&cbc,ibuf,obuf);
51 r= fwrite(obuf,1,sizeof(obuf),stdout); checkrw(r,sizeof(obuf),"output",stdout);