os/ossrv/ssl/libcrypto/src/crypto/engine/tb_rsa.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* ====================================================================
sl@0
     2
 * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
sl@0
     3
 *
sl@0
     4
 * Redistribution and use in source and binary forms, with or without
sl@0
     5
 * modification, are permitted provided that the following conditions
sl@0
     6
 * are met:
sl@0
     7
 *
sl@0
     8
 * 1. Redistributions of source code must retain the above copyright
sl@0
     9
 *    notice, this list of conditions and the following disclaimer. 
sl@0
    10
 *
sl@0
    11
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    12
 *    notice, this list of conditions and the following disclaimer in
sl@0
    13
 *    the documentation and/or other materials provided with the
sl@0
    14
 *    distribution.
sl@0
    15
 *
sl@0
    16
 * 3. All advertising materials mentioning features or use of this
sl@0
    17
 *    software must display the following acknowledgment:
sl@0
    18
 *    "This product includes software developed by the OpenSSL Project
sl@0
    19
 *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
sl@0
    20
 *
sl@0
    21
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
sl@0
    22
 *    endorse or promote products derived from this software without
sl@0
    23
 *    prior written permission. For written permission, please contact
sl@0
    24
 *    licensing@OpenSSL.org.
sl@0
    25
 *
sl@0
    26
 * 5. Products derived from this software may not be called "OpenSSL"
sl@0
    27
 *    nor may "OpenSSL" appear in their names without prior written
sl@0
    28
 *    permission of the OpenSSL Project.
sl@0
    29
 *
sl@0
    30
 * 6. Redistributions of any form whatsoever must retain the following
sl@0
    31
 *    acknowledgment:
sl@0
    32
 *    "This product includes software developed by the OpenSSL Project
sl@0
    33
 *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
sl@0
    34
 *
sl@0
    35
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
sl@0
    36
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sl@0
    37
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
sl@0
    38
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
sl@0
    39
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
sl@0
    40
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
sl@0
    41
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
sl@0
    42
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    43
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
sl@0
    44
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
sl@0
    45
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
sl@0
    46
 * OF THE POSSIBILITY OF SUCH DAMAGE.
sl@0
    47
 * ====================================================================
sl@0
    48
 *
sl@0
    49
 * This product includes cryptographic software written by Eric Young
sl@0
    50
 * (eay@cryptsoft.com).  This product includes software written by Tim
sl@0
    51
 * Hudson (tjh@cryptsoft.com).
sl@0
    52
 *
sl@0
    53
 */
sl@0
    54
 /*
sl@0
    55
 © Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
sl@0
    56
 */
sl@0
    57
sl@0
    58
sl@0
    59
#include "eng_int.h"
sl@0
    60
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
sl@0
    61
#include "libcrypto_wsd_macros.h"
sl@0
    62
#include "libcrypto_wsd.h"
sl@0
    63
#endif
sl@0
    64
/* If this symbol is defined then ENGINE_get_default_RSA(), the function that is
sl@0
    65
 * used by RSA to hook in implementation code and cache defaults (etc), will
sl@0
    66
 * display brief debugging summaries to stderr with the 'nid'. */
sl@0
    67
/* #define ENGINE_RSA_DEBUG */
sl@0
    68
#ifndef EMULATOR
sl@0
    69
static ENGINE_TABLE *rsa_table = NULL;
sl@0
    70
#else
sl@0
    71
GET_STATIC_VAR_FROM_TLS(rsa_table,tb_rsa,ENGINE_TABLE *)
sl@0
    72
#define rsa_table (*GET_WSD_VAR_NAME(rsa_table,tb_rsa, s)())
sl@0
    73
#endif
sl@0
    74
static const int dummy_nid = 1;
sl@0
    75
sl@0
    76
EXPORT_C void ENGINE_unregister_RSA(ENGINE *e)
sl@0
    77
	{
sl@0
    78
	engine_table_unregister(&rsa_table, e);
sl@0
    79
	}
sl@0
    80
sl@0
    81
static void engine_unregister_all_RSA(void)
sl@0
    82
	{
sl@0
    83
	engine_table_cleanup(&rsa_table);
sl@0
    84
	}
sl@0
    85
sl@0
    86
EXPORT_C int ENGINE_register_RSA(ENGINE *e)
sl@0
    87
	{
sl@0
    88
	if(e->rsa_meth)
sl@0
    89
		return engine_table_register(&rsa_table,
sl@0
    90
				engine_unregister_all_RSA, e, &dummy_nid, 1, 0);
sl@0
    91
	return 1;
sl@0
    92
	}
sl@0
    93
sl@0
    94
EXPORT_C void ENGINE_register_all_RSA()
sl@0
    95
	{
sl@0
    96
	ENGINE *e;
sl@0
    97
sl@0
    98
	for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
sl@0
    99
		ENGINE_register_RSA(e);
sl@0
   100
	}
sl@0
   101
sl@0
   102
EXPORT_C int ENGINE_set_default_RSA(ENGINE *e)
sl@0
   103
	{
sl@0
   104
	if(e->rsa_meth)
sl@0
   105
		return engine_table_register(&rsa_table,
sl@0
   106
				engine_unregister_all_RSA, e, &dummy_nid, 1, 1);
sl@0
   107
	return 1;
sl@0
   108
	}
sl@0
   109
sl@0
   110
/* Exposed API function to get a functional reference from the implementation
sl@0
   111
 * table (ie. try to get a functional reference from the tabled structural
sl@0
   112
 * references). */
sl@0
   113
EXPORT_C ENGINE *ENGINE_get_default_RSA(void)
sl@0
   114
	{
sl@0
   115
	return engine_table_select(&rsa_table, dummy_nid);
sl@0
   116
	}
sl@0
   117
sl@0
   118
/* Obtains an RSA implementation from an ENGINE functional reference */
sl@0
   119
EXPORT_C const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e)
sl@0
   120
	{
sl@0
   121
	return e->rsa_meth;
sl@0
   122
	}
sl@0
   123
sl@0
   124
/* Sets an RSA implementation in an ENGINE structure */
sl@0
   125
EXPORT_C int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth)
sl@0
   126
	{
sl@0
   127
	e->rsa_meth = rsa_meth;
sl@0
   128
	return 1;
sl@0
   129
	}