3
* Header file for pgcrypto.
5
* Copyright (c) 2001 Marko Kreen
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
11
* 1. Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* 2. Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in the
15
* documentation and/or other materials provided with the distribution.
17
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
* $PostgreSQL: pgsql/contrib/pgcrypto/px.h,v 1.9 2003-11-29 22:39:28 pgsql Exp $
35
#include <sys/types.h>
36
#include <sys/param.h>
42
#error BYTE_ORDER must be defined as LITTLE_ENDIAN or BIG_ENDIAN
48
#define px_alloc(s) palloc(s)
49
#define px_realloc(p, s) prealloc(p, s)
50
#define px_free(p) pfree(p)
54
void *xalloc(size_t s);
55
void *xrealloc(void *p, size_t s);
58
#define px_alloc(s) xalloc(s)
59
#define px_realloc(p, s) xrealloc(p, s)
60
#define px_free(p) xfree(p)
63
/* max len of 'type' parms */
64
#define PX_MAX_NAMELEN 128
66
/* max salt returned */
67
#define PX_MAX_SALT_LEN 128
70
typedef struct px_digest PX_MD;
71
typedef struct px_alias PX_Alias;
72
typedef struct px_hmac PX_HMAC;
73
typedef struct px_cipher PX_Cipher;
74
typedef struct px_combo PX_Combo;
78
unsigned (*result_size) (PX_MD * h);
79
unsigned (*block_size) (PX_MD * h);
80
void (*reset) (PX_MD * h);
81
void (*update) (PX_MD * h, const uint8 *data, unsigned dlen);
82
void (*finish) (PX_MD * h, uint8 *dst);
83
void (*free) (PX_MD * h);
100
unsigned (*result_size) (PX_HMAC * h);
101
unsigned (*block_size) (PX_HMAC * h);
102
void (*reset) (PX_HMAC * h);
103
void (*update) (PX_HMAC * h, const uint8 *data, unsigned dlen);
104
void (*finish) (PX_HMAC * h, uint8 *dst);
105
void (*free) (PX_HMAC * h);
106
void (*init) (PX_HMAC * h, const uint8 *key, unsigned klen);
119
unsigned (*block_size) (PX_Cipher * c);
120
unsigned (*key_size) (PX_Cipher * c); /* max key len */
121
unsigned (*iv_size) (PX_Cipher * c);
123
int (*init) (PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv);
124
int (*encrypt) (PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res);
125
int (*decrypt) (PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res);
126
void (*free) (PX_Cipher * c);
129
int pstat; /* mcrypt uses it */
134
int (*init) (PX_Combo * cx, const uint8 *key, unsigned klen,
135
const uint8 *iv, unsigned ivlen);
136
int (*encrypt) (PX_Combo * cx, const uint8 *data, unsigned dlen,
137
uint8 *res, unsigned *rlen);
138
int (*decrypt) (PX_Combo * cx, const uint8 *data, unsigned dlen,
139
uint8 *res, unsigned *rlen);
140
unsigned (*encrypt_len) (PX_Combo * cx, unsigned dlen);
141
unsigned (*decrypt_len) (PX_Combo * cx, unsigned dlen);
142
void (*free) (PX_Combo * cx);
148
int px_find_digest(const char *name, PX_MD ** res);
149
int px_find_hmac(const char *name, PX_HMAC ** res);
150
int px_find_cipher(const char *name, PX_Cipher ** res);
151
int px_find_combo(const char *name, PX_Combo ** res);
153
int px_get_random_bytes(uint8 *dst, unsigned count);
155
const char *px_resolve_alias(const PX_Alias * aliases, const char *name);
157
#define px_md_result_size(md) (md)->result_size(md)
158
#define px_md_block_size(md) (md)->block_size(md)
159
#define px_md_reset(md) (md)->reset(md)
160
#define px_md_update(md, data, dlen) (md)->update(md, data, dlen)
161
#define px_md_finish(md, buf) (md)->finish(md, buf)
162
#define px_md_free(md) (md)->free(md)
164
#define px_hmac_result_size(hmac) (hmac)->result_size(hmac)
165
#define px_hmac_block_size(hmac) (hmac)->block_size(hmac)
166
#define px_hmac_reset(hmac) (hmac)->reset(hmac)
167
#define px_hmac_init(hmac, key, klen) (hmac)->init(hmac, key, klen)
168
#define px_hmac_update(hmac, data, dlen) (hmac)->update(hmac, data, dlen)
169
#define px_hmac_finish(hmac, buf) (hmac)->finish(hmac, buf)
170
#define px_hmac_free(hmac) (hmac)->free(hmac)
173
#define px_cipher_key_size(c) (c)->key_size(c)
174
#define px_cipher_block_size(c) (c)->block_size(c)
175
#define px_cipher_iv_size(c) (c)->iv_size(c)
176
#define px_cipher_init(c, k, klen, iv) (c)->init(c, k, klen, iv)
177
#define px_cipher_encrypt(c, data, dlen, res) \
178
(c)->encrypt(c, data, dlen, res)
179
#define px_cipher_decrypt(c, data, dlen, res) \
180
(c)->decrypt(c, data, dlen, res)
181
#define px_cipher_free(c) (c)->free(c)
184
#define px_combo_encrypt_len(c, dlen) (c)->encrypt_len(c, dlen)
185
#define px_combo_decrypt_len(c, dlen) (c)->decrypt_len(c, dlen)
186
#define px_combo_init(c, key, klen, iv, ivlen) \
187
(c)->init(c, key, klen, iv, ivlen)
188
#define px_combo_encrypt(c, data, dlen, res, rlen) \
189
(c)->encrypt(c, data, dlen, res, rlen)
190
#define px_combo_decrypt(c, data, dlen, res, rlen) \
191
(c)->decrypt(c, data, dlen, res, rlen)
192
#define px_combo_free(c) (c)->free(c)