27 typedef crypto_hash_sha256_state sha256_context_t;
28 #define sha256_reset(ctx) crypto_hash_sha256_init(ctx)
29 #define sha256_update(ctx, pub, pub_len) crypto_hash_sha256_update(ctx, pub, pub_len)
30 #define sha256_finish(ctx, hash) crypto_hash_sha256_final(ctx, hash)
32 #include "crypto/sha2/sha256.h"
35 #include <openssl/err.h>
36 #include <openssl/evp.h>
41 static pthread_once_t noise_is_initialized = PTHREAD_ONCE_INIT;
57 if (sodium_init() < 0)
61 OpenSSL_add_all_algorithms();
62 ERR_load_crypto_strings();
137 void *ptr = calloc(1, size);
138 if (!ptr || size <
sizeof(
size_t))
140 *((
size_t *)ptr) =
size;
172 volatile uint8_t *d = (
volatile uint8_t *)data;
190 const uint8_t *str1 = (
const unsigned char *)s1;
191 const uint8_t *str2 = (
const unsigned char *)s2;
194 temp |= *str1 ^ *str2;
199 return (0x0100 - (
int)temp) >> 8;
213 const uint8_t *d = (
const uint8_t *)data;
219 return (0x0100 - (
int)temp) >> 8;
246 (
int fingerprint_type,
char *buffer,
size_t len,
247 const uint8_t *public_key,
size_t public_key_len)
249 static char const hexchars[] =
"0123456789abcdef";
250 sha256_context_t sha256;
273 if ((f_len * 3) > len)
277 sha256_reset(&sha256);
278 sha256_update(&sha256, public_key, public_key_len);
279 sha256_finish(&sha256, hash);
283 for (posn = 0; posn < f_len; ++posn) {
284 uint8_t byte = hash[posn];
285 buffer[posn * 3] = hexchars[(byte >> 4) & 0x0F];
286 buffer[posn * 3 + 1] = hexchars[byte & 0x0F];
287 buffer[posn * 3 + 2] =
':';
289 buffer[f_len * 3 - 1] =
'\0';
void noise_clean(void *data, size_t size)
Cleans a block of memory to destroy its contents.
NoiseHashState * hash
Points to the HashState object for this SymmetricState.
#define NOISE_ERROR_INVALID_PARAM
Invalid parameter to function; e.g. a NULL value.
#define NOISE_FINGERPRINT_FULL
Fingerprint format is the hexadecimal encoding of the entire 32 bytes of the SHA256 hash of the publi...
#define NOISE_ERROR_NONE
Success, no error.
size_t size
Total size of the structure.
int noise_is_zero(const void *data, size_t size)
Determine if a block of memory consists of all zero bytes.
#define NOISE_FINGERPRINT_BASIC
Fingerprint format is the hexadecimal encoding of the first 16 bytes of the SHA256 hash of the public...
int noise_format_fingerprint(int fingerprint_type, char *buffer, size_t len, const uint8_t *public_key, size_t public_key_len)
Formats the fingerprint for a raw public key value.
void * noise_new_object(size_t size)
Allocates memory from the system for an object.
#define NOISE_ERROR_INVALID_LENGTH
Invalid length specified for a key, packet, etc.
int noise_init(void)
Initializes the Noise-c library.
Internal definitions for the library.
void noise_free(void *ptr, size_t size)
Destroys the contents of a block of memory and free it.
#define NOISE_ERROR_SYSTEM
System error, with more information in errno.
void noise_init_helper(void)
int noise_is_equal(const void *s1, const void *s2, size_t size)
Determine if two blocks of memory are equal in constant time.