1 // TODO(eroman): Use known test vectors. The samples I used here I generated myself.
3 // Test key derivation using ECDH (P-256), using a public and private key from
4 // different key pairs.
9 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
10 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE"
16 "d":"uN2YSQvxuxhQQ9Y1XXjYi1vr2ZTdzuoDX18PYu4LU-0",
17 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
18 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o"
21 // This is the maximum length for P-256.
23 "derived_bytes": "163FAA3FC4815D47345C8E959F707B2F1D3537E7B2EA1DAEC23CA8D0A242CFF3"
26 // Same as the test above, but in reverse (choosing public/private from the
32 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
33 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
34 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
39 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
40 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o"
43 // This is the maximum length for P-256.
45 "derived_bytes": "163FAA3FC4815D47345C8E959F707B2F1D3537E7B2EA1DAEC23CA8D0A242CFF3"
48 // This is the same test as above, however the length is 2 bytes shorter.
53 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
54 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
55 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
60 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
61 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o"
64 // This is the maximum length for P-256.
66 "derived_bytes": "163FAA3FC4815D47345C8E959F707B2F1D3537E7B2EA1DAEC23CA8D0A242"
69 // Try deriving zero bits.
74 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
75 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
76 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
81 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
82 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o"
89 // Try deriving a single bit.
90 // Note that the full byte would be 0x16, however the remaining bits in the
91 // byte will be zero-ed.
96 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
97 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
98 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
103 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
104 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o"
108 "derived_bytes": "00"
111 // This is the same as an earlier test, however 253 bits instead of 256.
112 // Notice how the last byte went from 0xF3 --> 0xF0, because the unused bits
118 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
119 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
120 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
125 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
126 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o"
130 "derived_bytes": "163FAA3FC4815D47345C8E959F707B2F1D3537E7B2EA1DAEC23CA8D0A242CFF0"
134 // A test using P-521.
138 "d":"AI_Zu5xisuK-IIz85dTSoqaQSTxN1I88l05myJJ0ZYFMdQ2VmjFOIUTonKGG97yOGmikyid-6F48d7iI1zF6VRk7",
140 "x":"ACw6DX7wqwHVO-JzyOet0B-r10YVLv5R5q_IfiWCzclg0u_x57NCtOcFCFpM2ZnS22tyYjZb0gBHGcgUE_I-h-6s",
141 "y":"Actm2tCHBPOKLZMpJV3DaVOluln9zBsE2I0g6iV73I4M-liqA1rLSJN8q-vcSQtZF0JvzwuvGkGuTbvT_DaRQ2pf"
147 "x":"ADRllQ0B7icrnJ7ib2r-CXvymGFiC_3f6_o0SzLMBIggM8ndQm9l768SToMy1hUo64JsofGSQ37P4CRqT_QeivBD",
148 "y":"ALKEzew1Xe4Sv86lZVqb2xxZ0l7WrE3DPJ93fUtSPih5iH8jg0GPDKMVoA5ffFmqPwbdgS2BK18PBFIT7QDGb2Zx"
152 "derived_bytes": "0117D54D84379D0FD385BE068455A77A5366AB534FF172AB0A121F37D180DCCD19607ABB0C41CB9F6F12B01303AC4A69DC2D1D05180181FD496D9769B46BFFEC3400",
153 "valid_p521_keys": true // Special variable use by ecdh_unittest.cc::LoadTestKeys
156 // Same as above but with the public/private switched.
161 "x":"ACw6DX7wqwHVO-JzyOet0B-r10YVLv5R5q_IfiWCzclg0u_x57NCtOcFCFpM2ZnS22tyYjZb0gBHGcgUE_I-h-6s",
162 "y":"Actm2tCHBPOKLZMpJV3DaVOluln9zBsE2I0g6iV73I4M-liqA1rLSJN8q-vcSQtZF0JvzwuvGkGuTbvT_DaRQ2pf"
168 "d":"AU3LVJK4dtlbOEFb018ry-D-kYF7J7oQxXLpXcnQXbTh42FORGGGtySTA83gT_GiHJ0tnvgVrDdUMK1muJBGPrRf",
169 "x":"ADRllQ0B7icrnJ7ib2r-CXvymGFiC_3f6_o0SzLMBIggM8ndQm9l768SToMy1hUo64JsofGSQ37P4CRqT_QeivBD",
170 "y":"ALKEzew1Xe4Sv86lZVqb2xxZ0l7WrE3DPJ93fUtSPih5iH8jg0GPDKMVoA5ffFmqPwbdgS2BK18PBFIT7QDGb2Zx"
174 "derived_bytes": "0117D54D84379D0FD385BE068455A77A5366AB534FF172AB0A121F37D180DCCD19607ABB0C41CB9F6F12B01303AC4A69DC2D1D05180181FD496D9769B46BFFEC3400"
181 "x":"ACw6DX7wqwHVO-JzyOet0B-r10YVLv5R5q_IfiWCzclg0u_x57NCtOcFCFpM2ZnS22tyYjZb0gBHGcgUE_I-h-6s",
182 "y":"Actm2tCHBPOKLZMpJV3DaVOluln9zBsE2I0g6iV73I4M-liqA1rLSJN8q-vcSQtZF0JvzwuvGkGuTbvT_DaRQ2pf"
188 "d":"AU3LVJK4dtlbOEFb018ry-D-kYF7J7oQxXLpXcnQXbTh42FORGGGtySTA83gT_GiHJ0tnvgVrDdUMK1muJBGPrRf",
189 "x":"ADRllQ0B7icrnJ7ib2r-CXvymGFiC_3f6_o0SzLMBIggM8ndQm9l768SToMy1hUo64JsofGSQ37P4CRqT_QeivBD",
190 "y":"ALKEzew1Xe4Sv86lZVqb2xxZ0l7WrE3DPJ93fUtSPih5iH8jg0GPDKMVoA5ffFmqPwbdgS2BK18PBFIT7QDGb2Zx"
194 "derived_bytes": "0117D54D84379D0FD385BE068455A77A5366AB534FF172AB0A121F37D180DCCD19607ABB0C41CB9F6F12B01303AC4A69DC2D1D05180181FD496D9769B46BFFEC3400"
197 // Ask for 528 bits using P-521, which is the rounded up byte length of the
203 "x":"ACw6DX7wqwHVO-JzyOet0B-r10YVLv5R5q_IfiWCzclg0u_x57NCtOcFCFpM2ZnS22tyYjZb0gBHGcgUE_I-h-6s",
204 "y":"Actm2tCHBPOKLZMpJV3DaVOluln9zBsE2I0g6iV73I4M-liqA1rLSJN8q-vcSQtZF0JvzwuvGkGuTbvT_DaRQ2pf"
210 "d":"AU3LVJK4dtlbOEFb018ry-D-kYF7J7oQxXLpXcnQXbTh42FORGGGtySTA83gT_GiHJ0tnvgVrDdUMK1muJBGPrRf",
211 "x":"ADRllQ0B7icrnJ7ib2r-CXvymGFiC_3f6_o0SzLMBIggM8ndQm9l768SToMy1hUo64JsofGSQ37P4CRqT_QeivBD",
212 "y":"ALKEzew1Xe4Sv86lZVqb2xxZ0l7WrE3DPJ93fUtSPih5iH8jg0GPDKMVoA5ffFmqPwbdgS2BK18PBFIT7QDGb2Zx"
216 "derived_bytes": "0117D54D84379D0FD385BE068455A77A5366AB534FF172AB0A121F37D180DCCD19607ABB0C41CB9F6F12B01303AC4A69DC2D1D05180181FD496D9769B46BFFEC3425"
219 // The first 7 bits for P-521 will always be zero.
224 "x":"ACw6DX7wqwHVO-JzyOet0B-r10YVLv5R5q_IfiWCzclg0u_x57NCtOcFCFpM2ZnS22tyYjZb0gBHGcgUE_I-h-6s",
225 "y":"Actm2tCHBPOKLZMpJV3DaVOluln9zBsE2I0g6iV73I4M-liqA1rLSJN8q-vcSQtZF0JvzwuvGkGuTbvT_DaRQ2pf"
231 "d":"AU3LVJK4dtlbOEFb018ry-D-kYF7J7oQxXLpXcnQXbTh42FORGGGtySTA83gT_GiHJ0tnvgVrDdUMK1muJBGPrRf",
232 "x":"ADRllQ0B7icrnJ7ib2r-CXvymGFiC_3f6_o0SzLMBIggM8ndQm9l768SToMy1hUo64JsofGSQ37P4CRqT_QeivBD",
233 "y":"ALKEzew1Xe4Sv86lZVqb2xxZ0l7WrE3DPJ93fUtSPih5iH8jg0GPDKMVoA5ffFmqPwbdgS2BK18PBFIT7QDGb2Zx"
237 "derived_bytes": "00"
240 // Using different key pairs, verify again that the first 7 bits are zero.
245 "x":"ACw6DX7wqwHVO-JzyOet0B-r10YVLv5R5q_IfiWCzclg0u_x57NCtOcFCFpM2ZnS22tyYjZb0gBHGcgUE_I-h-6s",
246 "y":"Actm2tCHBPOKLZMpJV3DaVOluln9zBsE2I0g6iV73I4M-liqA1rLSJN8q-vcSQtZF0JvzwuvGkGuTbvT_DaRQ2pf"
252 "d": "Ab1WvRBhGO2iRhVb1DtCuOE_Cm4l3TuzdgJvq03JK2FXvG3-wtFd09DPKjmqaElAQq9IupYBEY2oLG8hCKOiA610",
253 "x": "AS-8rv-mpR8-5NPStRxd7G18cmyjU_wBTqK_fPu5uRDTLL-moA_jm2zbiUbyJ3U5iy4jPAzxRNeMindCtceju10j",
254 "y": "AJze-CPde_mnnozOrNLkUnwjHQrllnrwlY6THX3czygFo-YY3DA5_sn-u9MwUv5MD-6Y8DMQYGSYLYj04DVJ1KZN"
258 "derived_bytes": "00"
261 // Same as an earlier test, however the public key specifies the extraneous
262 // {"use": "sig"}. This doesn't make sense for ECDH; however, it is allowed
263 // by the implementation. This is not spec compliant, see:
264 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27601
269 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
270 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
271 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
276 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
277 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o",
285 // Same test as above, but instead of "use" it uses "key_ops" with bogus
291 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
292 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
293 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
298 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
299 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o",
300 "key_ops": ["encrypt", "decrypt"]
307 // -----------------------------------------
309 // -----------------------------------------
311 // The length is too long, by 1 bit
316 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
317 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
318 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
323 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
324 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o"
328 "error": "OperationError: Length specified for ECDH key derivation is too large. Maximum allowed is 256 bits"
331 // The length is too long, by 1 byte
336 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
337 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
338 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
343 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
344 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o"
348 "error": "OperationError: Length specified for ECDH key derivation is too large. Maximum allowed is 256 bits"
351 // Curve mismatch (public key is for P-521 however private key was for P-256).
356 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
357 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE",
358 "d":"CQ8uF_-zB1NftLO6ytwKM3Cnuol64PQw5qOuCzQJeFU"
364 "x":"ACw6DX7wqwHVO-JzyOet0B-r10YVLv5R5q_IfiWCzclg0u_x57NCtOcFCFpM2ZnS22tyYjZb0gBHGcgUE_I-h-6s",
365 "y":"Actm2tCHBPOKLZMpJV3DaVOluln9zBsE2I0g6iV73I4M-liqA1rLSJN8q-vcSQtZF0JvzwuvGkGuTbvT_DaRQ2pf"
369 "error": "InvalidAccess: The public parameter for ECDH key derivation is for a different named curve"
372 // Ask for 529 bits using P-521, which is too much.
377 "x":"ACw6DX7wqwHVO-JzyOet0B-r10YVLv5R5q_IfiWCzclg0u_x57NCtOcFCFpM2ZnS22tyYjZb0gBHGcgUE_I-h-6s",
378 "y":"Actm2tCHBPOKLZMpJV3DaVOluln9zBsE2I0g6iV73I4M-liqA1rLSJN8q-vcSQtZF0JvzwuvGkGuTbvT_DaRQ2pf"
384 "d":"AU3LVJK4dtlbOEFb018ry-D-kYF7J7oQxXLpXcnQXbTh42FORGGGtySTA83gT_GiHJ0tnvgVrDdUMK1muJBGPrRf",
385 "x":"ADRllQ0B7icrnJ7ib2r-CXvymGFiC_3f6_o0SzLMBIggM8ndQm9l768SToMy1hUo64JsofGSQ37P4CRqT_QeivBD",
386 "y":"ALKEzew1Xe4Sv86lZVqb2xxZ0l7WrE3DPJ93fUtSPih5iH8jg0GPDKMVoA5ffFmqPwbdgS2BK18PBFIT7QDGb2Zx"
390 "error": "OperationError: Length specified for ECDH key derivation is too large. Maximum allowed is 528 bits"
393 // The JWK has wrong usages (enc)
398 "x":"u6dWhaRHrvFF0CiFVuUUFafU6ixveQf9trHDXJ8hgV8",
399 "y":"thSm4LIY35vDD-5LE454eB7TShn919DVVGZ_7tWdjTE"
405 "d":"uN2YSQvxuxhQQ9Y1XXjYi1vr2ZTdzuoDX18PYu4LU-0",
406 "x":"S2S3tjygMB0DkM-N9jYUgGLt_9_H6km5P9V6V_KS4_4",
407 "y":"03j8Tyqgrc4R4FAUV2C7-im96yMmfmO_5Om6Kr8YP3o",
411 "private_key_error": "DataError: The JWK \"use\" member was inconsistent with that specified by the Web Crypto call. The JWK usage must be a superset of those requested"