~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to contrib/pgcrypto/internal.c

Tags: upstream-8.4.0
ImportĀ upstreamĀ versionĀ 8.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
27
 * SUCH DAMAGE.
28
28
 *
29
 
 * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.28 2008/02/17 02:09:26 tgl Exp $
 
29
 * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.29 2009/06/11 14:48:52 momjian Exp $
30
30
 */
31
31
 
32
32
#include "postgres.h"
75
75
#define SHA1_BLOCK_SIZE 64
76
76
#define MD5_BLOCK_SIZE 64
77
77
 
78
 
static void init_md5(PX_MD * h);
79
 
static void init_sha1(PX_MD * h);
 
78
static void init_md5(PX_MD *h);
 
79
static void init_sha1(PX_MD *h);
80
80
 
81
 
void            init_sha224(PX_MD * h);
82
 
void            init_sha256(PX_MD * h);
83
 
void            init_sha384(PX_MD * h);
84
 
void            init_sha512(PX_MD * h);
 
81
void            init_sha224(PX_MD *h);
 
82
void            init_sha256(PX_MD *h);
 
83
void            init_sha384(PX_MD *h);
 
84
void            init_sha512(PX_MD *h);
85
85
 
86
86
struct int_digest
87
87
{
88
88
        char       *name;
89
 
        void            (*init) (PX_MD * h);
 
89
        void            (*init) (PX_MD *h);
90
90
};
91
91
 
92
92
static const struct int_digest
103
103
/* MD5 */
104
104
 
105
105
static unsigned
106
 
int_md5_len(PX_MD * h)
 
106
int_md5_len(PX_MD *h)
107
107
{
108
108
        return MD5_DIGEST_LENGTH;
109
109
}
110
110
 
111
111
static unsigned
112
 
int_md5_block_len(PX_MD * h)
 
112
int_md5_block_len(PX_MD *h)
113
113
{
114
114
        return MD5_BLOCK_SIZE;
115
115
}
116
116
 
117
117
static void
118
 
int_md5_update(PX_MD * h, const uint8 *data, unsigned dlen)
 
118
int_md5_update(PX_MD *h, const uint8 *data, unsigned dlen)
119
119
{
120
120
        MD5_CTX    *ctx = (MD5_CTX *) h->p.ptr;
121
121
 
123
123
}
124
124
 
125
125
static void
126
 
int_md5_reset(PX_MD * h)
 
126
int_md5_reset(PX_MD *h)
127
127
{
128
128
        MD5_CTX    *ctx = (MD5_CTX *) h->p.ptr;
129
129
 
131
131
}
132
132
 
133
133
static void
134
 
int_md5_finish(PX_MD * h, uint8 *dst)
 
134
int_md5_finish(PX_MD *h, uint8 *dst)
135
135
{
136
136
        MD5_CTX    *ctx = (MD5_CTX *) h->p.ptr;
137
137
 
139
139
}
140
140
 
141
141
static void
142
 
int_md5_free(PX_MD * h)
 
142
int_md5_free(PX_MD *h)
143
143
{
144
144
        MD5_CTX    *ctx = (MD5_CTX *) h->p.ptr;
145
145
 
151
151
/* SHA1 */
152
152
 
153
153
static unsigned
154
 
int_sha1_len(PX_MD * h)
 
154
int_sha1_len(PX_MD *h)
155
155
{
156
156
        return SHA1_DIGEST_LENGTH;
157
157
}
158
158
 
159
159
static unsigned
160
 
int_sha1_block_len(PX_MD * h)
 
160
int_sha1_block_len(PX_MD *h)
161
161
{
162
162
        return SHA1_BLOCK_SIZE;
163
163
}
164
164
 
165
165
static void
166
 
int_sha1_update(PX_MD * h, const uint8 *data, unsigned dlen)
 
166
int_sha1_update(PX_MD *h, const uint8 *data, unsigned dlen)
167
167
{
168
168
        SHA1_CTX   *ctx = (SHA1_CTX *) h->p.ptr;
169
169
 
171
171
}
172
172
 
173
173
static void
174
 
int_sha1_reset(PX_MD * h)
 
174
int_sha1_reset(PX_MD *h)
175
175
{
176
176
        SHA1_CTX   *ctx = (SHA1_CTX *) h->p.ptr;
177
177
 
179
179
}
180
180
 
181
181
static void
182
 
int_sha1_finish(PX_MD * h, uint8 *dst)
 
182
int_sha1_finish(PX_MD *h, uint8 *dst)
183
183
{
184
184
        SHA1_CTX   *ctx = (SHA1_CTX *) h->p.ptr;
185
185
 
187
187
}
188
188
 
189
189
static void
190
 
int_sha1_free(PX_MD * h)
 
190
int_sha1_free(PX_MD *h)
191
191
{
192
192
        SHA1_CTX   *ctx = (SHA1_CTX *) h->p.ptr;
193
193
 
199
199
/* init functions */
200
200
 
201
201
static void
202
 
init_md5(PX_MD * md)
 
202
init_md5(PX_MD *md)
203
203
{
204
204
        MD5_CTX    *ctx;
205
205
 
219
219
}
220
220
 
221
221
static void
222
 
init_sha1(PX_MD * md)
 
222
init_sha1(PX_MD *md)
223
223
{
224
224
        SHA1_CTX   *ctx;
225
225
 
260
260
};
261
261
 
262
262
static void
263
 
intctx_free(PX_Cipher * c)
 
263
intctx_free(PX_Cipher *c)
264
264
{
265
265
        struct int_ctx *cx = (struct int_ctx *) c->ptr;
266
266
 
280
280
#define MODE_CBC 1
281
281
 
282
282
static unsigned
283
 
rj_block_size(PX_Cipher * c)
 
283
rj_block_size(PX_Cipher *c)
284
284
{
285
285
        return 128 / 8;
286
286
}
287
287
 
288
288
static unsigned
289
 
rj_key_size(PX_Cipher * c)
 
289
rj_key_size(PX_Cipher *c)
290
290
{
291
291
        return 256 / 8;
292
292
}
293
293
 
294
294
static unsigned
295
 
rj_iv_size(PX_Cipher * c)
 
295
rj_iv_size(PX_Cipher *c)
296
296
{
297
297
        return 128 / 8;
298
298
}
299
299
 
300
300
static int
301
 
rj_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
 
301
rj_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
302
302
{
303
303
        struct int_ctx *cx = (struct int_ctx *) c->ptr;
304
304
 
327
327
}
328
328
 
329
329
static int
330
 
rj_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
 
330
rj_encrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
331
331
{
332
332
        struct int_ctx *cx = (struct int_ctx *) c->ptr;
333
333
 
357
357
}
358
358
 
359
359
static int
360
 
rj_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
 
360
rj_decrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
361
361
{
362
362
        struct int_ctx *cx = (struct int_ctx *) c->ptr;
363
363
 
418
418
 */
419
419
 
420
420
static unsigned
421
 
bf_block_size(PX_Cipher * c)
 
421
bf_block_size(PX_Cipher *c)
422
422
{
423
423
        return 8;
424
424
}
425
425
 
426
426
static unsigned
427
 
bf_key_size(PX_Cipher * c)
 
427
bf_key_size(PX_Cipher *c)
428
428
{
429
429
        return 448 / 8;
430
430
}
431
431
 
432
432
static unsigned
433
 
bf_iv_size(PX_Cipher * c)
 
433
bf_iv_size(PX_Cipher *c)
434
434
{
435
435
        return 8;
436
436
}
437
437
 
438
438
static int
439
 
bf_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
 
439
bf_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
440
440
{
441
441
        struct int_ctx *cx = (struct int_ctx *) c->ptr;
442
442
 
448
448
}
449
449
 
450
450
static int
451
 
bf_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
 
451
bf_encrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
452
452
{
453
453
        struct int_ctx *cx = (struct int_ctx *) c->ptr;
454
454
        BlowfishContext *bfctx = &cx->ctx.bf;
473
473
}
474
474
 
475
475
static int
476
 
bf_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
 
476
bf_decrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
477
477
{
478
478
        struct int_ctx *cx = (struct int_ctx *) c->ptr;
479
479
        BlowfishContext *bfctx = &cx->ctx.bf;
577
577
/* PUBLIC FUNCTIONS */
578
578
 
579
579
int
580
 
px_find_digest(const char *name, PX_MD ** res)
 
580
px_find_digest(const char *name, PX_MD **res)
581
581
{
582
582
        const struct int_digest *p;
583
583
        PX_MD      *h;
596
596
}
597
597
 
598
598
int
599
 
px_find_cipher(const char *name, PX_Cipher ** res)
 
599
px_find_cipher(const char *name, PX_Cipher **res)
600
600
{
601
601
        int                     i;
602
602
        PX_Cipher  *c = NULL;