X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fcipher.c;h=61179078cbe88d605e1882d141c2c5eb6c1fdc4c;hb=f42e57f663a2663c830c4fb4c01927c2d3c89c09;hp=7e7b9f9275c38ce87097772e8aa70f4edfa9f6a8;hpb=19413a8048fd851866c551ab8035f008f0c7e806;p=tinc 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; +}