86d45af5fa42da0365f0e07b9f58b4af14b5ed5b
[openssl.git] / test / ecdhtest.c
1 /*
2  * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 /* ====================================================================
11  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
12  *
13  * The Elliptic Curve Public-Key Crypto Library (ECC Code) included
14  * herein is developed by SUN MICROSYSTEMS, INC., and is contributed
15  * to the OpenSSL project.
16  *
17  * The ECC Code is licensed pursuant to the OpenSSL open source
18  * license provided below.
19  *
20  * The ECDH software is originally written by Douglas Stebila of
21  * Sun Microsystems Laboratories.
22  *
23  */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "../e_os.h"
30
31 #include <openssl/opensslconf.h> /* for OPENSSL_NO_EC */
32 #include <openssl/crypto.h>
33 #include <openssl/bio.h>
34 #include <openssl/bn.h>
35 #include <openssl/objects.h>
36 #include <openssl/rand.h>
37 #include <openssl/sha.h>
38 #include <openssl/err.h>
39
40 #ifdef OPENSSL_NO_EC
41 int main(int argc, char *argv[])
42 {
43     printf("No ECDH support\n");
44     return (0);
45 }
46 #else
47 # include <openssl/ec.h>
48
49 static const char rnd_seed[] =
50     "string to make the random number generator think it has entropy";
51
52 int main(int argc, char *argv[])
53 {
54     int ret = 1;
55     BIO *out;
56
57     CRYPTO_set_mem_debug(1);
58     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
59
60     RAND_seed(rnd_seed, sizeof rnd_seed);
61
62     out = BIO_new(BIO_s_file());
63     if (out == NULL)
64         EXIT(1);
65     BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT);
66
67     /* NAMED CURVES TESTS: moved to evptests.txt */
68
69     /* KATs: moved to evptests.txt  */
70
71     /* NIST SP800-56A co-factor ECDH KATs: moved to evptests.txt */
72
73     ret = 0;
74
75  err:
76     ERR_print_errors_fp(stderr);
77     BIO_free(out);
78
79 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
80     if (CRYPTO_mem_leaks_fp(stderr) <= 0)
81         ret = 1;
82 #endif
83     EXIT(ret);
84 }
85 #endif