1 /* ecc.h - ECDH helpers */ 2 3 /* 4 * Copyright (c) 2016 Intel Corporation 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 /* @brief Container for public key callback */ 10 struct bt_pub_key_cb { 11 /** @brief Callback type for Public Key generation. 12 * 13 * Used to notify of the local public key or that the local key is not 14 * available (either because of a failure to read it or because it is 15 * being regenerated). 16 * 17 * @param key The local public key, or NULL in case of no key. 18 */ 19 void (*func)(const u8_t key[64]); 20 21 struct bt_pub_key_cb *_next; 22 }; 23 24 /* @brief Generate a new Public Key. 25 * 26 * Generate a new ECC Public Key. The callback will persist even after the 27 * key has been generated, and will be used to notify of new generation 28 * processes (NULL as key). 29 * 30 * @param cb Callback to notify the new key, or NULL to request an update 31 * without registering any new callback. 32 * 33 * @return Zero on success or negative error code otherwise 34 */ 35 int bt_pub_key_gen(struct bt_pub_key_cb *cb); 36 37 /* @brief Get the current Public Key. 38 * 39 * Get the current ECC Public Key. 40 * 41 * @return Current key, or NULL if not available. 42 */ 43 const u8_t *bt_pub_key_get(void); 44 45 /* @typedef bt_dh_key_cb_t 46 * @brief Callback type for DH Key calculation. 47 * 48 * Used to notify of the calculated DH Key. 49 * 50 * @param key The DH Key, or NULL in case of failure. 51 */ 52 typedef void (*bt_dh_key_cb_t)(const u8_t key[32]); 53 54 /* @brief Calculate a DH Key from a remote Public Key. 55 * 56 * Calculate a DH Key from the remote Public Key. 57 * 58 * @param remote_pk Remote Public Key. 59 * @param cb Callback to notify the calculated key. 60 * 61 * @return Zero on success or negative error code otherwise 62 */ 63 int bt_dh_key_gen(const u8_t remote_pk[64], bt_dh_key_cb_t cb); 64