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