2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991,1993 University of Maryland
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * sendbackup-krb4.c - those bits of sendbackup code that deal with encrypting
29 * data streams over the network. Even though these just
30 * call the underlying DES routines, the U.S. government
31 * considers this a munition. Go figure.
33 #include "krb4-security.h"
34 #include "sendbackup-krb4.h"
37 * NOTE: This symbol must be the same as DATABUF_SIZE in
38 * server-src/dumper-krb4.c
39 * so that the encrypt/decrypt routines are working on the same sized buffers.
40 * Really, this should be moved out of dumper.c so that both programs can use
41 * the same symbol. Hopefully that can be done later. This is good enough
42 * to get encryption working for now...
44 * - Chris Ross (cross@uu.net) 4-Jun-1998
46 #define DATABUF_SIZE DISK_BLOCK_BYTES
48 void kencrypt_stream()
50 char *bp, buffer[DATABUF_SIZE];
51 int rdsize, wrsize, left;
52 des_key_schedule sched;
55 des_key_sched(session_key, sched);
58 /* read a block, taking into account short reads */
62 if((rdsize = read(0, bp, left)) == -1)
63 error("kencrypt: read error: %s", strerror(errno));
64 if(rdsize == 0) break;
68 if(bp == buffer) break; /* end of file */
70 if(bp < buffer+DATABUF_SIZE)
73 des_pcbc_encrypt(buffer, buffer, DATABUF_SIZE, sched, session_key,
76 for(l = 0, n = DATABUF_SIZE; l < n; l += wrsize) {
77 if((wrsize = write(1, buffer + l, n - l)) < 0) {
78 error("kencrypt: write error: %s", strerror(errno));