12
px_crypt(const char *psw, const char *salt, char *buf, unsigned buflen);
14
returns buf or NULL for error.
16
unsigned px_gen_salt(const char *salt_type, char *dst, int rounds);
18
returns salt size. dst should be PX_MAX_SALT_LEN bytes.
19
'rounds' is algorithm specific. 0 means default for
25
int px_get_random_bytes(uint8 *dst, int num)
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]
36
Objects are activated with following functions:
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);
43
returns 0 on success, < 0 on error. If successful,
44
*res contains pointer to new object.
49
uint px_md_result_size(PX_MD *md)
51
returns final result size in bytes
53
void px_md_reset(PX_MD *md)
55
resets md to clean state
57
uint px_md_block_size(PX_MD *md)
59
return algorithm block size in bytes
61
void px_md_update(PX_MD *md, const uint8 *data, uint dlen)
63
updates hash state with new data
65
void px_md_finish(PX_MD *md, uint8 *buf)
67
puts final hash state into buf. buf should have room
68
for px_md_result_size() bytes.
70
void px_md_free(PX_MD *md)
74
HMAC (Hash Message Authentication Code)
75
=======================================
77
int px_hmac_init(PX_HMAC *hmac, const uint8 *key, uint klen)
79
initalized hmac state with key.
81
uint px_hmac_result_size(PX_HMAC *md)
83
returns final result size in bytes
85
void px_hmac_reset(PX_HMAC *md)
87
resets md to state after _init()
89
uint px_hmac_block_size(PX_HMAC *md)
91
return algorithm block size in bytes
93
void px_hmac_update(PX_HMAC *md, const uint8 *data, uint dlen)
95
updates hash state with new data
97
void px_hmac_finish(PX_HMAC *md, uint8 *buf)
99
puts final hash state into buf. buf should have room
100
for px_hmac_result_size() bytes.
102
void px_hmac_free(PX_HMAC *md)
110
uint px_cipher_key_size(PX_Cipher *c)
112
returns max key size in bytes
114
uint px_cipher_block_size(PX_Cipher *c)
116
returns cipher+mode block size in bytes. So blowfish
117
in CFB mode should return 1.
119
uint px_cipher_iv_size(PX_Cipher *c)
121
returns IV size in bytes.
123
int px_cipher_init(PX_Cipher *c, uint8 *key, uint klen, uint8 *iv)
125
initializes cipher with supplied key and iv.
127
int px_cipher_encrypt(PX_Cipher *c, uint8 *data, uint dlen, uint8 *res)
129
encrypts data. res must have room for dlen bytes.
130
data must be multiple of px_cipher_block_size().
132
int px_cipher_decrypt(PX_Cipher *c, uint8 *data, uint dlen, uint8 *res)
134
decrypts data. res must have room for dlen bytes.
136
void px_cipher_free(PX_Cipher *c)
138
frees resources assiocated.
143
uint px_combo_encrypt_len(PX_Combo *c, uint dlen)
145
calculates max result length for dlen of data.
147
uint px_combo_decrypt_len(PX_Combo *c, uint dlen)
149
calculates result length for dlen of data.
151
int px_combo_init(PX_Combo *c, uint8 *key, uint klen, uint8 *iv, uint ivlen)
153
initializes c with key and iv. If cipher uses fixed length keys,
154
key will be padded with zeroes to needed length.
156
int px_combo_encrypt(PX_Combo *c, uint8 *data, uint dlen, uint8 *res, uint rlen)
158
int px_combo_decrypt(PX_Combo *c, uint8 *data, uint dlen, uint8 *res, uint rlen)
160
void px_combo_free(PX_Combo *c)
162
frees resources assiocated.