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
)
69 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->sign
)
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 if (!ctx
->pmeth
->sign_init
)
78 ret
= ctx
->pmeth
->sign_init(ctx
);
80 ctx
->operation
= EVP_PKEY_OP_UNDEFINED
;
84 int EVP_PKEY_sign(EVP_PKEY_CTX
*ctx
,
85 unsigned char *sig
, int *siglen
,
86 unsigned char *tbs
, int tbslen
)
88 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->sign
)
90 EVPerr(EVP_F_EVP_PKEY_SIGN
,
91 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
94 if (ctx
->operation
!= EVP_PKEY_OP_SIGN
)
96 EVPerr(EVP_F_EVP_PKEY_SIGN
, EVP_R_OPERATON_NOT_INITIALIZED
);
99 return ctx
->pmeth
->sign(ctx
, sig
, siglen
, tbs
, tbslen
);
102 int EVP_PKEY_verify_init(EVP_PKEY_CTX
*ctx
)
105 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->verify
)
107 EVPerr(EVP_F_EVP_PKEY_VERIFY_INIT
,
108 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
111 ctx
->operation
= EVP_PKEY_OP_VERIFY
;
112 if (!ctx
->pmeth
->verify_init
)
114 ret
= ctx
->pmeth
->verify_init(ctx
);
116 ctx
->operation
= EVP_PKEY_OP_UNDEFINED
;
120 int EVP_PKEY_verify(EVP_PKEY_CTX
*ctx
,
121 unsigned char *sig
, int siglen
,
122 unsigned char *tbs
, int tbslen
)
124 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->verify
)
126 EVPerr(EVP_F_EVP_PKEY_VERIFY
,
127 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
130 if (ctx
->operation
!= EVP_PKEY_OP_VERIFY
)
132 EVPerr(EVP_F_EVP_PKEY_VERIFY
, EVP_R_OPERATON_NOT_INITIALIZED
);
135 return ctx
->pmeth
->verify(ctx
, sig
, siglen
, tbs
, tbslen
);
138 int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX
*ctx
)
141 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->verify_recover
)
143 EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT
,
144 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
147 ctx
->operation
= EVP_PKEY_OP_VERIFYRECOVER
;
148 if (!ctx
->pmeth
->verify_recover_init
)
150 ret
= ctx
->pmeth
->verify_recover_init(ctx
);
152 ctx
->operation
= EVP_PKEY_OP_UNDEFINED
;
156 int EVP_PKEY_verify_recover(EVP_PKEY_CTX
*ctx
,
157 unsigned char *rout
, int *routlen
,
158 unsigned char *sig
, int siglen
)
160 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->verify_recover
)
162 EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER
,
163 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
166 if (ctx
->operation
!= EVP_PKEY_OP_VERIFYRECOVER
)
168 EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER
, EVP_R_OPERATON_NOT_INITIALIZED
);
171 return ctx
->pmeth
->verify_recover(ctx
, rout
, routlen
, sig
, siglen
);
174 int EVP_PKEY_encrypt_init(EVP_PKEY_CTX
*ctx
)
177 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->encrypt
)
179 EVPerr(EVP_F_EVP_PKEY_ENCRYPT_INIT
,
180 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
183 ctx
->operation
= EVP_PKEY_OP_ENCRYPT
;
184 if (!ctx
->pmeth
->encrypt_init
)
186 ret
= ctx
->pmeth
->encrypt_init(ctx
);
188 ctx
->operation
= EVP_PKEY_OP_UNDEFINED
;
192 int EVP_PKEY_encrypt(EVP_PKEY_CTX
*ctx
,
193 unsigned char *out
, int *outlen
,
194 unsigned char *in
, int inlen
)
196 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->encrypt
)
198 EVPerr(EVP_F_EVP_PKEY_ENCRYPT
,
199 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
202 if (ctx
->operation
!= EVP_PKEY_OP_ENCRYPT
)
204 EVPerr(EVP_F_EVP_PKEY_ENCRYPT
, EVP_R_OPERATON_NOT_INITIALIZED
);
207 return ctx
->pmeth
->encrypt(ctx
, out
, outlen
, in
, inlen
);
210 int EVP_PKEY_decrypt_init(EVP_PKEY_CTX
*ctx
)
213 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->decrypt
)
215 EVPerr(EVP_F_EVP_PKEY_DECRYPT_INIT
,
216 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
219 ctx
->operation
= EVP_PKEY_OP_DECRYPT
;
220 if (!ctx
->pmeth
->decrypt_init
)
222 ret
= ctx
->pmeth
->decrypt_init(ctx
);
224 ctx
->operation
= EVP_PKEY_OP_UNDEFINED
;
228 int EVP_PKEY_decrypt(EVP_PKEY_CTX
*ctx
,
229 unsigned char *out
, int *outlen
,
230 unsigned char *in
, int inlen
)
232 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->decrypt
)
234 EVPerr(EVP_F_EVP_PKEY_DECRYPT
,
235 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
238 if (ctx
->operation
!= EVP_PKEY_OP_DECRYPT
)
240 EVPerr(EVP_F_EVP_PKEY_DECRYPT
, EVP_R_OPERATON_NOT_INITIALIZED
);
243 return ctx
->pmeth
->decrypt(ctx
, out
, outlen
, in
, inlen
);