[PATCH 2/3] API for reading the counter in CTR mode
Stephan Mueller
smueller at chronox.de
Thu Dec 1 17:11:42 CET 2016
The API call allows reading the current counter of the CTR mode. The API
remains internal to libgcrypt and is not exported to external callers.
Signed-off-by: Stephan Mueller <smueller at chronox.de>
---
cipher/cipher.c | 10 ++++++++++
src/gcrypt-int.h | 2 ++
2 files changed, 12 insertions(+)
diff --git a/cipher/cipher.c b/cipher/cipher.c
index ff3340f..55853da 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -1117,6 +1117,16 @@ _gcry_cipher_setctr (gcry_cipher_hd_t hd, const void *ctr, size_t ctrlen)
return 0;
}
+gpg_err_code_t
+_gcry_cipher_getctr (gcry_cipher_hd_t hd, void *ctr, size_t ctrlen)
+{
+ if (ctr && ctrlen == hd->spec->blocksize)
+ memcpy (ctr, hd->u_ctr.ctr, hd->spec->blocksize);
+ else
+ return GPG_ERR_INV_ARG;
+
+ return 0;
+}
gcry_err_code_t
_gcry_cipher_authenticate (gcry_cipher_hd_t hd, const void *abuf,
diff --git a/src/gcrypt-int.h b/src/gcrypt-int.h
index 729f54a..ef5337b 100644
--- a/src/gcrypt-int.h
+++ b/src/gcrypt-int.h
@@ -77,6 +77,8 @@ gpg_err_code_t _gcry_cipher_checktag (gcry_cipher_hd_t hd, const void *intag,
size_t taglen);
gpg_err_code_t _gcry_cipher_setctr (gcry_cipher_hd_t hd,
const void *ctr, size_t ctrlen);
+gpg_err_code_t _gcry_cipher_getctr (gcry_cipher_hd_t hd,
+ void *ctr, size_t ctrlen);
size_t _gcry_cipher_get_algo_keylen (int algo);
size_t _gcry_cipher_get_algo_blklen (int algo);
--
2.9.3
More information about the Gcrypt-devel
mailing list