23 #ifndef NOISE_INTERNAL_H
24 #define NOISE_INTERNAL_H
27 #if defined(__WIN32__) || defined(WIN32)
48 #define NOISE_MAX_HASHLEN 64
53 #define NOISE_PSK_LEN 32
114 uint8_t *data,
size_t len);
131 uint8_t *data,
size_t len);
206 #define NOISE_KEY_TYPE_NO_KEY 0
207 #define NOISE_KEY_TYPE_KEYPAIR 1
208 #define NOISE_KEY_TYPE_PUBLIC 2
213 struct NoiseDHState_s
228 uint8_t ephemeral_only : 1;
231 uint8_t nulls_allowed : 1;
274 const uint8_t *public_key);
286 int (*set_keypair_private)
299 int (*validate_public_key)
332 uint8_t *shared_key);
461 size_t message_len, uint8_t *signature);
480 size_t message_len,
const uint8_t *signature);
589 #define NOISE_TOKEN_END 0
590 #define NOISE_TOKEN_S 1
591 #define NOISE_TOKEN_E 2
592 #define NOISE_TOKEN_EE 3
593 #define NOISE_TOKEN_ES 4
594 #define NOISE_TOKEN_SE 5
595 #define NOISE_TOKEN_SS 6
596 #define NOISE_TOKEN_F 7
597 #define NOISE_TOKEN_FF 8
598 #define NOISE_TOKEN_FLIP_DIR 255
601 #define NOISE_PAT_FLAG_LOCAL_STATIC (1 << 0)
603 #define NOISE_PAT_FLAG_LOCAL_EPHEMERAL (1 << 1)
608 #define NOISE_PAT_FLAG_LOCAL_REQUIRED (1 << 2)
611 #define NOISE_PAT_FLAG_LOCAL_EPHEM_REQ (1 << 3)
613 #define NOISE_PAT_FLAG_LOCAL_HYBRID (1 << 4)
616 #define NOISE_PAT_FLAG_LOCAL_HYBRID_REQ (1 << 5)
619 #define NOISE_PAT_FLAG_REMOTE_STATIC (1 << 8)
621 #define NOISE_PAT_FLAG_REMOTE_EPHEMERAL (1 << 9)
626 #define NOISE_PAT_FLAG_REMOTE_REQUIRED (1 << 10)
629 #define NOISE_PAT_FLAG_REMOTE_EPHEM_REQ (1 << 11)
631 #define NOISE_PAT_FLAG_REMOTE_HYBRID (1 << 12)
634 #define NOISE_PAT_FLAG_REMOTE_HYBRID_REQ (1 << 13)
637 #define NOISE_REQ_LOCAL_REQUIRED (1 << 0)
639 #define NOISE_REQ_REMOTE_REQUIRED (1 << 1)
641 #define NOISE_REQ_PSK (1 << 2)
643 #define NOISE_REQ_FALLBACK_PREMSG (1 << 3)
645 #define NOISE_REQ_LOCAL_PREMSG (1 << 4)
647 #define NOISE_REQ_REMOTE_PREMSG (1 << 5)
649 #define NOISE_REQ_FALLBACK_POSSIBLE (1 << 6)
669 typedef uint16_t NoisePatternFlags_t;
#define NOISE_PSK_LEN
Standard length for pre-shared keys.
Noise protocol name broken out into separate identifier fields.
int(* decrypt)(NoiseCipherState *state, const uint8_t *ad, size_t ad_len, uint8_t *data, size_t len)
Decrypts data with this CipherState.
void(* reset)(NoiseHashState *state)
Resets the HashState for a new hashing session.
uint8_t mac_len
Length of the MAC for this cipher in bytes.
int(* encrypt)(NoiseCipherState *state, const uint8_t *ad, size_t ad_len, uint8_t *data, size_t len)
Encrypts data with this CipherState.
int(* validate_keypair)(const NoiseSignState *state, const uint8_t *private_key, const uint8_t *public_key)
Validates a keypair.
uint16_t hash_len
Length of the output from this hash algorithm.
uint16_t block_len
Length of the underlying block for this hash algorithm.
Internal structure of the NoiseSignState type.
uint8_t ck[NOISE_MAX_HASHLEN]
Current value of the chaining key for the handshake.
NoiseHashState * hash
Points to the HashState object for this SymmetricState.
uint8_t * public_key
Points to the public key in the subclass state.
uint8_t * public_key
Points to the public key in the subclass state.
Internal structure of the NoiseHashState type.
NoiseDHState * dh_fixed_ephemeral
Points to the object for the fixed ephemeral test key.
NoiseCipherState * noise_aesgcm_new(void)
Creates a new AES-GCM CipherState object.
NoiseProtocolId id
Algorithm identifiers for the components of the protocol.
size_t size
Total size of the structure.
const uint8_t * tokens
Points to the next message pattern tokens to be processed.
int(* validate_public_key)(const NoiseSignState *state, const uint8_t *public_key)
Validates a public key.
uint8_t has_key
Non-zero if the key has been set on this cipher.
size_t prologue_len
Length of the prologue value in bytes.
size_t size
Total size of the structure, including DH key storage.
NoiseDHState * dh_remote_ephemeral
Points to the DHState object for remote ephemeral key.
NoiseDHState * dh_local_ephemeral
Points to the DHState object for local ephemeral key.
int(* verify)(const NoiseSignState *state, const uint8_t *message, size_t message_len, const uint8_t *signature)
Verifies a digital signature on a message.
Main header file to include the Noise protocol library definitions.
uint8_t h[NOISE_MAX_HASHLEN]
Current value of the handshake hash.
#define NOISE_MAX_HASHLEN
Maximum hash length over all supported hash algorithms.
void(* destroy)(NoiseHashState *state)
Destroys this HashState prior to the memory being freed.
NoiseSymmetricState * symmetric
Points to the SymmetricState object for this HandshakeState.
uint16_t shared_key_len
Length of the shared key for this algorithm in bytes.
uint8_t pre_shared_key[NOISE_PSK_LEN]
Pre-shared key value.
Internal structure of the NoiseDHState type.
NoiseDHState * dh_remote_hybrid
Points to the DHState object for remote hybrid forward secrecy key.
void(* finalize)(NoiseHashState *state, uint8_t *hash)
Finalizes the HashState and returns the hash value.
uint8_t key_len
Length of the key for this cipher in bytes.
int action
Next action to be taken by the application.
uint64_t n
The nonce value for the next packet.
int(* sign)(const NoiseSignState *state, const uint8_t *message, size_t message_len, uint8_t *signature)
Creates a signature.
size_t size
Total size of the structure including subclass state.
uint8_t key_type
The type of key stored within this DHState object.
int cipher_id
Algorithm identifier for the cipher.
NoiseCipherState * cipher
Points to the CipherState object for this SymmetricState.
uint16_t key_type
The type of key stored within this SignState object.
void(* update)(NoiseHashState *state, const uint8_t *data, size_t len)
Updates the HashState with more input data.
int role
The role of this object, initiator or responder.
void(* destroy)(NoiseSignState *state)
Destroys this SignState prior to the memory being freed.
Internal structure of the NoiseSymmetricState type.
int requirements
Requirements that are yet to be satisfied.
uint8_t * prologue
Points to the prologue value.
size_t size
Total size of the structure including subclass state.
size_t pre_shared_key_len
Length of the pre-shared key value: zero or NOISE_PSK_LEN only.
Internal structure of the NoiseCipherState type.
void(* destroy)(NoiseCipherState *state)
Destroys this CipherState prior to the memory being freed.
uint16_t private_key_len
Length of the private key for this algorithm in bytes.
NoisePatternFlags_t noise_pattern_reverse_flags(NoisePatternFlags_t flags)
Reverses the local and remote flags for a pattern.
uint8_t * private_key
Points to the private key in the subclass state.
const uint8_t * noise_pattern_lookup(int id)
Looks up a specific handshake pattern.
uint16_t public_key_len
Length of the public key for this algorithm in bytes.
void(* init_key)(NoiseCipherState *state, const uint8_t *key)
Sets the key for this CipherState.
uint16_t private_key_len
Length of the private key for this algorithm in bytes.
int(* derive_public_key)(const NoiseSignState *state, const uint8_t *private_key, uint8_t *public_key)
Derives a public key from a private key.
int hash_id
Algorithm identifier for the hash.
uint16_t signature_len
Length of the signature for this algorithm in bytes.
NoiseDHState * dh_local_hybrid
Points to the DHState object for local hybrid forward secrecy key.
short dh_id
Algorithm identifier for the Diffie-Hellman operation.
int sign_id
Algorithm identifier for the digital signature operation.
size_t size
Total size of the structure including subclass state.
Internal structure of the NoiseHandshakeState type.
void(* generate_keypair)(NoiseSignState *state)
Generates a new key pair for this digital signature algorithm.
NoiseDHState * dh_remote_static
Points to the DHState object for remote static key.
uint8_t * private_key
Points to the private key in the subclass state.
short role
The role; either initiator or responder or zero.
void noise_rand_bytes(void *bytes, size_t size)
Gets cryptographically-strong random bytes from the operating system.
NoiseDHState * dh_local_static
Points to the DHState object for local static key.
size_t size
Total size of the structure including subclass state.
NoiseDHState * dh_fixed_hybrid
Points to the object for the fixed hybrid forward secrecy test key.
uint16_t public_key_len
Length of the public key for this algorithm in bytes.