Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • a94f8cb
  • /
  • crypto
  • /
  • evp
  • /
  • evp_utils.c
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:77622616b3bd54b5412481b25eb3897096cfd55f
directory badge Iframe embedding
swh:1:dir:48b1746cf92e6cc944b2cce6977b33917aae70c5
evp_utils.c
/*
 * Copyright 2019 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
 */

/* Internal EVP utility functions */

#include <openssl/core.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/asn1.h>        /* evp_local.h needs it */
#include <openssl/safestack.h>   /* evp_local.h needs it */
#include "crypto/evp.h"    /* evp_local.h needs it */
#include "evp_local.h"

/*
 * EVP_CTRL_RET_UNSUPPORTED = -1 is the returned value from any ctrl function
 * where the control command isn't supported, and an alternative code path
 * may be chosen.
 * Since these functions are used to implement ctrl functionality, we
 * use the same value, and other callers will have to compensate.
 */
#define PARAM_CHECK(obj, func, errfunc)                                        \
    if (obj == NULL)                                                           \
        return 0;                                                              \
    if (obj->prov == NULL)                                                     \
        return EVP_CTRL_RET_UNSUPPORTED;                                       \
    if (obj->func == NULL) {                                                   \
        errfunc();                                                             \
        return 0;                                                              \
    }

#define PARAM_FUNC(name, func, type, err)                                      \
int name (const type *obj, OSSL_PARAM params[])                                \
{                                                                              \
    PARAM_CHECK(obj, func, err)                                                \
    return obj->func(params);                                                  \
}

#define PARAM_CTX_FUNC(name, func, type, err)                                  \
int name (const type *obj, void *provctx, OSSL_PARAM params[])                 \
{                                                                              \
    PARAM_CHECK(obj, func, err)                                                \
    return obj->func(provctx, params);                                         \
}

#define PARAM_FUNCTIONS(type,                                                  \
                        getname, getfunc,                                      \
                        getctxname, getctxfunc,                                \
                        setctxname, setctxfunc)                                \
    PARAM_FUNC(getname, getfunc, type, geterr)                                 \
    PARAM_CTX_FUNC(getctxname, getctxfunc, type, geterr)                       \
    PARAM_CTX_FUNC(setctxname, setctxfunc, type, seterr)

/*
 * These error functions are a workaround for the error scripts, which
 * currently require that XXXerr method appears inside a function (not a macro).
 */
static void geterr(void)
{
    EVPerr(0, EVP_R_CANNOT_GET_PARAMETERS);
}

static void seterr(void)
{
    EVPerr(0, EVP_R_CANNOT_SET_PARAMETERS);
}

PARAM_FUNCTIONS(EVP_CIPHER,
                evp_do_ciph_getparams, get_params,
                evp_do_ciph_ctx_getparams, get_ctx_params,
                evp_do_ciph_ctx_setparams, set_ctx_params)

PARAM_FUNCTIONS(EVP_MD,
                evp_do_md_getparams, get_params,
                evp_do_md_ctx_getparams, get_ctx_params,
                evp_do_md_ctx_setparams, set_ctx_params)

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top