ECJPAKE.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file ECJPAKE.h
34  *
35  * @brief TI Driver for Elliptic Curve Password Authenticated Key Exchange
36  * by Juggling.
37  *
38  * @anchor ti_drivers_ECJPAKE_Overview
39  * # Overview #
40  * Elliptic Curve Password Authenticated Key Exchange by Juggling (EC-JPAKE)
41  * is a key agreement scheme that establishes a secure channel over an insecure
42  * network. It only requires sharing a password offline and does not require
43  * public key infrastructure or trusted third parties such as certificate
44  * authorities.
45  *
46  * At the end of the EC-JPAKE scheme, both parties derive a shared secret
47  * from which a session key is derived.
48  *
49  * The scheme is symmetric. Both parties perform the exact same operations
50  * to end up with the shared secret.
51  *
52  * # Steps involved #
53  * Since the scheme is symmetric, the steps involved will be illustrated
54  * using Alice and Bob as relevant parties.
55  *
56  * -# Alice and Bob decide on some pre-shared secret, the password, and
57  * negotiate this through some offline means such as during commissioning.
58  *
59  * -# Alice generates private keys x1, x2, v1, and v2 uniformly at random from [1, n - 1],
60  * where n is the order of the curve.
61  * -# Alice generates public keys X1 = x1 * G, X2 = x2 * G, V1 = v1 * G, and V2 = v2 * G.
62  * -# Alice generates Zero-Knowledge Proofs (ZKPs) for (X1, x1) and (X2, x2).
63  * The required hash is computed by concatenating G, V, the public key
64  * the ZKP authenticates, and the UserID of the authenticator and hashing
65  * the new bitstring. The exact order and formatting of all parameters and
66  * any extra information such as length words must be agreed upon by both
67  * parties to yield the same result.
68  * -# Alice sends X1, X2, V1, V2, r1, r2, and her UserID to Bob.
69  *
70  * -# Bob generates private keys x3, x4, v3, and v4 uniformly at random from [1, n - 1],
71  * where n is the order of the curve.
72  * -# Bob generates public keys X3 = x3 * G, X4 = x4 * G, V3 = v3 * G, and V4 = v4 * G.
73  * -# Bob generates Zero-Knowledge Proofs (ZKPs) for (X3, x3) and (X4, x4).
74  * -# Bob sends X3, X4, V3, V4, r3, r4, and his UserID to Bob.
75  *
76  * -# Alice and Bob verify the other parties ZKPs and break off the scheme if they
77  * do not check out.
78  *
79  * -# Alice computes the new generator point G2 = (X1 + X3 + X4).
80  * -# Alice computes the combined private key x5 = x2 * s, where s is the pre-shared
81  * secret.
82  * -# Alice computes the combined public key X5 = x5 * G2.
83  * -# Alice computes a ZKP for (X5, x5) using G2 as the generator point of the ZKP.
84  * -# Alice sends X5, V5, r5, and her UserID to Bob.
85  *
86  * -# Bob computes the new generator point G3 = (X3 + X1 + X2).
87  * -# Bob computes the combined private key x6 = x4 * s, where s is the pre-shared
88  * secret.
89  * -# Bob computes the combined public key X6 = x6 * G3.
90  * -# Bob computes a ZKP for (X6, x6) using G3 as the generator point of the ZKP.
91  * -# Bob sends X6, V6, r6, and his UserID to Alice.
92  *
93  * -# Alice and Bob verify the other parties ZKPs and break off the scheme if they
94  * do not check out. This involves computing the other parties generator point.
95  *
96  * -# Alice computes shared secret K = (X6 - (X4 * x5)) * x2.
97  *
98  * -# Bob computes shared secret K = (X5 - (X2 * x6)) * x4.
99  *
100  * -# Alice and Bob each run K through a mutually agreed upon key derivation
101  * function to compute the symmetric session key.
102  *
103  * @anchor ti_drivers_ECJPAKE_Usage
104  * # Usage #
105  *
106  * ## Before starting an ECJPAKE operation #
107  *
108  * Before starting an ECJPAKE operation, the application must do the following:
109  * -# Call ECJPAKE_init() to initialize the driver
110  * -# Call ECJPAKE_Params_init() to initialize the ECJPAKE_Params to default values.
111  * -# Modify the ECJPAKE_Params as desired
112  * -# Call ECJPAKE_open() to open an instance of the driver
113  *
114  * ## Round one #
115  * -# Initialize the following private key CryptoKeys.
116  * Seed them with keying material uniformly drawn from [1, n - 1]
117  * - myPrivateKey1
118  * - myPrivateKey2
119  * - myPrivateV1
120  * - myPrivateV2
121  * -# Initialize the following blank public key CryptoKeys:
122  * - myPublicKey1
123  * - myPublicKey2
124  * - myPublicV1
125  * - myPublicV2
126  * - theirPublicKey1
127  * - theirPublicKey2
128  * - theirPublicV1
129  * - theirPublicV2
130  * -# Call ECJPAKE_roundOneGenerateKeys() to generate all round one keys as needed.
131  * -# Generate the hashes for the ZKPs using previously agreed upon formatting.
132  * Use the default generator point of the curve in the first round.
133  * -# Generate your two ZKPs by calling ECJPAKE_generateZKP() once per ZKP.
134  * -# Exchange public keys, UserIDs, and ZKP signatures. Write the received keying
135  * material into the relevant buffers or load them into key stores as specified
136  * by the CryptoKeys initialised earlier.
137  * -# Verify the other party's ZKPs after computing their ZKP hash by calling
138  * ECJPAKE_verifyZKP() once per ZKP.
139  * -# You can now let all V keys, myPrivateKey1, and all ZKP signatures go out of scope
140  * and re-use their memory.
141  *
142  * ## Round two #
143  * -# Initialize the following private key CryptoKeys.
144  * Seed myPrivateV with keying material uniformly drawn from [1, n - 1].
145  * Initialise the preSharedSecret with the common keying material previously
146  * shared between you and the other party.
147  * - preSharedSecret
148  * - myCombinedPrivateKey
149  * -# Initialize the following blank public key CryptoKeys:
150  * - theirNewGenerator
151  * - myNewGenerator
152  * - myCombinedPublicKey
153  * - myPublicV
154  * -# Call ECJPAKE_roundTwoGenerateKeys() to generate the remaining round two keys.
155  * -# Generate the hash for your ZKP use myNewGenerator as your generator point.
156  * -# Exchange public keys, UserIDs, and ZKP signatures. Write the received keying
157  * material into the relevant buffers or load them into key stores as specified
158  * by the CryptoKeys initialised earlier.
159  * -# Verify the other party's ZKP after computing their ZKP hash b calling
160  * ECJPAKE_verifyZKP(). Use theirNewGenerator as the generator point for this
161  * ZKP.
162  * -# You can now let all keys and keying material but myCombinedPrivateKey,
163  * theirCombinedPublicKey, theirPublicKey2, and myPrivateKey2 go out of scope.
164  *
165  * ## Computing the shared secret #
166  * -# Initialize the following blank public key CryptoKey:
167  * - sharedSecret
168  * -# Call ECJPAKE_computeSharedSecret().
169  * -# Run sharedSecret through a key derivation function to compute the shared
170  * symmetric session key.
171  *
172  * ## General usage #
173  * The API expects elliptic curves as defined in ti/drivers/cryptoutils/ecc/ECCParams.h.
174  * Several commonly used curves are provided. Check the device-specific ECJPAKE documentation
175  * for curve type (short Weierstrass, Montgomery, Edwards) support for your device.
176  * ECJPAKE support for a curve type on a device does not imply curve-type support for
177  * other ECC schemes.
178  *
179  * Public keys and shared secrets are points on an elliptic curve. These points can
180  * be expressed in several ways. The most common one is in affine coordinates as an
181  * X,Y pair.
182  * This API uses points expressed in affine coordinates.
183  * The point is stored as a concatenated array of X followed by Y in a location
184  * described by its CryptoKey.
185  *
186  * This API accepts and returns the keying material of public keys according
187  * to the following table:
188  *
189  * | Curve Type | Keying Material Array | Array Length |
190  * |--------------------|-----------------------|---------------------------|
191  * | Short Weierstrass | [X, Y] | 2 * Curve Param Length |
192  * | Montgomery | [X, Y] | 2 * Curve Param Length |
193  * | Edwards | [X, Y] | 2 * Curve Param Length |
194  *
195  * @anchor ti_drivers_ECJPAKE_Synopsis
196  * ## Synopsis
197  *
198  * @anchor ti_drivers_ECJPAKE_Synopsis_Code
199  * @code
200  * // Import ECJPAKE Driver definitions
201  * #include <ti/drivers/ECJPAKE.h>
202  *
203  * ECJPAKE_init();
204  *
205  * // Since we are using default ECJPAKE_Params, we just pass in NULL for that parameter.
206  * ecjpakeHandle = ECJPAKE_open(0, NULL);
207 
208  * ECJPAKE_Handle handle = ECJPAKE_open(0, &params);
209  *
210  * ECJPAKE_OperationRoundOneGenerateKeys operationRoundOneGenerateKeys;
211  * ECJPAKE_OperationRoundTwoGenerateKeys operationRoundTwoGenerateKeys;
212  * ECJPAKE_OperationGenerateZKP operationGenerateZKP;
213  * ECJPAKE_OperationVerifyZKP operationVerifyZKP;
214  * ECJPAKE_OperationComputeSharedSecret operationComputeSharedSecret;
215  *
216  * // Generate my round one keys
217  * ECJPAKE_OperationRoundOneGenerateKeys_init(&operationRoundOneGenerateKeys);
218  * operationRoundOneGenerateKeys.curve = &ECCParams_NISTP256;
219  * operationRoundOneGenerateKeys.myPrivateKey1 = &myPrivateCryptoKey1;
220  * operationRoundOneGenerateKeys.myPrivateKey2 = &myPrivateCryptoKey2;
221  * operationRoundOneGenerateKeys.myPublicKey1 = &myPublicCryptoKey1;
222  * operationRoundOneGenerateKeys.myPublicKey2 = &myPublicCryptoKey2;
223  * operationRoundOneGenerateKeys.myPrivateV1 = &myPrivateCryptoV1;
224  * operationRoundOneGenerateKeys.myPrivateV2 = &myPrivateCryptoV2;
225  * operationRoundOneGenerateKeys.myPublicV1 = &myPublicCryptoV1;
226  * operationRoundOneGenerateKeys.myPublicV2 = &myPublicCryptoV2;
227  *
228  * result = ECJPAKE_roundOneGenerateKeys(handle, &operationRoundOneGenerateKeys);
229  *
230  * // Generate hashes here
231  *
232  * // generate my round one ZKPs
233  * ECJPAKE_OperationGenerateZKP_init(&operationGenerateZKP);
234  * operationGenerateZKP.curve = &ECCParams_NISTP256;
235  * operationGenerateZKP.myPrivateKey = &myPrivateCryptoKey1;
236  * operationGenerateZKP.myPrivateV = &myPrivateCryptoV1;
237  * operationGenerateZKP.hash = myHash1;
238  * operationGenerateZKP.r = myR1;
239  *
240  * result = ECJPAKE_generateZKP(handle, &operationGenerateZKP);
241  *
242  * ECJPAKE_OperationGenerateZKP_init(&operationGenerateZKP);
243  * operationGenerateZKP.curve = &ECCParams_NISTP256;
244  * operationGenerateZKP.myPrivateKey = &myPrivateCryptoKey2;
245  * operationGenerateZKP.myPrivateV = &myPrivateCryptoV2;
246  * operationGenerateZKP.hash = myHash2;
247  * operationGenerateZKP.r = myR2;
248  *
249  * result = ECJPAKE_generateZKP(handle, &operationGenerateZKP);
250  *
251  * // Do ZKP and key transmission here
252  *
253  * // Verify their round one ZKPs
254  * // Generate their hashes here
255  *
256  * ECJPAKE_OperationVerifyZKP_init(&operationVerifyZKP);
257  * operationVerifyZKP.curve = &ECCParams_NISTP256;
258  * operationVerifyZKP.theirGenerator = &nistP256GeneratorCryptoKey;
259  * operationVerifyZKP.theirPublicKey = &theirPublicCryptoKey1;
260  * operationVerifyZKP.theirPublicV = &theirPublicCryptoV1;
261  * operationVerifyZKP.hash = theirHash1;
262  * operationVerifyZKP.r = theirR1;
263  *
264  * result = ECJPAKE_verifyZKP(handle, &operationVerifyZKP);
265  *
266  * ECJPAKE_OperationVerifyZKP_init(&operationVerifyZKP);
267  * operationVerifyZKP.curve = &ECCParams_NISTP256;
268  * operationVerifyZKP.theirGenerator = &nistP256GeneratorCryptoKey;
269  * operationVerifyZKP.theirPublicKey = &theirPublicCryptoKey2;
270  * operationVerifyZKP.theirPublicV = &theirPublicCryptoV2;
271  * operationVerifyZKP.hash = theirHash2;
272  * operationVerifyZKP.r = theirR2;
273  *
274  * result = ECJPAKE_verifyZKP(handle,&operationVerifyZKP);
275  *
276  * // Round two starts now
277  *
278  * // Generate my round two keys
279  * ECJPAKE_OperationRoundTwoGenerateKeys_init(&operationRoundTwoGenerateKeys);
280  * operationRoundTwoGenerateKeys.curve = &ECCParams_NISTP256;
281  * operationRoundTwoGenerateKeys.myPrivateKey2 = &myPrivateCryptoKey2;
282  * operationRoundTwoGenerateKeys.myPublicKey1 = &myPublicCryptoKey1;
283  * operationRoundTwoGenerateKeys.myPublicKey2 = &myPublicCryptoKey2;
284  * operationRoundTwoGenerateKeys.theirPublicKey1 = &theirPublicCryptoKey1;
285  * operationRoundTwoGenerateKeys.theirPublicKey2 = &theirPublicCryptoKey2;
286  * operationRoundTwoGenerateKeys.preSharedSecret = &preSharedSecretCryptoKey;
287  * operationRoundTwoGenerateKeys.theirNewGenerator = &theirGeneratorKey;
288  * operationRoundTwoGenerateKeys.myNewGenerator = &myGeneratorKey;
289  * operationRoundTwoGenerateKeys.myCombinedPrivateKey = &myCombinedPrivateKey;
290  * operationRoundTwoGenerateKeys.myCombinedPublicKey = &myCombinedPublicKey;
291  * operationRoundTwoGenerateKeys.myPrivateV = &myPrivateCryptoV3;
292  * operationRoundTwoGenerateKeys.myPublicV = &myPublicCryptoV3;
293  *
294  * result = ECJPAKE_roundTwoGenerateKeys(handle, &operationRoundTwoGenerateKeys);
295  *
296  * // Generate my round two ZKP
297  * // Generate the round two hash here
298  *
299  * ECJPAKE_OperationGenerateZKP_init(&operationGenerateZKP);
300  * operationGenerateZKP.curve = &ECCParams_NISTP256;
301  * operationGenerateZKP.myPrivateKey = &myCombinedPrivateKey;
302  * operationGenerateZKP.myPrivateV = &myPrivateCryptoV3;
303  * operationGenerateZKP.hash = myHash3;
304  * operationGenerateZKP.r = myR3;
305  *
306  * result = ECJPAKE_generateZKP(handle, &operationGenerateZKP);
307  *
308  * // Exchange keys and ZKPs again
309  *
310  * // Verify their second round ZKP
311  * // Generate their round two hash here
312  *
313  * ECJPAKE_OperationVerifyZKP_init(&operationVerifyZKP);
314  * operationVerifyZKP.curve = &ECCParams_NISTP256;
315  * operationVerifyZKP.theirGenerator = &theirGeneratorKey;
316  * operationVerifyZKP.theirPublicKey = &theirCombinedPublicKey;
317  * operationVerifyZKP.theirPublicV = &theirPublicCryptoV3;
318  * operationVerifyZKP.hash = theirHash3;
319  * operationVerifyZKP.r = theirR3;
320  *
321  * result = ECJPAKE_verifyZKP(handle, &operationVerifyZKP);
322  *
323  * // Generate shared secret
324  * ECJPAKE_OperationComputeSharedSecret_init(&operationComputeSharedSecret);
325  * operationComputeSharedSecret.curve = &ECCParams_NISTP256;
326  * operationComputeSharedSecret.myCombinedPrivateKey = &myCombinedPrivateKey;
327  * operationComputeSharedSecret.theirCombinedPublicKey = &theirCombinedPublicKey;
328  * operationComputeSharedSecret.theirPublicKey2 = &theirPublicCryptoKey2;
329  * operationComputeSharedSecret.myPrivateKey2 = &myPrivateCryptoKey2;
330  * operationComputeSharedSecret.sharedSecret = &sharedSecretCryptoKey;
331  *
332  * result = ECJPAKE_computeSharedSecret(handle, &operationComputeSharedSecret);
333  *
334  * // Close the driver
335  * ECJPAKE_close(handle);
336  * @endcode
337  *
338  * @anchor ti_drivers_ECJPAKE_Examples
339  * # Examples #
340  *
341  * ## Basic ECJPAKE exchange #
342  *
343  * @code
344  *
345  *
346  * // My fixed keying material
347  * uint8_t myPrivateKeyMaterial1[32];
348  * uint8_t myPrivateKeyMaterial2[32];
349  * uint8_t myPrivateVMaterial1[32];
350  * uint8_t myPrivateVMaterial2[32];
351  * uint8_t myPrivateVMaterial3[32];
352  * uint8_t myHash1[32];
353  * uint8_t myHash2[32];
354  * uint8_t myHash3[32];
355  * // My derived keying material
356  * uint8_t myR1[32];
357  * uint8_t myR2[32];
358  * uint8_t myR3[32];
359  * uint8_t myPublicKeyMaterial1[64];
360  * uint8_t myPublicKeyMaterial2[64];
361  * uint8_t myPublicVMaterial1[64];
362  * uint8_t myPublicVMaterial2[64];
363  * uint8_t myPublicVMaterial3[64];
364  * uint8_t myCombinedPublicKeyMaterial1[64];
365  * uint8_t myCombinedPrivateKeyMaterial1[32];
366  * uint8_t myGenerator[64];
367  *
368  * // Their fixed keying material
369  * uint8_t theirHash1[32];
370  * uint8_t theirHash2[32];
371  * uint8_t theirHash3[32];
372  *
373  * // Their derived keying material
374  * uint8_t theirR1[32];
375  * uint8_t theirR2[32];
376  * uint8_t theirR3[32];
377  * uint8_t theirPublicKeyMaterial1[64];
378  * uint8_t theirPublicKeyMaterial2[64];
379  * uint8_t theirPublicVMaterial1[64];
380  * uint8_t theirPublicVMaterial2[64];
381  * uint8_t theirPublicVMaterial3[64];
382  * uint8_t theirCombinedPublicKeyMaterial1[64];
383  * uint8_t theirGenerator[64];
384  *
385  * // Shared secrets
386  * uint8_t preSharedSecretKeyingMaterial[32] = "This is our password";
387  * uint8_t sharedSecretKeyingMaterial1[64];
388  *
389  * // CryptoKeys
390  * CryptoKey nistP256GeneratorCryptoKey;
391  *
392  * // Pre-Shared Secret Key
393  * CryptoKey preSharedSecretCryptoKey;
394  *
395  * // Final shared secret keys
396  * CryptoKey sharedSecretCryptoKey;
397  *
398  * // My's keys
399  * CryptoKey myPrivateCryptoKey1;
400  * CryptoKey myPrivateCryptoKey2;
401  * CryptoKey myPrivateCryptoV1;
402  * CryptoKey myPrivateCryptoV2;
403  * CryptoKey myPrivateCryptoV3;
404  * CryptoKey myCombinedPrivateKey;
405  *
406  * CryptoKey myPublicCryptoKey1;
407  * CryptoKey myPublicCryptoKey2;
408  * CryptoKey myPublicCryptoV1;
409  * CryptoKey myPublicCryptoV2;
410  * CryptoKey myPublicCryptoV3;
411  * CryptoKey myCombinedPublicKey;
412  * CryptoKey myGeneratorKey;
413  *
414  * // Their's Keys
415  * CryptoKey theirPublicCryptoKey1;
416  * CryptoKey theirPublicCryptoKey2;
417  * CryptoKey theirPublicCryptoV1;
418  * CryptoKey theirPublicCryptoV2;
419  * CryptoKey theirPublicCryptoV3;
420  * CryptoKey theirCombinedPublicKey;
421  * CryptoKey theirGeneratorKey;
422  *
423  * // NISTP256 generator
424  * CryptoKeyPlaintext_initKey(&nistP256GeneratorCryptoKey, ECCParams_NISTP256.generatorX, sizeof(ECCParams_NISTP256.length * 2));
425  *
426  * // Pre-shared secret
427  * CryptoKeyPlaintext_initKey(&preSharedSecretCryptoKey, preSharedSecretKeyingMaterial, sizeof(preSharedSecretKeyingMaterial));
428  *
429  * // Final shared secret key
430  * CryptoKeyPlaintext_initKey(&sharedSecretCryptoKey, sharedSecretKeyingMaterial1, sizeof(sharedSecretKeyingMaterial1));
431  * CryptoKeyPlaintext_initKey(&sharedSecretCryptoKey2, sharedSecretKeyingMaterial2, sizeof(sharedSecretKeyingMaterial2));
432  *
433  *
434  * // My keys
435  * CryptoKeyPlaintext_initKey(&myPrivateCryptoKey1, myPrivateKeyMaterial1, sizeof(myPrivateKeyMaterial1));
436  * CryptoKeyPlaintext_initKey(&myPrivateCryptoKey2, myPrivateKeyMaterial2, sizeof(myPrivateKeyMaterial2));
437  * CryptoKeyPlaintext_initKey(&myPrivateCryptoV1, myPrivateVMaterial1, sizeof(myPrivateVMaterial1));
438  * CryptoKeyPlaintext_initKey(&myPrivateCryptoV2, myPrivateVMaterial2, sizeof(myPrivateVMaterial2));
439  * CryptoKeyPlaintext_initKey(&myPrivateCryptoV3, myPrivateVMaterial3, sizeof(myPrivateVMaterial3));
440  *
441  * CryptoKeyPlaintext_initBlankKey(&myPublicCryptoKey1, myPublicKeyMaterial1, sizeof(myPublicKeyMaterial1));
442  * CryptoKeyPlaintext_initBlankKey(&myPublicCryptoKey2, myPublicKeyMaterial2, sizeof(myPublicKeyMaterial2));
443  * CryptoKeyPlaintext_initBlankKey(&myPublicCryptoV1, myPublicVMaterial1, sizeof(myPublicVMaterial1));
444  * CryptoKeyPlaintext_initBlankKey(&myPublicCryptoV2, myPublicVMaterial2, sizeof(myPublicVMaterial2));
445  * CryptoKeyPlaintext_initBlankKey(&myPublicCryptoV3, myPublicVMaterial3, sizeof(myPublicVMaterial3));
446  * CryptoKeyPlaintext_initBlankKey(&myCombinedPrivateKey, myCombinedPrivateKeyMaterial1, sizeof(myCombinedPrivateKeyMaterial1));
447  * CryptoKeyPlaintext_initBlankKey(&myCombinedPublicKey, myCombinedPublicKeyMaterial1, sizeof(myCombinedPublicKeyMaterial1));
448  * CryptoKeyPlaintext_initBlankKey(&myGeneratorKey, myGenerator, sizeof(myGenerator));
449  *
450  * // Their keys
451  * CryptoKeyPlaintext_initBlankKey(&theirPublicCryptoKey1, theirPublicKeyMaterial1, sizeof(theirPublicKeyMaterial1));
452  * CryptoKeyPlaintext_initBlankKey(&theirPublicCryptoKey2, theirPublicKeyMaterial2, sizeof(theirPublicKeyMaterial2));
453  * CryptoKeyPlaintext_initBlankKey(&theirPublicCryptoV1, theirPublicVMaterial1, sizeof(theirPublicVMaterial1));
454  * CryptoKeyPlaintext_initBlankKey(&theirPublicCryptoV2, theirPublicVMaterial2, sizeof(theirPublicVMaterial2));
455  * CryptoKeyPlaintext_initBlankKey(&theirPublicCryptoV3, theirPublicVMaterial3, sizeof(theirPublicVMaterial3));
456  * CryptoKeyPlaintext_initBlankKey(&theirCombinedPublicKey, theirCombinedPublicKeyMaterial1, sizeof(theirCombinedPublicKeyMaterial1));
457  * CryptoKeyPlaintext_initBlankKey(&theirGeneratorKey, theirGenerator, sizeof(theirGenerator));
458  *
459  * // Initial driver setup
460  * ECJPAKE_Params params;
461  * ECJPAKE_Params_init(&params);
462  *
463  *
464  * ECJPAKE_Handle handle = ECJPAKE_open(0, &params);
465  *
466  * ECJPAKE_OperationRoundOneGenerateKeys operationRoundOneGenerateKeys;
467  * ECJPAKE_OperationRoundTwoGenerateKeys operationRoundTwoGenerateKeys;
468  * ECJPAKE_OperationGenerateZKP operationGenerateZKP;
469  * ECJPAKE_OperationVerifyZKP operationVerifyZKP;
470  * ECJPAKE_OperationComputeSharedSecret operationComputeSharedSecret;
471  *
472  * // Generate my round one keys
473  * ECJPAKE_OperationRoundOneGenerateKeys_init(&operationRoundOneGenerateKeys);
474  * operationRoundOneGenerateKeys.curve = &ECCParams_NISTP256;
475  * operationRoundOneGenerateKeys.myPrivateKey1 = &myPrivateCryptoKey1;
476  * operationRoundOneGenerateKeys.myPrivateKey2 = &myPrivateCryptoKey2;
477  * operationRoundOneGenerateKeys.myPublicKey1 = &myPublicCryptoKey1;
478  * operationRoundOneGenerateKeys.myPublicKey2 = &myPublicCryptoKey2;
479  * operationRoundOneGenerateKeys.myPrivateV1 = &myPrivateCryptoV1;
480  * operationRoundOneGenerateKeys.myPrivateV2 = &myPrivateCryptoV2;
481  * operationRoundOneGenerateKeys.myPublicV1 = &myPublicCryptoV1;
482  * operationRoundOneGenerateKeys.myPublicV2 = &myPublicCryptoV2;
483  *
484  * int_fast16_t result = ECJPAKE_roundOneGenerateKeys(handle, &operationRoundOneGenerateKeys);
485  *
486  * if (result != ECJPAKE_STATUS_SUCCESS) {
487  * while(1);
488  * }
489  *
490  * // Generate hashes here
491  *
492  * // generate my round one ZKPs
493  * ECJPAKE_OperationGenerateZKP_init(&operationGenerateZKP);
494  * operationGenerateZKP.curve = &ECCParams_NISTP256;
495  * operationGenerateZKP.myPrivateKey = &myPrivateCryptoKey1;
496  * operationGenerateZKP.myPrivateV = &myPrivateCryptoV1;
497  * operationGenerateZKP.hash = myHash1;
498  * operationGenerateZKP.r = myR1;
499  *
500  * result = ECJPAKE_generateZKP(handle, &operationGenerateZKP);
501  *
502  * if (result != ECJPAKE_STATUS_SUCCESS) {
503  * while(1);
504  * }
505  *
506  * ECJPAKE_OperationGenerateZKP_init(&operationGenerateZKP);
507  * operationGenerateZKP.curve = &ECCParams_NISTP256;
508  * operationGenerateZKP.myPrivateKey = &myPrivateCryptoKey2;
509  * operationGenerateZKP.myPrivateV = &myPrivateCryptoV2;
510  * operationGenerateZKP.hash = myHash2;
511  * operationGenerateZKP.r = myR2;
512  *
513  * result = ECJPAKE_generateZKP(handle, &operationGenerateZKP);
514  *
515  * if (result != ECJPAKE_STATUS_SUCCESS) {
516  * while(1);
517  * }
518  *
519  * // Do ZKP and key transmission here
520  *
521  * // Verify their round one ZKPs
522  * // Generate their hashes here
523  *
524  * ECJPAKE_OperationVerifyZKP_init(&operationVerifyZKP);
525  * operationVerifyZKP.curve = &ECCParams_NISTP256;
526  * operationVerifyZKP.theirGenerator = &nistP256GeneratorCryptoKey;
527  * operationVerifyZKP.theirPublicKey = &theirPublicCryptoKey1;
528  * operationVerifyZKP.theirPublicV = &theirPublicCryptoV1;
529  * operationVerifyZKP.hash = theirHash1;
530  * operationVerifyZKP.r = theirR1;
531  *
532  * result = ECJPAKE_verifyZKP(handle, &operationVerifyZKP);
533  *
534  * if (result != ECJPAKE_STATUS_SUCCESS) {
535  * while(1);
536  * }
537  *
538  * ECJPAKE_OperationVerifyZKP_init(&operationVerifyZKP);
539  * operationVerifyZKP.curve = &ECCParams_NISTP256;
540  * operationVerifyZKP.theirGenerator = &nistP256GeneratorCryptoKey;
541  * operationVerifyZKP.theirPublicKey = &theirPublicCryptoKey2;
542  * operationVerifyZKP.theirPublicV = &theirPublicCryptoV2;
543  * operationVerifyZKP.hash = theirHash2;
544  * operationVerifyZKP.r = theirR2;
545  *
546  * result = ECJPAKE_verifyZKP(handle,&operationVerifyZKP);
547  *
548  * if (result != ECJPAKE_STATUS_SUCCESS) {
549  * while(1);
550  * }
551  *
552  * // Round two starts now
553  *
554  * // Generate my round two keys
555  * ECJPAKE_OperationRoundTwoGenerateKeys_init(&operationRoundTwoGenerateKeys);
556  * operationRoundTwoGenerateKeys.curve = &ECCParams_NISTP256;
557  * operationRoundTwoGenerateKeys.myPrivateKey2 = &myPrivateCryptoKey2;
558  * operationRoundTwoGenerateKeys.myPublicKey1 = &myPublicCryptoKey1;
559  * operationRoundTwoGenerateKeys.myPublicKey2 = &myPublicCryptoKey2;
560  * operationRoundTwoGenerateKeys.theirPublicKey1 = &theirPublicCryptoKey1;
561  * operationRoundTwoGenerateKeys.theirPublicKey2 = &theirPublicCryptoKey2;
562  * operationRoundTwoGenerateKeys.preSharedSecret = &preSharedSecretCryptoKey;
563  * operationRoundTwoGenerateKeys.theirNewGenerator = &theirGeneratorKey;
564  * operationRoundTwoGenerateKeys.myNewGenerator = &myGeneratorKey;
565  * operationRoundTwoGenerateKeys.myCombinedPrivateKey = &myCombinedPrivateKey;
566  * operationRoundTwoGenerateKeys.myCombinedPublicKey = &myCombinedPublicKey;
567  * operationRoundTwoGenerateKeys.myPrivateV = &myPrivateCryptoV3;
568  * operationRoundTwoGenerateKeys.myPublicV = &myPublicCryptoV3;
569  *
570  * result = ECJPAKE_roundTwoGenerateKeys(handle, &operationRoundTwoGenerateKeys);
571  *
572  * // Generate my round two ZKP
573  * // Generate the round two hash here
574  *
575  * ECJPAKE_OperationGenerateZKP_init(&operationGenerateZKP);
576  * operationGenerateZKP.curve = &ECCParams_NISTP256;
577  * operationGenerateZKP.myPrivateKey = &myCombinedPrivateKey;
578  * operationGenerateZKP.myPrivateV = &myPrivateCryptoV3;
579  * operationGenerateZKP.hash = myHash3;
580  * operationGenerateZKP.r = myR3;
581  *
582  * result = ECJPAKE_generateZKP(handle, &operationGenerateZKP);
583  *
584  * if (result != ECJPAKE_STATUS_SUCCESS) {
585  * while(1);
586  * }
587  *
588  * // Exchange keys and ZKPs again
589  *
590  * // Verify their second round ZKP
591  * // Generate their round two hash here
592  *
593  * ECJPAKE_OperationVerifyZKP_init(&operationVerifyZKP);
594  * operationVerifyZKP.curve = &ECCParams_NISTP256;
595  * operationVerifyZKP.theirGenerator = &theirGeneratorKey;
596  * operationVerifyZKP.theirPublicKey = &theirCombinedPublicKey;
597  * operationVerifyZKP.theirPublicV = &theirPublicCryptoV3;
598  * operationVerifyZKP.hash = theirHash3;
599  * operationVerifyZKP.r = theirR3;
600  *
601  * result = ECJPAKE_verifyZKP(handle, &operationVerifyZKP);
602  *
603  * if (result != ECJPAKE_STATUS_SUCCESS) {
604  * while(1);
605  * }
606  *
607  *
608  * // Generate shared secret
609  * ECJPAKE_OperationComputeSharedSecret_init(&operationComputeSharedSecret);
610  * operationComputeSharedSecret.curve = &ECCParams_NISTP256;
611  * operationComputeSharedSecret.myCombinedPrivateKey = &myCombinedPrivateKey;
612  * operationComputeSharedSecret.theirCombinedPublicKey = &theirCombinedPublicKey;
613  * operationComputeSharedSecret.theirPublicKey2 = &theirPublicCryptoKey2;
614  * operationComputeSharedSecret.myPrivateKey2 = &myPrivateCryptoKey2;
615  * operationComputeSharedSecret.sharedSecret = &sharedSecretCryptoKey;
616  *
617  * result = ECJPAKE_computeSharedSecret(handle, &operationComputeSharedSecret);
618  *
619  * if (result != ECJPAKE_STATUS_SUCCESS) {
620  * while(1);
621  * }
622  *
623  * // Run sharedSecretCryptoKey through a key derivation function and
624  * // confirm to the other party that we have derived the same key
625  *
626  *
627  * @endcode
628  *
629  *
630  */
631 
632 
633 #ifndef ti_drivers_ECJPAKE__include
634 #define ti_drivers_ECJPAKE__include
635 
636 #ifdef __cplusplus
637 extern "C" {
638 #endif
639 
640 #include <stdbool.h>
641 #include <stddef.h>
642 #include <stdint.h>
643 
646 
659 #define ECJPAKE_STATUS_RESERVED (-32)
660 
667 #define ECJPAKE_STATUS_SUCCESS (0)
668 
675 #define ECJPAKE_STATUS_ERROR (-1)
676 
685 #define ECJPAKE_STATUS_RESOURCE_UNAVAILABLE (-2)
686 
692 #define ECJPAKE_STATUS_INVALID_PUBLIC_KEY (-3)
693 
700 #define ECJPAKE_STATUS_PUBLIC_KEY_NOT_ON_CURVE (-4)
701 
709 #define ECJPAKE_STATUS_PUBLIC_KEY_LARGER_THAN_PRIME (-5)
710 
717 #define ECJPAKE_STATUS_POINT_AT_INFINITY (-6)
718 
725 #define ECJPAKE_STATUS_INVALID_PRIVATE_KEY (-7)
726 
733 #define ECJPAKE_STATUS_INVALID_PRIVATE_V (-8)
734 
738 #define ECJPAKE_STATUS_CANCELED (-9)
739 
744 
766 typedef enum {
782 
794 typedef struct ECJPAKE_Config {
796  void *object;
797 
799  void const *hwAttrs;
801 
805 typedef struct {
860 
864 typedef struct {
877  const uint8_t *hash;
881  uint8_t *r;
885 
889 typedef struct {
906  const uint8_t *hash;
909  const uint8_t *r;
913 
917 typedef struct {
983 
987 typedef struct {
1011 
1012 
1016 typedef union {
1023 
1027 typedef enum {
1034 
1053 typedef void (*ECJPAKE_CallbackFxn) (ECJPAKE_Handle handle,
1054  int_fast16_t returnStatus,
1055  ECJPAKE_Operation operation,
1056  ECJPAKE_OperationType operationType);
1057 
1066 typedef struct {
1069  uint32_t timeout;
1072  void *custom;
1075 } ECJPAKE_Params;
1076 
1085 void ECJPAKE_init(void);
1086 
1096 
1106 
1116 
1126 
1127 
1137 
1147 void ECJPAKE_close(ECJPAKE_Handle handle);
1148 
1166 ECJPAKE_Handle ECJPAKE_open(uint_least8_t index, ECJPAKE_Params *params);
1167 
1180 void ECJPAKE_Params_init(ECJPAKE_Params *params);
1181 
1207 int_fast16_t ECJPAKE_roundOneGenerateKeys(ECJPAKE_Handle handle, ECJPAKE_OperationRoundOneGenerateKeys *operation);
1208 
1241 int_fast16_t ECJPAKE_generateZKP(ECJPAKE_Handle handle, ECJPAKE_OperationGenerateZKP *operation);
1242 
1266 int_fast16_t ECJPAKE_verifyZKP(ECJPAKE_Handle handle, ECJPAKE_OperationVerifyZKP *operation);
1267 
1291 int_fast16_t ECJPAKE_roundTwoGenerateKeys(ECJPAKE_Handle handle, ECJPAKE_OperationRoundTwoGenerateKeys *operation);
1292 
1318 int_fast16_t ECJPAKE_computeSharedSecret(ECJPAKE_Handle handle, ECJPAKE_OperationComputeSharedSecret *operation);
1319 
1333 int_fast16_t ECJPAKE_cancelOperation(ECJPAKE_Handle handle);
1334 
1335 #ifdef __cplusplus
1336 }
1337 #endif
1338 
1339 #endif /* ti_drivers_ECJPAKE__include */
Struct containing the parameters required to generate a ZKP.
Definition: ECJPAKE.h:864
const CryptoKey * myPrivateKey2
Definition: ECJPAKE.h:921
CryptoKey * myPublicKey2
Definition: ECJPAKE.h:822
The CryptoKey type is an opaque representation of a cryptographic key.
const uint8_t * hash
Definition: ECJPAKE.h:877
CryptoKey * myPrivateKey1
Definition: ECJPAKE.h:809
int_fast16_t ECJPAKE_computeSharedSecret(ECJPAKE_Handle handle, ECJPAKE_OperationComputeSharedSecret *operation)
Computes the shared secret.
ECJPAKE_OperationType
Enum for the operation types supported by the driver.
Definition: ECJPAKE.h:1027
CryptoKey * myPublicV2
Definition: ECJPAKE.h:850
void * object
Definition: ECJPAKE.h:796
void ECJPAKE_OperationVerifyZKP_init(ECJPAKE_OperationVerifyZKP *operation)
Function to initialize an ECJPAKE_OperationVerifyZKP struct to its defaults.
const ECCParams_CurveParams * curve
Definition: ECJPAKE.h:890
const CryptoKey * myCombinedPrivateKey
Definition: ECJPAKE.h:991
const ECCParams_CurveParams * curve
Definition: ECJPAKE.h:806
ECJPAKE_ReturnBehavior returnBehavior
Definition: ECJPAKE.h:1067
void ECJPAKE_close(ECJPAKE_Handle handle)
Function to close an ECJPAKE peripheral specified by the ECJPAKE handle.
ECJPAKE_OperationComputeSharedSecret * computeSharedSecret
Definition: ECJPAKE.h:1021
const CryptoKey * theirGenerator
Definition: ECJPAKE.h:893
const ECCParams_CurveParams * curve
Definition: ECJPAKE.h:918
void ECJPAKE_OperationRoundOneGenerateKeys_init(ECJPAKE_OperationRoundOneGenerateKeys *operation)
Function to initialize an ECJPAKE_OperationRoundOneGenerateKeys struct to its defaults.
CryptoKey datastructure.
Definition: CryptoKey.h:210
ECJPAKE_OperationRoundOneGenerateKeys * generateRoundOneKeys
Definition: ECJPAKE.h:1017
int_fast16_t ECJPAKE_roundTwoGenerateKeys(ECJPAKE_Handle handle, ECJPAKE_OperationRoundTwoGenerateKeys *operation)
Generates all public and private keying material for the first round of the EC-JPAKE scheme...
const CryptoKey * theirCombinedPublicKey
Definition: ECJPAKE.h:995
void ECJPAKE_OperationRoundTwoGenerateKeys_init(ECJPAKE_OperationRoundTwoGenerateKeys *operation)
Function to initialize an ECJPAKE_OperationRoundTwoGenerateKeys struct to its defaults.
int_fast16_t ECJPAKE_cancelOperation(ECJPAKE_Handle handle)
Cancels an ongoing ECJPAKE operation.
Struct containing the parameters required to generate the second round keys.
Definition: ECJPAKE.h:917
Struct containing the parameters required to compute the shared secret.
Definition: ECJPAKE.h:987
A structure containing the parameters of an elliptic curve in short Weierstrass form.
Definition: ECCParams.h:111
void(* ECJPAKE_CallbackFxn)(ECJPAKE_Handle handle, int_fast16_t returnStatus, ECJPAKE_Operation operation, ECJPAKE_OperationType operationType)
The definition of a callback function used by the ECJPAKE driver when used in ECJPAKE_RETURN_BEHAVIOR...
Definition: ECJPAKE.h:1053
int_fast16_t ECJPAKE_verifyZKP(ECJPAKE_Handle handle, ECJPAKE_OperationVerifyZKP *operation)
Verifies a Schnorr Zero-Knowledge Proof (ZKP) signature.
void ECJPAKE_init(void)
This function initializes the ECJPAKE module.
void * custom
Definition: ECJPAKE.h:1072
CryptoKey * myPublicV1
Definition: ECJPAKE.h:841
const CryptoKey * myPublicKey2
Definition: ECJPAKE.h:928
const CryptoKey * myPublicKey1
Definition: ECJPAKE.h:925
const CryptoKey * myPrivateKey
Definition: ECJPAKE.h:868
ECJPAKE Parameters.
Definition: ECJPAKE.h:1066
CryptoKey * myCombinedPublicKey
Definition: ECJPAKE.h:963
Struct containing the parameters required to generate the first round of keys.
Definition: ECJPAKE.h:805
Definition: ECJPAKE.h:777
CryptoKey * myPrivateKey2
Definition: ECJPAKE.h:813
int_fast16_t ECJPAKE_generateZKP(ECJPAKE_Handle handle, ECJPAKE_OperationGenerateZKP *operation)
Generates the r component of a Schnorr Zero-Knowledge Proof (ZKP) signature.
ECJPAKE_CallbackFxn callbackFxn
Definition: ECJPAKE.h:1068
const ECCParams_CurveParams * curve
Definition: ECJPAKE.h:865
const CryptoKey * preSharedSecret
Definition: ECJPAKE.h:937
CryptoKey * myNewGenerator
Definition: ECJPAKE.h:952
const CryptoKey * theirPublicKey1
Definition: ECJPAKE.h:931
ECJPAKE Global configuration.
Definition: ECJPAKE.h:794
CryptoKey * myPublicKey1
Definition: ECJPAKE.h:817
const CryptoKey * myPrivateV
Definition: ECJPAKE.h:872
CryptoKey * theirNewGenerator
Definition: ECJPAKE.h:946
const uint8_t * r
Definition: ECJPAKE.h:909
const CryptoKey * theirPublicKey2
Definition: ECJPAKE.h:998
void const * hwAttrs
Definition: ECJPAKE.h:799
Definition: ECJPAKE.h:1030
CryptoKey * myPrivateV
Definition: ECJPAKE.h:966
CryptoKey * myCombinedPrivateKey
Definition: ECJPAKE.h:958
Definition: ECJPAKE.h:767
struct ECJPAKE_Config ECJPAKE_Config
ECJPAKE Global configuration.
const uint8_t * hash
Definition: ECJPAKE.h:906
void ECJPAKE_Params_init(ECJPAKE_Params *params)
Function to initialize the ECJPAKE_Params struct to its defaults.
const CryptoKey * theirPublicKey2
Definition: ECJPAKE.h:934
Struct containing the parameters required to verify a ZKP.
Definition: ECJPAKE.h:889
ECJPAKE_OperationRoundTwoGenerateKeys * generateRoundTwoKeys
Definition: ECJPAKE.h:1020
CryptoKey * sharedSecret
Definition: ECJPAKE.h:1007
int_fast16_t ECJPAKE_roundOneGenerateKeys(ECJPAKE_Handle handle, ECJPAKE_OperationRoundOneGenerateKeys *operation)
Generates all public and private keying material for the first round of the EC-JPAKE scheme...
Definition: ECJPAKE.h:773
const CryptoKey * myPrivateKey2
Definition: ECJPAKE.h:1003
struct ECJPAKE_Config * ECJPAKE_Handle
A handle that is returned from an ECJPAKE_open() call.
Definition: ECJPAKE.h:743
ECJPAKE_OperationGenerateZKP * generateZKP
Definition: ECJPAKE.h:1018
Definition: ECJPAKE.h:1029
uint32_t timeout
Definition: ECJPAKE.h:1069
ECJPAKE_ReturnBehavior
The way in which ECJPAKE function calls return after performing an encryption + authentication or dec...
Definition: ECJPAKE.h:766
CryptoKey * myPrivateV2
Definition: ECJPAKE.h:834
CryptoKey * myPrivateV1
Definition: ECJPAKE.h:827
const CryptoKey * theirPublicV
Definition: ECJPAKE.h:903
CryptoKey * myPublicV
Definition: ECJPAKE.h:973
const CryptoKey * theirPublicKey
Definition: ECJPAKE.h:899
ECJPAKE_OperationVerifyZKP * verifyZKP
Definition: ECJPAKE.h:1019
Union containing pointers to all supported operation structs.
Definition: ECJPAKE.h:1016
ECJPAKE_Handle ECJPAKE_open(uint_least8_t index, ECJPAKE_Params *params)
This function opens a given ECJPAKE peripheral.
const ECCParams_CurveParams * curve
Definition: ECJPAKE.h:988
void ECJPAKE_OperationGenerateZKP_init(ECJPAKE_OperationGenerateZKP *operation)
Function to initialize an ECJPAKE_OperationGenerateZKP struct to its defaults.
uint8_t * r
Definition: ECJPAKE.h:881
void ECJPAKE_OperationComputeSharedSecret_init(ECJPAKE_OperationComputeSharedSecret *operation)
Function to initialize an ECJPAKE_OperationComputeSharedSecret struct to its defaults.
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale