1/* Additional defines for WolfSSL, see
2 * https://github.com/civetweb/civetweb/issues/583 */
3
4
5/* Required for WOLFSSL_X509 */
6#include <openssl/../internal.h>
7
8
9#define i2d_X509 cw_i2d_X509
10#define EVP_Digest cw_EVP_Digest
11
12
13/* i2d_X509 has no valid implementation in wolfssl
14 *
15 * The letters i and d in for example i2d_X509 stand for "internal" (that is an
16 *internal C structure)
17 * and " DER ". So that i2d_X509 converts from internal to DER.
18 *
19 * For OpenSSL 0.9.7 and later if *out is NULL memory will be allocated for a
20 *buffer and the encoded
21 * data written to it. In this case *out is not incremented and it points to the
22 *start of the data
23 * just written.
24 */
25int
26cw_i2d_X509(struct WOLFSSL_X509 *x, unsigned char **out)
27{
28	if (!x || !x->derCert) {
29		return -1;
30	}
31
32	const int ret = (int)x->derCert->length;
33
34	if (out && (ret > 0)) {
35		if (*out == NULL) {
36			*out = mg_malloc(ret);
37		}
38		if (*out != NULL) {
39			memcpy(*out, x->derCert->buffer, ret);
40		}
41	}
42
43	return ret;
44}
45
46
47/* EVP_Digest not in wolfssl */
48int
49cw_EVP_Digest(const void *data,
50              size_t count,
51              unsigned char *md,
52              unsigned int *size,
53              const EVP_MD *type,
54              ENGINE *impl)
55{
56	EVP_MD_CTX *ctx = EVP_MD_CTX_new();
57	int ret;
58
59	if (ctx == NULL)
60		return 0;
61
62	/* EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT); */
63	ret = EVP_DigestInit_ex(ctx, type, impl)
64	      && EVP_DigestUpdate(ctx, data, count)
65	      && EVP_DigestFinal_ex(ctx, md, size);
66	EVP_MD_CTX_free(ctx);
67
68	return ret;
69}
70
71
72/*
73 * the variable SSL_OP_NO_TLSv1_1 is not defined within the context of
74 * wolfssl but since the methods using the value are all stubs, we can
75 * define it arbitrarily and it will not have any consequences
76 */
77#define SSL_OP_NO_TLSv1_1 (0x10000000L)
78