}
}
+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);
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;
+}
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
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;
+}
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