Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
ecdh.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2024, RISE Research Institutes of Sweden AB
3
* Copyright (c) 2020, Industrial Systems Institute (ISI), Patras, Greece
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of the copyright holder nor the names of its contributors
15
* may be used to endorse or promote products derived from this software
16
* without specific prior written permission.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
* SUCH DAMAGE.
29
*
30
*/
31
32
/**
33
* \file
34
* ECDH interface for the EDHOC implementation.
35
*
36
* Thin synchronous wrapper around the Contiki-NG ECC driver
37
* (\c lib/ecc.h). Long-running operations from the underlying
38
* driver are busy-waited to completion so that the EDHOC
39
* protocol code can stay synchronous.
40
*
41
* \author
42
* Lidia Pocero <pocero@isi.gr>, Peter A Jonsson, Rikard Höglund, Marco Tiloca
43
*/
44
#ifndef _ECDH_H_
45
#define _ECDH_H_
46
47
#include <stdint.h>
48
#include <stdbool.h>
49
#include "
edhoc-key-storage.h
"
50
51
/**
52
* \brief Generates a fresh ECDH key pair.
53
* \param curve_id The EDHOC curve identifier (e.g. \c EDHOC_CURVE_P256).
54
* \param pub_x Output buffer for the x-coordinate (\c ECC_KEY_LEN bytes).
55
* \param pub_y Output buffer for the y-coordinate (\c ECC_KEY_LEN bytes).
56
* \param priv Output buffer for the private key (\c ECC_KEY_LEN bytes).
57
* \return true on success, false on error.
58
*/
59
bool
ecdh_generate_keypair
(uint8_t curve_id,
60
uint8_t *pub_x, uint8_t *pub_y, uint8_t *priv);
61
62
/**
63
* \brief Computes an ECDH shared secret.
64
* \param curve_id The EDHOC curve identifier (e.g. \c EDHOC_CURVE_P256).
65
* \param peer_x The peer's public-key x-coordinate (\c ECC_KEY_LEN bytes).
66
* The y-coordinate is recovered from \p peer_x using
67
* point decompression (odd-y branch), so EDHOC's
68
* x-only on-wire encoding can be passed in directly.
69
* \param private_key Our private key (\c ECC_KEY_LEN bytes).
70
* \param ikm Output buffer for the shared secret (\c ECC_KEY_LEN bytes).
71
* \return true on success, false on error.
72
*/
73
bool
ecdh_generate_ikm
(uint8_t curve_id,
74
const
uint8_t *peer_x,
75
const
uint8_t *private_key, uint8_t *ikm);
76
77
/**
78
* \brief Generates an ECDSA signature for a message hash.
79
* \param curve_id The EDHOC curve identifier (e.g. \c EDHOC_CURVE_P256).
80
* \param hash The message hash (\c ECC_KEY_LEN bytes).
81
* \param private_key The signer's private key (\c ECC_KEY_LEN bytes).
82
* \param signature Output buffer for the signature (\c 2*ECC_KEY_LEN bytes).
83
* \return true on success, false on error.
84
*/
85
bool
ecc_sign_hash
(uint8_t curve_id,
86
const
uint8_t *hash,
87
const
uint8_t *private_key,
88
uint8_t *signature);
89
90
/**
91
* \brief Verifies an ECDSA signature of a message hash.
92
* \param curve_id The EDHOC curve identifier (e.g. \c EDHOC_CURVE_P256).
93
* \param hash The message hash (\c ECC_KEY_LEN bytes).
94
* \param public_key The signer's public key (\c 2*ECC_KEY_LEN bytes).
95
* \param signature The signature to verify (\c 2*ECC_KEY_LEN bytes).
96
* \return true if the signature is valid, false otherwise.
97
*/
98
bool
ecc_verify_hash
(uint8_t curve_id,
99
const
uint8_t *hash,
100
const
uint8_t *public_key,
101
const
uint8_t *signature);
102
103
#endif
/* _ECDH_H_ */
ecc_sign_hash
bool ecc_sign_hash(uint8_t curve_id, const uint8_t *hash, const uint8_t *private_key, uint8_t *signature)
Generates an ECDSA signature for a message hash.
Definition
ecdh.c:174
ecdh_generate_ikm
bool ecdh_generate_ikm(uint8_t curve_id, const uint8_t *peer_x, const uint8_t *private_key, uint8_t *ikm)
Computes an ECDH shared secret.
Definition
ecdh.c:123
ecc_verify_hash
bool ecc_verify_hash(uint8_t curve_id, const uint8_t *hash, const uint8_t *public_key, const uint8_t *signature)
Verifies an ECDSA signature of a message hash.
Definition
ecdh.c:203
ecdh_generate_keypair
bool ecdh_generate_keypair(uint8_t curve_id, uint8_t *pub_x, uint8_t *pub_y, uint8_t *priv)
Generates a fresh ECDH key pair.
Definition
ecdh.c:91
edhoc-key-storage.h
EDHOC key storage - Implementation of key storage for managing DH-static authentication key pairs.
os
net
security
edhoc
ecdh.h
Generated on
for Contiki-NG by
1.17.0