3 Please read the README file for condition of use, before
6 Maurice Gittens <mgittens@gits.nl> January 1997
14 #include <openssl/evp.h>
19 #define INIT_VECTOR "12345678"
22 #define ALG EVP_des_ede3_cbc()
24 static const char *usage
= "Usage: example3 [-d] password\n";
26 void do_cipher(char *,int);
28 int main(int argc
, char *argv
[])
32 do_cipher(argv
[1],ENCRYPT
);
34 else if ((argc
== 3) && !strcmp(argv
[1],"-d"))
36 do_cipher(argv
[2],DECRYPT
);
40 fprintf(stderr
,"%s", usage
);
47 void do_cipher(char *pw
, int operation
)
50 char ebuf
[BUFLEN
+ 8];
51 unsigned int ebuflen
; /* rc; */
52 unsigned char iv
[EVP_MAX_IV_LENGTH
], key
[EVP_MAX_KEY_LENGTH
];
53 /* unsigned int ekeylen, net_ekeylen; */
56 memcpy(iv
, INIT_VECTOR
, sizeof(iv
));
58 EVP_BytesToKey(ALG
, EVP_md5(), "salu", pw
, strlen(pw
), 1, key
, iv
);
60 EVP_CIPHER_CTX_init(&ectx
);
61 EVP_CipherInit_ex(&ectx
, ALG
, NULL
, key
, iv
, operation
);
65 int readlen
= read(STDIN
, buf
, sizeof(buf
));
78 EVP_CipherUpdate(&ectx
, ebuf
, &ebuflen
, buf
, readlen
);
80 write(STDOUT
, ebuf
, ebuflen
);
83 EVP_CipherFinal_ex(&ectx
, ebuf
, &ebuflen
);
84 EVP_CIPHER_CTX_cleanup(&ectx
);
86 write(STDOUT
, ebuf
, ebuflen
);