Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / extlibs / tinydtls / ecc / ecc.h
index 92e1313..dd09ce6 100644 (file)
@@ -84,6 +84,146 @@ Inputs:
 */
 void uECC_set_rng(uECC_RNG_Function p_rng);
 
+//////////////////////////////////////////
+// DTLS_CRYPTO_HAL
+/**
+* Call this function to create a unique public-private key pair in secure hardware
+*
+* @param[out] p_publicKey  The public key that is associated with the private key that was just created.
+* @param[out] p_privateKeyHandle  A handle that is used to point to the private key stored in hardware.
+* @return 1 upon success, 0 if an error occurred.
+*/
+typedef int (*uECC_make_key_Function)(uint8_t p_publicKey[uECC_BYTES*2], uint8_t p_privateKeyHandle[uECC_BYTES]);
+
+/**
+* Set the callback function that will be used to generate a public-private key pair.
+* This function will replace uECC_make_key.
+*
+* @param[in] p_make_key_cb  The function that will be used to generate a public-private key pair.
+*/
+void uECC_set_make_key_cb(uECC_make_key_Function p_make_key_cb);
+
+/**
+* Call this function to sign a hash using a hardware protected private key.
+*
+* @param[in] p_privateKeyHandle  A handle that is used to point to the private key stored in hardware.
+* @param[in] p_hash  The hash to sign.
+* @param[out] p_signature  The signature that is produced in hardware by the private key..
+* @return 1 upon success, 0 if an error occurred.
+*/
+typedef int (*uECC_sign_Function)(uint8_t p_privateKeyHandle[uECC_BYTES], const uint8_t p_hash[uECC_BYTES], uint8_t p_signature[uECC_BYTES*2]);
+
+/**
+* Set the callback function that will be used to sign.
+* This function will replace uECC_sign.
+*
+* @param[in] p_sign_cb  The function that will be used to sign.
+*/
+void uECC_set_sign_cb(uECC_sign_Function p_sign_cb);
+
+/**
+* Call this function to verify a signature using the public key and hash that was signed. 
+*
+* @param[in] p_publicKey  The public key that is associated with the private key that produced the signature.
+* @param[in] p_hash  The hash that was signed.
+* @param[in] p_signature  The signature that was produced the private key that is associated with p_public_key
+* @return 1 upon success, 0 if an error occurred.
+*/
+typedef int (*uECC_verify_Function)(const uint8_t p_publicKey[uECC_BYTES*2], const uint8_t p_hash[uECC_BYTES], const uint8_t p_signature[uECC_BYTES*2]);
+
+/**
+* Set the callback function that will be used to verify.
+* This function will replace uECC_verify.
+*
+* @param[in] p_verify_cb  The function that will be used to verify.
+*/
+void uECC_set_verify_cb(uECC_verify_Function p_verify_cb);
+
+/**
+* Call this function to produce an ECDH shared key using the public key of the other node.
+* A hardware protected private key will be used for the point multiply
+*
+* @param[in] p_publicKey  The public key from the other node used for communication.
+* @param[in] p_privateKeyHandle  A handle that is used to point to the private key stored in hardware.
+* @param[out] p_secret  The pre-master key that is produced by the point multiply with p_public_key and our private key
+* @return 1 upon success, 0 if an error occurred.
+*/
+typedef int (*uECC_shared_secret_Function)(const uint8_t p_publicKey[uECC_BYTES*2], const uint8_t p_privateKeyHandle[uECC_BYTES], uint8_t p_secret[uECC_BYTES]);
+
+/**
+* Set the callback function that will be used to produce a shared secret.
+* This function will replace uECC_shared_secret.
+*
+* @param[in] p_make_key_cb  The function that will be used to generate the shared secret.
+*/
+void uECC_set_shared_secret_cb(uECC_shared_secret_Function p_shared_secret_cb);
+
+/**
+* Call this function to produce a shared key using the public key of the other node.
+* An ephemeral private key will be created in secure hardware that will be used for the point multiply
+*
+* @param[in] p_public_key  The public key from the other node used for communication.
+* @param[out] p_public_key_out  The ephemeral public key that will be used in the point multiply.
+* @param[out] p_secret  The pre-master key that is produced by the point multiply with p_public_key and our private key
+* @return 1 upon success, 0 if an error occurred.
+*/
+typedef int (*uECC_ecdhe_Function)(const uint8_t p_public_key_in[uECC_BYTES*2],
+                                   uint8_t p_public_key_out[uECC_BYTES*2],
+                                   uint8_t p_secret[uECC_BYTES]);
+
+/**
+* Set the callback function that will be used to produce a ECDHE shared secret.
+*
+* @param[in] p_ecdhe_cb  The function that will be used to generate the ECDHE shared secret.
+*/
+void uECC_set_ecdhe_cb(uECC_ecdhe_Function p_ecdhe_cb);
+
+/**
+* Call this function to return the public key for an existing private key.
+*
+* @param[out] p_key_handle  A handle that is used to point to the private key stored in hardware.
+*    The public key that is associated with this private key will be returned
+* @param[out] p_public_key  The public key that is associated with the private key that was just created.
+* @return 1 upon success, 0 if an error occurred.
+*/
+typedef int (*uECC_get_pubkey_Function)(const uint8_t p_key_handle[uECC_BYTES],
+                                        uint8_t p_public_key[uECC_BYTES*2]);
+
+/**
+* Set the callback function that will be used to return the public key for an existing private key.
+*
+* @param[in] p_get_pubkey_cb  The function that will be used to return the public key for an existing private key.
+*/
+void uECC_set_get_pubkey_cb(uECC_get_pubkey_Function p_get_pubkey_cb);
+
+
+/**
+* Call this function to produce a shared key using the public key of the other node.
+* An ephemeral private key will be created that will be used for the point multiply
+*
+* @param[in] p_public_key  The public key from the other node used for communication.
+* @param[out] p_public_key_out  The ephemeral public key that will be used in the point multiply.
+* @param[out] p_secret  The pre-master key that is produced by the point multiply with p_public_key and our private key
+* @return 1 upon success, 0 if an error occurred.
+*/
+int uECC_ecdhe(const uint8_t p_public_key_in[uECC_BYTES*2],
+               uint8_t p_public_key_out[uECC_BYTES*2],
+               uint8_t p_secret[uECC_BYTES]);
+
+/**
+* Call this function to return the public key for an existing private key.
+*
+* @param[out] p_key_handle  A handle that is used to point to the private key stored in hardware.
+*    The public key that is associated with this private key will be returned
+* @param[out] p_public_key  The public key that is associated with the private key that was just created.
+* @return 1 upon success, 0 if an error occurred.
+*/
+int uECC_get_pubkey(const uint8_t p_key_handle[uECC_BYTES],
+                    uint8_t p_public_key[uECC_BYTES*2]);
+
+//////////////////////////////////////////
+
+
 /* uECC_make_key() function.
 Create a public/private key pair.