[Cryptech-Commits] [sw/libhal] branch master updated: Allow NULL der_len parameter in hal-rsa_private_key_to_der().

git at cryptech.is git at cryptech.is
Mon Jun 13 19:46:42 UTC 2016


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch master
in repository sw/libhal.

The following commit(s) were added to refs/heads/master by this push:
       new  a20af99   Allow NULL der_len parameter in hal-rsa_private_key_to_der().
a20af99 is described below

commit a20af9980516d516f0403bb80551db8d283aa383
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Mon Jun 13 12:49:53 2016 -0400

    Allow NULL der_len parameter in hal-rsa_private_key_to_der().
---
 rsa.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/rsa.c b/rsa.c
index 7269aa9..8438bea 100644
--- a/rsa.c
+++ b/rsa.c
@@ -697,7 +697,7 @@ hal_error_t hal_rsa_private_key_to_der(const hal_rsa_key_t * const key,
 {
   hal_error_t err = HAL_OK;
 
-  if (key == NULL || der_len == NULL || key->type != HAL_KEY_TYPE_RSA_PRIVATE)
+  if (key == NULL || key->type != HAL_KEY_TYPE_RSA_PRIVATE)
     return HAL_ERROR_BAD_ARGUMENTS;
 
   fp_int version[1] = INIT_FP_INT;
@@ -706,9 +706,9 @@ hal_error_t hal_rsa_private_key_to_der(const hal_rsa_key_t * const key,
    * Calculate data length.
    */
 
-  size_t vlen = 0;
+  size_t hlen = 0, vlen = 0;
 
-#define _(x) { size_t i; if ((err = hal_asn1_encode_integer(x, NULL, &i, der_max - vlen)) != HAL_OK) return err; vlen += i; }
+#define _(x) { size_t n; if ((err = hal_asn1_encode_integer(x, NULL, &n, der_max - vlen)) != HAL_OK) return err; vlen += n; }
   RSAPrivateKey_fields;
 #undef _
 
@@ -716,11 +716,11 @@ hal_error_t hal_rsa_private_key_to_der(const hal_rsa_key_t * const key,
    * Encode header.
    */
 
-  if ((err = hal_asn1_encode_header(ASN1_SEQUENCE, vlen, der, der_len, der_max))  != HAL_OK)
+  if ((err = hal_asn1_encode_header(ASN1_SEQUENCE, vlen, der, &hlen, der_max))  != HAL_OK)
     return err;
 
-  const size_t hlen = *der_len;
-  *der_len += vlen;
+  if (der_len != NULL)
+    *der_len = hlen + vlen;
 
   if (der == NULL)
     return HAL_OK;
@@ -731,7 +731,7 @@ hal_error_t hal_rsa_private_key_to_der(const hal_rsa_key_t * const key,
 
   der += hlen;
 
-#define _(x) { size_t i; if ((err = hal_asn1_encode_integer(x, der, &i, vlen)) != HAL_OK) return err; der += i; vlen -= i; }
+#define _(x) { size_t n; if ((err = hal_asn1_encode_integer(x, der, &n, vlen)) != HAL_OK) return err; der += n; vlen -= n; }
   RSAPrivateKey_fields;
 #undef _
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Commits mailing list