PostgreSQL Source Code  git master
internal.c File Reference
#include "postgres.h"
#include <time.h>
#include "px.h"
#include "md5.h"
#include "sha1.h"
#include "blf.h"
#include "rijndael.h"
Include dependency graph for internal.c:

Go to the source code of this file.

Data Structures

struct  int_digest
 
struct  int_ctx
 
struct  int_cipher
 

Macros

#define MD5_DIGEST_LENGTH   16
 
#define SHA1_DIGEST_LENGTH   SHA1_RESULTLEN
 
#define SHA1_BLOCK_SIZE   64
 
#define MD5_BLOCK_SIZE   64
 
#define INT_MAX_KEY   (512/8)
 
#define INT_MAX_IV   (128/8)
 
#define MODE_ECB   0
 
#define MODE_CBC   1
 

Functions

static void init_md5 (PX_MD *h)
 
static void init_sha1 (PX_MD *h)
 
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_md5_len (PX_MD *h)
 
static unsigned int_md5_block_len (PX_MD *h)
 
static void int_md5_update (PX_MD *h, const uint8 *data, unsigned dlen)
 
static void int_md5_reset (PX_MD *h)
 
static void int_md5_finish (PX_MD *h, uint8 *dst)
 
static void int_md5_free (PX_MD *h)
 
static unsigned int_sha1_len (PX_MD *h)
 
static unsigned int_sha1_block_len (PX_MD *h)
 
static void int_sha1_update (PX_MD *h, const uint8 *data, unsigned dlen)
 
static void int_sha1_reset (PX_MD *h)
 
static void int_sha1_finish (PX_MD *h, uint8 *dst)
 
static void int_sha1_free (PX_MD *h)
 
static void intctx_free (PX_Cipher *c)
 
static unsigned rj_block_size (PX_Cipher *c)
 
static unsigned rj_key_size (PX_Cipher *c)
 
static unsigned rj_iv_size (PX_Cipher *c)
 
static int rj_init (PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
 
static int rj_real_init (struct int_ctx *cx, int dir)
 
static int rj_encrypt (PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
 
static int rj_decrypt (PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
 
static PX_Cipherrj_load (int mode)
 
static unsigned bf_block_size (PX_Cipher *c)
 
static unsigned bf_key_size (PX_Cipher *c)
 
static unsigned bf_iv_size (PX_Cipher *c)
 
static int bf_init (PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
 
static int bf_encrypt (PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
 
static int bf_decrypt (PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
 
static PX_Cipherbf_load (int mode)
 
static PX_Cipherrj_128_ecb (void)
 
static PX_Cipherrj_128_cbc (void)
 
static PX_Cipherbf_ecb_load (void)
 
static PX_Cipherbf_cbc_load (void)
 
int px_find_digest (const char *name, PX_MD **res)
 
int px_find_cipher (const char *name, PX_Cipher **res)
 

Variables

static const struct int_digest int_digest_list []
 
static const struct int_cipher int_ciphers []
 
static const PX_Alias int_aliases []
 

Macro Definition Documentation

◆ INT_MAX_IV

#define INT_MAX_IV   (128/8)

Definition at line 225 of file internal.c.

◆ INT_MAX_KEY

#define INT_MAX_KEY   (512/8)

Definition at line 224 of file internal.c.

◆ MD5_BLOCK_SIZE

#define MD5_BLOCK_SIZE   64

Definition at line 55 of file internal.c.

Referenced by int_md5_block_len().

◆ MD5_DIGEST_LENGTH

#define MD5_DIGEST_LENGTH   16

Definition at line 43 of file internal.c.

Referenced by int_md5_len().

◆ MODE_CBC

#define MODE_CBC   1

Definition at line 259 of file internal.c.

Referenced by bf_cbc_load(), bf_decrypt(), bf_encrypt(), rj_128_cbc(), rj_decrypt(), and rj_encrypt().

◆ MODE_ECB

#define MODE_ECB   0

Definition at line 258 of file internal.c.

Referenced by bf_decrypt(), bf_ecb_load(), bf_encrypt(), and rj_128_ecb().

◆ SHA1_BLOCK_SIZE

#define SHA1_BLOCK_SIZE   64

Definition at line 54 of file internal.c.

Referenced by int_sha1_block_len().

◆ SHA1_DIGEST_LENGTH

#define SHA1_DIGEST_LENGTH   SHA1_RESULTLEN

Definition at line 48 of file internal.c.

Referenced by int_sha1_len().

Function Documentation

◆ bf_block_size()

static unsigned bf_block_size ( PX_Cipher c)
static

Definition at line 400 of file internal.c.

Referenced by bf_load().

401 {
402  return 8;
403 }

◆ bf_cbc_load()

static PX_Cipher* bf_cbc_load ( void  )
static

Definition at line 524 of file internal.c.

References bf_load(), and MODE_CBC.

525 {
526  return bf_load(MODE_CBC);
527 }
static PX_Cipher * bf_load(int mode)
Definition: internal.c:480
#define MODE_CBC
Definition: internal.c:259

◆ bf_decrypt()

static int bf_decrypt ( PX_Cipher c,
const uint8 data,
unsigned  dlen,
uint8 res 
)
static

Definition at line 455 of file internal.c.

References int_ctx::bf, blowfish_decrypt_cbc(), blowfish_decrypt_ecb(), int_ctx::ctx, cx(), int_ctx::mode, MODE_CBC, MODE_ECB, px_cipher::ptr, and PXE_NOTBLOCKSIZE.

Referenced by bf_load().

456 {
457  struct int_ctx *cx = (struct int_ctx *) c->ptr;
458  BlowfishContext *bfctx = &cx->ctx.bf;
459 
460  if (dlen == 0)
461  return 0;
462 
463  if (dlen & 7)
464  return PXE_NOTBLOCKSIZE;
465 
466  memcpy(res, data, dlen);
467  switch (cx->mode)
468  {
469  case MODE_ECB:
470  blowfish_decrypt_ecb(res, dlen, bfctx);
471  break;
472  case MODE_CBC:
473  blowfish_decrypt_cbc(res, dlen, bfctx);
474  break;
475  }
476  return 0;
477 }
BlowfishContext bf
Definition: internal.c:233
void * ptr
Definition: px.h:162
#define MODE_CBC
Definition: internal.c:259
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
void blowfish_decrypt_ecb(uint8 *blk, int len, BlowfishContext *ctx)
Definition: blf.c:408
union int_ctx::@2 ctx
#define MODE_ECB
Definition: internal.c:258
#define PXE_NOTBLOCKSIZE
Definition: px.h:63
void blowfish_decrypt_cbc(uint8 *blk, int len, BlowfishContext *ctx)
Definition: blf.c:354
int mode
Definition: internal.c:238

◆ bf_ecb_load()

static PX_Cipher* bf_ecb_load ( void  )
static

Definition at line 518 of file internal.c.

References bf_load(), and MODE_ECB.

519 {
520  return bf_load(MODE_ECB);
521 }
static PX_Cipher * bf_load(int mode)
Definition: internal.c:480
#define MODE_ECB
Definition: internal.c:258

◆ bf_encrypt()

static int bf_encrypt ( PX_Cipher c,
const uint8 data,
unsigned  dlen,
uint8 res 
)
static

Definition at line 430 of file internal.c.

References int_ctx::bf, blowfish_encrypt_cbc(), blowfish_encrypt_ecb(), int_ctx::ctx, cx(), int_ctx::mode, MODE_CBC, MODE_ECB, px_cipher::ptr, and PXE_NOTBLOCKSIZE.

Referenced by bf_load().

431 {
432  struct int_ctx *cx = (struct int_ctx *) c->ptr;
433  BlowfishContext *bfctx = &cx->ctx.bf;
434 
435  if (dlen == 0)
436  return 0;
437 
438  if (dlen & 7)
439  return PXE_NOTBLOCKSIZE;
440 
441  memcpy(res, data, dlen);
442  switch (cx->mode)
443  {
444  case MODE_ECB:
445  blowfish_encrypt_ecb(res, dlen, bfctx);
446  break;
447  case MODE_CBC:
448  blowfish_encrypt_cbc(res, dlen, bfctx);
449  break;
450  }
451  return 0;
452 }
BlowfishContext bf
Definition: internal.c:233
void blowfish_encrypt_cbc(uint8 *blk, int len, BlowfishContext *ctx)
Definition: blf.c:321
void * ptr
Definition: px.h:162
#define MODE_CBC
Definition: internal.c:259
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
union int_ctx::@2 ctx
#define MODE_ECB
Definition: internal.c:258
#define PXE_NOTBLOCKSIZE
Definition: px.h:63
void blowfish_encrypt_ecb(uint8 *blk, int len, BlowfishContext *ctx)
Definition: blf.c:387
int mode
Definition: internal.c:238

◆ bf_init()

static int bf_init ( PX_Cipher c,
const uint8 key,
unsigned  klen,
const uint8 iv 
)
static

Definition at line 418 of file internal.c.

References int_ctx::bf, blowfish_setiv(), blowfish_setkey(), int_ctx::ctx, cx(), and px_cipher::ptr.

Referenced by bf_load().

419 {
420  struct int_ctx *cx = (struct int_ctx *) c->ptr;
421 
422  blowfish_setkey(&cx->ctx.bf, key, klen);
423  if (iv)
424  blowfish_setiv(&cx->ctx.bf, iv);
425 
426  return 0;
427 }
BlowfishContext bf
Definition: internal.c:233
void * ptr
Definition: px.h:162
uint8 iv[INT_MAX_IV]
Definition: internal.c:230
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
void blowfish_setiv(BlowfishContext *ctx, const uint8 *iv)
Definition: blf.c:495
union int_ctx::@2 ctx
void blowfish_setkey(BlowfishContext *ctx, const uint8 *key, short keybytes)
Definition: blf.c:429

◆ bf_iv_size()

static unsigned bf_iv_size ( PX_Cipher c)
static

Definition at line 412 of file internal.c.

Referenced by bf_load().

413 {
414  return 8;
415 }

◆ bf_key_size()

static unsigned bf_key_size ( PX_Cipher c)
static

Definition at line 406 of file internal.c.

Referenced by bf_load().

407 {
408  return 448 / 8;
409 }

◆ bf_load()

static PX_Cipher* bf_load ( int  mode)
static

Definition at line 480 of file internal.c.

References bf_block_size(), bf_decrypt(), bf_encrypt(), bf_init(), bf_iv_size(), bf_key_size(), px_cipher::block_size, cx(), px_cipher::decrypt, px_cipher::encrypt, px_cipher::free, px_cipher::init, intctx_free(), px_cipher::iv_size, px_cipher::key_size, mode, int_ctx::mode, px_cipher::ptr, and px_alloc.

Referenced by bf_cbc_load(), and bf_ecb_load().

481 {
482  PX_Cipher *c;
483  struct int_ctx *cx;
484 
485  c = px_alloc(sizeof *c);
486  memset(c, 0, sizeof *c);
487 
489  c->key_size = bf_key_size;
490  c->iv_size = bf_iv_size;
491  c->init = bf_init;
492  c->encrypt = bf_encrypt;
493  c->decrypt = bf_decrypt;
494  c->free = intctx_free;
495 
496  cx = px_alloc(sizeof *cx);
497  memset(cx, 0, sizeof *cx);
498  cx->mode = mode;
499  c->ptr = cx;
500  return c;
501 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
static int bf_decrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: internal.c:455
static void intctx_free(PX_Cipher *c)
Definition: internal.c:242
unsigned(* block_size)(PX_Cipher *c)
Definition: px.h:153
int(* decrypt)(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: px.h:159
void * ptr
Definition: px.h:162
void(* free)(PX_Cipher *c)
Definition: px.h:160
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
unsigned(* iv_size)(PX_Cipher *c)
Definition: px.h:155
char * c
unsigned(* key_size)(PX_Cipher *c)
Definition: px.h:154
static int bf_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
Definition: internal.c:418
int(* encrypt)(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: px.h:158
static unsigned bf_key_size(PX_Cipher *c)
Definition: internal.c:406
static int bf_encrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: internal.c:430
int(* init)(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
Definition: px.h:157
Definition: px.h:151
static unsigned bf_block_size(PX_Cipher *c)
Definition: internal.c:400
#define px_alloc(s)
Definition: px.h:44
static unsigned bf_iv_size(PX_Cipher *c)
Definition: internal.c:412
int mode
Definition: internal.c:238

◆ init_md5()

static void init_md5 ( PX_MD h)
static

Definition at line 181 of file internal.c.

References px_digest::block_size, px_digest::finish, px_digest::free, int_md5_block_len(), int_md5_finish(), int_md5_free(), int_md5_len(), int_md5_reset(), int_md5_update(), MD5_CTX, px_digest::p, px_digest::ptr, px_alloc, px_digest::reset, px_digest::result_size, and px_digest::update.

182 {
183  MD5_CTX *ctx;
184 
185  ctx = px_alloc(sizeof(*ctx));
186  memset(ctx, 0, sizeof(*ctx));
187 
188  md->p.ptr = ctx;
189 
190  md->result_size = int_md5_len;
191  md->block_size = int_md5_block_len;
192  md->reset = int_md5_reset;
193  md->update = int_md5_update;
194  md->finish = int_md5_finish;
195  md->free = int_md5_free;
196 
197  md->reset(md);
198 }
#define MD5_CTX
Definition: md5.h:70
static void int_md5_reset(PX_MD *h)
Definition: internal.c:105
union int_ctx::@2 ctx
static unsigned int_md5_len(PX_MD *h)
Definition: internal.c:85
static void int_md5_finish(PX_MD *h, uint8 *dst)
Definition: internal.c:113
static unsigned int_md5_block_len(PX_MD *h)
Definition: internal.c:91
#define px_alloc(s)
Definition: px.h:44
static void int_md5_free(PX_MD *h)
Definition: internal.c:121
static void int_md5_update(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: internal.c:97

◆ init_sha1()

static void init_sha1 ( PX_MD h)
static

Definition at line 201 of file internal.c.

References px_digest::block_size, px_digest::finish, px_digest::free, int_sha1_block_len(), int_sha1_finish(), int_sha1_free(), int_sha1_len(), int_sha1_reset(), int_sha1_update(), px_digest::p, px_digest::ptr, px_alloc, px_digest::reset, px_digest::result_size, and px_digest::update.

202 {
203  SHA1_CTX *ctx;
204 
205  ctx = px_alloc(sizeof(*ctx));
206  memset(ctx, 0, sizeof(*ctx));
207 
208  md->p.ptr = ctx;
209 
210  md->result_size = int_sha1_len;
211  md->block_size = int_sha1_block_len;
212  md->reset = int_sha1_reset;
213  md->update = int_sha1_update;
214  md->finish = int_sha1_finish;
215  md->free = int_sha1_free;
216 
217  md->reset(md);
218 }
static unsigned int_sha1_block_len(PX_MD *h)
Definition: internal.c:139
static void int_sha1_free(PX_MD *h)
Definition: internal.c:169
static void int_sha1_update(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: internal.c:145
Definition: sha1.h:41
union int_ctx::@2 ctx
static unsigned int_sha1_len(PX_MD *h)
Definition: internal.c:133
#define px_alloc(s)
Definition: px.h:44
static void int_sha1_reset(PX_MD *h)
Definition: internal.c:153
static void int_sha1_finish(PX_MD *h, uint8 *dst)
Definition: internal.c:161

◆ init_sha224()

void init_sha224 ( PX_MD h)

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

References px_digest::block_size, px_digest::finish, px_digest::free, int_sha224_block_len(), int_sha224_finish(), int_sha224_free(), int_sha224_len(), int_sha224_reset(), int_sha224_update(), px_digest::p, px_digest::ptr, px_alloc, px_digest::reset, px_digest::result_size, and px_digest::update.

240 {
242 
243  ctx = px_alloc(sizeof(*ctx));
244  memset(ctx, 0, sizeof(*ctx));
245 
246  md->p.ptr = ctx;
247 
248  md->result_size = int_sha224_len;
249  md->block_size = int_sha224_block_len;
250  md->reset = int_sha224_reset;
251  md->update = int_sha224_update;
252  md->finish = int_sha224_finish;
253  md->free = int_sha224_free;
254 
255  md->reset(md);
256 }
static void int_sha224_reset(PX_MD *h)
Definition: internal-sha2.c:67
union int_ctx::@2 ctx
static unsigned int_sha224_block_len(PX_MD *h)
Definition: internal-sha2.c:53
static void int_sha224_update(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: internal-sha2.c:59
static unsigned int_sha224_len(PX_MD *h)
Definition: internal-sha2.c:47
#define px_alloc(s)
Definition: px.h:44
static void int_sha224_free(PX_MD *h)
Definition: internal-sha2.c:83
static void int_sha224_finish(PX_MD *h, uint8 *dst)
Definition: internal-sha2.c:75

◆ init_sha256()

void init_sha256 ( PX_MD h)

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

References px_digest::block_size, px_digest::finish, px_digest::free, int_sha256_block_len(), int_sha256_finish(), int_sha256_free(), int_sha256_len(), int_sha256_reset(), int_sha256_update(), px_digest::p, px_digest::ptr, px_alloc, px_digest::reset, px_digest::result_size, and px_digest::update.

260 {
262 
263  ctx = px_alloc(sizeof(*ctx));
264  memset(ctx, 0, sizeof(*ctx));
265 
266  md->p.ptr = ctx;
267 
268  md->result_size = int_sha256_len;
269  md->block_size = int_sha256_block_len;
270  md->reset = int_sha256_reset;
271  md->update = int_sha256_update;
272  md->finish = int_sha256_finish;
273  md->free = int_sha256_free;
274 
275  md->reset(md);
276 }
static void int_sha256_reset(PX_MD *h)
static unsigned int_sha256_len(PX_MD *h)
Definition: internal-sha2.c:95
union int_ctx::@2 ctx
static void int_sha256_finish(PX_MD *h, uint8 *dst)
static void int_sha256_update(PX_MD *h, const uint8 *data, unsigned dlen)
static unsigned int_sha256_block_len(PX_MD *h)
#define px_alloc(s)
Definition: px.h:44
static void int_sha256_free(PX_MD *h)

◆ init_sha384()

void init_sha384 ( PX_MD h)

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

References px_digest::block_size, px_digest::finish, px_digest::free, int_sha384_block_len(), int_sha384_finish(), int_sha384_free(), int_sha384_len(), int_sha384_reset(), int_sha384_update(), px_digest::p, px_digest::ptr, px_alloc, px_digest::reset, px_digest::result_size, and px_digest::update.

280 {
282 
283  ctx = px_alloc(sizeof(*ctx));
284  memset(ctx, 0, sizeof(*ctx));
285 
286  md->p.ptr = ctx;
287 
288  md->result_size = int_sha384_len;
289  md->block_size = int_sha384_block_len;
290  md->reset = int_sha384_reset;
291  md->update = int_sha384_update;
292  md->finish = int_sha384_finish;
293  md->free = int_sha384_free;
294 
295  md->reset(md);
296 }
static void int_sha384_update(PX_MD *h, const uint8 *data, unsigned dlen)
static void int_sha384_reset(PX_MD *h)
static unsigned int_sha384_block_len(PX_MD *h)
static void int_sha384_finish(PX_MD *h, uint8 *dst)
static void int_sha384_free(PX_MD *h)
union int_ctx::@2 ctx
static unsigned int_sha384_len(PX_MD *h)
#define px_alloc(s)
Definition: px.h:44

◆ init_sha512()

void init_sha512 ( PX_MD h)

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

References px_digest::block_size, px_digest::finish, px_digest::free, int_sha512_block_len(), int_sha512_finish(), int_sha512_free(), int_sha512_len(), int_sha512_reset(), int_sha512_update(), px_digest::p, px_digest::ptr, px_alloc, px_digest::reset, px_digest::result_size, and px_digest::update.

300 {
302 
303  ctx = px_alloc(sizeof(*ctx));
304  memset(ctx, 0, sizeof(*ctx));
305 
306  md->p.ptr = ctx;
307 
308  md->result_size = int_sha512_len;
309  md->block_size = int_sha512_block_len;
310  md->reset = int_sha512_reset;
311  md->update = int_sha512_update;
312  md->finish = int_sha512_finish;
313  md->free = int_sha512_free;
314 
315  md->reset(md);
316 }
static unsigned int_sha512_len(PX_MD *h)
static void int_sha512_reset(PX_MD *h)
union int_ctx::@2 ctx
static void int_sha512_update(PX_MD *h, const uint8 *data, unsigned dlen)
static unsigned int_sha512_block_len(PX_MD *h)
#define px_alloc(s)
Definition: px.h:44
static void int_sha512_finish(PX_MD *h, uint8 *dst)
static void int_sha512_free(PX_MD *h)

◆ int_md5_block_len()

static unsigned int_md5_block_len ( PX_MD h)
static

Definition at line 91 of file internal.c.

References MD5_BLOCK_SIZE.

Referenced by init_md5().

92 {
93  return MD5_BLOCK_SIZE;
94 }
#define MD5_BLOCK_SIZE
Definition: internal.c:55

◆ int_md5_finish()

static void int_md5_finish ( PX_MD h,
uint8 dst 
)
static

Definition at line 113 of file internal.c.

References MD5_CTX, MD5Final, px_digest::p, and px_digest::ptr.

Referenced by init_md5().

114 {
115  MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
116 
117  MD5Final(dst, ctx);
118 }
#define MD5Final(x, y)
Definition: md5.h:73
void * ptr
Definition: px.h:122
#define MD5_CTX
Definition: md5.h:70
union int_ctx::@2 ctx
union px_digest::@13 p

◆ int_md5_free()

static void int_md5_free ( PX_MD h)
static

Definition at line 121 of file internal.c.

References MD5_CTX, px_digest::p, px_digest::ptr, px_free, and px_memset().

Referenced by init_md5().

122 {
123  MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
124 
125  px_memset(ctx, 0, sizeof(*ctx));
126  px_free(ctx);
127  px_free(h);
128 }
void * ptr
Definition: px.h:122
#define MD5_CTX
Definition: md5.h:70
#define px_free(p)
Definition: px.h:46
union int_ctx::@2 ctx
union px_digest::@13 p
void px_memset(void *ptr, int c, size_t len)
Definition: px.c:126

◆ int_md5_len()

static unsigned int_md5_len ( PX_MD h)
static

Definition at line 85 of file internal.c.

References MD5_DIGEST_LENGTH.

Referenced by init_md5().

86 {
87  return MD5_DIGEST_LENGTH;
88 }
#define MD5_DIGEST_LENGTH
Definition: internal.c:43

◆ int_md5_reset()

static void int_md5_reset ( PX_MD h)
static

Definition at line 105 of file internal.c.

References MD5_CTX, MD5Init, px_digest::p, and px_digest::ptr.

Referenced by init_md5().

106 {
107  MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
108 
109  MD5Init(ctx);
110 }
void * ptr
Definition: px.h:122
#define MD5_CTX
Definition: md5.h:70
#define MD5Init(x)
Definition: md5.h:71
union int_ctx::@2 ctx
union px_digest::@13 p

◆ int_md5_update()

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

Definition at line 97 of file internal.c.

References MD5_CTX, MD5Update, px_digest::p, and px_digest::ptr.

Referenced by init_md5().

98 {
99  MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
100 
101  MD5Update(ctx, data, dlen);
102 }
void * ptr
Definition: px.h:122
#define MD5_CTX
Definition: md5.h:70
#define MD5Update(x, y, z)
Definition: md5.h:72
union int_ctx::@2 ctx
union px_digest::@13 p

◆ int_sha1_block_len()

static unsigned int_sha1_block_len ( PX_MD h)
static

Definition at line 139 of file internal.c.

References SHA1_BLOCK_SIZE.

Referenced by init_sha1().

140 {
141  return SHA1_BLOCK_SIZE;
142 }
#define SHA1_BLOCK_SIZE
Definition: internal.c:54

◆ int_sha1_finish()

static void int_sha1_finish ( PX_MD h,
uint8 dst 
)
static

Definition at line 161 of file internal.c.

References px_digest::p, px_digest::ptr, and SHA1Final.

Referenced by init_sha1().

162 {
163  SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
164 
165  SHA1Final(dst, ctx);
166 }
void * ptr
Definition: px.h:122
Definition: sha1.h:41
union int_ctx::@2 ctx
#define SHA1Final(x, y)
Definition: sha1.h:71
union px_digest::@13 p

◆ int_sha1_free()

static void int_sha1_free ( PX_MD h)
static

Definition at line 169 of file internal.c.

References px_digest::p, px_digest::ptr, px_free, and px_memset().

Referenced by init_sha1().

170 {
171  SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
172 
173  px_memset(ctx, 0, sizeof(*ctx));
174  px_free(ctx);
175  px_free(h);
176 }
void * ptr
Definition: px.h:122
#define px_free(p)
Definition: px.h:46
Definition: sha1.h:41
union int_ctx::@2 ctx
union px_digest::@13 p
void px_memset(void *ptr, int c, size_t len)
Definition: px.c:126

◆ int_sha1_len()

static unsigned int_sha1_len ( PX_MD h)
static

Definition at line 133 of file internal.c.

References SHA1_DIGEST_LENGTH.

Referenced by init_sha1().

134 {
135  return SHA1_DIGEST_LENGTH;
136 }
#define SHA1_DIGEST_LENGTH
Definition: internal.c:48

◆ int_sha1_reset()

static void int_sha1_reset ( PX_MD h)
static

Definition at line 153 of file internal.c.

References px_digest::p, px_digest::ptr, and SHA1Init.

Referenced by init_sha1().

154 {
155  SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
156 
157  SHA1Init(ctx);
158 }
void * ptr
Definition: px.h:122
#define SHA1Init(x)
Definition: sha1.h:69
Definition: sha1.h:41
union int_ctx::@2 ctx
union px_digest::@13 p

◆ int_sha1_update()

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

Definition at line 145 of file internal.c.

References px_digest::p, px_digest::ptr, and SHA1Update.

Referenced by init_sha1().

146 {
147  SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
148 
149  SHA1Update(ctx, data, dlen);
150 }
void * ptr
Definition: px.h:122
Definition: sha1.h:41
union int_ctx::@2 ctx
union px_digest::@13 p
#define SHA1Update(x, y, z)
Definition: sha1.h:70

◆ intctx_free()

static void intctx_free ( PX_Cipher c)
static

Definition at line 242 of file internal.c.

References cx(), px_cipher::ptr, px_free, and px_memset().

Referenced by bf_load(), and rj_load().

243 {
244  struct int_ctx *cx = (struct int_ctx *) c->ptr;
245 
246  if (cx)
247  {
248  px_memset(cx, 0, sizeof *cx);
249  px_free(cx);
250  }
251  px_free(c);
252 }
#define px_free(p)
Definition: px.h:46
void * ptr
Definition: px.h:162
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
void px_memset(void *ptr, int c, size_t len)
Definition: px.c:126

◆ px_find_cipher()

int px_find_cipher ( const char *  name,
PX_Cipher **  res 
)

Definition at line 578 of file internal.c.

Referenced by pgp_load_cipher(), and px_find_combo().

579 {
580  int i;
581  PX_Cipher *c = NULL;
582 
584 
585  for (i = 0; int_ciphers[i].name; i++)
586  if (strcmp(int_ciphers[i].name, name) == 0)
587  {
588  c = int_ciphers[i].load();
589  break;
590  }
591 
592  if (c == NULL)
593  return PXE_NO_CIPHER;
594 
595  *res = c;
596  return 0;
597 }
static const struct int_cipher int_ciphers[]
Definition: internal.c:536
PX_Cipher *(* load)(void)
Definition: internal.c:532
char * name
Definition: internal.c:531
const char * px_resolve_alias(const PX_Alias *list, const char *name)
Definition: px.c:132
char * c
Definition: px.h:151
const char * name
Definition: encode.c:521
int i
#define PXE_NO_CIPHER
Definition: px.h:62
static const PX_Alias int_aliases[]
Definition: internal.c:544

◆ px_find_digest()

int px_find_digest ( const char *  name,
PX_MD **  res 
)

Definition at line 559 of file internal.c.

Referenced by pg_digest(), pgp_load_digest(), px_crypt_md5(), and px_find_hmac().

560 {
561  const struct int_digest *p;
562  PX_MD *h;
563 
564  for (p = int_digest_list; p->name; p++)
565  if (pg_strcasecmp(p->name, name) == 0)
566  {
567  h = px_alloc(sizeof(*h));
568  p->init(h);
569 
570  *res = h;
571 
572  return 0;
573  }
574  return PXE_NO_HASH;
575 }
static const struct int_digest int_digest_list[]
Definition: internal.c:72
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
Definition: px.h:110
#define PXE_NO_HASH
Definition: px.h:61
char * name
Definition: internal.c:67
const char * name
Definition: encode.c:521
#define px_alloc(s)
Definition: px.h:44
void(* init)(PX_MD *h)
Definition: internal.c:68

◆ rj_128_cbc()

static PX_Cipher* rj_128_cbc ( void  )
static

Definition at line 512 of file internal.c.

References MODE_CBC, and rj_load().

513 {
514  return rj_load(MODE_CBC);
515 }
#define MODE_CBC
Definition: internal.c:259
static PX_Cipher * rj_load(int mode)
Definition: internal.c:371

◆ rj_128_ecb()

static PX_Cipher* rj_128_ecb ( void  )
static

Definition at line 506 of file internal.c.

References MODE_ECB, and rj_load().

507 {
508  return rj_load(MODE_ECB);
509 }
#define MODE_ECB
Definition: internal.c:258
static PX_Cipher * rj_load(int mode)
Definition: internal.c:371

◆ rj_block_size()

static unsigned rj_block_size ( PX_Cipher c)
static

Definition at line 262 of file internal.c.

Referenced by rj_load().

263 {
264  return 128 / 8;
265 }

◆ rj_decrypt()

static int rj_decrypt ( PX_Cipher c,
const uint8 data,
unsigned  dlen,
uint8 res 
)
static

Definition at line 339 of file internal.c.

References aes_cbc_decrypt(), aes_ecb_decrypt(), int_ctx::ctx, cx(), int_ctx::is_init, int_ctx::iv, int_ctx::mode, MODE_CBC, px_cipher::ptr, PXE_CIPHER_INIT, PXE_NOTBLOCKSIZE, int_ctx::rj, and rj_real_init().

Referenced by rj_load().

340 {
341  struct int_ctx *cx = (struct int_ctx *) c->ptr;
342 
343  if (!cx->is_init)
344  if (rj_real_init(cx, 0))
345  return PXE_CIPHER_INIT;
346 
347  if (dlen == 0)
348  return 0;
349 
350  if (dlen & 15)
351  return PXE_NOTBLOCKSIZE;
352 
353  memcpy(res, data, dlen);
354 
355  if (cx->mode == MODE_CBC)
356  {
357  aes_cbc_decrypt(&cx->ctx.rj, cx->iv, res, dlen);
358  memcpy(cx->iv, data + dlen - 16, 16);
359  }
360  else
361  aes_ecb_decrypt(&cx->ctx.rj, res, dlen);
362 
363  return 0;
364 }
void aes_cbc_decrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len)
Definition: rijndael.c:567
void * ptr
Definition: px.h:162
#define MODE_CBC
Definition: internal.c:259
uint8 iv[INT_MAX_IV]
Definition: internal.c:230
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
void aes_ecb_decrypt(rijndael_ctx *ctx, uint8 *data, unsigned len)
Definition: rijndael.c:529
union int_ctx::@2 ctx
static int rj_real_init(struct int_ctx *cx, int dir)
Definition: internal.c:302
#define PXE_CIPHER_INIT
Definition: px.h:67
#define PXE_NOTBLOCKSIZE
Definition: px.h:63
rijndael_ctx rj
Definition: internal.c:234
int mode
Definition: internal.c:238
int is_init
Definition: internal.c:237

◆ rj_encrypt()

static int rj_encrypt ( PX_Cipher c,
const uint8 data,
unsigned  dlen,
uint8 res 
)
static

Definition at line 309 of file internal.c.

References aes_cbc_encrypt(), aes_ecb_encrypt(), int_ctx::ctx, cx(), int_ctx::is_init, int_ctx::iv, int_ctx::mode, MODE_CBC, px_cipher::ptr, PXE_CIPHER_INIT, PXE_NOTBLOCKSIZE, int_ctx::rj, and rj_real_init().

Referenced by rj_load().

310 {
311  struct int_ctx *cx = (struct int_ctx *) c->ptr;
312 
313  if (!cx->is_init)
314  {
315  if (rj_real_init(cx, 1))
316  return PXE_CIPHER_INIT;
317  }
318 
319  if (dlen == 0)
320  return 0;
321 
322  if (dlen & 15)
323  return PXE_NOTBLOCKSIZE;
324 
325  memcpy(res, data, dlen);
326 
327  if (cx->mode == MODE_CBC)
328  {
329  aes_cbc_encrypt(&cx->ctx.rj, cx->iv, res, dlen);
330  memcpy(cx->iv, res + dlen - 16, 16);
331  }
332  else
333  aes_ecb_encrypt(&cx->ctx.rj, res, dlen);
334 
335  return 0;
336 }
void aes_cbc_encrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len)
Definition: rijndael.c:545
void * ptr
Definition: px.h:162
#define MODE_CBC
Definition: internal.c:259
uint8 iv[INT_MAX_IV]
Definition: internal.c:230
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
union int_ctx::@2 ctx
static int rj_real_init(struct int_ctx *cx, int dir)
Definition: internal.c:302
#define PXE_CIPHER_INIT
Definition: px.h:67
void aes_ecb_encrypt(rijndael_ctx *ctx, uint8 *data, unsigned len)
Definition: rijndael.c:513
#define PXE_NOTBLOCKSIZE
Definition: px.h:63
rijndael_ctx rj
Definition: internal.c:234
int mode
Definition: internal.c:238
int is_init
Definition: internal.c:237

◆ rj_init()

static int rj_init ( PX_Cipher c,
const uint8 key,
unsigned  klen,
const uint8 iv 
)
static

Definition at line 280 of file internal.c.

References cx(), int_ctx::iv, int_ctx::keybuf, int_ctx::keylen, px_cipher::ptr, and PXE_KEY_TOO_BIG.

Referenced by rj_load().

281 {
282  struct int_ctx *cx = (struct int_ctx *) c->ptr;
283 
284  if (klen <= 128 / 8)
285  cx->keylen = 128 / 8;
286  else if (klen <= 192 / 8)
287  cx->keylen = 192 / 8;
288  else if (klen <= 256 / 8)
289  cx->keylen = 256 / 8;
290  else
291  return PXE_KEY_TOO_BIG;
292 
293  memcpy(&cx->keybuf, key, klen);
294 
295  if (iv)
296  memcpy(cx->iv, iv, 128 / 8);
297 
298  return 0;
299 }
void * ptr
Definition: px.h:162
uint8 keybuf[INT_MAX_KEY]
Definition: internal.c:229
uint8 iv[INT_MAX_IV]
Definition: internal.c:230
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
#define PXE_KEY_TOO_BIG
Definition: px.h:66
unsigned keylen
Definition: internal.c:236

◆ rj_iv_size()

static unsigned rj_iv_size ( PX_Cipher c)
static

Definition at line 274 of file internal.c.

Referenced by rj_load().

275 {
276  return 128 / 8;
277 }

◆ rj_key_size()

static unsigned rj_key_size ( PX_Cipher c)
static

Definition at line 268 of file internal.c.

Referenced by rj_load().

269 {
270  return 256 / 8;
271 }

◆ rj_load()

static PX_Cipher* rj_load ( int  mode)
static

Definition at line 371 of file internal.c.

References px_cipher::block_size, cx(), px_cipher::decrypt, px_cipher::encrypt, px_cipher::free, px_cipher::init, intctx_free(), px_cipher::iv_size, px_cipher::key_size, mode, int_ctx::mode, px_cipher::ptr, px_alloc, rj_block_size(), rj_decrypt(), rj_encrypt(), rj_init(), rj_iv_size(), and rj_key_size().

Referenced by rj_128_cbc(), and rj_128_ecb().

372 {
373  PX_Cipher *c;
374  struct int_ctx *cx;
375 
376  c = px_alloc(sizeof *c);
377  memset(c, 0, sizeof *c);
378 
380  c->key_size = rj_key_size;
381  c->iv_size = rj_iv_size;
382  c->init = rj_init;
383  c->encrypt = rj_encrypt;
384  c->decrypt = rj_decrypt;
385  c->free = intctx_free;
386 
387  cx = px_alloc(sizeof *cx);
388  memset(cx, 0, sizeof *cx);
389  cx->mode = mode;
390 
391  c->ptr = cx;
392  return c;
393 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
static void intctx_free(PX_Cipher *c)
Definition: internal.c:242
unsigned(* block_size)(PX_Cipher *c)
Definition: px.h:153
int(* decrypt)(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: px.h:159
void * ptr
Definition: px.h:162
void(* free)(PX_Cipher *c)
Definition: px.h:160
static unsigned rj_block_size(PX_Cipher *c)
Definition: internal.c:262
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
static int rj_encrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: internal.c:309
static int rj_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
Definition: internal.c:280
static unsigned rj_key_size(PX_Cipher *c)
Definition: internal.c:268
unsigned(* iv_size)(PX_Cipher *c)
Definition: px.h:155
char * c
unsigned(* key_size)(PX_Cipher *c)
Definition: px.h:154
static unsigned rj_iv_size(PX_Cipher *c)
Definition: internal.c:274
int(* encrypt)(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: px.h:158
static int rj_decrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: internal.c:339
int(* init)(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
Definition: px.h:157
Definition: px.h:151
#define px_alloc(s)
Definition: px.h:44
int mode
Definition: internal.c:238

◆ rj_real_init()

static int rj_real_init ( struct int_ctx cx,
int  dir 
)
static

Definition at line 302 of file internal.c.

References aes_set_key(), int_ctx::ctx, int_ctx::keybuf, int_ctx::keylen, and int_ctx::rj.

Referenced by rj_decrypt(), and rj_encrypt().

303 {
304  aes_set_key(&cx->ctx.rj, cx->keybuf, cx->keylen * 8, dir);
305  return 0;
306 }
uint8 keybuf[INT_MAX_KEY]
Definition: internal.c:229
void aes_set_key(rijndael_ctx *ctx, const uint8 *key, unsigned keybits, int enc)
Definition: rijndael.c:504
union int_ctx::@2 ctx
unsigned keylen
Definition: internal.c:236
rijndael_ctx rj
Definition: internal.c:234

Variable Documentation

◆ int_aliases

const PX_Alias int_aliases[]
static
Initial value:
= {
{"bf", "bf-cbc"},
{"blowfish", "bf-cbc"},
{"aes", "aes-128-cbc"},
{"aes-ecb", "aes-128-ecb"},
{"aes-cbc", "aes-128-cbc"},
{"aes-128", "aes-128-cbc"},
{"rijndael", "aes-128-cbc"},
{"rijndael-128", "aes-128-cbc"},
{NULL, NULL}
}

Definition at line 544 of file internal.c.

◆ int_ciphers

const struct int_cipher int_ciphers[]
static
Initial value:
= {
{"bf-cbc", bf_cbc_load},
{"bf-ecb", bf_ecb_load},
{"aes-128-cbc", rj_128_cbc},
{"aes-128-ecb", rj_128_ecb},
{NULL, NULL}
}
static PX_Cipher * bf_cbc_load(void)
Definition: internal.c:524
static PX_Cipher * bf_ecb_load(void)
Definition: internal.c:518
static PX_Cipher * rj_128_ecb(void)
Definition: internal.c:506
static PX_Cipher * rj_128_cbc(void)
Definition: internal.c:512

Definition at line 536 of file internal.c.

◆ int_digest_list

const struct int_digest int_digest_list[]
static
Initial value:
= {
{"md5", init_md5},
{"sha1", init_sha1},
{"sha224", init_sha224},
{"sha256", init_sha256},
{"sha384", init_sha384},
{"sha512", init_sha512},
{NULL, NULL}
}
void init_sha384(PX_MD *h)
void init_sha224(PX_MD *h)
static void init_md5(PX_MD *h)
Definition: internal.c:181
void init_sha256(PX_MD *h)
void init_sha512(PX_MD *h)
static void init_sha1(PX_MD *h)
Definition: internal.c:201

Definition at line 72 of file internal.c.