IDEA ofb of a file with passwords
Script started on Tue Sep 16 12:06:35 1997
sh-2.00$ cat ideaofb1.c
/* Use OFB with IDEA to encrypt (or decrypt) a file. */
#include <stdio.h>
#include <fcntl.h>
#include "/usr/local/ssl/include/idea.h"
unsigned char key[128];
unsigned char iv[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01
};
void main(int argc, char * argv[])
{
int i;
int num = 0;
int fd, fd2;
unsigned char buffer[8];
unsigned char output[8];
IDEA_KEY_SCHEDULE enc;
/* Argument check. */
if(argc < 3)
{
printf("usage: ideaofbenc file file\n");
exit(1);
}
/* Try to open both files, creating output file if necessary. */
if((fd = open(argv[1], O_RDONLY, 0) ) < 0)
{
perror(argv[1]);
exit(1);
}
if((fd2 = open(argv[2], O_WRONLY | O_CREAT, 0666)) < 0)
{
perror(argv[2]);
exit(1);
}
/* Get a key from the user. */
/* We'll ask for two passwords. */
des_read_password(key,"Enter first password ", 0);
des_read_password(key+8, "Enter second password ", 0);
/* And yet another to set the IV. */
des_read_password(iv, "Enter third password ", 0);
/* We don't need a decryption schedule for OFB. */
idea_set_encrypt_key(key, &enc);
/* Try encrypting one byte at a time. */
/* Could improve this by increasing the size of the reads
and writes. */
while( read(fd, buffer, 1) > 0)
{
idea_ofb64_encrypt(buffer, output, 1, &enc, iv, &num);
write(fd2, output, 1);
}
close(fd);
close(fd2);
}
sh-2.00$ ideaofb1 testdata test3
Enter first password
Enter second password
Enter third password
sh-2.00$ ideaofb1 test3 test4
Enter first password
Enter second password
Enter third password
sh-2.00$ exit
exit
script done on Tue Sep 16 12:07:31 1997
I checked, we do indeed get the file contents back.