Return to test_ecdsa.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libstrongswan / tests / suites |
1.1 misho 1: /* 2: * Copyright (C) 2013 Martin Willi 3: * Copyright (C) 2013 revosec AG 4: * 5: * This program is free software; you can redistribute it and/or modify it 6: * under the terms of the GNU General Public License as published by the 7: * Free Software Foundation; either version 2 of the License, or (at your 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 9: * 10: * This program is distributed in the hope that it will be useful, but 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13: * for more details. 14: */ 15: 16: #include "test_suite.h" 17: 18: #include <plugins/plugin_feature.h> 19: 20: /** 21: * Signature schemes to test 22: */ 23: static struct { 24: /* key size for scheme, 0 for any */ 25: int key_size; 26: signature_scheme_t scheme; 27: } schemes[] = { 28: { 0, SIGN_ECDSA_WITH_SHA1_DER }, 29: { 0, SIGN_ECDSA_WITH_SHA256_DER }, 30: { 0, SIGN_ECDSA_WITH_SHA384_DER }, 31: { 0, SIGN_ECDSA_WITH_SHA512_DER }, 32: { 0, SIGN_ECDSA_WITH_NULL }, 33: { 256, SIGN_ECDSA_256 }, 34: { 384, SIGN_ECDSA_384 }, 35: { 521, SIGN_ECDSA_521 }, 36: }; 37: 38: /** 39: * Perform a signature verification "good" test having a key pair 40: */ 41: static void test_good_sig(private_key_t *privkey, public_key_t *pubkey) 42: { 43: chunk_t sig, data = chunk_from_chars(0x01,0x02,0x03,0xFD,0xFE,0xFF); 44: int i; 45: 46: for (i = 0; i < countof(schemes); i++) 47: { 48: if (!lib->plugins->has_feature(lib->plugins, 49: PLUGIN_PROVIDE(PUBKEY_VERIFY, schemes[i].scheme)) || 50: !lib->plugins->has_feature(lib->plugins, 51: PLUGIN_PROVIDE(PRIVKEY_SIGN, schemes[i].scheme))) 52: { 53: continue; 54: } 55: if (schemes[i].key_size != 0 && 56: schemes[i].key_size != privkey->get_keysize(privkey)) 57: { 58: continue; 59: } 60: fail_unless(privkey->sign(privkey, schemes[i].scheme, NULL, data, &sig), 61: "sign %N", signature_scheme_names, schemes[i].scheme); 62: fail_unless(pubkey->verify(pubkey, schemes[i].scheme, NULL, data, sig), 63: "verify %N", signature_scheme_names, schemes[i].scheme); 64: free(sig.ptr); 65: } 66: } 67: 68: /** 69: * Some special signatures that should never validate successfully 70: */ 71: static chunk_t invalid_sigs[] = { 72: chunk_from_chars(), 73: chunk_from_chars(0x00), 74: chunk_from_chars(0x00,0x00), 75: chunk_from_chars(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00), 76: chunk_from_chars(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 77: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00), 78: chunk_from_chars(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 79: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 80: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00), 81: chunk_from_chars(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 82: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 83: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 84: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00), 85: chunk_from_chars(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 86: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 87: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 88: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 89: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 90: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00), 91: chunk_from_chars(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 92: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 93: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 94: 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 95: 0x00,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,0x00,0x00,0x00), 99: }; 100: 101: /** 102: * Check public key that it properly fails against some crafted sigs 103: */ 104: static void test_bad_sigs(public_key_t *pubkey) 105: { 106: chunk_t data = chunk_from_chars(0x01,0x02,0x03,0xFD,0xFE,0xFF); 107: int s, i; 108: 109: for (s = 0; s < countof(schemes); s++) 110: { 111: if (schemes[s].key_size != 0 && 112: schemes[s].key_size != pubkey->get_keysize(pubkey)) 113: { 114: continue; 115: } 116: if (!lib->plugins->has_feature(lib->plugins, 117: PLUGIN_PROVIDE(PUBKEY_VERIFY, schemes[s].scheme))) 118: { 119: continue; 120: } 121: for (i = 0; i < countof(invalid_sigs); i++) 122: { 123: fail_if( 124: pubkey->verify(pubkey, schemes[s].scheme, NULL, data, 125: invalid_sigs[i]), 126: "bad %N sig accepted %B", 127: signature_scheme_names, schemes[s].scheme, 128: &invalid_sigs[i]); 129: } 130: } 131: } 132: 133: /** 134: * ECDSA key sizes to test 135: */ 136: static int key_sizes[] = { 137: 256, 384, 521, 138: }; 139: 140: START_TEST(test_gen) 141: { 142: private_key_t *privkey; 143: public_key_t *pubkey; 144: 145: privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_ECDSA, 146: BUILD_KEY_SIZE, key_sizes[_i], BUILD_END); 147: ck_assert(privkey != NULL); 148: pubkey = privkey->get_public_key(privkey); 149: ck_assert(pubkey != NULL); 150: 151: test_good_sig(privkey, pubkey); 152: 153: test_bad_sigs(pubkey); 154: 155: pubkey->destroy(pubkey); 156: privkey->destroy(privkey); 157: } 158: END_TEST 159: 160: /** 161: * Private keys to load 162: */ 163: static struct { 164: chunk_t key; 165: chunk_t pkcs8; 166: chunk_t pub; 167: chunk_t fp_pk; 168: chunk_t fp_spki; 169: } keys[] = { 170: { chunk_from_chars( /* ECDSA-256 */ 171: 0x30,0x77,0x02,0x01,0x01,0x04,0x20,0x42,0xc6,0x8c,0xff,0x2b,0x8b,0x87,0xa1,0xfb, 172: 0x50,0xf6,0xfe,0xd6,0x88,0xb3,0x0a,0x48,0xb2,0xc5,0x8f,0x50,0xe0,0xcf,0x40,0xfa, 173: 0x57,0xd1,0xc6,0x6c,0x20,0x64,0xc5,0xa0,0x0a,0x06,0x08,0x2a,0x86,0x48,0xce,0x3d, 174: 0x03,0x01,0x07,0xa1,0x44,0x03,0x42,0x00,0x04,0x9c,0xb2,0x52,0xcb,0xc0,0x5c,0xcf, 175: 0x97,0xdd,0xd6,0xe7,0x49,0x32,0x47,0x0c,0x8e,0xdb,0x6d,0xbf,0xc8,0x1a,0x0a,0x01, 176: 0xe8,0x5e,0x3f,0x8e,0x64,0x33,0xb4,0x15,0xbb,0x1b,0xa5,0xed,0xf9,0x4b,0xa7,0xe8, 177: 0x5e,0x6f,0x49,0x24,0xf7,0x32,0xf4,0x9b,0x4c,0x47,0xdc,0xf1,0x28,0x44,0x1c,0x37, 178: 0xdb,0xee,0xfb,0xd8,0xbd,0x4e,0x5c,0xeb,0x07), 179: chunk_from_chars( 180: 0x30,0x81,0x87,0x02,0x01,0x00,0x30,0x13,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02, 181: 0x01,0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,0x03,0x01,0x07,0x04,0x6d,0x30,0x6b,0x02, 182: 0x01,0x01,0x04,0x20,0x42,0xc6,0x8c,0xff,0x2b,0x8b,0x87,0xa1,0xfb,0x50,0xf6,0xfe, 183: 0xd6,0x88,0xb3,0x0a,0x48,0xb2,0xc5,0x8f,0x50,0xe0,0xcf,0x40,0xfa,0x57,0xd1,0xc6, 184: 0x6c,0x20,0x64,0xc5,0xa1,0x44,0x03,0x42,0x00,0x04,0x9c,0xb2,0x52,0xcb,0xc0,0x5c, 185: 0xcf,0x97,0xdd,0xd6,0xe7,0x49,0x32,0x47,0x0c,0x8e,0xdb,0x6d,0xbf,0xc8,0x1a,0x0a, 186: 0x01,0xe8,0x5e,0x3f,0x8e,0x64,0x33,0xb4,0x15,0xbb,0x1b,0xa5,0xed,0xf9,0x4b,0xa7, 187: 0xe8,0x5e,0x6f,0x49,0x24,0xf7,0x32,0xf4,0x9b,0x4c,0x47,0xdc,0xf1,0x28,0x44,0x1c, 188: 0x37,0xdb,0xee,0xfb,0xd8,0xbd,0x4e,0x5c,0xeb,0x07), 189: chunk_from_chars( 190: 0x30,0x59,0x30,0x13,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,0x01,0x06,0x08,0x2a, 191: 0x86,0x48,0xce,0x3d,0x03,0x01,0x07,0x03,0x42,0x00,0x04,0x9c,0xb2,0x52,0xcb,0xc0, 192: 0x5c,0xcf,0x97,0xdd,0xd6,0xe7,0x49,0x32,0x47,0x0c,0x8e,0xdb,0x6d,0xbf,0xc8,0x1a, 193: 0x0a,0x01,0xe8,0x5e,0x3f,0x8e,0x64,0x33,0xb4,0x15,0xbb,0x1b,0xa5,0xed,0xf9,0x4b, 194: 0xa7,0xe8,0x5e,0x6f,0x49,0x24,0xf7,0x32,0xf4,0x9b,0x4c,0x47,0xdc,0xf1,0x28,0x44, 195: 0x1c,0x37,0xdb,0xee,0xfb,0xd8,0xbd,0x4e,0x5c,0xeb,0x07), 196: chunk_from_chars( 197: 0x07,0x64,0x50,0x1c,0x33,0x37,0x20,0x9b,0xe2,0x0e,0xe9,0x27,0xf0,0x29,0x5b,0x97, 198: 0x11,0x5f,0x7c,0xd1), 199: chunk_from_chars( 200: 0x1a,0x97,0x25,0x7a,0x48,0xae,0x8a,0x40,0x1a,0x4b,0xa0,0x0f,0x82,0x3c,0xa3,0x1f, 201: 0x61,0x91,0xd3,0x91), 202: }, 203: { chunk_from_chars( /* ECDSA-384 */ 204: 0x30,0x81,0xa4,0x02,0x01,0x01,0x04,0x30,0x4b,0xbf,0x6c,0xf5,0x24,0x78,0x53,0x4b, 205: 0x1a,0x91,0x23,0xae,0x30,0xc8,0xb3,0xc9,0xc2,0x9b,0x23,0x07,0x10,0x6f,0x1b,0x47, 206: 0x7c,0xa0,0xd4,0x79,0x3c,0xc4,0x83,0x10,0xd1,0x44,0x07,0xc2,0x1b,0x66,0xff,0xae, 207: 0x76,0x57,0x72,0x90,0x53,0xc2,0xf5,0x29,0xa0,0x07,0x06,0x05,0x2b,0x81,0x04,0x00, 208: 0x22,0xa1,0x64,0x03,0x62,0x00,0x04,0x1e,0xcf,0x1c,0x85,0x9d,0x06,0xa0,0x54,0xa2, 209: 0x24,0x2f,0xd8,0x63,0x56,0x7b,0x70,0x0b,0x7f,0x81,0x96,0xce,0xb9,0x2e,0x35,0x03, 210: 0x9c,0xf9,0x0a,0x5d,0x3b,0x10,0xf7,0x13,0x7a,0x0d,0xca,0x56,0xda,0x1d,0x44,0x84, 211: 0x07,0x6f,0x58,0xdc,0x34,0x7b,0x1d,0x4c,0xdd,0x28,0x10,0xc0,0xe2,0xae,0xf4,0xd6, 212: 0xda,0xea,0xaf,0xfc,0x7a,0xaf,0x59,0x5f,0xbc,0x91,0x65,0xd3,0x21,0x19,0x61,0xbb, 213: 0xfe,0x3c,0xdb,0x47,0xcb,0x7a,0xe7,0x5d,0xbd,0x28,0xde,0x25,0x64,0x9e,0x3a,0xa9, 214: 0x18,0xed,0x24,0xe1,0x1f,0x73,0xcc), 215: chunk_from_chars( 216: 0x30,0x81,0xb6,0x02,0x01,0x00,0x30,0x10,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02, 217: 0x01,0x06,0x05,0x2b,0x81,0x04,0x00,0x22,0x04,0x81,0x9e,0x30,0x81,0x9b,0x02,0x01, 218: 0x01,0x04,0x30,0x4b,0xbf,0x6c,0xf5,0x24,0x78,0x53,0x4b,0x1a,0x91,0x23,0xae,0x30, 219: 0xc8,0xb3,0xc9,0xc2,0x9b,0x23,0x07,0x10,0x6f,0x1b,0x47,0x7c,0xa0,0xd4,0x79,0x3c, 220: 0xc4,0x83,0x10,0xd1,0x44,0x07,0xc2,0x1b,0x66,0xff,0xae,0x76,0x57,0x72,0x90,0x53, 221: 0xc2,0xf5,0x29,0xa1,0x64,0x03,0x62,0x00,0x04,0x1e,0xcf,0x1c,0x85,0x9d,0x06,0xa0, 222: 0x54,0xa2,0x24,0x2f,0xd8,0x63,0x56,0x7b,0x70,0x0b,0x7f,0x81,0x96,0xce,0xb9,0x2e, 223: 0x35,0x03,0x9c,0xf9,0x0a,0x5d,0x3b,0x10,0xf7,0x13,0x7a,0x0d,0xca,0x56,0xda,0x1d, 224: 0x44,0x84,0x07,0x6f,0x58,0xdc,0x34,0x7b,0x1d,0x4c,0xdd,0x28,0x10,0xc0,0xe2,0xae, 225: 0xf4,0xd6,0xda,0xea,0xaf,0xfc,0x7a,0xaf,0x59,0x5f,0xbc,0x91,0x65,0xd3,0x21,0x19, 226: 0x61,0xbb,0xfe,0x3c,0xdb,0x47,0xcb,0x7a,0xe7,0x5d,0xbd,0x28,0xde,0x25,0x64,0x9e, 227: 0x3a,0xa9,0x18,0xed,0x24,0xe1,0x1f,0x73,0xcc), 228: chunk_from_chars( 229: 0x30,0x76,0x30,0x10,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,0x01,0x06,0x05,0x2b, 230: 0x81,0x04,0x00,0x22,0x03,0x62,0x00,0x04,0x1e,0xcf,0x1c,0x85,0x9d,0x06,0xa0,0x54, 231: 0xa2,0x24,0x2f,0xd8,0x63,0x56,0x7b,0x70,0x0b,0x7f,0x81,0x96,0xce,0xb9,0x2e,0x35, 232: 0x03,0x9c,0xf9,0x0a,0x5d,0x3b,0x10,0xf7,0x13,0x7a,0x0d,0xca,0x56,0xda,0x1d,0x44, 233: 0x84,0x07,0x6f,0x58,0xdc,0x34,0x7b,0x1d,0x4c,0xdd,0x28,0x10,0xc0,0xe2,0xae,0xf4, 234: 0xd6,0xda,0xea,0xaf,0xfc,0x7a,0xaf,0x59,0x5f,0xbc,0x91,0x65,0xd3,0x21,0x19,0x61, 235: 0xbb,0xfe,0x3c,0xdb,0x47,0xcb,0x7a,0xe7,0x5d,0xbd,0x28,0xde,0x25,0x64,0x9e,0x3a, 236: 0xa9,0x18,0xed,0x24,0xe1,0x1f,0x73,0xcc), 237: chunk_from_chars( 238: 0x33,0xe5,0x8b,0x39,0xb7,0x88,0xa1,0xbe,0x86,0x2f,0x5f,0xdf,0x8c,0x48,0xe2,0x4a, 239: 0x51,0x4e,0xe8,0xea), 240: chunk_from_chars( 241: 0x57,0x5b,0xdb,0x2e,0xa4,0xa9,0xd5,0x53,0x26,0x91,0x76,0x21,0xce,0x68,0x90,0xb2, 242: 0xa7,0x09,0x74,0xb4), 243: }, 244: { chunk_from_chars( /* ECDSA-521 */ 245: 0x30,0x81,0xdc,0x02,0x01,0x01,0x04,0x42,0x01,0xcf,0x38,0xaa,0xa7,0x7a,0x79,0x48, 246: 0xa9,0x60,0x55,0x24,0xa8,0x7e,0xe1,0xbc,0x45,0x35,0x16,0xff,0x18,0xce,0x44,0xa2, 247: 0x0b,0x72,0x6b,0xca,0x0a,0x40,0xb4,0x97,0x13,0x17,0x90,0x50,0x15,0xb9,0xba,0xfc, 248: 0x08,0x0e,0xdb,0xf8,0xfc,0x06,0x35,0x37,0xbf,0xfb,0x25,0x74,0xfe,0x0f,0xe1,0x3c, 249: 0x3a,0xf0,0x0d,0xe0,0x52,0x15,0xa8,0x07,0x6f,0x3e,0xa0,0x07,0x06,0x05,0x2b,0x81, 250: 0x04,0x00,0x23,0xa1,0x81,0x89,0x03,0x81,0x86,0x00,0x04,0x00,0x56,0x81,0x28,0xd6, 251: 0xac,0xe9,0xc8,0x82,0x2c,0xac,0x61,0x6d,0xdd,0x88,0x79,0x00,0xe3,0x7a,0x4d,0x25, 252: 0xc4,0xea,0x05,0x80,0x75,0x48,0xbc,0x75,0x73,0xc4,0xe9,0x76,0x68,0xba,0x51,0xc3, 253: 0x29,0xce,0x7d,0x1b,0xb0,0x8b,0xac,0xc1,0xcc,0x23,0xa7,0x2d,0xa7,0x2c,0x95,0xf6, 254: 0x01,0x40,0x26,0x01,0x1c,0x1c,0x9c,0xe7,0xa7,0xb4,0x0f,0x8e,0xba,0x01,0x07,0xb3, 255: 0xf7,0xbe,0x45,0x20,0xa9,0x9e,0x70,0xf0,0xcf,0x9b,0xa0,0x91,0xe3,0x88,0x8f,0x04, 256: 0x69,0x3d,0x0f,0x2b,0xf3,0xb4,0x03,0x19,0x89,0xcf,0xfa,0x77,0x04,0x15,0xaf,0xdd, 257: 0xf7,0x32,0x76,0x25,0x25,0x05,0x8d,0xfd,0x18,0x8a,0xda,0xd6,0xbc,0x71,0xb8,0x9f, 258: 0x39,0xb0,0xaf,0xcc,0x54,0xb0,0x9c,0x4d,0x54,0xfb,0x46,0x53,0x5f,0xf8,0x45), 259: chunk_from_chars( 260: 0x30,0x81,0xee,0x02,0x01,0x00,0x30,0x10,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02, 261: 0x01,0x06,0x05,0x2b,0x81,0x04,0x00,0x23,0x04,0x81,0xd6,0x30,0x81,0xd3,0x02,0x01, 262: 0x01,0x04,0x42,0x01,0xcf,0x38,0xaa,0xa7,0x7a,0x79,0x48,0xa9,0x60,0x55,0x24,0xa8, 263: 0x7e,0xe1,0xbc,0x45,0x35,0x16,0xff,0x18,0xce,0x44,0xa2,0x0b,0x72,0x6b,0xca,0x0a, 264: 0x40,0xb4,0x97,0x13,0x17,0x90,0x50,0x15,0xb9,0xba,0xfc,0x08,0x0e,0xdb,0xf8,0xfc, 265: 0x06,0x35,0x37,0xbf,0xfb,0x25,0x74,0xfe,0x0f,0xe1,0x3c,0x3a,0xf0,0x0d,0xe0,0x52, 266: 0x15,0xa8,0x07,0x6f,0x3e,0xa1,0x81,0x89,0x03,0x81,0x86,0x00,0x04,0x00,0x56,0x81, 267: 0x28,0xd6,0xac,0xe9,0xc8,0x82,0x2c,0xac,0x61,0x6d,0xdd,0x88,0x79,0x00,0xe3,0x7a, 268: 0x4d,0x25,0xc4,0xea,0x05,0x80,0x75,0x48,0xbc,0x75,0x73,0xc4,0xe9,0x76,0x68,0xba, 269: 0x51,0xc3,0x29,0xce,0x7d,0x1b,0xb0,0x8b,0xac,0xc1,0xcc,0x23,0xa7,0x2d,0xa7,0x2c, 270: 0x95,0xf6,0x01,0x40,0x26,0x01,0x1c,0x1c,0x9c,0xe7,0xa7,0xb4,0x0f,0x8e,0xba,0x01, 271: 0x07,0xb3,0xf7,0xbe,0x45,0x20,0xa9,0x9e,0x70,0xf0,0xcf,0x9b,0xa0,0x91,0xe3,0x88, 272: 0x8f,0x04,0x69,0x3d,0x0f,0x2b,0xf3,0xb4,0x03,0x19,0x89,0xcf,0xfa,0x77,0x04,0x15, 273: 0xaf,0xdd,0xf7,0x32,0x76,0x25,0x25,0x05,0x8d,0xfd,0x18,0x8a,0xda,0xd6,0xbc,0x71, 274: 0xb8,0x9f,0x39,0xb0,0xaf,0xcc,0x54,0xb0,0x9c,0x4d,0x54,0xfb,0x46,0x53,0x5f,0xf8, 275: 0x45), 276: chunk_from_chars( 277: 0x30,0x81,0x9b,0x30,0x10,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,0x01,0x06,0x05, 278: 0x2b,0x81,0x04,0x00,0x23,0x03,0x81,0x86,0x00,0x04,0x00,0x56,0x81,0x28,0xd6,0xac, 279: 0xe9,0xc8,0x82,0x2c,0xac,0x61,0x6d,0xdd,0x88,0x79,0x00,0xe3,0x7a,0x4d,0x25,0xc4, 280: 0xea,0x05,0x80,0x75,0x48,0xbc,0x75,0x73,0xc4,0xe9,0x76,0x68,0xba,0x51,0xc3,0x29, 281: 0xce,0x7d,0x1b,0xb0,0x8b,0xac,0xc1,0xcc,0x23,0xa7,0x2d,0xa7,0x2c,0x95,0xf6,0x01, 282: 0x40,0x26,0x01,0x1c,0x1c,0x9c,0xe7,0xa7,0xb4,0x0f,0x8e,0xba,0x01,0x07,0xb3,0xf7, 283: 0xbe,0x45,0x20,0xa9,0x9e,0x70,0xf0,0xcf,0x9b,0xa0,0x91,0xe3,0x88,0x8f,0x04,0x69, 284: 0x3d,0x0f,0x2b,0xf3,0xb4,0x03,0x19,0x89,0xcf,0xfa,0x77,0x04,0x15,0xaf,0xdd,0xf7, 285: 0x32,0x76,0x25,0x25,0x05,0x8d,0xfd,0x18,0x8a,0xda,0xd6,0xbc,0x71,0xb8,0x9f,0x39, 286: 0xb0,0xaf,0xcc,0x54,0xb0,0x9c,0x4d,0x54,0xfb,0x46,0x53,0x5f,0xf8,0x45), 287: chunk_from_chars( 288: 0x1d,0x3b,0x1b,0x05,0xd7,0xcb,0x87,0x17,0x49,0x2c,0x6a,0xed,0x3b,0x82,0xa8,0xc3, 289: 0xaa,0x76,0x72,0x91), 290: chunk_from_chars( 291: 0xd4,0x6d,0x34,0x22,0xd4,0xdd,0xca,0x63,0x26,0x95,0xb5,0x47,0x9b,0x8b,0x4a,0x30, 292: 0x67,0x27,0x3e,0xcd), 293: }, 294: }; 295: 296: START_TEST(test_load) 297: { 298: private_key_t *privkey; 299: public_key_t *pubkey; 300: chunk_t encoding, fp; 301: 302: privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_ECDSA, 303: BUILD_BLOB_ASN1_DER, keys[_i].key, BUILD_END); 304: ck_assert(privkey != NULL); 305: ck_assert(privkey->get_encoding(privkey, PRIVKEY_ASN1_DER, &encoding)); 306: if (encoding.len == keys[_i].pkcs8.len) 307: { 308: ck_assert_chunk_eq(keys[_i].pkcs8, encoding); 309: } 310: else 311: { 312: ck_assert_chunk_eq(keys[_i].key, encoding); 313: } 314: chunk_clear(&encoding); 315: 316: ck_assert(privkey->get_fingerprint(privkey, KEYID_PUBKEY_SHA1, &fp)); 317: ck_assert_chunk_eq(keys[_i].fp_pk, fp); 318: ck_assert(privkey->get_fingerprint(privkey, KEYID_PUBKEY_INFO_SHA1, &fp)); 319: ck_assert_chunk_eq(keys[_i].fp_spki, fp); 320: 321: pubkey = privkey->get_public_key(privkey); 322: ck_assert(pubkey != NULL); 323: ck_assert(pubkey->get_encoding(pubkey, PUBKEY_SPKI_ASN1_DER, &encoding)); 324: ck_assert_chunk_eq(keys[_i].pub, encoding); 325: chunk_free(&encoding); 326: 327: ck_assert(pubkey->get_fingerprint(pubkey, KEYID_PUBKEY_SHA1, &fp)); 328: ck_assert_chunk_eq(keys[_i].fp_pk, fp); 329: ck_assert(pubkey->get_fingerprint(pubkey, KEYID_PUBKEY_INFO_SHA1, &fp)); 330: ck_assert_chunk_eq(keys[_i].fp_spki, fp); 331: 332: test_good_sig(privkey, pubkey); 333: 334: test_bad_sigs(pubkey); 335: 336: pubkey->destroy(pubkey); 337: privkey->destroy(privkey); 338: } 339: END_TEST 340: 341: Suite *ecdsa_suite_create() 342: { 343: Suite *s; 344: TCase *tc; 345: int gen_count = countof(key_sizes); 346: 347: s = suite_create("ecdsa"); 348: 349: if (getenv("TESTS_REDUCED_KEYLENGTHS") != NULL) 350: { 351: gen_count = min(1, gen_count); 352: } 353: 354: tc = tcase_create("generate"); 355: tcase_add_loop_test(tc, test_gen, 0, gen_count); 356: suite_add_tcase(s, tc); 357: 358: tc = tcase_create("load"); 359: tcase_add_loop_test(tc, test_load, 0, countof(keys)); 360: suite_add_tcase(s, tc); 361: 362: return s; 363: }