List Info

Thread: OpenSSL: openssl/crypto/cms/ cms.h cms_enc.c cms_err.c




OpenSSL: openssl/crypto/cms/ cms.h cms_enc.c cms_err.c
country flaguser name
Germany
2008-03-16 08:05:04
  OpenSSL CVS Repository
  http://cvs.openssl.org/
 
____________________________________________________________
________________

  Server: cvs.openssl.org                  Name:   Dr.
Stephen Henson
  Root:   /v/openssl/cvs                   Email:  steveopenssl.org
  Module: openssl                          Date:  
16-Mar-2008 14:05:04
  Branch: HEAD                             Handle:
2008031613050300

  Modified files:
    openssl/crypto/cms      cms.h cms_enc.c cms_err.c

  Log:
    Add support for random key generation: this will be
needed by
    enveloped data.

  Summary:
    Revision    Changes     Path
    1.8         +1  -0      openssl/crypto/cms/cms.h
    1.7         +33 -9      openssl/crypto/cms/cms_enc.c
    1.7         +1  -0      openssl/crypto/cms/cms_err.c
 
____________________________________________________________
________________

  patch -p0 <<' .'
  Index: openssl/crypto/cms/cms.h
 
============================================================
================
  $ cvs diff -u -r1.7 -r1.8 cms.h
  --- openssl/crypto/cms/cms.h	15 Mar 2008 23:21:31
-0000	1.7
  +++ openssl/crypto/cms/cms.h	16 Mar 2008 13:05:03
-0000	1.8
   -352,6 +352,7 
   #define CMS_R_NO_CONTENT				 116
   #define CMS_R_NO_DEFAULT_DIGEST				 117
   #define CMS_R_NO_DIGEST_SET				 118
  +#define CMS_R_NO_KEY					 148
   #define CMS_R_NO_MATCHING_DIGEST			 119
   #define CMS_R_NO_MATCHING_RECIPIENT			 147
   #define CMS_R_NO_PRIVATE_KEY				 120
   .
  patch -p0 <<' .'
  Index: openssl/crypto/cms/cms_enc.c
 
============================================================
================
  $ cvs diff -u -r1.6 -r1.7 cms_enc.c
  --- openssl/crypto/cms/cms_enc.c	15 Mar 2008 23:21:31
-0000	1.6
  +++ openssl/crypto/cms/cms_enc.c	16 Mar 2008 13:05:03
-0000	1.7
   -77,7 +77,7 
   
   	int ok = 0;
   
  -	int enc;
  +	int enc, keep_key = 0;
   
   	enc = ec->cipher ? 1 : 0;
   
   -134,10 +134,26 
   			goto err;
   			}
   
  -	/* If necessary set key length */
   
  -	if (ec->keylen != EVP_CIPHER_CTX_key_length(ctx))
  +	if (enc && !ec->key)
   		{
  +		/* Generate random key */
  +		if (!ec->keylen)
  +			ec->keylen = EVP_CIPHER_CTX_key_length(ctx);
  +		ec->key = OPENSSL_malloc(ec->keylen);
  +		if (!ec->key)
  +			{
  +			CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
  +							ERR_R_MALLOC_FAILURE);
  +			goto err;
  +			}
  +		if (EVP_CIPHER_CTX_rand_key(ctx, ec->key) <= 0)
  +			goto err;
  +		keep_key = 1;
  +		}
  +	else if (ec->keylen !=
EVP_CIPHER_CTX_key_length(ctx))
  +		{
  +		/* If necessary set key length */
   		if (EVP_CIPHER_CTX_set_key_length(ctx, ec->keylen)
<= 0)
   			{
   			CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
   -172,7 +188,7 
   	ok = 1;
   
   	err:
  -	if (ec->key)
  +	if (ec->key && !keep_key)
   		{
   		OPENSSL_cleanse(ec->key, ec->keylen);
   		OPENSSL_free(ec->key);
   -189,13 +205,16 
   				const unsigned char *key, size_t keylen)
   	{
   	ec->cipher = cipher;
  -	ec->key = OPENSSL_malloc(keylen);
  -	if (!ec->key)
  -		return 0;
  +	if (key)
  +		{
  +		ec->key = OPENSSL_malloc(keylen);
  +		if (!ec->key)
  +			return 0;
  +		memcpy(ec->key, key, keylen);
  +		}
  +	ec->keylen = keylen;
   	if (cipher)
   		ec->contentType = OBJ_nid2obj(NID_pkcs7_data);
  -	memcpy(ec->key, key, keylen);
  -	ec->keylen = keylen;
   	return 1;
   	}
   
   -203,6 +222,11 
   				const unsigned char *key, size_t keylen)
   	{
   	CMS_EncryptedContentInfo *ec;
  +	if (!key || !keylen)
  +		{
  +		CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY,
CMS_R_NO_KEY);
  +		return 0;
  +		}
   	if (ciph)
   		{
   		cms->d.encryptedData =
M_ASN1_new_of(CMS_EncryptedData);
   .
  patch -p0 <<' .'
  Index: openssl/crypto/cms/cms_err.c
 
============================================================
================
  $ cvs diff -u -r1.6 -r1.7 cms_err.c
  --- openssl/crypto/cms/cms_err.c	15 Mar 2008 23:21:31
-0000	1.6
  +++ openssl/crypto/cms/cms_err.c	16 Mar 2008 13:05:03
-0000	1.7
   -155,6 +155,7 
   {ERR_REASON(CMS_R_NO_CONTENT)            ,"no
content"},
   {ERR_REASON(CMS_R_NO_DEFAULT_DIGEST)     ,"no
default digest"},
   {ERR_REASON(CMS_R_NO_DIGEST_SET)         ,"no digest
set"},
  +{ERR_REASON(CMS_R_NO_KEY)                ,"no
key"},
   {ERR_REASON(CMS_R_NO_MATCHING_DIGEST)    ,"no
matching digest"},
   {ERR_REASON(CMS_R_NO_MATCHING_RECIPIENT) ,"no
matching recipient"},
   {ERR_REASON(CMS_R_NO_PRIVATE_KEY)        ,"no
private key"},
   .
____________________________________________________________
__________
OpenSSL Project                                 http://www.openssl.org
CVS Repository Commit List                    
openssl-cvsopenssl.org
Automated List Manager                          
majordomoopenssl.org

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )