summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2010-06-17 17:44:44 +0200
committerWerner Koch <wk@gnupg.org>2010-06-17 17:44:44 +0200
commit006fd75aea5cc766bc223e435e5a07b543d658d3 (patch)
tree2f4365e73bf0a8b5272426fcf1fde9b75be4002e /common
parentAdd makefiles to build a w32 development package. (diff)
downloadgnupg2-006fd75aea5cc766bc223e435e5a07b543d658d3.tar.xz
gnupg2-006fd75aea5cc766bc223e435e5a07b543d658d3.zip
Avoid using the protect-tool to import pkcs#12.
Diffstat (limited to 'common')
-rw-r--r--common/ChangeLog8
-rw-r--r--common/membuf.c2
-rw-r--r--common/sexputil.c32
-rw-r--r--common/util.h2
4 files changed, 42 insertions, 2 deletions
diff --git a/common/ChangeLog b/common/ChangeLog
index 5aa39914c..e5815738c 100644
--- a/common/ChangeLog
+++ b/common/ChangeLog
@@ -1,3 +1,11 @@
+2010-06-17 Werner Koch <wk@g10code.com>
+
+ * sexputil.c (make_canon_sexp_pad): New.
+
+2010-06-14 Werner Koch <wk@g10code.com>
+
+ * membuf.c (put_membuf): Add shortcut for !LEN.
+
2010-06-11 Marcus Brinkmann <marcus@g10code.de>
* sysutils.c (translate_sys2libc_fd): Revert last change.
diff --git a/common/membuf.c b/common/membuf.c
index dc8f6f692..f9f82d357 100644
--- a/common/membuf.c
+++ b/common/membuf.c
@@ -59,7 +59,7 @@ init_membuf_secure (membuf_t *mb, int initiallen)
void
put_membuf (membuf_t *mb, const void *buf, size_t len)
{
- if (mb->out_of_core)
+ if (mb->out_of_core || !len)
return;
if (mb->len + len >= mb->size)
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.
diff --git a/common/util.h b/common/util.h
index 97ecef178..519bc5d68 100644
--- a/common/util.h
+++ b/common/util.h
@@ -146,6 +146,8 @@ gpg_error_t b64dec_finish (struct b64state *state);
/*-- sexputil.c */
gpg_error_t make_canon_sexp (gcry_sexp_t sexp,
unsigned char **r_buffer, size_t *r_buflen);
+gpg_error_t make_canon_sexp_pad (gcry_sexp_t sexp,
+ unsigned char **r_buffer, size_t *r_buflen);
gpg_error_t keygrip_from_canon_sexp (const unsigned char *key, size_t keylen,
unsigned char *grip);
int cmp_simple_canon_sexp (const unsigned char *a, const unsigned char *b);