10Sstevel@tonic-gate /* crypto/engine/eng_openssl.c */
20Sstevel@tonic-gate /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
30Sstevel@tonic-gate * project 2000.
40Sstevel@tonic-gate */
50Sstevel@tonic-gate /* ====================================================================
60Sstevel@tonic-gate * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
90Sstevel@tonic-gate * modification, are permitted provided that the following conditions
100Sstevel@tonic-gate * are met:
110Sstevel@tonic-gate *
120Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
130Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
140Sstevel@tonic-gate *
150Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
160Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in
170Sstevel@tonic-gate * the documentation and/or other materials provided with the
180Sstevel@tonic-gate * distribution.
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this
210Sstevel@tonic-gate * software must display the following acknowledgment:
220Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project
230Sstevel@tonic-gate * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
240Sstevel@tonic-gate *
250Sstevel@tonic-gate * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
260Sstevel@tonic-gate * endorse or promote products derived from this software without
270Sstevel@tonic-gate * prior written permission. For written permission, please contact
280Sstevel@tonic-gate * licensing@OpenSSL.org.
290Sstevel@tonic-gate *
300Sstevel@tonic-gate * 5. Products derived from this software may not be called "OpenSSL"
310Sstevel@tonic-gate * nor may "OpenSSL" appear in their names without prior written
320Sstevel@tonic-gate * permission of the OpenSSL Project.
330Sstevel@tonic-gate *
340Sstevel@tonic-gate * 6. Redistributions of any form whatsoever must retain the following
350Sstevel@tonic-gate * acknowledgment:
360Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project
370Sstevel@tonic-gate * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
380Sstevel@tonic-gate *
390Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
400Sstevel@tonic-gate * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
410Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
420Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
430Sstevel@tonic-gate * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
440Sstevel@tonic-gate * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
450Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
460Sstevel@tonic-gate * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
470Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
480Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
490Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
500Sstevel@tonic-gate * OF THE POSSIBILITY OF SUCH DAMAGE.
510Sstevel@tonic-gate * ====================================================================
520Sstevel@tonic-gate *
530Sstevel@tonic-gate * This product includes cryptographic software written by Eric Young
540Sstevel@tonic-gate * (eay@cryptsoft.com). This product includes software written by Tim
550Sstevel@tonic-gate * Hudson (tjh@cryptsoft.com).
560Sstevel@tonic-gate *
570Sstevel@tonic-gate */
58*2139Sjp161948 /* ====================================================================
59*2139Sjp161948 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60*2139Sjp161948 * ECDH support in OpenSSL originally developed by
61*2139Sjp161948 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62*2139Sjp161948 */
630Sstevel@tonic-gate
640Sstevel@tonic-gate
650Sstevel@tonic-gate #include <stdio.h>
660Sstevel@tonic-gate #include <openssl/crypto.h>
670Sstevel@tonic-gate #include "cryptlib.h"
680Sstevel@tonic-gate #include <openssl/engine.h>
690Sstevel@tonic-gate #include <openssl/dso.h>
700Sstevel@tonic-gate #include <openssl/pem.h>
710Sstevel@tonic-gate #include <openssl/evp.h>
72*2139Sjp161948 #include <openssl/rand.h>
73*2139Sjp161948 #ifndef OPENSSL_NO_RSA
74*2139Sjp161948 #include <openssl/rsa.h>
75*2139Sjp161948 #endif
76*2139Sjp161948 #ifndef OPENSSL_NO_DSA
77*2139Sjp161948 #include <openssl/dsa.h>
78*2139Sjp161948 #endif
79*2139Sjp161948 #ifndef OPENSSL_NO_DH
80*2139Sjp161948 #include <openssl/dh.h>
81*2139Sjp161948 #endif
820Sstevel@tonic-gate
830Sstevel@tonic-gate /* This testing gunk is implemented (and explained) lower down. It also assumes
840Sstevel@tonic-gate * the application explicitly calls "ENGINE_load_openssl()" because this is no
850Sstevel@tonic-gate * longer automatic in ENGINE_load_builtin_engines(). */
860Sstevel@tonic-gate #define TEST_ENG_OPENSSL_RC4
870Sstevel@tonic-gate #define TEST_ENG_OPENSSL_PKEY
880Sstevel@tonic-gate /* #define TEST_ENG_OPENSSL_RC4_OTHERS */
890Sstevel@tonic-gate #define TEST_ENG_OPENSSL_RC4_P_INIT
900Sstevel@tonic-gate /* #define TEST_ENG_OPENSSL_RC4_P_CIPHER */
910Sstevel@tonic-gate #define TEST_ENG_OPENSSL_SHA
920Sstevel@tonic-gate /* #define TEST_ENG_OPENSSL_SHA_OTHERS */
930Sstevel@tonic-gate /* #define TEST_ENG_OPENSSL_SHA_P_INIT */
940Sstevel@tonic-gate /* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */
950Sstevel@tonic-gate /* #define TEST_ENG_OPENSSL_SHA_P_FINAL */
960Sstevel@tonic-gate
970Sstevel@tonic-gate /* Now check what of those algorithms are actually enabled */
980Sstevel@tonic-gate #ifdef OPENSSL_NO_RC4
990Sstevel@tonic-gate #undef TEST_ENG_OPENSSL_RC4
1000Sstevel@tonic-gate #undef TEST_ENG_OPENSSL_RC4_OTHERS
1010Sstevel@tonic-gate #undef TEST_ENG_OPENSSL_RC4_P_INIT
1020Sstevel@tonic-gate #undef TEST_ENG_OPENSSL_RC4_P_CIPHER
1030Sstevel@tonic-gate #endif
1040Sstevel@tonic-gate #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA0) || defined(OPENSSL_NO_SHA1)
1050Sstevel@tonic-gate #undef TEST_ENG_OPENSSL_SHA
1060Sstevel@tonic-gate #undef TEST_ENG_OPENSSL_SHA_OTHERS
1070Sstevel@tonic-gate #undef TEST_ENG_OPENSSL_SHA_P_INIT
1080Sstevel@tonic-gate #undef TEST_ENG_OPENSSL_SHA_P_UPDATE
1090Sstevel@tonic-gate #undef TEST_ENG_OPENSSL_SHA_P_FINAL
1100Sstevel@tonic-gate #endif
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_RC4
1130Sstevel@tonic-gate static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
1140Sstevel@tonic-gate const int **nids, int nid);
1150Sstevel@tonic-gate #endif
1160Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_SHA
1170Sstevel@tonic-gate static int openssl_digests(ENGINE *e, const EVP_MD **digest,
1180Sstevel@tonic-gate const int **nids, int nid);
1190Sstevel@tonic-gate #endif
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_PKEY
1220Sstevel@tonic-gate static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
1230Sstevel@tonic-gate UI_METHOD *ui_method, void *callback_data);
1240Sstevel@tonic-gate #endif
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate /* The constants used when creating the ENGINE */
1270Sstevel@tonic-gate static const char *engine_openssl_id = "openssl";
1280Sstevel@tonic-gate static const char *engine_openssl_name = "Software engine support";
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /* This internal function is used by ENGINE_openssl() and possibly by the
1310Sstevel@tonic-gate * "dynamic" ENGINE support too */
bind_helper(ENGINE * e)1320Sstevel@tonic-gate static int bind_helper(ENGINE *e)
1330Sstevel@tonic-gate {
1340Sstevel@tonic-gate if(!ENGINE_set_id(e, engine_openssl_id)
1350Sstevel@tonic-gate || !ENGINE_set_name(e, engine_openssl_name)
1360Sstevel@tonic-gate #ifndef TEST_ENG_OPENSSL_NO_ALGORITHMS
1370Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
1380Sstevel@tonic-gate || !ENGINE_set_RSA(e, RSA_get_default_method())
1390Sstevel@tonic-gate #endif
1400Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
1410Sstevel@tonic-gate || !ENGINE_set_DSA(e, DSA_get_default_method())
1420Sstevel@tonic-gate #endif
143*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
144*2139Sjp161948 || !ENGINE_set_ECDH(e, ECDH_OpenSSL())
145*2139Sjp161948 #endif
146*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
147*2139Sjp161948 || !ENGINE_set_ECDSA(e, ECDSA_OpenSSL())
148*2139Sjp161948 #endif
1490Sstevel@tonic-gate #ifndef OPENSSL_NO_DH
1500Sstevel@tonic-gate || !ENGINE_set_DH(e, DH_get_default_method())
1510Sstevel@tonic-gate #endif
1520Sstevel@tonic-gate || !ENGINE_set_RAND(e, RAND_SSLeay())
1530Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_RC4
1540Sstevel@tonic-gate || !ENGINE_set_ciphers(e, openssl_ciphers)
1550Sstevel@tonic-gate #endif
1560Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_SHA
1570Sstevel@tonic-gate || !ENGINE_set_digests(e, openssl_digests)
1580Sstevel@tonic-gate #endif
1590Sstevel@tonic-gate #endif
1600Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_PKEY
1610Sstevel@tonic-gate || !ENGINE_set_load_privkey_function(e, openssl_load_privkey)
1620Sstevel@tonic-gate #endif
1630Sstevel@tonic-gate )
1640Sstevel@tonic-gate return 0;
1650Sstevel@tonic-gate /* If we add errors to this ENGINE, ensure the error handling is setup here */
1660Sstevel@tonic-gate /* openssl_load_error_strings(); */
1670Sstevel@tonic-gate return 1;
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate
engine_openssl(void)1700Sstevel@tonic-gate static ENGINE *engine_openssl(void)
1710Sstevel@tonic-gate {
1720Sstevel@tonic-gate ENGINE *ret = ENGINE_new();
1730Sstevel@tonic-gate if(!ret)
1740Sstevel@tonic-gate return NULL;
1750Sstevel@tonic-gate if(!bind_helper(ret))
1760Sstevel@tonic-gate {
1770Sstevel@tonic-gate ENGINE_free(ret);
1780Sstevel@tonic-gate return NULL;
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate return ret;
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate
ENGINE_load_openssl(void)1830Sstevel@tonic-gate void ENGINE_load_openssl(void)
1840Sstevel@tonic-gate {
1850Sstevel@tonic-gate ENGINE *toadd = engine_openssl();
1860Sstevel@tonic-gate if(!toadd) return;
1870Sstevel@tonic-gate ENGINE_add(toadd);
1880Sstevel@tonic-gate /* If the "add" worked, it gets a structural reference. So either way,
1890Sstevel@tonic-gate * we release our just-created reference. */
1900Sstevel@tonic-gate ENGINE_free(toadd);
1910Sstevel@tonic-gate ERR_clear_error();
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate /* This stuff is needed if this ENGINE is being compiled into a self-contained
1950Sstevel@tonic-gate * shared-library. */
1960Sstevel@tonic-gate #ifdef ENGINE_DYNAMIC_SUPPORT
bind_fn(ENGINE * e,const char * id)1970Sstevel@tonic-gate static int bind_fn(ENGINE *e, const char *id)
1980Sstevel@tonic-gate {
1990Sstevel@tonic-gate if(id && (strcmp(id, engine_openssl_id) != 0))
2000Sstevel@tonic-gate return 0;
2010Sstevel@tonic-gate if(!bind_helper(e))
2020Sstevel@tonic-gate return 0;
2030Sstevel@tonic-gate return 1;
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate IMPLEMENT_DYNAMIC_CHECK_FN()
2060Sstevel@tonic-gate IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
2070Sstevel@tonic-gate #endif /* ENGINE_DYNAMIC_SUPPORT */
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_RC4
2100Sstevel@tonic-gate /* This section of code compiles an "alternative implementation" of two modes of
2110Sstevel@tonic-gate * RC4 into this ENGINE. The result is that EVP_CIPHER operation for "rc4"
2120Sstevel@tonic-gate * should under normal circumstances go via this support rather than the default
2130Sstevel@tonic-gate * EVP support. There are other symbols to tweak the testing;
2140Sstevel@tonic-gate * TEST_ENC_OPENSSL_RC4_OTHERS - print a one line message to stderr each time
2150Sstevel@tonic-gate * we're asked for a cipher we don't support (should not happen).
2160Sstevel@tonic-gate * TEST_ENG_OPENSSL_RC4_P_INIT - print a one line message to stderr each time
2170Sstevel@tonic-gate * the "init_key" handler is called.
2180Sstevel@tonic-gate * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler.
2190Sstevel@tonic-gate */
2200Sstevel@tonic-gate #include <openssl/rc4.h>
2210Sstevel@tonic-gate #define TEST_RC4_KEY_SIZE 16
2220Sstevel@tonic-gate static int test_cipher_nids[] = {NID_rc4,NID_rc4_40};
2230Sstevel@tonic-gate static int test_cipher_nids_number = 2;
2240Sstevel@tonic-gate typedef struct {
2250Sstevel@tonic-gate unsigned char key[TEST_RC4_KEY_SIZE];
2260Sstevel@tonic-gate RC4_KEY ks;
2270Sstevel@tonic-gate } TEST_RC4_KEY;
2280Sstevel@tonic-gate #define test(ctx) ((TEST_RC4_KEY *)(ctx)->cipher_data)
test_rc4_init_key(EVP_CIPHER_CTX * ctx,const unsigned char * key,const unsigned char * iv,int enc)2290Sstevel@tonic-gate static int test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
2300Sstevel@tonic-gate const unsigned char *iv, int enc)
2310Sstevel@tonic-gate {
2320Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_RC4_P_INIT
2330Sstevel@tonic-gate fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n");
2340Sstevel@tonic-gate #endif
2350Sstevel@tonic-gate memcpy(&test(ctx)->key[0],key,EVP_CIPHER_CTX_key_length(ctx));
2360Sstevel@tonic-gate RC4_set_key(&test(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
2370Sstevel@tonic-gate test(ctx)->key);
2380Sstevel@tonic-gate return 1;
2390Sstevel@tonic-gate }
test_rc4_cipher(EVP_CIPHER_CTX * ctx,unsigned char * out,const unsigned char * in,unsigned int inl)2400Sstevel@tonic-gate static int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
2410Sstevel@tonic-gate const unsigned char *in, unsigned int inl)
2420Sstevel@tonic-gate {
2430Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER
2440Sstevel@tonic-gate fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n");
2450Sstevel@tonic-gate #endif
2460Sstevel@tonic-gate RC4(&test(ctx)->ks,inl,in,out);
2470Sstevel@tonic-gate return 1;
2480Sstevel@tonic-gate }
2490Sstevel@tonic-gate static const EVP_CIPHER test_r4_cipher=
2500Sstevel@tonic-gate {
2510Sstevel@tonic-gate NID_rc4,
2520Sstevel@tonic-gate 1,TEST_RC4_KEY_SIZE,0,
2530Sstevel@tonic-gate EVP_CIPH_VARIABLE_LENGTH,
2540Sstevel@tonic-gate test_rc4_init_key,
2550Sstevel@tonic-gate test_rc4_cipher,
2560Sstevel@tonic-gate NULL,
2570Sstevel@tonic-gate sizeof(TEST_RC4_KEY),
2580Sstevel@tonic-gate NULL,
2590Sstevel@tonic-gate NULL,
260*2139Sjp161948 NULL,
2610Sstevel@tonic-gate NULL
2620Sstevel@tonic-gate };
2630Sstevel@tonic-gate static const EVP_CIPHER test_r4_40_cipher=
2640Sstevel@tonic-gate {
2650Sstevel@tonic-gate NID_rc4_40,
2660Sstevel@tonic-gate 1,5 /* 40 bit */,0,
2670Sstevel@tonic-gate EVP_CIPH_VARIABLE_LENGTH,
2680Sstevel@tonic-gate test_rc4_init_key,
2690Sstevel@tonic-gate test_rc4_cipher,
2700Sstevel@tonic-gate NULL,
2710Sstevel@tonic-gate sizeof(TEST_RC4_KEY),
2720Sstevel@tonic-gate NULL,
2730Sstevel@tonic-gate NULL,
274*2139Sjp161948 NULL,
2750Sstevel@tonic-gate NULL
2760Sstevel@tonic-gate };
openssl_ciphers(ENGINE * e,const EVP_CIPHER ** cipher,const int ** nids,int nid)2770Sstevel@tonic-gate static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
2780Sstevel@tonic-gate const int **nids, int nid)
2790Sstevel@tonic-gate {
2800Sstevel@tonic-gate if(!cipher)
2810Sstevel@tonic-gate {
2820Sstevel@tonic-gate /* We are returning a list of supported nids */
2830Sstevel@tonic-gate *nids = test_cipher_nids;
2840Sstevel@tonic-gate return test_cipher_nids_number;
2850Sstevel@tonic-gate }
2860Sstevel@tonic-gate /* We are being asked for a specific cipher */
2870Sstevel@tonic-gate if(nid == NID_rc4)
2880Sstevel@tonic-gate *cipher = &test_r4_cipher;
2890Sstevel@tonic-gate else if(nid == NID_rc4_40)
2900Sstevel@tonic-gate *cipher = &test_r4_40_cipher;
2910Sstevel@tonic-gate else
2920Sstevel@tonic-gate {
2930Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_RC4_OTHERS
2940Sstevel@tonic-gate fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) returning NULL for "
2950Sstevel@tonic-gate "nid %d\n", nid);
2960Sstevel@tonic-gate #endif
2970Sstevel@tonic-gate *cipher = NULL;
2980Sstevel@tonic-gate return 0;
2990Sstevel@tonic-gate }
3000Sstevel@tonic-gate return 1;
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate #endif
3030Sstevel@tonic-gate
3040Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_SHA
3050Sstevel@tonic-gate /* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */
3060Sstevel@tonic-gate #include <openssl/sha.h>
3070Sstevel@tonic-gate static int test_digest_nids[] = {NID_sha1};
3080Sstevel@tonic-gate static int test_digest_nids_number = 1;
test_sha1_init(EVP_MD_CTX * ctx)3090Sstevel@tonic-gate static int test_sha1_init(EVP_MD_CTX *ctx)
3100Sstevel@tonic-gate {
3110Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_SHA_P_INIT
3120Sstevel@tonic-gate fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_init() called\n");
3130Sstevel@tonic-gate #endif
3140Sstevel@tonic-gate return SHA1_Init(ctx->md_data);
3150Sstevel@tonic-gate }
test_sha1_update(EVP_MD_CTX * ctx,const void * data,size_t count)316*2139Sjp161948 static int test_sha1_update(EVP_MD_CTX *ctx,const void *data,size_t count)
3170Sstevel@tonic-gate {
3180Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE
3190Sstevel@tonic-gate fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n");
3200Sstevel@tonic-gate #endif
3210Sstevel@tonic-gate return SHA1_Update(ctx->md_data,data,count);
3220Sstevel@tonic-gate }
test_sha1_final(EVP_MD_CTX * ctx,unsigned char * md)3230Sstevel@tonic-gate static int test_sha1_final(EVP_MD_CTX *ctx,unsigned char *md)
3240Sstevel@tonic-gate {
3250Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_SHA_P_FINAL
3260Sstevel@tonic-gate fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_final() called\n");
3270Sstevel@tonic-gate #endif
3280Sstevel@tonic-gate return SHA1_Final(md,ctx->md_data);
3290Sstevel@tonic-gate }
3300Sstevel@tonic-gate static const EVP_MD test_sha_md=
3310Sstevel@tonic-gate {
3320Sstevel@tonic-gate NID_sha1,
3330Sstevel@tonic-gate NID_sha1WithRSAEncryption,
3340Sstevel@tonic-gate SHA_DIGEST_LENGTH,
3350Sstevel@tonic-gate 0,
3360Sstevel@tonic-gate test_sha1_init,
3370Sstevel@tonic-gate test_sha1_update,
3380Sstevel@tonic-gate test_sha1_final,
3390Sstevel@tonic-gate NULL,
3400Sstevel@tonic-gate NULL,
3410Sstevel@tonic-gate EVP_PKEY_RSA_method,
3420Sstevel@tonic-gate SHA_CBLOCK,
3430Sstevel@tonic-gate sizeof(EVP_MD *)+sizeof(SHA_CTX),
3440Sstevel@tonic-gate };
openssl_digests(ENGINE * e,const EVP_MD ** digest,const int ** nids,int nid)3450Sstevel@tonic-gate static int openssl_digests(ENGINE *e, const EVP_MD **digest,
3460Sstevel@tonic-gate const int **nids, int nid)
3470Sstevel@tonic-gate {
3480Sstevel@tonic-gate if(!digest)
3490Sstevel@tonic-gate {
3500Sstevel@tonic-gate /* We are returning a list of supported nids */
3510Sstevel@tonic-gate *nids = test_digest_nids;
3520Sstevel@tonic-gate return test_digest_nids_number;
3530Sstevel@tonic-gate }
3540Sstevel@tonic-gate /* We are being asked for a specific digest */
3550Sstevel@tonic-gate if(nid == NID_sha1)
3560Sstevel@tonic-gate *digest = &test_sha_md;
3570Sstevel@tonic-gate else
3580Sstevel@tonic-gate {
3590Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_SHA_OTHERS
3600Sstevel@tonic-gate fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) returning NULL for "
3610Sstevel@tonic-gate "nid %d\n", nid);
3620Sstevel@tonic-gate #endif
3630Sstevel@tonic-gate *digest = NULL;
3640Sstevel@tonic-gate return 0;
3650Sstevel@tonic-gate }
3660Sstevel@tonic-gate return 1;
3670Sstevel@tonic-gate }
3680Sstevel@tonic-gate #endif
3690Sstevel@tonic-gate
3700Sstevel@tonic-gate #ifdef TEST_ENG_OPENSSL_PKEY
openssl_load_privkey(ENGINE * eng,const char * key_id,UI_METHOD * ui_method,void * callback_data)3710Sstevel@tonic-gate static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
3720Sstevel@tonic-gate UI_METHOD *ui_method, void *callback_data)
3730Sstevel@tonic-gate {
3740Sstevel@tonic-gate BIO *in;
3750Sstevel@tonic-gate EVP_PKEY *key;
3760Sstevel@tonic-gate fprintf(stderr, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n", key_id);
3770Sstevel@tonic-gate in = BIO_new_file(key_id, "r");
3780Sstevel@tonic-gate if (!in)
3790Sstevel@tonic-gate return NULL;
3800Sstevel@tonic-gate key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL);
3810Sstevel@tonic-gate BIO_free(in);
3820Sstevel@tonic-gate return key;
3830Sstevel@tonic-gate }
3840Sstevel@tonic-gate #endif
385