2 /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
61 #include <openssl/objects.h>
63 #include <openssl/evp.h>
66 int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
69 if (!ctx || !ctx->pmeth || !ctx->pmeth->sign_init)
71 EVPerr(EVP_F_EVP_PKEY_SIGN_INIT,
72 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
75 ctx->operation = EVP_PKEY_OP_SIGN;
76 ret = ctx->pmeth->sign_init(ctx, pkey);
78 ctx->operation = EVP_PKEY_OP_UNDEFINED;
82 int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
83 unsigned char *sig, int *siglen,
84 unsigned char *tbs, int tbslen)
86 if (!ctx || !ctx->pmeth || !ctx->pmeth->sign)
88 EVPerr(EVP_F_EVP_PKEY_SIGN,
89 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
92 if (ctx->operation != EVP_PKEY_OP_SIGN)
94 EVPerr(EVP_F_EVP_PKEY_SIGN, EVP_R_OPERATON_NOT_INITIALIZED);
97 return ctx->pmeth->sign(ctx, sig, siglen, tbs, tbslen);
100 int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
103 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_init)
105 EVPerr(EVP_F_EVP_PKEY_VERIFY_INIT,
106 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
109 ctx->operation = EVP_PKEY_OP_VERIFY;
110 ret = ctx->pmeth->verify_init(ctx, pkey);
112 ctx->operation = EVP_PKEY_OP_UNDEFINED;
116 int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
117 unsigned char *sig, int siglen,
118 unsigned char *tbs, int tbslen)
120 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify)
122 EVPerr(EVP_F_EVP_PKEY_VERIFY,
123 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
126 if (ctx->operation != EVP_PKEY_OP_VERIFY)
128 EVPerr(EVP_F_EVP_PKEY_VERIFY, EVP_R_OPERATON_NOT_INITIALIZED);
131 return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen);
134 int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
137 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover_init)
139 EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT,
140 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
143 ctx->operation = EVP_PKEY_OP_VERIFYRECOVER;
144 ret = ctx->pmeth->verify_recover_init(ctx, pkey);
146 ctx->operation = EVP_PKEY_OP_UNDEFINED;
150 int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx,
151 unsigned char *rout, int *routlen,
152 unsigned char *sig, int siglen)
154 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover)
156 EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER,
157 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
160 if (ctx->operation != EVP_PKEY_OP_VERIFYRECOVER)
162 EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, EVP_R_OPERATON_NOT_INITIALIZED);
165 return ctx->pmeth->verify_recover(ctx, rout, routlen, sig, siglen);
168 int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
171 if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt_init)
173 EVPerr(EVP_F_EVP_PKEY_ENCRYPT_INIT,
174 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
177 ctx->operation = EVP_PKEY_OP_ENCRYPT;
178 ret = ctx->pmeth->encrypt_init(ctx, pkey);
180 ctx->operation = EVP_PKEY_OP_UNDEFINED;
184 int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
185 unsigned char *out, int *outlen,
186 unsigned char *in, int inlen)
188 if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt)
190 EVPerr(EVP_F_EVP_PKEY_ENCRYPT,
191 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
194 if (ctx->operation != EVP_PKEY_OP_ENCRYPT)
196 EVPerr(EVP_F_EVP_PKEY_ENCRYPT, EVP_R_OPERATON_NOT_INITIALIZED);
199 return ctx->pmeth->encrypt(ctx, out, outlen, in, inlen);
202 int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
205 if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt_init)
207 EVPerr(EVP_F_EVP_PKEY_DECRYPT_INIT,
208 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
211 ctx->operation = EVP_PKEY_OP_DECRYPT;
212 ret = ctx->pmeth->decrypt_init(ctx, pkey);
214 ctx->operation = EVP_PKEY_OP_UNDEFINED;
218 int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
219 unsigned char *out, int *outlen,
220 unsigned char *in, int inlen)
222 if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt)
224 EVPerr(EVP_F_EVP_PKEY_DECRYPT,
225 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
228 if (ctx->operation != EVP_PKEY_OP_DECRYPT)
230 EVPerr(EVP_F_EVP_PKEY_DECRYPT, EVP_R_OPERATON_NOT_INITIALIZED);
233 return ctx->pmeth->decrypt(ctx, out, outlen, in, inlen);