CSM_Buffer memory allocation sheme, AppLogin and 3DES Encryption

"Simon Blanchet" <[email protected]> Wed, 13 Jun 2001 15:35:42 -0400
Newsgroups gmane.ietf.sfl
Message-ID <[email protected]>
I've been trying to work with SFL since a little time and I'm experiencing some problems.  First of all, I only wanted
to encrypt a very simple mail message using an previously generated X.509 Certificate (using OpenSSL).  I'm not totally
sure of the step that I used to do so.

More Information about my current Setup:

OS: Windows 2000
CTIL: sm_Free3DLL (using Crypto++ (I don't Have RSA BSafe))
SFL Version: 1.9

Basically here is what I'm trying to do:

1- I have a text file (filename: FromOutlook.txt) that represents a "upper level" MIME Entity (Begin with
Content-Type:...).
2- I have a X.509 DEREncoded Certificate previously generated with OpenSSL (filename: SimonBlanchetCert.cer)

What I'm trying to do:

(Only Encrypt, no signing, not including sender's cert)

1- Encrypt the FromOutlook.txt using 3DES-EDE3-CBC (for the CEK)
2- Encrypt the CEK with the Public Key of Certificate SimonBlanchetCert.cer
3- Obtain the resulting CMS Message (Encoded BLOB)

Now I'll present how I tried to do what I wanted (please correct me where I'm wrong)

1- Login to SFL using CSM_AppLogin

CSM_AppLogin* pAppLogin = new CSM_AppLogin("sm_free3DLLd", "sm_free3DLL NULL NULL NULL sm_FREE3");

2- Create an CSM_Buffer in order to construct an CSM_MsgToEncrypt

CSM_Buffer buf("FromOutlook.txt");

3- Create an CSM_MsgToEncrypt with the CSM_Buffer

CSM_MsgToEncrypt msg(&buf);

4- Trying to assing a recipient's Certificate

msg.SetContentEncryptOID(new CSM_OID("1.2.840.113549.3.7"));  // Necessay Step??? (is there any other ways)

CSM_Buffer cert("SimonBlanchetCert.cer");

CSM_RecipientInfo recipient(cert);

msg.m_pRecipients = new CSM_RecipientInfoLst;  // Is it the right way? (why it's my responsability to allocate memory?)

msg.m_pRecipients->AppendL(&recipient);  // It works (but does not looks like the right way...)

5- Try to encrypt the thing...

msg.Encrypt(pAppLogin);  // Takes arround 4 minutes for a ContentData of ~300k !!!!

It works until it tries to encrypt CEK with Recipient Info (it was not initialized (don't know how... it looks like...))


I misUnderstand a lot of thing (I think):

- AppLogin (I only want to encrypt so I don't need to initialize with PrivateKey or PKCS12... (at least I think...))
- How to assign recipients (Certificates and Recipients ID?)
- Memory allocation while encrypting (CSM_Buffer::AllocMoreMem is called like so many time for nothing)

I have many questions:

- Why does it takes so long to encrypt a very simple mail (size: ~300k) is it because of the fact that you are
allocating memory with 8 bytes chunks within CSM_Buffer::Write?  Do I need to do a special setup first to tell the size
of the resulting encryption?  By the way the lenght of the resulting BLOB is previsible no? (we can compute it for
single allocation before doing the processing... (just round the ContentToEncrypt to the next multiple of blockSize for
a BlockCipher))?

- Is it possible to Login without providing PrivateKey information in the case that you Encrypt Only (using 3DES for
Symmetric Encryption and RSA to encrypt CEK for the recipient)?

- What is the "Right" way to add (and constructs) recipient related information to a content that you only want to
encrypt?


By the way I'm not even sure if a use your SFL Library like it is supposed to be used (Read: Maybe I'm trying to do
something really simple the wrong way).

Thanks a lot for your support (and your futur answers)


|=========================================
| Simon Blanchet
| Software Designer
|
| Email: [email protected]
|=========================================