From 006fd75aea5cc766bc223e435e5a07b543d658d3 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 17 Jun 2010 15:44:44 +0000 Subject: Avoid using the protect-tool to import pkcs#12. --- common/sexputil.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'common/sexputil.c') diff --git a/common/sexputil.c b/common/sexputil.c index 736caded3..b336145c4 100644 --- a/common/sexputil.c +++ b/common/sexputil.c @@ -36,7 +36,7 @@ #include "sexp-parse.h" -/* Helper function to create a a canonical encoded S-expression from a +/* Helper function to create a canonical encoded S-expression from a Libgcrypt S-expression object. The function returns 0 on success and the malloced canonical S-expression is stored at R_BUFFER and the allocated length at R_BUFLEN. On error an error code is @@ -71,6 +71,36 @@ make_canon_sexp (gcry_sexp_t sexp, unsigned char **r_buffer, size_t *r_buflen) } +/* Same as make_canon_sexp but pad the buffer to multiple of 64 + bits. */ +gpg_error_t +make_canon_sexp_pad (gcry_sexp_t sexp, + unsigned char **r_buffer, size_t *r_buflen) +{ + size_t len; + unsigned char *buf; + + *r_buffer = NULL; + if (r_buflen) + *r_buflen = 0;; + + len = gcry_sexp_sprint (sexp, GCRYSEXP_FMT_CANON, NULL, 0); + if (!len) + return gpg_error (GPG_ERR_BUG); + len += (8 - len % 8) % 8; + buf = xtrycalloc (1, len); + if (!buf) + return gpg_error_from_syserror (); + if (!gcry_sexp_sprint (sexp, GCRYSEXP_FMT_CANON, buf, len)) + return gpg_error (GPG_ERR_BUG); + + *r_buffer = buf; + if (r_buflen) + *r_buflen = len; + + return 0; +} + /* Return the so called "keygrip" which is the SHA-1 hash of the public key parameters expressed in a way depended on the algorithm. -- cgit v1.2.3