~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to contrib/pgcrypto/API

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
C API for pgcrypto
 
3
==================
 
4
 
 
5
 
 
6
UN*X crypt()
 
7
============
 
8
 
 
9
#include <px-crypt.h>
 
10
 
 
11
char *
 
12
px_crypt(const char *psw, const char *salt, char *buf, unsigned buflen);
 
13
 
 
14
        returns buf or NULL for error.
 
15
 
 
16
unsigned px_gen_salt(const char *salt_type, char *dst, int rounds);
 
17
 
 
18
        returns salt size.  dst should be PX_MAX_SALT_LEN bytes.
 
19
        'rounds' is algorithm specific.  0 means default for
 
20
        that algorithm.
 
21
 
 
22
Random
 
23
======
 
24
 
 
25
int px_get_random_bytes(uint8 *dst, int num)
 
26
 
 
27
 
 
28
Crypto "objects"
 
29
================
 
30
 
 
31
PX_MD      - Message digest
 
32
PX_HMAC    - HMAC (Hash MAC)
 
33
PX_Cipher  - cipher+mode: provided by libs
 
34
PX_Combo   - higher-level encryption -> padding, [MD]
 
35
 
 
36
Objects are activated with following functions:
 
37
 
 
38
int px_find_digest(const char *name, PX_MD **res);
 
39
int px_find_hmac(const char *name, PX_HMAC **res);
 
40
int px_find_cipher(const char *name, PX_Cipher **res);
 
41
int px_find_combo(const char *name, PX_Combo **res);
 
42
 
 
43
        returns 0 on success, < 0 on error.  If successful,
 
44
        *res contains pointer to new object.
 
45
 
 
46
Message Digest
 
47
==============
 
48
 
 
49
uint px_md_result_size(PX_MD *md)
 
50
 
 
51
        returns final result size in bytes
 
52
 
 
53
void px_md_reset(PX_MD *md)
 
54
 
 
55
        resets md to clean state
 
56
 
 
57
uint px_md_block_size(PX_MD *md)
 
58
 
 
59
        return algorithm block size in bytes
 
60
 
 
61
void px_md_update(PX_MD *md, const uint8 *data, uint dlen)
 
62
 
 
63
        updates hash state with new data
 
64
 
 
65
void px_md_finish(PX_MD *md, uint8 *buf)
 
66
 
 
67
        puts final hash state into buf.  buf should have room
 
68
        for px_md_result_size() bytes.
 
69
 
 
70
void px_md_free(PX_MD *md)
 
71
 
 
72
        frees resources.
 
73
 
 
74
HMAC (Hash Message Authentication Code)
 
75
=======================================
 
76
 
 
77
int px_hmac_init(PX_HMAC *hmac, const uint8 *key, uint klen)
 
78
 
 
79
        initalized hmac state with key.
 
80
 
 
81
uint px_hmac_result_size(PX_HMAC *md)
 
82
 
 
83
        returns final result size in bytes
 
84
 
 
85
void px_hmac_reset(PX_HMAC *md)
 
86
 
 
87
        resets md to state after _init()
 
88
 
 
89
uint px_hmac_block_size(PX_HMAC *md)
 
90
 
 
91
        return algorithm block size in bytes
 
92
 
 
93
void px_hmac_update(PX_HMAC *md, const uint8 *data, uint dlen)
 
94
 
 
95
        updates hash state with new data
 
96
 
 
97
void px_hmac_finish(PX_HMAC *md, uint8 *buf)
 
98
 
 
99
        puts final hash state into buf.  buf should have room
 
100
        for px_hmac_result_size() bytes.
 
101
 
 
102
void px_hmac_free(PX_HMAC *md)
 
103
 
 
104
        frees resources.
 
105
 
 
106
 
 
107
Cipher
 
108
======
 
109
 
 
110
uint px_cipher_key_size(PX_Cipher *c)
 
111
 
 
112
        returns max key size in bytes
 
113
 
 
114
uint px_cipher_block_size(PX_Cipher *c)
 
115
 
 
116
        returns cipher+mode block size in bytes.  So blowfish
 
117
        in CFB mode should return 1.
 
118
 
 
119
uint px_cipher_iv_size(PX_Cipher *c)
 
120
 
 
121
        returns IV size in bytes.
 
122
 
 
123
int px_cipher_init(PX_Cipher *c, uint8 *key, uint klen, uint8 *iv)
 
124
 
 
125
        initializes cipher with supplied key and iv.
 
126
 
 
127
int px_cipher_encrypt(PX_Cipher *c, uint8 *data, uint dlen, uint8 *res)
 
128
 
 
129
        encrypts data.  res must have room for dlen bytes.
 
130
        data must be multiple of px_cipher_block_size().
 
131
 
 
132
int px_cipher_decrypt(PX_Cipher *c, uint8 *data, uint dlen, uint8 *res)
 
133
 
 
134
        decrypts data.  res must have room for dlen bytes.
 
135
 
 
136
void px_cipher_free(PX_Cipher *c)
 
137
 
 
138
        frees resources assiocated.
 
139
 
 
140
PX_Combo
 
141
========
 
142
 
 
143
uint px_combo_encrypt_len(PX_Combo *c, uint dlen)
 
144
 
 
145
        calculates max result length for dlen of data.
 
146
 
 
147
uint px_combo_decrypt_len(PX_Combo *c, uint dlen)
 
148
 
 
149
        calculates result length for dlen of data.
 
150
 
 
151
int px_combo_init(PX_Combo *c, uint8 *key, uint klen, uint8 *iv, uint ivlen)
 
152
 
 
153
        initializes c with key and iv.  If cipher uses fixed length keys,
 
154
        key will be padded with zeroes to needed length.
 
155
 
 
156
int px_combo_encrypt(PX_Combo *c, uint8 *data, uint dlen, uint8 *res, uint rlen)
 
157
 
 
158
int px_combo_decrypt(PX_Combo *c, uint8 *data, uint dlen, uint8 *res, uint rlen)
 
159
 
 
160
void px_combo_free(PX_Combo *c)
 
161
 
 
162
        frees resources assiocated.
 
163