Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_digest.c File Reference

Message digests, HMAC, PBKDF2, and AES-256-GCM AEAD over the OpenSSL EVP API. More...

#include "nilorea/n_digest.h"
#include "nilorea/n_common.h"
#include "nilorea/n_hex.h"
#include "nilorea/n_log.h"
#include "nilorea/n_str.h"
#include <openssl/crypto.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <limits.h>
#include <string.h>
+ Include dependency graph for n_digest.c:

Go to the source code of this file.

Functions

int n_aead_aes256gcm_decrypt (const unsigned char *key, const unsigned char *iv, size_t iv_len, const unsigned char *aad, size_t aad_len, const unsigned char *ct, size_t ct_len, const unsigned char *tag, unsigned char *out_pt)
 AES-256-GCM authenticated decryption.
 
int n_aead_aes256gcm_encrypt (const unsigned char *key, const unsigned char *iv, size_t iv_len, const unsigned char *aad, size_t aad_len, const unsigned char *pt, size_t pt_len, unsigned char *out_ct, unsigned char *out_tag)
 AES-256-GCM authenticated encryption.
 
int n_digest_consttime_equal (const unsigned char *a, const unsigned char *b, size_t len)
 constant-time comparison of two equal-length byte buffers (for verifying MACs/signatures without a timing side channel).
 
int n_digest_md5 (const unsigned char *data, size_t len, unsigned char *out)
 compute the MD5 digest of len bytes of data into out (N_DIGEST_MD5_LEN bytes).
 
static int n_digest_oneshot (const EVP_MD *md, const unsigned char *data, size_t len, unsigned char *out, const char *name)
 
int n_digest_sha1 (const unsigned char *data, size_t len, unsigned char *out)
 compute the SHA-1 digest of len bytes of data into out (N_DIGEST_SHA1_LEN bytes).
 
int n_digest_sha256 (const unsigned char *data, size_t len, unsigned char *out)
 compute the SHA-256 digest of len bytes of data into out (N_DIGEST_SHA256_LEN bytes).
 
N_STRn_digest_sha256_hex (const unsigned char *data, size_t len)
 compute the SHA-256 digest of data and return it as a lowercase hex N_STR; free with free_nstr.
 
int n_digest_sha384 (const unsigned char *data, size_t len, unsigned char *out)
 compute the SHA-384 digest of len bytes of data into out (N_DIGEST_SHA384_LEN bytes).
 
int n_digest_sha512 (const unsigned char *data, size_t len, unsigned char *out)
 compute the SHA-512 digest of len bytes of data into out (N_DIGEST_SHA512_LEN bytes).
 
static int n_hmac_oneshot (const EVP_MD *md, unsigned int expect_len, const unsigned char *key, size_t key_len, const unsigned char *data, size_t data_len, unsigned char *out, const char *name)
 
int n_hmac_sha1 (const unsigned char *key, size_t key_len, const unsigned char *data, size_t data_len, unsigned char *out)
 compute HMAC-SHA1 of data under key into out (N_DIGEST_SHA1_LEN bytes).
 
int n_hmac_sha256 (const unsigned char *key, size_t key_len, const unsigned char *data, size_t data_len, unsigned char *out)
 compute HMAC-SHA256 of data under key into out (N_DIGEST_SHA256_LEN bytes).
 
int n_hmac_sha384 (const unsigned char *key, size_t key_len, const unsigned char *data, size_t data_len, unsigned char *out)
 compute HMAC-SHA384 of data under key into out (N_DIGEST_SHA384_LEN bytes).
 
int n_hmac_sha512 (const unsigned char *key, size_t key_len, const unsigned char *data, size_t data_len, unsigned char *out)
 compute HMAC-SHA512 of data under key into out (N_DIGEST_SHA512_LEN bytes).
 
int n_pbkdf2_hmac_sha1 (const unsigned char *pass, size_t pass_len, const unsigned char *salt, size_t salt_len, unsigned int iterations, unsigned char *out, size_t out_len)
 derive out_len key bytes from pass and salt with PBKDF2-HMAC-SHA1 over iterations rounds (RFC 2898).
 
int n_pbkdf2_hmac_sha256 (const unsigned char *pass, size_t pass_len, const unsigned char *salt, size_t salt_len, unsigned int iterations, unsigned char *out, size_t out_len)
 derive out_len key bytes from pass and salt with PBKDF2-HMAC-SHA256 over iterations rounds (RFC 2898).
 
static int n_pbkdf2_oneshot (const EVP_MD *md, const unsigned char *pass, size_t pass_len, const unsigned char *salt, size_t salt_len, unsigned int iterations, unsigned char *out, size_t out_len, const char *name)
 

Detailed Description

Message digests, HMAC, PBKDF2, and AES-256-GCM AEAD over the OpenSSL EVP API.

Author
Castagnier Mickael
Version
1.0

Definition in file n_digest.c.

Function Documentation

◆ n_digest_oneshot()

static int n_digest_oneshot ( const EVP_MD *  md,
const unsigned char *  data,
size_t  len,
unsigned char *  out,
const char *  name 
)
static

Definition at line 45 of file n_digest.c.

References LOG_ERR, and n_log.

Referenced by n_digest_md5(), n_digest_sha1(), n_digest_sha256(), n_digest_sha384(), and n_digest_sha512().

+ Here is the caller graph for this function:

◆ n_hmac_oneshot()

static int n_hmac_oneshot ( const EVP_MD *  md,
unsigned int  expect_len,
const unsigned char *  key,
size_t  key_len,
const unsigned char *  data,
size_t  data_len,
unsigned char *  out,
const char *  name 
)
static

Definition at line 88 of file n_digest.c.

References key, LOG_ERR, and n_log.

Referenced by n_hmac_sha1(), n_hmac_sha256(), n_hmac_sha384(), and n_hmac_sha512().

+ Here is the caller graph for this function:

◆ n_pbkdf2_oneshot()

static int n_pbkdf2_oneshot ( const EVP_MD *  md,
const unsigned char *  pass,
size_t  pass_len,
const unsigned char *  salt,
size_t  salt_len,
unsigned int  iterations,
unsigned char *  out,
size_t  out_len,
const char *  name 
)
static

Definition at line 131 of file n_digest.c.

References LOG_ERR, and n_log.

Referenced by n_pbkdf2_hmac_sha1(), and n_pbkdf2_hmac_sha256().

+ Here is the caller graph for this function: