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