Noise-C
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
dhstate.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef NOISE_DHSTATE_H
24 #define NOISE_DHSTATE_H
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
34 
35 int noise_dhstate_new_by_id(NoiseDHState **state, int id);
36 int noise_dhstate_new_by_name(NoiseDHState **state, const char *name);
38 int noise_dhstate_get_dh_id(const NoiseDHState *state);
43 int noise_dhstate_has_keypair(const NoiseDHState *state);
47  (NoiseDHState *state, const NoiseDHState *other);
49  (NoiseDHState *state, const uint8_t *private_key, size_t private_key_len,
50  const uint8_t *public_key, size_t public_key_len);
52  (NoiseDHState *state, const uint8_t *private_key, size_t private_key_len);
54  (const NoiseDHState *state, uint8_t *private_key, size_t private_key_len,
55  uint8_t *public_key, size_t public_key_len);
57  (NoiseDHState *state, const uint8_t *public_key, size_t public_key_len);
59  (const NoiseDHState *state, uint8_t *public_key, size_t public_key_len);
64  (const NoiseDHState *private_key_state,
65  const NoiseDHState *public_key_state,
66  uint8_t *shared_key, size_t shared_key_len);
67 int noise_dhstate_copy(NoiseDHState *state, const NoiseDHState *from);
69  (const NoiseDHState *state, int fingerprint_type, char *buffer, size_t len);
70 int noise_dhstate_get_role(const NoiseDHState *state);
72 
73 #ifdef __cplusplus
74 };
75 #endif
76 
77 #endif
int noise_dhstate_get_public_key(const NoiseDHState *state, uint8_t *public_key, size_t public_key_len)
Gets the public key value from a DHState object.
Definition: dhstate.c:551
int noise_dhstate_clear_key(NoiseDHState *state)
Clears the key in a DHState object.
Definition: dhstate.c:622
size_t noise_dhstate_get_public_key_length(const NoiseDHState *state)
Gets the length of the public key for a DHState object.
Definition: dhstate.c:183
int noise_dhstate_get_keypair(const NoiseDHState *state, uint8_t *private_key, size_t private_key_len, uint8_t *public_key, size_t public_key_len)
Gets the keypair from within a DHState object.
Definition: dhstate.c:462
uint8_t * public_key
Points to the public key in the subclass state.
Definition: internal.h:246
size_t noise_dhstate_get_shared_key_length(const NoiseDHState *state)
Gets the length of the shared key for a DHState object.
Definition: dhstate.c:213
int noise_dhstate_get_dh_id(const NoiseDHState *state)
Gets the algorithm identifier for a DHState object.
Definition: dhstate.c:168
int noise_dhstate_format_fingerprint(const NoiseDHState *state, int fingerprint_type, char *buffer, size_t len)
Formats the public key fingerprint for the key within a DHState.
Definition: dhstate.c:776
int noise_dhstate_get_role(const NoiseDHState *state)
Gets the role that a DHState object will play in a handshake.
Definition: dhstate.c:805
int noise_dhstate_new_by_id(NoiseDHState **state, int id)
Creates a new DHState object by its algorithm identifier.
Definition: dhstate.c:67
uint16_t shared_key_len
Length of the shared key for this algorithm in bytes.
Definition: internal.h:240
Internal structure of the NoiseDHState type.
Definition: internal.h:213
int noise_dhstate_is_ephemeral_only(const NoiseDHState *state)
Determine if a DHState object only supports ephemeral keys.
Definition: dhstate.c:230
int noise_dhstate_has_keypair(const NoiseDHState *state)
Determine if a DHState object contains a keypair.
Definition: dhstate.c:247
int noise_dhstate_set_null_public_key(NoiseDHState *state)
Sets the public key in a DHState object to the special null value.
Definition: dhstate.c:576
int noise_dhstate_calculate(const NoiseDHState *private_key_state, const NoiseDHState *public_key_state, uint8_t *shared_key, size_t shared_key_len)
Performs a Diffie-Hellman calculation.
Definition: dhstate.c:686
int noise_dhstate_set_keypair(NoiseDHState *state, const uint8_t *private_key, size_t private_key_len, const uint8_t *public_key, size_t public_key_len)
Sets the keypair within a DHState object.
Definition: dhstate.c:374
int noise_dhstate_free(NoiseDHState *state)
Frees a DHState object after destroying all sensitive material.
Definition: dhstate.c:146
int noise_dhstate_generate_keypair(NoiseDHState *state)
Generates a new key pair within a DHState object.
Definition: dhstate.c:289
int noise_dhstate_has_public_key(const NoiseDHState *state)
Determine if a DHState object contains a public key.
Definition: dhstate.c:267
int noise_dhstate_is_null_public_key(const NoiseDHState *state)
Determine if the public key in a DHState object has the special null value.
Definition: dhstate.c:602
int noise_dhstate_new_by_name(NoiseDHState **state, const char *name)
Creates a new DHState object by its algorithm name.
Definition: dhstate.c:116
uint16_t private_key_len
Length of the private key for this algorithm in bytes.
Definition: internal.h:234
int noise_dhstate_copy(NoiseDHState *state, const NoiseDHState *from)
Copies the keys from one DHState object to another.
Definition: dhstate.c:730
size_t noise_dhstate_get_private_key_length(const NoiseDHState *state)
Gets the length of the private key for a DHState object.
Definition: dhstate.c:198
int noise_dhstate_set_keypair_private(NoiseDHState *state, const uint8_t *private_key, size_t private_key_len)
Sets the keypair within a DHState object based on a private key only.
Definition: dhstate.c:423
int noise_dhstate_set_public_key(NoiseDHState *state, const uint8_t *public_key, size_t public_key_len)
Sets the public key in a DHState object.
Definition: dhstate.c:511
int noise_dhstate_set_role(NoiseDHState *state, int role)
Sets the role that a DHState object will play in a handshake.
Definition: dhstate.c:835
int noise_dhstate_generate_dependent_keypair(NoiseDHState *state, const NoiseDHState *other)
Generates a new key pair within a DHState object that may depend upon the parameters from another DHS...
Definition: dhstate.c:332
uint8_t * private_key
Points to the private key in the subclass state.
Definition: internal.h:243
short role
The role; either initiator or responder or zero.
Definition: internal.h:222
uint16_t public_key_len
Length of the public key for this algorithm in bytes.
Definition: internal.h:237