subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmpil...@apache.org
Subject svn commit: r1325451 - /subversion/trunk/subversion/libsvn_subr/crypto.c
Date Thu, 12 Apr 2012 19:04:04 GMT
Author: cmpilato
Date: Thu Apr 12 19:04:04 2012
New Revision: 1325451

URL: http://svn.apache.org/viewvc?rev=1325451&view=rev
Log:
* subversion/libsvn_subr/crypto.c
  (svn_crypto__generate_secret_checktext): Ensure that we are
    generating block-aligned random "stuff".

Modified:
    subversion/trunk/subversion/libsvn_subr/crypto.c

Modified: subversion/trunk/subversion/libsvn_subr/crypto.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/crypto.c?rev=1325451&r1=1325450&r2=1325451&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/crypto.c (original)
+++ subversion/trunk/subversion/libsvn_subr/crypto.c Thu Apr 12 19:04:04 2012
@@ -504,18 +504,11 @@ svn_crypto__generate_secret_checktext(co
   apr_size_t result_len;
   unsigned char *result;
   apr_size_t ignored_result_len = 0;
+  apr_size_t stuff_len;
   svn_checksum_t *stuff_sum;
 
   SVN_ERR_ASSERT(ctx != NULL);
 
-  /* Generate 32 bytes of random stuff. */
-#define STUFF_LEN 32
-  SVN_ERR(get_random_bytes(&stuff_vector, ctx, STUFF_LEN, scratch_pool));
-
-  /* ### FIXME:  This should be a SHA-256.  */
-  SVN_ERR(svn_checksum(&stuff_sum, svn_checksum_sha1, stuff_vector,
-                       STUFF_LEN, scratch_pool));
-
   /* Generate the salt. */
   SVN_ERR(get_random_bytes(&salt_vector, ctx, SALT_LEN, result_pool));
 
@@ -549,9 +542,23 @@ svn_crypto__generate_secret_checktext(co
                              ctx, apr_err,
                              _("Error initializing block encryption")));
 
+  /* Generate a blob of random data, block-aligned per the
+     requirements of the encryption algorithm, but with a minimum size
+     of our choosing.  */
+#define MIN_STUFF_LEN 32
+  if (MIN_STUFF_LEN % block_size)
+    stuff_len = MIN_STUFF_LEN + (block_size - (MIN_STUFF_LEN % block_size));
+  else
+    stuff_len = MIN_STUFF_LEN;
+  SVN_ERR(get_random_bytes(&stuff_vector, ctx, stuff_len, scratch_pool));
+
+  /* ### FIXME:  This should be a SHA-256.  */
+  SVN_ERR(svn_checksum(&stuff_sum, svn_checksum_sha1, stuff_vector,
+                       stuff_len, scratch_pool));
+
   /* Get the length that we need to allocate.  */
   apr_err = apr_crypto_block_encrypt(NULL, &result_len, stuff_vector,
-                                     STUFF_LEN, block_ctx);
+                                     stuff_len, block_ctx);
   if (apr_err != APR_SUCCESS)
     {
       err = crypto_error_create(ctx, apr_err,
@@ -564,7 +571,7 @@ svn_crypto__generate_secret_checktext(co
 
   /* Encrypt the block. */
   apr_err = apr_crypto_block_encrypt(&result, &result_len, stuff_vector,
-                                     STUFF_LEN, block_ctx);
+                                     stuff_len, block_ctx);
   if (apr_err != APR_SUCCESS)
     {
       err = crypto_error_create(ctx, apr_err,



Mime
View raw message