Macros | Functions
sha256.c File Reference
#include <stddef.h>
#include <stdio.h>
#include "nvim/sha256.h"
#include "nvim/vim.h"

Macros

#define GET_UINT32(n, b, i)
 
#define PUT_UINT32(n, b, i)
 
#define SHR(x, n)   ((x & 0xFFFFFFFF) >> n)
 
#define ROTR(x, n)   (SHR(x, n) | (x << (32 - n)))
 
#define S0(x)   (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3))
 
#define S1(x)   (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10))
 
#define S2(x)   (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
 
#define S3(x)   (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
 
#define F0(x, y, z)   ((x & y) | (z & (x | y)))
 
#define F1(x, y, z)   (z ^ (x & (y ^ z)))
 
#define R(t)
 
#define P(a, b, c, d, e, f, g, h, x, K)
 
#define SHA_STEP   2
 

Functions

void sha256_start (context_sha256_T *ctx)
 
void sha256_update (context_sha256_T *ctx, const char_u *input, size_t length)
 
void sha256_finish (context_sha256_T *ctx, char_u digest[SHA256_SUM_SIZE])
 
const char * sha256_bytes (const uint8_t *restrict buf, size_t buf_len, const uint8_t *restrict salt, size_t salt_len)
 
bool sha256_self_test (void)
 

Detailed Description

FIPS-180-2 compliant SHA-256 implementation GPL by Christophe Devine, applies to older version. Modified for md5deep, in public domain. Modified For Vim, Mohsin Ahmed, http://www.cs.albany.edu/~mosh Mohsin Ahmed states this work is distributed under the VIM License or GPL, at your choice.

Vim specific notes: sha256_self_test() is implicitly called once.

Macro Definition Documentation

#define F0 (   x,
  y,
 
)    ((x & y) | (z & (x | y)))
#define F1 (   x,
  y,
 
)    (z ^ (x & (y ^ z)))
#define GET_UINT32 (   n,
  b,
  i 
)
Value:
{ \
(n) = ((uint32_t)(b)[(i)] << 24) \
| ((uint32_t)(b)[(i) + 1] << 16) \
| ((uint32_t)(b)[(i) + 2] << 8) \
| ((uint32_t)(b)[(i) + 3]); \
}
static char size_t n
Definition: memline.c:3251
int i
Definition: typval.c:868
#define P (   a,
  b,
  c,
  d,
  e,
  f,
  g,
  h,
  x,
 
)
Value:
{ \
temp1 = h + S3(e) + F1(e, f, g) + K + x; \
temp2 = S2(a) + F0(a, b, c); \
d += temp1; h = temp1 + temp2; \
}
#define S3(x)
dict_T * d
Definition: eval.c:14699
#define F0(x, y, z)
#define S2(x)
#define F1(x, y, z)
#define PUT_UINT32 (   n,
  b,
  i 
)
Value:
{ \
(b)[(i)] = (char_u)((n) >> 24); \
(b)[(i) + 1] = (char_u)((n) >> 16); \
(b)[(i) + 2] = (char_u)((n) >> 8); \
(b)[(i) + 3] = (char_u)((n)); \
}
static char size_t n
Definition: memline.c:3251
unsigned char char_u
Definition: types.h:11
int i
Definition: typval.c:868
#define R (   t)
Value:
(W[t] = S1(W[t - 2]) + W[t - 7] + \
S0(W[t - 15]) + W[t - 16])
#define S0(x)
#define S1(x)
#define ROTR (   x,
  n 
)    (SHR(x, n) | (x << (32 - n)))
#define S0 (   x)    (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3))
#define S1 (   x)    (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10))
#define S2 (   x)    (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
#define S3 (   x)    (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
#define SHA_STEP   2
#define SHR (   x,
  n 
)    ((x & 0xFFFFFFFF) >> n)

Function Documentation

const char* sha256_bytes ( const uint8_t *restrict  buf,
size_t  buf_len,
const uint8_t *restrict  salt,
size_t  salt_len 
)

Gets the hex digest of the buffer.

Parameters
buf
buf_len
salt
salt_len
Returns
hex digest of "buf[buf_len]" in a static array. if "salt" is not NULL also do "salt[salt_len]".
void sha256_finish ( context_sha256_T ctx,
char_u  digest[SHA256_SUM_SIZE] 
)
bool sha256_self_test ( void  )

Perform a test on the SHA256 algorithm.

Returns
true if not failures generated.
void sha256_start ( context_sha256_T ctx)
void sha256_update ( context_sha256_T ctx,
const char_u input,
size_t  length 
)