Some more crypto wrapper functions are needed.
This commit is contained in:
parent
19413a8048
commit
f42e57f663
4 changed files with 46 additions and 11 deletions
22
src/cipher.c
22
src/cipher.c
|
@ -156,6 +156,23 @@ void cipher_close(cipher_t *cipher) {
|
|||
}
|
||||
}
|
||||
|
||||
size_t cipher_keylength(const cipher_t *cipher) {
|
||||
return cipher->keylen + cipher->blklen;
|
||||
}
|
||||
|
||||
void cipher_get_key(const cipher_t *cipher, void *key) {
|
||||
memcpy(key, cipher->key, cipher->keylen + cipher->blklen);
|
||||
}
|
||||
|
||||
bool cipher_set_key(cipher_t *cipher, void *key) {
|
||||
memcpy(cipher->key, key, cipher->keylen + cipher->blklen);
|
||||
|
||||
gcry_cipher_setkey(cipher->handle, cipher->key, cipher->keylen);
|
||||
gcry_cipher_setiv(cipher->handle, cipher->key + cipher->keylen, cipher->blklen);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cipher_regenerate_key(cipher_t *cipher) {
|
||||
gcry_create_nonce(cipher->key, cipher->keylen + cipher->blklen);
|
||||
|
||||
|
@ -227,7 +244,10 @@ void cipher_reset(cipher_t *cipher) {
|
|||
gcry_cipher_setiv(cipher->handle, cipher->key + cipher->keylen, cipher->blklen);
|
||||
}
|
||||
|
||||
int cipher_get_nid(cipher_t *cipher) {
|
||||
int cipher_get_nid(const cipher_t *cipher) {
|
||||
return cipher->nid;
|
||||
}
|
||||
|
||||
bool cipher_active(const cipher_t *cipher) {
|
||||
return cipher->nid != 0;
|
||||
}
|
||||
|
|
21
src/cipher.h
21
src/cipher.h
|
@ -32,13 +32,18 @@ typedef struct cipher {
|
|||
uint16_t blklen;
|
||||
} cipher_t;
|
||||
|
||||
bool cipher_open_by_name(struct cipher *, const char *);
|
||||
bool cipher_open_by_nid(struct cipher *, int);
|
||||
bool cipher_open_blowfish_ofb(struct cipher *);
|
||||
void cipher_close(struct cipher *);
|
||||
bool cipher_regenerate_key(struct cipher *);
|
||||
bool cipher_encrypt(struct cipher *, void *indata, size_t inlen, void *outdata, size_t *outlen);
|
||||
bool cipher_decrypt(struct cipher *, void *indata, size_t inlen, void *outdata, size_t *outlen);
|
||||
int cipher_get_nid(struct cipher *);
|
||||
extern bool cipher_open_by_name(struct cipher *, const char *);
|
||||
extern bool cipher_open_by_nid(struct cipher *, int);
|
||||
extern bool cipher_open_blowfish_ofb(struct cipher *);
|
||||
extern void cipher_close(struct cipher *);
|
||||
extern size_t cipher_keylength(const struct cipher *);
|
||||
extern void cipher_get_key(const struct cipher *, void *);
|
||||
extern bool cipher_set_key(struct cipher *, void *);
|
||||
extern bool cipher_regenerate_key(struct cipher *);
|
||||
extern void cipher_reset(struct cipher *);
|
||||
extern bool cipher_encrypt(struct cipher *, void *indata, size_t inlen, void *outdata, size_t *outlen);
|
||||
extern bool cipher_decrypt(struct cipher *, void *indata, size_t inlen, void *outdata, size_t *outlen);
|
||||
extern int cipher_get_nid(const struct cipher *);
|
||||
extern bool cipher_active(const struct cipher *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -127,7 +127,14 @@ bool digest_verify(digest_t *digest, void *indata, size_t inlen, void *cmpdata)
|
|||
return !memcmp(indata, outdata, digest->len);
|
||||
}
|
||||
|
||||
int digest_get_nid(digest_t *digest) {
|
||||
int digest_get_nid(const digest_t *digest) {
|
||||
return digest->nid;
|
||||
}
|
||||
|
||||
size_t digest_length(const digest_t *digest) {
|
||||
return digest->len;
|
||||
}
|
||||
|
||||
bool digest_active(const digest_t *digest) {
|
||||
return digest->algo != GCRY_MD_NONE;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,11 @@ typedef struct digest {
|
|||
bool digest_open_by_name(struct digest *, const char *);
|
||||
bool digest_open_by_nid(struct digest *, int);
|
||||
bool digest_open_sha1(struct digest *);
|
||||
void digest_close(struct digest *);
|
||||
bool digest_create(struct digest *, void *indata, size_t inlen, void *outdata);
|
||||
bool digest_verify(struct digest *, void *indata, size_t inlen, void *digestdata);
|
||||
int digest_get_nid(struct digest *);
|
||||
int digest_get_nid(const struct digest *);
|
||||
size_t digest_length(const struct digest *);
|
||||
bool digest_active(const struct digest *);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue