1 /* 2 * Copyright (C) 2022 - This file is part of libecc project 3 * 4 * Authors: 5 * Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr> 6 * Ryad BENADJILA <ryadbenadjila@gmail.com> 7 * 8 * This software is licensed under a dual BSD and GPL v2 license. 9 * See LICENSE file at the root folder of the project. 10 */ 11 #ifndef __BIGN_TEST_VECTORS_H__ 12 #define __BIGN_TEST_VECTORS_H__ 13 14 #if defined(WITH_HASH_BELT_HASH) && defined(WITH_CURVE_BIGN256V1) 15 /************************************************/ 16 static const u8 bign_1_test_vectors_priv_key[] = { 17 0x69, 0xe2, 0x73, 0xc2, 0x5f, 0x23, 0x79, 0x0c, 0x9e, 0x42, 0x32, 0x07, 0xed, 0x1f, 0x28, 0x34, 0x18, 0xf2, 0x74, 0x9c, 0x32, 0xf0, 0x33, 0x45, 0x67, 0x39, 0x73, 0x4b, 0xb8, 0xb5, 0x66, 0x1f, 18 }; 19 static const u8 bign_1_test_vectors_expected_sig[] = { 20 0xE3, 0x6B, 0x7F, 0x03, 0x77, 0xAE, 0x4C, 0x52, 0x40, 0x27, 0xC3, 0x87, 0xFA, 0xDF, 0x1B, 0x20, 0xCE, 0x72, 0xF1, 0x53, 0x0B, 0x71, 0xF2, 0xB5, 0xFD, 0x3A, 0x8C, 0x58, 0x4F, 0xE2, 0xE1, 0xAE, 0xD2, 0x00, 0x82, 0xE3, 0x0C, 0x8A, 0xF6, 0x50, 0x11, 0xF4, 0xFB, 0x54, 0x64, 0x9D, 0xFD, 0x3D, 21 }; 22 static int bign_1_nn_random_belt_hash_test_vector(nn_t out, nn_src_t q) 23 { 24 int ret, cmp; 25 26 /* 27 * Fixed ephemeral private key for bign signature 28 * test vectors from STB 34.101.45-2013 29 */ 30 const u8 k_buf[] = { 31 0xd2, 0xb7, 0x08, 0xa3, 0x7a, 0xa7, 0x33, 0x5c, 0xe1, 0x1c, 0x46, 0x3c, 0x48, 0xec, 0xd6, 0x3e, 0x2c, 0x74, 0xfa, 0xe0, 0xe7, 0x3d, 0xf2, 0x21, 0xad, 0x11, 0x58, 0xcd, 0xb2, 0x74, 0x0e, 0x4c, 32 }; 33 34 ret = nn_init_from_buf(out, k_buf, sizeof(k_buf)); EG(ret, err); 35 ret = nn_cmp(out, q, &cmp); EG(ret, err); 36 37 ret = (cmp >= 0) ? -1 : 0; 38 39 err: 40 return ret; 41 } 42 static const u8 bign_1_test_vectors_adata[] = { 43 0x00, 0x0b, 0x00, 0x00, 44 0x06, 0x09, 0x2A, 0x70, 0x00, 0x02, 0x00, 0x22, 0x65, 0x1F, 0x51, 45 }; 46 47 static const ec_test_case bign_1_test_case = { 48 .name = "BIGN-BELT-HASH/bign256v1 1", 49 .ec_str_p = &bign256v1_str_params, 50 .priv_key = bign_1_test_vectors_priv_key, 51 .priv_key_len = sizeof(bign_1_test_vectors_priv_key), 52 .nn_random = bign_1_nn_random_belt_hash_test_vector, 53 .hash_type = BELT_HASH, 54 .msg = "\xB1\x94\xBA\xC8\x0A\x08\xF5\x3B\x36\x6D\x00\x8E\x58", 55 .msglen = 13, 56 .sig_type = BIGN, 57 .exp_sig = bign_1_test_vectors_expected_sig, 58 .exp_siglen = sizeof(bign_1_test_vectors_expected_sig), 59 .adata = bign_1_test_vectors_adata, 60 .adata_len = sizeof(bign_1_test_vectors_adata) 61 }; 62 63 /********************************************************************/ 64 static const u8 bign_2_test_vectors_priv_key[] = { 65 0x69, 0xe2, 0x73, 0xc2, 0x5f, 0x23, 0x79, 0x0c, 0x9e, 0x42, 0x32, 0x07, 0xed, 0x1f, 0x28, 0x34, 0x18, 0xf2, 0x74, 0x9c, 0x32, 0xf0, 0x33, 0x45, 0x67, 0x39, 0x73, 0x4b, 0xb8, 0xb5, 0x66, 0x1f, 66 }; 67 static const u8 bign_2_test_vectors_expected_sig[] = { 68 0x47, 0xA6, 0x3C, 0x8B, 0x9C, 0x93, 0x6E, 0x94, 0xB5, 0xFA, 0xB3, 0xD9, 0xCB, 0xD7, 0x83, 0x66, 69 0x29, 0x0F, 0x32, 0x10, 0xE1, 0x63, 0xEE, 0xC8, 0xDB, 0x4E, 0x92, 0x1E, 0x84, 0x79, 0xD4, 0x13, 0x8F, 0x11, 0x2C, 0xC2, 0x3E, 0x6D, 0xCE, 0x65, 0xEC, 0x5F, 0xF2, 0x1D, 0xF4, 0x23, 0x1C, 0x28, 70 }; 71 static int bign_2_nn_random_belt_hash_test_vector(nn_t out, nn_src_t q) 72 { 73 int ret, cmp; 74 75 /* 76 * Fixed ephemeral private key for bign signature 77 * test vectors from STB 34.101.45-2013 78 * NOTE: the ephemeral private key has been recomputed using the private key as 79 * it is not explicitly provided by the example. 80 */ 81 const u8 k_buf[] = { 82 0xec, 0xe9, 0xbc, 0x3b, 0xd9, 0x90, 0x03, 0x0f, 0x4f, 0x28, 0x39, 0x0d, 0xdd, 0x51, 0x22, 0x57, 0x15, 0x44, 0x7f, 0x63, 0x9f, 0x40, 0x19, 0x6f, 0xe4, 0x39, 0x08, 0xbe, 0x98, 0x82, 0x4e, 0x0a, 83 }; 84 85 ret = nn_init_from_buf(out, k_buf, sizeof(k_buf)); EG(ret, err); 86 ret = nn_cmp(out, q, &cmp); EG(ret, err); 87 88 ret = (cmp >= 0) ? -1 : 0; 89 90 err: 91 return ret; 92 } 93 static const u8 bign_2_test_vectors_adata[] = { 94 0x00, 0x0b, 0x00, 0x00, 95 0x06, 0x09, 0x2A, 0x70, 0x00, 0x02, 0x00, 0x22, 0x65, 0x1F, 0x51, 96 }; 97 98 static const ec_test_case bign_2_test_case = { 99 .name = "BIGN-BELT-HASH/bign256v1 2", 100 .ec_str_p = &bign256v1_str_params, 101 .priv_key = bign_2_test_vectors_priv_key, 102 .priv_key_len = sizeof(bign_2_test_vectors_priv_key), 103 .nn_random = bign_2_nn_random_belt_hash_test_vector, 104 .hash_type = BELT_HASH, 105 .msg = "\xB1\x94\xBA\xC8\x0A\x08\xF5\x3B\x36\x6D\x00\x8E\x58\x4A\x5D\xE4\x85\x04\xFA\x9D\x1B\xB6\xC7\xAC\x25\x2E\x72\xC2\x02\xFD\xCE\x0D\x5B\xE3\xD6\x12\x17\xB9\x61\x81\xFE\x67\x86\xAD\x71\x6B\x89\x0B", 106 .msglen = 48, 107 .sig_type = BIGN, 108 .exp_sig = bign_2_test_vectors_expected_sig, 109 .exp_siglen = sizeof(bign_2_test_vectors_expected_sig), 110 .adata = bign_2_test_vectors_adata, 111 .adata_len = sizeof(bign_2_test_vectors_adata) 112 }; 113 114 /************************************************/ 115 static const u8 bign_3_test_vectors_priv_key[] = { 116 0x69, 0xe2, 0x73, 0xc2, 0x5f, 0x23, 0x79, 0x0c, 0x9e, 0x42, 0x32, 0x07, 0xed, 0x1f, 0x28, 0x34, 0x18, 0xf2, 0x74, 0x9c, 0x32, 0xf0, 0x33, 0x45, 0x67, 0x39, 0x73, 0x4b, 0xb8, 0xb5, 0x66, 0x1f, 117 }; 118 static const u8 bign_3_test_vectors_expected_sig[] = { 119 0x19, 0xD3, 0x2B, 0x7E, 0x01, 0xE2, 0x5B, 0xAE, 0x4A, 0x70, 0xEB, 0x6B, 0xCA, 0x42, 0x60, 0x2C, 120 0xCA, 0x6A, 0x13, 0x94, 0x44, 0x51, 0xBC, 0xC5, 0xD4, 0xC5, 0x4C, 0xFD, 0x87, 0x37, 0x61, 0x9C, 0x32, 0x8B, 0x8A, 0x58, 0xFB, 0x9C, 0x68, 0xFD, 0x17, 0xD5, 0x69, 0xF7, 0xD0, 0x64, 0x95, 0xFB, 121 }; 122 static int bign_3_nn_random_belt_hash_test_vector(nn_t out, nn_src_t q) 123 { 124 int ret, cmp; 125 126 /* 127 * Fixed ephemeral private key for bign signature 128 */ 129 const u8 k_buf[] = { 130 0x1e, 0x11, 0x97, 0xae, 0x17, 0xe4, 0x5c, 0xa4, 0xa1, 0xb6, 0xfa, 0x53, 0x95, 0x8c, 0xfd, 0x40, 0x64, 0x58, 0x04, 0x40, 0x1a, 0x47, 0xf2, 0xe1, 0xc4, 0xbb, 0x1d, 0x41, 0xd8, 0x14, 0x96, 0x82, 131 }; 132 133 ret = nn_init_from_buf(out, k_buf, sizeof(k_buf)); EG(ret, err); 134 ret = nn_cmp(out, q, &cmp); EG(ret, err); 135 136 ret = (cmp >= 0) ? -1 : 0; 137 138 err: 139 return ret; 140 } 141 static const u8 bign_3_test_vectors_adata[] = { 142 0x00, 0x0b, 0x00, 0x00, 143 0x06, 0x09, 0x2A, 0x70, 0x00, 0x02, 0x00, 0x22, 0x65, 0x1F, 0x51, 144 }; 145 146 static const ec_test_case bign_3_test_case = { 147 .name = "BIGN-BELT-HASH/bign256v1 3", 148 .ec_str_p = &bign256v1_str_params, 149 .priv_key = bign_3_test_vectors_priv_key, 150 .priv_key_len = sizeof(bign_3_test_vectors_priv_key), 151 .nn_random = bign_3_nn_random_belt_hash_test_vector, 152 .hash_type = BELT_HASH, 153 .msg = "\xB1\x94\xBA\xC8\x0A\x08\xF5\x3B\x36\x6D\x00\x8E\x58", 154 .msglen = 13, 155 .sig_type = BIGN, 156 .exp_sig = bign_3_test_vectors_expected_sig, 157 .exp_siglen = sizeof(bign_3_test_vectors_expected_sig), 158 .adata = bign_3_test_vectors_adata, 159 .adata_len = sizeof(bign_3_test_vectors_adata) 160 }; 161 162 /********************************************************************/ 163 static const u8 bign_4_test_vectors_priv_key[] = { 164 0x69, 0xe2, 0x73, 0xc2, 0x5f, 0x23, 0x79, 0x0c, 0x9e, 0x42, 0x32, 0x07, 0xed, 0x1f, 0x28, 0x34, 0x18, 0xf2, 0x74, 0x9c, 0x32, 0xf0, 0x33, 0x45, 0x67, 0x39, 0x73, 0x4b, 0xb8, 0xb5, 0x66, 0x1f, 165 }; 166 static const u8 bign_4_test_vectors_expected_sig[] = { 167 0x47, 0xA6, 0x3C, 0x8B, 0x9C, 0x93, 0x6E, 0x94, 0xB5, 0xFA, 0xB3, 0xD9, 0xCB, 0xD7, 0x83, 0x66, 168 0x29, 0x0F, 0x32, 0x10, 0xE1, 0x63, 0xEE, 0xC8, 0xDB, 0x4E, 0x92, 0x1E, 0x84, 0x79, 0xD4, 0x13, 0x8F, 0x11, 0x2C, 0xC2, 0x3E, 0x6D, 0xCE, 0x65, 0xEC, 0x5F, 0xF2, 0x1D, 0xF4, 0x23, 0x1C, 0x28, 169 }; 170 static int bign_4_nn_random_belt_hash_test_vector(nn_t out, nn_src_t q) 171 { 172 int ret, cmp; 173 174 /* 175 * Fixed ephemeral private key for bign signature 176 * test vectors from STB 34.101.45-2013 177 * NOTE: the ephemeral private key has been recomputed using the private key as 178 * it is not explicitly provided by the example. 179 */ 180 const u8 k_buf[] = { 181 0xec, 0xe9, 0xbc, 0x3b, 0xd9, 0x90, 0x03, 0x0f, 0x4f, 0x28, 0x39, 0x0d, 0xdd, 0x51, 0x22, 0x57, 0x15, 0x44, 0x7f, 0x63, 0x9f, 0x40, 0x19, 0x6f, 0xe4, 0x39, 0x08, 0xbe, 0x98, 0x82, 0x4e, 0x0a, 182 }; 183 184 ret = nn_init_from_buf(out, k_buf, sizeof(k_buf)); EG(ret, err); 185 ret = nn_cmp(out, q, &cmp); EG(ret, err); 186 187 ret = (cmp >= 0) ? -1 : 0; 188 189 err: 190 return ret; 191 } 192 static const u8 bign_4_test_vectors_adata[] = { 193 0x00, 0x0b, 0x00, 0x00, 194 0x06, 0x09, 0x2A, 0x70, 0x00, 0x02, 0x00, 0x22, 0x65, 0x1F, 0x51, 195 }; 196 197 static const ec_test_case bign_4_test_case = { 198 .name = "BIGN-BELT-HASH/bign256v1 4", 199 .ec_str_p = &bign256v1_str_params, 200 .priv_key = bign_4_test_vectors_priv_key, 201 .priv_key_len = sizeof(bign_4_test_vectors_priv_key), 202 .nn_random = bign_4_nn_random_belt_hash_test_vector, 203 .hash_type = BELT_HASH, 204 .msg = "\xB1\x94\xBA\xC8\x0A\x08\xF5\x3B\x36\x6D\x00\x8E\x58\x4A\x5D\xE4\x85\x04\xFA\x9D\x1B\xB6\xC7\xAC\x25\x2E\x72\xC2\x02\xFD\xCE\x0D\x5B\xE3\xD6\x12\x17\xB9\x61\x81\xFE\x67\x86\xAD\x71\x6B\x89\x0B", 205 .msglen = 48, 206 .sig_type = BIGN, 207 .exp_sig = bign_4_test_vectors_expected_sig, 208 .exp_siglen = sizeof(bign_4_test_vectors_expected_sig), 209 .adata = bign_4_test_vectors_adata, 210 .adata_len = sizeof(bign_4_test_vectors_adata) 211 }; 212 #endif 213 214 #if defined(WITH_HASH_BASH384) && defined(WITH_CURVE_BIGN384V1) 215 /********************************************************************/ 216 static const u8 bign_5_test_vectors_priv_key[] = { 217 0x0e, 0xb5, 0x93, 0x2d, 0x23, 0x1a, 0xe1, 0x37, 0x61, 0x41, 0x80, 0xec, 0x3b, 0xbe, 0x08, 0x0f, 0x93, 0xba, 0x80, 0x27, 0x8f, 0x05, 0xd8, 0x2f, 0x87, 0x6a, 0xf9, 0xf9, 0xea, 0x0a, 0xf1, 0x9e, 0x6c, 0xa1, 0x6f, 0x21, 0x6c, 0x38, 0x21, 0xdc, 0x72, 0x23, 0x3c, 0x7b, 0xbf, 0x1d, 0xc2, 0x84, 218 }; 219 static const u8 bign_5_test_vectors_expected_sig[] = { 220 0xA7, 0xFC, 0x9D, 0x62, 0xB6, 0x85, 0x9E, 0xBB, 0x0A, 0x98, 0xAA, 0xE3, 0x6B, 0xE4, 0x79, 0x69, 221 0xC3, 0x62, 0xB6, 0x66, 0x95, 0x75, 0x0D, 0xDD, 0x2C, 0xA1, 0x75, 0x32, 0x18, 0x26, 0xD4, 0xBC, 222 0x8F, 0x78, 0xEB, 0xF5, 0x55, 0xA8, 0x71, 0x21, 0x3F, 0xEC, 0x6B, 0x50, 0xA6, 0x3D, 0x30, 0xC5, 223 0x89, 0x73, 0x3B, 0x0A, 0x56, 0xF6, 0xC0, 0xC2, 0xBC, 0x03, 0xA3, 0x53, 0x29, 0x69, 0xCD, 0xF0, 224 0x11, 0xDC, 0x28, 0xD4, 0x84, 0x4E, 0x79, 0xEC, 225 }; 226 static int bign_5_nn_random_belt_hash_test_vector(nn_t out, nn_src_t q) 227 { 228 int ret, cmp; 229 230 /* 231 * Fixed ephemeral private key for bign signature 232 */ 233 const u8 k_buf[] = { 234 0x15, 0xf4, 0x26, 0x4c, 0xa3, 0x51, 0x9a, 0xa6, 0x0a, 0xd8, 0xae, 0x14, 0x79, 0x31, 0x73, 235 0x19, 0x80, 0xa8, 0xe1, 0xc3, 0x61, 0x0d, 0xa5, 0xdd, 0xa3, 0x17, 0xea, 0x54, 0xca, 0x73, 236 0x3a, 0xa1, 0xe7, 0x1d, 0x1a, 0x5b, 0x0a, 0xc1, 0xae, 0x49, 0xbc, 0xd0, 0x90, 0x02, 0xc1, 237 0x9d, 0x3c, 0x19, 238 }; 239 240 ret = nn_init_from_buf(out, k_buf, sizeof(k_buf)); EG(ret, err); 241 ret = nn_cmp(out, q, &cmp); EG(ret, err); 242 243 ret = (cmp >= 0) ? -1 : 0; 244 245 err: 246 return ret; 247 } 248 static const u8 bign_5_test_vectors_adata[] = { 249 0x00, 0x0b, 0x00, 0x00, 250 0x06, 0x09, 0x2A, 0x70, 0x00, 0x02, 0x00, 0x22, 0x65, 0x4d, 0x0c, 251 }; 252 253 static const ec_test_case bign_5_test_case = { 254 .name = "BIGN-BASH384/bign384v1 5", 255 .ec_str_p = &bign384v1_str_params, 256 .priv_key = bign_5_test_vectors_priv_key, 257 .priv_key_len = sizeof(bign_5_test_vectors_priv_key), 258 .nn_random = bign_5_nn_random_belt_hash_test_vector, 259 .hash_type = BASH384, 260 .msg = "\xb1\x94\xba\xc8\x0a\x08\xf5\x3b\x36\x6d\x00\x8e\x58\x4a\x5d\xe4\x85\x04\xfa\x9d\x1b\xb6\xc7\xac\x25\x2e\x72\xc2\x02\xfd\xce\x0d\x5b\xe3\xd6\x12\x17\xb9\x61\x81\xfe\x67\x86\xad\x71\x6b\x89\x0b\x5c\xb0\xc0\xff\x33\xc3\x56\xb8\x35\xc4\x05\xae\xd8\xe0\x7f\x99\xe1\x2b\xdc\x1a\xe2\x82\x57\xec\x70\x3f\xcc\xf0\x95\xee\x8d\xf1\xc1\xab\x76\x38\x9f\xe6\x78\xca\xf7\xc6\xf8\x60\xd5\xbb\x9c", 261 .msglen = 95, 262 .sig_type = BIGN, 263 .exp_sig = bign_5_test_vectors_expected_sig, 264 .exp_siglen = sizeof(bign_5_test_vectors_expected_sig), 265 .adata = bign_5_test_vectors_adata, 266 .adata_len = sizeof(bign_5_test_vectors_adata) 267 }; 268 /********************************************************************/ 269 static const u8 bign_6_test_vectors_priv_key[] = { 270 0x0e, 0xb5, 0x93, 0x2d, 0x23, 0x1a, 0xe1, 0x37, 0x61, 0x41, 0x80, 0xec, 0x3b, 0xbe, 0x08, 0x0f, 0x93, 0xba, 0x80, 0x27, 0x8f, 0x05, 0xd8, 0x2f, 0x87, 0x6a, 0xf9, 0xf9, 0xea, 0x0a, 0xf1, 0x9e, 0x6c, 0xa1, 0x6f, 0x21, 0x6c, 0x38, 0x21, 0xdc, 0x72, 0x23, 0x3c, 0x7b, 0xbf, 0x1d, 0xc2, 0x84, 271 }; 272 static const u8 bign_6_test_vectors_expected_sig[] = { 273 0x51, 0xD1, 0x1A, 0xBB, 0x63, 0x92, 0xD9, 0x04, 0x06, 0x85, 0xC4, 0xCC, 0x3A, 0x87, 0x55, 0x3B, 274 0xAF, 0x47, 0x44, 0x81, 0x19, 0x86, 0x02, 0xFC, 0xF1, 0x80, 0xDD, 0x0E, 0x0F, 0x00, 0x76, 0xB7, 275 0x5A, 0x9B, 0x87, 0x52, 0x69, 0x56, 0x09, 0x30, 0x80, 0xDA, 0x21, 0xAC, 0xFE, 0x73, 0xA7, 0x0E, 276 0xEF, 0x4E, 0x5C, 0xEA, 0xE8, 0xC0, 0x7C, 0xDB, 0xA5, 0x26, 0xCF, 0xA3, 0xF6, 0xC5, 0x0D, 0xFD, 277 0x4E, 0x8E, 0x88, 0x17, 0xC1, 0xAE, 0x62, 0x4B, 278 }; 279 static int bign_6_nn_random_belt_hash_test_vector(nn_t out, nn_src_t q) 280 { 281 int ret, cmp; 282 283 /* 284 * Fixed ephemeral private key for bign signature 285 */ 286 const u8 k_buf[] = { 287 0x15, 0xf4, 0x26, 0x4c, 0xa3, 0x51, 0x9a, 0xa6, 0x0a, 0xd8, 0xae, 0x14, 0x79, 0x31, 0x73, 288 0x19, 0x80, 0xa8, 0xe1, 0xc3, 0x61, 0x0d, 0xa5, 0xdd, 0xa3, 0x17, 0xea, 0x54, 0xca, 0x73, 289 0x3a, 0xa1, 0xe7, 0x1d, 0x1a, 0x5b, 0x0a, 0xc1, 0xae, 0x49, 0xbc, 0xd0, 0x90, 0x02, 0xc1, 290 0x9d, 0x3c, 0x19, 291 292 }; 293 294 ret = nn_init_from_buf(out, k_buf, sizeof(k_buf)); EG(ret, err); 295 ret = nn_cmp(out, q, &cmp); EG(ret, err); 296 297 ret = (cmp >= 0) ? -1 : 0; 298 299 err: 300 return ret; 301 } 302 static const u8 bign_6_test_vectors_adata[] = { 303 0x00, 0x0b, 0x00, 0x00, 304 0x06, 0x09, 0x2A, 0x70, 0x00, 0x02, 0x00, 0x22, 0x65, 0x4d, 0x0c, 305 }; 306 307 static const ec_test_case bign_6_test_case = { 308 .name = "BIGN-BASH384/bign384v1 6", 309 .ec_str_p = &bign384v1_str_params, 310 .priv_key = bign_6_test_vectors_priv_key, 311 .priv_key_len = sizeof(bign_6_test_vectors_priv_key), 312 .nn_random = bign_6_nn_random_belt_hash_test_vector, 313 .hash_type = BASH384, 314 .msg = "\xb1\x94\xba\xc8\x0a\x08\xf5\x3b\x36\x6d\x00\x8e\x58\x4a\x5d\xe4\x85\x04\xfa\x9d\x1b\xb6\xc7\xac\x25\x2e\x72\xc2\x02\xfd\xce\x0d\x5b\xe3\xd6\x12\x17\xb9\x61\x81\xfe\x67\x86\xad\x71\x6b\x89\x0b\x5c\xb0\xc0\xff\x33\xc3\x56\xb8\x35\xc4\x05\xae\xd8\xe0\x7f\x99\xe1\x2b\xdc\x1a\xe2\x82\x57\xec\x70\x3f\xcc\xf0\x95\xee\x8d\xf1\xc1\xab\x76\x38\x9f\xe6\x78\xca\xf7\xc6\xf8\x60\xd5\xbb\x9c\x4f", 315 .msglen = 96, 316 .sig_type = BIGN, 317 .exp_sig = bign_6_test_vectors_expected_sig, 318 .exp_siglen = sizeof(bign_6_test_vectors_expected_sig), 319 .adata = bign_6_test_vectors_adata, 320 .adata_len = sizeof(bign_6_test_vectors_adata) 321 }; 322 323 #endif 324 325 326 #if defined(WITH_HASH_BASH512) && defined(WITH_CURVE_BIGN512V1) 327 /********************************************************************/ 328 static const u8 bign_7_test_vectors_priv_key[] = { 329 0xb8, 0xb9, 0x4a, 0xd2, 0xe5, 0x05, 0x02, 0xc5, 0x21, 0xe8, 0x8f, 0x1b, 0xcf, 0x97, 0x0b, 0x1b, 0x47, 0x78, 0x02, 0x31, 0x5b, 0xfe, 0x1f, 0x71, 0xd8, 0x55, 0x71, 0xa2, 0xd1, 0xc1, 0x90, 0x60, 0xba, 0xa2, 0xf1, 0xe0, 0x7d, 0x73, 0xd5, 0x2f, 0x37, 0x31, 0x0b, 0x04, 0x02, 0x3a, 0xbf, 0x33, 0x63, 0xb5, 0xf2, 0x95, 0x2a, 0x62, 0x17, 0xa4, 0x8a, 0x56, 0xf4, 0x3e, 0x35, 0x96, 0xc0, 0xbe, 330 }; 331 static const u8 bign_7_test_vectors_expected_sig[] = { 332 0xF9, 0x22, 0xD7, 0x01, 0x48, 0xC5, 0x5A, 0xD5, 0x47, 0xEB, 0x0A, 0x19, 0x30, 0xE5, 0x2C, 0xC5, 0x52, 0xD9, 0x28, 0xDC, 0x76, 0xE4, 0x03, 0x0C, 0x9E, 0xE5, 0x7D, 0xE8, 333 0xDE, 0xD1, 0xB5, 0xF9, 0x5D, 0x4E, 0x33, 0xF4, 0x7C, 0xD3, 0x61, 0xDA, 0xCB, 0x1F, 0x26, 0xB2, 0x01, 0x32, 0xE4, 0x5D, 0x49, 0x88, 0xFB, 0x86, 0xAF, 0x1B, 0x54, 0x65, 334 0x8F, 0xE2, 0xFE, 0x97, 0x11, 0x61, 0x77, 0xF5, 0xD3, 0x11, 0x7C, 0xE0, 0x63, 0x2D, 0xDF, 0xAA, 0x8E, 0xDE, 0x10, 0xDA, 0x7D, 0xF8, 0x35, 0xD2, 0x72, 0x5E, 0x2B, 0x83, 0x4C, 0xA9, 0x6C, 0x8C, 0x06, 0x1B, 0xC8, 0x31, 0xDF, 0xA5, 0xB3, 0x16, 335 }; 336 static int bign_7_nn_random_belt_hash_test_vector(nn_t out, nn_src_t q) 337 { 338 int ret, cmp; 339 340 /* 341 * Fixed ephemeral private key for bign signature 342 */ 343 const u8 k_buf[] = { 344 0x62, 0x64, 0x5d, 0x68, 0xca, 0x6f, 0xb3, 0x52, 0x10, 0xf6, 0xdb, 0x92, 0xe2, 345 0xe7, 0x86, 0xee, 0x34, 0x65, 0xdd, 0xc9, 0x62, 0xbe, 0x99, 0x70, 0xfe, 0x1c, 346 0x12, 0xe6, 0xe7, 0xca, 0x95, 0xe9, 0x1a, 0xe0, 0x7b, 0x65, 0x9a, 0x8b, 0x7c, 347 0x03, 0xf9, 0xb7, 0x2e, 0x64, 0x1f, 0xef, 0xdc, 0x5b, 0x7a, 0xb6, 0xcd, 0x8c, 348 0x03, 0x95, 0xe3, 0x80, 0xb9, 0x2c, 0x2f, 0xfd, 0x19, 0xe7, 0x83, 0x2c, 349 }; 350 351 ret = nn_init_from_buf(out, k_buf, sizeof(k_buf)); EG(ret, err); 352 ret = nn_cmp(out, q, &cmp); EG(ret, err); 353 354 ret = (cmp >= 0) ? -1 : 0; 355 356 err: 357 return ret; 358 } 359 static const u8 bign_7_test_vectors_adata[] = { 360 0x00, 0x0b, 0x00, 0x00, 361 0x06, 0x09, 0x2A, 0x70, 0x00, 0x02, 0x00, 0x22, 0x65, 0x4d, 0x0d, 362 }; 363 364 static const ec_test_case bign_7_test_case = { 365 .name = "BIGN-BASH512/bign512v1 7", 366 .ec_str_p = &bign512v1_str_params, 367 .priv_key = bign_7_test_vectors_priv_key, 368 .priv_key_len = sizeof(bign_7_test_vectors_priv_key), 369 .nn_random = bign_7_nn_random_belt_hash_test_vector, 370 .hash_type = BASH512, 371 .msg = "\xb1\x94\xba\xc8\x0a\x08\xf5\x3b\x36\x6d\x00\x8e\x58\x4a\x5d\xe4\x85\x04\xfa\x9d\x1b\xb6\xc7\xac\x25\x2e\x72\xc2\x02\xfd\xce\x0d\x5b\xe3\xd6\x12\x17\xb9\x61\x81\xfe\x67\x86\xad\x71\x6b\x89\x0b\x5c\xb0\xc0\xff\x33\xc3\x56\xb8\x35\xc4\x05\xae\xd8\xe0\x7f", 372 .msglen = 63, 373 .sig_type = BIGN, 374 .exp_sig = bign_7_test_vectors_expected_sig, 375 .exp_siglen = sizeof(bign_7_test_vectors_expected_sig), 376 .adata = bign_7_test_vectors_adata, 377 .adata_len = sizeof(bign_7_test_vectors_adata) 378 }; 379 380 /********************************************************************/ 381 static const u8 bign_8_test_vectors_priv_key[] = { 382 0xb8, 0xb9, 0x4a, 0xd2, 0xe5, 0x05, 0x02, 0xc5, 0x21, 0xe8, 0x8f, 0x1b, 0xcf, 0x97, 0x0b, 0x1b, 0x47, 0x78, 0x02, 0x31, 0x5b, 0xfe, 0x1f, 0x71, 0xd8, 0x55, 0x71, 0xa2, 0xd1, 0xc1, 0x90, 0x60, 0xba, 0xa2, 0xf1, 0xe0, 0x7d, 0x73, 0xd5, 0x2f, 0x37, 0x31, 0x0b, 0x04, 0x02, 0x3a, 0xbf, 0x33, 0x63, 0xb5, 0xf2, 0x95, 0x2a, 0x62, 0x17, 0xa4, 0x8a, 0x56, 0xf4, 0x3e, 0x35, 0x96, 0xc0, 0xbe, 383 }; 384 static const u8 bign_8_test_vectors_expected_sig[] = { 385 0x4B, 0x47, 0x8B, 0x2B, 0x28, 0x79, 0x5A, 0x43, 0x8C, 0x3F, 0x4A, 0x70, 0xD7, 0xF3, 0x02, 0xD3, 386 0xD1, 0xB6, 0x15, 0xE9, 0x85, 0xCE, 0x22, 0xDA, 0x71, 0x22, 0xAE, 0x1E, 0xAB, 0x0D, 0xD9, 0x87, 387 0x92, 0x39, 0x94, 0x96, 0x8A, 0x24, 0xBF, 0x15, 0xC2, 0xE6, 0x59, 0xB4, 0x54, 0x6F, 0x83, 0xCF, 388 0x16, 0x49, 0x33, 0x38, 0x79, 0xD4, 0x79, 0x54, 0xC4, 0xAB, 0x7E, 0x41, 0x04, 0x6E, 0xB3, 0xD9, 389 0x27, 0x87, 0xF7, 0x85, 0xC9, 0x12, 0x30, 0xCD, 0x7E, 0x65, 0xE4, 0x55, 0x26, 0xD4, 0x56, 0x50, 390 0x92, 0x1D, 0x77, 0x2D, 0xD4, 0x2B, 0xD3, 0x52, 0x2C, 0xF7, 0xBD, 0x5F, 0x7D, 0x79, 0xAB, 0x65, 391 }; 392 static int bign_8_nn_random_belt_hash_test_vector(nn_t out, nn_src_t q) 393 { 394 int ret, cmp; 395 396 /* 397 * Fixed ephemeral private key for bign signature 398 */ 399 const u8 k_buf[] = { 400 0x62, 0x64, 0x5d, 0x68, 0xca, 0x6f, 0xb3, 0x52, 0x10, 0xf6, 0xdb, 0x92, 0xe2, 401 0xe7, 0x86, 0xee, 0x34, 0x65, 0xdd, 0xc9, 0x62, 0xbe, 0x99, 0x70, 0xfe, 0x1c, 402 0x12, 0xe6, 0xe7, 0xca, 0x95, 0xe9, 0x1a, 0xe0, 0x7b, 0x65, 0x9a, 0x8b, 0x7c, 403 0x03, 0xf9, 0xb7, 0x2e, 0x64, 0x1f, 0xef, 0xdc, 0x5b, 0x7a, 0xb6, 0xcd, 0x8c, 404 0x03, 0x95, 0xe3, 0x80, 0xb9, 0x2c, 0x2f, 0xfd, 0x19, 0xe7, 0x83, 0x2c, 405 }; 406 407 ret = nn_init_from_buf(out, k_buf, sizeof(k_buf)); EG(ret, err); 408 ret = nn_cmp(out, q, &cmp); EG(ret, err); 409 410 ret = (cmp >= 0) ? -1 : 0; 411 412 err: 413 return ret; 414 } 415 static const u8 bign_8_test_vectors_adata[] = { 416 0x00, 0x0b, 0x00, 0x00, 417 0x06, 0x09, 0x2A, 0x70, 0x00, 0x02, 0x00, 0x22, 0x65, 0x4d, 0x0d, 418 }; 419 420 static const ec_test_case bign_8_test_case = { 421 .name = "BIGN-BASH512/bign512v1 8", 422 .ec_str_p = &bign512v1_str_params, 423 .priv_key = bign_8_test_vectors_priv_key, 424 .priv_key_len = sizeof(bign_8_test_vectors_priv_key), 425 .nn_random = bign_8_nn_random_belt_hash_test_vector, 426 .hash_type = BASH512, 427 .msg = "\xb1\x94\xba\xc8\x0a\x08\xf5\x3b\x36\x6d\x00\x8e\x58\x4a\x5d\xe4\x85\x04\xfa\x9d\x1b\xb6\xc7\xac\x25\x2e\x72\xc2\x02\xfd\xce\x0d\x5b\xe3\xd6\x12\x17\xb9\x61\x81\xfe\x67\x86\xad\x71\x6b\x89\x0b\x5c\xb0\xc0\xff\x33\xc3\x56\xb8\x35\xc4\x05\xae\xd8\xe0\x7f\x99", 428 .msglen = 64, 429 .sig_type = BIGN, 430 .exp_sig = bign_8_test_vectors_expected_sig, 431 .exp_siglen = sizeof(bign_8_test_vectors_expected_sig), 432 .adata = bign_8_test_vectors_adata, 433 .adata_len = sizeof(bign_8_test_vectors_adata) 434 }; 435 #endif 436 437 /************************************************/ 438 #define BIGN_ALL_TESTS() \ 439 &bign_1_test_case, \ 440 &bign_2_test_case, \ 441 &bign_3_test_case, \ 442 &bign_4_test_case, \ 443 &bign_5_test_case, \ 444 &bign_6_test_case, \ 445 &bign_7_test_case, \ 446 &bign_8_test_case, 447 448 #endif /* __BIGN_TEST_VECTORS_H__ */ 449