1 /* fips/ecdsa/fips_ecdsa_selftest.c */
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2011 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
55 #define OPENSSL_FIPSAPI
58 #include <openssl/crypto.h>
59 #include <openssl/ec.h>
60 #include <openssl/ecdsa.h>
61 #include <openssl/fips.h>
62 #include <openssl/err.h>
63 #include <openssl/evp.h>
64 #include <openssl/bn.h>
68 static const char P_224_name[] = "ECDSA P-224";
70 static const unsigned char P_224_d[] = {
71 0x98,0x1f,0xb5,0xf1,0xfc,0x87,0x1d,0x7d,0xde,0x1e,0x01,0x64,
72 0x09,0x9b,0xe7,0x1b,0x9f,0xad,0x63,0xdd,0x33,0x01,0xd1,0x50,
75 static const unsigned char P_224_qx[] = {
76 0x95,0x47,0x99,0x44,0x29,0x8f,0x51,0x39,0xe2,0x53,0xec,0x79,
77 0xb0,0x4d,0xde,0x87,0x1a,0x76,0x54,0xd5,0x96,0xb8,0x7a,0x6d,
80 static const unsigned char P_224_qy[] = {
81 0x91,0x5f,0xd5,0x31,0xdd,0x24,0xe5,0x78,0xd9,0x08,0x24,0x8a,
82 0x49,0x99,0xec,0x55,0xf2,0x82,0xb3,0xc4,0xb7,0x33,0x68,0xe4,
86 #ifndef OPENSSL_NO_EC2M
88 static const char K_233_name[] = "ECDSA K-233";
90 static const unsigned char K_233_d[] = {
91 0x10,0x0a,0xe0,0xae,0xcf,0x1b,0xa4,0x55,0x1a,0xd4,0xc8,0x3f,
92 0xc3,0x7e,0xdc,0x97,0x40,0x2c,0x6a,0xc8,0xe2,0x50,0x09,0xf8,
93 0x1c,0x70,0x23,0xcb,0xde
95 static const unsigned char K_233_qx[] = {
96 0x01,0xa6,0xbf,0x38,0x32,0xe2,0xd7,0x15,0x4a,0xc8,0xaa,0x1f,
97 0x9d,0xdb,0xb8,0x8f,0x9a,0x9b,0xc0,0xb4,0xc1,0xb6,0xa5,0x5c,
98 0x93,0xb9,0x8a,0x83,0x65,0xe9
100 static const unsigned char K_233_qy[] = {
101 0x01,0x81,0x3d,0xfe,0x38,0x56,0x8f,0x3c,0x23,0x29,0xc6,0x59,
102 0xcb,0xa5,0x90,0x86,0xd1,0x8c,0xd8,0xb0,0xf2,0xd4,0x35,0x2b,
103 0x11,0x40,0x33,0x9a,0x88,0x10
112 const unsigned char *x;
114 const unsigned char *y;
116 const unsigned char *d;
120 #define make_ecdsa_test(nid, pr) { nid, pr##_name, \
121 pr##_qx, sizeof(pr##_qx), \
122 pr##_qy, sizeof(pr##_qy), \
123 pr##_d, sizeof(pr##_d)}
125 static EC_SELFTEST_DATA test_ec_data[] =
127 make_ecdsa_test(NID_secp224r1, P_224),
128 #ifndef OPENSSL_NO_EC2M
129 make_ecdsa_test(NID_sect233k1, K_233)
133 int FIPS_selftest_ecdsa()
136 BIGNUM *x = NULL, *y = NULL, *d = NULL;
141 for (i = 0; i < sizeof(test_ec_data)/sizeof(EC_SELFTEST_DATA); i++)
143 EC_SELFTEST_DATA *ecd = test_ec_data + i;
145 x = BN_bin2bn(ecd->x, ecd->xlen, x);
146 y = BN_bin2bn(ecd->y, ecd->ylen, y);
147 d = BN_bin2bn(ecd->d, ecd->dlen, d);
152 ec = EC_KEY_new_by_curve_name(ecd->curve);
156 if (!EC_KEY_set_public_key_affine_coordinates(ec, x, y))
159 if (!EC_KEY_set_private_key(ec, d))
162 pk.type = EVP_PKEY_EC;
165 if (!fips_pkey_signature_test(FIPS_TEST_SIGNATURE, &pk, NULL, 0,
166 NULL, 0, EVP_sha512(), 0,