This is a fork due to permission issues

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Committer:
timbeight
Date:
Thu May 19 16:02:10 2016 +0000
Revision:
1:0ddbe2d3319c
Parent:
0:f7c60d3e7b8a
This is my first commit while in the class.

Who changed what in which revision?

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