aboutsummaryrefslogtreecommitdiff
path: root/crypto/dsa
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2019-06-10 17:52:15 +0100
committerPauli <paul.dale@oracle.com>2019-07-12 06:26:46 +1000
commitb8805834756434bfc6ee3840e7097e6e1a877905 (patch)
tree8e0850d386e82479a6900ba864d4f5c13079356c /crypto/dsa
parent15cb0f095878092a625219f58bd915bdf1acc973 (diff)
downloadopenssl-b8805834756434bfc6ee3840e7097e6e1a877905.zip
openssl-b8805834756434bfc6ee3840e7097e6e1a877905.tar.gz
openssl-b8805834756434bfc6ee3840e7097e6e1a877905.tar.bz2
Convert asn1_dsa.c to use the WPACKET API instead
Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/9111)
Diffstat (limited to 'crypto/dsa')
-rw-r--r--crypto/dsa/dsa_asn1.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/crypto/dsa/dsa_asn1.c b/crypto/dsa/dsa_asn1.c
index 1c7e8c8..eddcc11 100644
--- a/crypto/dsa/dsa_asn1.c
+++ b/crypto/dsa/dsa_asn1.c
@@ -61,30 +61,42 @@ DSA_SIG *d2i_DSA_SIG(DSA_SIG **psig, const unsigned char **ppin, long len)
int i2d_DSA_SIG(const DSA_SIG *sig, unsigned char **ppout)
{
- unsigned char *buf = NULL;
- unsigned char *tmp;
- unsigned char **pp = NULL;
- size_t len;
+ BUF_MEM *buf = NULL;
size_t encoded_len;
+ WPACKET pkt;
- if (ppout != NULL && *ppout == NULL) {
- if ((len = encode_der_dsa_sig(sig->r, sig->s, NULL, SIZE_MAX)) == 0)
+ if (ppout == NULL) {
+ if (!WPACKET_init_null(&pkt, 0))
return -1;
- buf = OPENSSL_malloc(len);
- if (buf == NULL)
+ } else if (*ppout == NULL) {
+ if ((buf = BUF_MEM_new()) == NULL
+ || !WPACKET_init_len(&pkt, buf, 0)) {
+ BUF_MEM_free(buf);
return -1;
- tmp = buf;
- pp = &tmp;
+ }
} else {
- len = SIZE_MAX;
- pp = ppout;
+ if (!WPACKET_init_static_len(&pkt, *ppout, SIZE_MAX, 0))
+ return -1;
}
- if ((encoded_len = encode_der_dsa_sig(sig->r, sig->s, pp, len)) == 0) {
- OPENSSL_free(buf);
+
+ if (!encode_der_dsa_sig(&pkt, sig->r, sig->s)
+ || !WPACKET_get_total_written(&pkt, &encoded_len)
+ || !WPACKET_finish(&pkt)) {
+ BUF_MEM_free(buf);
+ WPACKET_cleanup(&pkt);
return -1;
}
- if (buf != NULL)
- *ppout = buf;
+
+ if (ppout != NULL) {
+ if (*ppout == NULL) {
+ *ppout = (unsigned char *)buf->data;
+ buf->data = NULL;
+ BUF_MEM_free(buf);
+ } else {
+ *ppout += encoded_len;
+ }
+ }
+
return (int)encoded_len;
}