diff options
author | Tobias Brunner <tobias@strongswan.org> | 2013-08-15 12:29:06 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2013-09-13 15:23:49 +0200 |
commit | b5cc7053c83285181b0ee7ea0f13bed3431d9fd0 (patch) | |
tree | 91a8fad57409cda8717012f1e8b57d0c3000e155 /src/libstrongswan/plugins/openssl/openssl_util.c | |
parent | a3232fa802b08447d3fb9534da5342992eee5337 (diff) | |
download | strongswan-b5cc7053c83285181b0ee7ea0f13bed3431d9fd0.tar.bz2 strongswan-b5cc7053c83285181b0ee7ea0f13bed3431d9fd0.tar.xz |
openssl: Add helper function to convert BIGNUMs to chunks
Diffstat (limited to 'src/libstrongswan/plugins/openssl/openssl_util.c')
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_util.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_util.c b/src/libstrongswan/plugins/openssl/openssl_util.c index bc10dd28c..0e61086b1 100644 --- a/src/libstrongswan/plugins/openssl/openssl_util.c +++ b/src/libstrongswan/plugins/openssl/openssl_util.c @@ -126,6 +126,24 @@ bool openssl_bn_split(chunk_t chunk, BIGNUM *a, BIGNUM *b) /** * Described in header. */ +bool openssl_bn2chunk(BIGNUM *bn, chunk_t *chunk) +{ + *chunk = chunk_alloc(BN_num_bytes(bn)); + if (BN_bn2bin(bn, chunk->ptr) == chunk->len) + { + if (chunk->len && chunk->ptr[0] & 0x80) + { /* if MSB is set, prepend a zero to make it non-negative */ + *chunk = chunk_cat("cm", chunk_from_chars(0x00), *chunk); + } + return TRUE; + } + chunk_free(chunk); + return FALSE; +} + +/** + * Described in header. + */ chunk_t openssl_asn1_obj2chunk(ASN1_OBJECT *asn1) { if (asn1) |