PostgreSQL Source Code  git master
internal-sha2.c File Reference
#include "postgres.h"
#include <time.h>
#include "common/cryptohash.h"
#include "common/sha2.h"
#include "px.h"
Include dependency graph for internal-sha2.c:

Go to the source code of this file.

Functions

void init_sha224 (PX_MD *h)
 
void init_sha256 (PX_MD *h)
 
void init_sha384 (PX_MD *h)
 
void init_sha512 (PX_MD *h)
 
static unsigned int_sha224_len (PX_MD *h)
 
static unsigned int_sha224_block_len (PX_MD *h)
 
static unsigned int_sha256_len (PX_MD *h)
 
static unsigned int_sha256_block_len (PX_MD *h)
 
static unsigned int_sha384_len (PX_MD *h)
 
static unsigned int_sha384_block_len (PX_MD *h)
 
static unsigned int_sha512_len (PX_MD *h)
 
static unsigned int_sha512_block_len (PX_MD *h)
 
static void int_sha2_update (PX_MD *h, const uint8 *data, unsigned dlen)
 
static void int_sha2_reset (PX_MD *h)
 
static void int_sha2_finish (PX_MD *h, uint8 *dst)
 
static void int_sha2_free (PX_MD *h)
 

Function Documentation

◆ init_sha224()

void init_sha224 ( PX_MD h)

Definition at line 137 of file internal-sha2.c.

References px_digest::block_size, px_digest::finish, px_digest::free, int_sha224_block_len(), int_sha224_len(), int_sha2_finish(), int_sha2_free(), int_sha2_reset(), int_sha2_update(), px_digest::p, pg_cryptohash_create(), PG_SHA224, px_digest::ptr, px_digest::reset, px_digest::result_size, and px_digest::update.

138 {
139  pg_cryptohash_ctx *ctx;
140 
142  md->p.ptr = ctx;
143 
144  md->result_size = int_sha224_len;
145  md->block_size = int_sha224_block_len;
146  md->reset = int_sha2_reset;
147  md->update = int_sha2_update;
148  md->finish = int_sha2_finish;
149  md->free = int_sha2_free;
150 
151  md->reset(md);
152 }
static void int_sha2_reset(PX_MD *h)
static unsigned int_sha224_block_len(PX_MD *h)
Definition: internal-sha2.c:53
static void int_sha2_free(PX_MD *h)
static void int_sha2_update(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: internal-sha2.c:99
static void int_sha2_finish(PX_MD *h, uint8 *dst)
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
Definition: cryptohash.c:66
static unsigned int_sha224_len(PX_MD *h)
Definition: internal-sha2.c:47

◆ init_sha256()

void init_sha256 ( PX_MD h)

Definition at line 155 of file internal-sha2.c.

References px_digest::block_size, px_digest::finish, px_digest::free, int_sha256_block_len(), int_sha256_len(), int_sha2_finish(), int_sha2_free(), int_sha2_reset(), int_sha2_update(), px_digest::p, pg_cryptohash_create(), PG_SHA256, px_digest::ptr, px_digest::reset, px_digest::result_size, and px_digest::update.

156 {
157  pg_cryptohash_ctx *ctx;
158 
160  md->p.ptr = ctx;
161 
162  md->result_size = int_sha256_len;
163  md->block_size = int_sha256_block_len;
164  md->reset = int_sha2_reset;
165  md->update = int_sha2_update;
166  md->finish = int_sha2_finish;
167  md->free = int_sha2_free;
168 
169  md->reset(md);
170 }
static void int_sha2_reset(PX_MD *h)
static unsigned int_sha256_len(PX_MD *h)
Definition: internal-sha2.c:60
static void int_sha2_free(PX_MD *h)
static void int_sha2_update(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: internal-sha2.c:99
static void int_sha2_finish(PX_MD *h, uint8 *dst)
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
Definition: cryptohash.c:66
static unsigned int_sha256_block_len(PX_MD *h)
Definition: internal-sha2.c:66

◆ init_sha384()

void init_sha384 ( PX_MD h)

Definition at line 173 of file internal-sha2.c.

References px_digest::block_size, px_digest::finish, px_digest::free, int_sha2_finish(), int_sha2_free(), int_sha2_reset(), int_sha2_update(), int_sha384_block_len(), int_sha384_len(), px_digest::p, pg_cryptohash_create(), PG_SHA384, px_digest::ptr, px_digest::reset, px_digest::result_size, and px_digest::update.

174 {
175  pg_cryptohash_ctx *ctx;
176 
178  md->p.ptr = ctx;
179 
180  md->result_size = int_sha384_len;
181  md->block_size = int_sha384_block_len;
182  md->reset = int_sha2_reset;
183  md->update = int_sha2_update;
184  md->finish = int_sha2_finish;
185  md->free = int_sha2_free;
186 
187  md->reset(md);
188 }
static void int_sha2_reset(PX_MD *h)
static unsigned int_sha384_block_len(PX_MD *h)
Definition: internal-sha2.c:79
static void int_sha2_free(PX_MD *h)
static void int_sha2_update(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: internal-sha2.c:99
static void int_sha2_finish(PX_MD *h, uint8 *dst)
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
Definition: cryptohash.c:66
static unsigned int_sha384_len(PX_MD *h)
Definition: internal-sha2.c:73

◆ init_sha512()

void init_sha512 ( PX_MD h)

Definition at line 191 of file internal-sha2.c.

References px_digest::block_size, px_digest::finish, px_digest::free, int_sha2_finish(), int_sha2_free(), int_sha2_reset(), int_sha2_update(), int_sha512_block_len(), int_sha512_len(), px_digest::p, pg_cryptohash_create(), PG_SHA512, px_digest::ptr, px_digest::reset, px_digest::result_size, and px_digest::update.

192 {
193  pg_cryptohash_ctx *ctx;
194 
196  md->p.ptr = ctx;
197 
198  md->result_size = int_sha512_len;
199  md->block_size = int_sha512_block_len;
200  md->reset = int_sha2_reset;
201  md->update = int_sha2_update;
202  md->finish = int_sha2_finish;
203  md->free = int_sha2_free;
204 
205  md->reset(md);
206 }
static void int_sha2_reset(PX_MD *h)
static unsigned int_sha512_len(PX_MD *h)
Definition: internal-sha2.c:86
static void int_sha2_free(PX_MD *h)
static void int_sha2_update(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: internal-sha2.c:99
static unsigned int_sha512_block_len(PX_MD *h)
Definition: internal-sha2.c:92
static void int_sha2_finish(PX_MD *h, uint8 *dst)
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
Definition: cryptohash.c:66

◆ int_sha224_block_len()

static unsigned int_sha224_block_len ( PX_MD h)
static

Definition at line 53 of file internal-sha2.c.

References PG_SHA224_BLOCK_LENGTH.

Referenced by init_sha224().

54 {
56 }
#define PG_SHA224_BLOCK_LENGTH
Definition: sha2.h:19

◆ int_sha224_len()

static unsigned int_sha224_len ( PX_MD h)
static

Definition at line 47 of file internal-sha2.c.

References PG_SHA224_DIGEST_LENGTH.

Referenced by init_sha224().

48 {
50 }
#define PG_SHA224_DIGEST_LENGTH
Definition: sha2.h:20

◆ int_sha256_block_len()

static unsigned int_sha256_block_len ( PX_MD h)
static

Definition at line 66 of file internal-sha2.c.

References PG_SHA256_BLOCK_LENGTH.

Referenced by init_sha256().

67 {
69 }
#define PG_SHA256_BLOCK_LENGTH
Definition: sha2.h:21

◆ int_sha256_len()

static unsigned int_sha256_len ( PX_MD h)
static

Definition at line 60 of file internal-sha2.c.

References PG_SHA256_DIGEST_LENGTH.

Referenced by init_sha256().

61 {
63 }
#define PG_SHA256_DIGEST_LENGTH
Definition: sha2.h:22

◆ int_sha2_finish()

static void int_sha2_finish ( PX_MD h,
uint8 dst 
)
static

Definition at line 117 of file internal-sha2.c.

References elog, ERROR, px_digest::p, pg_cryptohash_final(), px_digest::ptr, and px_digest::result_size.

Referenced by init_sha224(), init_sha256(), init_sha384(), and init_sha512().

118 {
120 
121  if (pg_cryptohash_final(ctx, dst, h->result_size(h)) < 0)
122  elog(ERROR, "could not finalize %s context", "SHA2");
123 }
int pg_cryptohash_final(pg_cryptohash_ctx *ctx, uint8 *dest, size_t len)
Definition: cryptohash.c:168
void * ptr
Definition: px.h:110
#define ERROR
Definition: elog.h:46
union px_digest::@9 p
unsigned(* result_size)(PX_MD *h)
Definition: px.h:100
#define elog(elevel,...)
Definition: elog.h:232

◆ int_sha2_free()

static void int_sha2_free ( PX_MD h)
static

Definition at line 126 of file internal-sha2.c.

References px_digest::p, pfree(), pg_cryptohash_free(), and px_digest::ptr.

Referenced by init_sha224(), init_sha256(), init_sha384(), and init_sha512().

127 {
129 
130  pg_cryptohash_free(ctx);
131  pfree(h);
132 }
void * ptr
Definition: px.h:110
void pfree(void *pointer)
Definition: mcxt.c:1169
union px_digest::@9 p
void pg_cryptohash_free(pg_cryptohash_ctx *ctx)
Definition: cryptohash.c:216

◆ int_sha2_reset()

static void int_sha2_reset ( PX_MD h)
static

Definition at line 108 of file internal-sha2.c.

References elog, ERROR, px_digest::p, pg_cryptohash_init(), and px_digest::ptr.

Referenced by init_sha224(), init_sha256(), init_sha384(), and init_sha512().

109 {
111 
112  if (pg_cryptohash_init(ctx) < 0)
113  elog(ERROR, "could not initialize %s context", "SHA2");
114 }
void * ptr
Definition: px.h:110
#define ERROR
Definition: elog.h:46
union px_digest::@9 p
int pg_cryptohash_init(pg_cryptohash_ctx *ctx)
Definition: cryptohash.c:92
#define elog(elevel,...)
Definition: elog.h:232

◆ int_sha2_update()

static void int_sha2_update ( PX_MD h,
const uint8 data,
unsigned  dlen 
)
static

Definition at line 99 of file internal-sha2.c.

References elog, ERROR, px_digest::p, pg_cryptohash_update(), and px_digest::ptr.

Referenced by init_sha224(), init_sha256(), init_sha384(), and init_sha512().

100 {
102 
103  if (pg_cryptohash_update(ctx, data, dlen) < 0)
104  elog(ERROR, "could not update %s context", "SHA2");
105 }
void * ptr
Definition: px.h:110
#define ERROR
Definition: elog.h:46
union px_digest::@9 p
int pg_cryptohash_update(pg_cryptohash_ctx *ctx, const uint8 *data, size_t len)
Definition: cryptohash.c:130
#define elog(elevel,...)
Definition: elog.h:232

◆ int_sha384_block_len()

static unsigned int_sha384_block_len ( PX_MD h)
static

Definition at line 79 of file internal-sha2.c.

References PG_SHA384_BLOCK_LENGTH.

Referenced by init_sha384().

80 {
82 }
#define PG_SHA384_BLOCK_LENGTH
Definition: sha2.h:23

◆ int_sha384_len()

static unsigned int_sha384_len ( PX_MD h)
static

Definition at line 73 of file internal-sha2.c.

References PG_SHA384_DIGEST_LENGTH.

Referenced by init_sha384().

74 {
76 }
#define PG_SHA384_DIGEST_LENGTH
Definition: sha2.h:24

◆ int_sha512_block_len()

static unsigned int_sha512_block_len ( PX_MD h)
static

Definition at line 92 of file internal-sha2.c.

References PG_SHA512_BLOCK_LENGTH.

Referenced by init_sha512().

93 {
95 }
#define PG_SHA512_BLOCK_LENGTH
Definition: sha2.h:25

◆ int_sha512_len()

static unsigned int_sha512_len ( PX_MD h)
static

Definition at line 86 of file internal-sha2.c.

References PG_SHA512_DIGEST_LENGTH.

Referenced by init_sha512().

87 {
89 }
#define PG_SHA512_DIGEST_LENGTH
Definition: sha2.h:26