diff options
author | Rob Austein <sra@hactrn.net> | 2016-06-13 12:49:53 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2016-06-13 12:49:53 -0400 |
commit | a20af9980516d516f0403bb80551db8d283aa383 (patch) | |
tree | ae732107a7c56dca3a81ebf804d14163b3760f1a /rsa.c | |
parent | 290d6ff054e2b68717eacc15ddaecae080d1ad3d (diff) |
Allow NULL der_len parameter in hal-rsa_private_key_to_der().
Diffstat (limited to 'rsa.c')
-rw-r--r-- | rsa.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -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 _ |