PostgreSQL Source Code  git master
cryptohash.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct pg_cryptohash_ctx pg_cryptohash_ctx
 

Enumerations

enum  pg_cryptohash_type {
  PG_MD5 = 0 , PG_SHA1 , PG_SHA224 , PG_SHA256 ,
  PG_SHA384 , PG_SHA512
}
 

Functions

pg_cryptohash_ctxpg_cryptohash_create (pg_cryptohash_type type)
 
int pg_cryptohash_init (pg_cryptohash_ctx *ctx)
 
int pg_cryptohash_update (pg_cryptohash_ctx *ctx, const uint8 *data, size_t len)
 
int pg_cryptohash_final (pg_cryptohash_ctx *ctx, uint8 *dest, size_t len)
 
void pg_cryptohash_free (pg_cryptohash_ctx *ctx)
 

Typedef Documentation

◆ pg_cryptohash_ctx

Definition at line 1 of file cryptohash.h.

Enumeration Type Documentation

◆ pg_cryptohash_type

Enumerator
PG_MD5 
PG_SHA1 
PG_SHA224 
PG_SHA256 
PG_SHA384 
PG_SHA512 

Definition at line 19 of file cryptohash.h.

20 {
21  PG_MD5 = 0,
22  PG_SHA1,
23  PG_SHA224,
24  PG_SHA256,
25  PG_SHA384,
26  PG_SHA512
pg_cryptohash_type
Definition: cryptohash.h:20
@ PG_SHA512
Definition: cryptohash.h:26
@ PG_SHA224
Definition: cryptohash.h:23
@ PG_SHA384
Definition: cryptohash.h:25
@ PG_SHA1
Definition: cryptohash.h:22
@ PG_SHA256
Definition: cryptohash.h:24
@ PG_MD5
Definition: cryptohash.h:21

Function Documentation

◆ pg_cryptohash_create()

pg_cryptohash_ctx* pg_cryptohash_create ( pg_cryptohash_type  type)

Definition at line 66 of file cryptohash.c.

67 {
68  pg_cryptohash_ctx *ctx;
69 
70  /*
71  * Note that this always allocates enough space for the largest hash. A
72  * smaller allocation would be enough for md5, sha224 and sha256, but the
73  * small extra amount of memory does not make it worth complicating this
74  * code.
75  */
76  ctx = ALLOC(sizeof(pg_cryptohash_ctx));
77  if (ctx == NULL)
78  return NULL;
79  memset(ctx, 0, sizeof(pg_cryptohash_ctx));
80  ctx->type = type;
81 
82  return ctx;
83 }
#define ALLOC(size)
Definition: cryptohash.c:36
pg_cryptohash_type type
Definition: cryptohash.c:46

References ALLOC, CurrentResourceOwner, ereport, errcode(), errmsg(), ERROR, pg_cryptohash_ctx::evpctx, explicit_bzero(), FREE, PointerGetDatum, ResourceOwnerEnlargeCryptoHash(), ResourceOwnerRememberCryptoHash(), pg_cryptohash_ctx::resowner, generate_unaccent_rules::type, and pg_cryptohash_ctx::type.

Referenced by cryptohash_internal(), InitializeBackupManifest(), pg_checksum_init(), pg_hmac_create(), pg_hmac_init(), pg_md5_binary(), pg_md5_hash(), scram_H(), scram_mock_salt(), uuid_generate_internal(), and verify_manifest_checksum().

◆ pg_cryptohash_final()

int pg_cryptohash_final ( pg_cryptohash_ctx ctx,
uint8 dest,
size_t  len 
)

Definition at line 168 of file cryptohash.c.

169 {
170  if (ctx == NULL)
171  return -1;
172 
173  switch (ctx->type)
174  {
175  case PG_MD5:
176  if (len < MD5_DIGEST_LENGTH)
177  return -1;
178  pg_md5_final(&ctx->data.md5, dest);
179  break;
180  case PG_SHA1:
181  if (len < SHA1_DIGEST_LENGTH)
182  return -1;
183  pg_sha1_final(&ctx->data.sha1, dest);
184  break;
185  case PG_SHA224:
187  return -1;
189  break;
190  case PG_SHA256:
192  return -1;
194  break;
195  case PG_SHA384:
197  return -1;
199  break;
200  case PG_SHA512:
202  return -1;
204  break;
205  }
206 
207  return 0;
208 }
void pg_md5_final(pg_md5_ctx *ctx, uint8 *dest)
Definition: md5.c:435
#define MD5_DIGEST_LENGTH
Definition: md5.h:20
const void size_t len
void pg_sha1_final(pg_sha1_ctx *ctx, uint8 *dest)
Definition: sha1.c:365
#define SHA1_DIGEST_LENGTH
Definition: sha1.h:17
void pg_sha512_final(pg_sha512_ctx *context, uint8 *digest)
Definition: sha2.c:905
void pg_sha256_final(pg_sha256_ctx *context, uint8 *digest)
Definition: sha2.c:577
void pg_sha224_final(pg_sha224_ctx *context, uint8 *digest)
Definition: sha2.c:994
void pg_sha384_final(pg_sha384_ctx *context, uint8 *digest)
Definition: sha2.c:950
#define PG_SHA256_DIGEST_LENGTH
Definition: sha2.h:23
#define PG_SHA384_DIGEST_LENGTH
Definition: sha2.h:26
#define PG_SHA512_DIGEST_LENGTH
Definition: sha2.h:29
#define PG_SHA224_DIGEST_LENGTH
Definition: sha2.h:20
pg_md5_ctx md5
Definition: cryptohash.c:50
pg_sha384_ctx sha384
Definition: cryptohash.c:54
pg_sha1_ctx sha1
Definition: cryptohash.c:51
pg_sha256_ctx sha256
Definition: cryptohash.c:53
pg_sha512_ctx sha512
Definition: cryptohash.c:55
union pg_cryptohash_ctx::@34 data
pg_sha224_ctx sha224
Definition: cryptohash.c:52

References pg_cryptohash_ctx::data, generate_unaccent_rules::dest, pg_cryptohash_ctx::evpctx, len, pg_cryptohash_ctx::md5, MD5_DIGEST_LENGTH, PG_MD5, pg_md5_final(), PG_SHA1, pg_sha1_final(), PG_SHA224, PG_SHA224_DIGEST_LENGTH, pg_sha224_final(), PG_SHA256, PG_SHA256_DIGEST_LENGTH, pg_sha256_final(), PG_SHA384, PG_SHA384_DIGEST_LENGTH, pg_sha384_final(), PG_SHA512, PG_SHA512_DIGEST_LENGTH, pg_sha512_final(), pg_cryptohash_ctx::sha1, SHA1_DIGEST_LENGTH, pg_cryptohash_ctx::sha224, pg_cryptohash_ctx::sha256, pg_cryptohash_ctx::sha384, pg_cryptohash_ctx::sha512, status(), and pg_cryptohash_ctx::type.

Referenced by cryptohash_internal(), pg_checksum_final(), pg_hmac_final(), pg_hmac_init(), pg_md5_binary(), pg_md5_hash(), scram_H(), scram_mock_salt(), SendBackupManifest(), uuid_generate_internal(), and verify_manifest_checksum().

◆ pg_cryptohash_free()

◆ pg_cryptohash_init()

int pg_cryptohash_init ( pg_cryptohash_ctx ctx)

Definition at line 92 of file cryptohash.c.

93 {
94  if (ctx == NULL)
95  return -1;
96 
97  switch (ctx->type)
98  {
99  case PG_MD5:
100  pg_md5_init(&ctx->data.md5);
101  break;
102  case PG_SHA1:
103  pg_sha1_init(&ctx->data.sha1);
104  break;
105  case PG_SHA224:
106  pg_sha224_init(&ctx->data.sha224);
107  break;
108  case PG_SHA256:
109  pg_sha256_init(&ctx->data.sha256);
110  break;
111  case PG_SHA384:
112  pg_sha384_init(&ctx->data.sha384);
113  break;
114  case PG_SHA512:
115  pg_sha512_init(&ctx->data.sha512);
116  break;
117  }
118 
119  return 0;
120 }
void pg_md5_init(pg_md5_ctx *ctx)
Definition: md5.c:385
void pg_sha1_init(pg_sha1_ctx *ctx)
Definition: sha1.c:316
void pg_sha384_init(pg_sha384_ctx *context)
Definition: sha2.c:934
void pg_sha256_init(pg_sha256_ctx *context)
Definition: sha2.c:279
void pg_sha512_init(pg_sha512_ctx *context)
Definition: sha2.c:605
void pg_sha224_init(pg_sha224_ctx *context)
Definition: sha2.c:978

References pg_cryptohash_ctx::data, pg_cryptohash_ctx::evpctx, pg_cryptohash_ctx::md5, PG_MD5, pg_md5_init(), PG_SHA1, pg_sha1_init(), PG_SHA224, pg_sha224_init(), PG_SHA256, pg_sha256_init(), PG_SHA384, pg_sha384_init(), PG_SHA512, pg_sha512_init(), pg_cryptohash_ctx::sha1, pg_cryptohash_ctx::sha224, pg_cryptohash_ctx::sha256, pg_cryptohash_ctx::sha384, pg_cryptohash_ctx::sha512, status(), and pg_cryptohash_ctx::type.

Referenced by cryptohash_internal(), InitializeBackupManifest(), pg_checksum_init(), pg_hmac_final(), pg_hmac_init(), pg_md5_binary(), pg_md5_hash(), scram_H(), scram_mock_salt(), uuid_generate_internal(), and verify_manifest_checksum().

◆ pg_cryptohash_update()

int pg_cryptohash_update ( pg_cryptohash_ctx ctx,
const uint8 data,
size_t  len 
)

Definition at line 130 of file cryptohash.c.

131 {
132  if (ctx == NULL)
133  return -1;
134 
135  switch (ctx->type)
136  {
137  case PG_MD5:
138  pg_md5_update(&ctx->data.md5, data, len);
139  break;
140  case PG_SHA1:
141  pg_sha1_update(&ctx->data.sha1, data, len);
142  break;
143  case PG_SHA224:
145  break;
146  case PG_SHA256:
148  break;
149  case PG_SHA384:
151  break;
152  case PG_SHA512:
154  break;
155  }
156 
157  return 0;
158 }
void pg_md5_update(pg_md5_ctx *ctx, const uint8 *data, size_t len)
Definition: md5.c:403
const void * data
void pg_sha1_update(pg_sha1_ctx *ctx, const uint8 *data, size_t len)
Definition: sha1.c:332
void pg_sha512_update(pg_sha512_ctx *context, const uint8 *data, size_t len)
Definition: sha2.c:802
void pg_sha224_update(pg_sha224_ctx *context, const uint8 *data, size_t len)
Definition: sha2.c:988
void pg_sha384_update(pg_sha384_ctx *context, const uint8 *data, size_t len)
Definition: sha2.c:944
void pg_sha256_update(pg_sha256_ctx *context, const uint8 *data, size_t len)
Definition: sha2.c:476

References pg_cryptohash_ctx::data, data, pg_cryptohash_ctx::evpctx, len, pg_cryptohash_ctx::md5, PG_MD5, pg_md5_update(), PG_SHA1, pg_sha1_update(), PG_SHA224, pg_sha224_update(), PG_SHA256, pg_sha256_update(), PG_SHA384, pg_sha384_update(), PG_SHA512, pg_sha512_update(), pg_cryptohash_ctx::sha1, pg_cryptohash_ctx::sha224, pg_cryptohash_ctx::sha256, pg_cryptohash_ctx::sha384, pg_cryptohash_ctx::sha512, status(), and pg_cryptohash_ctx::type.

Referenced by AppendStringToManifest(), cryptohash_internal(), pg_checksum_update(), pg_hmac_final(), pg_hmac_init(), pg_hmac_update(), pg_md5_binary(), pg_md5_hash(), scram_H(), scram_mock_salt(), uuid_generate_internal(), and verify_manifest_checksum().