PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 SYSTEM_RESEED_MIN   (20*60) /* 20 min */
 
#define SYSTEM_RESEED_CHECK_TIME   (10*60) /* 10 min */
 
#define SYSTEM_RESEED_CHANCE   (4) /* 256/4 * 10min ~ 10h */
 
#define SYSTEM_RESEED_MAX   (12*60*60) /* 12h */
 
#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

#define INT_MAX_IV   (128/8)

Definition at line 244 of file internal.c.

#define INT_MAX_KEY   (512/8)

Definition at line 243 of file internal.c.

#define MD5_BLOCK_SIZE   64

Definition at line 74 of file internal.c.

Referenced by int_md5_block_len().

#define MD5_DIGEST_LENGTH   16

Definition at line 62 of file internal.c.

Referenced by int_md5_len().

#define MODE_CBC   1

Definition at line 278 of file internal.c.

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

#define MODE_ECB   0

Definition at line 277 of file internal.c.

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

#define SHA1_BLOCK_SIZE   64

Definition at line 73 of file internal.c.

Referenced by int_sha1_block_len().

#define SHA1_DIGEST_LENGTH   SHA1_RESULTLEN

Definition at line 67 of file internal.c.

Referenced by int_sha1_len().

#define SYSTEM_RESEED_CHANCE   (4) /* 256/4 * 10min ~ 10h */

Definition at line 53 of file internal.c.

#define SYSTEM_RESEED_CHECK_TIME   (10*60) /* 10 min */

Definition at line 49 of file internal.c.

#define SYSTEM_RESEED_MAX   (12*60*60) /* 12h */

Definition at line 58 of file internal.c.

#define SYSTEM_RESEED_MIN   (20*60) /* 20 min */

Definition at line 45 of file internal.c.

Function Documentation

static unsigned bf_block_size ( PX_Cipher c)
static

Definition at line 419 of file internal.c.

Referenced by bf_load().

420 {
421  return 8;
422 }
static PX_Cipher* bf_cbc_load ( void  )
static

Definition at line 543 of file internal.c.

References bf_load(), and MODE_CBC.

544 {
545  return bf_load(MODE_CBC);
546 }
static PX_Cipher * bf_load(int mode)
Definition: internal.c:499
#define MODE_CBC
Definition: internal.c:278
static int bf_decrypt ( PX_Cipher c,
const uint8 data,
unsigned  dlen,
uint8 res 
)
static

Definition at line 474 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().

475 {
476  struct int_ctx *cx = (struct int_ctx *) c->ptr;
477  BlowfishContext *bfctx = &cx->ctx.bf;
478 
479  if (dlen == 0)
480  return 0;
481 
482  if (dlen & 7)
483  return PXE_NOTBLOCKSIZE;
484 
485  memcpy(res, data, dlen);
486  switch (cx->mode)
487  {
488  case MODE_ECB:
489  blowfish_decrypt_ecb(res, dlen, bfctx);
490  break;
491  case MODE_CBC:
492  blowfish_decrypt_cbc(res, dlen, bfctx);
493  break;
494  }
495  return 0;
496 }
BlowfishContext bf
Definition: internal.c:252
void * ptr
Definition: px.h:165
#define MODE_CBC
Definition: internal.c:278
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:277
#define PXE_NOTBLOCKSIZE
Definition: px.h:66
void blowfish_decrypt_cbc(uint8 *blk, int len, BlowfishContext *ctx)
Definition: blf.c:354
int mode
Definition: internal.c:257
static PX_Cipher* bf_ecb_load ( void  )
static

Definition at line 537 of file internal.c.

References bf_load(), and MODE_ECB.

538 {
539  return bf_load(MODE_ECB);
540 }
static PX_Cipher * bf_load(int mode)
Definition: internal.c:499
#define MODE_ECB
Definition: internal.c:277
static int bf_encrypt ( PX_Cipher c,
const uint8 data,
unsigned  dlen,
uint8 res 
)
static

Definition at line 449 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().

450 {
451  struct int_ctx *cx = (struct int_ctx *) c->ptr;
452  BlowfishContext *bfctx = &cx->ctx.bf;
453 
454  if (dlen == 0)
455  return 0;
456 
457  if (dlen & 7)
458  return PXE_NOTBLOCKSIZE;
459 
460  memcpy(res, data, dlen);
461  switch (cx->mode)
462  {
463  case MODE_ECB:
464  blowfish_encrypt_ecb(res, dlen, bfctx);
465  break;
466  case MODE_CBC:
467  blowfish_encrypt_cbc(res, dlen, bfctx);
468  break;
469  }
470  return 0;
471 }
BlowfishContext bf
Definition: internal.c:252
void blowfish_encrypt_cbc(uint8 *blk, int len, BlowfishContext *ctx)
Definition: blf.c:321
void * ptr
Definition: px.h:165
#define MODE_CBC
Definition: internal.c:278
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:277
#define PXE_NOTBLOCKSIZE
Definition: px.h:66
void blowfish_encrypt_ecb(uint8 *blk, int len, BlowfishContext *ctx)
Definition: blf.c:387
int mode
Definition: internal.c:257
static int bf_init ( PX_Cipher c,
const uint8 key,
unsigned  klen,
const uint8 iv 
)
static

Definition at line 437 of file internal.c.

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

Referenced by bf_load().

438 {
439  struct int_ctx *cx = (struct int_ctx *) c->ptr;
440 
441  blowfish_setkey(&cx->ctx.bf, key, klen);
442  if (iv)
443  blowfish_setiv(&cx->ctx.bf, iv);
444 
445  return 0;
446 }
BlowfishContext bf
Definition: internal.c:252
void * ptr
Definition: px.h:165
uint8 iv[INT_MAX_IV]
Definition: internal.c:249
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
static unsigned bf_iv_size ( PX_Cipher c)
static

Definition at line 431 of file internal.c.

Referenced by bf_load().

432 {
433  return 8;
434 }
static unsigned bf_key_size ( PX_Cipher c)
static

Definition at line 425 of file internal.c.

Referenced by bf_load().

426 {
427  return 448 / 8;
428 }
static PX_Cipher* bf_load ( int  mode)
static

Definition at line 499 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, int_ctx::mode, px_cipher::ptr, and px_alloc.

Referenced by bf_cbc_load(), and bf_ecb_load().

500 {
501  PX_Cipher *c;
502  struct int_ctx *cx;
503 
504  c = px_alloc(sizeof *c);
505  memset(c, 0, sizeof *c);
506 
508  c->key_size = bf_key_size;
509  c->iv_size = bf_iv_size;
510  c->init = bf_init;
511  c->encrypt = bf_encrypt;
512  c->decrypt = bf_decrypt;
513  c->free = intctx_free;
514 
515  cx = px_alloc(sizeof *cx);
516  memset(cx, 0, sizeof *cx);
517  cx->mode = mode;
518  c->ptr = cx;
519  return c;
520 }
void(* free)(PX_Cipher *c)
Definition: px.h:163
unsigned(* key_size)(PX_Cipher *c)
Definition: px.h:157
static int bf_decrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: internal.c:474
static void intctx_free(PX_Cipher *c)
Definition: internal.c:261
void * ptr
Definition: px.h:165
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
char * c
int(* init)(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
Definition: px.h:160
unsigned(* iv_size)(PX_Cipher *c)
Definition: px.h:158
int(* encrypt)(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: px.h:161
static int bf_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
Definition: internal.c:437
static unsigned bf_key_size(PX_Cipher *c)
Definition: internal.c:425
static int bf_encrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: internal.c:449
Definition: px.h:154
static unsigned bf_block_size(PX_Cipher *c)
Definition: internal.c:419
#define px_alloc(s)
Definition: px.h:44
static unsigned bf_iv_size(PX_Cipher *c)
Definition: internal.c:431
int mode
Definition: internal.c:257
unsigned(* block_size)(PX_Cipher *c)
Definition: px.h:156
int(* decrypt)(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: px.h:162
static void init_md5 ( PX_MD h)
static

Definition at line 200 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.

201 {
202  MD5_CTX *ctx;
203 
204  ctx = px_alloc(sizeof(*ctx));
205  memset(ctx, 0, sizeof(*ctx));
206 
207  md->p.ptr = ctx;
208 
209  md->result_size = int_md5_len;
210  md->block_size = int_md5_block_len;
211  md->reset = int_md5_reset;
212  md->update = int_md5_update;
213  md->finish = int_md5_finish;
214  md->free = int_md5_free;
215 
216  md->reset(md);
217 }
#define MD5_CTX
Definition: md5.h:70
static void int_md5_reset(PX_MD *h)
Definition: internal.c:124
union int_ctx::@2 ctx
static unsigned int_md5_len(PX_MD *h)
Definition: internal.c:104
static void int_md5_finish(PX_MD *h, uint8 *dst)
Definition: internal.c:132
static unsigned int_md5_block_len(PX_MD *h)
Definition: internal.c:110
#define px_alloc(s)
Definition: px.h:44
static void int_md5_free(PX_MD *h)
Definition: internal.c:140
static void int_md5_update(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: internal.c:116
static void init_sha1 ( PX_MD h)
static

Definition at line 220 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.

221 {
222  SHA1_CTX *ctx;
223 
224  ctx = px_alloc(sizeof(*ctx));
225  memset(ctx, 0, sizeof(*ctx));
226 
227  md->p.ptr = ctx;
228 
229  md->result_size = int_sha1_len;
230  md->block_size = int_sha1_block_len;
231  md->reset = int_sha1_reset;
232  md->update = int_sha1_update;
233  md->finish = int_sha1_finish;
234  md->free = int_sha1_free;
235 
236  md->reset(md);
237 }
static unsigned int_sha1_block_len(PX_MD *h)
Definition: internal.c:158
static void int_sha1_free(PX_MD *h)
Definition: internal.c:188
static void int_sha1_update(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: internal.c:164
Definition: sha1.h:41
union int_ctx::@2 ctx
static unsigned int_sha1_len(PX_MD *h)
Definition: internal.c:152
#define px_alloc(s)
Definition: px.h:44
static void int_sha1_reset(PX_MD *h)
Definition: internal.c:172
static void int_sha1_finish(PX_MD *h, uint8 *dst)
Definition: internal.c:180
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
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)
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
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)
static unsigned int_md5_block_len ( PX_MD h)
static

Definition at line 110 of file internal.c.

References MD5_BLOCK_SIZE.

Referenced by init_md5().

111 {
112  return MD5_BLOCK_SIZE;
113 }
#define MD5_BLOCK_SIZE
Definition: internal.c:74
static void int_md5_finish ( PX_MD h,
uint8 dst 
)
static

Definition at line 132 of file internal.c.

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

Referenced by init_md5().

133 {
134  MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
135 
136  MD5Final(dst, ctx);
137 }
#define MD5Final(x, y)
Definition: md5.h:73
void * ptr
Definition: px.h:125
#define MD5_CTX
Definition: md5.h:70
union int_ctx::@2 ctx
union px_digest::@13 p
static void int_md5_free ( PX_MD h)
static

Definition at line 140 of file internal.c.

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

Referenced by init_md5().

141 {
142  MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
143 
144  px_memset(ctx, 0, sizeof(*ctx));
145  px_free(ctx);
146  px_free(h);
147 }
void * ptr
Definition: px.h:125
#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:134
static unsigned int_md5_len ( PX_MD h)
static

Definition at line 104 of file internal.c.

References MD5_DIGEST_LENGTH.

Referenced by init_md5().

105 {
106  return MD5_DIGEST_LENGTH;
107 }
#define MD5_DIGEST_LENGTH
Definition: internal.c:62
static void int_md5_reset ( PX_MD h)
static

Definition at line 124 of file internal.c.

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

Referenced by init_md5().

125 {
126  MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
127 
128  MD5Init(ctx);
129 }
void * ptr
Definition: px.h:125
#define MD5_CTX
Definition: md5.h:70
#define MD5Init(x)
Definition: md5.h:71
union int_ctx::@2 ctx
union px_digest::@13 p
static void int_md5_update ( PX_MD h,
const uint8 data,
unsigned  dlen 
)
static

Definition at line 116 of file internal.c.

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

Referenced by init_md5().

117 {
118  MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
119 
120  MD5Update(ctx, data, dlen);
121 }
void * ptr
Definition: px.h:125
#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
static unsigned int_sha1_block_len ( PX_MD h)
static

Definition at line 158 of file internal.c.

References SHA1_BLOCK_SIZE.

Referenced by init_sha1().

159 {
160  return SHA1_BLOCK_SIZE;
161 }
#define SHA1_BLOCK_SIZE
Definition: internal.c:73
static void int_sha1_finish ( PX_MD h,
uint8 dst 
)
static

Definition at line 180 of file internal.c.

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

Referenced by init_sha1().

181 {
182  SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
183 
184  SHA1Final(dst, ctx);
185 }
void * ptr
Definition: px.h:125
Definition: sha1.h:41
union int_ctx::@2 ctx
#define SHA1Final(x, y)
Definition: sha1.h:71
union px_digest::@13 p
static void int_sha1_free ( PX_MD h)
static

Definition at line 188 of file internal.c.

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

Referenced by init_sha1().

189 {
190  SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
191 
192  px_memset(ctx, 0, sizeof(*ctx));
193  px_free(ctx);
194  px_free(h);
195 }
void * ptr
Definition: px.h:125
#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:134
static unsigned int_sha1_len ( PX_MD h)
static

Definition at line 152 of file internal.c.

References SHA1_DIGEST_LENGTH.

Referenced by init_sha1().

153 {
154  return SHA1_DIGEST_LENGTH;
155 }
#define SHA1_DIGEST_LENGTH
Definition: internal.c:67
static void int_sha1_reset ( PX_MD h)
static

Definition at line 172 of file internal.c.

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

Referenced by init_sha1().

173 {
174  SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
175 
176  SHA1Init(ctx);
177 }
void * ptr
Definition: px.h:125
#define SHA1Init(x)
Definition: sha1.h:69
Definition: sha1.h:41
union int_ctx::@2 ctx
union px_digest::@13 p
static void int_sha1_update ( PX_MD h,
const uint8 data,
unsigned  dlen 
)
static

Definition at line 164 of file internal.c.

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

Referenced by init_sha1().

165 {
166  SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
167 
168  SHA1Update(ctx, data, dlen);
169 }
void * ptr
Definition: px.h:125
Definition: sha1.h:41
union int_ctx::@2 ctx
union px_digest::@13 p
#define SHA1Update(x, y, z)
Definition: sha1.h:70
static void intctx_free ( PX_Cipher c)
static

Definition at line 261 of file internal.c.

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

Referenced by bf_load(), and rj_load().

262 {
263  struct int_ctx *cx = (struct int_ctx *) c->ptr;
264 
265  if (cx)
266  {
267  px_memset(cx, 0, sizeof *cx);
268  px_free(cx);
269  }
270  px_free(c);
271 }
#define px_free(p)
Definition: px.h:46
void * ptr
Definition: px.h:165
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:134
int px_find_cipher ( const char *  name,
PX_Cipher **  res 
)

Definition at line 597 of file internal.c.

Referenced by pgp_load_cipher(), and px_find_combo().

598 {
599  int i;
600  PX_Cipher *c = NULL;
601 
603 
604  for (i = 0; int_ciphers[i].name; i++)
605  if (strcmp(int_ciphers[i].name, name) == 0)
606  {
607  c = int_ciphers[i].load();
608  break;
609  }
610 
611  if (c == NULL)
612  return PXE_NO_CIPHER;
613 
614  *res = c;
615  return 0;
616 }
static const struct int_cipher int_ciphers[]
Definition: internal.c:555
PX_Cipher *(* load)(void)
Definition: internal.c:551
char * name
Definition: internal.c:550
const char * px_resolve_alias(const PX_Alias *list, const char *name)
Definition: px.c:140
char * c
Definition: px.h:154
const char * name
Definition: encode.c:521
int i
#define PXE_NO_CIPHER
Definition: px.h:65
static const PX_Alias int_aliases[]
Definition: internal.c:563
int px_find_digest ( const char *  name,
PX_MD **  res 
)

Definition at line 578 of file internal.c.

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

579 {
580  const struct int_digest *p;
581  PX_MD *h;
582 
583  for (p = int_digest_list; p->name; p++)
584  if (pg_strcasecmp(p->name, name) == 0)
585  {
586  h = px_alloc(sizeof(*h));
587  p->init(h);
588 
589  *res = h;
590 
591  return 0;
592  }
593  return PXE_NO_HASH;
594 }
static const struct int_digest int_digest_list[]
Definition: internal.c:91
void(* init)(PX_MD *h)
Definition: internal.c:87
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
Definition: px.h:113
#define PXE_NO_HASH
Definition: px.h:64
char * name
Definition: internal.c:86
const char * name
Definition: encode.c:521
#define px_alloc(s)
Definition: px.h:44
static PX_Cipher* rj_128_cbc ( void  )
static

Definition at line 531 of file internal.c.

References MODE_CBC, and rj_load().

532 {
533  return rj_load(MODE_CBC);
534 }
#define MODE_CBC
Definition: internal.c:278
static PX_Cipher * rj_load(int mode)
Definition: internal.c:390
static PX_Cipher* rj_128_ecb ( void  )
static

Definition at line 525 of file internal.c.

References MODE_ECB, and rj_load().

526 {
527  return rj_load(MODE_ECB);
528 }
#define MODE_ECB
Definition: internal.c:277
static PX_Cipher * rj_load(int mode)
Definition: internal.c:390
static unsigned rj_block_size ( PX_Cipher c)
static

Definition at line 281 of file internal.c.

Referenced by rj_load().

282 {
283  return 128 / 8;
284 }
static int rj_decrypt ( PX_Cipher c,
const uint8 data,
unsigned  dlen,
uint8 res 
)
static

Definition at line 358 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().

359 {
360  struct int_ctx *cx = (struct int_ctx *) c->ptr;
361 
362  if (!cx->is_init)
363  if (rj_real_init(cx, 0))
364  return PXE_CIPHER_INIT;
365 
366  if (dlen == 0)
367  return 0;
368 
369  if (dlen & 15)
370  return PXE_NOTBLOCKSIZE;
371 
372  memcpy(res, data, dlen);
373 
374  if (cx->mode == MODE_CBC)
375  {
376  aes_cbc_decrypt(&cx->ctx.rj, cx->iv, res, dlen);
377  memcpy(cx->iv, data + dlen - 16, 16);
378  }
379  else
380  aes_ecb_decrypt(&cx->ctx.rj, res, dlen);
381 
382  return 0;
383 }
void aes_cbc_decrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len)
Definition: rijndael.c:567
void * ptr
Definition: px.h:165
#define MODE_CBC
Definition: internal.c:278
uint8 iv[INT_MAX_IV]
Definition: internal.c:249
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:321
#define PXE_CIPHER_INIT
Definition: px.h:70
#define PXE_NOTBLOCKSIZE
Definition: px.h:66
rijndael_ctx rj
Definition: internal.c:253
int mode
Definition: internal.c:257
int is_init
Definition: internal.c:256
static int rj_encrypt ( PX_Cipher c,
const uint8 data,
unsigned  dlen,
uint8 res 
)
static

Definition at line 328 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().

329 {
330  struct int_ctx *cx = (struct int_ctx *) c->ptr;
331 
332  if (!cx->is_init)
333  {
334  if (rj_real_init(cx, 1))
335  return PXE_CIPHER_INIT;
336  }
337 
338  if (dlen == 0)
339  return 0;
340 
341  if (dlen & 15)
342  return PXE_NOTBLOCKSIZE;
343 
344  memcpy(res, data, dlen);
345 
346  if (cx->mode == MODE_CBC)
347  {
348  aes_cbc_encrypt(&cx->ctx.rj, cx->iv, res, dlen);
349  memcpy(cx->iv, res + dlen - 16, 16);
350  }
351  else
352  aes_ecb_encrypt(&cx->ctx.rj, res, dlen);
353 
354  return 0;
355 }
void aes_cbc_encrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len)
Definition: rijndael.c:545
void * ptr
Definition: px.h:165
#define MODE_CBC
Definition: internal.c:278
uint8 iv[INT_MAX_IV]
Definition: internal.c:249
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:321
#define PXE_CIPHER_INIT
Definition: px.h:70
void aes_ecb_encrypt(rijndael_ctx *ctx, uint8 *data, unsigned len)
Definition: rijndael.c:513
#define PXE_NOTBLOCKSIZE
Definition: px.h:66
rijndael_ctx rj
Definition: internal.c:253
int mode
Definition: internal.c:257
int is_init
Definition: internal.c:256
static int rj_init ( PX_Cipher c,
const uint8 key,
unsigned  klen,
const uint8 iv 
)
static

Definition at line 299 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().

300 {
301  struct int_ctx *cx = (struct int_ctx *) c->ptr;
302 
303  if (klen <= 128 / 8)
304  cx->keylen = 128 / 8;
305  else if (klen <= 192 / 8)
306  cx->keylen = 192 / 8;
307  else if (klen <= 256 / 8)
308  cx->keylen = 256 / 8;
309  else
310  return PXE_KEY_TOO_BIG;
311 
312  memcpy(&cx->keybuf, key, klen);
313 
314  if (iv)
315  memcpy(cx->iv, iv, 128 / 8);
316 
317  return 0;
318 }
void * ptr
Definition: px.h:165
uint8 keybuf[INT_MAX_KEY]
Definition: internal.c:248
uint8 iv[INT_MAX_IV]
Definition: internal.c:249
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
#define PXE_KEY_TOO_BIG
Definition: px.h:69
unsigned keylen
Definition: internal.c:255
static unsigned rj_iv_size ( PX_Cipher c)
static

Definition at line 293 of file internal.c.

Referenced by rj_load().

294 {
295  return 128 / 8;
296 }
static unsigned rj_key_size ( PX_Cipher c)
static

Definition at line 287 of file internal.c.

Referenced by rj_load().

288 {
289  return 256 / 8;
290 }
static PX_Cipher* rj_load ( int  mode)
static

Definition at line 390 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, 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().

391 {
392  PX_Cipher *c;
393  struct int_ctx *cx;
394 
395  c = px_alloc(sizeof *c);
396  memset(c, 0, sizeof *c);
397 
399  c->key_size = rj_key_size;
400  c->iv_size = rj_iv_size;
401  c->init = rj_init;
402  c->encrypt = rj_encrypt;
403  c->decrypt = rj_decrypt;
404  c->free = intctx_free;
405 
406  cx = px_alloc(sizeof *cx);
407  memset(cx, 0, sizeof *cx);
408  cx->mode = mode;
409 
410  c->ptr = cx;
411  return c;
412 }
void(* free)(PX_Cipher *c)
Definition: px.h:163
unsigned(* key_size)(PX_Cipher *c)
Definition: px.h:157
static void intctx_free(PX_Cipher *c)
Definition: internal.c:261
void * ptr
Definition: px.h:165
static unsigned rj_block_size(PX_Cipher *c)
Definition: internal.c:281
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:328
static int rj_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
Definition: internal.c:299
static unsigned rj_key_size(PX_Cipher *c)
Definition: internal.c:287
char * c
int(* init)(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
Definition: px.h:160
unsigned(* iv_size)(PX_Cipher *c)
Definition: px.h:158
int(* encrypt)(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: px.h:161
static unsigned rj_iv_size(PX_Cipher *c)
Definition: internal.c:293
static int rj_decrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: internal.c:358
Definition: px.h:154
#define px_alloc(s)
Definition: px.h:44
int mode
Definition: internal.c:257
unsigned(* block_size)(PX_Cipher *c)
Definition: px.h:156
int(* decrypt)(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
Definition: px.h:162
static int rj_real_init ( struct int_ctx cx,
int  dir 
)
static

Definition at line 321 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().

322 {
323  aes_set_key(&cx->ctx.rj, cx->keybuf, cx->keylen * 8, dir);
324  return 0;
325 }
uint8 keybuf[INT_MAX_KEY]
Definition: internal.c:248
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:255
rijndael_ctx rj
Definition: internal.c:253

Variable Documentation

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 563 of file internal.c.

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:543
static PX_Cipher * bf_ecb_load(void)
Definition: internal.c:537
static PX_Cipher * rj_128_ecb(void)
Definition: internal.c:525
static PX_Cipher * rj_128_cbc(void)
Definition: internal.c:531

Definition at line 555 of file internal.c.

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:200
void init_sha256(PX_MD *h)
void init_sha512(PX_MD *h)
static void init_sha1(PX_MD *h)
Definition: internal.c:220

Definition at line 91 of file internal.c.