Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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