1235783Skib/* crypto/ecdh/ecdh_key.c */
2235783Skib/* ====================================================================
3235783Skib * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4235783Skib *
5235783Skib * The Elliptic Curve Public-Key Crypto Library (ECC Code) included
6235783Skib * herein is developed by SUN MICROSYSTEMS, INC., and is contributed
7235783Skib * to the OpenSSL project.
8235783Skib *
9235783Skib * The ECC Code is licensed pursuant to the OpenSSL open source
10235783Skib * license provided below.
11235783Skib *
12235783Skib * The ECDH software is originally written by Douglas Stebila of
13235783Skib * Sun Microsystems Laboratories.
14235783Skib *
15235783Skib */
16235783Skib/* ====================================================================
17235783Skib * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
18235783Skib *
19235783Skib * Redistribution and use in source and binary forms, with or without
20235783Skib * modification, are permitted provided that the following conditions
21235783Skib * are met:
22235783Skib *
23235783Skib * 1. Redistributions of source code must retain the above copyright
24235783Skib *    notice, this list of conditions and the following disclaimer.
25235783Skib *
26235783Skib * 2. Redistributions in binary form must reproduce the above copyright
27235783Skib *    notice, this list of conditions and the following disclaimer in
28235783Skib *    the documentation and/or other materials provided with the
29235783Skib *    distribution.
30235783Skib *
31235783Skib * 3. All advertising materials mentioning features or use of this
32235783Skib *    software must display the following acknowledgment:
33235783Skib *    "This product includes software developed by the OpenSSL Project
34235783Skib *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
35235783Skib *
36235783Skib * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
37235783Skib *    endorse or promote products derived from this software without
38235783Skib *    prior written permission. For written permission, please contact
39235783Skib *    openssl-core@OpenSSL.org.
40235783Skib *
41235783Skib * 5. Products derived from this software may not be called "OpenSSL"
42235783Skib *    nor may "OpenSSL" appear in their names without prior written
43235783Skib *    permission of the OpenSSL Project.
44235783Skib *
45235783Skib * 6. Redistributions of any form whatsoever must retain the following
46235783Skib *    acknowledgment:
47235783Skib *    "This product includes software developed by the OpenSSL Project
48235783Skib *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
49235783Skib *
50235783Skib * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
51235783Skib * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52235783Skib * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53235783Skib * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
54235783Skib * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55235783Skib * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56235783Skib * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
57235783Skib * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58235783Skib * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
59235783Skib * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60235783Skib * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
61235783Skib * OF THE POSSIBILITY OF SUCH DAMAGE.
62235783Skib * ====================================================================
63235783Skib *
64235783Skib * This product includes cryptographic software written by Eric Young
65235783Skib * (eay@cryptsoft.com).  This product includes software written by Tim
66235783Skib * Hudson (tjh@cryptsoft.com).
67235783Skib *
68235783Skib */
69235783Skib
70235783Skib#include "ech_locl.h"
71235783Skib
72235783Skibint ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
73235783Skib                     EC_KEY *eckey,
74235783Skib                     void *(*KDF) (const void *in, size_t inlen, void *out,
75235783Skib                                   size_t *outlen))
76235783Skib{
77235783Skib    ECDH_DATA *ecdh = ecdh_check(eckey);
78235783Skib    if (ecdh == NULL)
79235783Skib        return 0;
80235783Skib    return ecdh->meth->compute_key(out, outlen, pub_key, eckey, KDF);
81235783Skib}
82235783Skib