file_path
stringlengths 19
75
| code
stringlengths 279
1.37M
|
---|---|
./openssl/fuzz/asn1.c | /*
* Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/*
* Fuzz ASN.1 parsing for various data structures. Specify which on the
* command line:
*
* asn1 <data structure>
*/
/* We need to use some deprecated APIs */
#define OPENSSL_SUPPRESS_DEPRECATED
#include <stdio.h>
#include <string.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/dh.h>
#include <openssl/dsa.h>
#include <openssl/ec.h>
#include <openssl/ocsp.h>
#include <openssl/pkcs12.h>
#include <openssl/rsa.h>
#include <openssl/ts.h>
#include <openssl/x509v3.h>
#include <openssl/cms.h>
#include <openssl/ess.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/ssl.h>
#include "internal/nelem.h"
#include "fuzzer.h"
static ASN1_ITEM_EXP *item_type[] = {
ASN1_ITEM_ref(ACCESS_DESCRIPTION),
#ifndef OPENSSL_NO_RFC3779
ASN1_ITEM_ref(ASIdentifierChoice),
ASN1_ITEM_ref(ASIdentifiers),
ASN1_ITEM_ref(ASIdOrRange),
#endif
ASN1_ITEM_ref(ASN1_ANY),
ASN1_ITEM_ref(ASN1_BIT_STRING),
ASN1_ITEM_ref(ASN1_BMPSTRING),
ASN1_ITEM_ref(ASN1_BOOLEAN),
ASN1_ITEM_ref(ASN1_ENUMERATED),
ASN1_ITEM_ref(ASN1_FBOOLEAN),
ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
ASN1_ITEM_ref(ASN1_GENERALSTRING),
ASN1_ITEM_ref(ASN1_IA5STRING),
ASN1_ITEM_ref(ASN1_INTEGER),
ASN1_ITEM_ref(ASN1_NULL),
ASN1_ITEM_ref(ASN1_OBJECT),
ASN1_ITEM_ref(ASN1_OCTET_STRING),
ASN1_ITEM_ref(ASN1_OCTET_STRING_NDEF),
ASN1_ITEM_ref(ASN1_PRINTABLE),
ASN1_ITEM_ref(ASN1_PRINTABLESTRING),
ASN1_ITEM_ref(ASN1_SEQUENCE),
ASN1_ITEM_ref(ASN1_SEQUENCE_ANY),
ASN1_ITEM_ref(ASN1_SET_ANY),
ASN1_ITEM_ref(ASN1_T61STRING),
ASN1_ITEM_ref(ASN1_TBOOLEAN),
ASN1_ITEM_ref(ASN1_TIME),
ASN1_ITEM_ref(ASN1_UNIVERSALSTRING),
ASN1_ITEM_ref(ASN1_UTCTIME),
ASN1_ITEM_ref(ASN1_UTF8STRING),
ASN1_ITEM_ref(ASN1_VISIBLESTRING),
#ifndef OPENSSL_NO_RFC3779
ASN1_ITEM_ref(ASRange),
#endif
ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
ASN1_ITEM_ref(AUTHORITY_KEYID),
ASN1_ITEM_ref(BASIC_CONSTRAINTS),
ASN1_ITEM_ref(BIGNUM),
ASN1_ITEM_ref(CBIGNUM),
ASN1_ITEM_ref(CERTIFICATEPOLICIES),
#ifndef OPENSSL_NO_CMS
ASN1_ITEM_ref(CMS_ContentInfo),
ASN1_ITEM_ref(CMS_ReceiptRequest),
ASN1_ITEM_ref(CRL_DIST_POINTS),
#endif
#ifndef OPENSSL_NO_DH
ASN1_ITEM_ref(DHparams),
#endif
ASN1_ITEM_ref(DIRECTORYSTRING),
ASN1_ITEM_ref(DISPLAYTEXT),
ASN1_ITEM_ref(DIST_POINT),
ASN1_ITEM_ref(DIST_POINT_NAME),
#if !defined(OPENSSL_NO_EC) && !defined(OPENSSL_NO_DEPRECATED_3_0)
ASN1_ITEM_ref(ECPARAMETERS),
ASN1_ITEM_ref(ECPKPARAMETERS),
#endif
ASN1_ITEM_ref(EDIPARTYNAME),
ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
ASN1_ITEM_ref(GENERAL_NAME),
ASN1_ITEM_ref(GENERAL_NAMES),
ASN1_ITEM_ref(GENERAL_SUBTREE),
#ifndef OPENSSL_NO_RFC3779
ASN1_ITEM_ref(IPAddressChoice),
ASN1_ITEM_ref(IPAddressFamily),
ASN1_ITEM_ref(IPAddressOrRange),
ASN1_ITEM_ref(IPAddressRange),
#endif
ASN1_ITEM_ref(ISSUING_DIST_POINT),
#ifndef OPENSSL_NO_DEPRECATED_3_0
ASN1_ITEM_ref(LONG),
#endif
ASN1_ITEM_ref(NAME_CONSTRAINTS),
ASN1_ITEM_ref(NETSCAPE_CERT_SEQUENCE),
ASN1_ITEM_ref(NETSCAPE_SPKAC),
ASN1_ITEM_ref(NETSCAPE_SPKI),
ASN1_ITEM_ref(NOTICEREF),
#ifndef OPENSSL_NO_OCSP
ASN1_ITEM_ref(OCSP_BASICRESP),
ASN1_ITEM_ref(OCSP_CERTID),
ASN1_ITEM_ref(OCSP_CERTSTATUS),
ASN1_ITEM_ref(OCSP_CRLID),
ASN1_ITEM_ref(OCSP_ONEREQ),
ASN1_ITEM_ref(OCSP_REQINFO),
ASN1_ITEM_ref(OCSP_REQUEST),
ASN1_ITEM_ref(OCSP_RESPBYTES),
ASN1_ITEM_ref(OCSP_RESPDATA),
ASN1_ITEM_ref(OCSP_RESPID),
ASN1_ITEM_ref(OCSP_RESPONSE),
ASN1_ITEM_ref(OCSP_REVOKEDINFO),
ASN1_ITEM_ref(OCSP_SERVICELOC),
ASN1_ITEM_ref(OCSP_SIGNATURE),
ASN1_ITEM_ref(OCSP_SINGLERESP),
#endif
ASN1_ITEM_ref(OTHERNAME),
ASN1_ITEM_ref(PBE2PARAM),
ASN1_ITEM_ref(PBEPARAM),
ASN1_ITEM_ref(PBKDF2PARAM),
ASN1_ITEM_ref(PKCS12),
ASN1_ITEM_ref(PKCS12_AUTHSAFES),
ASN1_ITEM_ref(PKCS12_BAGS),
ASN1_ITEM_ref(PKCS12_MAC_DATA),
ASN1_ITEM_ref(PKCS12_SAFEBAG),
ASN1_ITEM_ref(PKCS12_SAFEBAGS),
ASN1_ITEM_ref(PKCS7),
ASN1_ITEM_ref(PKCS7_ATTR_SIGN),
ASN1_ITEM_ref(PKCS7_ATTR_VERIFY),
ASN1_ITEM_ref(PKCS7_DIGEST),
ASN1_ITEM_ref(PKCS7_ENC_CONTENT),
ASN1_ITEM_ref(PKCS7_ENCRYPT),
ASN1_ITEM_ref(PKCS7_ENVELOPE),
ASN1_ITEM_ref(PKCS7_ISSUER_AND_SERIAL),
ASN1_ITEM_ref(PKCS7_RECIP_INFO),
ASN1_ITEM_ref(PKCS7_SIGNED),
ASN1_ITEM_ref(PKCS7_SIGN_ENVELOPE),
ASN1_ITEM_ref(PKCS7_SIGNER_INFO),
ASN1_ITEM_ref(PKCS8_PRIV_KEY_INFO),
ASN1_ITEM_ref(PKEY_USAGE_PERIOD),
ASN1_ITEM_ref(POLICY_CONSTRAINTS),
ASN1_ITEM_ref(POLICYINFO),
ASN1_ITEM_ref(POLICY_MAPPING),
ASN1_ITEM_ref(POLICY_MAPPINGS),
ASN1_ITEM_ref(POLICYQUALINFO),
ASN1_ITEM_ref(PROXY_CERT_INFO_EXTENSION),
ASN1_ITEM_ref(PROXY_POLICY),
ASN1_ITEM_ref(RSA_OAEP_PARAMS),
ASN1_ITEM_ref(RSA_PSS_PARAMS),
#ifndef OPENSSL_NO_DEPRECATED_3_0
ASN1_ITEM_ref(RSAPrivateKey),
ASN1_ITEM_ref(RSAPublicKey),
#endif
ASN1_ITEM_ref(SXNET),
ASN1_ITEM_ref(SXNETID),
ASN1_ITEM_ref(USERNOTICE),
ASN1_ITEM_ref(X509),
ASN1_ITEM_ref(X509_ALGOR),
ASN1_ITEM_ref(X509_ALGORS),
ASN1_ITEM_ref(X509_ATTRIBUTE),
ASN1_ITEM_ref(X509_CERT_AUX),
ASN1_ITEM_ref(X509_CINF),
ASN1_ITEM_ref(X509_CRL),
ASN1_ITEM_ref(X509_CRL_INFO),
ASN1_ITEM_ref(X509_EXTENSION),
ASN1_ITEM_ref(X509_EXTENSIONS),
ASN1_ITEM_ref(X509_NAME),
ASN1_ITEM_ref(X509_NAME_ENTRY),
ASN1_ITEM_ref(X509_PUBKEY),
ASN1_ITEM_ref(X509_REQ),
ASN1_ITEM_ref(X509_REQ_INFO),
ASN1_ITEM_ref(X509_REVOKED),
ASN1_ITEM_ref(X509_SIG),
ASN1_ITEM_ref(X509_VAL),
#ifndef OPENSSL_NO_DEPRECATED_3_0
ASN1_ITEM_ref(ZLONG),
#endif
ASN1_ITEM_ref(INT32),
ASN1_ITEM_ref(ZINT32),
ASN1_ITEM_ref(UINT32),
ASN1_ITEM_ref(ZUINT32),
ASN1_ITEM_ref(INT64),
ASN1_ITEM_ref(ZINT64),
ASN1_ITEM_ref(UINT64),
ASN1_ITEM_ref(ZUINT64),
NULL
};
static ASN1_PCTX *pctx;
#define DO_TEST(TYPE, D2I, I2D, PRINT) { \
const unsigned char *p = buf; \
unsigned char *der = NULL; \
TYPE *type = D2I(NULL, &p, len); \
\
if (type != NULL) { \
int len2; \
BIO *bio = BIO_new(BIO_s_null()); \
\
if (bio != NULL) { \
PRINT(bio, type); \
BIO_free(bio); \
} \
len2 = I2D(type, &der); \
if (len2 != 0) {} \
OPENSSL_free(der); \
TYPE ## _free(type); \
} \
}
#define DO_TEST_PRINT_OFFSET(TYPE, D2I, I2D, PRINT) { \
const unsigned char *p = buf; \
unsigned char *der = NULL; \
TYPE *type = D2I(NULL, &p, len); \
\
if (type != NULL) { \
BIO *bio = BIO_new(BIO_s_null()); \
\
if (bio != NULL) { \
PRINT(bio, type, 0); \
BIO_free(bio); \
} \
I2D(type, &der); \
OPENSSL_free(der); \
TYPE ## _free(type); \
} \
}
#define DO_TEST_PRINT_PCTX(TYPE, D2I, I2D, PRINT) { \
const unsigned char *p = buf; \
unsigned char *der = NULL; \
TYPE *type = D2I(NULL, &p, len); \
\
if (type != NULL) { \
BIO *bio = BIO_new(BIO_s_null()); \
\
if (bio != NULL) { \
PRINT(bio, type, 0, pctx); \
BIO_free(bio); \
} \
I2D(type, &der); \
OPENSSL_free(der); \
TYPE ## _free(type); \
} \
}
#define DO_TEST_NO_PRINT(TYPE, D2I, I2D) { \
const unsigned char *p = buf; \
unsigned char *der = NULL; \
TYPE *type = D2I(NULL, &p, len); \
\
if (type != NULL) { \
BIO *bio = BIO_new(BIO_s_null()); \
\
BIO_free(bio); \
I2D(type, &der); \
OPENSSL_free(der); \
TYPE ## _free(type); \
} \
}
int FuzzerInitialize(int *argc, char ***argv)
{
FuzzerSetRand();
pctx = ASN1_PCTX_new();
ASN1_PCTX_set_flags(pctx, ASN1_PCTX_FLAGS_SHOW_ABSENT |
ASN1_PCTX_FLAGS_SHOW_SEQUENCE | ASN1_PCTX_FLAGS_SHOW_SSOF |
ASN1_PCTX_FLAGS_SHOW_TYPE | ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME);
ASN1_PCTX_set_str_flags(pctx, ASN1_STRFLGS_UTF8_CONVERT |
ASN1_STRFLGS_SHOW_TYPE | ASN1_STRFLGS_DUMP_ALL);
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
int n;
for (n = 0; item_type[n] != NULL; ++n) {
const uint8_t *b = buf;
unsigned char *der = NULL;
const ASN1_ITEM *i = ASN1_ITEM_ptr(item_type[n]);
ASN1_VALUE *o = ASN1_item_d2i(NULL, &b, len, i);
if (o != NULL) {
BIO *bio = BIO_new(BIO_s_null());
if (bio != NULL) {
ASN1_item_print(bio, o, 4, i, pctx);
BIO_free(bio);
}
if (ASN1_item_i2d(o, &der, i) > 0) {
OPENSSL_free(der);
}
ASN1_item_free(o, i);
}
}
#ifndef OPENSSL_NO_TS
DO_TEST(TS_REQ, d2i_TS_REQ, i2d_TS_REQ, TS_REQ_print_bio);
DO_TEST(TS_MSG_IMPRINT, d2i_TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, TS_MSG_IMPRINT_print_bio);
DO_TEST(TS_RESP, d2i_TS_RESP, i2d_TS_RESP, TS_RESP_print_bio);
DO_TEST(TS_STATUS_INFO, d2i_TS_STATUS_INFO, i2d_TS_STATUS_INFO, TS_STATUS_INFO_print_bio);
DO_TEST(TS_TST_INFO, d2i_TS_TST_INFO, i2d_TS_TST_INFO, TS_TST_INFO_print_bio);
DO_TEST_NO_PRINT(TS_ACCURACY, d2i_TS_ACCURACY, i2d_TS_ACCURACY);
#endif
DO_TEST_NO_PRINT(ESS_ISSUER_SERIAL, d2i_ESS_ISSUER_SERIAL, i2d_ESS_ISSUER_SERIAL);
DO_TEST_NO_PRINT(ESS_CERT_ID, d2i_ESS_CERT_ID, i2d_ESS_CERT_ID);
DO_TEST_NO_PRINT(ESS_SIGNING_CERT, d2i_ESS_SIGNING_CERT, i2d_ESS_SIGNING_CERT);
DO_TEST_NO_PRINT(ESS_CERT_ID_V2, d2i_ESS_CERT_ID_V2, i2d_ESS_CERT_ID_V2);
DO_TEST_NO_PRINT(ESS_SIGNING_CERT_V2, d2i_ESS_SIGNING_CERT_V2, i2d_ESS_SIGNING_CERT_V2);
#if !defined(OPENSSL_NO_DH) && !defined(OPENSSL_NO_DEPRECATED_3_0)
DO_TEST_NO_PRINT(DH, d2i_DHparams, i2d_DHparams);
DO_TEST_NO_PRINT(DH, d2i_DHxparams, i2d_DHxparams);
#endif
#ifndef OPENSSL_NO_DSA
DO_TEST_NO_PRINT(DSA_SIG, d2i_DSA_SIG, i2d_DSA_SIG);
# ifndef OPENSSL_NO_DEPRECATED_3_0
DO_TEST_NO_PRINT(DSA, d2i_DSAPrivateKey, i2d_DSAPrivateKey);
DO_TEST_NO_PRINT(DSA, d2i_DSAPublicKey, i2d_DSAPublicKey);
DO_TEST_NO_PRINT(DSA, d2i_DSAparams, i2d_DSAparams);
# endif
#endif
#ifndef OPENSSL_NO_DEPRECATED_3_0
DO_TEST_NO_PRINT(RSA, d2i_RSAPublicKey, i2d_RSAPublicKey);
#endif
#ifndef OPENSSL_NO_EC
# ifndef OPENSSL_NO_DEPRECATED_3_0
DO_TEST_PRINT_OFFSET(EC_GROUP, d2i_ECPKParameters, i2d_ECPKParameters, ECPKParameters_print);
DO_TEST_PRINT_OFFSET(EC_KEY, d2i_ECPrivateKey, i2d_ECPrivateKey, EC_KEY_print);
DO_TEST(EC_KEY, d2i_ECParameters, i2d_ECParameters, ECParameters_print);
DO_TEST_NO_PRINT(ECDSA_SIG, d2i_ECDSA_SIG, i2d_ECDSA_SIG);
# endif
#endif
DO_TEST_PRINT_PCTX(EVP_PKEY, d2i_AutoPrivateKey, i2d_PrivateKey, EVP_PKEY_print_private);
DO_TEST(SSL_SESSION, d2i_SSL_SESSION, i2d_SSL_SESSION, SSL_SESSION_print);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
ASN1_PCTX_free(pctx);
FuzzerClearRand();
}
|
./openssl/fuzz/punycode.c | /*
* Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include "crypto/punycode.h"
#include "internal/nelem.h"
#include <openssl/crypto.h>
#include "fuzzer.h"
#include <stdio.h>
#include <string.h>
int FuzzerInitialize(int *argc, char ***argv)
{
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
char *b;
unsigned int out[16], outlen = OSSL_NELEM(out);
char outc[16];
b = OPENSSL_malloc(len + 1);
if (b != NULL) {
ossl_punycode_decode((const char *)buf, len, out, &outlen);
memcpy(b, buf, len);
b[len] = '\0';
ossl_a2ulabel(b, outc, sizeof(outc));
OPENSSL_free(b);
}
return 0;
}
void FuzzerCleanup(void)
{
}
|
./openssl/fuzz/quic-lcidm.c | /*
* Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include "fuzzer.h"
#include "internal/quic_lcidm.h"
#include "internal/packet.h"
int FuzzerInitialize(int *argc, char ***argv)
{
FuzzerSetRand();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL);
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
ERR_clear_error();
return 1;
}
/*
* Fuzzer input "protocol":
* Big endian
* u8(LCID length)
* Zero or more of:
* ENROL_ODCID u0(0x00) u64(opaque) u8(cidl):cid
* RETIRE_ODCID u8(0x01) u64(opaque)
* GENERATE_INITIAL u8(0x02) u64(opaque)
* GENERATE u8(0x03) u64(opaque)
* RETIRE u8(0x04) u64(opaque) u64(retire_prior_to)
* CULL u8(0x05) u64(opaque)
* LOOKUP u8(0x06) u8(cidl):cid
*/
enum {
CMD_ENROL_ODCID,
CMD_RETIRE_ODCID,
CMD_GENERATE_INITIAL,
CMD_GENERATE,
CMD_RETIRE,
CMD_CULL,
CMD_LOOKUP
};
static int get_cid(PACKET *pkt, QUIC_CONN_ID *cid)
{
unsigned int cidl;
if (!PACKET_get_1(pkt, &cidl)
|| cidl > QUIC_MAX_CONN_ID_LEN
|| !PACKET_copy_bytes(pkt, cid->id, cidl))
return 0;
cid->id_len = (unsigned char)cidl;
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
int rc = 0;
QUIC_LCIDM *lcidm = NULL;
PACKET pkt;
uint64_t arg_opaque, arg_retire_prior_to, seq_num_out;
unsigned int cmd, lcidl;
QUIC_CONN_ID arg_cid, cid_out;
OSSL_QUIC_FRAME_NEW_CONN_ID ncid_frame;
int did_retire;
void *opaque_out;
if (!PACKET_buf_init(&pkt, buf, len))
goto err;
if (!PACKET_get_1(&pkt, &lcidl)
|| lcidl > QUIC_MAX_CONN_ID_LEN) {
rc = -1;
goto err;
}
if ((lcidm = ossl_quic_lcidm_new(NULL, lcidl)) == NULL) {
rc = -1;
goto err;
}
while (PACKET_remaining(&pkt) > 0) {
if (!PACKET_get_1(&pkt, &cmd))
goto err;
switch (cmd) {
case CMD_ENROL_ODCID:
if (!PACKET_get_net_8(&pkt, &arg_opaque)
|| !get_cid(&pkt, &arg_cid)) {
rc = -1;
goto err;
}
ossl_quic_lcidm_enrol_odcid(lcidm, (void *)(uintptr_t)arg_opaque,
&arg_cid);
break;
case CMD_RETIRE_ODCID:
if (!PACKET_get_net_8(&pkt, &arg_opaque)) {
rc = -1;
goto err;
}
ossl_quic_lcidm_retire_odcid(lcidm, (void *)(uintptr_t)arg_opaque);
break;
case CMD_GENERATE_INITIAL:
if (!PACKET_get_net_8(&pkt, &arg_opaque)) {
rc = -1;
goto err;
}
ossl_quic_lcidm_generate_initial(lcidm, (void *)(uintptr_t)arg_opaque,
&cid_out);
break;
case CMD_GENERATE:
if (!PACKET_get_net_8(&pkt, &arg_opaque)) {
rc = -1;
goto err;
}
ossl_quic_lcidm_generate(lcidm, (void *)(uintptr_t)arg_opaque,
&ncid_frame);
break;
case CMD_RETIRE:
if (!PACKET_get_net_8(&pkt, &arg_opaque)
|| !PACKET_get_net_8(&pkt, &arg_retire_prior_to)) {
rc = -1;
goto err;
}
ossl_quic_lcidm_retire(lcidm, (void *)(uintptr_t)arg_opaque,
arg_retire_prior_to,
NULL, &cid_out,
&seq_num_out, &did_retire);
break;
case CMD_CULL:
if (!PACKET_get_net_8(&pkt, &arg_opaque)) {
rc = -1;
goto err;
}
ossl_quic_lcidm_cull(lcidm, (void *)(uintptr_t)arg_opaque);
break;
case CMD_LOOKUP:
if (!get_cid(&pkt, &arg_cid)) {
rc = -1;
goto err;
}
ossl_quic_lcidm_lookup(lcidm, &arg_cid, &seq_num_out, &opaque_out);
break;
default:
rc = -1;
goto err;
}
}
err:
ossl_quic_lcidm_free(lcidm);
return rc;
}
void FuzzerCleanup(void)
{
FuzzerClearRand();
}
|
./openssl/fuzz/test-corpus.c | /*
* Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/*
* Given a list of files, run each of them through the fuzzer. Note that
* failure will be indicated by some kind of crash. Switching on things like
* asan improves the test.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <openssl/crypto.h>
#include "fuzzer.h"
#include "internal/o_dir.h"
#if defined(_WIN32) && defined(_MAX_PATH) && !defined(PATH_MAX)
# define PATH_MAX _MAX_PATH
#endif
#ifndef PATH_MAX
# define PATH_MAX 4096
#endif
# if !defined(S_ISREG)
# define S_ISREG(m) ((m) & S_IFREG)
# endif
static void testfile(const char *pathname)
{
struct stat st;
FILE *f;
unsigned char *buf;
size_t s;
if (stat(pathname, &st) < 0 || !S_ISREG(st.st_mode))
return;
printf("# %s\n", pathname);
fflush(stdout);
f = fopen(pathname, "rb");
if (f == NULL)
return;
buf = malloc(st.st_size);
if (buf != NULL) {
s = fread(buf, 1, st.st_size, f);
OPENSSL_assert(s == (size_t)st.st_size);
FuzzerTestOneInput(buf, s);
free(buf);
}
fclose(f);
}
int main(int argc, char **argv) {
int n;
FuzzerInitialize(&argc, &argv);
for (n = 1; n < argc; ++n) {
size_t dirname_len = strlen(argv[n]);
const char *filename = NULL;
char *pathname = NULL;
OPENSSL_DIR_CTX *ctx = NULL;
int wasdir = 0;
/*
* We start with trying to read the given path as a directory.
*/
while ((filename = OPENSSL_DIR_read(&ctx, argv[n])) != NULL) {
wasdir = 1;
if (pathname == NULL) {
pathname = malloc(PATH_MAX);
if (pathname == NULL)
break;
strcpy(pathname, argv[n]);
#ifdef __VMS
if (strchr(":<]", pathname[dirname_len - 1]) == NULL)
#endif
pathname[dirname_len++] = '/';
pathname[dirname_len] = '\0';
}
strcpy(pathname + dirname_len, filename);
testfile(pathname);
}
OPENSSL_DIR_end(&ctx);
/* If it wasn't a directory, treat it as a file instead */
if (!wasdir)
testfile(argv[n]);
free(pathname);
}
FuzzerCleanup();
return 0;
}
|
./openssl/fuzz/fuzz_rand.c | /*
* Copyright 2016-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <openssl/core_names.h>
#include <openssl/rand.h>
#include <openssl/provider.h>
#include "fuzzer.h"
static OSSL_FUNC_rand_newctx_fn fuzz_rand_newctx;
static OSSL_FUNC_rand_freectx_fn fuzz_rand_freectx;
static OSSL_FUNC_rand_instantiate_fn fuzz_rand_instantiate;
static OSSL_FUNC_rand_uninstantiate_fn fuzz_rand_uninstantiate;
static OSSL_FUNC_rand_generate_fn fuzz_rand_generate;
static OSSL_FUNC_rand_gettable_ctx_params_fn fuzz_rand_gettable_ctx_params;
static OSSL_FUNC_rand_get_ctx_params_fn fuzz_rand_get_ctx_params;
static OSSL_FUNC_rand_enable_locking_fn fuzz_rand_enable_locking;
static void *fuzz_rand_newctx(
void *provctx, void *parent, const OSSL_DISPATCH *parent_dispatch)
{
int *st = OPENSSL_malloc(sizeof(*st));
if (st != NULL)
*st = EVP_RAND_STATE_UNINITIALISED;
return st;
}
static void fuzz_rand_freectx(ossl_unused void *vrng)
{
OPENSSL_free(vrng);
}
static int fuzz_rand_instantiate(ossl_unused void *vrng,
ossl_unused unsigned int strength,
ossl_unused int prediction_resistance,
ossl_unused const unsigned char *pstr,
ossl_unused size_t pstr_len,
ossl_unused const OSSL_PARAM params[])
{
*(int *)vrng = EVP_RAND_STATE_READY;
return 1;
}
static int fuzz_rand_uninstantiate(ossl_unused void *vrng)
{
*(int *)vrng = EVP_RAND_STATE_UNINITIALISED;
return 1;
}
static int fuzz_rand_generate(ossl_unused void *vdrbg,
unsigned char *out, size_t outlen,
ossl_unused unsigned int strength,
ossl_unused int prediction_resistance,
ossl_unused const unsigned char *adin,
ossl_unused size_t adinlen)
{
unsigned char val = 1;
size_t i;
for (i = 0; i < outlen; i++)
out[i] = val++;
return 1;
}
static int fuzz_rand_enable_locking(ossl_unused void *vrng)
{
return 1;
}
static int fuzz_rand_get_ctx_params(void *vrng, OSSL_PARAM params[])
{
OSSL_PARAM *p;
p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_STATE);
if (p != NULL && !OSSL_PARAM_set_int(p, *(int *)vrng))
return 0;
p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_STRENGTH);
if (p != NULL && !OSSL_PARAM_set_int(p, 500))
return 0;
p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_MAX_REQUEST);
if (p != NULL && !OSSL_PARAM_set_size_t(p, INT_MAX))
return 0;
return 1;
}
static const OSSL_PARAM *fuzz_rand_gettable_ctx_params(ossl_unused void *vrng,
ossl_unused void *provctx)
{
static const OSSL_PARAM known_gettable_ctx_params[] = {
OSSL_PARAM_int(OSSL_RAND_PARAM_STATE, NULL),
OSSL_PARAM_uint(OSSL_RAND_PARAM_STRENGTH, NULL),
OSSL_PARAM_size_t(OSSL_RAND_PARAM_MAX_REQUEST, NULL),
OSSL_PARAM_END
};
return known_gettable_ctx_params;
}
static const OSSL_DISPATCH fuzz_rand_functions[] = {
{ OSSL_FUNC_RAND_NEWCTX, (void (*)(void))fuzz_rand_newctx },
{ OSSL_FUNC_RAND_FREECTX, (void (*)(void))fuzz_rand_freectx },
{ OSSL_FUNC_RAND_INSTANTIATE, (void (*)(void))fuzz_rand_instantiate },
{ OSSL_FUNC_RAND_UNINSTANTIATE, (void (*)(void))fuzz_rand_uninstantiate },
{ OSSL_FUNC_RAND_GENERATE, (void (*)(void))fuzz_rand_generate },
{ OSSL_FUNC_RAND_ENABLE_LOCKING, (void (*)(void))fuzz_rand_enable_locking },
{ OSSL_FUNC_RAND_GETTABLE_CTX_PARAMS,
(void(*)(void))fuzz_rand_gettable_ctx_params },
{ OSSL_FUNC_RAND_GET_CTX_PARAMS, (void(*)(void))fuzz_rand_get_ctx_params },
OSSL_DISPATCH_END
};
static const OSSL_ALGORITHM fuzz_rand_rand[] = {
{ "fuzz", "provider=fuzz-rand", fuzz_rand_functions },
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM *fuzz_rand_query(void *provctx,
int operation_id,
int *no_cache)
{
*no_cache = 0;
switch (operation_id) {
case OSSL_OP_RAND:
return fuzz_rand_rand;
}
return NULL;
}
/* Functions we provide to the core */
static const OSSL_DISPATCH fuzz_rand_method[] = {
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))OSSL_LIB_CTX_free },
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fuzz_rand_query },
OSSL_DISPATCH_END
};
static int fuzz_rand_provider_init(const OSSL_CORE_HANDLE *handle,
const OSSL_DISPATCH *in,
const OSSL_DISPATCH **out, void **provctx)
{
*provctx = OSSL_LIB_CTX_new();
if (*provctx == NULL)
return 0;
*out = fuzz_rand_method;
return 1;
}
static OSSL_PROVIDER *r_prov;
void FuzzerSetRand(void)
{
if (!OSSL_PROVIDER_add_builtin(NULL, "fuzz-rand", fuzz_rand_provider_init)
|| !RAND_set_DRBG_type(NULL, "fuzz", NULL, NULL, NULL)
|| (r_prov = OSSL_PROVIDER_try_load(NULL, "fuzz-rand", 1)) == NULL)
exit(1);
}
void FuzzerClearRand(void)
{
OSSL_PROVIDER_unload(r_prov);
}
|
./openssl/fuzz/quic-srtm.c | /*
* Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include "fuzzer.h"
#include "internal/quic_srtm.h"
int FuzzerInitialize(int *argc, char ***argv)
{
FuzzerSetRand();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL);
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
ERR_clear_error();
return 1;
}
/*
* Fuzzer input "protocol":
* Big endian
* Zero or more of:
* ADD - u8(0x00) u64(opaque) u64(seq_num) u128(token)
* REMOVE - u8(0x01) u64(opaque) u64(seq_num)
* CULL - u8(0x02) u64(opaque)
* LOOKUP - u8(0x03) u128(token) u64(idx)
*/
enum {
CMD_ADD,
CMD_REMOVE,
CMD_CULL,
CMD_LOOKUP
};
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
int rc = 0;
QUIC_SRTM *srtm = NULL;
PACKET pkt;
unsigned int cmd;
uint64_t arg_opaque, arg_seq_num, arg_idx;
QUIC_STATELESS_RESET_TOKEN arg_token;
if ((srtm = ossl_quic_srtm_new(NULL, NULL)) == NULL) {
rc = -1;
goto err;
}
if (!PACKET_buf_init(&pkt, buf, len))
goto err;
while (PACKET_remaining(&pkt) > 0) {
if (!PACKET_get_1(&pkt, &cmd))
goto err;
switch (cmd) {
case CMD_ADD:
if (!PACKET_get_net_8(&pkt, &arg_opaque)
|| !PACKET_get_net_8(&pkt, &arg_seq_num)
|| !PACKET_copy_bytes(&pkt, arg_token.token,
sizeof(arg_token.token)))
continue; /* just stop */
ossl_quic_srtm_add(srtm, (void *)(uintptr_t)arg_opaque,
arg_seq_num, &arg_token);
ossl_quic_srtm_check(srtm);
break;
case CMD_REMOVE:
if (!PACKET_get_net_8(&pkt, &arg_opaque)
|| !PACKET_get_net_8(&pkt, &arg_seq_num))
continue; /* just stop */
ossl_quic_srtm_remove(srtm, (void *)(uintptr_t)arg_opaque,
arg_seq_num);
ossl_quic_srtm_check(srtm);
break;
case CMD_CULL:
if (!PACKET_get_net_8(&pkt, &arg_opaque))
continue; /* just stop */
ossl_quic_srtm_cull(srtm, (void *)(uintptr_t)arg_opaque);
ossl_quic_srtm_check(srtm);
break;
case CMD_LOOKUP:
if (!PACKET_copy_bytes(&pkt, arg_token.token,
sizeof(arg_token.token))
|| !PACKET_get_net_8(&pkt, &arg_idx))
continue; /* just stop */
ossl_quic_srtm_lookup(srtm, &arg_token, (size_t)arg_idx,
NULL, NULL);
ossl_quic_srtm_check(srtm);
break;
default:
/* Other bytes are treated as no-ops */
continue;
}
}
err:
ossl_quic_srtm_free(srtm);
return rc;
}
void FuzzerCleanup(void)
{
FuzzerClearRand();
}
|
./openssl/fuzz/server.c | /*
* Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/* Shamelessly copied from BoringSSL and converted to C. */
/* Test first part of SSL server handshake. */
/* We need to use some deprecated APIs */
#define OPENSSL_SUPPRESS_DEPRECATED
#include <time.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/rsa.h>
#include <openssl/dsa.h>
#include <openssl/ec.h>
#include <openssl/dh.h>
#include <openssl/err.h>
#include "fuzzer.h"
static const uint8_t kCertificateDER[] = {
0x30, 0x82, 0x02, 0xff, 0x30, 0x82, 0x01, 0xe7, 0xa0, 0x03, 0x02, 0x01,
0x02, 0x02, 0x11, 0x00, 0xb1, 0x84, 0xee, 0x34, 0x99, 0x98, 0x76, 0xfb,
0x6f, 0xb2, 0x15, 0xc8, 0x47, 0x79, 0x05, 0x9b, 0x30, 0x0d, 0x06, 0x09,
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07,
0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x30, 0x1e, 0x17, 0x0d, 0x31,
0x35, 0x31, 0x31, 0x30, 0x37, 0x30, 0x30, 0x32, 0x34, 0x35, 0x36, 0x5a,
0x17, 0x0d, 0x31, 0x36, 0x31, 0x31, 0x30, 0x36, 0x30, 0x30, 0x32, 0x34,
0x35, 0x36, 0x5a, 0x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
0x04, 0x0a, 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x30,
0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30,
0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xce, 0x47, 0xcb, 0x11,
0xbb, 0xd2, 0x9d, 0x8e, 0x9e, 0xd2, 0x1e, 0x14, 0xaf, 0xc7, 0xea, 0xb6,
0xc9, 0x38, 0x2a, 0x6f, 0xb3, 0x7e, 0xfb, 0xbc, 0xfc, 0x59, 0x42, 0xb9,
0x56, 0xf0, 0x4c, 0x3f, 0xf7, 0x31, 0x84, 0xbe, 0xac, 0x03, 0x9e, 0x71,
0x91, 0x85, 0xd8, 0x32, 0xbd, 0x00, 0xea, 0xac, 0x65, 0xf6, 0x03, 0xc8,
0x0f, 0x8b, 0xfd, 0x6e, 0x58, 0x88, 0x04, 0x41, 0x92, 0x74, 0xa6, 0x57,
0x2e, 0x8e, 0x88, 0xd5, 0x3d, 0xda, 0x14, 0x3e, 0x63, 0x88, 0x22, 0xe3,
0x53, 0xe9, 0xba, 0x39, 0x09, 0xac, 0xfb, 0xd0, 0x4c, 0xf2, 0x3c, 0x20,
0xd6, 0x97, 0xe6, 0xed, 0xf1, 0x62, 0x1e, 0xe5, 0xc9, 0x48, 0xa0, 0xca,
0x2e, 0x3c, 0x14, 0x5a, 0x82, 0xd4, 0xed, 0xb1, 0xe3, 0x43, 0xc1, 0x2a,
0x59, 0xa5, 0xb9, 0xc8, 0x48, 0xa7, 0x39, 0x23, 0x74, 0xa7, 0x37, 0xb0,
0x6f, 0xc3, 0x64, 0x99, 0x6c, 0xa2, 0x82, 0xc8, 0xf6, 0xdb, 0x86, 0x40,
0xce, 0xd1, 0x85, 0x9f, 0xce, 0x69, 0xf4, 0x15, 0x2a, 0x23, 0xca, 0xea,
0xb7, 0x7b, 0xdf, 0xfb, 0x43, 0x5f, 0xff, 0x7a, 0x49, 0x49, 0x0e, 0xe7,
0x02, 0x51, 0x45, 0x13, 0xe8, 0x90, 0x64, 0x21, 0x0c, 0x26, 0x2b, 0x5d,
0xfc, 0xe4, 0xb5, 0x86, 0x89, 0x43, 0x22, 0x4c, 0xf3, 0x3b, 0xf3, 0x09,
0xc4, 0xa4, 0x10, 0x80, 0xf2, 0x46, 0xe2, 0x46, 0x8f, 0x76, 0x50, 0xbf,
0xaf, 0x2b, 0x90, 0x1b, 0x78, 0xc7, 0xcf, 0xc1, 0x77, 0xd0, 0xfb, 0xa9,
0xfb, 0xc9, 0x66, 0x5a, 0xc5, 0x9b, 0x31, 0x41, 0x67, 0x01, 0xbe, 0x33,
0x10, 0xba, 0x05, 0x58, 0xed, 0x76, 0x53, 0xde, 0x5d, 0xc1, 0xe8, 0xbb,
0x9f, 0xf1, 0xcd, 0xfb, 0xdf, 0x64, 0x7f, 0xd7, 0x18, 0xab, 0x0f, 0x94,
0x28, 0x95, 0x4a, 0xcc, 0x6a, 0xa9, 0x50, 0xc7, 0x05, 0x47, 0x10, 0x41,
0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0e, 0x06,
0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x05,
0xa0, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a,
0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x30, 0x0c,
0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00,
0x30, 0x19, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x12, 0x30, 0x10, 0x82,
0x0e, 0x66, 0x75, 0x7a, 0x7a, 0x2e, 0x62, 0x6f, 0x72, 0x69, 0x6e, 0x67,
0x73, 0x73, 0x6c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x92,
0xde, 0xef, 0x96, 0x06, 0x7b, 0xff, 0x71, 0x7d, 0x4e, 0xa0, 0x7d, 0xae,
0xb8, 0x22, 0xb4, 0x2c, 0xf7, 0x96, 0x9c, 0x37, 0x1d, 0x8f, 0xe7, 0xd9,
0x47, 0xff, 0x3f, 0xe9, 0x35, 0x95, 0x0e, 0xdd, 0xdc, 0x7f, 0xc8, 0x8a,
0x1e, 0x36, 0x1d, 0x38, 0x47, 0xfc, 0x76, 0xd2, 0x1f, 0x98, 0xa1, 0x36,
0xac, 0xc8, 0x70, 0x38, 0x0a, 0x3d, 0x51, 0x8d, 0x0f, 0x03, 0x1b, 0xef,
0x62, 0xa1, 0xcb, 0x2b, 0x4a, 0x8c, 0x12, 0x2b, 0x54, 0x50, 0x9a, 0x6b,
0xfe, 0xaf, 0xd9, 0xf6, 0xbf, 0x58, 0x11, 0x58, 0x5e, 0xe5, 0x86, 0x1e,
0x3b, 0x6b, 0x30, 0x7e, 0x72, 0x89, 0xe8, 0x6b, 0x7b, 0xb7, 0xaf, 0xef,
0x8b, 0xa9, 0x3e, 0xb0, 0xcd, 0x0b, 0xef, 0xb0, 0x0c, 0x96, 0x2b, 0xc5,
0x3b, 0xd5, 0xf1, 0xc2, 0xae, 0x3a, 0x60, 0xd9, 0x0f, 0x75, 0x37, 0x55,
0x4d, 0x62, 0xd2, 0xed, 0x96, 0xac, 0x30, 0x6b, 0xda, 0xa1, 0x48, 0x17,
0x96, 0x23, 0x85, 0x9a, 0x57, 0x77, 0xe9, 0x22, 0xa2, 0x37, 0x03, 0xba,
0x49, 0x77, 0x40, 0x3b, 0x76, 0x4b, 0xda, 0xc1, 0x04, 0x57, 0x55, 0x34,
0x22, 0x83, 0x45, 0x29, 0xab, 0x2e, 0x11, 0xff, 0x0d, 0xab, 0x55, 0xb1,
0xa7, 0x58, 0x59, 0x05, 0x25, 0xf9, 0x1e, 0x3d, 0xb7, 0xac, 0x04, 0x39,
0x2c, 0xf9, 0xaf, 0xb8, 0x68, 0xfb, 0x8e, 0x35, 0x71, 0x32, 0xff, 0x70,
0xe9, 0x46, 0x6d, 0x5c, 0x06, 0x90, 0x88, 0x23, 0x48, 0x0c, 0x50, 0xeb,
0x0a, 0xa9, 0xae, 0xe8, 0xfc, 0xbe, 0xa5, 0x76, 0x94, 0xd7, 0x64, 0x22,
0x38, 0x98, 0x17, 0xa4, 0x3a, 0xa7, 0x59, 0x9f, 0x1d, 0x3b, 0x75, 0x90,
0x1a, 0x81, 0xef, 0x19, 0xfb, 0x2b, 0xb7, 0xa7, 0x64, 0x61, 0x22, 0xa4,
0x6f, 0x7b, 0xfa, 0x58, 0xbb, 0x8c, 0x4e, 0x77, 0x67, 0xd0, 0x5d, 0x58,
0x76, 0x8a, 0xbb,
};
#ifndef OPENSSL_NO_DEPRECATED_3_0
static const uint8_t kRSAPrivateKeyDER[] = {
0x30, 0x82, 0x04, 0xa5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00,
0xce, 0x47, 0xcb, 0x11, 0xbb, 0xd2, 0x9d, 0x8e, 0x9e, 0xd2, 0x1e, 0x14,
0xaf, 0xc7, 0xea, 0xb6, 0xc9, 0x38, 0x2a, 0x6f, 0xb3, 0x7e, 0xfb, 0xbc,
0xfc, 0x59, 0x42, 0xb9, 0x56, 0xf0, 0x4c, 0x3f, 0xf7, 0x31, 0x84, 0xbe,
0xac, 0x03, 0x9e, 0x71, 0x91, 0x85, 0xd8, 0x32, 0xbd, 0x00, 0xea, 0xac,
0x65, 0xf6, 0x03, 0xc8, 0x0f, 0x8b, 0xfd, 0x6e, 0x58, 0x88, 0x04, 0x41,
0x92, 0x74, 0xa6, 0x57, 0x2e, 0x8e, 0x88, 0xd5, 0x3d, 0xda, 0x14, 0x3e,
0x63, 0x88, 0x22, 0xe3, 0x53, 0xe9, 0xba, 0x39, 0x09, 0xac, 0xfb, 0xd0,
0x4c, 0xf2, 0x3c, 0x20, 0xd6, 0x97, 0xe6, 0xed, 0xf1, 0x62, 0x1e, 0xe5,
0xc9, 0x48, 0xa0, 0xca, 0x2e, 0x3c, 0x14, 0x5a, 0x82, 0xd4, 0xed, 0xb1,
0xe3, 0x43, 0xc1, 0x2a, 0x59, 0xa5, 0xb9, 0xc8, 0x48, 0xa7, 0x39, 0x23,
0x74, 0xa7, 0x37, 0xb0, 0x6f, 0xc3, 0x64, 0x99, 0x6c, 0xa2, 0x82, 0xc8,
0xf6, 0xdb, 0x86, 0x40, 0xce, 0xd1, 0x85, 0x9f, 0xce, 0x69, 0xf4, 0x15,
0x2a, 0x23, 0xca, 0xea, 0xb7, 0x7b, 0xdf, 0xfb, 0x43, 0x5f, 0xff, 0x7a,
0x49, 0x49, 0x0e, 0xe7, 0x02, 0x51, 0x45, 0x13, 0xe8, 0x90, 0x64, 0x21,
0x0c, 0x26, 0x2b, 0x5d, 0xfc, 0xe4, 0xb5, 0x86, 0x89, 0x43, 0x22, 0x4c,
0xf3, 0x3b, 0xf3, 0x09, 0xc4, 0xa4, 0x10, 0x80, 0xf2, 0x46, 0xe2, 0x46,
0x8f, 0x76, 0x50, 0xbf, 0xaf, 0x2b, 0x90, 0x1b, 0x78, 0xc7, 0xcf, 0xc1,
0x77, 0xd0, 0xfb, 0xa9, 0xfb, 0xc9, 0x66, 0x5a, 0xc5, 0x9b, 0x31, 0x41,
0x67, 0x01, 0xbe, 0x33, 0x10, 0xba, 0x05, 0x58, 0xed, 0x76, 0x53, 0xde,
0x5d, 0xc1, 0xe8, 0xbb, 0x9f, 0xf1, 0xcd, 0xfb, 0xdf, 0x64, 0x7f, 0xd7,
0x18, 0xab, 0x0f, 0x94, 0x28, 0x95, 0x4a, 0xcc, 0x6a, 0xa9, 0x50, 0xc7,
0x05, 0x47, 0x10, 0x41, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01,
0x01, 0x00, 0xa8, 0x47, 0xb9, 0x4a, 0x06, 0x47, 0x93, 0x71, 0x3d, 0xef,
0x7b, 0xca, 0xb4, 0x7c, 0x0a, 0xe6, 0x82, 0xd0, 0xe7, 0x0d, 0xa9, 0x08,
0xf6, 0xa4, 0xfd, 0xd8, 0x73, 0xae, 0x6f, 0x56, 0x29, 0x5e, 0x25, 0x72,
0xa8, 0x30, 0x44, 0x73, 0xcf, 0x56, 0x26, 0xb9, 0x61, 0xde, 0x42, 0x81,
0xf4, 0xf0, 0x1f, 0x5d, 0xcb, 0x47, 0xf2, 0x26, 0xe9, 0xe0, 0x93, 0x28,
0xa3, 0x10, 0x3b, 0x42, 0x1e, 0x51, 0x11, 0x12, 0x06, 0x5e, 0xaf, 0xce,
0xb0, 0xa5, 0x14, 0xdd, 0x82, 0x58, 0xa1, 0xa4, 0x12, 0xdf, 0x65, 0x1d,
0x51, 0x70, 0x64, 0xd5, 0x58, 0x68, 0x11, 0xa8, 0x6a, 0x23, 0xc2, 0xbf,
0xa1, 0x25, 0x24, 0x47, 0xb3, 0xa4, 0x3c, 0x83, 0x96, 0xb7, 0x1f, 0xf4,
0x44, 0xd4, 0xd1, 0xe9, 0xfc, 0x33, 0x68, 0x5e, 0xe2, 0x68, 0x99, 0x9c,
0x91, 0xe8, 0x72, 0xc9, 0xd7, 0x8c, 0x80, 0x20, 0x8e, 0x77, 0x83, 0x4d,
0xe4, 0xab, 0xf9, 0x74, 0xa1, 0xdf, 0xd3, 0xc0, 0x0d, 0x5b, 0x05, 0x51,
0xc2, 0x6f, 0xb2, 0x91, 0x02, 0xec, 0xc0, 0x02, 0x1a, 0x5c, 0x91, 0x05,
0xf1, 0xe3, 0xfa, 0x65, 0xc2, 0xad, 0x24, 0xe6, 0xe5, 0x3c, 0xb6, 0x16,
0xf1, 0xa1, 0x67, 0x1a, 0x9d, 0x37, 0x56, 0xbf, 0x01, 0xd7, 0x3b, 0x35,
0x30, 0x57, 0x73, 0xf4, 0xf0, 0x5e, 0xa7, 0xe8, 0x0a, 0xc1, 0x94, 0x17,
0xcf, 0x0a, 0xbd, 0xf5, 0x31, 0xa7, 0x2d, 0xf7, 0xf5, 0xd9, 0x8c, 0xc2,
0x01, 0xbd, 0xda, 0x16, 0x8e, 0xb9, 0x30, 0x40, 0xa6, 0x6e, 0xbd, 0xcd,
0x4d, 0x84, 0x67, 0x4e, 0x0b, 0xce, 0xd5, 0xef, 0xf8, 0x08, 0x63, 0x02,
0xc6, 0xc7, 0xf7, 0x67, 0x92, 0xe2, 0x23, 0x9d, 0x27, 0x22, 0x1d, 0xc6,
0x67, 0x5e, 0x66, 0xbf, 0x03, 0xb8, 0xa9, 0x67, 0xd4, 0x39, 0xd8, 0x75,
0xfa, 0xe8, 0xed, 0x56, 0xb8, 0x81, 0x02, 0x81, 0x81, 0x00, 0xf7, 0x46,
0x68, 0xc6, 0x13, 0xf8, 0xba, 0x0f, 0x83, 0xdb, 0x05, 0xa8, 0x25, 0x00,
0x70, 0x9c, 0x9e, 0x8b, 0x12, 0x34, 0x0d, 0x96, 0xcf, 0x0d, 0x98, 0x9b,
0x8d, 0x9c, 0x96, 0x78, 0xd1, 0x3c, 0x01, 0x8c, 0xb9, 0x35, 0x5c, 0x20,
0x42, 0xb4, 0x38, 0xe3, 0xd6, 0x54, 0xe7, 0x55, 0xd6, 0x26, 0x8a, 0x0c,
0xf6, 0x1f, 0xe0, 0x04, 0xc1, 0x22, 0x42, 0x19, 0x61, 0xc4, 0x94, 0x7c,
0x07, 0x2e, 0x80, 0x52, 0xfe, 0x8d, 0xe6, 0x92, 0x3a, 0x91, 0xfe, 0x72,
0x99, 0xe1, 0x2a, 0x73, 0x76, 0xb1, 0x24, 0x20, 0x67, 0xde, 0x28, 0xcb,
0x0e, 0xe6, 0x52, 0xb5, 0xfa, 0xfb, 0x8b, 0x1e, 0x6a, 0x1d, 0x09, 0x26,
0xb9, 0xa7, 0x61, 0xba, 0xf8, 0x79, 0xd2, 0x66, 0x57, 0x28, 0xd7, 0x31,
0xb5, 0x0b, 0x27, 0x19, 0x1e, 0x6f, 0x46, 0xfc, 0x54, 0x95, 0xeb, 0x78,
0x01, 0xb6, 0xd9, 0x79, 0x5a, 0x4d, 0x02, 0x81, 0x81, 0x00, 0xd5, 0x8f,
0x16, 0x53, 0x2f, 0x57, 0x93, 0xbf, 0x09, 0x75, 0xbf, 0x63, 0x40, 0x3d,
0x27, 0xfd, 0x23, 0x21, 0xde, 0x9b, 0xe9, 0x73, 0x3f, 0x49, 0x02, 0xd2,
0x38, 0x96, 0xcf, 0xc3, 0xba, 0x92, 0x07, 0x87, 0x52, 0xa9, 0x35, 0xe3,
0x0c, 0xe4, 0x2f, 0x05, 0x7b, 0x37, 0xa5, 0x40, 0x9c, 0x3b, 0x94, 0xf7,
0xad, 0xa0, 0xee, 0x3a, 0xa8, 0xfb, 0x1f, 0x11, 0x1f, 0xd8, 0x9a, 0x80,
0x42, 0x3d, 0x7f, 0xa4, 0xb8, 0x9a, 0xaa, 0xea, 0x72, 0xc1, 0xe3, 0xed,
0x06, 0x60, 0x92, 0x37, 0xf9, 0xba, 0xfb, 0x9e, 0xed, 0x05, 0xa6, 0xd4,
0x72, 0x68, 0x4f, 0x63, 0xfe, 0xd6, 0x10, 0x0d, 0x4f, 0x0a, 0x93, 0xc6,
0xb9, 0xd7, 0xaf, 0xfd, 0xd9, 0x57, 0x7d, 0xcb, 0x75, 0xe8, 0x93, 0x2b,
0xae, 0x4f, 0xea, 0xd7, 0x30, 0x0b, 0x58, 0x44, 0x82, 0x0f, 0x84, 0x5d,
0x62, 0x11, 0x78, 0xea, 0x5f, 0xc5, 0x02, 0x81, 0x81, 0x00, 0x82, 0x0c,
0xc1, 0xe6, 0x0b, 0x72, 0xf1, 0x48, 0x5f, 0xac, 0xbd, 0x98, 0xe5, 0x7d,
0x09, 0xbd, 0x15, 0x95, 0x47, 0x09, 0xa1, 0x6c, 0x03, 0x91, 0xbf, 0x05,
0x70, 0xc1, 0x3e, 0x52, 0x64, 0x99, 0x0e, 0xa7, 0x98, 0x70, 0xfb, 0xf6,
0xeb, 0x9e, 0x25, 0x9d, 0x8e, 0x88, 0x30, 0xf2, 0xf0, 0x22, 0x6c, 0xd0,
0xcc, 0x51, 0x8f, 0x5c, 0x70, 0xc7, 0x37, 0xc4, 0x69, 0xab, 0x1d, 0xfc,
0xed, 0x3a, 0x03, 0xbb, 0xa2, 0xad, 0xb6, 0xea, 0x89, 0x6b, 0x67, 0x4b,
0x96, 0xaa, 0xd9, 0xcc, 0xc8, 0x4b, 0xfa, 0x18, 0x21, 0x08, 0xb2, 0xa3,
0xb9, 0x3e, 0x61, 0x99, 0xdc, 0x5a, 0x97, 0x9c, 0x73, 0x6a, 0xb9, 0xf9,
0x68, 0x03, 0x24, 0x5f, 0x55, 0x77, 0x9c, 0xb4, 0xbe, 0x7a, 0x78, 0x53,
0x68, 0x48, 0x69, 0x53, 0xc8, 0xb1, 0xf5, 0xbf, 0x98, 0x2d, 0x11, 0x1e,
0x98, 0xa8, 0x36, 0x50, 0xa0, 0xb1, 0x02, 0x81, 0x81, 0x00, 0x90, 0x88,
0x30, 0x71, 0xc7, 0xfe, 0x9b, 0x6d, 0x95, 0x37, 0x6d, 0x79, 0xfc, 0x85,
0xe7, 0x44, 0x78, 0xbc, 0x79, 0x6e, 0x47, 0x86, 0xc9, 0xf3, 0xdd, 0xc6,
0xec, 0xa9, 0x94, 0x9f, 0x40, 0xeb, 0x87, 0xd0, 0xdb, 0xee, 0xcd, 0x1b,
0x87, 0x23, 0xff, 0x76, 0xd4, 0x37, 0x8a, 0xcd, 0xb9, 0x6e, 0xd1, 0x98,
0xf6, 0x97, 0x8d, 0xe3, 0x81, 0x6d, 0xc3, 0x4e, 0xd1, 0xa0, 0xc4, 0x9f,
0xbd, 0x34, 0xe5, 0xe8, 0x53, 0x4f, 0xca, 0x10, 0xb5, 0xed, 0xe7, 0x16,
0x09, 0x54, 0xde, 0x60, 0xa7, 0xd1, 0x16, 0x6e, 0x2e, 0xb7, 0xbe, 0x7a,
0xd5, 0x9b, 0x26, 0xef, 0xe4, 0x0e, 0x77, 0xfa, 0xa9, 0xdd, 0xdc, 0xb9,
0x88, 0x19, 0x23, 0x70, 0xc7, 0xe1, 0x60, 0xaf, 0x8c, 0x73, 0x04, 0xf7,
0x71, 0x17, 0x81, 0x36, 0x75, 0xbb, 0x97, 0xd7, 0x75, 0xb6, 0x8e, 0xbc,
0xac, 0x9c, 0x6a, 0x9b, 0x24, 0x89, 0x02, 0x81, 0x80, 0x5a, 0x2b, 0xc7,
0x6b, 0x8c, 0x65, 0xdb, 0x04, 0x73, 0xab, 0x25, 0xe1, 0x5b, 0xbc, 0x3c,
0xcf, 0x5a, 0x3c, 0x04, 0xae, 0x97, 0x2e, 0xfd, 0xa4, 0x97, 0x1f, 0x05,
0x17, 0x27, 0xac, 0x7c, 0x30, 0x85, 0xb4, 0x82, 0x3f, 0x5b, 0xb7, 0x94,
0x3b, 0x7f, 0x6c, 0x0c, 0xc7, 0x16, 0xc6, 0xa0, 0xbd, 0x80, 0xb0, 0x81,
0xde, 0xa0, 0x23, 0xa6, 0xf6, 0x75, 0x33, 0x51, 0x35, 0xa2, 0x75, 0x55,
0x70, 0x4d, 0x42, 0xbb, 0xcf, 0x54, 0xe4, 0xdb, 0x2d, 0x88, 0xa0, 0x7a,
0xf2, 0x17, 0xa7, 0xdd, 0x13, 0x44, 0x9f, 0x5f, 0x6b, 0x2c, 0x42, 0x42,
0x8b, 0x13, 0x4d, 0xf9, 0x5b, 0xf8, 0x33, 0x42, 0xd9, 0x9e, 0x50, 0x1c,
0x7c, 0xbc, 0xfa, 0x62, 0x85, 0x0b, 0xcf, 0x99, 0xda, 0x9e, 0x04, 0x90,
0xb2, 0xc6, 0xb2, 0x0a, 0x2a, 0x7c, 0x6d, 0x6a, 0x40, 0xfc, 0xf5, 0x50,
0x98, 0x46, 0x89, 0x82, 0x40,
};
#endif
#ifndef OPENSSL_NO_EC
# ifndef OPENSSL_NO_DEPRECATED_3_0
/*
* -----BEGIN EC PRIVATE KEY-----
* MHcCAQEEIJLyl7hJjpQL/RhP1x2zS79xdiPJQB683gWeqcqHPeZkoAoGCCqGSM49
* AwEHoUQDQgAEdsjygVYjjaKBF4CNECVllNf017p5/MxNSWDoTHy9I2GeDwEDDazI
* D/xy8JiYjtPKVE/Zqwbmivp2UwtH28a7NQ==
* -----END EC PRIVATE KEY-----
*/
static const char ECDSAPrivateKeyPEM[] = {
0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x45,
0x43, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45,
0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x48, 0x63, 0x43, 0x41,
0x51, 0x45, 0x45, 0x49, 0x4a, 0x4c, 0x79, 0x6c, 0x37, 0x68, 0x4a, 0x6a,
0x70, 0x51, 0x4c, 0x2f, 0x52, 0x68, 0x50, 0x31, 0x78, 0x32, 0x7a, 0x53,
0x37, 0x39, 0x78, 0x64, 0x69, 0x50, 0x4a, 0x51, 0x42, 0x36, 0x38, 0x33,
0x67, 0x57, 0x65, 0x71, 0x63, 0x71, 0x48, 0x50, 0x65, 0x5a, 0x6b, 0x6f,
0x41, 0x6f, 0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x0a,
0x41, 0x77, 0x45, 0x48, 0x6f, 0x55, 0x51, 0x44, 0x51, 0x67, 0x41, 0x45,
0x64, 0x73, 0x6a, 0x79, 0x67, 0x56, 0x59, 0x6a, 0x6a, 0x61, 0x4b, 0x42,
0x46, 0x34, 0x43, 0x4e, 0x45, 0x43, 0x56, 0x6c, 0x6c, 0x4e, 0x66, 0x30,
0x31, 0x37, 0x70, 0x35, 0x2f, 0x4d, 0x78, 0x4e, 0x53, 0x57, 0x44, 0x6f,
0x54, 0x48, 0x79, 0x39, 0x49, 0x32, 0x47, 0x65, 0x44, 0x77, 0x45, 0x44,
0x44, 0x61, 0x7a, 0x49, 0x0a, 0x44, 0x2f, 0x78, 0x79, 0x38, 0x4a, 0x69,
0x59, 0x6a, 0x74, 0x50, 0x4b, 0x56, 0x45, 0x2f, 0x5a, 0x71, 0x77, 0x62,
0x6d, 0x69, 0x76, 0x70, 0x32, 0x55, 0x77, 0x74, 0x48, 0x32, 0x38, 0x61,
0x37, 0x4e, 0x51, 0x3d, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45,
0x4e, 0x44, 0x20, 0x45, 0x43, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54,
0x45, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a
};
# endif
/*
* -----BEGIN CERTIFICATE-----
* MIIBXzCCAQagAwIBAgIJAK6/Yvf/ain6MAoGCCqGSM49BAMCMBIxEDAOBgNVBAoM
* B0FjbWUgQ28wHhcNMTYxMjI1MTEzOTI3WhcNMjYxMjI1MTEzOTI3WjASMRAwDgYD
* VQQKDAdBY21lIENvMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEdsjygVYjjaKB
* F4CNECVllNf017p5/MxNSWDoTHy9I2GeDwEDDazID/xy8JiYjtPKVE/Zqwbmivp2
* UwtH28a7NaNFMEMwCQYDVR0TBAIwADALBgNVHQ8EBAMCBaAwEwYDVR0lBAwwCgYI
* KwYBBQUHAwEwFAYDVR0RBA0wC4IJbG9jYWxob3N0MAoGCCqGSM49BAMCA0cAMEQC
* IEzr3t/jejVE9oSnBp8c3P2p+lDLVRrB8zxLyjZvirUXAiAyQPaE9MNcL8/nRpuu
* 99I1enCSmWIAJ57IwuJ/n1d45Q==
* -----END CERTIFICATE-----
*/
static const char ECDSACertPEM[] = {
0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43,
0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d,
0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x42, 0x58, 0x7a, 0x43, 0x43,
0x41, 0x51, 0x61, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x4a,
0x41, 0x4b, 0x36, 0x2f, 0x59, 0x76, 0x66, 0x2f, 0x61, 0x69, 0x6e, 0x36,
0x4d, 0x41, 0x6f, 0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39,
0x42, 0x41, 0x4d, 0x43, 0x4d, 0x42, 0x49, 0x78, 0x45, 0x44, 0x41, 0x4f,
0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x6f, 0x4d, 0x0a, 0x42, 0x30, 0x46,
0x6a, 0x62, 0x57, 0x55, 0x67, 0x51, 0x32, 0x38, 0x77, 0x48, 0x68, 0x63,
0x4e, 0x4d, 0x54, 0x59, 0x78, 0x4d, 0x6a, 0x49, 0x31, 0x4d, 0x54, 0x45,
0x7a, 0x4f, 0x54, 0x49, 0x33, 0x57, 0x68, 0x63, 0x4e, 0x4d, 0x6a, 0x59,
0x78, 0x4d, 0x6a, 0x49, 0x31, 0x4d, 0x54, 0x45, 0x7a, 0x4f, 0x54, 0x49,
0x33, 0x57, 0x6a, 0x41, 0x53, 0x4d, 0x52, 0x41, 0x77, 0x44, 0x67, 0x59,
0x44, 0x0a, 0x56, 0x51, 0x51, 0x4b, 0x44, 0x41, 0x64, 0x42, 0x59, 0x32,
0x31, 0x6c, 0x49, 0x45, 0x4e, 0x76, 0x4d, 0x46, 0x6b, 0x77, 0x45, 0x77,
0x59, 0x48, 0x4b, 0x6f, 0x5a, 0x49, 0x7a, 0x6a, 0x30, 0x43, 0x41, 0x51,
0x59, 0x49, 0x4b, 0x6f, 0x5a, 0x49, 0x7a, 0x6a, 0x30, 0x44, 0x41, 0x51,
0x63, 0x44, 0x51, 0x67, 0x41, 0x45, 0x64, 0x73, 0x6a, 0x79, 0x67, 0x56,
0x59, 0x6a, 0x6a, 0x61, 0x4b, 0x42, 0x0a, 0x46, 0x34, 0x43, 0x4e, 0x45,
0x43, 0x56, 0x6c, 0x6c, 0x4e, 0x66, 0x30, 0x31, 0x37, 0x70, 0x35, 0x2f,
0x4d, 0x78, 0x4e, 0x53, 0x57, 0x44, 0x6f, 0x54, 0x48, 0x79, 0x39, 0x49,
0x32, 0x47, 0x65, 0x44, 0x77, 0x45, 0x44, 0x44, 0x61, 0x7a, 0x49, 0x44,
0x2f, 0x78, 0x79, 0x38, 0x4a, 0x69, 0x59, 0x6a, 0x74, 0x50, 0x4b, 0x56,
0x45, 0x2f, 0x5a, 0x71, 0x77, 0x62, 0x6d, 0x69, 0x76, 0x70, 0x32, 0x0a,
0x55, 0x77, 0x74, 0x48, 0x32, 0x38, 0x61, 0x37, 0x4e, 0x61, 0x4e, 0x46,
0x4d, 0x45, 0x4d, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56, 0x52, 0x30, 0x54,
0x42, 0x41, 0x49, 0x77, 0x41, 0x44, 0x41, 0x4c, 0x42, 0x67, 0x4e, 0x56,
0x48, 0x51, 0x38, 0x45, 0x42, 0x41, 0x4d, 0x43, 0x42, 0x61, 0x41, 0x77,
0x45, 0x77, 0x59, 0x44, 0x56, 0x52, 0x30, 0x6c, 0x42, 0x41, 0x77, 0x77,
0x43, 0x67, 0x59, 0x49, 0x0a, 0x4b, 0x77, 0x59, 0x42, 0x42, 0x51, 0x55,
0x48, 0x41, 0x77, 0x45, 0x77, 0x46, 0x41, 0x59, 0x44, 0x56, 0x52, 0x30,
0x52, 0x42, 0x41, 0x30, 0x77, 0x43, 0x34, 0x49, 0x4a, 0x62, 0x47, 0x39,
0x6a, 0x59, 0x57, 0x78, 0x6f, 0x62, 0x33, 0x4e, 0x30, 0x4d, 0x41, 0x6f,
0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x42, 0x41, 0x4d,
0x43, 0x41, 0x30, 0x63, 0x41, 0x4d, 0x45, 0x51, 0x43, 0x0a, 0x49, 0x45,
0x7a, 0x72, 0x33, 0x74, 0x2f, 0x6a, 0x65, 0x6a, 0x56, 0x45, 0x39, 0x6f,
0x53, 0x6e, 0x42, 0x70, 0x38, 0x63, 0x33, 0x50, 0x32, 0x70, 0x2b, 0x6c,
0x44, 0x4c, 0x56, 0x52, 0x72, 0x42, 0x38, 0x7a, 0x78, 0x4c, 0x79, 0x6a,
0x5a, 0x76, 0x69, 0x72, 0x55, 0x58, 0x41, 0x69, 0x41, 0x79, 0x51, 0x50,
0x61, 0x45, 0x39, 0x4d, 0x4e, 0x63, 0x4c, 0x38, 0x2f, 0x6e, 0x52, 0x70,
0x75, 0x75, 0x0a, 0x39, 0x39, 0x49, 0x31, 0x65, 0x6e, 0x43, 0x53, 0x6d,
0x57, 0x49, 0x41, 0x4a, 0x35, 0x37, 0x49, 0x77, 0x75, 0x4a, 0x2f, 0x6e,
0x31, 0x64, 0x34, 0x35, 0x51, 0x3d, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d,
0x2d, 0x45, 0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49,
0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a
};
#endif
#if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
/*
* -----BEGIN DSA PRIVATE KEY-----
* MIIBuwIBAAKBgQDdkFKzNABLOha7Eqj7004+p5fhtR6bxpujToMmSZTYi8igVVXP
* Wzf03ULKS5UKjA6WpR6EiZAhm+PdxusZ5xfAuRZLdKy0bgxn1f348Rwh+EQNaEM8
* 0TGcnw5ijwKmSw5yyHPDWdiHzoqEBlhAf8Nl22YTXax/clsc/pu/RRLAdwIVAIEg
* QqWRf/1EIZZcgM65Qpd65YuxAoGBAKBauV/RuloFHoSy5iWXESDywiS380tN5974
* GukGwoYdZo5uSIH6ahpeNSef0MbHGAzr7ZVEnhCQfRAwH1gRvSHoq/Rbmcvtd3r+
* QtQHOwvQHgLAynhI4i73c794czHaR+439bmcaSwDnQduRM85Mho/jiiZzAVPxBmG
* POIMWNXXAoGAI6Ep5IE7yn3JzkXO9B6tC3bbDM+ZzuuInwZLbtZ8lim7Dsqabg4k
* 2YbE4R95Bnfwnjsyl80mq/DbQN5lAHBvjDrkC6ItojBGKI3+iIrqGUEJdxvl4ulj
* F0PmSD7zvIG8BfocKOel+EHH0YryExiW6krV1KW2ZRmJrqSFw6KCjV0CFFQFbPfU
* xy5PmKytJmXR8BmppkIO
* -----END DSA PRIVATE KEY-----
*/
static const char DSAPrivateKeyPEM[] = {
0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x44,
0x53, 0x41, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b,
0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x42,
0x75, 0x77, 0x49, 0x42, 0x41, 0x41, 0x4b, 0x42, 0x67, 0x51, 0x44, 0x64,
0x6b, 0x46, 0x4b, 0x7a, 0x4e, 0x41, 0x42, 0x4c, 0x4f, 0x68, 0x61, 0x37,
0x45, 0x71, 0x6a, 0x37, 0x30, 0x30, 0x34, 0x2b, 0x70, 0x35, 0x66, 0x68,
0x74, 0x52, 0x36, 0x62, 0x78, 0x70, 0x75, 0x6a, 0x54, 0x6f, 0x4d, 0x6d,
0x53, 0x5a, 0x54, 0x59, 0x69, 0x38, 0x69, 0x67, 0x56, 0x56, 0x58, 0x50,
0x0a, 0x57, 0x7a, 0x66, 0x30, 0x33, 0x55, 0x4c, 0x4b, 0x53, 0x35, 0x55,
0x4b, 0x6a, 0x41, 0x36, 0x57, 0x70, 0x52, 0x36, 0x45, 0x69, 0x5a, 0x41,
0x68, 0x6d, 0x2b, 0x50, 0x64, 0x78, 0x75, 0x73, 0x5a, 0x35, 0x78, 0x66,
0x41, 0x75, 0x52, 0x5a, 0x4c, 0x64, 0x4b, 0x79, 0x30, 0x62, 0x67, 0x78,
0x6e, 0x31, 0x66, 0x33, 0x34, 0x38, 0x52, 0x77, 0x68, 0x2b, 0x45, 0x51,
0x4e, 0x61, 0x45, 0x4d, 0x38, 0x0a, 0x30, 0x54, 0x47, 0x63, 0x6e, 0x77,
0x35, 0x69, 0x6a, 0x77, 0x4b, 0x6d, 0x53, 0x77, 0x35, 0x79, 0x79, 0x48,
0x50, 0x44, 0x57, 0x64, 0x69, 0x48, 0x7a, 0x6f, 0x71, 0x45, 0x42, 0x6c,
0x68, 0x41, 0x66, 0x38, 0x4e, 0x6c, 0x32, 0x32, 0x59, 0x54, 0x58, 0x61,
0x78, 0x2f, 0x63, 0x6c, 0x73, 0x63, 0x2f, 0x70, 0x75, 0x2f, 0x52, 0x52,
0x4c, 0x41, 0x64, 0x77, 0x49, 0x56, 0x41, 0x49, 0x45, 0x67, 0x0a, 0x51,
0x71, 0x57, 0x52, 0x66, 0x2f, 0x31, 0x45, 0x49, 0x5a, 0x5a, 0x63, 0x67,
0x4d, 0x36, 0x35, 0x51, 0x70, 0x64, 0x36, 0x35, 0x59, 0x75, 0x78, 0x41,
0x6f, 0x47, 0x42, 0x41, 0x4b, 0x42, 0x61, 0x75, 0x56, 0x2f, 0x52, 0x75,
0x6c, 0x6f, 0x46, 0x48, 0x6f, 0x53, 0x79, 0x35, 0x69, 0x57, 0x58, 0x45,
0x53, 0x44, 0x79, 0x77, 0x69, 0x53, 0x33, 0x38, 0x30, 0x74, 0x4e, 0x35,
0x39, 0x37, 0x34, 0x0a, 0x47, 0x75, 0x6b, 0x47, 0x77, 0x6f, 0x59, 0x64,
0x5a, 0x6f, 0x35, 0x75, 0x53, 0x49, 0x48, 0x36, 0x61, 0x68, 0x70, 0x65,
0x4e, 0x53, 0x65, 0x66, 0x30, 0x4d, 0x62, 0x48, 0x47, 0x41, 0x7a, 0x72,
0x37, 0x5a, 0x56, 0x45, 0x6e, 0x68, 0x43, 0x51, 0x66, 0x52, 0x41, 0x77,
0x48, 0x31, 0x67, 0x52, 0x76, 0x53, 0x48, 0x6f, 0x71, 0x2f, 0x52, 0x62,
0x6d, 0x63, 0x76, 0x74, 0x64, 0x33, 0x72, 0x2b, 0x0a, 0x51, 0x74, 0x51,
0x48, 0x4f, 0x77, 0x76, 0x51, 0x48, 0x67, 0x4c, 0x41, 0x79, 0x6e, 0x68,
0x49, 0x34, 0x69, 0x37, 0x33, 0x63, 0x37, 0x39, 0x34, 0x63, 0x7a, 0x48,
0x61, 0x52, 0x2b, 0x34, 0x33, 0x39, 0x62, 0x6d, 0x63, 0x61, 0x53, 0x77,
0x44, 0x6e, 0x51, 0x64, 0x75, 0x52, 0x4d, 0x38, 0x35, 0x4d, 0x68, 0x6f,
0x2f, 0x6a, 0x69, 0x69, 0x5a, 0x7a, 0x41, 0x56, 0x50, 0x78, 0x42, 0x6d,
0x47, 0x0a, 0x50, 0x4f, 0x49, 0x4d, 0x57, 0x4e, 0x58, 0x58, 0x41, 0x6f,
0x47, 0x41, 0x49, 0x36, 0x45, 0x70, 0x35, 0x49, 0x45, 0x37, 0x79, 0x6e,
0x33, 0x4a, 0x7a, 0x6b, 0x58, 0x4f, 0x39, 0x42, 0x36, 0x74, 0x43, 0x33,
0x62, 0x62, 0x44, 0x4d, 0x2b, 0x5a, 0x7a, 0x75, 0x75, 0x49, 0x6e, 0x77,
0x5a, 0x4c, 0x62, 0x74, 0x5a, 0x38, 0x6c, 0x69, 0x6d, 0x37, 0x44, 0x73,
0x71, 0x61, 0x62, 0x67, 0x34, 0x6b, 0x0a, 0x32, 0x59, 0x62, 0x45, 0x34,
0x52, 0x39, 0x35, 0x42, 0x6e, 0x66, 0x77, 0x6e, 0x6a, 0x73, 0x79, 0x6c,
0x38, 0x30, 0x6d, 0x71, 0x2f, 0x44, 0x62, 0x51, 0x4e, 0x35, 0x6c, 0x41,
0x48, 0x42, 0x76, 0x6a, 0x44, 0x72, 0x6b, 0x43, 0x36, 0x49, 0x74, 0x6f,
0x6a, 0x42, 0x47, 0x4b, 0x49, 0x33, 0x2b, 0x69, 0x49, 0x72, 0x71, 0x47,
0x55, 0x45, 0x4a, 0x64, 0x78, 0x76, 0x6c, 0x34, 0x75, 0x6c, 0x6a, 0x0a,
0x46, 0x30, 0x50, 0x6d, 0x53, 0x44, 0x37, 0x7a, 0x76, 0x49, 0x47, 0x38,
0x42, 0x66, 0x6f, 0x63, 0x4b, 0x4f, 0x65, 0x6c, 0x2b, 0x45, 0x48, 0x48,
0x30, 0x59, 0x72, 0x79, 0x45, 0x78, 0x69, 0x57, 0x36, 0x6b, 0x72, 0x56,
0x31, 0x4b, 0x57, 0x32, 0x5a, 0x52, 0x6d, 0x4a, 0x72, 0x71, 0x53, 0x46,
0x77, 0x36, 0x4b, 0x43, 0x6a, 0x56, 0x30, 0x43, 0x46, 0x46, 0x51, 0x46,
0x62, 0x50, 0x66, 0x55, 0x0a, 0x78, 0x79, 0x35, 0x50, 0x6d, 0x4b, 0x79,
0x74, 0x4a, 0x6d, 0x58, 0x52, 0x38, 0x42, 0x6d, 0x70, 0x70, 0x6b, 0x49,
0x4f, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x44,
0x53, 0x41, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b,
0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a
};
/*
* -----BEGIN CERTIFICATE-----
* MIICqTCCAmegAwIBAgIJAILDGUk37fWGMAsGCWCGSAFlAwQDAjASMRAwDgYDVQQK
* DAdBY21lIENvMB4XDTE2MTIyNTEzMjUzNloXDTI2MTIyNTEzMjUzNlowEjEQMA4G
* A1UECgwHQWNtZSBDbzCCAbcwggEsBgcqhkjOOAQBMIIBHwKBgQDdkFKzNABLOha7
* Eqj7004+p5fhtR6bxpujToMmSZTYi8igVVXPWzf03ULKS5UKjA6WpR6EiZAhm+Pd
* xusZ5xfAuRZLdKy0bgxn1f348Rwh+EQNaEM80TGcnw5ijwKmSw5yyHPDWdiHzoqE
* BlhAf8Nl22YTXax/clsc/pu/RRLAdwIVAIEgQqWRf/1EIZZcgM65Qpd65YuxAoGB
* AKBauV/RuloFHoSy5iWXESDywiS380tN5974GukGwoYdZo5uSIH6ahpeNSef0MbH
* GAzr7ZVEnhCQfRAwH1gRvSHoq/Rbmcvtd3r+QtQHOwvQHgLAynhI4i73c794czHa
* R+439bmcaSwDnQduRM85Mho/jiiZzAVPxBmGPOIMWNXXA4GEAAKBgCOhKeSBO8p9
* yc5FzvQerQt22wzPmc7riJ8GS27WfJYpuw7Kmm4OJNmGxOEfeQZ38J47MpfNJqvw
* 20DeZQBwb4w65AuiLaIwRiiN/oiK6hlBCXcb5eLpYxdD5kg+87yBvAX6HCjnpfhB
* x9GK8hMYlupK1dSltmUZia6khcOigo1do0UwQzAJBgNVHRMEAjAAMAsGA1UdDwQE
* AwIFoDATBgNVHSUEDDAKBggrBgEFBQcDATAUBgNVHREEDTALgglsb2NhbGhvc3Qw
* CwYJYIZIAWUDBAMCAy8AMCwCFClxInXTRWNJEWdi5ilNr/fbM1bKAhQy4B7wtmfd
* I+zV6g3w9qBkNqStpA==
* -----END CERTIFICATE-----
*/
static const char DSACertPEM[] = {
0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43,
0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d,
0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x43, 0x71, 0x54, 0x43, 0x43,
0x41, 0x6d, 0x65, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x4a,
0x41, 0x49, 0x4c, 0x44, 0x47, 0x55, 0x6b, 0x33, 0x37, 0x66, 0x57, 0x47,
0x4d, 0x41, 0x73, 0x47, 0x43, 0x57, 0x43, 0x47, 0x53, 0x41, 0x46, 0x6c,
0x41, 0x77, 0x51, 0x44, 0x41, 0x6a, 0x41, 0x53, 0x4d, 0x52, 0x41, 0x77,
0x44, 0x67, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4b, 0x0a, 0x44, 0x41, 0x64,
0x42, 0x59, 0x32, 0x31, 0x6c, 0x49, 0x45, 0x4e, 0x76, 0x4d, 0x42, 0x34,
0x58, 0x44, 0x54, 0x45, 0x32, 0x4d, 0x54, 0x49, 0x79, 0x4e, 0x54, 0x45,
0x7a, 0x4d, 0x6a, 0x55, 0x7a, 0x4e, 0x6c, 0x6f, 0x58, 0x44, 0x54, 0x49,
0x32, 0x4d, 0x54, 0x49, 0x79, 0x4e, 0x54, 0x45, 0x7a, 0x4d, 0x6a, 0x55,
0x7a, 0x4e, 0x6c, 0x6f, 0x77, 0x45, 0x6a, 0x45, 0x51, 0x4d, 0x41, 0x34,
0x47, 0x0a, 0x41, 0x31, 0x55, 0x45, 0x43, 0x67, 0x77, 0x48, 0x51, 0x57,
0x4e, 0x74, 0x5a, 0x53, 0x42, 0x44, 0x62, 0x7a, 0x43, 0x43, 0x41, 0x62,
0x63, 0x77, 0x67, 0x67, 0x45, 0x73, 0x42, 0x67, 0x63, 0x71, 0x68, 0x6b,
0x6a, 0x4f, 0x4f, 0x41, 0x51, 0x42, 0x4d, 0x49, 0x49, 0x42, 0x48, 0x77,
0x4b, 0x42, 0x67, 0x51, 0x44, 0x64, 0x6b, 0x46, 0x4b, 0x7a, 0x4e, 0x41,
0x42, 0x4c, 0x4f, 0x68, 0x61, 0x37, 0x0a, 0x45, 0x71, 0x6a, 0x37, 0x30,
0x30, 0x34, 0x2b, 0x70, 0x35, 0x66, 0x68, 0x74, 0x52, 0x36, 0x62, 0x78,
0x70, 0x75, 0x6a, 0x54, 0x6f, 0x4d, 0x6d, 0x53, 0x5a, 0x54, 0x59, 0x69,
0x38, 0x69, 0x67, 0x56, 0x56, 0x58, 0x50, 0x57, 0x7a, 0x66, 0x30, 0x33,
0x55, 0x4c, 0x4b, 0x53, 0x35, 0x55, 0x4b, 0x6a, 0x41, 0x36, 0x57, 0x70,
0x52, 0x36, 0x45, 0x69, 0x5a, 0x41, 0x68, 0x6d, 0x2b, 0x50, 0x64, 0x0a,
0x78, 0x75, 0x73, 0x5a, 0x35, 0x78, 0x66, 0x41, 0x75, 0x52, 0x5a, 0x4c,
0x64, 0x4b, 0x79, 0x30, 0x62, 0x67, 0x78, 0x6e, 0x31, 0x66, 0x33, 0x34,
0x38, 0x52, 0x77, 0x68, 0x2b, 0x45, 0x51, 0x4e, 0x61, 0x45, 0x4d, 0x38,
0x30, 0x54, 0x47, 0x63, 0x6e, 0x77, 0x35, 0x69, 0x6a, 0x77, 0x4b, 0x6d,
0x53, 0x77, 0x35, 0x79, 0x79, 0x48, 0x50, 0x44, 0x57, 0x64, 0x69, 0x48,
0x7a, 0x6f, 0x71, 0x45, 0x0a, 0x42, 0x6c, 0x68, 0x41, 0x66, 0x38, 0x4e,
0x6c, 0x32, 0x32, 0x59, 0x54, 0x58, 0x61, 0x78, 0x2f, 0x63, 0x6c, 0x73,
0x63, 0x2f, 0x70, 0x75, 0x2f, 0x52, 0x52, 0x4c, 0x41, 0x64, 0x77, 0x49,
0x56, 0x41, 0x49, 0x45, 0x67, 0x51, 0x71, 0x57, 0x52, 0x66, 0x2f, 0x31,
0x45, 0x49, 0x5a, 0x5a, 0x63, 0x67, 0x4d, 0x36, 0x35, 0x51, 0x70, 0x64,
0x36, 0x35, 0x59, 0x75, 0x78, 0x41, 0x6f, 0x47, 0x42, 0x0a, 0x41, 0x4b,
0x42, 0x61, 0x75, 0x56, 0x2f, 0x52, 0x75, 0x6c, 0x6f, 0x46, 0x48, 0x6f,
0x53, 0x79, 0x35, 0x69, 0x57, 0x58, 0x45, 0x53, 0x44, 0x79, 0x77, 0x69,
0x53, 0x33, 0x38, 0x30, 0x74, 0x4e, 0x35, 0x39, 0x37, 0x34, 0x47, 0x75,
0x6b, 0x47, 0x77, 0x6f, 0x59, 0x64, 0x5a, 0x6f, 0x35, 0x75, 0x53, 0x49,
0x48, 0x36, 0x61, 0x68, 0x70, 0x65, 0x4e, 0x53, 0x65, 0x66, 0x30, 0x4d,
0x62, 0x48, 0x0a, 0x47, 0x41, 0x7a, 0x72, 0x37, 0x5a, 0x56, 0x45, 0x6e,
0x68, 0x43, 0x51, 0x66, 0x52, 0x41, 0x77, 0x48, 0x31, 0x67, 0x52, 0x76,
0x53, 0x48, 0x6f, 0x71, 0x2f, 0x52, 0x62, 0x6d, 0x63, 0x76, 0x74, 0x64,
0x33, 0x72, 0x2b, 0x51, 0x74, 0x51, 0x48, 0x4f, 0x77, 0x76, 0x51, 0x48,
0x67, 0x4c, 0x41, 0x79, 0x6e, 0x68, 0x49, 0x34, 0x69, 0x37, 0x33, 0x63,
0x37, 0x39, 0x34, 0x63, 0x7a, 0x48, 0x61, 0x0a, 0x52, 0x2b, 0x34, 0x33,
0x39, 0x62, 0x6d, 0x63, 0x61, 0x53, 0x77, 0x44, 0x6e, 0x51, 0x64, 0x75,
0x52, 0x4d, 0x38, 0x35, 0x4d, 0x68, 0x6f, 0x2f, 0x6a, 0x69, 0x69, 0x5a,
0x7a, 0x41, 0x56, 0x50, 0x78, 0x42, 0x6d, 0x47, 0x50, 0x4f, 0x49, 0x4d,
0x57, 0x4e, 0x58, 0x58, 0x41, 0x34, 0x47, 0x45, 0x41, 0x41, 0x4b, 0x42,
0x67, 0x43, 0x4f, 0x68, 0x4b, 0x65, 0x53, 0x42, 0x4f, 0x38, 0x70, 0x39,
0x0a, 0x79, 0x63, 0x35, 0x46, 0x7a, 0x76, 0x51, 0x65, 0x72, 0x51, 0x74,
0x32, 0x32, 0x77, 0x7a, 0x50, 0x6d, 0x63, 0x37, 0x72, 0x69, 0x4a, 0x38,
0x47, 0x53, 0x32, 0x37, 0x57, 0x66, 0x4a, 0x59, 0x70, 0x75, 0x77, 0x37,
0x4b, 0x6d, 0x6d, 0x34, 0x4f, 0x4a, 0x4e, 0x6d, 0x47, 0x78, 0x4f, 0x45,
0x66, 0x65, 0x51, 0x5a, 0x33, 0x38, 0x4a, 0x34, 0x37, 0x4d, 0x70, 0x66,
0x4e, 0x4a, 0x71, 0x76, 0x77, 0x0a, 0x32, 0x30, 0x44, 0x65, 0x5a, 0x51,
0x42, 0x77, 0x62, 0x34, 0x77, 0x36, 0x35, 0x41, 0x75, 0x69, 0x4c, 0x61,
0x49, 0x77, 0x52, 0x69, 0x69, 0x4e, 0x2f, 0x6f, 0x69, 0x4b, 0x36, 0x68,
0x6c, 0x42, 0x43, 0x58, 0x63, 0x62, 0x35, 0x65, 0x4c, 0x70, 0x59, 0x78,
0x64, 0x44, 0x35, 0x6b, 0x67, 0x2b, 0x38, 0x37, 0x79, 0x42, 0x76, 0x41,
0x58, 0x36, 0x48, 0x43, 0x6a, 0x6e, 0x70, 0x66, 0x68, 0x42, 0x0a, 0x78,
0x39, 0x47, 0x4b, 0x38, 0x68, 0x4d, 0x59, 0x6c, 0x75, 0x70, 0x4b, 0x31,
0x64, 0x53, 0x6c, 0x74, 0x6d, 0x55, 0x5a, 0x69, 0x61, 0x36, 0x6b, 0x68,
0x63, 0x4f, 0x69, 0x67, 0x6f, 0x31, 0x64, 0x6f, 0x30, 0x55, 0x77, 0x51,
0x7a, 0x41, 0x4a, 0x42, 0x67, 0x4e, 0x56, 0x48, 0x52, 0x4d, 0x45, 0x41,
0x6a, 0x41, 0x41, 0x4d, 0x41, 0x73, 0x47, 0x41, 0x31, 0x55, 0x64, 0x44,
0x77, 0x51, 0x45, 0x0a, 0x41, 0x77, 0x49, 0x46, 0x6f, 0x44, 0x41, 0x54,
0x42, 0x67, 0x4e, 0x56, 0x48, 0x53, 0x55, 0x45, 0x44, 0x44, 0x41, 0x4b,
0x42, 0x67, 0x67, 0x72, 0x42, 0x67, 0x45, 0x46, 0x42, 0x51, 0x63, 0x44,
0x41, 0x54, 0x41, 0x55, 0x42, 0x67, 0x4e, 0x56, 0x48, 0x52, 0x45, 0x45,
0x44, 0x54, 0x41, 0x4c, 0x67, 0x67, 0x6c, 0x73, 0x62, 0x32, 0x4e, 0x68,
0x62, 0x47, 0x68, 0x76, 0x63, 0x33, 0x51, 0x77, 0x0a, 0x43, 0x77, 0x59,
0x4a, 0x59, 0x49, 0x5a, 0x49, 0x41, 0x57, 0x55, 0x44, 0x42, 0x41, 0x4d,
0x43, 0x41, 0x79, 0x38, 0x41, 0x4d, 0x43, 0x77, 0x43, 0x46, 0x43, 0x6c,
0x78, 0x49, 0x6e, 0x58, 0x54, 0x52, 0x57, 0x4e, 0x4a, 0x45, 0x57, 0x64,
0x69, 0x35, 0x69, 0x6c, 0x4e, 0x72, 0x2f, 0x66, 0x62, 0x4d, 0x31, 0x62,
0x4b, 0x41, 0x68, 0x51, 0x79, 0x34, 0x42, 0x37, 0x77, 0x74, 0x6d, 0x66,
0x64, 0x0a, 0x49, 0x2b, 0x7a, 0x56, 0x36, 0x67, 0x33, 0x77, 0x39, 0x71,
0x42, 0x6b, 0x4e, 0x71, 0x53, 0x74, 0x70, 0x41, 0x3d, 0x3d, 0x0a, 0x2d,
0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54,
0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d,
0x0a
};
#endif
/* unused, to avoid warning. */
static int idx;
#define FUZZTIME 1485898104
#define TIME_IMPL(t) { if (t != NULL) *t = FUZZTIME; return FUZZTIME; }
/*
* This might not work in all cases (and definitely not on Windows
* because of the way linkers are) and callees can still get the
* current time instead of the fixed time. This will just result
* in things not being fully reproducible and have a slightly
* different coverage.
*/
#if !defined(_WIN32)
time_t time(time_t *t) TIME_IMPL(t)
#endif
int FuzzerInitialize(int *argc, char ***argv)
{
STACK_OF(SSL_COMP) *comp_methods;
FuzzerSetRand();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL);
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
idx = SSL_get_ex_data_X509_STORE_CTX_idx();
comp_methods = SSL_COMP_get_compression_methods();
if (comp_methods != NULL)
sk_SSL_COMP_sort(comp_methods);
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
SSL *server;
BIO *in;
BIO *out;
#if !defined(OPENSSL_NO_EC) \
|| (!defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0))
BIO *bio_buf;
#endif
SSL_CTX *ctx;
int ret;
#ifndef OPENSSL_NO_DEPRECATED_3_0
RSA *privkey;
#endif
const uint8_t *bufp;
#if !defined(OPENSSL_NO_DEPRECATED_3_0)
EVP_PKEY *pkey;
#endif
X509 *cert;
#ifndef OPENSSL_NO_DEPRECATED_3_0
# ifndef OPENSSL_NO_EC
EC_KEY *ecdsakey = NULL;
# endif
#endif
#if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
DSA *dsakey = NULL;
#endif
uint8_t opt;
if (len < 2)
return 0;
/* This only fuzzes the initial flow from the client so far. */
ctx = SSL_CTX_new(SSLv23_method());
ret = SSL_CTX_set_min_proto_version(ctx, 0);
OPENSSL_assert(ret == 1);
ret = SSL_CTX_set_cipher_list(ctx, "ALL:eNULL:@SECLEVEL=0");
OPENSSL_assert(ret == 1);
#ifndef OPENSSL_NO_DEPRECATED_3_0
/* RSA */
bufp = kRSAPrivateKeyDER;
privkey = d2i_RSAPrivateKey(NULL, &bufp, sizeof(kRSAPrivateKeyDER));
OPENSSL_assert(privkey != NULL);
pkey = EVP_PKEY_new();
EVP_PKEY_assign_RSA(pkey, privkey);
ret = SSL_CTX_use_PrivateKey(ctx, pkey);
OPENSSL_assert(ret == 1);
EVP_PKEY_free(pkey);
#endif
bufp = kCertificateDER;
cert = d2i_X509(NULL, &bufp, sizeof(kCertificateDER));
OPENSSL_assert(cert != NULL);
ret = SSL_CTX_use_certificate(ctx, cert);
OPENSSL_assert(ret == 1);
X509_free(cert);
#ifndef OPENSSL_NO_EC
# ifndef OPENSSL_NO_DEPRECATED_3_0
/* ECDSA */
bio_buf = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(bio_buf, ECDSAPrivateKeyPEM, sizeof(ECDSAPrivateKeyPEM)) == sizeof(ECDSAPrivateKeyPEM));
ecdsakey = PEM_read_bio_ECPrivateKey(bio_buf, NULL, NULL, NULL);
ERR_print_errors_fp(stderr);
OPENSSL_assert(ecdsakey != NULL);
BIO_free(bio_buf);
pkey = EVP_PKEY_new();
EVP_PKEY_assign_EC_KEY(pkey, ecdsakey);
ret = SSL_CTX_use_PrivateKey(ctx, pkey);
OPENSSL_assert(ret == 1);
EVP_PKEY_free(pkey);
# endif
bio_buf = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(bio_buf, ECDSACertPEM, sizeof(ECDSACertPEM)) == sizeof(ECDSACertPEM));
cert = PEM_read_bio_X509(bio_buf, NULL, NULL, NULL);
OPENSSL_assert(cert != NULL);
BIO_free(bio_buf);
ret = SSL_CTX_use_certificate(ctx, cert);
OPENSSL_assert(ret == 1);
X509_free(cert);
#endif
#if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
/* DSA */
bio_buf = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(bio_buf, DSAPrivateKeyPEM, sizeof(DSAPrivateKeyPEM)) == sizeof(DSAPrivateKeyPEM));
dsakey = PEM_read_bio_DSAPrivateKey(bio_buf, NULL, NULL, NULL);
ERR_print_errors_fp(stderr);
OPENSSL_assert(dsakey != NULL);
BIO_free(bio_buf);
pkey = EVP_PKEY_new();
EVP_PKEY_assign_DSA(pkey, dsakey);
ret = SSL_CTX_use_PrivateKey(ctx, pkey);
OPENSSL_assert(ret == 1);
EVP_PKEY_free(pkey);
bio_buf = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(bio_buf, DSACertPEM, sizeof(DSACertPEM)) == sizeof(DSACertPEM));
cert = PEM_read_bio_X509(bio_buf, NULL, NULL, NULL);
OPENSSL_assert(cert != NULL);
BIO_free(bio_buf);
ret = SSL_CTX_use_certificate(ctx, cert);
OPENSSL_assert(ret == 1);
X509_free(cert);
#endif
server = SSL_new(ctx);
in = BIO_new(BIO_s_mem());
out = BIO_new(BIO_s_mem());
SSL_set_bio(server, in, out);
SSL_set_accept_state(server);
opt = (uint8_t)buf[len-1];
len--;
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
if ((opt & 0x01) != 0)
{
do {
char early_buf[16384];
size_t early_len;
ret = SSL_read_early_data(server, early_buf, sizeof(early_buf), &early_len);
if (ret != SSL_READ_EARLY_DATA_SUCCESS)
break;
} while (1);
}
if (SSL_do_handshake(server) == 1) {
/* Keep reading application data until error or EOF. */
uint8_t tmp[1024];
for (;;) {
if (SSL_read(server, tmp, sizeof(tmp)) <= 0) {
break;
}
}
}
SSL_free(server);
ERR_clear_error();
SSL_CTX_free(ctx);
return 0;
}
void FuzzerCleanup(void)
{
FuzzerClearRand();
}
|
./openssl/fuzz/smime.c | /*
* Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include "fuzzer.h"
#include <openssl/err.h>
#include <openssl/pkcs7.h>
#include <openssl/x509.h>
#include <stdio.h>
int FuzzerInitialize(int *argc, char ***argv)
{
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
BIO *b = BIO_new_mem_buf(buf, len);
PKCS7 *p7 = SMIME_read_PKCS7(b, NULL);
if (p7 != NULL) {
STACK_OF(PKCS7_SIGNER_INFO) *p7si = PKCS7_get_signer_info(p7);
int i;
for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(p7si); i++) {
STACK_OF(X509_ALGOR) *algs;
PKCS7_cert_from_signer_info(p7,
sk_PKCS7_SIGNER_INFO_value(p7si, i));
algs = PKCS7_get_smimecap(sk_PKCS7_SIGNER_INFO_value(p7si, i));
sk_X509_ALGOR_pop_free(algs, X509_ALGOR_free);
}
PKCS7_free(p7);
}
BIO_free(b);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
}
|
./openssl/fuzz/fuzzer.h | /*
* Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <stddef.h> /* for size_t */
#include <openssl/e_os2.h> /* for uint8_t */
int FuzzerTestOneInput(const uint8_t *buf, size_t len);
int FuzzerInitialize(int *argc, char ***argv);
void FuzzerCleanup(void);
void FuzzerSetRand(void);
void FuzzerClearRand(void);
|
./openssl/fuzz/bignum.c | /*
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/*
* Confirm that a^b mod c agrees when calculated cleverly vs naively, for
* random a, b and c.
*/
#include <stdio.h>
#include <openssl/bn.h>
#include <openssl/err.h>
#include "fuzzer.h"
int FuzzerInitialize(int *argc, char ***argv)
{
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_clear_error();
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
int success = 0;
size_t l1 = 0, l2 = 0, l3 = 0;
int s1 = 0, s3 = 0;
BN_CTX *ctx;
BIGNUM *b1;
BIGNUM *b2;
BIGNUM *b3;
BIGNUM *b4;
BIGNUM *b5;
b1 = BN_new();
b2 = BN_new();
b3 = BN_new();
b4 = BN_new();
b5 = BN_new();
ctx = BN_CTX_new();
/* Divide the input into three parts, using the values of the first two
* bytes to choose lengths, which generate b1, b2 and b3. Use three bits
* of the third byte to choose signs for the three numbers.
*/
if (len > 2) {
len -= 3;
l1 = (buf[0] * len) / 255;
++buf;
l2 = (buf[0] * (len - l1)) / 255;
++buf;
l3 = len - l1 - l2;
s1 = buf[0] & 1;
s3 = buf[0] & 4;
++buf;
}
OPENSSL_assert(BN_bin2bn(buf, l1, b1) == b1);
BN_set_negative(b1, s1);
OPENSSL_assert(BN_bin2bn(buf + l1, l2, b2) == b2);
OPENSSL_assert(BN_bin2bn(buf + l1 + l2, l3, b3) == b3);
BN_set_negative(b3, s3);
/* mod 0 is undefined */
if (BN_is_zero(b3)) {
success = 1;
goto done;
}
OPENSSL_assert(BN_mod_exp(b4, b1, b2, b3, ctx));
OPENSSL_assert(BN_mod_exp_simple(b5, b1, b2, b3, ctx));
success = BN_cmp(b4, b5) == 0;
if (!success) {
BN_print_fp(stdout, b1);
putchar('\n');
BN_print_fp(stdout, b2);
putchar('\n');
BN_print_fp(stdout, b3);
putchar('\n');
BN_print_fp(stdout, b4);
putchar('\n');
BN_print_fp(stdout, b5);
putchar('\n');
}
done:
OPENSSL_assert(success);
BN_free(b1);
BN_free(b2);
BN_free(b3);
BN_free(b4);
BN_free(b5);
BN_CTX_free(ctx);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
}
|
./openssl/fuzz/driver.c | /*
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <stdint.h>
#include <unistd.h>
#include <stdlib.h>
#include <openssl/opensslconf.h>
#include "fuzzer.h"
#ifndef OPENSSL_NO_FUZZ_LIBFUZZER
int LLVMFuzzerInitialize(int *argc, char ***argv);
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len);
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
return FuzzerInitialize(argc, argv);
}
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
{
return FuzzerTestOneInput(buf, len);
}
#elif !defined(OPENSSL_NO_FUZZ_AFL)
#define BUF_SIZE 65536
int main(int argc, char** argv)
{
FuzzerInitialize(&argc, &argv);
while (__AFL_LOOP(10000)) {
uint8_t *buf = malloc(BUF_SIZE);
size_t size = read(0, buf, BUF_SIZE);
FuzzerTestOneInput(buf, size);
free(buf);
}
FuzzerCleanup();
return 0;
}
#else
#error "Unsupported fuzzer"
#endif
|
./openssl/fuzz/client.c | /*
* Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <time.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/rsa.h>
#include <openssl/dsa.h>
#include <openssl/ec.h>
#include <openssl/dh.h>
#include <openssl/err.h>
#include "fuzzer.h"
/* unused, to avoid warning. */
static int idx;
#define FUZZTIME 1485898104
#define TIME_IMPL(t) { if (t != NULL) *t = FUZZTIME; return FUZZTIME; }
/*
* This might not work in all cases (and definitely not on Windows
* because of the way linkers are) and callees can still get the
* current time instead of the fixed time. This will just result
* in things not being fully reproducible and have a slightly
* different coverage.
*/
#if !defined(_WIN32)
time_t time(time_t *t) TIME_IMPL(t)
#endif
int FuzzerInitialize(int *argc, char ***argv)
{
STACK_OF(SSL_COMP) *comp_methods;
FuzzerSetRand();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL);
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
idx = SSL_get_ex_data_X509_STORE_CTX_idx();
comp_methods = SSL_COMP_get_compression_methods();
if (comp_methods != NULL)
sk_SSL_COMP_sort(comp_methods);
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
SSL *client = NULL;
BIO *in;
BIO *out;
SSL_CTX *ctx;
if (len == 0)
return 0;
/* This only fuzzes the initial flow from the client so far. */
ctx = SSL_CTX_new(SSLv23_method());
if (ctx == NULL)
goto end;
client = SSL_new(ctx);
if (client == NULL)
goto end;
OPENSSL_assert(SSL_set_min_proto_version(client, 0) == 1);
OPENSSL_assert(SSL_set_cipher_list(client, "ALL:eNULL:@SECLEVEL=0") == 1);
SSL_set_tlsext_host_name(client, "localhost");
in = BIO_new(BIO_s_mem());
if (in == NULL)
goto end;
out = BIO_new(BIO_s_mem());
if (out == NULL) {
BIO_free(in);
goto end;
}
SSL_set_bio(client, in, out);
SSL_set_connect_state(client);
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
if (SSL_do_handshake(client) == 1) {
/* Keep reading application data until error or EOF. */
uint8_t tmp[1024];
for (;;) {
if (SSL_read(client, tmp, sizeof(tmp)) <= 0) {
break;
}
}
}
end:
SSL_free(client);
ERR_clear_error();
SSL_CTX_free(ctx);
return 0;
}
void FuzzerCleanup(void)
{
FuzzerClearRand();
}
|
./openssl/fuzz/decoder.c | /*
* Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <openssl/decoder.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include "fuzzer.h"
static ASN1_PCTX *pctx;
int FuzzerInitialize(int *argc, char ***argv)
{
FuzzerSetRand();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS
| OPENSSL_INIT_ADD_ALL_CIPHERS
| OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
pctx = ASN1_PCTX_new();
ASN1_PCTX_set_flags(pctx, ASN1_PCTX_FLAGS_SHOW_ABSENT
| ASN1_PCTX_FLAGS_SHOW_SEQUENCE
| ASN1_PCTX_FLAGS_SHOW_SSOF
| ASN1_PCTX_FLAGS_SHOW_TYPE
| ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME);
ASN1_PCTX_set_str_flags(pctx, ASN1_STRFLGS_UTF8_CONVERT
| ASN1_STRFLGS_SHOW_TYPE
| ASN1_STRFLGS_DUMP_ALL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
OSSL_DECODER_CTX *dctx;
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *ctx = NULL;
BIO *bio;
bio = BIO_new(BIO_s_null());
dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, NULL, NULL, NULL, 0, NULL,
NULL);
if (dctx == NULL) {
return 0;
}
if (OSSL_DECODER_from_data(dctx, &buf, &len)) {
EVP_PKEY *pkey2;
EVP_PKEY_print_public(bio, pkey, 1, pctx);
EVP_PKEY_print_private(bio, pkey, 1, pctx);
EVP_PKEY_print_params(bio, pkey, 1, pctx);
pkey2 = EVP_PKEY_dup(pkey);
OPENSSL_assert(pkey2 != NULL);
EVP_PKEY_eq(pkey, pkey2);
EVP_PKEY_free(pkey2);
ctx = EVP_PKEY_CTX_new(pkey, NULL);
EVP_PKEY_param_check(ctx);
EVP_PKEY_public_check(ctx);
EVP_PKEY_private_check(ctx);
EVP_PKEY_pairwise_check(ctx);
OPENSSL_assert(ctx != NULL);
EVP_PKEY_CTX_free(ctx);
EVP_PKEY_free(pkey);
}
OSSL_DECODER_CTX_free(dctx);
BIO_free(bio);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
ASN1_PCTX_free(pctx);
FuzzerClearRand();
}
|
./openssl/fuzz/bndiv.c | /*
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/*
* Confirm that if (d, r) = a / b, then b * d + r == a, and that sign(d) ==
* sign(a), and 0 <= r <= b
*/
#include <stdio.h>
#include <openssl/bn.h>
#include <openssl/err.h>
#include "fuzzer.h"
/* 256 kB */
#define MAX_LEN (256 * 1000)
static BN_CTX *ctx;
static BIGNUM *b1;
static BIGNUM *b2;
static BIGNUM *b3;
static BIGNUM *b4;
static BIGNUM *b5;
int FuzzerInitialize(int *argc, char ***argv)
{
b1 = BN_new();
b2 = BN_new();
b3 = BN_new();
b4 = BN_new();
b5 = BN_new();
ctx = BN_CTX_new();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_clear_error();
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
int success = 0;
size_t l1 = 0, l2 = 0;
/* s1 and s2 will be the signs for b1 and b2. */
int s1 = 0, s2 = 0;
/* limit the size of the input to avoid timeout */
if (len > MAX_LEN)
len = MAX_LEN;
/* We are going to split the buffer in two, sizes l1 and l2, giving b1 and
* b2.
*/
if (len > 0) {
--len;
/* Use first byte to divide the remaining buffer into 3Fths. I admit
* this disallows some number sizes. If it matters, better ideas are
* welcome (Ben).
*/
l1 = ((buf[0] & 0x3f) * len) / 0x3f;
s1 = buf[0] & 0x40;
s2 = buf[0] & 0x80;
++buf;
l2 = len - l1;
}
OPENSSL_assert(BN_bin2bn(buf, l1, b1) == b1);
BN_set_negative(b1, s1);
OPENSSL_assert(BN_bin2bn(buf + l1, l2, b2) == b2);
BN_set_negative(b2, s2);
/* divide by 0 is an error */
if (BN_is_zero(b2)) {
success = 1;
goto done;
}
OPENSSL_assert(BN_div(b3, b4, b1, b2, ctx));
if (BN_is_zero(b1))
success = BN_is_zero(b3) && BN_is_zero(b4);
else if (BN_is_negative(b1))
success = (BN_is_negative(b3) != BN_is_negative(b2) || BN_is_zero(b3))
&& (BN_is_negative(b4) || BN_is_zero(b4));
else
success = (BN_is_negative(b3) == BN_is_negative(b2) || BN_is_zero(b3))
&& (!BN_is_negative(b4) || BN_is_zero(b4));
OPENSSL_assert(BN_mul(b5, b3, b2, ctx));
OPENSSL_assert(BN_add(b5, b5, b4));
success = success && BN_cmp(b5, b1) == 0;
if (!success) {
BN_print_fp(stdout, b1);
putchar('\n');
BN_print_fp(stdout, b2);
putchar('\n');
BN_print_fp(stdout, b3);
putchar('\n');
BN_print_fp(stdout, b4);
putchar('\n');
BN_print_fp(stdout, b5);
putchar('\n');
printf("%d %d %d %d %d %d %d\n", BN_is_negative(b1),
BN_is_negative(b2),
BN_is_negative(b3), BN_is_negative(b4), BN_is_zero(b4),
BN_is_negative(b3) != BN_is_negative(b2)
&& (BN_is_negative(b4) || BN_is_zero(b4)),
BN_cmp(b5, b1));
puts("----\n");
}
done:
OPENSSL_assert(success);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
BN_free(b1);
BN_free(b2);
BN_free(b3);
BN_free(b4);
BN_free(b5);
BN_CTX_free(ctx);
}
|
./openssl/fuzz/x509.c | /*
* Copyright 2016-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <openssl/x509.h>
#include <openssl/ocsp.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include "fuzzer.h"
int FuzzerInitialize(int *argc, char ***argv)
{
FuzzerSetRand();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS
| OPENSSL_INIT_ADD_ALL_CIPHERS | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
return 1;
}
static int cb(int ok, X509_STORE_CTX *ctx)
{
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
const unsigned char *p = buf;
size_t orig_len = len;
unsigned char *der = NULL;
BIO *bio = NULL;
X509 *x509_1 = NULL, *x509_2 = NULL;
X509_STORE *store = NULL;
X509_VERIFY_PARAM *param = NULL;
X509_STORE_CTX *ctx = NULL;
X509_CRL *crl = NULL;
STACK_OF(X509_CRL) *crls = NULL;
STACK_OF(X509) *certs = NULL;
OCSP_RESPONSE *resp = NULL;
OCSP_BASICRESP *bs = NULL;
OCSP_CERTID *id = NULL;
x509_1 = d2i_X509(NULL, &p, len);
if (x509_1 == NULL)
goto err;
bio = BIO_new(BIO_s_null());
if (bio == NULL)
goto err;
/* This will load and print the public key as well as extensions */
X509_print(bio, x509_1);
BIO_free(bio);
X509_issuer_and_serial_hash(x509_1);
i2d_X509(x509_1, &der);
OPENSSL_free(der);
len = orig_len - (p - buf);
x509_2 = d2i_X509(NULL, &p, len);
if (x509_2 == NULL)
goto err;
len = orig_len - (p - buf);
crl = d2i_X509_CRL(NULL, &p, len);
if (crl == NULL)
goto err;
len = orig_len - (p - buf);
resp = d2i_OCSP_RESPONSE(NULL, &p, len);
store = X509_STORE_new();
X509_STORE_add_cert(store, x509_2);
param = X509_VERIFY_PARAM_new();
X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_NO_CHECK_TIME);
X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_X509_STRICT);
X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_PARTIAL_CHAIN);
X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
X509_STORE_set1_param(store, param);
X509_STORE_set_verify_cb(store, cb);
ctx = X509_STORE_CTX_new();
if (ctx == NULL)
goto err;
X509_STORE_CTX_init(ctx, store, x509_1, NULL);
if (crl != NULL) {
crls = sk_X509_CRL_new_null();
if (crls == NULL)
goto err;
sk_X509_CRL_push(crls, crl);
X509_STORE_CTX_set0_crls(ctx, crls);
}
X509_verify_cert(ctx);
if (resp != NULL)
bs = OCSP_response_get1_basic(resp);
if (bs != NULL) {
int status, reason;
ASN1_GENERALIZEDTIME *revtime, *thisupd, *nextupd;
certs = sk_X509_new_null();
if (certs == NULL)
goto err;
sk_X509_push(certs, x509_1);
sk_X509_push(certs, x509_2);
OCSP_basic_verify(bs, certs, store, OCSP_PARTIAL_CHAIN);
id = OCSP_cert_to_id(NULL, x509_1, x509_2);
if (id == NULL)
goto err;
OCSP_resp_find_status(bs, id, &status, &reason, &revtime, &thisupd,
&nextupd);
}
err:
X509_STORE_CTX_free(ctx);
X509_VERIFY_PARAM_free(param);
X509_STORE_free(store);
X509_free(x509_1);
X509_free(x509_2);
X509_CRL_free(crl);
OCSP_CERTID_free(id);
OCSP_BASICRESP_free(bs);
OCSP_RESPONSE_free(resp);
sk_X509_CRL_free(crls);
sk_X509_free(certs);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
FuzzerClearRand();
}
|
./openssl/fuzz/pem.c | /*
* Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <openssl/pem.h>
#include <openssl/err.h>
#include "fuzzer.h"
int FuzzerInitialize(int *argc, char ***argv)
{
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
BIO *in;
char *name = NULL, *header = NULL;
unsigned char *data = NULL;
long outlen;
if (len <= 1)
return 0;
in = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(in, buf + 1, len - 1) == len - 1);
if (PEM_read_bio_ex(in, &name, &header, &data, &outlen, buf[0]) == 1) {
/* Try to read all the data we get to see if allocated properly. */
BIO_write(in, name, strlen(name));
BIO_write(in, header, strlen(header));
BIO_write(in, data, outlen);
}
if (buf[0] & PEM_FLAG_SECURE) {
OPENSSL_secure_free(name);
OPENSSL_secure_free(header);
OPENSSL_secure_free(data);
} else {
OPENSSL_free(name);
OPENSSL_free(header);
OPENSSL_free(data);
}
BIO_free(in);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
}
|
./openssl/fuzz/quic-rcidm.c | /*
* Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include "fuzzer.h"
#include "internal/quic_rcidm.h"
#include "internal/packet.h"
int FuzzerInitialize(int *argc, char ***argv)
{
FuzzerSetRand();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL);
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
ERR_clear_error();
return 1;
}
/*
* Fuzzer input "protocol":
* Big endian
* Zero or more of:
* RESET_WITH_ODCID u8(0x00) u8(cidl):cid
* RESET_WITHOUT_ODCID u8(0x01)
* (free and reallocate)
* ADD_FROM_INITIAL u8(0x02) u8(cidl):cid
* ADD_FROM_SERVER_RETRY u8(0x03) u8(cidl):cid
* ADD_FROM_NCID u8(0x04) u64(seq_num)
* u64(retire_prior_to) u8(cidl):cid
* ON_HANDSHAKE_COMPLETE u8(0x05)
* ON_PACKET_SENT u8(0x06) u64(num_pkt)
* REQUEST_ROLL u8(0x07)
* POP_RETIRE_SEQ_NUM u8(0x08)
* PEEK_RETIRE_SEQ_NUM u8(0x09)
* GET_PREFERRED_TX_DCID u8(0x0A)
* GET_PREFERRED_TX_DCID_CHANGED u8(0x0B) u8(clear)
*/
enum {
CMD_RESET_WITH_ODCID,
CMD_RESET_WITHOUT_ODCID,
CMD_ADD_FROM_INITIAL,
CMD_ADD_FROM_SERVER_RETRY,
CMD_ADD_FROM_NCID,
CMD_ON_HANDSHAKE_COMPLETE,
CMD_ON_PACKET_SENT,
CMD_REQUEST_ROLL,
CMD_POP_RETIRE_SEQ_NUM,
CMD_PEEK_RETIRE_SEQ_NUM,
CMD_GET_PREFERRED_TX_DCID,
CMD_GET_PREFERRED_TX_DCID_CHANGED
};
static int get_cid(PACKET *pkt, QUIC_CONN_ID *cid)
{
unsigned int cidl;
if (!PACKET_get_1(pkt, &cidl)
|| cidl > QUIC_MAX_CONN_ID_LEN
|| !PACKET_copy_bytes(pkt, cid->id, cidl))
return 0;
cid->id_len = (unsigned char)cidl;
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
int rc = 0;
QUIC_RCIDM *rcidm = NULL;
PACKET pkt;
uint64_t seq_num_out, arg_num_pkt;
unsigned int cmd, arg_clear;
QUIC_CONN_ID arg_cid, cid_out;
OSSL_QUIC_FRAME_NEW_CONN_ID ncid_frame;
if (!PACKET_buf_init(&pkt, buf, len))
goto err;
if ((rcidm = ossl_quic_rcidm_new(NULL)) == NULL)
goto err;
while (PACKET_remaining(&pkt) > 0) {
if (!PACKET_get_1(&pkt, &cmd))
goto err;
switch (cmd) {
case CMD_RESET_WITH_ODCID:
if (!get_cid(&pkt, &arg_cid)) {
rc = -1;
goto err;
}
ossl_quic_rcidm_free(rcidm);
if ((rcidm = ossl_quic_rcidm_new(&arg_cid)) == NULL)
goto err;
break;
case CMD_RESET_WITHOUT_ODCID:
ossl_quic_rcidm_free(rcidm);
if ((rcidm = ossl_quic_rcidm_new(NULL)) == NULL)
goto err;
break;
case CMD_ADD_FROM_INITIAL:
if (!get_cid(&pkt, &arg_cid)) {
rc = -1;
goto err;
}
ossl_quic_rcidm_add_from_initial(rcidm, &arg_cid);
break;
case CMD_ADD_FROM_SERVER_RETRY:
if (!get_cid(&pkt, &arg_cid)) {
rc = -1;
goto err;
}
ossl_quic_rcidm_add_from_server_retry(rcidm, &arg_cid);
break;
case CMD_ADD_FROM_NCID:
if (!PACKET_get_net_8(&pkt, &ncid_frame.seq_num)
|| !PACKET_get_net_8(&pkt, &ncid_frame.retire_prior_to)
|| !get_cid(&pkt, &ncid_frame.conn_id)) {
rc = -1;
goto err;
}
ossl_quic_rcidm_add_from_ncid(rcidm, &ncid_frame);
break;
case CMD_ON_HANDSHAKE_COMPLETE:
ossl_quic_rcidm_on_handshake_complete(rcidm);
break;
case CMD_ON_PACKET_SENT:
if (!PACKET_get_net_8(&pkt, &arg_num_pkt)) {
rc = -1;
goto err;
}
ossl_quic_rcidm_on_packet_sent(rcidm, arg_num_pkt);
break;
case CMD_REQUEST_ROLL:
ossl_quic_rcidm_request_roll(rcidm);
break;
case CMD_POP_RETIRE_SEQ_NUM:
ossl_quic_rcidm_pop_retire_seq_num(rcidm, &seq_num_out);
break;
case CMD_PEEK_RETIRE_SEQ_NUM:
ossl_quic_rcidm_peek_retire_seq_num(rcidm, &seq_num_out);
break;
case CMD_GET_PREFERRED_TX_DCID:
ossl_quic_rcidm_get_preferred_tx_dcid(rcidm, &cid_out);
break;
case CMD_GET_PREFERRED_TX_DCID_CHANGED:
if (!PACKET_get_1(&pkt, &arg_clear)) {
rc = -1;
goto err;
}
ossl_quic_rcidm_get_preferred_tx_dcid_changed(rcidm, arg_clear);
break;
default:
rc = -1;
goto err;
}
}
err:
ossl_quic_rcidm_free(rcidm);
return rc;
}
void FuzzerCleanup(void)
{
FuzzerClearRand();
}
|
./openssl/fuzz/conf.c | /*
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/*
* Test configuration parsing.
*/
#include <openssl/conf.h>
#include <openssl/err.h>
#include "fuzzer.h"
int FuzzerInitialize(int *argc, char ***argv)
{
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_clear_error();
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
CONF *conf;
BIO *in;
long eline;
if (len == 0)
return 0;
conf = NCONF_new(NULL);
in = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
NCONF_load_bio(conf, in, &eline);
NCONF_free(conf);
BIO_free(in);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
}
|
./openssl/fuzz/v3name.c | /*
* Copyright 2012-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <openssl/e_os2.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include "internal/nelem.h"
#include "fuzzer.h"
int FuzzerInitialize(int *argc, char ***argv)
{
return 1;
}
int FuzzerTestOneInput(const uint8_t* data, size_t size){
GENERAL_NAME *namesa;
GENERAL_NAME *namesb;
const unsigned char *derp = data;
/*
* We create two versions of each GENERAL_NAME so that we ensure when
* we compare them they are always different pointers.
*/
namesa = d2i_GENERAL_NAME(NULL, &derp, size);
derp = data;
namesb = d2i_GENERAL_NAME(NULL, &derp, size);
GENERAL_NAME_cmp(namesa, namesb);
if (namesa != NULL)
GENERAL_NAME_free(namesa);
if (namesb != NULL)
GENERAL_NAME_free(namesb);
return 0;
}
void FuzzerCleanup(void)
{
}
|
./openssl/fuzz/asn1parse.c | /*
* Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/*
* Fuzz the parser used for dumping ASN.1 using "openssl asn1parse".
*/
#include <stdio.h>
#include <openssl/asn1.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/err.h>
#include "fuzzer.h"
static BIO *bio_out;
int FuzzerInitialize(int *argc, char ***argv)
{
bio_out = BIO_new(BIO_s_null()); /* output will be ignored */
if (bio_out == NULL)
return 0;
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
(void)ASN1_parse_dump(bio_out, buf, len, 0, 0);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
BIO_free(bio_out);
}
|
./openssl/fuzz/crl.c | /*
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <openssl/x509.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include "fuzzer.h"
int FuzzerInitialize(int *argc, char ***argv)
{
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
const unsigned char *p = buf;
unsigned char *der = NULL;
X509_CRL *crl = d2i_X509_CRL(NULL, &p, len);
if (crl != NULL) {
BIO *bio = BIO_new(BIO_s_null());
X509_CRL_print(bio, crl);
BIO_free(bio);
i2d_X509_CRL(crl, &der);
OPENSSL_free(der);
X509_CRL_free(crl);
}
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
}
|
./openssl/fuzz/cms.c | /*
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/*
* Test CMS DER parsing.
*/
#include <openssl/bio.h>
#include <openssl/cms.h>
#include <openssl/err.h>
#include "fuzzer.h"
int FuzzerInitialize(int *argc, char ***argv)
{
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
CMS_ContentInfo *cms;
BIO *in;
if (len == 0)
return 0;
in = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
cms = d2i_CMS_bio(in, NULL);
if (cms != NULL) {
BIO *out = BIO_new(BIO_s_null());
i2d_CMS_bio(out, cms);
BIO_free(out);
CMS_ContentInfo_free(cms);
}
BIO_free(in);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
}
|
./openssl/fuzz/ct.c | /*
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
/*
* Fuzz the SCT parser.
*/
#include <stdio.h>
#include <openssl/ct.h>
#include <openssl/err.h>
#include "fuzzer.h"
int FuzzerInitialize(int *argc, char ***argv)
{
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
CRYPTO_free_ex_index(0, -1);
ERR_clear_error();
return 1;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
const uint8_t **pp = &buf;
unsigned char *der = NULL;
STACK_OF(SCT) *scts = d2i_SCT_LIST(NULL, pp, len);
if (scts != NULL) {
BIO *bio = BIO_new(BIO_s_null());
SCT_LIST_print(scts, bio, 4, "\n", NULL);
BIO_free(bio);
if (i2d_SCT_LIST(scts, &der)) {
/* Silence unused result warning */
}
OPENSSL_free(der);
SCT_LIST_free(scts);
}
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
}
|
./openssl/fuzz/cmp.c | /*
* Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* Test CMP DER parsing.
*/
#include <openssl/bio.h>
#include <openssl/cmp.h>
#include "../crypto/cmp/cmp_local.h"
#include <openssl/err.h>
#include "fuzzer.h"
int FuzzerInitialize(int *argc, char ***argv)
{
FuzzerSetRand();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
return 1;
}
static int num_responses;
static OSSL_CMP_MSG *transfer_cb(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req)
{
if (num_responses++ > 2)
return NULL; /* prevent loops due to repeated pollRep */
return OSSL_CMP_MSG_dup((OSSL_CMP_MSG *)
OSSL_CMP_CTX_get_transfer_cb_arg(ctx));
}
static int print_noop(const char *func, const char *file, int line,
OSSL_CMP_severity level, const char *msg)
{
return 1;
}
static int allow_unprotected(const OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *rep,
int invalid_protection, int expected_type)
{
return 1;
}
static void cmp_client_process_response(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg)
{
X509_NAME *name = X509_NAME_new();
ASN1_INTEGER *serial = ASN1_INTEGER_new();
ctx->unprotectedSend = 1; /* satisfy ossl_cmp_msg_protect() */
ctx->disableConfirm = 1; /* check just one response message */
ctx->popoMethod = OSSL_CRMF_POPO_NONE; /* satisfy ossl_cmp_certReq_new() */
ctx->oldCert = X509_new(); /* satisfy crm_new() and ossl_cmp_rr_new() */
if (!OSSL_CMP_CTX_set1_secretValue(ctx, (unsigned char *)"",
0) /* prevent too unspecific error */
|| ctx->oldCert == NULL
|| name == NULL || !X509_set_issuer_name(ctx->oldCert, name)
|| serial == NULL || !X509_set_serialNumber(ctx->oldCert, serial))
goto err;
(void)OSSL_CMP_CTX_set_transfer_cb(ctx, transfer_cb);
(void)OSSL_CMP_CTX_set_transfer_cb_arg(ctx, msg);
(void)OSSL_CMP_CTX_set_log_cb(ctx, print_noop);
num_responses = 0;
switch (msg->body != NULL ? msg->body->type : -1) {
case OSSL_CMP_PKIBODY_IP:
(void)OSSL_CMP_exec_IR_ses(ctx);
break;
case OSSL_CMP_PKIBODY_CP:
(void)OSSL_CMP_exec_CR_ses(ctx);
(void)OSSL_CMP_exec_P10CR_ses(ctx);
break;
case OSSL_CMP_PKIBODY_KUP:
(void)OSSL_CMP_exec_KUR_ses(ctx);
break;
case OSSL_CMP_PKIBODY_POLLREP:
ctx->status = OSSL_CMP_PKISTATUS_waiting;
(void)OSSL_CMP_try_certreq(ctx, OSSL_CMP_PKIBODY_CR, NULL, NULL);
break;
case OSSL_CMP_PKIBODY_RP:
(void)OSSL_CMP_exec_RR_ses(ctx);
break;
case OSSL_CMP_PKIBODY_GENP:
sk_OSSL_CMP_ITAV_pop_free(OSSL_CMP_exec_GENM_ses(ctx),
OSSL_CMP_ITAV_free);
break;
default:
(void)ossl_cmp_msg_check_update(ctx, msg, allow_unprotected, 0);
break;
}
err:
X509_NAME_free(name);
ASN1_INTEGER_free(serial);
}
static OSSL_CMP_PKISI *process_cert_request(OSSL_CMP_SRV_CTX *srv_ctx,
const OSSL_CMP_MSG *cert_req,
int certReqId,
const OSSL_CRMF_MSG *crm,
const X509_REQ *p10cr,
X509 **certOut,
STACK_OF(X509) **chainOut,
STACK_OF(X509) **caPubs)
{
ERR_raise(ERR_LIB_CMP, CMP_R_ERROR_PROCESSING_MESSAGE);
return NULL;
}
static OSSL_CMP_PKISI *process_rr(OSSL_CMP_SRV_CTX *srv_ctx,
const OSSL_CMP_MSG *rr,
const X509_NAME *issuer,
const ASN1_INTEGER *serial)
{
ERR_raise(ERR_LIB_CMP, CMP_R_ERROR_PROCESSING_MESSAGE);
return NULL;
}
static int process_genm(OSSL_CMP_SRV_CTX *srv_ctx,
const OSSL_CMP_MSG *genm,
const STACK_OF(OSSL_CMP_ITAV) *in,
STACK_OF(OSSL_CMP_ITAV) **out)
{
ERR_raise(ERR_LIB_CMP, CMP_R_ERROR_PROCESSING_MESSAGE);
return 0;
}
static void process_error(OSSL_CMP_SRV_CTX *srv_ctx, const OSSL_CMP_MSG *error,
const OSSL_CMP_PKISI *statusInfo,
const ASN1_INTEGER *errorCode,
const OSSL_CMP_PKIFREETEXT *errorDetails)
{
ERR_raise(ERR_LIB_CMP, CMP_R_ERROR_PROCESSING_MESSAGE);
}
static int process_certConf(OSSL_CMP_SRV_CTX *srv_ctx,
const OSSL_CMP_MSG *certConf, int certReqId,
const ASN1_OCTET_STRING *certHash,
const OSSL_CMP_PKISI *si)
{
ERR_raise(ERR_LIB_CMP, CMP_R_ERROR_PROCESSING_MESSAGE);
return 0;
}
static int process_pollReq(OSSL_CMP_SRV_CTX *srv_ctx,
const OSSL_CMP_MSG *pollReq, int certReqId,
OSSL_CMP_MSG **certReq, int64_t *check_after)
{
ERR_raise(ERR_LIB_CMP, CMP_R_ERROR_PROCESSING_MESSAGE);
return 0;
}
static int clean_transaction(ossl_unused OSSL_CMP_SRV_CTX *srv_ctx,
ossl_unused const ASN1_OCTET_STRING *id)
{
return 1;
}
static int delayed_delivery(ossl_unused OSSL_CMP_SRV_CTX *srv_ctx,
ossl_unused const OSSL_CMP_MSG *req)
{
return 0;
}
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
OSSL_CMP_MSG *msg;
BIO *in;
if (len == 0)
return 0;
in = BIO_new(BIO_s_mem());
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
msg = d2i_OSSL_CMP_MSG_bio(in, NULL);
if (msg != NULL) {
BIO *out = BIO_new(BIO_s_null());
OSSL_CMP_SRV_CTX *srv_ctx = OSSL_CMP_SRV_CTX_new(NULL, NULL);
OSSL_CMP_CTX *client_ctx = OSSL_CMP_CTX_new(NULL, NULL);
i2d_OSSL_CMP_MSG_bio(out, msg);
ASN1_item_print(out, (ASN1_VALUE *)msg, 4,
ASN1_ITEM_rptr(OSSL_CMP_MSG), NULL);
BIO_free(out);
if (client_ctx != NULL)
cmp_client_process_response(client_ctx, msg);
if (srv_ctx != NULL
&& OSSL_CMP_CTX_set_log_cb(OSSL_CMP_SRV_CTX_get0_cmp_ctx(srv_ctx),
print_noop)
&& OSSL_CMP_SRV_CTX_init(srv_ctx, NULL, process_cert_request,
process_rr, process_genm, process_error,
process_certConf, process_pollReq)
&& OSSL_CMP_SRV_CTX_init_trans(srv_ctx, delayed_delivery,
clean_transaction))
OSSL_CMP_MSG_free(OSSL_CMP_SRV_process_request(srv_ctx, msg));
OSSL_CMP_CTX_free(client_ctx);
OSSL_CMP_SRV_CTX_free(srv_ctx);
OSSL_CMP_MSG_free(msg);
}
BIO_free(in);
ERR_clear_error();
return 0;
}
void FuzzerCleanup(void)
{
FuzzerClearRand();
}
|
./openssl/fuzz/quic-client.c | /*
* Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.openssl.org/source/license.html
* or in the file LICENSE in the source distribution.
*/
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include "fuzzer.h"
#include "internal/sockets.h"
#include "internal/time.h"
#include "internal/quic_ssl.h"
/* unused, to avoid warning. */
static int idx;
static OSSL_TIME fake_now;
static OSSL_TIME fake_now_cb(void *arg)
{
return fake_now;
}
int FuzzerInitialize(int *argc, char ***argv)
{
STACK_OF(SSL_COMP) *comp_methods;
FuzzerSetRand();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ASYNC, NULL);
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
ERR_clear_error();
CRYPTO_free_ex_index(0, -1);
idx = SSL_get_ex_data_X509_STORE_CTX_idx();
comp_methods = SSL_COMP_get_compression_methods();
if (comp_methods != NULL)
sk_SSL_COMP_sort(comp_methods);
return 1;
}
#define HANDSHAKING 0
#define READING 1
#define WRITING 2
#define ACCEPTING_STREAM 3
#define CREATING_STREAM 4
#define SWAPPING_STREAM 5
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
{
SSL *client = NULL, *stream = NULL;
SSL *allstreams[] = {NULL, NULL, NULL, NULL};
size_t i, thisstream = 0, numstreams = 1;
BIO *in;
BIO *out;
SSL_CTX *ctx;
BIO_ADDR *peer_addr = NULL;
struct in_addr ina = {0};
struct timeval tv;
int state = HANDSHAKING;
uint8_t tmp[1024];
int writelen = 0;
if (len == 0)
return 0;
/* This only fuzzes the initial flow from the client so far. */
ctx = SSL_CTX_new(OSSL_QUIC_client_method());
if (ctx == NULL)
goto end;
client = SSL_new(ctx);
if (client == NULL)
goto end;
fake_now = ossl_ms2time(1);
if (!ossl_quic_conn_set_override_now_cb(client, fake_now_cb, NULL))
goto end;
peer_addr = BIO_ADDR_new();
if (peer_addr == NULL)
goto end;
ina.s_addr = htonl(0x7f000001UL);
if (!BIO_ADDR_rawmake(peer_addr, AF_INET, &ina, sizeof(ina), htons(4433)))
goto end;
SSL_set_tlsext_host_name(client, "localhost");
in = BIO_new(BIO_s_dgram_mem());
if (in == NULL)
goto end;
out = BIO_new(BIO_s_dgram_mem());
if (out == NULL) {
BIO_free(in);
goto end;
}
if (!BIO_dgram_set_caps(out, BIO_DGRAM_CAP_HANDLES_DST_ADDR)) {
BIO_free(in);
BIO_free(out);
goto end;
}
SSL_set_bio(client, in, out);
if (SSL_set_alpn_protos(client, (const unsigned char *)"\x08ossltest", 9) != 0)
goto end;
if (SSL_set1_initial_peer_addr(client, peer_addr) != 1)
goto end;
SSL_set_connect_state(client);
if (!SSL_set_incoming_stream_policy(client,
SSL_INCOMING_STREAM_POLICY_ACCEPT,
0))
goto end;
allstreams[0] = stream = client;
for (;;) {
size_t size;
uint64_t nxtpktms = 0;
OSSL_TIME nxtpkt = ossl_time_zero(), nxttimeout;
int isinf, ret = 0;
if (len >= 2) {
if (len >= 5 && buf[0] == 0xff && buf[1] == 0xff) {
switch (buf[2]) {
case 0x00:
if (state == READING)
state = ACCEPTING_STREAM;
break;
case 0x01:
if (state == READING)
state = CREATING_STREAM;
break;
case 0x02:
if (state == READING)
state = SWAPPING_STREAM;
break;
default:
/*ignore*/
break;
}
len -= 3;
buf += 3;
}
nxtpktms = buf[0] + (buf[1] << 8);
nxtpkt = ossl_time_add(fake_now, ossl_ms2time(nxtpktms));
len -= 2;
buf += 2;
}
for (;;) {
switch (state) {
case HANDSHAKING:
ret = SSL_do_handshake(stream);
if (ret == 1)
state = READING;
break;
case READING:
ret = SSL_read(stream, tmp, sizeof(tmp));
if (ret > 0) {
state = WRITING;
writelen = ret;
assert(writelen <= (int)sizeof(tmp));
}
break;
case WRITING:
ret = SSL_write(stream, tmp, writelen);
if (ret > 0)
state = READING;
break;
case ACCEPTING_STREAM:
state = READING;
ret = 1;
if (numstreams == OSSL_NELEM(allstreams)
|| SSL_get_accept_stream_queue_len(client) == 0)
break;
thisstream = numstreams;
stream = allstreams[numstreams++]
= SSL_accept_stream(client, 0);
if (stream == NULL)
goto end;
break;
case CREATING_STREAM:
state = READING;
ret = 1;
if (numstreams == OSSL_NELEM(allstreams))
break;
stream = SSL_new_stream(client, 0);
if (stream == NULL) {
/* Ignore, and go back to the previous stream */
stream = allstreams[thisstream];
break;
}
thisstream = numstreams;
allstreams[numstreams++] = stream;
break;
case SWAPPING_STREAM:
state = READING;
ret = 1;
if (numstreams == 1)
break;
if (++thisstream == numstreams)
thisstream = 0;
stream = allstreams[thisstream];
break;
}
assert(stream != NULL);
assert(thisstream < numstreams);
if (ret <= 0) {
switch (SSL_get_error(stream, ret)) {
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
break;
default:
goto end;
}
}
if (!SSL_get_event_timeout(client, &tv, &isinf))
goto end;
if (isinf) {
fake_now = nxtpkt;
break;
} else {
nxttimeout = ossl_time_add(fake_now,
ossl_time_from_timeval(tv));
if (len > 3 && ossl_time_compare(nxttimeout, nxtpkt) >= 0) {
fake_now = nxtpkt;
break;
}
fake_now = nxttimeout;
}
}
if (len <= 3)
break;
size = buf[0] + (buf[1] << 8);
if (size > len - 2)
break;
if (size > 0)
BIO_write(in, buf+2, size);
len -= size + 2;
buf += size + 2;
}
end:
for (i = 0; i < numstreams; i++)
SSL_free(allstreams[i]);
ERR_clear_error();
SSL_CTX_free(ctx);
BIO_ADDR_free(peer_addr);
return 0;
}
void FuzzerCleanup(void)
{
FuzzerClearRand();
}
|
./openssl/providers/nullprov.c | /*
* Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <stdio.h>
#include <openssl/core.h>
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include <openssl/params.h>
#include "prov/implementations.h"
#include "prov/providercommon.h"
OSSL_provider_init_fn ossl_null_provider_init;
/* Parameters we provide to the core */
static const OSSL_PARAM null_param_types[] = {
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
OSSL_PARAM_END
};
static const OSSL_PARAM *null_gettable_params(const OSSL_PROVIDER *prov)
{
return null_param_types;
}
static int null_get_params(const OSSL_PROVIDER *provctx, OSSL_PARAM params[])
{
OSSL_PARAM *p;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Null Provider"))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
return 0;
return 1;
}
static const OSSL_ALGORITHM *null_query(OSSL_PROVIDER *prov,
int operation_id,
int *no_cache)
{
*no_cache = 0;
return NULL;
}
/* Functions we provide to the core */
static const OSSL_DISPATCH null_dispatch_table[] = {
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))null_gettable_params },
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))null_get_params },
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))null_query },
OSSL_DISPATCH_END
};
int ossl_null_provider_init(const OSSL_CORE_HANDLE *handle,
const OSSL_DISPATCH *in,
const OSSL_DISPATCH **out,
void **provctx)
{
*out = null_dispatch_table;
/* Could be anything - we don't use it */
*provctx = (void *)handle;
return 1;
}
|
./openssl/providers/legacyprov.c | /*
* Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <stdio.h>
#include <openssl/core.h>
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include <openssl/err.h>
#include <openssl/params.h>
#include "prov/provider_ctx.h"
#include "prov/implementations.h"
#include "prov/names.h"
#include "prov/providercommon.h"
/*
* Forward declarations to ensure that interface functions are correctly
* defined.
*/
static OSSL_FUNC_provider_gettable_params_fn legacy_gettable_params;
static OSSL_FUNC_provider_get_params_fn legacy_get_params;
static OSSL_FUNC_provider_query_operation_fn legacy_query;
#define ALG(NAMES, FUNC) { NAMES, "provider=legacy", FUNC }
#ifdef STATIC_LEGACY
OSSL_provider_init_fn ossl_legacy_provider_init;
# define OSSL_provider_init ossl_legacy_provider_init
#endif
#ifndef STATIC_LEGACY
/*
* Should these function pointers be stored in the provider side provctx?
* Could they ever be different from one init to the next? We assume not for
* now.
*/
/* Functions provided by the core */
static OSSL_FUNC_core_new_error_fn *c_new_error;
static OSSL_FUNC_core_set_error_debug_fn *c_set_error_debug;
static OSSL_FUNC_core_vset_error_fn *c_vset_error;
static OSSL_FUNC_core_set_error_mark_fn *c_set_error_mark;
static OSSL_FUNC_core_clear_last_error_mark_fn *c_clear_last_error_mark;
static OSSL_FUNC_core_pop_error_to_mark_fn *c_pop_error_to_mark;
#endif
/* Parameters we provide to the core */
static const OSSL_PARAM legacy_param_types[] = {
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
OSSL_PARAM_END
};
static const OSSL_PARAM *legacy_gettable_params(void *provctx)
{
return legacy_param_types;
}
static int legacy_get_params(void *provctx, OSSL_PARAM params[])
{
OSSL_PARAM *p;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Legacy Provider"))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
return 0;
return 1;
}
static const OSSL_ALGORITHM legacy_digests[] = {
#ifndef OPENSSL_NO_MD2
ALG(PROV_NAMES_MD2, ossl_md2_functions),
#endif
#ifndef OPENSSL_NO_MD4
ALG(PROV_NAMES_MD4, ossl_md4_functions),
#endif
#ifndef OPENSSL_NO_MDC2
ALG(PROV_NAMES_MDC2, ossl_mdc2_functions),
#endif /* OPENSSL_NO_MDC2 */
#ifndef OPENSSL_NO_WHIRLPOOL
ALG(PROV_NAMES_WHIRLPOOL, ossl_wp_functions),
#endif /* OPENSSL_NO_WHIRLPOOL */
#ifndef OPENSSL_NO_RMD160
ALG(PROV_NAMES_RIPEMD_160, ossl_ripemd160_functions),
#endif /* OPENSSL_NO_RMD160 */
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM legacy_ciphers[] = {
#ifndef OPENSSL_NO_CAST
ALG(PROV_NAMES_CAST5_ECB, ossl_cast5128ecb_functions),
ALG(PROV_NAMES_CAST5_CBC, ossl_cast5128cbc_functions),
ALG(PROV_NAMES_CAST5_OFB, ossl_cast5128ofb64_functions),
ALG(PROV_NAMES_CAST5_CFB, ossl_cast5128cfb64_functions),
#endif /* OPENSSL_NO_CAST */
#ifndef OPENSSL_NO_BF
ALG(PROV_NAMES_BF_ECB, ossl_blowfish128ecb_functions),
ALG(PROV_NAMES_BF_CBC, ossl_blowfish128cbc_functions),
ALG(PROV_NAMES_BF_OFB, ossl_blowfish128ofb64_functions),
ALG(PROV_NAMES_BF_CFB, ossl_blowfish128cfb64_functions),
#endif /* OPENSSL_NO_BF */
#ifndef OPENSSL_NO_IDEA
ALG(PROV_NAMES_IDEA_ECB, ossl_idea128ecb_functions),
ALG(PROV_NAMES_IDEA_CBC, ossl_idea128cbc_functions),
ALG(PROV_NAMES_IDEA_OFB, ossl_idea128ofb64_functions),
ALG(PROV_NAMES_IDEA_CFB, ossl_idea128cfb64_functions),
#endif /* OPENSSL_NO_IDEA */
#ifndef OPENSSL_NO_SEED
ALG(PROV_NAMES_SEED_ECB, ossl_seed128ecb_functions),
ALG(PROV_NAMES_SEED_CBC, ossl_seed128cbc_functions),
ALG(PROV_NAMES_SEED_OFB, ossl_seed128ofb128_functions),
ALG(PROV_NAMES_SEED_CFB, ossl_seed128cfb128_functions),
#endif /* OPENSSL_NO_SEED */
#ifndef OPENSSL_NO_RC2
ALG(PROV_NAMES_RC2_ECB, ossl_rc2128ecb_functions),
ALG(PROV_NAMES_RC2_CBC, ossl_rc2128cbc_functions),
ALG(PROV_NAMES_RC2_40_CBC, ossl_rc240cbc_functions),
ALG(PROV_NAMES_RC2_64_CBC, ossl_rc264cbc_functions),
ALG(PROV_NAMES_RC2_CFB, ossl_rc2128cfb128_functions),
ALG(PROV_NAMES_RC2_OFB, ossl_rc2128ofb128_functions),
#endif /* OPENSSL_NO_RC2 */
#ifndef OPENSSL_NO_RC4
ALG(PROV_NAMES_RC4, ossl_rc4128_functions),
ALG(PROV_NAMES_RC4_40, ossl_rc440_functions),
# ifndef OPENSSL_NO_MD5
ALG(PROV_NAMES_RC4_HMAC_MD5, ossl_rc4_hmac_ossl_md5_functions),
# endif /* OPENSSL_NO_MD5 */
#endif /* OPENSSL_NO_RC4 */
#ifndef OPENSSL_NO_RC5
ALG(PROV_NAMES_RC5_ECB, ossl_rc5128ecb_functions),
ALG(PROV_NAMES_RC5_CBC, ossl_rc5128cbc_functions),
ALG(PROV_NAMES_RC5_OFB, ossl_rc5128ofb64_functions),
ALG(PROV_NAMES_RC5_CFB, ossl_rc5128cfb64_functions),
#endif /* OPENSSL_NO_RC5 */
#ifndef OPENSSL_NO_DES
ALG(PROV_NAMES_DESX_CBC, ossl_tdes_desx_cbc_functions),
ALG(PROV_NAMES_DES_ECB, ossl_des_ecb_functions),
ALG(PROV_NAMES_DES_CBC, ossl_des_cbc_functions),
ALG(PROV_NAMES_DES_OFB, ossl_des_ofb64_functions),
ALG(PROV_NAMES_DES_CFB, ossl_des_cfb64_functions),
ALG(PROV_NAMES_DES_CFB1, ossl_des_cfb1_functions),
ALG(PROV_NAMES_DES_CFB8, ossl_des_cfb8_functions),
#endif /* OPENSSL_NO_DES */
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM legacy_kdfs[] = {
ALG(PROV_NAMES_PBKDF1, ossl_kdf_pbkdf1_functions),
ALG(PROV_NAMES_PVKKDF, ossl_kdf_pvk_functions),
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM *legacy_query(void *provctx, int operation_id,
int *no_cache)
{
*no_cache = 0;
switch (operation_id) {
case OSSL_OP_DIGEST:
return legacy_digests;
case OSSL_OP_CIPHER:
return legacy_ciphers;
case OSSL_OP_KDF:
return legacy_kdfs;
}
return NULL;
}
static void legacy_teardown(void *provctx)
{
OSSL_LIB_CTX_free(PROV_LIBCTX_OF(provctx));
ossl_prov_ctx_free(provctx);
}
/* Functions we provide to the core */
static const OSSL_DISPATCH legacy_dispatch_table[] = {
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))legacy_teardown },
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))legacy_gettable_params },
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))legacy_get_params },
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))legacy_query },
OSSL_DISPATCH_END
};
int OSSL_provider_init(const OSSL_CORE_HANDLE *handle,
const OSSL_DISPATCH *in,
const OSSL_DISPATCH **out,
void **provctx)
{
OSSL_LIB_CTX *libctx = NULL;
#ifndef STATIC_LEGACY
const OSSL_DISPATCH *tmp;
#endif
#ifndef STATIC_LEGACY
for (tmp = in; tmp->function_id != 0; tmp++) {
/*
* We do not support the scenario of an application linked against
* multiple versions of libcrypto (e.g. one static and one dynamic),
* but sharing a single legacy.so. We do a simple sanity check here.
*/
#define set_func(c, f) if (c == NULL) c = f; else if (c != f) return 0;
switch (tmp->function_id) {
case OSSL_FUNC_CORE_NEW_ERROR:
set_func(c_new_error, OSSL_FUNC_core_new_error(tmp));
break;
case OSSL_FUNC_CORE_SET_ERROR_DEBUG:
set_func(c_set_error_debug, OSSL_FUNC_core_set_error_debug(tmp));
break;
case OSSL_FUNC_CORE_VSET_ERROR:
set_func(c_vset_error, OSSL_FUNC_core_vset_error(tmp));
break;
case OSSL_FUNC_CORE_SET_ERROR_MARK:
set_func(c_set_error_mark, OSSL_FUNC_core_set_error_mark(tmp));
break;
case OSSL_FUNC_CORE_CLEAR_LAST_ERROR_MARK:
set_func(c_clear_last_error_mark,
OSSL_FUNC_core_clear_last_error_mark(tmp));
break;
case OSSL_FUNC_CORE_POP_ERROR_TO_MARK:
set_func(c_pop_error_to_mark, OSSL_FUNC_core_pop_error_to_mark(tmp));
break;
}
}
#endif
if ((*provctx = ossl_prov_ctx_new()) == NULL
|| (libctx = OSSL_LIB_CTX_new_child(handle, in)) == NULL) {
OSSL_LIB_CTX_free(libctx);
legacy_teardown(*provctx);
*provctx = NULL;
return 0;
}
ossl_prov_ctx_set0_libctx(*provctx, libctx);
ossl_prov_ctx_set0_handle(*provctx, handle);
*out = legacy_dispatch_table;
return 1;
}
#ifndef STATIC_LEGACY
/*
* Provider specific implementation of libcrypto functions in terms of
* upcalls.
*/
/*
* For ERR functions, we pass a NULL context. This is valid to do as long
* as only error codes that the calling libcrypto supports are used.
*/
void ERR_new(void)
{
c_new_error(NULL);
}
void ERR_set_debug(const char *file, int line, const char *func)
{
c_set_error_debug(NULL, file, line, func);
}
void ERR_set_error(int lib, int reason, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
c_vset_error(NULL, ERR_PACK(lib, 0, reason), fmt, args);
va_end(args);
}
void ERR_vset_error(int lib, int reason, const char *fmt, va_list args)
{
c_vset_error(NULL, ERR_PACK(lib, 0, reason), fmt, args);
}
int ERR_set_mark(void)
{
return c_set_error_mark(NULL);
}
int ERR_clear_last_mark(void)
{
return c_clear_last_error_mark(NULL);
}
int ERR_pop_to_mark(void)
{
return c_pop_error_to_mark(NULL);
}
#endif
|
./openssl/providers/defltprov.c | /*
* Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <stdio.h>
#include <openssl/opensslconf.h>
#include <openssl/core.h>
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include <openssl/params.h>
#include "prov/bio.h"
#include "prov/provider_ctx.h"
#include "prov/providercommon.h"
#include "prov/implementations.h"
#include "prov/names.h"
#include "prov/provider_util.h"
#include "prov/seeding.h"
#include "internal/nelem.h"
/*
* Forward declarations to ensure that interface functions are correctly
* defined.
*/
static OSSL_FUNC_provider_gettable_params_fn deflt_gettable_params;
static OSSL_FUNC_provider_get_params_fn deflt_get_params;
static OSSL_FUNC_provider_query_operation_fn deflt_query;
#define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK }
#define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL)
/* Functions provided by the core */
static OSSL_FUNC_core_gettable_params_fn *c_gettable_params = NULL;
static OSSL_FUNC_core_get_params_fn *c_get_params = NULL;
/* Parameters we provide to the core */
static const OSSL_PARAM deflt_param_types[] = {
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
OSSL_PARAM_END
};
static const OSSL_PARAM *deflt_gettable_params(void *provctx)
{
return deflt_param_types;
}
static int deflt_get_params(void *provctx, OSSL_PARAM params[])
{
OSSL_PARAM *p;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Default Provider"))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
return 0;
return 1;
}
/*
* For the algorithm names, we use the following formula for our primary
* names:
*
* ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
*
* VERSION is only present if there are multiple versions of
* an alg (MD2, MD4, MD5). It may be omitted if there is only
* one version (if a subsequent version is released in the future,
* we can always change the canonical name, and add the old name
* as an alias).
*
* SUBNAME may be present where we are combining multiple
* algorithms together, e.g. MD5-SHA1.
*
* SIZE is only present if multiple versions of an algorithm exist
* with different sizes (e.g. AES-128-CBC, AES-256-CBC)
*
* MODE is only present where applicable.
*
* We add diverse other names where applicable, such as the names that
* NIST uses, or that are used for ASN.1 OBJECT IDENTIFIERs, or names
* we have used historically.
*
* Algorithm names are case insensitive, but we use all caps in our "canonical"
* names for consistency.
*/
static const OSSL_ALGORITHM deflt_digests[] = {
/* Our primary name:NIST name[:our older names] */
{ PROV_NAMES_SHA1, "provider=default", ossl_sha1_functions },
{ PROV_NAMES_SHA2_224, "provider=default", ossl_sha224_functions },
{ PROV_NAMES_SHA2_256, "provider=default", ossl_sha256_functions },
{ PROV_NAMES_SHA2_256_192, "provider=default", ossl_sha256_192_functions },
{ PROV_NAMES_SHA2_384, "provider=default", ossl_sha384_functions },
{ PROV_NAMES_SHA2_512, "provider=default", ossl_sha512_functions },
{ PROV_NAMES_SHA2_512_224, "provider=default", ossl_sha512_224_functions },
{ PROV_NAMES_SHA2_512_256, "provider=default", ossl_sha512_256_functions },
/* We agree with NIST here, so one name only */
{ PROV_NAMES_SHA3_224, "provider=default", ossl_sha3_224_functions },
{ PROV_NAMES_SHA3_256, "provider=default", ossl_sha3_256_functions },
{ PROV_NAMES_SHA3_384, "provider=default", ossl_sha3_384_functions },
{ PROV_NAMES_SHA3_512, "provider=default", ossl_sha3_512_functions },
{ PROV_NAMES_KECCAK_224, "provider=default", ossl_keccak_224_functions },
{ PROV_NAMES_KECCAK_256, "provider=default", ossl_keccak_256_functions },
{ PROV_NAMES_KECCAK_384, "provider=default", ossl_keccak_384_functions },
{ PROV_NAMES_KECCAK_512, "provider=default", ossl_keccak_512_functions },
/*
* KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for
* the KMAC-128 and KMAC-256.
*/
{ PROV_NAMES_KECCAK_KMAC_128, "provider=default",
ossl_keccak_kmac_128_functions },
{ PROV_NAMES_KECCAK_KMAC_256, "provider=default",
ossl_keccak_kmac_256_functions },
/* Our primary name:NIST name */
{ PROV_NAMES_SHAKE_128, "provider=default", ossl_shake_128_functions },
{ PROV_NAMES_SHAKE_256, "provider=default", ossl_shake_256_functions },
#ifndef OPENSSL_NO_BLAKE2
/*
* https://blake2.net/ doesn't specify size variants,
* but mentions that Bouncy Castle uses the names
* BLAKE2b-160, BLAKE2b-256, BLAKE2b-384, and BLAKE2b-512
* If we assume that "2b" and "2s" are versions, that pattern
* fits with ours. We also add our historical names.
*/
{ PROV_NAMES_BLAKE2S_256, "provider=default", ossl_blake2s256_functions },
{ PROV_NAMES_BLAKE2B_512, "provider=default", ossl_blake2b512_functions },
#endif /* OPENSSL_NO_BLAKE2 */
#ifndef OPENSSL_NO_SM3
{ PROV_NAMES_SM3, "provider=default", ossl_sm3_functions },
#endif /* OPENSSL_NO_SM3 */
#ifndef OPENSSL_NO_MD5
{ PROV_NAMES_MD5, "provider=default", ossl_md5_functions },
{ PROV_NAMES_MD5_SHA1, "provider=default", ossl_md5_sha1_functions },
#endif /* OPENSSL_NO_MD5 */
#ifndef OPENSSL_NO_RMD160
{ PROV_NAMES_RIPEMD_160, "provider=default", ossl_ripemd160_functions },
#endif /* OPENSSL_NO_RMD160 */
{ PROV_NAMES_NULL, "provider=default", ossl_nullmd_functions },
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
ALG(PROV_NAMES_NULL, ossl_null_functions),
ALG(PROV_NAMES_AES_256_ECB, ossl_aes256ecb_functions),
ALG(PROV_NAMES_AES_192_ECB, ossl_aes192ecb_functions),
ALG(PROV_NAMES_AES_128_ECB, ossl_aes128ecb_functions),
ALG(PROV_NAMES_AES_256_CBC, ossl_aes256cbc_functions),
ALG(PROV_NAMES_AES_192_CBC, ossl_aes192cbc_functions),
ALG(PROV_NAMES_AES_128_CBC, ossl_aes128cbc_functions),
ALG(PROV_NAMES_AES_128_CBC_CTS, ossl_aes128cbc_cts_functions),
ALG(PROV_NAMES_AES_192_CBC_CTS, ossl_aes192cbc_cts_functions),
ALG(PROV_NAMES_AES_256_CBC_CTS, ossl_aes256cbc_cts_functions),
ALG(PROV_NAMES_AES_256_OFB, ossl_aes256ofb_functions),
ALG(PROV_NAMES_AES_192_OFB, ossl_aes192ofb_functions),
ALG(PROV_NAMES_AES_128_OFB, ossl_aes128ofb_functions),
ALG(PROV_NAMES_AES_256_CFB, ossl_aes256cfb_functions),
ALG(PROV_NAMES_AES_192_CFB, ossl_aes192cfb_functions),
ALG(PROV_NAMES_AES_128_CFB, ossl_aes128cfb_functions),
ALG(PROV_NAMES_AES_256_CFB1, ossl_aes256cfb1_functions),
ALG(PROV_NAMES_AES_192_CFB1, ossl_aes192cfb1_functions),
ALG(PROV_NAMES_AES_128_CFB1, ossl_aes128cfb1_functions),
ALG(PROV_NAMES_AES_256_CFB8, ossl_aes256cfb8_functions),
ALG(PROV_NAMES_AES_192_CFB8, ossl_aes192cfb8_functions),
ALG(PROV_NAMES_AES_128_CFB8, ossl_aes128cfb8_functions),
ALG(PROV_NAMES_AES_256_CTR, ossl_aes256ctr_functions),
ALG(PROV_NAMES_AES_192_CTR, ossl_aes192ctr_functions),
ALG(PROV_NAMES_AES_128_CTR, ossl_aes128ctr_functions),
ALG(PROV_NAMES_AES_256_XTS, ossl_aes256xts_functions),
ALG(PROV_NAMES_AES_128_XTS, ossl_aes128xts_functions),
#ifndef OPENSSL_NO_OCB
ALG(PROV_NAMES_AES_256_OCB, ossl_aes256ocb_functions),
ALG(PROV_NAMES_AES_192_OCB, ossl_aes192ocb_functions),
ALG(PROV_NAMES_AES_128_OCB, ossl_aes128ocb_functions),
#endif /* OPENSSL_NO_OCB */
#ifndef OPENSSL_NO_SIV
ALG(PROV_NAMES_AES_128_SIV, ossl_aes128siv_functions),
ALG(PROV_NAMES_AES_192_SIV, ossl_aes192siv_functions),
ALG(PROV_NAMES_AES_256_SIV, ossl_aes256siv_functions),
ALG(PROV_NAMES_AES_128_GCM_SIV, ossl_aes128gcm_siv_functions),
ALG(PROV_NAMES_AES_192_GCM_SIV, ossl_aes192gcm_siv_functions),
ALG(PROV_NAMES_AES_256_GCM_SIV, ossl_aes256gcm_siv_functions),
#endif /* OPENSSL_NO_SIV */
ALG(PROV_NAMES_AES_256_GCM, ossl_aes256gcm_functions),
ALG(PROV_NAMES_AES_192_GCM, ossl_aes192gcm_functions),
ALG(PROV_NAMES_AES_128_GCM, ossl_aes128gcm_functions),
ALG(PROV_NAMES_AES_256_CCM, ossl_aes256ccm_functions),
ALG(PROV_NAMES_AES_192_CCM, ossl_aes192ccm_functions),
ALG(PROV_NAMES_AES_128_CCM, ossl_aes128ccm_functions),
ALG(PROV_NAMES_AES_256_WRAP, ossl_aes256wrap_functions),
ALG(PROV_NAMES_AES_192_WRAP, ossl_aes192wrap_functions),
ALG(PROV_NAMES_AES_128_WRAP, ossl_aes128wrap_functions),
ALG(PROV_NAMES_AES_256_WRAP_PAD, ossl_aes256wrappad_functions),
ALG(PROV_NAMES_AES_192_WRAP_PAD, ossl_aes192wrappad_functions),
ALG(PROV_NAMES_AES_128_WRAP_PAD, ossl_aes128wrappad_functions),
ALG(PROV_NAMES_AES_256_WRAP_INV, ossl_aes256wrapinv_functions),
ALG(PROV_NAMES_AES_192_WRAP_INV, ossl_aes192wrapinv_functions),
ALG(PROV_NAMES_AES_128_WRAP_INV, ossl_aes128wrapinv_functions),
ALG(PROV_NAMES_AES_256_WRAP_PAD_INV, ossl_aes256wrappadinv_functions),
ALG(PROV_NAMES_AES_192_WRAP_PAD_INV, ossl_aes192wrappadinv_functions),
ALG(PROV_NAMES_AES_128_WRAP_PAD_INV, ossl_aes128wrappadinv_functions),
ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA1, ossl_aes128cbc_hmac_sha1_functions,
ossl_cipher_capable_aes_cbc_hmac_sha1),
ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA1, ossl_aes256cbc_hmac_sha1_functions,
ossl_cipher_capable_aes_cbc_hmac_sha1),
ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA256, ossl_aes128cbc_hmac_sha256_functions,
ossl_cipher_capable_aes_cbc_hmac_sha256),
ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA256, ossl_aes256cbc_hmac_sha256_functions,
ossl_cipher_capable_aes_cbc_hmac_sha256),
#ifndef OPENSSL_NO_ARIA
ALG(PROV_NAMES_ARIA_256_GCM, ossl_aria256gcm_functions),
ALG(PROV_NAMES_ARIA_192_GCM, ossl_aria192gcm_functions),
ALG(PROV_NAMES_ARIA_128_GCM, ossl_aria128gcm_functions),
ALG(PROV_NAMES_ARIA_256_CCM, ossl_aria256ccm_functions),
ALG(PROV_NAMES_ARIA_192_CCM, ossl_aria192ccm_functions),
ALG(PROV_NAMES_ARIA_128_CCM, ossl_aria128ccm_functions),
ALG(PROV_NAMES_ARIA_256_ECB, ossl_aria256ecb_functions),
ALG(PROV_NAMES_ARIA_192_ECB, ossl_aria192ecb_functions),
ALG(PROV_NAMES_ARIA_128_ECB, ossl_aria128ecb_functions),
ALG(PROV_NAMES_ARIA_256_CBC, ossl_aria256cbc_functions),
ALG(PROV_NAMES_ARIA_192_CBC, ossl_aria192cbc_functions),
ALG(PROV_NAMES_ARIA_128_CBC, ossl_aria128cbc_functions),
ALG(PROV_NAMES_ARIA_256_OFB, ossl_aria256ofb_functions),
ALG(PROV_NAMES_ARIA_192_OFB, ossl_aria192ofb_functions),
ALG(PROV_NAMES_ARIA_128_OFB, ossl_aria128ofb_functions),
ALG(PROV_NAMES_ARIA_256_CFB, ossl_aria256cfb_functions),
ALG(PROV_NAMES_ARIA_192_CFB, ossl_aria192cfb_functions),
ALG(PROV_NAMES_ARIA_128_CFB, ossl_aria128cfb_functions),
ALG(PROV_NAMES_ARIA_256_CFB1, ossl_aria256cfb1_functions),
ALG(PROV_NAMES_ARIA_192_CFB1, ossl_aria192cfb1_functions),
ALG(PROV_NAMES_ARIA_128_CFB1, ossl_aria128cfb1_functions),
ALG(PROV_NAMES_ARIA_256_CFB8, ossl_aria256cfb8_functions),
ALG(PROV_NAMES_ARIA_192_CFB8, ossl_aria192cfb8_functions),
ALG(PROV_NAMES_ARIA_128_CFB8, ossl_aria128cfb8_functions),
ALG(PROV_NAMES_ARIA_256_CTR, ossl_aria256ctr_functions),
ALG(PROV_NAMES_ARIA_192_CTR, ossl_aria192ctr_functions),
ALG(PROV_NAMES_ARIA_128_CTR, ossl_aria128ctr_functions),
#endif /* OPENSSL_NO_ARIA */
#ifndef OPENSSL_NO_CAMELLIA
ALG(PROV_NAMES_CAMELLIA_256_ECB, ossl_camellia256ecb_functions),
ALG(PROV_NAMES_CAMELLIA_192_ECB, ossl_camellia192ecb_functions),
ALG(PROV_NAMES_CAMELLIA_128_ECB, ossl_camellia128ecb_functions),
ALG(PROV_NAMES_CAMELLIA_256_CBC, ossl_camellia256cbc_functions),
ALG(PROV_NAMES_CAMELLIA_192_CBC, ossl_camellia192cbc_functions),
ALG(PROV_NAMES_CAMELLIA_128_CBC, ossl_camellia128cbc_functions),
ALG(PROV_NAMES_CAMELLIA_128_CBC_CTS, ossl_camellia128cbc_cts_functions),
ALG(PROV_NAMES_CAMELLIA_192_CBC_CTS, ossl_camellia192cbc_cts_functions),
ALG(PROV_NAMES_CAMELLIA_256_CBC_CTS, ossl_camellia256cbc_cts_functions),
ALG(PROV_NAMES_CAMELLIA_256_OFB, ossl_camellia256ofb_functions),
ALG(PROV_NAMES_CAMELLIA_192_OFB, ossl_camellia192ofb_functions),
ALG(PROV_NAMES_CAMELLIA_128_OFB, ossl_camellia128ofb_functions),
ALG(PROV_NAMES_CAMELLIA_256_CFB, ossl_camellia256cfb_functions),
ALG(PROV_NAMES_CAMELLIA_192_CFB, ossl_camellia192cfb_functions),
ALG(PROV_NAMES_CAMELLIA_128_CFB, ossl_camellia128cfb_functions),
ALG(PROV_NAMES_CAMELLIA_256_CFB1, ossl_camellia256cfb1_functions),
ALG(PROV_NAMES_CAMELLIA_192_CFB1, ossl_camellia192cfb1_functions),
ALG(PROV_NAMES_CAMELLIA_128_CFB1, ossl_camellia128cfb1_functions),
ALG(PROV_NAMES_CAMELLIA_256_CFB8, ossl_camellia256cfb8_functions),
ALG(PROV_NAMES_CAMELLIA_192_CFB8, ossl_camellia192cfb8_functions),
ALG(PROV_NAMES_CAMELLIA_128_CFB8, ossl_camellia128cfb8_functions),
ALG(PROV_NAMES_CAMELLIA_256_CTR, ossl_camellia256ctr_functions),
ALG(PROV_NAMES_CAMELLIA_192_CTR, ossl_camellia192ctr_functions),
ALG(PROV_NAMES_CAMELLIA_128_CTR, ossl_camellia128ctr_functions),
#endif /* OPENSSL_NO_CAMELLIA */
#ifndef OPENSSL_NO_DES
ALG(PROV_NAMES_DES_EDE3_ECB, ossl_tdes_ede3_ecb_functions),
ALG(PROV_NAMES_DES_EDE3_CBC, ossl_tdes_ede3_cbc_functions),
ALG(PROV_NAMES_DES_EDE3_OFB, ossl_tdes_ede3_ofb_functions),
ALG(PROV_NAMES_DES_EDE3_CFB, ossl_tdes_ede3_cfb_functions),
ALG(PROV_NAMES_DES_EDE3_CFB8, ossl_tdes_ede3_cfb8_functions),
ALG(PROV_NAMES_DES_EDE3_CFB1, ossl_tdes_ede3_cfb1_functions),
ALG(PROV_NAMES_DES3_WRAP, ossl_tdes_wrap_cbc_functions),
ALG(PROV_NAMES_DES_EDE_ECB, ossl_tdes_ede2_ecb_functions),
ALG(PROV_NAMES_DES_EDE_CBC, ossl_tdes_ede2_cbc_functions),
ALG(PROV_NAMES_DES_EDE_OFB, ossl_tdes_ede2_ofb_functions),
ALG(PROV_NAMES_DES_EDE_CFB, ossl_tdes_ede2_cfb_functions),
#endif /* OPENSSL_NO_DES */
#ifndef OPENSSL_NO_SM4
ALG(PROV_NAMES_SM4_GCM, ossl_sm4128gcm_functions),
ALG(PROV_NAMES_SM4_CCM, ossl_sm4128ccm_functions),
ALG(PROV_NAMES_SM4_ECB, ossl_sm4128ecb_functions),
ALG(PROV_NAMES_SM4_CBC, ossl_sm4128cbc_functions),
ALG(PROV_NAMES_SM4_CTR, ossl_sm4128ctr_functions),
ALG(PROV_NAMES_SM4_OFB, ossl_sm4128ofb128_functions),
ALG(PROV_NAMES_SM4_CFB, ossl_sm4128cfb128_functions),
ALG(PROV_NAMES_SM4_XTS, ossl_sm4128xts_functions),
#endif /* OPENSSL_NO_SM4 */
#ifndef OPENSSL_NO_CHACHA
ALG(PROV_NAMES_ChaCha20, ossl_chacha20_functions),
# ifndef OPENSSL_NO_POLY1305
ALG(PROV_NAMES_ChaCha20_Poly1305, ossl_chacha20_ossl_poly1305_functions),
# endif /* OPENSSL_NO_POLY1305 */
#endif /* OPENSSL_NO_CHACHA */
{ { NULL, NULL, NULL }, NULL }
};
static OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)];
static const OSSL_ALGORITHM deflt_macs[] = {
#ifndef OPENSSL_NO_BLAKE2
{ PROV_NAMES_BLAKE2BMAC, "provider=default", ossl_blake2bmac_functions },
{ PROV_NAMES_BLAKE2SMAC, "provider=default", ossl_blake2smac_functions },
#endif
#ifndef OPENSSL_NO_CMAC
{ PROV_NAMES_CMAC, "provider=default", ossl_cmac_functions },
#endif
{ PROV_NAMES_GMAC, "provider=default", ossl_gmac_functions },
{ PROV_NAMES_HMAC, "provider=default", ossl_hmac_functions },
{ PROV_NAMES_KMAC_128, "provider=default", ossl_kmac128_functions },
{ PROV_NAMES_KMAC_256, "provider=default", ossl_kmac256_functions },
#ifndef OPENSSL_NO_SIPHASH
{ PROV_NAMES_SIPHASH, "provider=default", ossl_siphash_functions },
#endif
#ifndef OPENSSL_NO_POLY1305
{ PROV_NAMES_POLY1305, "provider=default", ossl_poly1305_functions },
#endif
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM deflt_kdfs[] = {
{ PROV_NAMES_HKDF, "provider=default", ossl_kdf_hkdf_functions },
{ PROV_NAMES_TLS1_3_KDF, "provider=default",
ossl_kdf_tls1_3_kdf_functions },
{ PROV_NAMES_SSKDF, "provider=default", ossl_kdf_sskdf_functions },
{ PROV_NAMES_PBKDF2, "provider=default", ossl_kdf_pbkdf2_functions },
{ PROV_NAMES_PKCS12KDF, "provider=default", ossl_kdf_pkcs12_functions },
{ PROV_NAMES_SSHKDF, "provider=default", ossl_kdf_sshkdf_functions },
{ PROV_NAMES_X963KDF, "provider=default", ossl_kdf_x963_kdf_functions },
{ PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_tls1_prf_functions },
{ PROV_NAMES_KBKDF, "provider=default", ossl_kdf_kbkdf_functions },
{ PROV_NAMES_X942KDF_ASN1, "provider=default", ossl_kdf_x942_kdf_functions },
#ifndef OPENSSL_NO_SCRYPT
{ PROV_NAMES_SCRYPT, "provider=default", ossl_kdf_scrypt_functions },
#endif
{ PROV_NAMES_KRB5KDF, "provider=default", ossl_kdf_krb5kdf_functions },
{ PROV_NAMES_HMAC_DRBG_KDF, "provider=default",
ossl_kdf_hmac_drbg_functions },
#ifndef OPENSSL_NO_ARGON2
{ PROV_NAMES_ARGON2I, "provider=default", ossl_kdf_argon2i_functions },
{ PROV_NAMES_ARGON2D, "provider=default", ossl_kdf_argon2d_functions },
{ PROV_NAMES_ARGON2ID, "provider=default", ossl_kdf_argon2id_functions },
#endif
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM deflt_keyexch[] = {
#ifndef OPENSSL_NO_DH
{ PROV_NAMES_DH, "provider=default", ossl_dh_keyexch_functions },
#endif
#ifndef OPENSSL_NO_EC
{ PROV_NAMES_ECDH, "provider=default", ossl_ecdh_keyexch_functions },
# ifndef OPENSSL_NO_ECX
{ PROV_NAMES_X25519, "provider=default", ossl_x25519_keyexch_functions },
{ PROV_NAMES_X448, "provider=default", ossl_x448_keyexch_functions },
# endif
#endif
{ PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_tls1_prf_keyexch_functions },
{ PROV_NAMES_HKDF, "provider=default", ossl_kdf_hkdf_keyexch_functions },
{ PROV_NAMES_SCRYPT, "provider=default",
ossl_kdf_scrypt_keyexch_functions },
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM deflt_rands[] = {
{ PROV_NAMES_CTR_DRBG, "provider=default", ossl_drbg_ctr_functions },
{ PROV_NAMES_HASH_DRBG, "provider=default", ossl_drbg_hash_functions },
{ PROV_NAMES_HMAC_DRBG, "provider=default", ossl_drbg_ossl_hmac_functions },
{ PROV_NAMES_SEED_SRC, "provider=default", ossl_seed_src_functions },
{ PROV_NAMES_TEST_RAND, "provider=default", ossl_test_rng_functions },
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM deflt_signature[] = {
#ifndef OPENSSL_NO_DSA
{ PROV_NAMES_DSA, "provider=default", ossl_dsa_signature_functions },
#endif
{ PROV_NAMES_RSA, "provider=default", ossl_rsa_signature_functions },
#ifndef OPENSSL_NO_EC
# ifndef OPENSSL_NO_ECX
{ PROV_NAMES_ED25519, "provider=default", ossl_ed25519_signature_functions },
{ PROV_NAMES_ED448, "provider=default", ossl_ed448_signature_functions },
# endif
{ PROV_NAMES_ECDSA, "provider=default", ossl_ecdsa_signature_functions },
# ifndef OPENSSL_NO_SM2
{ PROV_NAMES_SM2, "provider=default", ossl_sm2_signature_functions },
# endif
#endif
{ PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_hmac_signature_functions },
{ PROV_NAMES_SIPHASH, "provider=default",
ossl_mac_legacy_siphash_signature_functions },
#ifndef OPENSSL_NO_POLY1305
{ PROV_NAMES_POLY1305, "provider=default",
ossl_mac_legacy_poly1305_signature_functions },
#endif
#ifndef OPENSSL_NO_CMAC
{ PROV_NAMES_CMAC, "provider=default", ossl_mac_legacy_cmac_signature_functions },
#endif
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM deflt_asym_cipher[] = {
{ PROV_NAMES_RSA, "provider=default", ossl_rsa_asym_cipher_functions },
#ifndef OPENSSL_NO_SM2
{ PROV_NAMES_SM2, "provider=default", ossl_sm2_asym_cipher_functions },
#endif
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM deflt_asym_kem[] = {
{ PROV_NAMES_RSA, "provider=default", ossl_rsa_asym_kem_functions },
#ifndef OPENSSL_NO_EC
# ifndef OPENSSL_NO_ECX
{ PROV_NAMES_X25519, "provider=default", ossl_ecx_asym_kem_functions },
{ PROV_NAMES_X448, "provider=default", ossl_ecx_asym_kem_functions },
# endif
{ PROV_NAMES_EC, "provider=default", ossl_ec_asym_kem_functions },
#endif
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM deflt_keymgmt[] = {
#ifndef OPENSSL_NO_DH
{ PROV_NAMES_DH, "provider=default", ossl_dh_keymgmt_functions,
PROV_DESCS_DH },
{ PROV_NAMES_DHX, "provider=default", ossl_dhx_keymgmt_functions,
PROV_DESCS_DHX },
#endif
#ifndef OPENSSL_NO_DSA
{ PROV_NAMES_DSA, "provider=default", ossl_dsa_keymgmt_functions,
PROV_DESCS_DSA},
#endif
{ PROV_NAMES_RSA, "provider=default", ossl_rsa_keymgmt_functions,
PROV_DESCS_RSA },
{ PROV_NAMES_RSA_PSS, "provider=default", ossl_rsapss_keymgmt_functions,
PROV_DESCS_RSA_PSS },
#ifndef OPENSSL_NO_EC
{ PROV_NAMES_EC, "provider=default", ossl_ec_keymgmt_functions,
PROV_DESCS_EC },
# ifndef OPENSSL_NO_ECX
{ PROV_NAMES_X25519, "provider=default", ossl_x25519_keymgmt_functions,
PROV_DESCS_X25519 },
{ PROV_NAMES_X448, "provider=default", ossl_x448_keymgmt_functions,
PROV_DESCS_X448 },
{ PROV_NAMES_ED25519, "provider=default", ossl_ed25519_keymgmt_functions,
PROV_DESCS_ED25519 },
{ PROV_NAMES_ED448, "provider=default", ossl_ed448_keymgmt_functions,
PROV_DESCS_ED448 },
# endif
#endif
{ PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_keymgmt_functions,
PROV_DESCS_TLS1_PRF_SIGN },
{ PROV_NAMES_HKDF, "provider=default", ossl_kdf_keymgmt_functions,
PROV_DESCS_HKDF_SIGN },
{ PROV_NAMES_SCRYPT, "provider=default", ossl_kdf_keymgmt_functions,
PROV_DESCS_SCRYPT_SIGN },
{ PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_keymgmt_functions,
PROV_DESCS_HMAC_SIGN },
{ PROV_NAMES_SIPHASH, "provider=default", ossl_mac_legacy_keymgmt_functions,
PROV_DESCS_SIPHASH_SIGN },
#ifndef OPENSSL_NO_POLY1305
{ PROV_NAMES_POLY1305, "provider=default", ossl_mac_legacy_keymgmt_functions,
PROV_DESCS_POLY1305_SIGN },
#endif
#ifndef OPENSSL_NO_CMAC
{ PROV_NAMES_CMAC, "provider=default", ossl_cmac_legacy_keymgmt_functions,
PROV_DESCS_CMAC_SIGN },
#endif
#ifndef OPENSSL_NO_SM2
{ PROV_NAMES_SM2, "provider=default", ossl_sm2_keymgmt_functions,
PROV_DESCS_SM2 },
#endif
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM deflt_encoder[] = {
#define ENCODER_PROVIDER "default"
#include "encoders.inc"
{ NULL, NULL, NULL }
#undef ENCODER_PROVIDER
};
static const OSSL_ALGORITHM deflt_decoder[] = {
#define DECODER_PROVIDER "default"
#include "decoders.inc"
{ NULL, NULL, NULL }
#undef DECODER_PROVIDER
};
static const OSSL_ALGORITHM deflt_store[] = {
#define STORE(name, _fips, func_table) \
{ name, "provider=default,fips=" _fips, (func_table) },
#include "stores.inc"
{ NULL, NULL, NULL }
#undef STORE
};
static const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id,
int *no_cache)
{
*no_cache = 0;
switch (operation_id) {
case OSSL_OP_DIGEST:
return deflt_digests;
case OSSL_OP_CIPHER:
return exported_ciphers;
case OSSL_OP_MAC:
return deflt_macs;
case OSSL_OP_KDF:
return deflt_kdfs;
case OSSL_OP_RAND:
return deflt_rands;
case OSSL_OP_KEYMGMT:
return deflt_keymgmt;
case OSSL_OP_KEYEXCH:
return deflt_keyexch;
case OSSL_OP_SIGNATURE:
return deflt_signature;
case OSSL_OP_ASYM_CIPHER:
return deflt_asym_cipher;
case OSSL_OP_KEM:
return deflt_asym_kem;
case OSSL_OP_ENCODER:
return deflt_encoder;
case OSSL_OP_DECODER:
return deflt_decoder;
case OSSL_OP_STORE:
return deflt_store;
}
return NULL;
}
static void deflt_teardown(void *provctx)
{
BIO_meth_free(ossl_prov_ctx_get0_core_bio_method(provctx));
ossl_prov_ctx_free(provctx);
}
/* Functions we provide to the core */
static const OSSL_DISPATCH deflt_dispatch_table[] = {
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown },
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params },
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params },
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query },
{ OSSL_FUNC_PROVIDER_GET_CAPABILITIES,
(void (*)(void))ossl_prov_get_capabilities },
OSSL_DISPATCH_END
};
OSSL_provider_init_fn ossl_default_provider_init;
int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle,
const OSSL_DISPATCH *in,
const OSSL_DISPATCH **out,
void **provctx)
{
OSSL_FUNC_core_get_libctx_fn *c_get_libctx = NULL;
BIO_METHOD *corebiometh;
if (!ossl_prov_bio_from_dispatch(in)
|| !ossl_prov_seeding_from_dispatch(in))
return 0;
for (; in->function_id != 0; in++) {
switch (in->function_id) {
case OSSL_FUNC_CORE_GETTABLE_PARAMS:
c_gettable_params = OSSL_FUNC_core_gettable_params(in);
break;
case OSSL_FUNC_CORE_GET_PARAMS:
c_get_params = OSSL_FUNC_core_get_params(in);
break;
case OSSL_FUNC_CORE_GET_LIBCTX:
c_get_libctx = OSSL_FUNC_core_get_libctx(in);
break;
default:
/* Just ignore anything we don't understand */
break;
}
}
if (c_get_libctx == NULL)
return 0;
/*
* We want to make sure that all calls from this provider that requires
* a library context use the same context as the one used to call our
* functions. We do that by passing it along in the provider context.
*
* This only works for built-in providers. Most providers should
* create their own library context.
*/
if ((*provctx = ossl_prov_ctx_new()) == NULL
|| (corebiometh = ossl_bio_prov_init_bio_method()) == NULL) {
ossl_prov_ctx_free(*provctx);
*provctx = NULL;
return 0;
}
ossl_prov_ctx_set0_libctx(*provctx,
(OSSL_LIB_CTX *)c_get_libctx(handle));
ossl_prov_ctx_set0_handle(*provctx, handle);
ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh);
*out = deflt_dispatch_table;
ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers);
return 1;
}
|
./openssl/providers/prov_running.c | /*
* Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/e_os2.h>
#include "prov/providercommon.h"
/* By default, our providers don't have an error state */
void ossl_set_error_state(const char *type)
{
}
/* By default, our providers are always in a happy state */
int ossl_prov_is_running(void)
{
return 1;
}
|
./openssl/providers/baseprov.c | /*
* Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <stdio.h>
#include <openssl/opensslconf.h>
#include <openssl/core.h>
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include <openssl/params.h>
#include "prov/bio.h"
#include "prov/provider_ctx.h"
#include "prov/providercommon.h"
#include "prov/implementations.h"
#include "prov/provider_util.h"
#include "prov/names.h"
/*
* Forward declarations to ensure that interface functions are correctly
* defined.
*/
static OSSL_FUNC_provider_gettable_params_fn base_gettable_params;
static OSSL_FUNC_provider_get_params_fn base_get_params;
static OSSL_FUNC_provider_query_operation_fn base_query;
/* Functions provided by the core */
static OSSL_FUNC_core_gettable_params_fn *c_gettable_params = NULL;
static OSSL_FUNC_core_get_params_fn *c_get_params = NULL;
/* Parameters we provide to the core */
static const OSSL_PARAM base_param_types[] = {
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
OSSL_PARAM_END
};
static const OSSL_PARAM *base_gettable_params(void *provctx)
{
return base_param_types;
}
static int base_get_params(void *provctx, OSSL_PARAM params[])
{
OSSL_PARAM *p;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
if (p != NULL
&& !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Base Provider"))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
return 0;
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
return 0;
return 1;
}
static const OSSL_ALGORITHM base_encoder[] = {
#define ENCODER_PROVIDER "base"
#include "encoders.inc"
{ NULL, NULL, NULL }
#undef ENCODER_PROVIDER
};
static const OSSL_ALGORITHM base_decoder[] = {
#define DECODER_PROVIDER "base"
#include "decoders.inc"
{ NULL, NULL, NULL }
#undef DECODER_PROVIDER
};
static const OSSL_ALGORITHM base_store[] = {
#define STORE(name, _fips, func_table) \
{ name, "provider=base,fips=" _fips, (func_table) },
#include "stores.inc"
{ NULL, NULL, NULL }
#undef STORE
};
static const OSSL_ALGORITHM base_rands[] = {
{ PROV_NAMES_SEED_SRC, "provider=base", ossl_seed_src_functions },
{ NULL, NULL, NULL }
};
static const OSSL_ALGORITHM *base_query(void *provctx, int operation_id,
int *no_cache)
{
*no_cache = 0;
switch (operation_id) {
case OSSL_OP_ENCODER:
return base_encoder;
case OSSL_OP_DECODER:
return base_decoder;
case OSSL_OP_STORE:
return base_store;
case OSSL_OP_RAND:
return base_rands;
}
return NULL;
}
static void base_teardown(void *provctx)
{
BIO_meth_free(ossl_prov_ctx_get0_core_bio_method(provctx));
ossl_prov_ctx_free(provctx);
}
/* Functions we provide to the core */
static const OSSL_DISPATCH base_dispatch_table[] = {
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))base_teardown },
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS,
(void (*)(void))base_gettable_params },
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))base_get_params },
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))base_query },
OSSL_DISPATCH_END
};
OSSL_provider_init_fn ossl_base_provider_init;
int ossl_base_provider_init(const OSSL_CORE_HANDLE *handle,
const OSSL_DISPATCH *in, const OSSL_DISPATCH **out,
void **provctx)
{
OSSL_FUNC_core_get_libctx_fn *c_get_libctx = NULL;
BIO_METHOD *corebiometh;
if (!ossl_prov_bio_from_dispatch(in))
return 0;
for (; in->function_id != 0; in++) {
switch (in->function_id) {
case OSSL_FUNC_CORE_GETTABLE_PARAMS:
c_gettable_params = OSSL_FUNC_core_gettable_params(in);
break;
case OSSL_FUNC_CORE_GET_PARAMS:
c_get_params = OSSL_FUNC_core_get_params(in);
break;
case OSSL_FUNC_CORE_GET_LIBCTX:
c_get_libctx = OSSL_FUNC_core_get_libctx(in);
break;
default:
/* Just ignore anything we don't understand */
break;
}
}
if (c_get_libctx == NULL)
return 0;
/*
* We want to make sure that all calls from this provider that requires
* a library context use the same context as the one used to call our
* functions. We do that by passing it along in the provider context.
*
* This only works for built-in providers. Most providers should
* create their own library context.
*/
if ((*provctx = ossl_prov_ctx_new()) == NULL
|| (corebiometh = ossl_bio_prov_init_bio_method()) == NULL) {
ossl_prov_ctx_free(*provctx);
*provctx = NULL;
return 0;
}
ossl_prov_ctx_set0_libctx(*provctx,
(OSSL_LIB_CTX *)c_get_libctx(handle));
ossl_prov_ctx_set0_handle(*provctx, handle);
ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh);
*out = base_dispatch_table;
return 1;
}
|
./openssl/providers/implementations/macs/gmac_prov.c | /*
* Copyright 2018-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdlib.h>
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include <openssl/params.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/proverr.h>
#include "prov/implementations.h"
#include "prov/provider_ctx.h"
#include "prov/provider_util.h"
#include "prov/providercommon.h"
/*
* Forward declaration of everything implemented here. This is not strictly
* necessary for the compiler, but provides an assurance that the signatures
* of the functions in the dispatch table are correct.
*/
static OSSL_FUNC_mac_newctx_fn gmac_new;
static OSSL_FUNC_mac_dupctx_fn gmac_dup;
static OSSL_FUNC_mac_freectx_fn gmac_free;
static OSSL_FUNC_mac_gettable_params_fn gmac_gettable_params;
static OSSL_FUNC_mac_get_params_fn gmac_get_params;
static OSSL_FUNC_mac_settable_ctx_params_fn gmac_settable_ctx_params;
static OSSL_FUNC_mac_set_ctx_params_fn gmac_set_ctx_params;
static OSSL_FUNC_mac_init_fn gmac_init;
static OSSL_FUNC_mac_update_fn gmac_update;
static OSSL_FUNC_mac_final_fn gmac_final;
/* local GMAC pkey structure */
struct gmac_data_st {
void *provctx;
EVP_CIPHER_CTX *ctx; /* Cipher context */
PROV_CIPHER cipher;
};
static void gmac_free(void *vmacctx)
{
struct gmac_data_st *macctx = vmacctx;
if (macctx != NULL) {
EVP_CIPHER_CTX_free(macctx->ctx);
ossl_prov_cipher_reset(&macctx->cipher);
OPENSSL_free(macctx);
}
}
static void *gmac_new(void *provctx)
{
struct gmac_data_st *macctx;
if (!ossl_prov_is_running())
return NULL;
if ((macctx = OPENSSL_zalloc(sizeof(*macctx))) == NULL
|| (macctx->ctx = EVP_CIPHER_CTX_new()) == NULL) {
gmac_free(macctx);
return NULL;
}
macctx->provctx = provctx;
return macctx;
}
static void *gmac_dup(void *vsrc)
{
struct gmac_data_st *src = vsrc;
struct gmac_data_st *dst;
if (!ossl_prov_is_running())
return NULL;
dst = gmac_new(src->provctx);
if (dst == NULL)
return NULL;
if (!EVP_CIPHER_CTX_copy(dst->ctx, src->ctx)
|| !ossl_prov_cipher_copy(&dst->cipher, &src->cipher)) {
gmac_free(dst);
return NULL;
}
return dst;
}
static size_t gmac_size(void)
{
return EVP_GCM_TLS_TAG_LEN;
}
static int gmac_setkey(struct gmac_data_st *macctx,
const unsigned char *key, size_t keylen)
{
EVP_CIPHER_CTX *ctx = macctx->ctx;
if (keylen != (size_t)EVP_CIPHER_CTX_get_key_length(ctx)) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
return 0;
}
if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL))
return 0;
return 1;
}
static int gmac_init(void *vmacctx, const unsigned char *key,
size_t keylen, const OSSL_PARAM params[])
{
struct gmac_data_st *macctx = vmacctx;
if (!ossl_prov_is_running() || !gmac_set_ctx_params(macctx, params))
return 0;
if (key != NULL)
return gmac_setkey(macctx, key, keylen);
return EVP_EncryptInit_ex(macctx->ctx, NULL, NULL, NULL, NULL);
}
static int gmac_update(void *vmacctx, const unsigned char *data,
size_t datalen)
{
struct gmac_data_st *macctx = vmacctx;
EVP_CIPHER_CTX *ctx = macctx->ctx;
int outlen;
if (datalen == 0)
return 1;
while (datalen > INT_MAX) {
if (!EVP_EncryptUpdate(ctx, NULL, &outlen, data, INT_MAX))
return 0;
data += INT_MAX;
datalen -= INT_MAX;
}
return EVP_EncryptUpdate(ctx, NULL, &outlen, data, datalen);
}
static int gmac_final(void *vmacctx, unsigned char *out, size_t *outl,
size_t outsize)
{
OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
struct gmac_data_st *macctx = vmacctx;
int hlen = 0;
if (!ossl_prov_is_running())
return 0;
if (!EVP_EncryptFinal_ex(macctx->ctx, out, &hlen))
return 0;
hlen = gmac_size();
params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG,
out, (size_t)hlen);
if (!EVP_CIPHER_CTX_get_params(macctx->ctx, params))
return 0;
*outl = hlen;
return 1;
}
static const OSSL_PARAM known_gettable_params[] = {
OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),
OSSL_PARAM_END
};
static const OSSL_PARAM *gmac_gettable_params(void *provctx)
{
return known_gettable_params;
}
static int gmac_get_params(OSSL_PARAM params[])
{
OSSL_PARAM *p;
if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL)
return OSSL_PARAM_set_size_t(p, gmac_size());
return 1;
}
static const OSSL_PARAM known_settable_ctx_params[] = {
OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_CIPHER, NULL, 0),
OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_PROPERTIES, NULL, 0),
OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0),
OSSL_PARAM_octet_string(OSSL_MAC_PARAM_IV, NULL, 0),
OSSL_PARAM_END
};
static const OSSL_PARAM *gmac_settable_ctx_params(ossl_unused void *ctx,
ossl_unused void *provctx)
{
return known_settable_ctx_params;
}
/*
* ALL parameters should be set before init().
*/
static int gmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[])
{
struct gmac_data_st *macctx = vmacctx;
EVP_CIPHER_CTX *ctx = macctx->ctx;
OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(macctx->provctx);
const OSSL_PARAM *p;
if (params == NULL)
return 1;
if (ctx == NULL)
return 0;
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_CIPHER)) != NULL) {
if (!ossl_prov_cipher_load_from_params(&macctx->cipher, params, provctx))
return 0;
if (EVP_CIPHER_get_mode(ossl_prov_cipher_cipher(&macctx->cipher))
!= EVP_CIPH_GCM_MODE) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_MODE);
return 0;
}
if (!EVP_EncryptInit_ex(ctx, ossl_prov_cipher_cipher(&macctx->cipher),
ossl_prov_cipher_engine(&macctx->cipher), NULL,
NULL))
return 0;
}
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL)
if (p->data_type != OSSL_PARAM_OCTET_STRING
|| !gmac_setkey(macctx, p->data, p->data_size))
return 0;
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_IV)) != NULL) {
if (p->data_type != OSSL_PARAM_OCTET_STRING)
return 0;
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
p->data_size, NULL) <= 0
|| !EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, p->data))
return 0;
}
return 1;
}
const OSSL_DISPATCH ossl_gmac_functions[] = {
{ OSSL_FUNC_MAC_NEWCTX, (void (*)(void))gmac_new },
{ OSSL_FUNC_MAC_DUPCTX, (void (*)(void))gmac_dup },
{ OSSL_FUNC_MAC_FREECTX, (void (*)(void))gmac_free },
{ OSSL_FUNC_MAC_INIT, (void (*)(void))gmac_init },
{ OSSL_FUNC_MAC_UPDATE, (void (*)(void))gmac_update },
{ OSSL_FUNC_MAC_FINAL, (void (*)(void))gmac_final },
{ OSSL_FUNC_MAC_GETTABLE_PARAMS, (void (*)(void))gmac_gettable_params },
{ OSSL_FUNC_MAC_GET_PARAMS, (void (*)(void))gmac_get_params },
{ OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS,
(void (*)(void))gmac_settable_ctx_params },
{ OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))gmac_set_ctx_params },
OSSL_DISPATCH_END
};
|
./openssl/providers/implementations/macs/blake2s_mac.c | /*
* Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/* Constants */
#define BLAKE2_CTX BLAKE2S_CTX
#define BLAKE2_PARAM BLAKE2S_PARAM
#define BLAKE2_KEYBYTES BLAKE2S_KEYBYTES
#define BLAKE2_OUTBYTES BLAKE2S_OUTBYTES
#define BLAKE2_PERSONALBYTES BLAKE2S_PERSONALBYTES
#define BLAKE2_SALTBYTES BLAKE2S_SALTBYTES
#define BLAKE2_BLOCKBYTES BLAKE2S_BLOCKBYTES
/* Function names */
#define BLAKE2_PARAM_INIT ossl_blake2s_param_init
#define BLAKE2_INIT_KEY ossl_blake2s_init_key
#define BLAKE2_UPDATE ossl_blake2s_update
#define BLAKE2_FINAL ossl_blake2s_final
#define BLAKE2_PARAM_SET_DIGEST_LENGTH ossl_blake2s_param_set_digest_length
#define BLAKE2_PARAM_SET_KEY_LENGTH ossl_blake2s_param_set_key_length
#define BLAKE2_PARAM_SET_PERSONAL ossl_blake2s_param_set_personal
#define BLAKE2_PARAM_SET_SALT ossl_blake2s_param_set_salt
/* OSSL_DISPATCH symbol */
#define BLAKE2_FUNCTIONS ossl_blake2smac_functions
#include "blake2_mac_impl.c"
|
./openssl/providers/implementations/macs/siphash_prov.c | /*
* Copyright 2018-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include <openssl/params.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/proverr.h>
#include "crypto/siphash.h"
#include "prov/implementations.h"
#include "prov/providercommon.h"
/*
* Forward declaration of everything implemented here. This is not strictly
* necessary for the compiler, but provides an assurance that the signatures
* of the functions in the dispatch table are correct.
*/
static OSSL_FUNC_mac_newctx_fn siphash_new;
static OSSL_FUNC_mac_dupctx_fn siphash_dup;
static OSSL_FUNC_mac_freectx_fn siphash_free;
static OSSL_FUNC_mac_gettable_ctx_params_fn siphash_gettable_ctx_params;
static OSSL_FUNC_mac_get_ctx_params_fn siphash_get_ctx_params;
static OSSL_FUNC_mac_settable_ctx_params_fn siphash_settable_ctx_params;
static OSSL_FUNC_mac_set_ctx_params_fn siphash_set_params;
static OSSL_FUNC_mac_init_fn siphash_init;
static OSSL_FUNC_mac_update_fn siphash_update;
static OSSL_FUNC_mac_final_fn siphash_final;
struct siphash_data_st {
void *provctx;
SIPHASH siphash; /* Siphash data */
SIPHASH sipcopy; /* Siphash data copy for reinitialization */
unsigned int crounds, drounds;
};
static unsigned int crounds(struct siphash_data_st *ctx)
{
return ctx->crounds != 0 ? ctx->crounds : SIPHASH_C_ROUNDS;
}
static unsigned int drounds(struct siphash_data_st *ctx)
{
return ctx->drounds != 0 ? ctx->drounds : SIPHASH_D_ROUNDS;
}
static void *siphash_new(void *provctx)
{
struct siphash_data_st *ctx;
if (!ossl_prov_is_running())
return NULL;
ctx = OPENSSL_zalloc(sizeof(*ctx));
if (ctx != NULL)
ctx->provctx = provctx;
return ctx;
}
static void siphash_free(void *vmacctx)
{
OPENSSL_free(vmacctx);
}
static void *siphash_dup(void *vsrc)
{
struct siphash_data_st *ssrc = vsrc;
struct siphash_data_st *sdst;
if (!ossl_prov_is_running())
return NULL;
sdst = OPENSSL_malloc(sizeof(*sdst));
if (sdst == NULL)
return NULL;
*sdst = *ssrc;
return sdst;
}
static size_t siphash_size(void *vmacctx)
{
struct siphash_data_st *ctx = vmacctx;
return SipHash_hash_size(&ctx->siphash);
}
static int siphash_setkey(struct siphash_data_st *ctx,
const unsigned char *key, size_t keylen)
{
int ret;
if (keylen != SIPHASH_KEY_SIZE)
return 0;
ret = SipHash_Init(&ctx->siphash, key, crounds(ctx), drounds(ctx));
if (ret)
ctx->sipcopy = ctx->siphash;
return ret;
}
static int siphash_init(void *vmacctx, const unsigned char *key, size_t keylen,
const OSSL_PARAM params[])
{
struct siphash_data_st *ctx = vmacctx;
if (!ossl_prov_is_running() || !siphash_set_params(ctx, params))
return 0;
/*
* Without a key, there is not much to do here,
* The actual initialization happens through controls.
*/
if (key == NULL) {
ctx->siphash = ctx->sipcopy;
return 1;
}
return siphash_setkey(ctx, key, keylen);
}
static int siphash_update(void *vmacctx, const unsigned char *data,
size_t datalen)
{
struct siphash_data_st *ctx = vmacctx;
if (datalen == 0)
return 1;
SipHash_Update(&ctx->siphash, data, datalen);
return 1;
}
static int siphash_final(void *vmacctx, unsigned char *out, size_t *outl,
size_t outsize)
{
struct siphash_data_st *ctx = vmacctx;
size_t hlen = siphash_size(ctx);
if (!ossl_prov_is_running() || outsize < hlen)
return 0;
*outl = hlen;
return SipHash_Final(&ctx->siphash, out, hlen);
}
static const OSSL_PARAM *siphash_gettable_ctx_params(ossl_unused void *ctx,
ossl_unused void *provctx)
{
static const OSSL_PARAM known_gettable_ctx_params[] = {
OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),
OSSL_PARAM_uint(OSSL_MAC_PARAM_C_ROUNDS, NULL),
OSSL_PARAM_uint(OSSL_MAC_PARAM_D_ROUNDS, NULL),
OSSL_PARAM_END
};
return known_gettable_ctx_params;
}
static int siphash_get_ctx_params(void *vmacctx, OSSL_PARAM params[])
{
struct siphash_data_st *ctx = vmacctx;
OSSL_PARAM *p;
if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL
&& !OSSL_PARAM_set_size_t(p, siphash_size(vmacctx)))
return 0;
if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_C_ROUNDS)) != NULL
&& !OSSL_PARAM_set_uint(p, crounds(ctx)))
return 0;
if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_D_ROUNDS)) != NULL
&& !OSSL_PARAM_set_uint(p, drounds(ctx)))
return 0;
return 1;
}
static const OSSL_PARAM *siphash_settable_ctx_params(ossl_unused void *ctx,
void *provctx)
{
static const OSSL_PARAM known_settable_ctx_params[] = {
OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),
OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0),
OSSL_PARAM_uint(OSSL_MAC_PARAM_C_ROUNDS, NULL),
OSSL_PARAM_uint(OSSL_MAC_PARAM_D_ROUNDS, NULL),
OSSL_PARAM_END
};
return known_settable_ctx_params;
}
static int siphash_set_params(void *vmacctx, const OSSL_PARAM *params)
{
struct siphash_data_st *ctx = vmacctx;
const OSSL_PARAM *p = NULL;
size_t size;
if (params == NULL)
return 1;
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_SIZE)) != NULL) {
if (!OSSL_PARAM_get_size_t(p, &size)
|| !SipHash_set_hash_size(&ctx->siphash, size)
|| !SipHash_set_hash_size(&ctx->sipcopy, size))
return 0;
}
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_C_ROUNDS)) != NULL
&& !OSSL_PARAM_get_uint(p, &ctx->crounds))
return 0;
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_D_ROUNDS)) != NULL
&& !OSSL_PARAM_get_uint(p, &ctx->drounds))
return 0;
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL)
if (p->data_type != OSSL_PARAM_OCTET_STRING
|| !siphash_setkey(ctx, p->data, p->data_size))
return 0;
return 1;
}
const OSSL_DISPATCH ossl_siphash_functions[] = {
{ OSSL_FUNC_MAC_NEWCTX, (void (*)(void))siphash_new },
{ OSSL_FUNC_MAC_DUPCTX, (void (*)(void))siphash_dup },
{ OSSL_FUNC_MAC_FREECTX, (void (*)(void))siphash_free },
{ OSSL_FUNC_MAC_INIT, (void (*)(void))siphash_init },
{ OSSL_FUNC_MAC_UPDATE, (void (*)(void))siphash_update },
{ OSSL_FUNC_MAC_FINAL, (void (*)(void))siphash_final },
{ OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS,
(void (*)(void))siphash_gettable_ctx_params },
{ OSSL_FUNC_MAC_GET_CTX_PARAMS, (void (*)(void))siphash_get_ctx_params },
{ OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS,
(void (*)(void))siphash_settable_ctx_params },
{ OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))siphash_set_params },
OSSL_DISPATCH_END
};
|
./openssl/providers/implementations/macs/hmac_prov.c | /*
* Copyright 2018-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* HMAC low level APIs are deprecated for public use, but still ok for internal
* use.
*/
#include "internal/deprecated.h"
#include <string.h>
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include <openssl/params.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include "internal/ssl3_cbc.h"
#include "prov/implementations.h"
#include "prov/provider_ctx.h"
#include "prov/provider_util.h"
#include "prov/providercommon.h"
/*
* Forward declaration of everything implemented here. This is not strictly
* necessary for the compiler, but provides an assurance that the signatures
* of the functions in the dispatch table are correct.
*/
static OSSL_FUNC_mac_newctx_fn hmac_new;
static OSSL_FUNC_mac_dupctx_fn hmac_dup;
static OSSL_FUNC_mac_freectx_fn hmac_free;
static OSSL_FUNC_mac_gettable_ctx_params_fn hmac_gettable_ctx_params;
static OSSL_FUNC_mac_get_ctx_params_fn hmac_get_ctx_params;
static OSSL_FUNC_mac_settable_ctx_params_fn hmac_settable_ctx_params;
static OSSL_FUNC_mac_set_ctx_params_fn hmac_set_ctx_params;
static OSSL_FUNC_mac_init_fn hmac_init;
static OSSL_FUNC_mac_update_fn hmac_update;
static OSSL_FUNC_mac_final_fn hmac_final;
/* local HMAC context structure */
/* typedef EVP_MAC_IMPL */
struct hmac_data_st {
void *provctx;
HMAC_CTX *ctx; /* HMAC context */
PROV_DIGEST digest;
unsigned char *key;
size_t keylen;
/* Length of full TLS record including the MAC and any padding */
size_t tls_data_size;
unsigned char tls_header[13];
int tls_header_set;
unsigned char tls_mac_out[EVP_MAX_MD_SIZE];
size_t tls_mac_out_size;
};
static void *hmac_new(void *provctx)
{
struct hmac_data_st *macctx;
if (!ossl_prov_is_running())
return NULL;
if ((macctx = OPENSSL_zalloc(sizeof(*macctx))) == NULL
|| (macctx->ctx = HMAC_CTX_new()) == NULL) {
OPENSSL_free(macctx);
return NULL;
}
macctx->provctx = provctx;
return macctx;
}
static void hmac_free(void *vmacctx)
{
struct hmac_data_st *macctx = vmacctx;
if (macctx != NULL) {
HMAC_CTX_free(macctx->ctx);
ossl_prov_digest_reset(&macctx->digest);
OPENSSL_secure_clear_free(macctx->key, macctx->keylen);
OPENSSL_free(macctx);
}
}
static void *hmac_dup(void *vsrc)
{
struct hmac_data_st *src = vsrc;
struct hmac_data_st *dst;
HMAC_CTX *ctx;
if (!ossl_prov_is_running())
return NULL;
dst = hmac_new(src->provctx);
if (dst == NULL)
return NULL;
ctx = dst->ctx;
*dst = *src;
dst->ctx = ctx;
dst->key = NULL;
memset(&dst->digest, 0, sizeof(dst->digest));
if (!HMAC_CTX_copy(dst->ctx, src->ctx)
|| !ossl_prov_digest_copy(&dst->digest, &src->digest)) {
hmac_free(dst);
return NULL;
}
if (src->key != NULL) {
/* There is no "secure" OPENSSL_memdup */
dst->key = OPENSSL_secure_malloc(src->keylen > 0 ? src->keylen : 1);
if (dst->key == NULL) {
hmac_free(dst);
return 0;
}
memcpy(dst->key, src->key, src->keylen);
}
return dst;
}
static size_t hmac_size(struct hmac_data_st *macctx)
{
return HMAC_size(macctx->ctx);
}
static int hmac_block_size(struct hmac_data_st *macctx)
{
const EVP_MD *md = ossl_prov_digest_md(&macctx->digest);
if (md == NULL)
return 0;
return EVP_MD_block_size(md);
}
static int hmac_setkey(struct hmac_data_st *macctx,
const unsigned char *key, size_t keylen)
{
const EVP_MD *digest;
if (macctx->key != NULL)
OPENSSL_secure_clear_free(macctx->key, macctx->keylen);
/* Keep a copy of the key in case we need it for TLS HMAC */
macctx->key = OPENSSL_secure_malloc(keylen > 0 ? keylen : 1);
if (macctx->key == NULL)
return 0;
memcpy(macctx->key, key, keylen);
macctx->keylen = keylen;
digest = ossl_prov_digest_md(&macctx->digest);
/* HMAC_Init_ex doesn't tolerate all zero params, so we must be careful */
if (key != NULL || (macctx->tls_data_size == 0 && digest != NULL))
return HMAC_Init_ex(macctx->ctx, key, keylen, digest,
ossl_prov_digest_engine(&macctx->digest));
return 1;
}
static int hmac_init(void *vmacctx, const unsigned char *key,
size_t keylen, const OSSL_PARAM params[])
{
struct hmac_data_st *macctx = vmacctx;
if (!ossl_prov_is_running() || !hmac_set_ctx_params(macctx, params))
return 0;
if (key != NULL)
return hmac_setkey(macctx, key, keylen);
/* Just reinit the HMAC context */
return HMAC_Init_ex(macctx->ctx, NULL, 0, NULL, NULL);
}
static int hmac_update(void *vmacctx, const unsigned char *data,
size_t datalen)
{
struct hmac_data_st *macctx = vmacctx;
if (macctx->tls_data_size > 0) {
/* We're doing a TLS HMAC */
if (!macctx->tls_header_set) {
/* We expect the first update call to contain the TLS header */
if (datalen != sizeof(macctx->tls_header))
return 0;
memcpy(macctx->tls_header, data, datalen);
macctx->tls_header_set = 1;
return 1;
}
/* macctx->tls_data_size is datalen plus the padding length */
if (macctx->tls_data_size < datalen)
return 0;
return ssl3_cbc_digest_record(ossl_prov_digest_md(&macctx->digest),
macctx->tls_mac_out,
&macctx->tls_mac_out_size,
macctx->tls_header,
data,
datalen,
macctx->tls_data_size,
macctx->key,
macctx->keylen,
0);
}
return HMAC_Update(macctx->ctx, data, datalen);
}
static int hmac_final(void *vmacctx, unsigned char *out, size_t *outl,
size_t outsize)
{
unsigned int hlen;
struct hmac_data_st *macctx = vmacctx;
if (!ossl_prov_is_running())
return 0;
if (macctx->tls_data_size > 0) {
if (macctx->tls_mac_out_size == 0)
return 0;
if (outl != NULL)
*outl = macctx->tls_mac_out_size;
memcpy(out, macctx->tls_mac_out, macctx->tls_mac_out_size);
return 1;
}
if (!HMAC_Final(macctx->ctx, out, &hlen))
return 0;
*outl = hlen;
return 1;
}
static const OSSL_PARAM known_gettable_ctx_params[] = {
OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),
OSSL_PARAM_size_t(OSSL_MAC_PARAM_BLOCK_SIZE, NULL),
OSSL_PARAM_END
};
static const OSSL_PARAM *hmac_gettable_ctx_params(ossl_unused void *ctx,
ossl_unused void *provctx)
{
return known_gettable_ctx_params;
}
static int hmac_get_ctx_params(void *vmacctx, OSSL_PARAM params[])
{
struct hmac_data_st *macctx = vmacctx;
OSSL_PARAM *p;
if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL
&& !OSSL_PARAM_set_size_t(p, hmac_size(macctx)))
return 0;
if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_BLOCK_SIZE)) != NULL
&& !OSSL_PARAM_set_int(p, hmac_block_size(macctx)))
return 0;
return 1;
}
static const OSSL_PARAM known_settable_ctx_params[] = {
OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_DIGEST, NULL, 0),
OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_PROPERTIES, NULL, 0),
OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0),
OSSL_PARAM_int(OSSL_MAC_PARAM_DIGEST_NOINIT, NULL),
OSSL_PARAM_int(OSSL_MAC_PARAM_DIGEST_ONESHOT, NULL),
OSSL_PARAM_size_t(OSSL_MAC_PARAM_TLS_DATA_SIZE, NULL),
OSSL_PARAM_END
};
static const OSSL_PARAM *hmac_settable_ctx_params(ossl_unused void *ctx,
ossl_unused void *provctx)
{
return known_settable_ctx_params;
}
/*
* ALL parameters should be set before init().
*/
static int hmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[])
{
struct hmac_data_st *macctx = vmacctx;
OSSL_LIB_CTX *ctx = PROV_LIBCTX_OF(macctx->provctx);
const OSSL_PARAM *p;
if (params == NULL)
return 1;
if (!ossl_prov_digest_load_from_params(&macctx->digest, params, ctx))
return 0;
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) {
if (p->data_type != OSSL_PARAM_OCTET_STRING)
return 0;
if (!hmac_setkey(macctx, p->data, p->data_size))
return 0;
}
if ((p = OSSL_PARAM_locate_const(params,
OSSL_MAC_PARAM_TLS_DATA_SIZE)) != NULL) {
if (!OSSL_PARAM_get_size_t(p, &macctx->tls_data_size))
return 0;
}
return 1;
}
const OSSL_DISPATCH ossl_hmac_functions[] = {
{ OSSL_FUNC_MAC_NEWCTX, (void (*)(void))hmac_new },
{ OSSL_FUNC_MAC_DUPCTX, (void (*)(void))hmac_dup },
{ OSSL_FUNC_MAC_FREECTX, (void (*)(void))hmac_free },
{ OSSL_FUNC_MAC_INIT, (void (*)(void))hmac_init },
{ OSSL_FUNC_MAC_UPDATE, (void (*)(void))hmac_update },
{ OSSL_FUNC_MAC_FINAL, (void (*)(void))hmac_final },
{ OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS,
(void (*)(void))hmac_gettable_ctx_params },
{ OSSL_FUNC_MAC_GET_CTX_PARAMS, (void (*)(void))hmac_get_ctx_params },
{ OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS,
(void (*)(void))hmac_settable_ctx_params },
{ OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))hmac_set_ctx_params },
OSSL_DISPATCH_END
};
|
End of preview. Expand
in Dataset Viewer.
No dataset card yet
New: Create and edit this dataset card directly on the website!
Contribute a Dataset Card- Downloads last month
- 0