PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
px.h
Go to the documentation of this file.
1/*
2 * px.h
3 * Header file for pgcrypto.
4 *
5 * Copyright (c) 2001 Marko Kreen
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
16 *
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
27 * SUCH DAMAGE.
28 *
29 * contrib/pgcrypto/px.h
30 */
31
32#ifndef __PX_H
33#define __PX_H
34
35#include <sys/param.h>
36
37/* keep debug messages? */
38#define PX_DEBUG
39
40/* max salt returned */
41#define PX_MAX_SALT_LEN 128
42
43/*
44 * PX error codes
45 */
46#define PXE_OK 0
47/* -1 is unused */
48#define PXE_NO_HASH -2
49#define PXE_NO_CIPHER -3
50/* -4 is unused */
51#define PXE_BAD_OPTION -5
52#define PXE_BAD_FORMAT -6
53#define PXE_KEY_TOO_BIG -7
54#define PXE_CIPHER_INIT -8
55#define PXE_HASH_UNUSABLE_FOR_HMAC -9
56/* -10 is unused */
57/* -11 is unused */
58#define PXE_BUG -12
59#define PXE_ARGUMENT_ERROR -13
60#define PXE_UNKNOWN_SALT_ALGO -14
61#define PXE_BAD_SALT_ROUNDS -15
62/* -16 is unused */
63#define PXE_NO_RANDOM -17
64#define PXE_DECRYPT_FAILED -18
65#define PXE_ENCRYPT_FAILED -19
66
67#define PXE_PGP_CORRUPT_DATA -100
68#define PXE_PGP_CORRUPT_ARMOR -101
69#define PXE_PGP_UNSUPPORTED_COMPR -102
70#define PXE_PGP_UNSUPPORTED_CIPHER -103
71#define PXE_PGP_UNSUPPORTED_HASH -104
72#define PXE_PGP_COMPRESSION_ERROR -105
73#define PXE_PGP_NOT_TEXT -106
74#define PXE_PGP_UNEXPECTED_PKT -107
75/* -108 is unused */
76#define PXE_PGP_MATH_FAILED -109
77#define PXE_PGP_SHORT_ELGAMAL_KEY -110
78/* -111 is unused */
79#define PXE_PGP_UNKNOWN_PUBALGO -112
80#define PXE_PGP_WRONG_KEY -113
81#define PXE_PGP_MULTIPLE_KEYS -114
82#define PXE_PGP_EXPECT_PUBLIC_KEY -115
83#define PXE_PGP_EXPECT_SECRET_KEY -116
84#define PXE_PGP_NOT_V4_KEYPKT -117
85#define PXE_PGP_KEYPKT_CORRUPT -118
86#define PXE_PGP_NO_USABLE_KEY -119
87#define PXE_PGP_NEED_SECRET_PSW -120
88#define PXE_PGP_BAD_S2K_MODE -121
89#define PXE_PGP_UNSUPPORTED_PUBALGO -122
90#define PXE_PGP_MULTIPLE_SUBKEYS -123
91
93{
98
99typedef struct px_digest PX_MD;
100typedef struct px_alias PX_Alias;
101typedef struct px_hmac PX_HMAC;
102typedef struct px_cipher PX_Cipher;
103typedef struct px_combo PX_Combo;
104
105extern int builtin_crypto_enabled;
106
108{
109 unsigned (*result_size) (PX_MD *h);
110 unsigned (*block_size) (PX_MD *h);
111 void (*reset) (PX_MD *h);
112 void (*update) (PX_MD *h, const uint8 *data, unsigned dlen);
113 void (*finish) (PX_MD *h, uint8 *dst);
114 void (*free) (PX_MD *h);
115 /* private */
116 union
117 {
118 unsigned code;
119 void *ptr;
120 } p;
121};
122
124{
125 char *alias;
126 char *name;
127};
128
130{
131 unsigned (*result_size) (PX_HMAC *h);
132 unsigned (*block_size) (PX_HMAC *h);
133 void (*reset) (PX_HMAC *h);
134 void (*update) (PX_HMAC *h, const uint8 *data, unsigned dlen);
135 void (*finish) (PX_HMAC *h, uint8 *dst);
136 void (*free) (PX_HMAC *h);
137 void (*init) (PX_HMAC *h, const uint8 *key, unsigned klen);
138
140 /* private */
141 struct
142 {
145 } p;
146};
147
149{
150 unsigned (*block_size) (PX_Cipher *c);
151 unsigned (*key_size) (PX_Cipher *c); /* max key len */
152 unsigned (*iv_size) (PX_Cipher *c);
153
154 int (*init) (PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv);
155 int (*encrypt) (PX_Cipher *c, int padding, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen);
156 int (*decrypt) (PX_Cipher *c, int padding, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen);
157 void (*free) (PX_Cipher *c);
158 /* private */
159 void *ptr;
160 int pstat; /* mcrypt uses it */
161};
162
164{
165 int (*init) (PX_Combo *cx, const uint8 *key, unsigned klen,
166 const uint8 *iv, unsigned ivlen);
167 int (*encrypt) (PX_Combo *cx, const uint8 *data, unsigned dlen,
168 uint8 *res, unsigned *rlen);
169 int (*decrypt) (PX_Combo *cx, const uint8 *data, unsigned dlen,
170 uint8 *res, unsigned *rlen);
171 unsigned (*encrypt_len) (PX_Combo *cx, unsigned dlen);
172 unsigned (*decrypt_len) (PX_Combo *cx, unsigned dlen);
173 void (*free) (PX_Combo *cx);
174
176 unsigned padding;
177};
178
179int px_find_digest(const char *name, PX_MD **res);
180int px_find_hmac(const char *name, PX_HMAC **res);
181int px_find_cipher(const char *name, PX_Cipher **res);
182int px_find_combo(const char *name, PX_Combo **res);
183
185const char *px_strerror(int err);
186
187const char *px_resolve_alias(const PX_Alias *list, const char *name);
188
189void px_set_debug_handler(void (*handler) (const char *));
190
191void px_memset(void *ptr, int c, size_t len);
192
193bool CheckFIPSMode(void);
194void CheckBuiltinCryptoMode(void);
195
196#ifdef PX_DEBUG
197void px_debug(const char *fmt,...) pg_attribute_printf(1, 2);
198#else
199#define px_debug(...)
200#endif
201
202#define px_md_result_size(md) (md)->result_size(md)
203#define px_md_block_size(md) (md)->block_size(md)
204#define px_md_reset(md) (md)->reset(md)
205#define px_md_update(md, data, dlen) (md)->update(md, data, dlen)
206#define px_md_finish(md, buf) (md)->finish(md, buf)
207#define px_md_free(md) (md)->free(md)
208
209#define px_hmac_result_size(hmac) (hmac)->result_size(hmac)
210#define px_hmac_block_size(hmac) (hmac)->block_size(hmac)
211#define px_hmac_reset(hmac) (hmac)->reset(hmac)
212#define px_hmac_init(hmac, key, klen) (hmac)->init(hmac, key, klen)
213#define px_hmac_update(hmac, data, dlen) (hmac)->update(hmac, data, dlen)
214#define px_hmac_finish(hmac, buf) (hmac)->finish(hmac, buf)
215#define px_hmac_free(hmac) (hmac)->free(hmac)
216
217
218#define px_cipher_key_size(c) (c)->key_size(c)
219#define px_cipher_block_size(c) (c)->block_size(c)
220#define px_cipher_iv_size(c) (c)->iv_size(c)
221#define px_cipher_init(c, k, klen, iv) (c)->init(c, k, klen, iv)
222#define px_cipher_encrypt(c, padding, data, dlen, res, rlen) \
223 (c)->encrypt(c, padding, data, dlen, res, rlen)
224#define px_cipher_decrypt(c, padding, data, dlen, res, rlen) \
225 (c)->decrypt(c, padding, data, dlen, res, rlen)
226#define px_cipher_free(c) (c)->free(c)
227
228
229#define px_combo_encrypt_len(c, dlen) (c)->encrypt_len(c, dlen)
230#define px_combo_decrypt_len(c, dlen) (c)->decrypt_len(c, dlen)
231#define px_combo_init(c, key, klen, iv, ivlen) \
232 (c)->init(c, key, klen, iv, ivlen)
233#define px_combo_encrypt(c, data, dlen, res, rlen) \
234 (c)->encrypt(c, data, dlen, res, rlen)
235#define px_combo_decrypt(c, data, dlen, res, rlen) \
236 (c)->decrypt(c, data, dlen, res, rlen)
237#define px_combo_free(c) (c)->free(c)
238
239#endif /* __PX_H */
uint8_t uint8
Definition: c.h:500
#define pg_noreturn
Definition: c.h:165
#define pg_attribute_printf(f, a)
Definition: c.h:233
void err(int eval, const char *fmt,...)
Definition: err.c:43
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
const void size_t len
const void * data
char * c
int px_find_digest(const char *name, PX_MD **res)
Definition: openssl.c:161
void CheckBuiltinCryptoMode(void)
Definition: openssl.c:874
int px_find_hmac(const char *name, PX_HMAC **res)
Definition: px-hmac.c:142
bool CheckFIPSMode(void)
Definition: openssl.c:844
BuiltinCryptoOptions
Definition: px.h:93
@ BC_ON
Definition: px.h:94
@ BC_OFF
Definition: px.h:95
@ BC_FIPS
Definition: px.h:96
pg_noreturn void px_THROW_ERROR(int err)
Definition: px.c:93
const char * px_strerror(int err)
Definition: px.c:111
int px_find_cipher(const char *name, PX_Cipher **res)
Definition: openssl.c:776
void px_set_debug_handler(void(*handler)(const char *))
Definition: px.c:143
int builtin_crypto_enabled
Definition: pgcrypto.c:62
void px_debug(const char *fmt,...) pg_attribute_printf(1
const char * px_resolve_alias(const PX_Alias *list, const char *name)
Definition: px.c:129
int px_find_combo(const char *name, PX_Combo **res)
Definition: px.c:285
void px_memset(void *ptr, int c, size_t len)
Definition: px.c:123
Definition: px.h:124
char * alias
Definition: px.h:125
char * name
Definition: px.h:126
Definition: px.h:149
int pstat
Definition: px.h:160
void(* free)(PX_Cipher *c)
Definition: px.h:157
unsigned(* block_size)(PX_Cipher *c)
Definition: px.h:150
void * ptr
Definition: px.h:159
unsigned(* iv_size)(PX_Cipher *c)
Definition: px.h:152
int(* encrypt)(PX_Cipher *c, int padding, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.h:155
int(* init)(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
Definition: px.h:154
unsigned(* key_size)(PX_Cipher *c)
Definition: px.h:151
int(* decrypt)(PX_Cipher *c, int padding, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.h:156
Definition: px.h:164
unsigned padding
Definition: px.h:176
int(* decrypt)(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.h:169
unsigned(* decrypt_len)(PX_Combo *cx, unsigned dlen)
Definition: px.h:172
int(* encrypt)(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.h:167
PX_Cipher * cipher
Definition: px.h:175
void(* free)(PX_Combo *cx)
Definition: px.h:173
unsigned(* encrypt_len)(PX_Combo *cx, unsigned dlen)
Definition: px.h:171
int(* init)(PX_Combo *cx, const uint8 *key, unsigned klen, const uint8 *iv, unsigned ivlen)
Definition: px.h:165
Definition: px.h:108
void(* free)(PX_MD *h)
Definition: px.h:114
void(* update)(PX_MD *h, const uint8 *data, unsigned dlen)
Definition: px.h:112
unsigned(* result_size)(PX_MD *h)
Definition: px.h:109
union px_digest::@8 p
void(* reset)(PX_MD *h)
Definition: px.h:111
unsigned code
Definition: px.h:118
unsigned(* block_size)(PX_MD *h)
Definition: px.h:110
void * ptr
Definition: px.h:119
void(* finish)(PX_MD *h, uint8 *dst)
Definition: px.h:113
Definition: px.h:130
PX_MD * md
Definition: px.h:139
unsigned(* block_size)(PX_HMAC *h)
Definition: px.h:132
void(* finish)(PX_HMAC *h, uint8 *dst)
Definition: px.h:135
uint8 * ipad
Definition: px.h:143
struct px_hmac::@9 p
void(* init)(PX_HMAC *h, const uint8 *key, unsigned klen)
Definition: px.h:137
uint8 * opad
Definition: px.h:144
unsigned(* result_size)(PX_HMAC *h)
Definition: px.h:131
void(* update)(PX_HMAC *h, const uint8 *data, unsigned dlen)
Definition: px.h:134
void(* free)(PX_HMAC *h)
Definition: px.h:136
void(* reset)(PX_HMAC *h)
Definition: px.h:133
const char * name