2 * Copyright 1988 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
12 #include "mit-cpyright.h"
19 Key_schedule KEYSCHED;
20 C_Block key = { 0, 1, 2, 3, 4, 5, 6, 7 };
22 char inbuf[512 + 8]; /* leave room for cksum and len */
29 #include "AFS_component_version_number.c"
40 fprintf(stderr, "%s: Usage: %s infile outfile mode.\n", argv[0],
44 if (!strcmp(argv[3], "e"))
46 else if (!strcmp(argv[3], "d"))
49 fprintf(stderr, "%s: Mode must be e (encrypt) or d (decrypt).\n",
53 if ((ind = open(argv[1], O_RDONLY, 0666)) < 0) {
54 fprintf(stderr, "%s: Cannot open %s for input.\n", argv[0], argv[1]);
57 if (!strcmp(argv[2], "-"))
59 else if ((oud = open(argv[2], O_CREAT | O_WRONLY, 0666)) < 0) {
60 fprintf(stderr, "%s: Cannot open %s for output.\n", argv[0], argv[2]);
64 (void)freopen("/dev/tty", "r", stdin);
65 (void)freopen("/dev/tty", "w", stdout);
67 read_password(key, "\n\07\07Enter Key> ", 1);
68 if (key_sched(key, KEYSCHED) < 0) {
69 fprintf(stderr, "%s: Key parity error\n", argv[0]);
74 memcpy(sum, key, sizeof(C_Block));
76 if ((length = read(ind, inbuf, 512)) < 0) {
77 fprintf(stderr, "%s: Error reading from input.\n", argv[0]);
79 } else if (length == 0) {
80 fprintf(stderr, "\n");
85 sum = quad_cksum(inbuf, NULL, length, 1, sum);
87 quad_cksum(inbuf, sum, length, 1, sum);
89 fprintf(stderr, "\nlength = %d tot length = %d quad_sum = %X %X",
90 length, orig_size, *(afs_uint32 *) sum,
91 *((afs_uint32 *) sum + 1));
94 pcbc_encrypt(inbuf, oubuf, (afs_int32) length, KEYSCHED, ivec,
98 sum = quad_cksum(oubuf, NULL, length, 1, sum);
100 quad_cksum(oubuf, sum, length, 1, sum);
102 fprintf(stderr, "\nlength = %d tot length = %d quad_sum = %X ",
103 length, orig_size, *(afs_uint32 *) sum,
104 *((afs_uint32 *) sum + 1));
106 length = (length + 7) & ~07;
107 write(oud, oubuf, length);
109 p = (int *)&oubuf[length - 8];
111 p = (int *)&inbuf[length - 8];
116 fprintf(stderr, "\ntot length = %d quad_sum = %X\n", orig_size, sum);
117 /* if encrypting, now put the original length and checksum in */