Noise-C
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Data Structures | Macros | Functions
internal.h File Reference

Internal definitions for the library. More...

#include <noise/protocol.h>
#include <alloca.h>

Go to the source code of this file.

Data Structures

struct  NoiseCipherState_s
 Internal structure of the NoiseCipherState type. More...
 
struct  NoiseDHState_s
 Internal structure of the NoiseDHState type. More...
 
struct  NoiseHandshakeState_s
 Internal structure of the NoiseHandshakeState type. More...
 
struct  NoiseHashState_s
 Internal structure of the NoiseHashState type. More...
 
struct  NoiseSignState_s
 Internal structure of the NoiseSignState type. More...
 
struct  NoiseSymmetricState_s
 Internal structure of the NoiseSymmetricState type. More...
 

Macros

#define NOISE_KEY_TYPE_KEYPAIR   1
 
#define NOISE_KEY_TYPE_NO_KEY   0
 
#define NOISE_KEY_TYPE_PUBLIC   2
 
#define NOISE_MAX_HASHLEN   64
 Maximum hash length over all supported hash algorithms. More...
 
#define NOISE_PAT_FLAG_LOCAL_EPHEM_REQ   (1 << 3)
 
#define NOISE_PAT_FLAG_LOCAL_EPHEMERAL   (1 << 1)
 
#define NOISE_PAT_FLAG_LOCAL_HYBRID   (1 << 4)
 
#define NOISE_PAT_FLAG_LOCAL_HYBRID_REQ   (1 << 5)
 
#define NOISE_PAT_FLAG_LOCAL_REQUIRED   (1 << 2)
 
#define NOISE_PAT_FLAG_LOCAL_STATIC   (1 << 0)
 
#define NOISE_PAT_FLAG_REMOTE_EPHEM_REQ   (1 << 11)
 
#define NOISE_PAT_FLAG_REMOTE_EPHEMERAL   (1 << 9)
 
#define NOISE_PAT_FLAG_REMOTE_HYBRID   (1 << 12)
 
#define NOISE_PAT_FLAG_REMOTE_HYBRID_REQ   (1 << 13)
 
#define NOISE_PAT_FLAG_REMOTE_REQUIRED   (1 << 10)
 
#define NOISE_PAT_FLAG_REMOTE_STATIC   (1 << 8)
 
#define NOISE_PSK_LEN   32
 Standard length for pre-shared keys. More...
 
#define NOISE_REQ_FALLBACK_POSSIBLE   (1 << 6)
 
#define NOISE_REQ_FALLBACK_PREMSG   (1 << 3)
 
#define NOISE_REQ_LOCAL_PREMSG   (1 << 4)
 
#define NOISE_REQ_LOCAL_REQUIRED   (1 << 0)
 
#define NOISE_REQ_PSK   (1 << 2)
 
#define NOISE_REQ_REMOTE_PREMSG   (1 << 5)
 
#define NOISE_REQ_REMOTE_REQUIRED   (1 << 1)
 
#define NOISE_TOKEN_E   2
 
#define NOISE_TOKEN_EE   3
 
#define NOISE_TOKEN_END   0
 
#define NOISE_TOKEN_ES   4
 
#define NOISE_TOKEN_F   7
 
#define NOISE_TOKEN_FF   8
 
#define NOISE_TOKEN_FLIP_DIR   255
 
#define NOISE_TOKEN_S   1
 
#define NOISE_TOKEN_SE   5
 
#define NOISE_TOKEN_SS   6
 

Functions

const uint8_t * noise_pattern_lookup (int id)
 Looks up a specific handshake pattern. More...
 
NoisePatternFlags_t noise_pattern_reverse_flags (NoisePatternFlags_t flags)
 Reverses the local and remote flags for a pattern. More...
 
void noise_rand_bytes (void *bytes, size_t size)
 Gets cryptographically-strong random bytes from the operating system. More...
 

Detailed Description

Internal definitions for the library.

Note
This file and its definitions are not part of the public API. The definitions are subject to change without notice.

Definition in file internal.h.


Data Structure Documentation

struct NoiseHandshakeState_s

Internal structure of the NoiseHandshakeState type.

Definition at line 531 of file internal.h.

Data Fields
int action Next action to be taken by the application.
NoiseDHState * dh_fixed_ephemeral Points to the object for the fixed ephemeral test key.
NoiseDHState * dh_fixed_hybrid Points to the object for the fixed hybrid forward secrecy test key.
NoiseDHState * dh_local_ephemeral Points to the DHState object for local ephemeral key.
NoiseDHState * dh_local_hybrid Points to the DHState object for local hybrid forward secrecy key.
NoiseDHState * dh_local_static Points to the DHState object for local static key.
NoiseDHState * dh_remote_ephemeral Points to the DHState object for remote ephemeral key.
NoiseDHState * dh_remote_hybrid Points to the DHState object for remote hybrid forward secrecy key.
NoiseDHState * dh_remote_static Points to the DHState object for remote static key.
uint8_t pre_shared_key[NOISE_PSK_LEN] Pre-shared key value.
size_t pre_shared_key_len Length of the pre-shared key value: zero or NOISE_PSK_LEN only.
uint8_t * prologue Points to the prologue value.
size_t prologue_len Length of the prologue value in bytes.
int requirements Requirements that are yet to be satisfied.
int role The role of this object, initiator or responder.
size_t size Total size of the structure, including DH key storage.
NoiseSymmetricState * symmetric Points to the SymmetricState object for this HandshakeState.
const uint8_t * tokens Points to the next message pattern tokens to be processed.
struct NoiseSymmetricState_s

Internal structure of the NoiseSymmetricState type.

Definition at line 500 of file internal.h.

Data Fields
NoiseCipherState * cipher Points to the CipherState object for this SymmetricState.

When the SymmetricState is split, this field will be set to NULL as the CipherState will be handed off to the application with a new key.

See Also
noise_symmetricstate_split()
uint8_t ck[NOISE_MAX_HASHLEN] Current value of the chaining key for the handshake.
uint8_t h[NOISE_MAX_HASHLEN] Current value of the handshake hash.
NoiseHashState * hash Points to the HashState object for this SymmetricState.
NoiseProtocolId id Algorithm identifiers for the components of the protocol.
size_t size Total size of the structure.

Macro Definition Documentation

#define NOISE_KEY_TYPE_KEYPAIR   1

Set to a keypair

Definition at line 207 of file internal.h.

#define NOISE_KEY_TYPE_NO_KEY   0

No key set yet

Definition at line 206 of file internal.h.

#define NOISE_KEY_TYPE_PUBLIC   2

Set to a public key only

Definition at line 208 of file internal.h.

#define NOISE_MAX_HASHLEN   64

Maximum hash length over all supported hash algorithms.

Definition at line 48 of file internal.h.

#define NOISE_PAT_FLAG_LOCAL_EPHEM_REQ   (1 << 3)

Pattern requires that the local ephemeral key be provided ahead of time to start the protocol (for XXfallback)

Definition at line 611 of file internal.h.

#define NOISE_PAT_FLAG_LOCAL_EPHEMERAL   (1 << 1)

Pattern requires a local ephemeral keypair

Definition at line 603 of file internal.h.

#define NOISE_PAT_FLAG_LOCAL_HYBRID   (1 << 4)

Pattern requires a local hybrid keypair

Definition at line 613 of file internal.h.

#define NOISE_PAT_FLAG_LOCAL_HYBRID_REQ   (1 << 5)

Pattern requires that the local hybrid key be provided ahead of time to start the protocol (for XXfallback)

Definition at line 616 of file internal.h.

#define NOISE_PAT_FLAG_LOCAL_REQUIRED   (1 << 2)

Pattern requires that the local public key be provided ahead of time to start the protocol. That is, it is not sent as part of the protocol but is assumed to already be known to the other party.

Definition at line 608 of file internal.h.

#define NOISE_PAT_FLAG_LOCAL_STATIC   (1 << 0)

Pattern requires a local static keypair

Definition at line 601 of file internal.h.

#define NOISE_PAT_FLAG_REMOTE_EPHEM_REQ   (1 << 11)

Pattern requires that the remote ephemeral key be provided ahead of time to start the protocol (for XXfallback)

Definition at line 629 of file internal.h.

#define NOISE_PAT_FLAG_REMOTE_EPHEMERAL   (1 << 9)

Pattern requires a remote ephemeral public key

Definition at line 621 of file internal.h.

#define NOISE_PAT_FLAG_REMOTE_HYBRID   (1 << 12)

Pattern requires a remote hybrid public key

Definition at line 631 of file internal.h.

#define NOISE_PAT_FLAG_REMOTE_HYBRID_REQ   (1 << 13)

Pattern requires that the remote hybrid key be provided ahead of time to start the protocol (for XXfallback)

Definition at line 634 of file internal.h.

#define NOISE_PAT_FLAG_REMOTE_REQUIRED   (1 << 10)

Pattern requires that the remote public key be provided ahead of time to start the protocol. That is, it is not sent as part of the protocol but is assumed to already be known to the other party.

Definition at line 626 of file internal.h.

#define NOISE_PAT_FLAG_REMOTE_STATIC   (1 << 8)

Pattern requires a remote static public key

Definition at line 619 of file internal.h.

#define NOISE_PSK_LEN   32

Standard length for pre-shared keys.

Definition at line 53 of file internal.h.

#define NOISE_REQ_FALLBACK_POSSIBLE   (1 << 6)

Fallback is possible from this pattern (two-way, ends in "K")

Definition at line 649 of file internal.h.

#define NOISE_REQ_FALLBACK_PREMSG   (1 << 3)

Emphemeral key for fallback pre-message has been provided

Definition at line 643 of file internal.h.

#define NOISE_REQ_LOCAL_PREMSG   (1 << 4)

Local public key is part of the pre-message

Definition at line 645 of file internal.h.

#define NOISE_REQ_LOCAL_REQUIRED   (1 << 0)

Local static keypair is required for the handshake

Definition at line 637 of file internal.h.

#define NOISE_REQ_PSK   (1 << 2)

Pre-shared key has not been provided yet

Definition at line 641 of file internal.h.

#define NOISE_REQ_REMOTE_PREMSG   (1 << 5)

Remote public key is part of the pre-message

Definition at line 647 of file internal.h.

#define NOISE_REQ_REMOTE_REQUIRED   (1 << 1)

Remote public key is required for the handshake

Definition at line 639 of file internal.h.

#define NOISE_TOKEN_E   2

"e" token

Definition at line 591 of file internal.h.

#define NOISE_TOKEN_EE   3

"ee" token

Definition at line 592 of file internal.h.

#define NOISE_TOKEN_END   0

End of pattern, start data session

Definition at line 589 of file internal.h.

#define NOISE_TOKEN_ES   4

"es" token

Definition at line 593 of file internal.h.

#define NOISE_TOKEN_F   7

"f" token (hybrid forward secrecy)

Definition at line 596 of file internal.h.

#define NOISE_TOKEN_FF   8

"ff" token (hybrid forward secrecy)

Definition at line 597 of file internal.h.

#define NOISE_TOKEN_FLIP_DIR   255

Flip the handshake direction

Definition at line 598 of file internal.h.

#define NOISE_TOKEN_S   1

"s" token

Definition at line 590 of file internal.h.

#define NOISE_TOKEN_SE   5

"se" token

Definition at line 594 of file internal.h.

#define NOISE_TOKEN_SS   6

"ss" token

Definition at line 595 of file internal.h.

Function Documentation

const uint8_t* noise_pattern_lookup ( int  id)

Looks up a specific handshake pattern.

Parameters
idThe identifier for the handshake pattern.
Returns
A pointer to the pattern or NULL if id is unknown.

The first byte of the returned pattern contains the pattern flags. The remaining bytes are the token for the pattern, terminated by NOISE_TOKEN_END.

Definition at line 1253 of file patterns.c.

NoisePatternFlags_t noise_pattern_reverse_flags ( NoisePatternFlags_t  flags)

Reverses the local and remote flags for a pattern.

Parameters
flagsThe flags, assuming that the initiator is "local".
Returns
The reversed flags, with the responder now being "local".

Definition at line 1306 of file patterns.c.

void noise_rand_bytes ( void *  bytes,
size_t  size 
)

Gets cryptographically-strong random bytes from the operating system.

Parameters
bytesThe buffer to fill with random bytes.
sizeThe number of random bytes to obtain.

This function should not block waiting for entropy.

Note
Not part of the public API.

Definition at line 68 of file rand_os.c.