From: Guus Sliepen Date: Tue, 22 May 2007 23:41:22 +0000 (+0000) Subject: Some more crypto wrapper functions are needed. X-Git-Tag: import-tinc-1.1~632 X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=f42e57f663a2663c830c4fb4c01927c2d3c89c09;p=meshlink Some more crypto wrapper functions are needed. --- diff --git a/src/cipher.c b/src/cipher.c index 7e7b9f92..61179078 100644 --- a/src/cipher.c +++ b/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; +} diff --git a/src/cipher.h b/src/cipher.h index 522d7fb7..45a4fc5a 100644 --- a/src/cipher.h +++ b/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 diff --git a/src/digest.c b/src/digest.c index 98754ab2..50b0f238 100644 --- a/src/digest.c +++ b/src/digest.c @@ -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; +} diff --git a/src/digest.h b/src/digest.h index fa470c79..dd9029e7 100644 --- a/src/digest.h +++ b/src/digest.h @@ -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