/* pmeth_fn.c */
-/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
/* ====================================================================
#include <stdio.h>
#include <stdlib.h>
-#include <openssl/objects.h>
#include "cryptlib.h"
+#include <openssl/objects.h>
#include <openssl/evp.h>
#include "evp_locl.h"
#define M_check_autoarg(ctx, arg, arglen, err) \
if (ctx->pmeth->flags & EVP_PKEY_FLAG_AUTOARGLEN) \
{ \
- int pksize = EVP_PKEY_size(ctx->pkey); \
+ size_t pksize = (size_t)EVP_PKEY_size(ctx->pkey); \
if (!arg) \
{ \
*arglen = pksize; \
} \
else if (*arglen < pksize) \
{ \
- EVPerr(err, EVP_R_BUFFER_TOO_SMALL); \
+ EVPerr(err, EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/\
return 0; \
} \
}
}
int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
- unsigned char *sig, int *siglen,
- const unsigned char *tbs, int tbslen)
+ unsigned char *sig, size_t *siglen,
+ const unsigned char *tbs, size_t tbslen)
{
if (!ctx || !ctx->pmeth || !ctx->pmeth->sign)
{
}
int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
- const unsigned char *sig, int siglen,
- const unsigned char *tbs, int tbslen)
+ const unsigned char *sig, size_t siglen,
+ const unsigned char *tbs, size_t tbslen)
{
if (!ctx || !ctx->pmeth || !ctx->pmeth->verify)
{
}
int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx,
- unsigned char *rout, int *routlen,
- const unsigned char *sig, int siglen)
+ unsigned char *rout, size_t *routlen,
+ const unsigned char *sig, size_t siglen)
{
if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover)
{
}
int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
- unsigned char *out, int *outlen,
- const unsigned char *in, int inlen)
+ unsigned char *out, size_t *outlen,
+ const unsigned char *in, size_t inlen)
{
if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt)
{
}
int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
- unsigned char *out, int *outlen,
- const unsigned char *in, int inlen)
+ unsigned char *out, size_t *outlen,
+ const unsigned char *in, size_t inlen)
{
if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt)
{
int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer)
{
int ret;
- if (!ctx || !ctx->pmeth || !ctx->pmeth->derive || !ctx->pmeth->ctrl)
+ if (!ctx || !ctx->pmeth || !(ctx->pmeth->derive||ctx->pmeth->encrypt||ctx->pmeth->decrypt) || !ctx->pmeth->ctrl)
{
EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER,
EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
return -2;
}
- if (ctx->operation != EVP_PKEY_OP_DERIVE)
+ if (ctx->operation != EVP_PKEY_OP_DERIVE && ctx->operation != EVP_PKEY_OP_ENCRYPT && ctx->operation != EVP_PKEY_OP_DECRYPT)
{
EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER,
EVP_R_OPERATON_NOT_INITIALIZED);
return -1;
}
+ /* ran@cryptocom.ru: For clarity. The error is if parameters in peer are
+ * present (!missing) but don't match. EVP_PKEY_cmp_parameters may return
+ * 1 (match), 0 (don't match) and -2 (comparison is not defined). -1
+ * (different key types) is impossible here because it is checked earlier.
+ * -2 is OK for us here, as well as 1, so we can check for 0 only. */
if (!EVP_PKEY_missing_parameters(peer) &&
!EVP_PKEY_cmp_parameters(ctx->pkey, peer))
{
return -1;
}
+ if (ctx->peerkey)
+ EVP_PKEY_free(ctx->peerkey);
ctx->peerkey = peer;
ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 1, peer);
}
-int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, int *pkeylen)
+int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen)
{
if (!ctx || !ctx->pmeth || !ctx->pmeth->derive)
{