1 From ssl-lists-owner@mincom.com Tue Oct 15 18:16:14 1996
2 Received: from cygnus.mincom.oz.au by orb.mincom.oz.au with SMTP id AA11550
3 (5.65c/IDA-1.4.4 for eay); Tue, 15 Oct 1996 08:17:41 +1000
4 Received: (from daemon@localhost) by cygnus.mincom.oz.au (8.7.5/8.7.3) id IAA12472 for ssl-users-outgoing; Tue, 15 Oct 1996 08:16:35 +1000 (EST)
5 Received: from orb.mincom.oz.au (eay@orb.mincom.oz.au [192.55.197.1]) by cygnus.mincom.oz.au (8.7.5/8.7.3) with SMTP id IAA12463 for <ssl-users@listserv.mincom.oz.au>; Tue, 15 Oct 1996 08:16:32 +1000 (EST)
6 Received: by orb.mincom.oz.au id AA11544
7 (5.65c/IDA-1.4.4 for ssl-users@listserv.mincom.oz.au); Tue, 15 Oct 1996 08:16:15 +1000
8 Date: Tue, 15 Oct 1996 08:16:14 +1000 (EST)
9 From: Eric Young <eay@mincom.com>
11 To: Roland Haring <rharing@tandem.cl>
12 Cc: ssl-users@mincom.com
13 Subject: Re: Symmetric encryption with ssleay
14 In-Reply-To: <m0vBpyq-00001aC@tandemnet.tandem.cl>
15 Message-Id: <Pine.SOL.3.91.961015075623.11394A-100000@orb>
17 Content-Type: TEXT/PLAIN; charset=US-ASCII
18 Sender: ssl-lists-owner@mincom.com
24 On Fri, 11 Oct 1996, Roland Haring wrote:
26 > Would somebody be so kind to give me the minimum basic
27 > calls I need to do to libcrypto.a to get some text encrypted
28 > and decrypted again? ...hopefully with code included to do
29 > base64 encryption and decryption ... e.g. that sign-it.c code
30 > posted some while ago was a big help :-) (please, do not point
31 > me to apps/enc.c where I suspect my Heissenbug to be hidden :-)
33 Ok, the base64 encoding stuff in 'enc.c' does the wrong thing sometimes
34 when the data is less than a line long (this is for decoding). I'll dig
35 up the exact fix today and post it. I am taking longer on 0.6.5 than I
36 intended so I'll just post this patch.
38 The documentation to read is in
40 doc/encode.doc (very sparse :-).
44 The basic calls to encrypt with say triple DES are
47 char key[EVP_MAX_KEY_LENGTH];
48 char iv[EVP_MAX_IV_LENGTH];
50 unsigned char out[512+8];
53 /* optional generation of key/iv data from text password using md5
54 * via an upward compatable verson of PKCS#5. */
55 EVP_BytesToKey(EVP_des_ede3_cbc,EVP_md5,NULL,passwd,strlen(passwd),
58 /* Initalise the EVP_CIPHER_CTX */
59 EVP_EncryptInit(ctx,EVP_des_ede3_cbc,key,iv);
63 /* This is processing 512 bytes at a time, the bytes are being
64 * copied into 'out', outl bytes are output. 'out' should not be the
65 * same as 'in' for reasons mentioned in the documentation. */
66 EVP_EncryptUpdate(ctx,out,&outl,in,512);
69 /* Output the last 'block'. If the cipher is a block cipher, the last
70 * block is encoded in such a way so that a wrong decryption will normally be
71 * detected - again, one of the PKCS standards. */
73 EVP_EncryptFinal(ctx,out,&outl);
75 To decrypt, use the EVP_DecryptXXXXX functions except that EVP_DecryptFinal()
76 will return 0 if the decryption fails (only detectable on block ciphers).
82 which does either encryption or decryption depending on an extra
83 parameter to EVP_CipherInit().
86 To do the base64 encoding,
95 where the encoding is quite simple, but the decoding can be a bit more
96 fun (due to dud input).
98 EVP_DecodeUpdate() returns -1 for an error on an input line, 0 if the
99 'last line' was just processed, and 1 if more lines should be submitted.
101 EVP_DecodeFinal() returns -1 for an error or 1 if things are ok.
107 i=EVP_DecodeUpdate(....);
110 /* process the data */
114 EVP_DecodeFinal(....);
115 /* process the data */
117 The problem in 'enc.c' is that I was stuff the processing up after the
118 EVP_DecodeFinal(...) when the for(..) loop was not being run (one line of
119 base64 data) and this was because 'enc.c' tries to scan over a file until
120 it hits the first valid base64 encoded line.
122 hope this helps a bit.
125 Eric Young | BOOL is tri-state according to Bill Gates.
126 AARNet: eay@mincom.oz.au | RTFM Win32 GetMessage().