1 #include <libecc/lib_ecc_config.h> 2 #ifdef WITH_CURVE_GOST_R3410_2012_256_PARAMSETC 3 4 #ifndef __EC_PARAMS_GOST_R3410_2012_256_PARAMSETC_H__ 5 #define __EC_PARAMS_GOST_R3410_2012_256_PARAMSETC_H__ 6 #include <libecc/curves/known/ec_params_external.h> 7 static const u8 gost_R3410_2012_256_paramSetC_p[] = { 8 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 9 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 10 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 11 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x99, 12 }; 13 14 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p); 15 16 #define CURVE_GOST_R3410_2012_256_PARAMSETC_P_BITLEN 256 17 static const u8 gost_R3410_2012_256_paramSetC_p_bitlen[] = { 18 0x01, 0x00, 19 }; 20 21 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_bitlen); 22 23 #if (WORD_BYTES == 8) /* 64-bit words */ 24 static const u8 gost_R3410_2012_256_paramSetC_r[] = { 25 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 26 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 27 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 28 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x67, 29 }; 30 31 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_r); 32 33 static const u8 gost_R3410_2012_256_paramSetC_r_square[] = { 34 0x02, 0x7a, 0xcd, 0xc4, 35 }; 36 37 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_r_square); 38 39 static const u8 gost_R3410_2012_256_paramSetC_mpinv[] = { 40 0xbd, 0x66, 0x7a, 0xb8, 0xa3, 0x34, 0x78, 0x57, 41 }; 42 43 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_mpinv); 44 45 static const u8 gost_R3410_2012_256_paramSetC_p_shift[] = { 46 0x00, 47 }; 48 49 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_shift); 50 51 static const u8 gost_R3410_2012_256_paramSetC_p_normalized[] = { 52 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x99, 56 }; 57 58 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_normalized); 59 60 static const u8 gost_R3410_2012_256_paramSetC_p_reciprocal[] = { 61 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 62 }; 63 64 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_reciprocal); 65 66 #elif (WORD_BYTES == 4) /* 32-bit words */ 67 static const u8 gost_R3410_2012_256_paramSetC_r[] = { 68 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 69 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 70 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 71 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x67, 72 }; 73 74 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_r); 75 76 static const u8 gost_R3410_2012_256_paramSetC_r_square[] = { 77 0x02, 0x7a, 0xcd, 0xc4, 78 }; 79 80 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_r_square); 81 82 static const u8 gost_R3410_2012_256_paramSetC_mpinv[] = { 83 0xa3, 0x34, 0x78, 0x57, 84 }; 85 86 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_mpinv); 87 88 static const u8 gost_R3410_2012_256_paramSetC_p_shift[] = { 89 0x00, 90 }; 91 92 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_shift); 93 94 static const u8 gost_R3410_2012_256_paramSetC_p_normalized[] = { 95 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x99, 99 }; 100 101 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_normalized); 102 103 static const u8 gost_R3410_2012_256_paramSetC_p_reciprocal[] = { 104 0xff, 0xff, 0xff, 0xff, 105 }; 106 107 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_reciprocal); 108 109 #elif (WORD_BYTES == 2) /* 16-bit words */ 110 static const u8 gost_R3410_2012_256_paramSetC_r[] = { 111 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 112 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 113 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 114 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x67, 115 }; 116 117 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_r); 118 119 static const u8 gost_R3410_2012_256_paramSetC_r_square[] = { 120 0x02, 0x7a, 0xcd, 0xc4, 121 }; 122 123 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_r_square); 124 125 static const u8 gost_R3410_2012_256_paramSetC_mpinv[] = { 126 0x78, 0x57, 127 }; 128 129 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_mpinv); 130 131 static const u8 gost_R3410_2012_256_paramSetC_p_shift[] = { 132 0x00, 133 }; 134 135 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_shift); 136 137 static const u8 gost_R3410_2012_256_paramSetC_p_normalized[] = { 138 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 141 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x99, 142 }; 143 144 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_normalized); 145 146 static const u8 gost_R3410_2012_256_paramSetC_p_reciprocal[] = { 147 0xff, 0xff, 148 }; 149 150 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_p_reciprocal); 151 152 #else /* unknown word size */ 153 #error "Unsupported word size" 154 #endif 155 156 static const u8 gost_R3410_2012_256_paramSetC_a[] = { 157 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x96, 161 }; 162 163 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_a); 164 165 static const u8 gost_R3410_2012_256_paramSetC_b[] = { 166 0x3e, 0x1a, 0xf4, 0x19, 0xa2, 0x69, 0xa5, 0xf8, 167 0x66, 0xa7, 0xd3, 0xc2, 0x5c, 0x3d, 0xf8, 0x0a, 168 0xe9, 0x79, 0x25, 0x93, 0x73, 0xff, 0x2b, 0x18, 169 0x2f, 0x49, 0xd4, 0xce, 0x7e, 0x1b, 0xbc, 0x8b, 170 }; 171 172 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_b); 173 174 #define CURVE_GOST_R3410_2012_256_PARAMSETC_CURVE_ORDER_BITLEN 256 175 static const u8 gost_R3410_2012_256_paramSetC_curve_order[] = { 176 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 178 0x5f, 0x70, 0x0c, 0xff, 0xf1, 0xa6, 0x24, 0xe5, 179 0xe4, 0x97, 0x16, 0x1b, 0xcc, 0x8a, 0x19, 0x8f, 180 }; 181 182 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_curve_order); 183 184 static const u8 gost_R3410_2012_256_paramSetC_gx[] = { 185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 186 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 189 }; 190 191 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_gx); 192 193 static const u8 gost_R3410_2012_256_paramSetC_gy[] = { 194 0x3f, 0xa8, 0x12, 0x43, 0x59, 0xf9, 0x66, 0x80, 195 0xb8, 0x3d, 0x1c, 0x3e, 0xb2, 0xc0, 0x70, 0xe5, 196 0xc5, 0x45, 0xc9, 0x85, 0x8d, 0x03, 0xec, 0xfb, 197 0x74, 0x4b, 0xf8, 0xd7, 0x17, 0x71, 0x7e, 0xfc, 198 }; 199 200 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_gy); 201 202 static const u8 gost_R3410_2012_256_paramSetC_gz[] = { 203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 207 }; 208 209 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_gz); 210 211 static const u8 gost_R3410_2012_256_paramSetC_gen_order[] = { 212 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 214 0x5f, 0x70, 0x0c, 0xff, 0xf1, 0xa6, 0x24, 0xe5, 215 0xe4, 0x97, 0x16, 0x1b, 0xcc, 0x8a, 0x19, 0x8f, 216 }; 217 218 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_gen_order); 219 220 #define CURVE_GOST_R3410_2012_256_PARAMSETC_Q_BITLEN 256 221 static const u8 gost_R3410_2012_256_paramSetC_gen_order_bitlen[] = { 222 0x01, 0x00, 223 }; 224 225 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_gen_order_bitlen); 226 227 static const u8 gost_R3410_2012_256_paramSetC_cofactor[] = { 228 0x01, 229 }; 230 231 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_cofactor); 232 233 static const u8 gost_R3410_2012_256_paramSetC_alpha_montgomery[] = { 234 0x00, 235 }; 236 TO_EC_STR_PARAM_FIXED_SIZE(gost_R3410_2012_256_paramSetC_alpha_montgomery, 0); 237 238 static const u8 gost_R3410_2012_256_paramSetC_gamma_montgomery[] = { 239 0x00, 240 }; 241 TO_EC_STR_PARAM_FIXED_SIZE(gost_R3410_2012_256_paramSetC_gamma_montgomery, 0); 242 243 static const u8 gost_R3410_2012_256_paramSetC_alpha_edwards[] = { 244 0x00, 245 }; 246 TO_EC_STR_PARAM_FIXED_SIZE(gost_R3410_2012_256_paramSetC_alpha_edwards, 0); 247 248 static const u8 gost_R3410_2012_256_paramSetC_name[] = "GOST_R3410_2012_256_PARAMSETC"; 249 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_name); 250 251 static const u8 gost_R3410_2012_256_paramSetC_oid[] = "1.2.643.7.1.2.1.1.3"; 252 TO_EC_STR_PARAM(gost_R3410_2012_256_paramSetC_oid); 253 254 static const ec_str_params gost_R3410_2012_256_paramSetC_str_params = { 255 .p = &gost_R3410_2012_256_paramSetC_p_str_param, 256 .p_bitlen = &gost_R3410_2012_256_paramSetC_p_bitlen_str_param, 257 .r = &gost_R3410_2012_256_paramSetC_r_str_param, 258 .r_square = &gost_R3410_2012_256_paramSetC_r_square_str_param, 259 .mpinv = &gost_R3410_2012_256_paramSetC_mpinv_str_param, 260 .p_shift = &gost_R3410_2012_256_paramSetC_p_shift_str_param, 261 .p_normalized = &gost_R3410_2012_256_paramSetC_p_normalized_str_param, 262 .p_reciprocal = &gost_R3410_2012_256_paramSetC_p_reciprocal_str_param, 263 .a = &gost_R3410_2012_256_paramSetC_a_str_param, 264 .b = &gost_R3410_2012_256_paramSetC_b_str_param, 265 .curve_order = &gost_R3410_2012_256_paramSetC_curve_order_str_param, 266 .gx = &gost_R3410_2012_256_paramSetC_gx_str_param, 267 .gy = &gost_R3410_2012_256_paramSetC_gy_str_param, 268 .gz = &gost_R3410_2012_256_paramSetC_gz_str_param, 269 .gen_order = &gost_R3410_2012_256_paramSetC_gen_order_str_param, 270 .gen_order_bitlen = &gost_R3410_2012_256_paramSetC_gen_order_bitlen_str_param, 271 .cofactor = &gost_R3410_2012_256_paramSetC_cofactor_str_param, 272 .alpha_montgomery = &gost_R3410_2012_256_paramSetC_alpha_montgomery_str_param, 273 .gamma_montgomery = &gost_R3410_2012_256_paramSetC_gamma_montgomery_str_param, 274 .alpha_edwards = &gost_R3410_2012_256_paramSetC_alpha_edwards_str_param, 275 .oid = &gost_R3410_2012_256_paramSetC_oid_str_param, 276 .name = &gost_R3410_2012_256_paramSetC_name_str_param, 277 }; 278 279 /* 280 * Compute max bit length of all curves for p and q 281 */ 282 #ifndef CURVES_MAX_P_BIT_LEN 283 #define CURVES_MAX_P_BIT_LEN 0 284 #endif 285 #if (CURVES_MAX_P_BIT_LEN < CURVE_GOST_R3410_2012_256_PARAMSETC_P_BITLEN) 286 #undef CURVES_MAX_P_BIT_LEN 287 #define CURVES_MAX_P_BIT_LEN CURVE_GOST_R3410_2012_256_PARAMSETC_P_BITLEN 288 #endif 289 #ifndef CURVES_MAX_Q_BIT_LEN 290 #define CURVES_MAX_Q_BIT_LEN 0 291 #endif 292 #if (CURVES_MAX_Q_BIT_LEN < CURVE_GOST_R3410_2012_256_PARAMSETC_Q_BITLEN) 293 #undef CURVES_MAX_Q_BIT_LEN 294 #define CURVES_MAX_Q_BIT_LEN CURVE_GOST_R3410_2012_256_PARAMSETC_Q_BITLEN 295 #endif 296 #ifndef CURVES_MAX_CURVE_ORDER_BIT_LEN 297 #define CURVES_MAX_CURVE_ORDER_BIT_LEN 0 298 #endif 299 #if (CURVES_MAX_CURVE_ORDER_BIT_LEN < CURVE_GOST_R3410_2012_256_PARAMSETC_CURVE_ORDER_BITLEN) 300 #undef CURVES_MAX_CURVE_ORDER_BIT_LEN 301 #define CURVES_MAX_CURVE_ORDER_BIT_LEN CURVE_GOST_R3410_2012_256_PARAMSETC_CURVE_ORDER_BITLEN 302 #endif 303 304 /* 305 * Compute and adapt max name and oid length 306 */ 307 #ifndef MAX_CURVE_OID_LEN 308 #define MAX_CURVE_OID_LEN 0 309 #endif 310 #ifndef MAX_CURVE_NAME_LEN 311 #define MAX_CURVE_NAME_LEN 0 312 #endif 313 #if (MAX_CURVE_OID_LEN < 20) 314 #undef MAX_CURVE_OID_LEN 315 #define MAX_CURVE_OID_LEN 20 316 #endif 317 #if (MAX_CURVE_NAME_LEN < 50) 318 #undef MAX_CURVE_NAME_LEN 319 #define MAX_CURVE_NAME_LEN 50 320 #endif 321 322 #endif /* __EC_PARAMS_GOST_R3410_2012_256_PARAMSETC_H__ */ 323 324 #endif /* WITH_CURVE_GOST_R3410_2012_256_PARAMSETC */ 325