2 * OpenConnect (SSL + DTLS) VPN client
4 * Copyright © 2008-2012 Intel Corporation.
6 * Author: David Woodhouse <dwmw2@infradead.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * version 2.1, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to:
20 * Free Software Foundation, Inc.
21 * 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA
27 #include <openssl/evp.h>
28 #include <openssl/rand.h>
30 #include "openconnect-internal.h"
32 int openconnect_sha1(unsigned char *result, void *data, int len)
37 EVP_Digest(data, len, result, NULL, EVP_sha1(), NULL);
38 EVP_MD_CTX_cleanup(&c);
43 int openconnect_get_cert_DER(struct openconnect_info *vpninfo,
44 struct x509_st *cert, unsigned char **buf)
46 BIO *bp = BIO_new(BIO_s_mem());
50 if (!i2d_X509_bio(bp, cert)) {
55 BIO_get_mem_ptr(bp, &certinfo);
62 memcpy(*buf, certinfo->data, l);
67 int openconnect_random(void *bytes, int len)
69 if (RAND_bytes(bytes, len) != 1)