mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /*
mbedAustin 11:cada08fc8a70 2 * Elliptic curves over GF(p): curve-specific data and functions
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 5 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 6 *
mbedAustin 11:cada08fc8a70 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 8 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 9 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 10 *
mbedAustin 11:cada08fc8a70 11 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 16 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 17 * limitations under the License.
mbedAustin 11:cada08fc8a70 18 *
mbedAustin 11:cada08fc8a70 19 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 20 */
mbedAustin 11:cada08fc8a70 21
mbedAustin 11:cada08fc8a70 22 #if !defined(MBEDTLS_CONFIG_FILE)
mbedAustin 11:cada08fc8a70 23 #include "mbedtls/config.h"
mbedAustin 11:cada08fc8a70 24 #else
mbedAustin 11:cada08fc8a70 25 #include MBEDTLS_CONFIG_FILE
mbedAustin 11:cada08fc8a70 26 #endif
mbedAustin 11:cada08fc8a70 27
mbedAustin 11:cada08fc8a70 28 #if defined(MBEDTLS_ECP_C)
mbedAustin 11:cada08fc8a70 29
mbedAustin 11:cada08fc8a70 30 #include "mbedtls/ecp.h"
mbedAustin 11:cada08fc8a70 31
mbedAustin 11:cada08fc8a70 32 #include <string.h>
mbedAustin 11:cada08fc8a70 33
mbedAustin 11:cada08fc8a70 34 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
mbedAustin 11:cada08fc8a70 35 !defined(inline) && !defined(__cplusplus)
mbedAustin 11:cada08fc8a70 36 #define inline __inline
mbedAustin 11:cada08fc8a70 37 #endif
mbedAustin 11:cada08fc8a70 38
mbedAustin 11:cada08fc8a70 39 /*
mbedAustin 11:cada08fc8a70 40 * Conversion macros for embedded constants:
mbedAustin 11:cada08fc8a70 41 * build lists of mbedtls_mpi_uint's from lists of unsigned char's grouped by 8, 4 or 2
mbedAustin 11:cada08fc8a70 42 */
mbedAustin 11:cada08fc8a70 43 #if defined(MBEDTLS_HAVE_INT32)
mbedAustin 11:cada08fc8a70 44
mbedAustin 11:cada08fc8a70 45 #define BYTES_TO_T_UINT_4( a, b, c, d ) \
mbedAustin 11:cada08fc8a70 46 ( (mbedtls_mpi_uint) a << 0 ) | \
mbedAustin 11:cada08fc8a70 47 ( (mbedtls_mpi_uint) b << 8 ) | \
mbedAustin 11:cada08fc8a70 48 ( (mbedtls_mpi_uint) c << 16 ) | \
mbedAustin 11:cada08fc8a70 49 ( (mbedtls_mpi_uint) d << 24 )
mbedAustin 11:cada08fc8a70 50
mbedAustin 11:cada08fc8a70 51 #define BYTES_TO_T_UINT_2( a, b ) \
mbedAustin 11:cada08fc8a70 52 BYTES_TO_T_UINT_4( a, b, 0, 0 )
mbedAustin 11:cada08fc8a70 53
mbedAustin 11:cada08fc8a70 54 #define BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \
mbedAustin 11:cada08fc8a70 55 BYTES_TO_T_UINT_4( a, b, c, d ), \
mbedAustin 11:cada08fc8a70 56 BYTES_TO_T_UINT_4( e, f, g, h )
mbedAustin 11:cada08fc8a70 57
mbedAustin 11:cada08fc8a70 58 #else /* 64-bits */
mbedAustin 11:cada08fc8a70 59
mbedAustin 11:cada08fc8a70 60 #define BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \
mbedAustin 11:cada08fc8a70 61 ( (mbedtls_mpi_uint) a << 0 ) | \
mbedAustin 11:cada08fc8a70 62 ( (mbedtls_mpi_uint) b << 8 ) | \
mbedAustin 11:cada08fc8a70 63 ( (mbedtls_mpi_uint) c << 16 ) | \
mbedAustin 11:cada08fc8a70 64 ( (mbedtls_mpi_uint) d << 24 ) | \
mbedAustin 11:cada08fc8a70 65 ( (mbedtls_mpi_uint) e << 32 ) | \
mbedAustin 11:cada08fc8a70 66 ( (mbedtls_mpi_uint) f << 40 ) | \
mbedAustin 11:cada08fc8a70 67 ( (mbedtls_mpi_uint) g << 48 ) | \
mbedAustin 11:cada08fc8a70 68 ( (mbedtls_mpi_uint) h << 56 )
mbedAustin 11:cada08fc8a70 69
mbedAustin 11:cada08fc8a70 70 #define BYTES_TO_T_UINT_4( a, b, c, d ) \
mbedAustin 11:cada08fc8a70 71 BYTES_TO_T_UINT_8( a, b, c, d, 0, 0, 0, 0 )
mbedAustin 11:cada08fc8a70 72
mbedAustin 11:cada08fc8a70 73 #define BYTES_TO_T_UINT_2( a, b ) \
mbedAustin 11:cada08fc8a70 74 BYTES_TO_T_UINT_8( a, b, 0, 0, 0, 0, 0, 0 )
mbedAustin 11:cada08fc8a70 75
mbedAustin 11:cada08fc8a70 76 #endif /* bits in mbedtls_mpi_uint */
mbedAustin 11:cada08fc8a70 77
mbedAustin 11:cada08fc8a70 78 /*
mbedAustin 11:cada08fc8a70 79 * Note: the constants are in little-endian order
mbedAustin 11:cada08fc8a70 80 * to be directly usable in MPIs
mbedAustin 11:cada08fc8a70 81 */
mbedAustin 11:cada08fc8a70 82
mbedAustin 11:cada08fc8a70 83 /*
mbedAustin 11:cada08fc8a70 84 * Domain parameters for secp192r1
mbedAustin 11:cada08fc8a70 85 */
mbedAustin 11:cada08fc8a70 86 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
mbedAustin 11:cada08fc8a70 87 static const mbedtls_mpi_uint secp192r1_p[] = {
mbedAustin 11:cada08fc8a70 88 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 89 BYTES_TO_T_UINT_8( 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 90 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 91 };
mbedAustin 11:cada08fc8a70 92 static const mbedtls_mpi_uint secp192r1_b[] = {
mbedAustin 11:cada08fc8a70 93 BYTES_TO_T_UINT_8( 0xB1, 0xB9, 0x46, 0xC1, 0xEC, 0xDE, 0xB8, 0xFE ),
mbedAustin 11:cada08fc8a70 94 BYTES_TO_T_UINT_8( 0x49, 0x30, 0x24, 0x72, 0xAB, 0xE9, 0xA7, 0x0F ),
mbedAustin 11:cada08fc8a70 95 BYTES_TO_T_UINT_8( 0xE7, 0x80, 0x9C, 0xE5, 0x19, 0x05, 0x21, 0x64 ),
mbedAustin 11:cada08fc8a70 96 };
mbedAustin 11:cada08fc8a70 97 static const mbedtls_mpi_uint secp192r1_gx[] = {
mbedAustin 11:cada08fc8a70 98 BYTES_TO_T_UINT_8( 0x12, 0x10, 0xFF, 0x82, 0xFD, 0x0A, 0xFF, 0xF4 ),
mbedAustin 11:cada08fc8a70 99 BYTES_TO_T_UINT_8( 0x00, 0x88, 0xA1, 0x43, 0xEB, 0x20, 0xBF, 0x7C ),
mbedAustin 11:cada08fc8a70 100 BYTES_TO_T_UINT_8( 0xF6, 0x90, 0x30, 0xB0, 0x0E, 0xA8, 0x8D, 0x18 ),
mbedAustin 11:cada08fc8a70 101 };
mbedAustin 11:cada08fc8a70 102 static const mbedtls_mpi_uint secp192r1_gy[] = {
mbedAustin 11:cada08fc8a70 103 BYTES_TO_T_UINT_8( 0x11, 0x48, 0x79, 0x1E, 0xA1, 0x77, 0xF9, 0x73 ),
mbedAustin 11:cada08fc8a70 104 BYTES_TO_T_UINT_8( 0xD5, 0xCD, 0x24, 0x6B, 0xED, 0x11, 0x10, 0x63 ),
mbedAustin 11:cada08fc8a70 105 BYTES_TO_T_UINT_8( 0x78, 0xDA, 0xC8, 0xFF, 0x95, 0x2B, 0x19, 0x07 ),
mbedAustin 11:cada08fc8a70 106 };
mbedAustin 11:cada08fc8a70 107 static const mbedtls_mpi_uint secp192r1_n[] = {
mbedAustin 11:cada08fc8a70 108 BYTES_TO_T_UINT_8( 0x31, 0x28, 0xD2, 0xB4, 0xB1, 0xC9, 0x6B, 0x14 ),
mbedAustin 11:cada08fc8a70 109 BYTES_TO_T_UINT_8( 0x36, 0xF8, 0xDE, 0x99, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 110 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 111 };
mbedAustin 11:cada08fc8a70 112 #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
mbedAustin 11:cada08fc8a70 113
mbedAustin 11:cada08fc8a70 114 /*
mbedAustin 11:cada08fc8a70 115 * Domain parameters for secp224r1
mbedAustin 11:cada08fc8a70 116 */
mbedAustin 11:cada08fc8a70 117 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
mbedAustin 11:cada08fc8a70 118 static const mbedtls_mpi_uint secp224r1_p[] = {
mbedAustin 11:cada08fc8a70 119 BYTES_TO_T_UINT_8( 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 120 BYTES_TO_T_UINT_8( 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 121 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 122 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 123 };
mbedAustin 11:cada08fc8a70 124 static const mbedtls_mpi_uint secp224r1_b[] = {
mbedAustin 11:cada08fc8a70 125 BYTES_TO_T_UINT_8( 0xB4, 0xFF, 0x55, 0x23, 0x43, 0x39, 0x0B, 0x27 ),
mbedAustin 11:cada08fc8a70 126 BYTES_TO_T_UINT_8( 0xBA, 0xD8, 0xBF, 0xD7, 0xB7, 0xB0, 0x44, 0x50 ),
mbedAustin 11:cada08fc8a70 127 BYTES_TO_T_UINT_8( 0x56, 0x32, 0x41, 0xF5, 0xAB, 0xB3, 0x04, 0x0C ),
mbedAustin 11:cada08fc8a70 128 BYTES_TO_T_UINT_4( 0x85, 0x0A, 0x05, 0xB4 ),
mbedAustin 11:cada08fc8a70 129 };
mbedAustin 11:cada08fc8a70 130 static const mbedtls_mpi_uint secp224r1_gx[] = {
mbedAustin 11:cada08fc8a70 131 BYTES_TO_T_UINT_8( 0x21, 0x1D, 0x5C, 0x11, 0xD6, 0x80, 0x32, 0x34 ),
mbedAustin 11:cada08fc8a70 132 BYTES_TO_T_UINT_8( 0x22, 0x11, 0xC2, 0x56, 0xD3, 0xC1, 0x03, 0x4A ),
mbedAustin 11:cada08fc8a70 133 BYTES_TO_T_UINT_8( 0xB9, 0x90, 0x13, 0x32, 0x7F, 0xBF, 0xB4, 0x6B ),
mbedAustin 11:cada08fc8a70 134 BYTES_TO_T_UINT_4( 0xBD, 0x0C, 0x0E, 0xB7 ),
mbedAustin 11:cada08fc8a70 135 };
mbedAustin 11:cada08fc8a70 136 static const mbedtls_mpi_uint secp224r1_gy[] = {
mbedAustin 11:cada08fc8a70 137 BYTES_TO_T_UINT_8( 0x34, 0x7E, 0x00, 0x85, 0x99, 0x81, 0xD5, 0x44 ),
mbedAustin 11:cada08fc8a70 138 BYTES_TO_T_UINT_8( 0x64, 0x47, 0x07, 0x5A, 0xA0, 0x75, 0x43, 0xCD ),
mbedAustin 11:cada08fc8a70 139 BYTES_TO_T_UINT_8( 0xE6, 0xDF, 0x22, 0x4C, 0xFB, 0x23, 0xF7, 0xB5 ),
mbedAustin 11:cada08fc8a70 140 BYTES_TO_T_UINT_4( 0x88, 0x63, 0x37, 0xBD ),
mbedAustin 11:cada08fc8a70 141 };
mbedAustin 11:cada08fc8a70 142 static const mbedtls_mpi_uint secp224r1_n[] = {
mbedAustin 11:cada08fc8a70 143 BYTES_TO_T_UINT_8( 0x3D, 0x2A, 0x5C, 0x5C, 0x45, 0x29, 0xDD, 0x13 ),
mbedAustin 11:cada08fc8a70 144 BYTES_TO_T_UINT_8( 0x3E, 0xF0, 0xB8, 0xE0, 0xA2, 0x16, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 145 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 146 BYTES_TO_T_UINT_4( 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 147 };
mbedAustin 11:cada08fc8a70 148 #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
mbedAustin 11:cada08fc8a70 149
mbedAustin 11:cada08fc8a70 150 /*
mbedAustin 11:cada08fc8a70 151 * Domain parameters for secp256r1
mbedAustin 11:cada08fc8a70 152 */
mbedAustin 11:cada08fc8a70 153 #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
mbedAustin 11:cada08fc8a70 154 static const mbedtls_mpi_uint secp256r1_p[] = {
mbedAustin 11:cada08fc8a70 155 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 156 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 157 BYTES_TO_T_UINT_8( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 158 BYTES_TO_T_UINT_8( 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 159 };
mbedAustin 11:cada08fc8a70 160 static const mbedtls_mpi_uint secp256r1_b[] = {
mbedAustin 11:cada08fc8a70 161 BYTES_TO_T_UINT_8( 0x4B, 0x60, 0xD2, 0x27, 0x3E, 0x3C, 0xCE, 0x3B ),
mbedAustin 11:cada08fc8a70 162 BYTES_TO_T_UINT_8( 0xF6, 0xB0, 0x53, 0xCC, 0xB0, 0x06, 0x1D, 0x65 ),
mbedAustin 11:cada08fc8a70 163 BYTES_TO_T_UINT_8( 0xBC, 0x86, 0x98, 0x76, 0x55, 0xBD, 0xEB, 0xB3 ),
mbedAustin 11:cada08fc8a70 164 BYTES_TO_T_UINT_8( 0xE7, 0x93, 0x3A, 0xAA, 0xD8, 0x35, 0xC6, 0x5A ),
mbedAustin 11:cada08fc8a70 165 };
mbedAustin 11:cada08fc8a70 166 static const mbedtls_mpi_uint secp256r1_gx[] = {
mbedAustin 11:cada08fc8a70 167 BYTES_TO_T_UINT_8( 0x96, 0xC2, 0x98, 0xD8, 0x45, 0x39, 0xA1, 0xF4 ),
mbedAustin 11:cada08fc8a70 168 BYTES_TO_T_UINT_8( 0xA0, 0x33, 0xEB, 0x2D, 0x81, 0x7D, 0x03, 0x77 ),
mbedAustin 11:cada08fc8a70 169 BYTES_TO_T_UINT_8( 0xF2, 0x40, 0xA4, 0x63, 0xE5, 0xE6, 0xBC, 0xF8 ),
mbedAustin 11:cada08fc8a70 170 BYTES_TO_T_UINT_8( 0x47, 0x42, 0x2C, 0xE1, 0xF2, 0xD1, 0x17, 0x6B ),
mbedAustin 11:cada08fc8a70 171 };
mbedAustin 11:cada08fc8a70 172 static const mbedtls_mpi_uint secp256r1_gy[] = {
mbedAustin 11:cada08fc8a70 173 BYTES_TO_T_UINT_8( 0xF5, 0x51, 0xBF, 0x37, 0x68, 0x40, 0xB6, 0xCB ),
mbedAustin 11:cada08fc8a70 174 BYTES_TO_T_UINT_8( 0xCE, 0x5E, 0x31, 0x6B, 0x57, 0x33, 0xCE, 0x2B ),
mbedAustin 11:cada08fc8a70 175 BYTES_TO_T_UINT_8( 0x16, 0x9E, 0x0F, 0x7C, 0x4A, 0xEB, 0xE7, 0x8E ),
mbedAustin 11:cada08fc8a70 176 BYTES_TO_T_UINT_8( 0x9B, 0x7F, 0x1A, 0xFE, 0xE2, 0x42, 0xE3, 0x4F ),
mbedAustin 11:cada08fc8a70 177 };
mbedAustin 11:cada08fc8a70 178 static const mbedtls_mpi_uint secp256r1_n[] = {
mbedAustin 11:cada08fc8a70 179 BYTES_TO_T_UINT_8( 0x51, 0x25, 0x63, 0xFC, 0xC2, 0xCA, 0xB9, 0xF3 ),
mbedAustin 11:cada08fc8a70 180 BYTES_TO_T_UINT_8( 0x84, 0x9E, 0x17, 0xA7, 0xAD, 0xFA, 0xE6, 0xBC ),
mbedAustin 11:cada08fc8a70 181 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 182 BYTES_TO_T_UINT_8( 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 183 };
mbedAustin 11:cada08fc8a70 184 #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
mbedAustin 11:cada08fc8a70 185
mbedAustin 11:cada08fc8a70 186 /*
mbedAustin 11:cada08fc8a70 187 * Domain parameters for secp384r1
mbedAustin 11:cada08fc8a70 188 */
mbedAustin 11:cada08fc8a70 189 #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
mbedAustin 11:cada08fc8a70 190 static const mbedtls_mpi_uint secp384r1_p[] = {
mbedAustin 11:cada08fc8a70 191 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 192 BYTES_TO_T_UINT_8( 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 193 BYTES_TO_T_UINT_8( 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 194 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 195 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 196 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 197 };
mbedAustin 11:cada08fc8a70 198 static const mbedtls_mpi_uint secp384r1_b[] = {
mbedAustin 11:cada08fc8a70 199 BYTES_TO_T_UINT_8( 0xEF, 0x2A, 0xEC, 0xD3, 0xED, 0xC8, 0x85, 0x2A ),
mbedAustin 11:cada08fc8a70 200 BYTES_TO_T_UINT_8( 0x9D, 0xD1, 0x2E, 0x8A, 0x8D, 0x39, 0x56, 0xC6 ),
mbedAustin 11:cada08fc8a70 201 BYTES_TO_T_UINT_8( 0x5A, 0x87, 0x13, 0x50, 0x8F, 0x08, 0x14, 0x03 ),
mbedAustin 11:cada08fc8a70 202 BYTES_TO_T_UINT_8( 0x12, 0x41, 0x81, 0xFE, 0x6E, 0x9C, 0x1D, 0x18 ),
mbedAustin 11:cada08fc8a70 203 BYTES_TO_T_UINT_8( 0x19, 0x2D, 0xF8, 0xE3, 0x6B, 0x05, 0x8E, 0x98 ),
mbedAustin 11:cada08fc8a70 204 BYTES_TO_T_UINT_8( 0xE4, 0xE7, 0x3E, 0xE2, 0xA7, 0x2F, 0x31, 0xB3 ),
mbedAustin 11:cada08fc8a70 205 };
mbedAustin 11:cada08fc8a70 206 static const mbedtls_mpi_uint secp384r1_gx[] = {
mbedAustin 11:cada08fc8a70 207 BYTES_TO_T_UINT_8( 0xB7, 0x0A, 0x76, 0x72, 0x38, 0x5E, 0x54, 0x3A ),
mbedAustin 11:cada08fc8a70 208 BYTES_TO_T_UINT_8( 0x6C, 0x29, 0x55, 0xBF, 0x5D, 0xF2, 0x02, 0x55 ),
mbedAustin 11:cada08fc8a70 209 BYTES_TO_T_UINT_8( 0x38, 0x2A, 0x54, 0x82, 0xE0, 0x41, 0xF7, 0x59 ),
mbedAustin 11:cada08fc8a70 210 BYTES_TO_T_UINT_8( 0x98, 0x9B, 0xA7, 0x8B, 0x62, 0x3B, 0x1D, 0x6E ),
mbedAustin 11:cada08fc8a70 211 BYTES_TO_T_UINT_8( 0x74, 0xAD, 0x20, 0xF3, 0x1E, 0xC7, 0xB1, 0x8E ),
mbedAustin 11:cada08fc8a70 212 BYTES_TO_T_UINT_8( 0x37, 0x05, 0x8B, 0xBE, 0x22, 0xCA, 0x87, 0xAA ),
mbedAustin 11:cada08fc8a70 213 };
mbedAustin 11:cada08fc8a70 214 static const mbedtls_mpi_uint secp384r1_gy[] = {
mbedAustin 11:cada08fc8a70 215 BYTES_TO_T_UINT_8( 0x5F, 0x0E, 0xEA, 0x90, 0x7C, 0x1D, 0x43, 0x7A ),
mbedAustin 11:cada08fc8a70 216 BYTES_TO_T_UINT_8( 0x9D, 0x81, 0x7E, 0x1D, 0xCE, 0xB1, 0x60, 0x0A ),
mbedAustin 11:cada08fc8a70 217 BYTES_TO_T_UINT_8( 0xC0, 0xB8, 0xF0, 0xB5, 0x13, 0x31, 0xDA, 0xE9 ),
mbedAustin 11:cada08fc8a70 218 BYTES_TO_T_UINT_8( 0x7C, 0x14, 0x9A, 0x28, 0xBD, 0x1D, 0xF4, 0xF8 ),
mbedAustin 11:cada08fc8a70 219 BYTES_TO_T_UINT_8( 0x29, 0xDC, 0x92, 0x92, 0xBF, 0x98, 0x9E, 0x5D ),
mbedAustin 11:cada08fc8a70 220 BYTES_TO_T_UINT_8( 0x6F, 0x2C, 0x26, 0x96, 0x4A, 0xDE, 0x17, 0x36 ),
mbedAustin 11:cada08fc8a70 221 };
mbedAustin 11:cada08fc8a70 222 static const mbedtls_mpi_uint secp384r1_n[] = {
mbedAustin 11:cada08fc8a70 223 BYTES_TO_T_UINT_8( 0x73, 0x29, 0xC5, 0xCC, 0x6A, 0x19, 0xEC, 0xEC ),
mbedAustin 11:cada08fc8a70 224 BYTES_TO_T_UINT_8( 0x7A, 0xA7, 0xB0, 0x48, 0xB2, 0x0D, 0x1A, 0x58 ),
mbedAustin 11:cada08fc8a70 225 BYTES_TO_T_UINT_8( 0xDF, 0x2D, 0x37, 0xF4, 0x81, 0x4D, 0x63, 0xC7 ),
mbedAustin 11:cada08fc8a70 226 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 227 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 228 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 229 };
mbedAustin 11:cada08fc8a70 230 #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
mbedAustin 11:cada08fc8a70 231
mbedAustin 11:cada08fc8a70 232 /*
mbedAustin 11:cada08fc8a70 233 * Domain parameters for secp521r1
mbedAustin 11:cada08fc8a70 234 */
mbedAustin 11:cada08fc8a70 235 #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
mbedAustin 11:cada08fc8a70 236 static const mbedtls_mpi_uint secp521r1_p[] = {
mbedAustin 11:cada08fc8a70 237 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 238 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 239 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 240 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 241 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 242 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 243 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 244 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 245 BYTES_TO_T_UINT_2( 0xFF, 0x01 ),
mbedAustin 11:cada08fc8a70 246 };
mbedAustin 11:cada08fc8a70 247 static const mbedtls_mpi_uint secp521r1_b[] = {
mbedAustin 11:cada08fc8a70 248 BYTES_TO_T_UINT_8( 0x00, 0x3F, 0x50, 0x6B, 0xD4, 0x1F, 0x45, 0xEF ),
mbedAustin 11:cada08fc8a70 249 BYTES_TO_T_UINT_8( 0xF1, 0x34, 0x2C, 0x3D, 0x88, 0xDF, 0x73, 0x35 ),
mbedAustin 11:cada08fc8a70 250 BYTES_TO_T_UINT_8( 0x07, 0xBF, 0xB1, 0x3B, 0xBD, 0xC0, 0x52, 0x16 ),
mbedAustin 11:cada08fc8a70 251 BYTES_TO_T_UINT_8( 0x7B, 0x93, 0x7E, 0xEC, 0x51, 0x39, 0x19, 0x56 ),
mbedAustin 11:cada08fc8a70 252 BYTES_TO_T_UINT_8( 0xE1, 0x09, 0xF1, 0x8E, 0x91, 0x89, 0xB4, 0xB8 ),
mbedAustin 11:cada08fc8a70 253 BYTES_TO_T_UINT_8( 0xF3, 0x15, 0xB3, 0x99, 0x5B, 0x72, 0xDA, 0xA2 ),
mbedAustin 11:cada08fc8a70 254 BYTES_TO_T_UINT_8( 0xEE, 0x40, 0x85, 0xB6, 0xA0, 0x21, 0x9A, 0x92 ),
mbedAustin 11:cada08fc8a70 255 BYTES_TO_T_UINT_8( 0x1F, 0x9A, 0x1C, 0x8E, 0x61, 0xB9, 0x3E, 0x95 ),
mbedAustin 11:cada08fc8a70 256 BYTES_TO_T_UINT_2( 0x51, 0x00 ),
mbedAustin 11:cada08fc8a70 257 };
mbedAustin 11:cada08fc8a70 258 static const mbedtls_mpi_uint secp521r1_gx[] = {
mbedAustin 11:cada08fc8a70 259 BYTES_TO_T_UINT_8( 0x66, 0xBD, 0xE5, 0xC2, 0x31, 0x7E, 0x7E, 0xF9 ),
mbedAustin 11:cada08fc8a70 260 BYTES_TO_T_UINT_8( 0x9B, 0x42, 0x6A, 0x85, 0xC1, 0xB3, 0x48, 0x33 ),
mbedAustin 11:cada08fc8a70 261 BYTES_TO_T_UINT_8( 0xDE, 0xA8, 0xFF, 0xA2, 0x27, 0xC1, 0x1D, 0xFE ),
mbedAustin 11:cada08fc8a70 262 BYTES_TO_T_UINT_8( 0x28, 0x59, 0xE7, 0xEF, 0x77, 0x5E, 0x4B, 0xA1 ),
mbedAustin 11:cada08fc8a70 263 BYTES_TO_T_UINT_8( 0xBA, 0x3D, 0x4D, 0x6B, 0x60, 0xAF, 0x28, 0xF8 ),
mbedAustin 11:cada08fc8a70 264 BYTES_TO_T_UINT_8( 0x21, 0xB5, 0x3F, 0x05, 0x39, 0x81, 0x64, 0x9C ),
mbedAustin 11:cada08fc8a70 265 BYTES_TO_T_UINT_8( 0x42, 0xB4, 0x95, 0x23, 0x66, 0xCB, 0x3E, 0x9E ),
mbedAustin 11:cada08fc8a70 266 BYTES_TO_T_UINT_8( 0xCD, 0xE9, 0x04, 0x04, 0xB7, 0x06, 0x8E, 0x85 ),
mbedAustin 11:cada08fc8a70 267 BYTES_TO_T_UINT_2( 0xC6, 0x00 ),
mbedAustin 11:cada08fc8a70 268 };
mbedAustin 11:cada08fc8a70 269 static const mbedtls_mpi_uint secp521r1_gy[] = {
mbedAustin 11:cada08fc8a70 270 BYTES_TO_T_UINT_8( 0x50, 0x66, 0xD1, 0x9F, 0x76, 0x94, 0xBE, 0x88 ),
mbedAustin 11:cada08fc8a70 271 BYTES_TO_T_UINT_8( 0x40, 0xC2, 0x72, 0xA2, 0x86, 0x70, 0x3C, 0x35 ),
mbedAustin 11:cada08fc8a70 272 BYTES_TO_T_UINT_8( 0x61, 0x07, 0xAD, 0x3F, 0x01, 0xB9, 0x50, 0xC5 ),
mbedAustin 11:cada08fc8a70 273 BYTES_TO_T_UINT_8( 0x40, 0x26, 0xF4, 0x5E, 0x99, 0x72, 0xEE, 0x97 ),
mbedAustin 11:cada08fc8a70 274 BYTES_TO_T_UINT_8( 0x2C, 0x66, 0x3E, 0x27, 0x17, 0xBD, 0xAF, 0x17 ),
mbedAustin 11:cada08fc8a70 275 BYTES_TO_T_UINT_8( 0x68, 0x44, 0x9B, 0x57, 0x49, 0x44, 0xF5, 0x98 ),
mbedAustin 11:cada08fc8a70 276 BYTES_TO_T_UINT_8( 0xD9, 0x1B, 0x7D, 0x2C, 0xB4, 0x5F, 0x8A, 0x5C ),
mbedAustin 11:cada08fc8a70 277 BYTES_TO_T_UINT_8( 0x04, 0xC0, 0x3B, 0x9A, 0x78, 0x6A, 0x29, 0x39 ),
mbedAustin 11:cada08fc8a70 278 BYTES_TO_T_UINT_2( 0x18, 0x01 ),
mbedAustin 11:cada08fc8a70 279 };
mbedAustin 11:cada08fc8a70 280 static const mbedtls_mpi_uint secp521r1_n[] = {
mbedAustin 11:cada08fc8a70 281 BYTES_TO_T_UINT_8( 0x09, 0x64, 0x38, 0x91, 0x1E, 0xB7, 0x6F, 0xBB ),
mbedAustin 11:cada08fc8a70 282 BYTES_TO_T_UINT_8( 0xAE, 0x47, 0x9C, 0x89, 0xB8, 0xC9, 0xB5, 0x3B ),
mbedAustin 11:cada08fc8a70 283 BYTES_TO_T_UINT_8( 0xD0, 0xA5, 0x09, 0xF7, 0x48, 0x01, 0xCC, 0x7F ),
mbedAustin 11:cada08fc8a70 284 BYTES_TO_T_UINT_8( 0x6B, 0x96, 0x2F, 0xBF, 0x83, 0x87, 0x86, 0x51 ),
mbedAustin 11:cada08fc8a70 285 BYTES_TO_T_UINT_8( 0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 286 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 287 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 288 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 289 BYTES_TO_T_UINT_2( 0xFF, 0x01 ),
mbedAustin 11:cada08fc8a70 290 };
mbedAustin 11:cada08fc8a70 291 #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
mbedAustin 11:cada08fc8a70 292
mbedAustin 11:cada08fc8a70 293 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
mbedAustin 11:cada08fc8a70 294 static const mbedtls_mpi_uint secp192k1_p[] = {
mbedAustin 11:cada08fc8a70 295 BYTES_TO_T_UINT_8( 0x37, 0xEE, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 296 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 297 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 298 };
mbedAustin 11:cada08fc8a70 299 static const mbedtls_mpi_uint secp192k1_a[] = {
mbedAustin 11:cada08fc8a70 300 BYTES_TO_T_UINT_2( 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 301 };
mbedAustin 11:cada08fc8a70 302 static const mbedtls_mpi_uint secp192k1_b[] = {
mbedAustin 11:cada08fc8a70 303 BYTES_TO_T_UINT_2( 0x03, 0x00 ),
mbedAustin 11:cada08fc8a70 304 };
mbedAustin 11:cada08fc8a70 305 static const mbedtls_mpi_uint secp192k1_gx[] = {
mbedAustin 11:cada08fc8a70 306 BYTES_TO_T_UINT_8( 0x7D, 0x6C, 0xE0, 0xEA, 0xB1, 0xD1, 0xA5, 0x1D ),
mbedAustin 11:cada08fc8a70 307 BYTES_TO_T_UINT_8( 0x34, 0xF4, 0xB7, 0x80, 0x02, 0x7D, 0xB0, 0x26 ),
mbedAustin 11:cada08fc8a70 308 BYTES_TO_T_UINT_8( 0xAE, 0xE9, 0x57, 0xC0, 0x0E, 0xF1, 0x4F, 0xDB ),
mbedAustin 11:cada08fc8a70 309 };
mbedAustin 11:cada08fc8a70 310 static const mbedtls_mpi_uint secp192k1_gy[] = {
mbedAustin 11:cada08fc8a70 311 BYTES_TO_T_UINT_8( 0x9D, 0x2F, 0x5E, 0xD9, 0x88, 0xAA, 0x82, 0x40 ),
mbedAustin 11:cada08fc8a70 312 BYTES_TO_T_UINT_8( 0x34, 0x86, 0xBE, 0x15, 0xD0, 0x63, 0x41, 0x84 ),
mbedAustin 11:cada08fc8a70 313 BYTES_TO_T_UINT_8( 0xA7, 0x28, 0x56, 0x9C, 0x6D, 0x2F, 0x2F, 0x9B ),
mbedAustin 11:cada08fc8a70 314 };
mbedAustin 11:cada08fc8a70 315 static const mbedtls_mpi_uint secp192k1_n[] = {
mbedAustin 11:cada08fc8a70 316 BYTES_TO_T_UINT_8( 0x8D, 0xFD, 0xDE, 0x74, 0x6A, 0x46, 0x69, 0x0F ),
mbedAustin 11:cada08fc8a70 317 BYTES_TO_T_UINT_8( 0x17, 0xFC, 0xF2, 0x26, 0xFE, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 318 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 319 };
mbedAustin 11:cada08fc8a70 320 #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
mbedAustin 11:cada08fc8a70 321
mbedAustin 11:cada08fc8a70 322 #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
mbedAustin 11:cada08fc8a70 323 static const mbedtls_mpi_uint secp224k1_p[] = {
mbedAustin 11:cada08fc8a70 324 BYTES_TO_T_UINT_8( 0x6D, 0xE5, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 325 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 326 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 327 BYTES_TO_T_UINT_4( 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 328 };
mbedAustin 11:cada08fc8a70 329 static const mbedtls_mpi_uint secp224k1_a[] = {
mbedAustin 11:cada08fc8a70 330 BYTES_TO_T_UINT_2( 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 331 };
mbedAustin 11:cada08fc8a70 332 static const mbedtls_mpi_uint secp224k1_b[] = {
mbedAustin 11:cada08fc8a70 333 BYTES_TO_T_UINT_2( 0x05, 0x00 ),
mbedAustin 11:cada08fc8a70 334 };
mbedAustin 11:cada08fc8a70 335 static const mbedtls_mpi_uint secp224k1_gx[] = {
mbedAustin 11:cada08fc8a70 336 BYTES_TO_T_UINT_8( 0x5C, 0xA4, 0xB7, 0xB6, 0x0E, 0x65, 0x7E, 0x0F ),
mbedAustin 11:cada08fc8a70 337 BYTES_TO_T_UINT_8( 0xA9, 0x75, 0x70, 0xE4, 0xE9, 0x67, 0xA4, 0x69 ),
mbedAustin 11:cada08fc8a70 338 BYTES_TO_T_UINT_8( 0xA1, 0x28, 0xFC, 0x30, 0xDF, 0x99, 0xF0, 0x4D ),
mbedAustin 11:cada08fc8a70 339 BYTES_TO_T_UINT_4( 0x33, 0x5B, 0x45, 0xA1 ),
mbedAustin 11:cada08fc8a70 340 };
mbedAustin 11:cada08fc8a70 341 static const mbedtls_mpi_uint secp224k1_gy[] = {
mbedAustin 11:cada08fc8a70 342 BYTES_TO_T_UINT_8( 0xA5, 0x61, 0x6D, 0x55, 0xDB, 0x4B, 0xCA, 0xE2 ),
mbedAustin 11:cada08fc8a70 343 BYTES_TO_T_UINT_8( 0x59, 0xBD, 0xB0, 0xC0, 0xF7, 0x19, 0xE3, 0xF7 ),
mbedAustin 11:cada08fc8a70 344 BYTES_TO_T_UINT_8( 0xD6, 0xFB, 0xCA, 0x82, 0x42, 0x34, 0xBA, 0x7F ),
mbedAustin 11:cada08fc8a70 345 BYTES_TO_T_UINT_4( 0xED, 0x9F, 0x08, 0x7E ),
mbedAustin 11:cada08fc8a70 346 };
mbedAustin 11:cada08fc8a70 347 static const mbedtls_mpi_uint secp224k1_n[] = {
mbedAustin 11:cada08fc8a70 348 BYTES_TO_T_UINT_8( 0xF7, 0xB1, 0x9F, 0x76, 0x71, 0xA9, 0xF0, 0xCA ),
mbedAustin 11:cada08fc8a70 349 BYTES_TO_T_UINT_8( 0x84, 0x61, 0xEC, 0xD2, 0xE8, 0xDC, 0x01, 0x00 ),
mbedAustin 11:cada08fc8a70 350 BYTES_TO_T_UINT_8( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 351 BYTES_TO_T_UINT_8( 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 352 };
mbedAustin 11:cada08fc8a70 353 #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
mbedAustin 11:cada08fc8a70 354
mbedAustin 11:cada08fc8a70 355 #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
mbedAustin 11:cada08fc8a70 356 static const mbedtls_mpi_uint secp256k1_p[] = {
mbedAustin 11:cada08fc8a70 357 BYTES_TO_T_UINT_8( 0x2F, 0xFC, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 358 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 359 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 360 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 361 };
mbedAustin 11:cada08fc8a70 362 static const mbedtls_mpi_uint secp256k1_a[] = {
mbedAustin 11:cada08fc8a70 363 BYTES_TO_T_UINT_2( 0x00, 0x00 ),
mbedAustin 11:cada08fc8a70 364 };
mbedAustin 11:cada08fc8a70 365 static const mbedtls_mpi_uint secp256k1_b[] = {
mbedAustin 11:cada08fc8a70 366 BYTES_TO_T_UINT_2( 0x07, 0x00 ),
mbedAustin 11:cada08fc8a70 367 };
mbedAustin 11:cada08fc8a70 368 static const mbedtls_mpi_uint secp256k1_gx[] = {
mbedAustin 11:cada08fc8a70 369 BYTES_TO_T_UINT_8( 0x98, 0x17, 0xF8, 0x16, 0x5B, 0x81, 0xF2, 0x59 ),
mbedAustin 11:cada08fc8a70 370 BYTES_TO_T_UINT_8( 0xD9, 0x28, 0xCE, 0x2D, 0xDB, 0xFC, 0x9B, 0x02 ),
mbedAustin 11:cada08fc8a70 371 BYTES_TO_T_UINT_8( 0x07, 0x0B, 0x87, 0xCE, 0x95, 0x62, 0xA0, 0x55 ),
mbedAustin 11:cada08fc8a70 372 BYTES_TO_T_UINT_8( 0xAC, 0xBB, 0xDC, 0xF9, 0x7E, 0x66, 0xBE, 0x79 ),
mbedAustin 11:cada08fc8a70 373 };
mbedAustin 11:cada08fc8a70 374 static const mbedtls_mpi_uint secp256k1_gy[] = {
mbedAustin 11:cada08fc8a70 375 BYTES_TO_T_UINT_8( 0xB8, 0xD4, 0x10, 0xFB, 0x8F, 0xD0, 0x47, 0x9C ),
mbedAustin 11:cada08fc8a70 376 BYTES_TO_T_UINT_8( 0x19, 0x54, 0x85, 0xA6, 0x48, 0xB4, 0x17, 0xFD ),
mbedAustin 11:cada08fc8a70 377 BYTES_TO_T_UINT_8( 0xA8, 0x08, 0x11, 0x0E, 0xFC, 0xFB, 0xA4, 0x5D ),
mbedAustin 11:cada08fc8a70 378 BYTES_TO_T_UINT_8( 0x65, 0xC4, 0xA3, 0x26, 0x77, 0xDA, 0x3A, 0x48 ),
mbedAustin 11:cada08fc8a70 379 };
mbedAustin 11:cada08fc8a70 380 static const mbedtls_mpi_uint secp256k1_n[] = {
mbedAustin 11:cada08fc8a70 381 BYTES_TO_T_UINT_8( 0x41, 0x41, 0x36, 0xD0, 0x8C, 0x5E, 0xD2, 0xBF ),
mbedAustin 11:cada08fc8a70 382 BYTES_TO_T_UINT_8( 0x3B, 0xA0, 0x48, 0xAF, 0xE6, 0xDC, 0xAE, 0xBA ),
mbedAustin 11:cada08fc8a70 383 BYTES_TO_T_UINT_8( 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 384 BYTES_TO_T_UINT_8( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ),
mbedAustin 11:cada08fc8a70 385 };
mbedAustin 11:cada08fc8a70 386 #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
mbedAustin 11:cada08fc8a70 387
mbedAustin 11:cada08fc8a70 388 /*
mbedAustin 11:cada08fc8a70 389 * Domain parameters for brainpoolP256r1 (RFC 5639 3.4)
mbedAustin 11:cada08fc8a70 390 */
mbedAustin 11:cada08fc8a70 391 #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
mbedAustin 11:cada08fc8a70 392 static const mbedtls_mpi_uint brainpoolP256r1_p[] = {
mbedAustin 11:cada08fc8a70 393 BYTES_TO_T_UINT_8( 0x77, 0x53, 0x6E, 0x1F, 0x1D, 0x48, 0x13, 0x20 ),
mbedAustin 11:cada08fc8a70 394 BYTES_TO_T_UINT_8( 0x28, 0x20, 0x26, 0xD5, 0x23, 0xF6, 0x3B, 0x6E ),
mbedAustin 11:cada08fc8a70 395 BYTES_TO_T_UINT_8( 0x72, 0x8D, 0x83, 0x9D, 0x90, 0x0A, 0x66, 0x3E ),
mbedAustin 11:cada08fc8a70 396 BYTES_TO_T_UINT_8( 0xBC, 0xA9, 0xEE, 0xA1, 0xDB, 0x57, 0xFB, 0xA9 ),
mbedAustin 11:cada08fc8a70 397 };
mbedAustin 11:cada08fc8a70 398 static const mbedtls_mpi_uint brainpoolP256r1_a[] = {
mbedAustin 11:cada08fc8a70 399 BYTES_TO_T_UINT_8( 0xD9, 0xB5, 0x30, 0xF3, 0x44, 0x4B, 0x4A, 0xE9 ),
mbedAustin 11:cada08fc8a70 400 BYTES_TO_T_UINT_8( 0x6C, 0x5C, 0xDC, 0x26, 0xC1, 0x55, 0x80, 0xFB ),
mbedAustin 11:cada08fc8a70 401 BYTES_TO_T_UINT_8( 0xE7, 0xFF, 0x7A, 0x41, 0x30, 0x75, 0xF6, 0xEE ),
mbedAustin 11:cada08fc8a70 402 BYTES_TO_T_UINT_8( 0x57, 0x30, 0x2C, 0xFC, 0x75, 0x09, 0x5A, 0x7D ),
mbedAustin 11:cada08fc8a70 403 };
mbedAustin 11:cada08fc8a70 404 static const mbedtls_mpi_uint brainpoolP256r1_b[] = {
mbedAustin 11:cada08fc8a70 405 BYTES_TO_T_UINT_8( 0xB6, 0x07, 0x8C, 0xFF, 0x18, 0xDC, 0xCC, 0x6B ),
mbedAustin 11:cada08fc8a70 406 BYTES_TO_T_UINT_8( 0xCE, 0xE1, 0xF7, 0x5C, 0x29, 0x16, 0x84, 0x95 ),
mbedAustin 11:cada08fc8a70 407 BYTES_TO_T_UINT_8( 0xBF, 0x7C, 0xD7, 0xBB, 0xD9, 0xB5, 0x30, 0xF3 ),
mbedAustin 11:cada08fc8a70 408 BYTES_TO_T_UINT_8( 0x44, 0x4B, 0x4A, 0xE9, 0x6C, 0x5C, 0xDC, 0x26 ),
mbedAustin 11:cada08fc8a70 409 };
mbedAustin 11:cada08fc8a70 410 static const mbedtls_mpi_uint brainpoolP256r1_gx[] = {
mbedAustin 11:cada08fc8a70 411 BYTES_TO_T_UINT_8( 0x62, 0x32, 0xCE, 0x9A, 0xBD, 0x53, 0x44, 0x3A ),
mbedAustin 11:cada08fc8a70 412 BYTES_TO_T_UINT_8( 0xC2, 0x23, 0xBD, 0xE3, 0xE1, 0x27, 0xDE, 0xB9 ),
mbedAustin 11:cada08fc8a70 413 BYTES_TO_T_UINT_8( 0xAF, 0xB7, 0x81, 0xFC, 0x2F, 0x48, 0x4B, 0x2C ),
mbedAustin 11:cada08fc8a70 414 BYTES_TO_T_UINT_8( 0xCB, 0x57, 0x7E, 0xCB, 0xB9, 0xAE, 0xD2, 0x8B ),
mbedAustin 11:cada08fc8a70 415 };
mbedAustin 11:cada08fc8a70 416 static const mbedtls_mpi_uint brainpoolP256r1_gy[] = {
mbedAustin 11:cada08fc8a70 417 BYTES_TO_T_UINT_8( 0x97, 0x69, 0x04, 0x2F, 0xC7, 0x54, 0x1D, 0x5C ),
mbedAustin 11:cada08fc8a70 418 BYTES_TO_T_UINT_8( 0x54, 0x8E, 0xED, 0x2D, 0x13, 0x45, 0x77, 0xC2 ),
mbedAustin 11:cada08fc8a70 419 BYTES_TO_T_UINT_8( 0xC9, 0x1D, 0x61, 0x14, 0x1A, 0x46, 0xF8, 0x97 ),
mbedAustin 11:cada08fc8a70 420 BYTES_TO_T_UINT_8( 0xFD, 0xC4, 0xDA, 0xC3, 0x35, 0xF8, 0x7E, 0x54 ),
mbedAustin 11:cada08fc8a70 421 };
mbedAustin 11:cada08fc8a70 422 static const mbedtls_mpi_uint brainpoolP256r1_n[] = {
mbedAustin 11:cada08fc8a70 423 BYTES_TO_T_UINT_8( 0xA7, 0x56, 0x48, 0x97, 0x82, 0x0E, 0x1E, 0x90 ),
mbedAustin 11:cada08fc8a70 424 BYTES_TO_T_UINT_8( 0xF7, 0xA6, 0x61, 0xB5, 0xA3, 0x7A, 0x39, 0x8C ),
mbedAustin 11:cada08fc8a70 425 BYTES_TO_T_UINT_8( 0x71, 0x8D, 0x83, 0x9D, 0x90, 0x0A, 0x66, 0x3E ),
mbedAustin 11:cada08fc8a70 426 BYTES_TO_T_UINT_8( 0xBC, 0xA9, 0xEE, 0xA1, 0xDB, 0x57, 0xFB, 0xA9 ),
mbedAustin 11:cada08fc8a70 427 };
mbedAustin 11:cada08fc8a70 428 #endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
mbedAustin 11:cada08fc8a70 429
mbedAustin 11:cada08fc8a70 430 /*
mbedAustin 11:cada08fc8a70 431 * Domain parameters for brainpoolP384r1 (RFC 5639 3.6)
mbedAustin 11:cada08fc8a70 432 */
mbedAustin 11:cada08fc8a70 433 #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
mbedAustin 11:cada08fc8a70 434 static const mbedtls_mpi_uint brainpoolP384r1_p[] = {
mbedAustin 11:cada08fc8a70 435 BYTES_TO_T_UINT_8( 0x53, 0xEC, 0x07, 0x31, 0x13, 0x00, 0x47, 0x87 ),
mbedAustin 11:cada08fc8a70 436 BYTES_TO_T_UINT_8( 0x71, 0x1A, 0x1D, 0x90, 0x29, 0xA7, 0xD3, 0xAC ),
mbedAustin 11:cada08fc8a70 437 BYTES_TO_T_UINT_8( 0x23, 0x11, 0xB7, 0x7F, 0x19, 0xDA, 0xB1, 0x12 ),
mbedAustin 11:cada08fc8a70 438 BYTES_TO_T_UINT_8( 0xB4, 0x56, 0x54, 0xED, 0x09, 0x71, 0x2F, 0x15 ),
mbedAustin 11:cada08fc8a70 439 BYTES_TO_T_UINT_8( 0xDF, 0x41, 0xE6, 0x50, 0x7E, 0x6F, 0x5D, 0x0F ),
mbedAustin 11:cada08fc8a70 440 BYTES_TO_T_UINT_8( 0x28, 0x6D, 0x38, 0xA3, 0x82, 0x1E, 0xB9, 0x8C ),
mbedAustin 11:cada08fc8a70 441 };
mbedAustin 11:cada08fc8a70 442 static const mbedtls_mpi_uint brainpoolP384r1_a[] = {
mbedAustin 11:cada08fc8a70 443 BYTES_TO_T_UINT_8( 0x26, 0x28, 0xCE, 0x22, 0xDD, 0xC7, 0xA8, 0x04 ),
mbedAustin 11:cada08fc8a70 444 BYTES_TO_T_UINT_8( 0xEB, 0xD4, 0x3A, 0x50, 0x4A, 0x81, 0xA5, 0x8A ),
mbedAustin 11:cada08fc8a70 445 BYTES_TO_T_UINT_8( 0x0F, 0xF9, 0x91, 0xBA, 0xEF, 0x65, 0x91, 0x13 ),
mbedAustin 11:cada08fc8a70 446 BYTES_TO_T_UINT_8( 0x87, 0x27, 0xB2, 0x4F, 0x8E, 0xA2, 0xBE, 0xC2 ),
mbedAustin 11:cada08fc8a70 447 BYTES_TO_T_UINT_8( 0xA0, 0xAF, 0x05, 0xCE, 0x0A, 0x08, 0x72, 0x3C ),
mbedAustin 11:cada08fc8a70 448 BYTES_TO_T_UINT_8( 0x0C, 0x15, 0x8C, 0x3D, 0xC6, 0x82, 0xC3, 0x7B ),
mbedAustin 11:cada08fc8a70 449 };
mbedAustin 11:cada08fc8a70 450 static const mbedtls_mpi_uint brainpoolP384r1_b[] = {
mbedAustin 11:cada08fc8a70 451 BYTES_TO_T_UINT_8( 0x11, 0x4C, 0x50, 0xFA, 0x96, 0x86, 0xB7, 0x3A ),
mbedAustin 11:cada08fc8a70 452 BYTES_TO_T_UINT_8( 0x94, 0xC9, 0xDB, 0x95, 0x02, 0x39, 0xB4, 0x7C ),
mbedAustin 11:cada08fc8a70 453 BYTES_TO_T_UINT_8( 0xD5, 0x62, 0xEB, 0x3E, 0xA5, 0x0E, 0x88, 0x2E ),
mbedAustin 11:cada08fc8a70 454 BYTES_TO_T_UINT_8( 0xA6, 0xD2, 0xDC, 0x07, 0xE1, 0x7D, 0xB7, 0x2F ),
mbedAustin 11:cada08fc8a70 455 BYTES_TO_T_UINT_8( 0x7C, 0x44, 0xF0, 0x16, 0x54, 0xB5, 0x39, 0x8B ),
mbedAustin 11:cada08fc8a70 456 BYTES_TO_T_UINT_8( 0x26, 0x28, 0xCE, 0x22, 0xDD, 0xC7, 0xA8, 0x04 ),
mbedAustin 11:cada08fc8a70 457 };
mbedAustin 11:cada08fc8a70 458 static const mbedtls_mpi_uint brainpoolP384r1_gx[] = {
mbedAustin 11:cada08fc8a70 459 BYTES_TO_T_UINT_8( 0x1E, 0xAF, 0xD4, 0x47, 0xE2, 0xB2, 0x87, 0xEF ),
mbedAustin 11:cada08fc8a70 460 BYTES_TO_T_UINT_8( 0xAA, 0x46, 0xD6, 0x36, 0x34, 0xE0, 0x26, 0xE8 ),
mbedAustin 11:cada08fc8a70 461 BYTES_TO_T_UINT_8( 0xE8, 0x10, 0xBD, 0x0C, 0xFE, 0xCA, 0x7F, 0xDB ),
mbedAustin 11:cada08fc8a70 462 BYTES_TO_T_UINT_8( 0xE3, 0x4F, 0xF1, 0x7E, 0xE7, 0xA3, 0x47, 0x88 ),
mbedAustin 11:cada08fc8a70 463 BYTES_TO_T_UINT_8( 0x6B, 0x3F, 0xC1, 0xB7, 0x81, 0x3A, 0xA6, 0xA2 ),
mbedAustin 11:cada08fc8a70 464 BYTES_TO_T_UINT_8( 0xFF, 0x45, 0xCF, 0x68, 0xF0, 0x64, 0x1C, 0x1D ),
mbedAustin 11:cada08fc8a70 465 };
mbedAustin 11:cada08fc8a70 466 static const mbedtls_mpi_uint brainpoolP384r1_gy[] = {
mbedAustin 11:cada08fc8a70 467 BYTES_TO_T_UINT_8( 0x15, 0x53, 0x3C, 0x26, 0x41, 0x03, 0x82, 0x42 ),
mbedAustin 11:cada08fc8a70 468 BYTES_TO_T_UINT_8( 0x11, 0x81, 0x91, 0x77, 0x21, 0x46, 0x46, 0x0E ),
mbedAustin 11:cada08fc8a70 469 BYTES_TO_T_UINT_8( 0x28, 0x29, 0x91, 0xF9, 0x4F, 0x05, 0x9C, 0xE1 ),
mbedAustin 11:cada08fc8a70 470 BYTES_TO_T_UINT_8( 0x64, 0x58, 0xEC, 0xFE, 0x29, 0x0B, 0xB7, 0x62 ),
mbedAustin 11:cada08fc8a70 471 BYTES_TO_T_UINT_8( 0x52, 0xD5, 0xCF, 0x95, 0x8E, 0xEB, 0xB1, 0x5C ),
mbedAustin 11:cada08fc8a70 472 BYTES_TO_T_UINT_8( 0xA4, 0xC2, 0xF9, 0x20, 0x75, 0x1D, 0xBE, 0x8A ),
mbedAustin 11:cada08fc8a70 473 };
mbedAustin 11:cada08fc8a70 474 static const mbedtls_mpi_uint brainpoolP384r1_n[] = {
mbedAustin 11:cada08fc8a70 475 BYTES_TO_T_UINT_8( 0x65, 0x65, 0x04, 0xE9, 0x02, 0x32, 0x88, 0x3B ),
mbedAustin 11:cada08fc8a70 476 BYTES_TO_T_UINT_8( 0x10, 0xC3, 0x7F, 0x6B, 0xAF, 0xB6, 0x3A, 0xCF ),
mbedAustin 11:cada08fc8a70 477 BYTES_TO_T_UINT_8( 0xA7, 0x25, 0x04, 0xAC, 0x6C, 0x6E, 0x16, 0x1F ),
mbedAustin 11:cada08fc8a70 478 BYTES_TO_T_UINT_8( 0xB3, 0x56, 0x54, 0xED, 0x09, 0x71, 0x2F, 0x15 ),
mbedAustin 11:cada08fc8a70 479 BYTES_TO_T_UINT_8( 0xDF, 0x41, 0xE6, 0x50, 0x7E, 0x6F, 0x5D, 0x0F ),
mbedAustin 11:cada08fc8a70 480 BYTES_TO_T_UINT_8( 0x28, 0x6D, 0x38, 0xA3, 0x82, 0x1E, 0xB9, 0x8C ),
mbedAustin 11:cada08fc8a70 481 };
mbedAustin 11:cada08fc8a70 482 #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
mbedAustin 11:cada08fc8a70 483
mbedAustin 11:cada08fc8a70 484 /*
mbedAustin 11:cada08fc8a70 485 * Domain parameters for brainpoolP512r1 (RFC 5639 3.7)
mbedAustin 11:cada08fc8a70 486 */
mbedAustin 11:cada08fc8a70 487 #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
mbedAustin 11:cada08fc8a70 488 static const mbedtls_mpi_uint brainpoolP512r1_p[] = {
mbedAustin 11:cada08fc8a70 489 BYTES_TO_T_UINT_8( 0xF3, 0x48, 0x3A, 0x58, 0x56, 0x60, 0xAA, 0x28 ),
mbedAustin 11:cada08fc8a70 490 BYTES_TO_T_UINT_8( 0x85, 0xC6, 0x82, 0x2D, 0x2F, 0xFF, 0x81, 0x28 ),
mbedAustin 11:cada08fc8a70 491 BYTES_TO_T_UINT_8( 0xE6, 0x80, 0xA3, 0xE6, 0x2A, 0xA1, 0xCD, 0xAE ),
mbedAustin 11:cada08fc8a70 492 BYTES_TO_T_UINT_8( 0x42, 0x68, 0xC6, 0x9B, 0x00, 0x9B, 0x4D, 0x7D ),
mbedAustin 11:cada08fc8a70 493 BYTES_TO_T_UINT_8( 0x71, 0x08, 0x33, 0x70, 0xCA, 0x9C, 0x63, 0xD6 ),
mbedAustin 11:cada08fc8a70 494 BYTES_TO_T_UINT_8( 0x0E, 0xD2, 0xC9, 0xB3, 0xB3, 0x8D, 0x30, 0xCB ),
mbedAustin 11:cada08fc8a70 495 BYTES_TO_T_UINT_8( 0x07, 0xFC, 0xC9, 0x33, 0xAE, 0xE6, 0xD4, 0x3F ),
mbedAustin 11:cada08fc8a70 496 BYTES_TO_T_UINT_8( 0x8B, 0xC4, 0xE9, 0xDB, 0xB8, 0x9D, 0xDD, 0xAA ),
mbedAustin 11:cada08fc8a70 497 };
mbedAustin 11:cada08fc8a70 498 static const mbedtls_mpi_uint brainpoolP512r1_a[] = {
mbedAustin 11:cada08fc8a70 499 BYTES_TO_T_UINT_8( 0xCA, 0x94, 0xFC, 0x77, 0x4D, 0xAC, 0xC1, 0xE7 ),
mbedAustin 11:cada08fc8a70 500 BYTES_TO_T_UINT_8( 0xB9, 0xC7, 0xF2, 0x2B, 0xA7, 0x17, 0x11, 0x7F ),
mbedAustin 11:cada08fc8a70 501 BYTES_TO_T_UINT_8( 0xB5, 0xC8, 0x9A, 0x8B, 0xC9, 0xF1, 0x2E, 0x0A ),
mbedAustin 11:cada08fc8a70 502 BYTES_TO_T_UINT_8( 0xA1, 0x3A, 0x25, 0xA8, 0x5A, 0x5D, 0xED, 0x2D ),
mbedAustin 11:cada08fc8a70 503 BYTES_TO_T_UINT_8( 0xBC, 0x63, 0x98, 0xEA, 0xCA, 0x41, 0x34, 0xA8 ),
mbedAustin 11:cada08fc8a70 504 BYTES_TO_T_UINT_8( 0x10, 0x16, 0xF9, 0x3D, 0x8D, 0xDD, 0xCB, 0x94 ),
mbedAustin 11:cada08fc8a70 505 BYTES_TO_T_UINT_8( 0xC5, 0x4C, 0x23, 0xAC, 0x45, 0x71, 0x32, 0xE2 ),
mbedAustin 11:cada08fc8a70 506 BYTES_TO_T_UINT_8( 0x89, 0x3B, 0x60, 0x8B, 0x31, 0xA3, 0x30, 0x78 ),
mbedAustin 11:cada08fc8a70 507 };
mbedAustin 11:cada08fc8a70 508 static const mbedtls_mpi_uint brainpoolP512r1_b[] = {
mbedAustin 11:cada08fc8a70 509 BYTES_TO_T_UINT_8( 0x23, 0xF7, 0x16, 0x80, 0x63, 0xBD, 0x09, 0x28 ),
mbedAustin 11:cada08fc8a70 510 BYTES_TO_T_UINT_8( 0xDD, 0xE5, 0xBA, 0x5E, 0xB7, 0x50, 0x40, 0x98 ),
mbedAustin 11:cada08fc8a70 511 BYTES_TO_T_UINT_8( 0x67, 0x3E, 0x08, 0xDC, 0xCA, 0x94, 0xFC, 0x77 ),
mbedAustin 11:cada08fc8a70 512 BYTES_TO_T_UINT_8( 0x4D, 0xAC, 0xC1, 0xE7, 0xB9, 0xC7, 0xF2, 0x2B ),
mbedAustin 11:cada08fc8a70 513 BYTES_TO_T_UINT_8( 0xA7, 0x17, 0x11, 0x7F, 0xB5, 0xC8, 0x9A, 0x8B ),
mbedAustin 11:cada08fc8a70 514 BYTES_TO_T_UINT_8( 0xC9, 0xF1, 0x2E, 0x0A, 0xA1, 0x3A, 0x25, 0xA8 ),
mbedAustin 11:cada08fc8a70 515 BYTES_TO_T_UINT_8( 0x5A, 0x5D, 0xED, 0x2D, 0xBC, 0x63, 0x98, 0xEA ),
mbedAustin 11:cada08fc8a70 516 BYTES_TO_T_UINT_8( 0xCA, 0x41, 0x34, 0xA8, 0x10, 0x16, 0xF9, 0x3D ),
mbedAustin 11:cada08fc8a70 517 };
mbedAustin 11:cada08fc8a70 518 static const mbedtls_mpi_uint brainpoolP512r1_gx[] = {
mbedAustin 11:cada08fc8a70 519 BYTES_TO_T_UINT_8( 0x22, 0xF8, 0xB9, 0xBC, 0x09, 0x22, 0x35, 0x8B ),
mbedAustin 11:cada08fc8a70 520 BYTES_TO_T_UINT_8( 0x68, 0x5E, 0x6A, 0x40, 0x47, 0x50, 0x6D, 0x7C ),
mbedAustin 11:cada08fc8a70 521 BYTES_TO_T_UINT_8( 0x5F, 0x7D, 0xB9, 0x93, 0x7B, 0x68, 0xD1, 0x50 ),
mbedAustin 11:cada08fc8a70 522 BYTES_TO_T_UINT_8( 0x8D, 0xD4, 0xD0, 0xE2, 0x78, 0x1F, 0x3B, 0xFF ),
mbedAustin 11:cada08fc8a70 523 BYTES_TO_T_UINT_8( 0x8E, 0x09, 0xD0, 0xF4, 0xEE, 0x62, 0x3B, 0xB4 ),
mbedAustin 11:cada08fc8a70 524 BYTES_TO_T_UINT_8( 0xC1, 0x16, 0xD9, 0xB5, 0x70, 0x9F, 0xED, 0x85 ),
mbedAustin 11:cada08fc8a70 525 BYTES_TO_T_UINT_8( 0x93, 0x6A, 0x4C, 0x9C, 0x2E, 0x32, 0x21, 0x5A ),
mbedAustin 11:cada08fc8a70 526 BYTES_TO_T_UINT_8( 0x64, 0xD9, 0x2E, 0xD8, 0xBD, 0xE4, 0xAE, 0x81 ),
mbedAustin 11:cada08fc8a70 527 };
mbedAustin 11:cada08fc8a70 528 static const mbedtls_mpi_uint brainpoolP512r1_gy[] = {
mbedAustin 11:cada08fc8a70 529 BYTES_TO_T_UINT_8( 0x92, 0x08, 0xD8, 0x3A, 0x0F, 0x1E, 0xCD, 0x78 ),
mbedAustin 11:cada08fc8a70 530 BYTES_TO_T_UINT_8( 0x06, 0x54, 0xF0, 0xA8, 0x2F, 0x2B, 0xCA, 0xD1 ),
mbedAustin 11:cada08fc8a70 531 BYTES_TO_T_UINT_8( 0xAE, 0x63, 0x27, 0x8A, 0xD8, 0x4B, 0xCA, 0x5B ),
mbedAustin 11:cada08fc8a70 532 BYTES_TO_T_UINT_8( 0x5E, 0x48, 0x5F, 0x4A, 0x49, 0xDE, 0xDC, 0xB2 ),
mbedAustin 11:cada08fc8a70 533 BYTES_TO_T_UINT_8( 0x11, 0x81, 0x1F, 0x88, 0x5B, 0xC5, 0x00, 0xA0 ),
mbedAustin 11:cada08fc8a70 534 BYTES_TO_T_UINT_8( 0x1A, 0x7B, 0xA5, 0x24, 0x00, 0xF7, 0x09, 0xF2 ),
mbedAustin 11:cada08fc8a70 535 BYTES_TO_T_UINT_8( 0xFD, 0x22, 0x78, 0xCF, 0xA9, 0xBF, 0xEA, 0xC0 ),
mbedAustin 11:cada08fc8a70 536 BYTES_TO_T_UINT_8( 0xEC, 0x32, 0x63, 0x56, 0x5D, 0x38, 0xDE, 0x7D ),
mbedAustin 11:cada08fc8a70 537 };
mbedAustin 11:cada08fc8a70 538 static const mbedtls_mpi_uint brainpoolP512r1_n[] = {
mbedAustin 11:cada08fc8a70 539 BYTES_TO_T_UINT_8( 0x69, 0x00, 0xA9, 0x9C, 0x82, 0x96, 0x87, 0xB5 ),
mbedAustin 11:cada08fc8a70 540 BYTES_TO_T_UINT_8( 0xDD, 0xDA, 0x5D, 0x08, 0x81, 0xD3, 0xB1, 0x1D ),
mbedAustin 11:cada08fc8a70 541 BYTES_TO_T_UINT_8( 0x47, 0x10, 0xAC, 0x7F, 0x19, 0x61, 0x86, 0x41 ),
mbedAustin 11:cada08fc8a70 542 BYTES_TO_T_UINT_8( 0x19, 0x26, 0xA9, 0x4C, 0x41, 0x5C, 0x3E, 0x55 ),
mbedAustin 11:cada08fc8a70 543 BYTES_TO_T_UINT_8( 0x70, 0x08, 0x33, 0x70, 0xCA, 0x9C, 0x63, 0xD6 ),
mbedAustin 11:cada08fc8a70 544 BYTES_TO_T_UINT_8( 0x0E, 0xD2, 0xC9, 0xB3, 0xB3, 0x8D, 0x30, 0xCB ),
mbedAustin 11:cada08fc8a70 545 BYTES_TO_T_UINT_8( 0x07, 0xFC, 0xC9, 0x33, 0xAE, 0xE6, 0xD4, 0x3F ),
mbedAustin 11:cada08fc8a70 546 BYTES_TO_T_UINT_8( 0x8B, 0xC4, 0xE9, 0xDB, 0xB8, 0x9D, 0xDD, 0xAA ),
mbedAustin 11:cada08fc8a70 547 };
mbedAustin 11:cada08fc8a70 548 #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
mbedAustin 11:cada08fc8a70 549
mbedAustin 11:cada08fc8a70 550 /*
mbedAustin 11:cada08fc8a70 551 * Create an MPI from embedded constants
mbedAustin 11:cada08fc8a70 552 * (assumes len is an exact multiple of sizeof mbedtls_mpi_uint)
mbedAustin 11:cada08fc8a70 553 */
mbedAustin 11:cada08fc8a70 554 static inline void ecp_mpi_load( mbedtls_mpi *X, const mbedtls_mpi_uint *p, size_t len )
mbedAustin 11:cada08fc8a70 555 {
mbedAustin 11:cada08fc8a70 556 X->s = 1;
mbedAustin 11:cada08fc8a70 557 X->n = len / sizeof( mbedtls_mpi_uint );
mbedAustin 11:cada08fc8a70 558 X->p = (mbedtls_mpi_uint *) p;
mbedAustin 11:cada08fc8a70 559 }
mbedAustin 11:cada08fc8a70 560
mbedAustin 11:cada08fc8a70 561 /*
mbedAustin 11:cada08fc8a70 562 * Set an MPI to static value 1
mbedAustin 11:cada08fc8a70 563 */
mbedAustin 11:cada08fc8a70 564 static inline void ecp_mpi_set1( mbedtls_mpi *X )
mbedAustin 11:cada08fc8a70 565 {
mbedAustin 11:cada08fc8a70 566 static mbedtls_mpi_uint one[] = { 1 };
mbedAustin 11:cada08fc8a70 567 X->s = 1;
mbedAustin 11:cada08fc8a70 568 X->n = 1;
mbedAustin 11:cada08fc8a70 569 X->p = one;
mbedAustin 11:cada08fc8a70 570 }
mbedAustin 11:cada08fc8a70 571
mbedAustin 11:cada08fc8a70 572 /*
mbedAustin 11:cada08fc8a70 573 * Make group available from embedded constants
mbedAustin 11:cada08fc8a70 574 */
mbedAustin 11:cada08fc8a70 575 static int ecp_group_load( mbedtls_ecp_group *grp,
mbedAustin 11:cada08fc8a70 576 const mbedtls_mpi_uint *p, size_t plen,
mbedAustin 11:cada08fc8a70 577 const mbedtls_mpi_uint *a, size_t alen,
mbedAustin 11:cada08fc8a70 578 const mbedtls_mpi_uint *b, size_t blen,
mbedAustin 11:cada08fc8a70 579 const mbedtls_mpi_uint *gx, size_t gxlen,
mbedAustin 11:cada08fc8a70 580 const mbedtls_mpi_uint *gy, size_t gylen,
mbedAustin 11:cada08fc8a70 581 const mbedtls_mpi_uint *n, size_t nlen)
mbedAustin 11:cada08fc8a70 582 {
mbedAustin 11:cada08fc8a70 583 ecp_mpi_load( &grp->P, p, plen );
mbedAustin 11:cada08fc8a70 584 if( a != NULL )
mbedAustin 11:cada08fc8a70 585 ecp_mpi_load( &grp->A, a, alen );
mbedAustin 11:cada08fc8a70 586 ecp_mpi_load( &grp->B, b, blen );
mbedAustin 11:cada08fc8a70 587 ecp_mpi_load( &grp->N, n, nlen );
mbedAustin 11:cada08fc8a70 588
mbedAustin 11:cada08fc8a70 589 ecp_mpi_load( &grp->G.X, gx, gxlen );
mbedAustin 11:cada08fc8a70 590 ecp_mpi_load( &grp->G.Y, gy, gylen );
mbedAustin 11:cada08fc8a70 591 ecp_mpi_set1( &grp->G.Z );
mbedAustin 11:cada08fc8a70 592
mbedAustin 11:cada08fc8a70 593 grp->pbits = mbedtls_mpi_bitlen( &grp->P );
mbedAustin 11:cada08fc8a70 594 grp->nbits = mbedtls_mpi_bitlen( &grp->N );
mbedAustin 11:cada08fc8a70 595
mbedAustin 11:cada08fc8a70 596 grp->h = 1;
mbedAustin 11:cada08fc8a70 597
mbedAustin 11:cada08fc8a70 598 return( 0 );
mbedAustin 11:cada08fc8a70 599 }
mbedAustin 11:cada08fc8a70 600
mbedAustin 11:cada08fc8a70 601 #if defined(MBEDTLS_ECP_NIST_OPTIM)
mbedAustin 11:cada08fc8a70 602 /* Forward declarations */
mbedAustin 11:cada08fc8a70 603 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
mbedAustin 11:cada08fc8a70 604 static int ecp_mod_p192( mbedtls_mpi * );
mbedAustin 11:cada08fc8a70 605 #endif
mbedAustin 11:cada08fc8a70 606 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
mbedAustin 11:cada08fc8a70 607 static int ecp_mod_p224( mbedtls_mpi * );
mbedAustin 11:cada08fc8a70 608 #endif
mbedAustin 11:cada08fc8a70 609 #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
mbedAustin 11:cada08fc8a70 610 static int ecp_mod_p256( mbedtls_mpi * );
mbedAustin 11:cada08fc8a70 611 #endif
mbedAustin 11:cada08fc8a70 612 #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
mbedAustin 11:cada08fc8a70 613 static int ecp_mod_p384( mbedtls_mpi * );
mbedAustin 11:cada08fc8a70 614 #endif
mbedAustin 11:cada08fc8a70 615 #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
mbedAustin 11:cada08fc8a70 616 static int ecp_mod_p521( mbedtls_mpi * );
mbedAustin 11:cada08fc8a70 617 #endif
mbedAustin 11:cada08fc8a70 618
mbedAustin 11:cada08fc8a70 619 #define NIST_MODP( P ) grp->modp = ecp_mod_ ## P;
mbedAustin 11:cada08fc8a70 620 #else
mbedAustin 11:cada08fc8a70 621 #define NIST_MODP( P )
mbedAustin 11:cada08fc8a70 622 #endif /* MBEDTLS_ECP_NIST_OPTIM */
mbedAustin 11:cada08fc8a70 623
mbedAustin 11:cada08fc8a70 624 /* Additional forward declarations */
mbedAustin 11:cada08fc8a70 625 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
mbedAustin 11:cada08fc8a70 626 static int ecp_mod_p255( mbedtls_mpi * );
mbedAustin 11:cada08fc8a70 627 #endif
mbedAustin 11:cada08fc8a70 628 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
mbedAustin 11:cada08fc8a70 629 static int ecp_mod_p192k1( mbedtls_mpi * );
mbedAustin 11:cada08fc8a70 630 #endif
mbedAustin 11:cada08fc8a70 631 #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
mbedAustin 11:cada08fc8a70 632 static int ecp_mod_p224k1( mbedtls_mpi * );
mbedAustin 11:cada08fc8a70 633 #endif
mbedAustin 11:cada08fc8a70 634 #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
mbedAustin 11:cada08fc8a70 635 static int ecp_mod_p256k1( mbedtls_mpi * );
mbedAustin 11:cada08fc8a70 636 #endif
mbedAustin 11:cada08fc8a70 637
mbedAustin 11:cada08fc8a70 638 #define LOAD_GROUP_A( G ) ecp_group_load( grp, \
mbedAustin 11:cada08fc8a70 639 G ## _p, sizeof( G ## _p ), \
mbedAustin 11:cada08fc8a70 640 G ## _a, sizeof( G ## _a ), \
mbedAustin 11:cada08fc8a70 641 G ## _b, sizeof( G ## _b ), \
mbedAustin 11:cada08fc8a70 642 G ## _gx, sizeof( G ## _gx ), \
mbedAustin 11:cada08fc8a70 643 G ## _gy, sizeof( G ## _gy ), \
mbedAustin 11:cada08fc8a70 644 G ## _n, sizeof( G ## _n ) )
mbedAustin 11:cada08fc8a70 645
mbedAustin 11:cada08fc8a70 646 #define LOAD_GROUP( G ) ecp_group_load( grp, \
mbedAustin 11:cada08fc8a70 647 G ## _p, sizeof( G ## _p ), \
mbedAustin 11:cada08fc8a70 648 NULL, 0, \
mbedAustin 11:cada08fc8a70 649 G ## _b, sizeof( G ## _b ), \
mbedAustin 11:cada08fc8a70 650 G ## _gx, sizeof( G ## _gx ), \
mbedAustin 11:cada08fc8a70 651 G ## _gy, sizeof( G ## _gy ), \
mbedAustin 11:cada08fc8a70 652 G ## _n, sizeof( G ## _n ) )
mbedAustin 11:cada08fc8a70 653
mbedAustin 11:cada08fc8a70 654 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
mbedAustin 11:cada08fc8a70 655 /*
mbedAustin 11:cada08fc8a70 656 * Specialized function for creating the Curve25519 group
mbedAustin 11:cada08fc8a70 657 */
mbedAustin 11:cada08fc8a70 658 static int ecp_use_curve25519( mbedtls_ecp_group *grp )
mbedAustin 11:cada08fc8a70 659 {
mbedAustin 11:cada08fc8a70 660 int ret;
mbedAustin 11:cada08fc8a70 661
mbedAustin 11:cada08fc8a70 662 /* Actually ( A + 2 ) / 4 */
mbedAustin 11:cada08fc8a70 663 MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &grp->A, 16, "01DB42" ) );
mbedAustin 11:cada08fc8a70 664
mbedAustin 11:cada08fc8a70 665 /* P = 2^255 - 19 */
mbedAustin 11:cada08fc8a70 666 MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &grp->P, 1 ) );
mbedAustin 11:cada08fc8a70 667 MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &grp->P, 255 ) );
mbedAustin 11:cada08fc8a70 668 MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &grp->P, &grp->P, 19 ) );
mbedAustin 11:cada08fc8a70 669 grp->pbits = mbedtls_mpi_bitlen( &grp->P );
mbedAustin 11:cada08fc8a70 670
mbedAustin 11:cada08fc8a70 671 /* Y intentionaly not set, since we use x/z coordinates.
mbedAustin 11:cada08fc8a70 672 * This is used as a marker to identify Montgomery curves! */
mbedAustin 11:cada08fc8a70 673 MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &grp->G.X, 9 ) );
mbedAustin 11:cada08fc8a70 674 MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &grp->G.Z, 1 ) );
mbedAustin 11:cada08fc8a70 675 mbedtls_mpi_free( &grp->G.Y );
mbedAustin 11:cada08fc8a70 676
mbedAustin 11:cada08fc8a70 677 /* Actually, the required msb for private keys */
mbedAustin 11:cada08fc8a70 678 grp->nbits = 254;
mbedAustin 11:cada08fc8a70 679
mbedAustin 11:cada08fc8a70 680 cleanup:
mbedAustin 11:cada08fc8a70 681 if( ret != 0 )
mbedAustin 11:cada08fc8a70 682 mbedtls_ecp_group_free( grp );
mbedAustin 11:cada08fc8a70 683
mbedAustin 11:cada08fc8a70 684 return( ret );
mbedAustin 11:cada08fc8a70 685 }
mbedAustin 11:cada08fc8a70 686 #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
mbedAustin 11:cada08fc8a70 687
mbedAustin 11:cada08fc8a70 688 /*
mbedAustin 11:cada08fc8a70 689 * Set a group using well-known domain parameters
mbedAustin 11:cada08fc8a70 690 */
mbedAustin 11:cada08fc8a70 691 int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id )
mbedAustin 11:cada08fc8a70 692 {
mbedAustin 11:cada08fc8a70 693 mbedtls_ecp_group_free( grp );
mbedAustin 11:cada08fc8a70 694
mbedAustin 11:cada08fc8a70 695 grp->id = id;
mbedAustin 11:cada08fc8a70 696
mbedAustin 11:cada08fc8a70 697 switch( id )
mbedAustin 11:cada08fc8a70 698 {
mbedAustin 11:cada08fc8a70 699 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
mbedAustin 11:cada08fc8a70 700 case MBEDTLS_ECP_DP_SECP192R1:
mbedAustin 11:cada08fc8a70 701 NIST_MODP( p192 );
mbedAustin 11:cada08fc8a70 702 return( LOAD_GROUP( secp192r1 ) );
mbedAustin 11:cada08fc8a70 703 #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
mbedAustin 11:cada08fc8a70 704
mbedAustin 11:cada08fc8a70 705 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
mbedAustin 11:cada08fc8a70 706 case MBEDTLS_ECP_DP_SECP224R1:
mbedAustin 11:cada08fc8a70 707 NIST_MODP( p224 );
mbedAustin 11:cada08fc8a70 708 return( LOAD_GROUP( secp224r1 ) );
mbedAustin 11:cada08fc8a70 709 #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
mbedAustin 11:cada08fc8a70 710
mbedAustin 11:cada08fc8a70 711 #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
mbedAustin 11:cada08fc8a70 712 case MBEDTLS_ECP_DP_SECP256R1:
mbedAustin 11:cada08fc8a70 713 NIST_MODP( p256 );
mbedAustin 11:cada08fc8a70 714 return( LOAD_GROUP( secp256r1 ) );
mbedAustin 11:cada08fc8a70 715 #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
mbedAustin 11:cada08fc8a70 716
mbedAustin 11:cada08fc8a70 717 #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
mbedAustin 11:cada08fc8a70 718 case MBEDTLS_ECP_DP_SECP384R1:
mbedAustin 11:cada08fc8a70 719 NIST_MODP( p384 );
mbedAustin 11:cada08fc8a70 720 return( LOAD_GROUP( secp384r1 ) );
mbedAustin 11:cada08fc8a70 721 #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
mbedAustin 11:cada08fc8a70 722
mbedAustin 11:cada08fc8a70 723 #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
mbedAustin 11:cada08fc8a70 724 case MBEDTLS_ECP_DP_SECP521R1:
mbedAustin 11:cada08fc8a70 725 NIST_MODP( p521 );
mbedAustin 11:cada08fc8a70 726 return( LOAD_GROUP( secp521r1 ) );
mbedAustin 11:cada08fc8a70 727 #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
mbedAustin 11:cada08fc8a70 728
mbedAustin 11:cada08fc8a70 729 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
mbedAustin 11:cada08fc8a70 730 case MBEDTLS_ECP_DP_SECP192K1:
mbedAustin 11:cada08fc8a70 731 grp->modp = ecp_mod_p192k1;
mbedAustin 11:cada08fc8a70 732 return( LOAD_GROUP_A( secp192k1 ) );
mbedAustin 11:cada08fc8a70 733 #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
mbedAustin 11:cada08fc8a70 734
mbedAustin 11:cada08fc8a70 735 #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
mbedAustin 11:cada08fc8a70 736 case MBEDTLS_ECP_DP_SECP224K1:
mbedAustin 11:cada08fc8a70 737 grp->modp = ecp_mod_p224k1;
mbedAustin 11:cada08fc8a70 738 return( LOAD_GROUP_A( secp224k1 ) );
mbedAustin 11:cada08fc8a70 739 #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
mbedAustin 11:cada08fc8a70 740
mbedAustin 11:cada08fc8a70 741 #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
mbedAustin 11:cada08fc8a70 742 case MBEDTLS_ECP_DP_SECP256K1:
mbedAustin 11:cada08fc8a70 743 grp->modp = ecp_mod_p256k1;
mbedAustin 11:cada08fc8a70 744 return( LOAD_GROUP_A( secp256k1 ) );
mbedAustin 11:cada08fc8a70 745 #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
mbedAustin 11:cada08fc8a70 746
mbedAustin 11:cada08fc8a70 747 #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
mbedAustin 11:cada08fc8a70 748 case MBEDTLS_ECP_DP_BP256R1:
mbedAustin 11:cada08fc8a70 749 return( LOAD_GROUP_A( brainpoolP256r1 ) );
mbedAustin 11:cada08fc8a70 750 #endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
mbedAustin 11:cada08fc8a70 751
mbedAustin 11:cada08fc8a70 752 #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
mbedAustin 11:cada08fc8a70 753 case MBEDTLS_ECP_DP_BP384R1:
mbedAustin 11:cada08fc8a70 754 return( LOAD_GROUP_A( brainpoolP384r1 ) );
mbedAustin 11:cada08fc8a70 755 #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
mbedAustin 11:cada08fc8a70 756
mbedAustin 11:cada08fc8a70 757 #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
mbedAustin 11:cada08fc8a70 758 case MBEDTLS_ECP_DP_BP512R1:
mbedAustin 11:cada08fc8a70 759 return( LOAD_GROUP_A( brainpoolP512r1 ) );
mbedAustin 11:cada08fc8a70 760 #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
mbedAustin 11:cada08fc8a70 761
mbedAustin 11:cada08fc8a70 762 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
mbedAustin 11:cada08fc8a70 763 case MBEDTLS_ECP_DP_CURVE25519:
mbedAustin 11:cada08fc8a70 764 grp->modp = ecp_mod_p255;
mbedAustin 11:cada08fc8a70 765 return( ecp_use_curve25519( grp ) );
mbedAustin 11:cada08fc8a70 766 #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
mbedAustin 11:cada08fc8a70 767
mbedAustin 11:cada08fc8a70 768 default:
mbedAustin 11:cada08fc8a70 769 mbedtls_ecp_group_free( grp );
mbedAustin 11:cada08fc8a70 770 return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE );
mbedAustin 11:cada08fc8a70 771 }
mbedAustin 11:cada08fc8a70 772 }
mbedAustin 11:cada08fc8a70 773
mbedAustin 11:cada08fc8a70 774 #if defined(MBEDTLS_ECP_NIST_OPTIM)
mbedAustin 11:cada08fc8a70 775 /*
mbedAustin 11:cada08fc8a70 776 * Fast reduction modulo the primes used by the NIST curves.
mbedAustin 11:cada08fc8a70 777 *
mbedAustin 11:cada08fc8a70 778 * These functions are critical for speed, but not needed for correct
mbedAustin 11:cada08fc8a70 779 * operations. So, we make the choice to heavily rely on the internals of our
mbedAustin 11:cada08fc8a70 780 * bignum library, which creates a tight coupling between these functions and
mbedAustin 11:cada08fc8a70 781 * our MPI implementation. However, the coupling between the ECP module and
mbedAustin 11:cada08fc8a70 782 * MPI remains loose, since these functions can be deactivated at will.
mbedAustin 11:cada08fc8a70 783 */
mbedAustin 11:cada08fc8a70 784
mbedAustin 11:cada08fc8a70 785 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
mbedAustin 11:cada08fc8a70 786 /*
mbedAustin 11:cada08fc8a70 787 * Compared to the way things are presented in FIPS 186-3 D.2,
mbedAustin 11:cada08fc8a70 788 * we proceed in columns, from right (least significant chunk) to left,
mbedAustin 11:cada08fc8a70 789 * adding chunks to N in place, and keeping a carry for the next chunk.
mbedAustin 11:cada08fc8a70 790 * This avoids moving things around in memory, and uselessly adding zeros,
mbedAustin 11:cada08fc8a70 791 * compared to the more straightforward, line-oriented approach.
mbedAustin 11:cada08fc8a70 792 *
mbedAustin 11:cada08fc8a70 793 * For this prime we need to handle data in chunks of 64 bits.
mbedAustin 11:cada08fc8a70 794 * Since this is always a multiple of our basic mbedtls_mpi_uint, we can
mbedAustin 11:cada08fc8a70 795 * use a mbedtls_mpi_uint * to designate such a chunk, and small loops to handle it.
mbedAustin 11:cada08fc8a70 796 */
mbedAustin 11:cada08fc8a70 797
mbedAustin 11:cada08fc8a70 798 /* Add 64-bit chunks (dst += src) and update carry */
mbedAustin 11:cada08fc8a70 799 static inline void add64( mbedtls_mpi_uint *dst, mbedtls_mpi_uint *src, mbedtls_mpi_uint *carry )
mbedAustin 11:cada08fc8a70 800 {
mbedAustin 11:cada08fc8a70 801 unsigned char i;
mbedAustin 11:cada08fc8a70 802 mbedtls_mpi_uint c = 0;
mbedAustin 11:cada08fc8a70 803 for( i = 0; i < 8 / sizeof( mbedtls_mpi_uint ); i++, dst++, src++ )
mbedAustin 11:cada08fc8a70 804 {
mbedAustin 11:cada08fc8a70 805 *dst += c; c = ( *dst < c );
mbedAustin 11:cada08fc8a70 806 *dst += *src; c += ( *dst < *src );
mbedAustin 11:cada08fc8a70 807 }
mbedAustin 11:cada08fc8a70 808 *carry += c;
mbedAustin 11:cada08fc8a70 809 }
mbedAustin 11:cada08fc8a70 810
mbedAustin 11:cada08fc8a70 811 /* Add carry to a 64-bit chunk and update carry */
mbedAustin 11:cada08fc8a70 812 static inline void carry64( mbedtls_mpi_uint *dst, mbedtls_mpi_uint *carry )
mbedAustin 11:cada08fc8a70 813 {
mbedAustin 11:cada08fc8a70 814 unsigned char i;
mbedAustin 11:cada08fc8a70 815 for( i = 0; i < 8 / sizeof( mbedtls_mpi_uint ); i++, dst++ )
mbedAustin 11:cada08fc8a70 816 {
mbedAustin 11:cada08fc8a70 817 *dst += *carry;
mbedAustin 11:cada08fc8a70 818 *carry = ( *dst < *carry );
mbedAustin 11:cada08fc8a70 819 }
mbedAustin 11:cada08fc8a70 820 }
mbedAustin 11:cada08fc8a70 821
mbedAustin 11:cada08fc8a70 822 #define WIDTH 8 / sizeof( mbedtls_mpi_uint )
mbedAustin 11:cada08fc8a70 823 #define A( i ) N->p + i * WIDTH
mbedAustin 11:cada08fc8a70 824 #define ADD( i ) add64( p, A( i ), &c )
mbedAustin 11:cada08fc8a70 825 #define NEXT p += WIDTH; carry64( p, &c )
mbedAustin 11:cada08fc8a70 826 #define LAST p += WIDTH; *p = c; while( ++p < end ) *p = 0
mbedAustin 11:cada08fc8a70 827
mbedAustin 11:cada08fc8a70 828 /*
mbedAustin 11:cada08fc8a70 829 * Fast quasi-reduction modulo p192 (FIPS 186-3 D.2.1)
mbedAustin 11:cada08fc8a70 830 */
mbedAustin 11:cada08fc8a70 831 static int ecp_mod_p192( mbedtls_mpi *N )
mbedAustin 11:cada08fc8a70 832 {
mbedAustin 11:cada08fc8a70 833 int ret;
mbedAustin 11:cada08fc8a70 834 mbedtls_mpi_uint c = 0;
mbedAustin 11:cada08fc8a70 835 mbedtls_mpi_uint *p, *end;
mbedAustin 11:cada08fc8a70 836
mbedAustin 11:cada08fc8a70 837 /* Make sure we have enough blocks so that A(5) is legal */
mbedAustin 11:cada08fc8a70 838 MBEDTLS_MPI_CHK( mbedtls_mpi_grow( N, 6 * WIDTH ) );
mbedAustin 11:cada08fc8a70 839
mbedAustin 11:cada08fc8a70 840 p = N->p;
mbedAustin 11:cada08fc8a70 841 end = p + N->n;
mbedAustin 11:cada08fc8a70 842
mbedAustin 11:cada08fc8a70 843 ADD( 3 ); ADD( 5 ); NEXT; // A0 += A3 + A5
mbedAustin 11:cada08fc8a70 844 ADD( 3 ); ADD( 4 ); ADD( 5 ); NEXT; // A1 += A3 + A4 + A5
mbedAustin 11:cada08fc8a70 845 ADD( 4 ); ADD( 5 ); LAST; // A2 += A4 + A5
mbedAustin 11:cada08fc8a70 846
mbedAustin 11:cada08fc8a70 847 cleanup:
mbedAustin 11:cada08fc8a70 848 return( ret );
mbedAustin 11:cada08fc8a70 849 }
mbedAustin 11:cada08fc8a70 850
mbedAustin 11:cada08fc8a70 851 #undef WIDTH
mbedAustin 11:cada08fc8a70 852 #undef A
mbedAustin 11:cada08fc8a70 853 #undef ADD
mbedAustin 11:cada08fc8a70 854 #undef NEXT
mbedAustin 11:cada08fc8a70 855 #undef LAST
mbedAustin 11:cada08fc8a70 856 #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
mbedAustin 11:cada08fc8a70 857
mbedAustin 11:cada08fc8a70 858 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
mbedAustin 11:cada08fc8a70 859 defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
mbedAustin 11:cada08fc8a70 860 defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
mbedAustin 11:cada08fc8a70 861 /*
mbedAustin 11:cada08fc8a70 862 * The reader is advised to first understand ecp_mod_p192() since the same
mbedAustin 11:cada08fc8a70 863 * general structure is used here, but with additional complications:
mbedAustin 11:cada08fc8a70 864 * (1) chunks of 32 bits, and (2) subtractions.
mbedAustin 11:cada08fc8a70 865 */
mbedAustin 11:cada08fc8a70 866
mbedAustin 11:cada08fc8a70 867 /*
mbedAustin 11:cada08fc8a70 868 * For these primes, we need to handle data in chunks of 32 bits.
mbedAustin 11:cada08fc8a70 869 * This makes it more complicated if we use 64 bits limbs in MPI,
mbedAustin 11:cada08fc8a70 870 * which prevents us from using a uniform access method as for p192.
mbedAustin 11:cada08fc8a70 871 *
mbedAustin 11:cada08fc8a70 872 * So, we define a mini abstraction layer to access 32 bit chunks,
mbedAustin 11:cada08fc8a70 873 * load them in 'cur' for work, and store them back from 'cur' when done.
mbedAustin 11:cada08fc8a70 874 *
mbedAustin 11:cada08fc8a70 875 * While at it, also define the size of N in terms of 32-bit chunks.
mbedAustin 11:cada08fc8a70 876 */
mbedAustin 11:cada08fc8a70 877 #define LOAD32 cur = A( i );
mbedAustin 11:cada08fc8a70 878
mbedAustin 11:cada08fc8a70 879 #if defined(MBEDTLS_HAVE_INT32) /* 32 bit */
mbedAustin 11:cada08fc8a70 880
mbedAustin 11:cada08fc8a70 881 #define MAX32 N->n
mbedAustin 11:cada08fc8a70 882 #define A( j ) N->p[j]
mbedAustin 11:cada08fc8a70 883 #define STORE32 N->p[i] = cur;
mbedAustin 11:cada08fc8a70 884
mbedAustin 11:cada08fc8a70 885 #else /* 64-bit */
mbedAustin 11:cada08fc8a70 886
mbedAustin 11:cada08fc8a70 887 #define MAX32 N->n * 2
mbedAustin 11:cada08fc8a70 888 #define A( j ) j % 2 ? (uint32_t)( N->p[j/2] >> 32 ) : (uint32_t)( N->p[j/2] )
mbedAustin 11:cada08fc8a70 889 #define STORE32 \
mbedAustin 11:cada08fc8a70 890 if( i % 2 ) { \
mbedAustin 11:cada08fc8a70 891 N->p[i/2] &= 0x00000000FFFFFFFF; \
mbedAustin 11:cada08fc8a70 892 N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32; \
mbedAustin 11:cada08fc8a70 893 } else { \
mbedAustin 11:cada08fc8a70 894 N->p[i/2] &= 0xFFFFFFFF00000000; \
mbedAustin 11:cada08fc8a70 895 N->p[i/2] |= (mbedtls_mpi_uint) cur; \
mbedAustin 11:cada08fc8a70 896 }
mbedAustin 11:cada08fc8a70 897
mbedAustin 11:cada08fc8a70 898 #endif /* sizeof( mbedtls_mpi_uint ) */
mbedAustin 11:cada08fc8a70 899
mbedAustin 11:cada08fc8a70 900 /*
mbedAustin 11:cada08fc8a70 901 * Helpers for addition and subtraction of chunks, with signed carry.
mbedAustin 11:cada08fc8a70 902 */
mbedAustin 11:cada08fc8a70 903 static inline void add32( uint32_t *dst, uint32_t src, signed char *carry )
mbedAustin 11:cada08fc8a70 904 {
mbedAustin 11:cada08fc8a70 905 *dst += src;
mbedAustin 11:cada08fc8a70 906 *carry += ( *dst < src );
mbedAustin 11:cada08fc8a70 907 }
mbedAustin 11:cada08fc8a70 908
mbedAustin 11:cada08fc8a70 909 static inline void sub32( uint32_t *dst, uint32_t src, signed char *carry )
mbedAustin 11:cada08fc8a70 910 {
mbedAustin 11:cada08fc8a70 911 *carry -= ( *dst < src );
mbedAustin 11:cada08fc8a70 912 *dst -= src;
mbedAustin 11:cada08fc8a70 913 }
mbedAustin 11:cada08fc8a70 914
mbedAustin 11:cada08fc8a70 915 #define ADD( j ) add32( &cur, A( j ), &c );
mbedAustin 11:cada08fc8a70 916 #define SUB( j ) sub32( &cur, A( j ), &c );
mbedAustin 11:cada08fc8a70 917
mbedAustin 11:cada08fc8a70 918 /*
mbedAustin 11:cada08fc8a70 919 * Helpers for the main 'loop'
mbedAustin 11:cada08fc8a70 920 * (see fix_negative for the motivation of C)
mbedAustin 11:cada08fc8a70 921 */
mbedAustin 11:cada08fc8a70 922 #define INIT( b ) \
mbedAustin 11:cada08fc8a70 923 int ret; \
mbedAustin 11:cada08fc8a70 924 signed char c = 0, cc; \
mbedAustin 11:cada08fc8a70 925 uint32_t cur; \
mbedAustin 11:cada08fc8a70 926 size_t i = 0, bits = b; \
mbedAustin 11:cada08fc8a70 927 mbedtls_mpi C; \
mbedAustin 11:cada08fc8a70 928 mbedtls_mpi_uint Cp[ b / 8 / sizeof( mbedtls_mpi_uint) + 1 ]; \
mbedAustin 11:cada08fc8a70 929 \
mbedAustin 11:cada08fc8a70 930 C.s = 1; \
mbedAustin 11:cada08fc8a70 931 C.n = b / 8 / sizeof( mbedtls_mpi_uint) + 1; \
mbedAustin 11:cada08fc8a70 932 C.p = Cp; \
mbedAustin 11:cada08fc8a70 933 memset( Cp, 0, C.n * sizeof( mbedtls_mpi_uint ) ); \
mbedAustin 11:cada08fc8a70 934 \
mbedAustin 11:cada08fc8a70 935 MBEDTLS_MPI_CHK( mbedtls_mpi_grow( N, b * 2 / 8 / sizeof( mbedtls_mpi_uint ) ) ); \
mbedAustin 11:cada08fc8a70 936 LOAD32;
mbedAustin 11:cada08fc8a70 937
mbedAustin 11:cada08fc8a70 938 #define NEXT \
mbedAustin 11:cada08fc8a70 939 STORE32; i++; LOAD32; \
mbedAustin 11:cada08fc8a70 940 cc = c; c = 0; \
mbedAustin 11:cada08fc8a70 941 if( cc < 0 ) \
mbedAustin 11:cada08fc8a70 942 sub32( &cur, -cc, &c ); \
mbedAustin 11:cada08fc8a70 943 else \
mbedAustin 11:cada08fc8a70 944 add32( &cur, cc, &c ); \
mbedAustin 11:cada08fc8a70 945
mbedAustin 11:cada08fc8a70 946 #define LAST \
mbedAustin 11:cada08fc8a70 947 STORE32; i++; \
mbedAustin 11:cada08fc8a70 948 cur = c > 0 ? c : 0; STORE32; \
mbedAustin 11:cada08fc8a70 949 cur = 0; while( ++i < MAX32 ) { STORE32; } \
mbedAustin 11:cada08fc8a70 950 if( c < 0 ) fix_negative( N, c, &C, bits );
mbedAustin 11:cada08fc8a70 951
mbedAustin 11:cada08fc8a70 952 /*
mbedAustin 11:cada08fc8a70 953 * If the result is negative, we get it in the form
mbedAustin 11:cada08fc8a70 954 * c * 2^(bits + 32) + N, with c negative and N positive shorter than 'bits'
mbedAustin 11:cada08fc8a70 955 */
mbedAustin 11:cada08fc8a70 956 static inline int fix_negative( mbedtls_mpi *N, signed char c, mbedtls_mpi *C, size_t bits )
mbedAustin 11:cada08fc8a70 957 {
mbedAustin 11:cada08fc8a70 958 int ret;
mbedAustin 11:cada08fc8a70 959
mbedAustin 11:cada08fc8a70 960 /* C = - c * 2^(bits + 32) */
mbedAustin 11:cada08fc8a70 961 #if !defined(MBEDTLS_HAVE_INT64)
mbedAustin 11:cada08fc8a70 962 ((void) bits);
mbedAustin 11:cada08fc8a70 963 #else
mbedAustin 11:cada08fc8a70 964 if( bits == 224 )
mbedAustin 11:cada08fc8a70 965 C->p[ C->n - 1 ] = ((mbedtls_mpi_uint) -c) << 32;
mbedAustin 11:cada08fc8a70 966 else
mbedAustin 11:cada08fc8a70 967 #endif
mbedAustin 11:cada08fc8a70 968 C->p[ C->n - 1 ] = (mbedtls_mpi_uint) -c;
mbedAustin 11:cada08fc8a70 969
mbedAustin 11:cada08fc8a70 970 /* N = - ( C - N ) */
mbedAustin 11:cada08fc8a70 971 MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( N, C, N ) );
mbedAustin 11:cada08fc8a70 972 N->s = -1;
mbedAustin 11:cada08fc8a70 973
mbedAustin 11:cada08fc8a70 974 cleanup:
mbedAustin 11:cada08fc8a70 975
mbedAustin 11:cada08fc8a70 976 return( ret );
mbedAustin 11:cada08fc8a70 977 }
mbedAustin 11:cada08fc8a70 978
mbedAustin 11:cada08fc8a70 979 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
mbedAustin 11:cada08fc8a70 980 /*
mbedAustin 11:cada08fc8a70 981 * Fast quasi-reduction modulo p224 (FIPS 186-3 D.2.2)
mbedAustin 11:cada08fc8a70 982 */
mbedAustin 11:cada08fc8a70 983 static int ecp_mod_p224( mbedtls_mpi *N )
mbedAustin 11:cada08fc8a70 984 {
mbedAustin 11:cada08fc8a70 985 INIT( 224 );
mbedAustin 11:cada08fc8a70 986
mbedAustin 11:cada08fc8a70 987 SUB( 7 ); SUB( 11 ); NEXT; // A0 += -A7 - A11
mbedAustin 11:cada08fc8a70 988 SUB( 8 ); SUB( 12 ); NEXT; // A1 += -A8 - A12
mbedAustin 11:cada08fc8a70 989 SUB( 9 ); SUB( 13 ); NEXT; // A2 += -A9 - A13
mbedAustin 11:cada08fc8a70 990 SUB( 10 ); ADD( 7 ); ADD( 11 ); NEXT; // A3 += -A10 + A7 + A11
mbedAustin 11:cada08fc8a70 991 SUB( 11 ); ADD( 8 ); ADD( 12 ); NEXT; // A4 += -A11 + A8 + A12
mbedAustin 11:cada08fc8a70 992 SUB( 12 ); ADD( 9 ); ADD( 13 ); NEXT; // A5 += -A12 + A9 + A13
mbedAustin 11:cada08fc8a70 993 SUB( 13 ); ADD( 10 ); LAST; // A6 += -A13 + A10
mbedAustin 11:cada08fc8a70 994
mbedAustin 11:cada08fc8a70 995 cleanup:
mbedAustin 11:cada08fc8a70 996 return( ret );
mbedAustin 11:cada08fc8a70 997 }
mbedAustin 11:cada08fc8a70 998 #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
mbedAustin 11:cada08fc8a70 999
mbedAustin 11:cada08fc8a70 1000 #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
mbedAustin 11:cada08fc8a70 1001 /*
mbedAustin 11:cada08fc8a70 1002 * Fast quasi-reduction modulo p256 (FIPS 186-3 D.2.3)
mbedAustin 11:cada08fc8a70 1003 */
mbedAustin 11:cada08fc8a70 1004 static int ecp_mod_p256( mbedtls_mpi *N )
mbedAustin 11:cada08fc8a70 1005 {
mbedAustin 11:cada08fc8a70 1006 INIT( 256 );
mbedAustin 11:cada08fc8a70 1007
mbedAustin 11:cada08fc8a70 1008 ADD( 8 ); ADD( 9 );
mbedAustin 11:cada08fc8a70 1009 SUB( 11 ); SUB( 12 ); SUB( 13 ); SUB( 14 ); NEXT; // A0
mbedAustin 11:cada08fc8a70 1010
mbedAustin 11:cada08fc8a70 1011 ADD( 9 ); ADD( 10 );
mbedAustin 11:cada08fc8a70 1012 SUB( 12 ); SUB( 13 ); SUB( 14 ); SUB( 15 ); NEXT; // A1
mbedAustin 11:cada08fc8a70 1013
mbedAustin 11:cada08fc8a70 1014 ADD( 10 ); ADD( 11 );
mbedAustin 11:cada08fc8a70 1015 SUB( 13 ); SUB( 14 ); SUB( 15 ); NEXT; // A2
mbedAustin 11:cada08fc8a70 1016
mbedAustin 11:cada08fc8a70 1017 ADD( 11 ); ADD( 11 ); ADD( 12 ); ADD( 12 ); ADD( 13 );
mbedAustin 11:cada08fc8a70 1018 SUB( 15 ); SUB( 8 ); SUB( 9 ); NEXT; // A3
mbedAustin 11:cada08fc8a70 1019
mbedAustin 11:cada08fc8a70 1020 ADD( 12 ); ADD( 12 ); ADD( 13 ); ADD( 13 ); ADD( 14 );
mbedAustin 11:cada08fc8a70 1021 SUB( 9 ); SUB( 10 ); NEXT; // A4
mbedAustin 11:cada08fc8a70 1022
mbedAustin 11:cada08fc8a70 1023 ADD( 13 ); ADD( 13 ); ADD( 14 ); ADD( 14 ); ADD( 15 );
mbedAustin 11:cada08fc8a70 1024 SUB( 10 ); SUB( 11 ); NEXT; // A5
mbedAustin 11:cada08fc8a70 1025
mbedAustin 11:cada08fc8a70 1026 ADD( 14 ); ADD( 14 ); ADD( 15 ); ADD( 15 ); ADD( 14 ); ADD( 13 );
mbedAustin 11:cada08fc8a70 1027 SUB( 8 ); SUB( 9 ); NEXT; // A6
mbedAustin 11:cada08fc8a70 1028
mbedAustin 11:cada08fc8a70 1029 ADD( 15 ); ADD( 15 ); ADD( 15 ); ADD( 8 );
mbedAustin 11:cada08fc8a70 1030 SUB( 10 ); SUB( 11 ); SUB( 12 ); SUB( 13 ); LAST; // A7
mbedAustin 11:cada08fc8a70 1031
mbedAustin 11:cada08fc8a70 1032 cleanup:
mbedAustin 11:cada08fc8a70 1033 return( ret );
mbedAustin 11:cada08fc8a70 1034 }
mbedAustin 11:cada08fc8a70 1035 #endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
mbedAustin 11:cada08fc8a70 1036
mbedAustin 11:cada08fc8a70 1037 #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
mbedAustin 11:cada08fc8a70 1038 /*
mbedAustin 11:cada08fc8a70 1039 * Fast quasi-reduction modulo p384 (FIPS 186-3 D.2.4)
mbedAustin 11:cada08fc8a70 1040 */
mbedAustin 11:cada08fc8a70 1041 static int ecp_mod_p384( mbedtls_mpi *N )
mbedAustin 11:cada08fc8a70 1042 {
mbedAustin 11:cada08fc8a70 1043 INIT( 384 );
mbedAustin 11:cada08fc8a70 1044
mbedAustin 11:cada08fc8a70 1045 ADD( 12 ); ADD( 21 ); ADD( 20 );
mbedAustin 11:cada08fc8a70 1046 SUB( 23 ); NEXT; // A0
mbedAustin 11:cada08fc8a70 1047
mbedAustin 11:cada08fc8a70 1048 ADD( 13 ); ADD( 22 ); ADD( 23 );
mbedAustin 11:cada08fc8a70 1049 SUB( 12 ); SUB( 20 ); NEXT; // A2
mbedAustin 11:cada08fc8a70 1050
mbedAustin 11:cada08fc8a70 1051 ADD( 14 ); ADD( 23 );
mbedAustin 11:cada08fc8a70 1052 SUB( 13 ); SUB( 21 ); NEXT; // A2
mbedAustin 11:cada08fc8a70 1053
mbedAustin 11:cada08fc8a70 1054 ADD( 15 ); ADD( 12 ); ADD( 20 ); ADD( 21 );
mbedAustin 11:cada08fc8a70 1055 SUB( 14 ); SUB( 22 ); SUB( 23 ); NEXT; // A3
mbedAustin 11:cada08fc8a70 1056
mbedAustin 11:cada08fc8a70 1057 ADD( 21 ); ADD( 21 ); ADD( 16 ); ADD( 13 ); ADD( 12 ); ADD( 20 ); ADD( 22 );
mbedAustin 11:cada08fc8a70 1058 SUB( 15 ); SUB( 23 ); SUB( 23 ); NEXT; // A4
mbedAustin 11:cada08fc8a70 1059
mbedAustin 11:cada08fc8a70 1060 ADD( 22 ); ADD( 22 ); ADD( 17 ); ADD( 14 ); ADD( 13 ); ADD( 21 ); ADD( 23 );
mbedAustin 11:cada08fc8a70 1061 SUB( 16 ); NEXT; // A5
mbedAustin 11:cada08fc8a70 1062
mbedAustin 11:cada08fc8a70 1063 ADD( 23 ); ADD( 23 ); ADD( 18 ); ADD( 15 ); ADD( 14 ); ADD( 22 );
mbedAustin 11:cada08fc8a70 1064 SUB( 17 ); NEXT; // A6
mbedAustin 11:cada08fc8a70 1065
mbedAustin 11:cada08fc8a70 1066 ADD( 19 ); ADD( 16 ); ADD( 15 ); ADD( 23 );
mbedAustin 11:cada08fc8a70 1067 SUB( 18 ); NEXT; // A7
mbedAustin 11:cada08fc8a70 1068
mbedAustin 11:cada08fc8a70 1069 ADD( 20 ); ADD( 17 ); ADD( 16 );
mbedAustin 11:cada08fc8a70 1070 SUB( 19 ); NEXT; // A8
mbedAustin 11:cada08fc8a70 1071
mbedAustin 11:cada08fc8a70 1072 ADD( 21 ); ADD( 18 ); ADD( 17 );
mbedAustin 11:cada08fc8a70 1073 SUB( 20 ); NEXT; // A9
mbedAustin 11:cada08fc8a70 1074
mbedAustin 11:cada08fc8a70 1075 ADD( 22 ); ADD( 19 ); ADD( 18 );
mbedAustin 11:cada08fc8a70 1076 SUB( 21 ); NEXT; // A10
mbedAustin 11:cada08fc8a70 1077
mbedAustin 11:cada08fc8a70 1078 ADD( 23 ); ADD( 20 ); ADD( 19 );
mbedAustin 11:cada08fc8a70 1079 SUB( 22 ); LAST; // A11
mbedAustin 11:cada08fc8a70 1080
mbedAustin 11:cada08fc8a70 1081 cleanup:
mbedAustin 11:cada08fc8a70 1082 return( ret );
mbedAustin 11:cada08fc8a70 1083 }
mbedAustin 11:cada08fc8a70 1084 #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
mbedAustin 11:cada08fc8a70 1085
mbedAustin 11:cada08fc8a70 1086 #undef A
mbedAustin 11:cada08fc8a70 1087 #undef LOAD32
mbedAustin 11:cada08fc8a70 1088 #undef STORE32
mbedAustin 11:cada08fc8a70 1089 #undef MAX32
mbedAustin 11:cada08fc8a70 1090 #undef INIT
mbedAustin 11:cada08fc8a70 1091 #undef NEXT
mbedAustin 11:cada08fc8a70 1092 #undef LAST
mbedAustin 11:cada08fc8a70 1093
mbedAustin 11:cada08fc8a70 1094 #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED ||
mbedAustin 11:cada08fc8a70 1095 MBEDTLS_ECP_DP_SECP256R1_ENABLED ||
mbedAustin 11:cada08fc8a70 1096 MBEDTLS_ECP_DP_SECP384R1_ENABLED */
mbedAustin 11:cada08fc8a70 1097
mbedAustin 11:cada08fc8a70 1098 #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
mbedAustin 11:cada08fc8a70 1099 /*
mbedAustin 11:cada08fc8a70 1100 * Here we have an actual Mersenne prime, so things are more straightforward.
mbedAustin 11:cada08fc8a70 1101 * However, chunks are aligned on a 'weird' boundary (521 bits).
mbedAustin 11:cada08fc8a70 1102 */
mbedAustin 11:cada08fc8a70 1103
mbedAustin 11:cada08fc8a70 1104 /* Size of p521 in terms of mbedtls_mpi_uint */
mbedAustin 11:cada08fc8a70 1105 #define P521_WIDTH ( 521 / 8 / sizeof( mbedtls_mpi_uint ) + 1 )
mbedAustin 11:cada08fc8a70 1106
mbedAustin 11:cada08fc8a70 1107 /* Bits to keep in the most significant mbedtls_mpi_uint */
mbedAustin 11:cada08fc8a70 1108 #define P521_MASK 0x01FF
mbedAustin 11:cada08fc8a70 1109
mbedAustin 11:cada08fc8a70 1110 /*
mbedAustin 11:cada08fc8a70 1111 * Fast quasi-reduction modulo p521 (FIPS 186-3 D.2.5)
mbedAustin 11:cada08fc8a70 1112 * Write N as A1 + 2^521 A0, return A0 + A1
mbedAustin 11:cada08fc8a70 1113 */
mbedAustin 11:cada08fc8a70 1114 static int ecp_mod_p521( mbedtls_mpi *N )
mbedAustin 11:cada08fc8a70 1115 {
mbedAustin 11:cada08fc8a70 1116 int ret;
mbedAustin 11:cada08fc8a70 1117 size_t i;
mbedAustin 11:cada08fc8a70 1118 mbedtls_mpi M;
mbedAustin 11:cada08fc8a70 1119 mbedtls_mpi_uint Mp[P521_WIDTH + 1];
mbedAustin 11:cada08fc8a70 1120 /* Worst case for the size of M is when mbedtls_mpi_uint is 16 bits:
mbedAustin 11:cada08fc8a70 1121 * we need to hold bits 513 to 1056, which is 34 limbs, that is
mbedAustin 11:cada08fc8a70 1122 * P521_WIDTH + 1. Otherwise P521_WIDTH is enough. */
mbedAustin 11:cada08fc8a70 1123
mbedAustin 11:cada08fc8a70 1124 if( N->n < P521_WIDTH )
mbedAustin 11:cada08fc8a70 1125 return( 0 );
mbedAustin 11:cada08fc8a70 1126
mbedAustin 11:cada08fc8a70 1127 /* M = A1 */
mbedAustin 11:cada08fc8a70 1128 M.s = 1;
mbedAustin 11:cada08fc8a70 1129 M.n = N->n - ( P521_WIDTH - 1 );
mbedAustin 11:cada08fc8a70 1130 if( M.n > P521_WIDTH + 1 )
mbedAustin 11:cada08fc8a70 1131 M.n = P521_WIDTH + 1;
mbedAustin 11:cada08fc8a70 1132 M.p = Mp;
mbedAustin 11:cada08fc8a70 1133 memcpy( Mp, N->p + P521_WIDTH - 1, M.n * sizeof( mbedtls_mpi_uint ) );
mbedAustin 11:cada08fc8a70 1134 MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &M, 521 % ( 8 * sizeof( mbedtls_mpi_uint ) ) ) );
mbedAustin 11:cada08fc8a70 1135
mbedAustin 11:cada08fc8a70 1136 /* N = A0 */
mbedAustin 11:cada08fc8a70 1137 N->p[P521_WIDTH - 1] &= P521_MASK;
mbedAustin 11:cada08fc8a70 1138 for( i = P521_WIDTH; i < N->n; i++ )
mbedAustin 11:cada08fc8a70 1139 N->p[i] = 0;
mbedAustin 11:cada08fc8a70 1140
mbedAustin 11:cada08fc8a70 1141 /* N = A0 + A1 */
mbedAustin 11:cada08fc8a70 1142 MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( N, N, &M ) );
mbedAustin 11:cada08fc8a70 1143
mbedAustin 11:cada08fc8a70 1144 cleanup:
mbedAustin 11:cada08fc8a70 1145 return( ret );
mbedAustin 11:cada08fc8a70 1146 }
mbedAustin 11:cada08fc8a70 1147
mbedAustin 11:cada08fc8a70 1148 #undef P521_WIDTH
mbedAustin 11:cada08fc8a70 1149 #undef P521_MASK
mbedAustin 11:cada08fc8a70 1150 #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
mbedAustin 11:cada08fc8a70 1151
mbedAustin 11:cada08fc8a70 1152 #endif /* MBEDTLS_ECP_NIST_OPTIM */
mbedAustin 11:cada08fc8a70 1153
mbedAustin 11:cada08fc8a70 1154 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
mbedAustin 11:cada08fc8a70 1155
mbedAustin 11:cada08fc8a70 1156 /* Size of p255 in terms of mbedtls_mpi_uint */
mbedAustin 11:cada08fc8a70 1157 #define P255_WIDTH ( 255 / 8 / sizeof( mbedtls_mpi_uint ) + 1 )
mbedAustin 11:cada08fc8a70 1158
mbedAustin 11:cada08fc8a70 1159 /*
mbedAustin 11:cada08fc8a70 1160 * Fast quasi-reduction modulo p255 = 2^255 - 19
mbedAustin 11:cada08fc8a70 1161 * Write N as A0 + 2^255 A1, return A0 + 19 * A1
mbedAustin 11:cada08fc8a70 1162 */
mbedAustin 11:cada08fc8a70 1163 static int ecp_mod_p255( mbedtls_mpi *N )
mbedAustin 11:cada08fc8a70 1164 {
mbedAustin 11:cada08fc8a70 1165 int ret;
mbedAustin 11:cada08fc8a70 1166 size_t i;
mbedAustin 11:cada08fc8a70 1167 mbedtls_mpi M;
mbedAustin 11:cada08fc8a70 1168 mbedtls_mpi_uint Mp[P255_WIDTH + 2];
mbedAustin 11:cada08fc8a70 1169
mbedAustin 11:cada08fc8a70 1170 if( N->n < P255_WIDTH )
mbedAustin 11:cada08fc8a70 1171 return( 0 );
mbedAustin 11:cada08fc8a70 1172
mbedAustin 11:cada08fc8a70 1173 /* M = A1 */
mbedAustin 11:cada08fc8a70 1174 M.s = 1;
mbedAustin 11:cada08fc8a70 1175 M.n = N->n - ( P255_WIDTH - 1 );
mbedAustin 11:cada08fc8a70 1176 if( M.n > P255_WIDTH + 1 )
mbedAustin 11:cada08fc8a70 1177 M.n = P255_WIDTH + 1;
mbedAustin 11:cada08fc8a70 1178 M.p = Mp;
mbedAustin 11:cada08fc8a70 1179 memset( Mp, 0, sizeof Mp );
mbedAustin 11:cada08fc8a70 1180 memcpy( Mp, N->p + P255_WIDTH - 1, M.n * sizeof( mbedtls_mpi_uint ) );
mbedAustin 11:cada08fc8a70 1181 MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &M, 255 % ( 8 * sizeof( mbedtls_mpi_uint ) ) ) );
mbedAustin 11:cada08fc8a70 1182 M.n++; /* Make room for multiplication by 19 */
mbedAustin 11:cada08fc8a70 1183
mbedAustin 11:cada08fc8a70 1184 /* N = A0 */
mbedAustin 11:cada08fc8a70 1185 MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( N, 255, 0 ) );
mbedAustin 11:cada08fc8a70 1186 for( i = P255_WIDTH; i < N->n; i++ )
mbedAustin 11:cada08fc8a70 1187 N->p[i] = 0;
mbedAustin 11:cada08fc8a70 1188
mbedAustin 11:cada08fc8a70 1189 /* N = A0 + 19 * A1 */
mbedAustin 11:cada08fc8a70 1190 MBEDTLS_MPI_CHK( mbedtls_mpi_mul_int( &M, &M, 19 ) );
mbedAustin 11:cada08fc8a70 1191 MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( N, N, &M ) );
mbedAustin 11:cada08fc8a70 1192
mbedAustin 11:cada08fc8a70 1193 cleanup:
mbedAustin 11:cada08fc8a70 1194 return( ret );
mbedAustin 11:cada08fc8a70 1195 }
mbedAustin 11:cada08fc8a70 1196 #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
mbedAustin 11:cada08fc8a70 1197
mbedAustin 11:cada08fc8a70 1198 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || \
mbedAustin 11:cada08fc8a70 1199 defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || \
mbedAustin 11:cada08fc8a70 1200 defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
mbedAustin 11:cada08fc8a70 1201 /*
mbedAustin 11:cada08fc8a70 1202 * Fast quasi-reduction modulo P = 2^s - R,
mbedAustin 11:cada08fc8a70 1203 * with R about 33 bits, used by the Koblitz curves.
mbedAustin 11:cada08fc8a70 1204 *
mbedAustin 11:cada08fc8a70 1205 * Write N as A0 + 2^224 A1, return A0 + R * A1.
mbedAustin 11:cada08fc8a70 1206 * Actually do two passes, since R is big.
mbedAustin 11:cada08fc8a70 1207 */
mbedAustin 11:cada08fc8a70 1208 #define P_KOBLITZ_MAX ( 256 / 8 / sizeof( mbedtls_mpi_uint ) ) // Max limbs in P
mbedAustin 11:cada08fc8a70 1209 #define P_KOBLITZ_R ( 8 / sizeof( mbedtls_mpi_uint ) ) // Limbs in R
mbedAustin 11:cada08fc8a70 1210 static inline int ecp_mod_koblitz( mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t p_limbs,
mbedAustin 11:cada08fc8a70 1211 size_t adjust, size_t shift, mbedtls_mpi_uint mask )
mbedAustin 11:cada08fc8a70 1212 {
mbedAustin 11:cada08fc8a70 1213 int ret;
mbedAustin 11:cada08fc8a70 1214 size_t i;
mbedAustin 11:cada08fc8a70 1215 mbedtls_mpi M, R;
mbedAustin 11:cada08fc8a70 1216 mbedtls_mpi_uint Mp[P_KOBLITZ_MAX + P_KOBLITZ_R];
mbedAustin 11:cada08fc8a70 1217
mbedAustin 11:cada08fc8a70 1218 if( N->n < p_limbs )
mbedAustin 11:cada08fc8a70 1219 return( 0 );
mbedAustin 11:cada08fc8a70 1220
mbedAustin 11:cada08fc8a70 1221 /* Init R */
mbedAustin 11:cada08fc8a70 1222 R.s = 1;
mbedAustin 11:cada08fc8a70 1223 R.p = Rp;
mbedAustin 11:cada08fc8a70 1224 R.n = P_KOBLITZ_R;
mbedAustin 11:cada08fc8a70 1225
mbedAustin 11:cada08fc8a70 1226 /* Common setup for M */
mbedAustin 11:cada08fc8a70 1227 M.s = 1;
mbedAustin 11:cada08fc8a70 1228 M.p = Mp;
mbedAustin 11:cada08fc8a70 1229
mbedAustin 11:cada08fc8a70 1230 /* M = A1 */
mbedAustin 11:cada08fc8a70 1231 M.n = N->n - ( p_limbs - adjust );
mbedAustin 11:cada08fc8a70 1232 if( M.n > p_limbs + adjust )
mbedAustin 11:cada08fc8a70 1233 M.n = p_limbs + adjust;
mbedAustin 11:cada08fc8a70 1234 memset( Mp, 0, sizeof Mp );
mbedAustin 11:cada08fc8a70 1235 memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( mbedtls_mpi_uint ) );
mbedAustin 11:cada08fc8a70 1236 if( shift != 0 )
mbedAustin 11:cada08fc8a70 1237 MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &M, shift ) );
mbedAustin 11:cada08fc8a70 1238 M.n += R.n - adjust; /* Make room for multiplication by R */
mbedAustin 11:cada08fc8a70 1239
mbedAustin 11:cada08fc8a70 1240 /* N = A0 */
mbedAustin 11:cada08fc8a70 1241 if( mask != 0 )
mbedAustin 11:cada08fc8a70 1242 N->p[p_limbs - 1] &= mask;
mbedAustin 11:cada08fc8a70 1243 for( i = p_limbs; i < N->n; i++ )
mbedAustin 11:cada08fc8a70 1244 N->p[i] = 0;
mbedAustin 11:cada08fc8a70 1245
mbedAustin 11:cada08fc8a70 1246 /* N = A0 + R * A1 */
mbedAustin 11:cada08fc8a70 1247 MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &M, &M, &R ) );
mbedAustin 11:cada08fc8a70 1248 MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( N, N, &M ) );
mbedAustin 11:cada08fc8a70 1249
mbedAustin 11:cada08fc8a70 1250 /* Second pass */
mbedAustin 11:cada08fc8a70 1251
mbedAustin 11:cada08fc8a70 1252 /* M = A1 */
mbedAustin 11:cada08fc8a70 1253 M.n = N->n - ( p_limbs - adjust );
mbedAustin 11:cada08fc8a70 1254 if( M.n > p_limbs + adjust )
mbedAustin 11:cada08fc8a70 1255 M.n = p_limbs + adjust;
mbedAustin 11:cada08fc8a70 1256 memset( Mp, 0, sizeof Mp );
mbedAustin 11:cada08fc8a70 1257 memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( mbedtls_mpi_uint ) );
mbedAustin 11:cada08fc8a70 1258 if( shift != 0 )
mbedAustin 11:cada08fc8a70 1259 MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &M, shift ) );
mbedAustin 11:cada08fc8a70 1260 M.n += R.n - adjust; /* Make room for multiplication by R */
mbedAustin 11:cada08fc8a70 1261
mbedAustin 11:cada08fc8a70 1262 /* N = A0 */
mbedAustin 11:cada08fc8a70 1263 if( mask != 0 )
mbedAustin 11:cada08fc8a70 1264 N->p[p_limbs - 1] &= mask;
mbedAustin 11:cada08fc8a70 1265 for( i = p_limbs; i < N->n; i++ )
mbedAustin 11:cada08fc8a70 1266 N->p[i] = 0;
mbedAustin 11:cada08fc8a70 1267
mbedAustin 11:cada08fc8a70 1268 /* N = A0 + R * A1 */
mbedAustin 11:cada08fc8a70 1269 MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &M, &M, &R ) );
mbedAustin 11:cada08fc8a70 1270 MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( N, N, &M ) );
mbedAustin 11:cada08fc8a70 1271
mbedAustin 11:cada08fc8a70 1272 cleanup:
mbedAustin 11:cada08fc8a70 1273 return( ret );
mbedAustin 11:cada08fc8a70 1274 }
mbedAustin 11:cada08fc8a70 1275 #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED) ||
mbedAustin 11:cada08fc8a70 1276 MBEDTLS_ECP_DP_SECP224K1_ENABLED) ||
mbedAustin 11:cada08fc8a70 1277 MBEDTLS_ECP_DP_SECP256K1_ENABLED) */
mbedAustin 11:cada08fc8a70 1278
mbedAustin 11:cada08fc8a70 1279 #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
mbedAustin 11:cada08fc8a70 1280 /*
mbedAustin 11:cada08fc8a70 1281 * Fast quasi-reduction modulo p192k1 = 2^192 - R,
mbedAustin 11:cada08fc8a70 1282 * with R = 2^32 + 2^12 + 2^8 + 2^7 + 2^6 + 2^3 + 1 = 0x0100001119
mbedAustin 11:cada08fc8a70 1283 */
mbedAustin 11:cada08fc8a70 1284 static int ecp_mod_p192k1( mbedtls_mpi *N )
mbedAustin 11:cada08fc8a70 1285 {
mbedAustin 11:cada08fc8a70 1286 static mbedtls_mpi_uint Rp[] = {
mbedAustin 11:cada08fc8a70 1287 BYTES_TO_T_UINT_8( 0xC9, 0x11, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 ) };
mbedAustin 11:cada08fc8a70 1288
mbedAustin 11:cada08fc8a70 1289 return( ecp_mod_koblitz( N, Rp, 192 / 8 / sizeof( mbedtls_mpi_uint ), 0, 0, 0 ) );
mbedAustin 11:cada08fc8a70 1290 }
mbedAustin 11:cada08fc8a70 1291 #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
mbedAustin 11:cada08fc8a70 1292
mbedAustin 11:cada08fc8a70 1293 #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
mbedAustin 11:cada08fc8a70 1294 /*
mbedAustin 11:cada08fc8a70 1295 * Fast quasi-reduction modulo p224k1 = 2^224 - R,
mbedAustin 11:cada08fc8a70 1296 * with R = 2^32 + 2^12 + 2^11 + 2^9 + 2^7 + 2^4 + 2 + 1 = 0x0100001A93
mbedAustin 11:cada08fc8a70 1297 */
mbedAustin 11:cada08fc8a70 1298 static int ecp_mod_p224k1( mbedtls_mpi *N )
mbedAustin 11:cada08fc8a70 1299 {
mbedAustin 11:cada08fc8a70 1300 static mbedtls_mpi_uint Rp[] = {
mbedAustin 11:cada08fc8a70 1301 BYTES_TO_T_UINT_8( 0x93, 0x1A, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 ) };
mbedAustin 11:cada08fc8a70 1302
mbedAustin 11:cada08fc8a70 1303 #if defined(MBEDTLS_HAVE_INT64)
mbedAustin 11:cada08fc8a70 1304 return( ecp_mod_koblitz( N, Rp, 4, 1, 32, 0xFFFFFFFF ) );
mbedAustin 11:cada08fc8a70 1305 #else
mbedAustin 11:cada08fc8a70 1306 return( ecp_mod_koblitz( N, Rp, 224 / 8 / sizeof( mbedtls_mpi_uint ), 0, 0, 0 ) );
mbedAustin 11:cada08fc8a70 1307 #endif
mbedAustin 11:cada08fc8a70 1308 }
mbedAustin 11:cada08fc8a70 1309
mbedAustin 11:cada08fc8a70 1310 #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
mbedAustin 11:cada08fc8a70 1311
mbedAustin 11:cada08fc8a70 1312 #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
mbedAustin 11:cada08fc8a70 1313 /*
mbedAustin 11:cada08fc8a70 1314 * Fast quasi-reduction modulo p256k1 = 2^256 - R,
mbedAustin 11:cada08fc8a70 1315 * with R = 2^32 + 2^9 + 2^8 + 2^7 + 2^6 + 2^4 + 1 = 0x01000003D1
mbedAustin 11:cada08fc8a70 1316 */
mbedAustin 11:cada08fc8a70 1317 static int ecp_mod_p256k1( mbedtls_mpi *N )
mbedAustin 11:cada08fc8a70 1318 {
mbedAustin 11:cada08fc8a70 1319 static mbedtls_mpi_uint Rp[] = {
mbedAustin 11:cada08fc8a70 1320 BYTES_TO_T_UINT_8( 0xD1, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 ) };
mbedAustin 11:cada08fc8a70 1321 return( ecp_mod_koblitz( N, Rp, 256 / 8 / sizeof( mbedtls_mpi_uint ), 0, 0, 0 ) );
mbedAustin 11:cada08fc8a70 1322 }
mbedAustin 11:cada08fc8a70 1323 #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
mbedAustin 11:cada08fc8a70 1324
mbedAustin 11:cada08fc8a70 1325 #endif /* MBEDTLS_ECP_C */